SBgl 0.1.0
A graphics framework in C99
Loading...
Searching...
No Matches
win32_internal.h File Reference
#include "core/sbgl_input.h"
#include "sbgl_types.h"
#include <windows.h>
Include dependency graph for win32_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  sbgl_Window
 Native X11 window state. More...
 

Macros

#define UNICODE
 
#define WIN32_LEAN_AND_MEAN
 

Functions

void win32_internal_process_message (sbgl_InputState *input, UINT msg, WPARAM wparam, LPARAM lparam)
 
void win32_internal_update_input_states (sbgl_InputState *input, struct sbgl_Window *window)
 

Macro Definition Documentation

◆ UNICODE

#define UNICODE

Definition at line 5 of file win32_internal.h.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 7 of file win32_internal.h.

Function Documentation

◆ win32_internal_process_message()

void win32_internal_process_message ( sbgl_InputState * input,
UINT msg,
WPARAM wparam,
LPARAM lparam )

Definition at line 98 of file input.c.

98 {
99 if (!input) return;
100 switch (msg) {
101 case WM_KEYDOWN:
102 case WM_SYSKEYDOWN: {
103 SBGL_Scancode code = win32_vk_to_scancode(wparam);
104 if (code < SBGL_SCANCODE_MAX) {
105 // Filter auto-repeat: bit 30 of lparam indicates previous key state
106 // If set, this is an auto-repeat message, not an initial press
107 bool isRepeat = (lparam & (1 << 30)) != 0;
108 if (!isRepeat) {
109 input->keysPressed[code] = true;
110 }
111 input->keysDown[code] = true;
112 }
113 break;
114 }
115 case WM_KEYUP:
116 case WM_SYSKEYUP: {
117 SBGL_Scancode code = win32_vk_to_scancode(wparam);
118 if (code < SBGL_SCANCODE_MAX) input->keysDown[code] = false;
119 break;
120 }
121 case WM_MOUSEMOVE: {
122 input->mouseX = LOWORD(lparam);
123 input->mouseY = HIWORD(lparam);
124 break;
125 }
126 case WM_LBUTTONDOWN: input->mouseDown[SBGL_MOUSE_BUTTON_LEFT] = true; break;
127 case WM_LBUTTONUP: input->mouseDown[SBGL_MOUSE_BUTTON_LEFT] = false; break;
128 case WM_RBUTTONDOWN: input->mouseDown[SBGL_MOUSE_BUTTON_RIGHT] = true; break;
129 case WM_RBUTTONUP: input->mouseDown[SBGL_MOUSE_BUTTON_RIGHT] = false; break;
130 case WM_MBUTTONDOWN: input->mouseDown[SBGL_MOUSE_BUTTON_MIDDLE] = true; break;
131 case WM_MBUTTONUP: input->mouseDown[SBGL_MOUSE_BUTTON_MIDDLE] = false; break;
132 case WM_KILLFOCUS: {
133 /* Input states are cleared when the window loses focus to prevent
134 stuck keys or buttons from affecting the simulation. */
135 memset(input->keysDown, 0, sizeof(input->keysDown));
136 memset(input->mouseDown, 0, sizeof(input->mouseDown));
137 break;
138 }
139 }
140}
SBGL_Scancode
OS-independent physical scancodes.
Definition sbgl_input.h:21
@ SBGL_SCANCODE_MAX
Definition sbgl_input.h:137
@ SBGL_MOUSE_BUTTON_MIDDLE
Definition sbgl_input.h:146
@ SBGL_MOUSE_BUTTON_LEFT
Definition sbgl_input.h:144
@ SBGL_MOUSE_BUTTON_RIGHT
Definition sbgl_input.h:145
static SBGL_Scancode win32_vk_to_scancode(WPARAM wparam)
Definition input.c:4
bool mouseDown[SBGL_MOUSE_BUTTON_MAX]
Definition sbgl_input.h:168
bool keysPressed[SBGL_SCANCODE_MAX]
Definition sbgl_input.h:167
bool keysDown[SBGL_SCANCODE_MAX]
Definition sbgl_input.h:166

◆ win32_internal_update_input_states()

void win32_internal_update_input_states ( sbgl_InputState * input,
struct sbgl_Window * window )

Definition at line 142 of file input.c.

142 {
143 if (!input) return;
144
145 if (window && window->cursorLocked) {
146 // Use accumulated raw input deltas for high-precision camera control
147 input->mouseDeltaX = window->accumulatedDeltaX;
148 input->mouseDeltaY = window->accumulatedDeltaY;
149
150 // Reset accumulators for next frame
151 window->accumulatedDeltaX = 0;
152 window->accumulatedDeltaY = 0;
153
154 // Keep internal tracking in sync
155 input->_internalMouseX = input->mouseX;
156 input->_internalMouseY = input->mouseY;
157 } else {
158 // Use standard position-based delta calculation
159 input->mouseDeltaX = input->mouseX - input->_internalMouseX;
160 input->mouseDeltaY = input->mouseY - input->_internalMouseY;
161 input->_internalMouseX = input->mouseX;
162 input->_internalMouseY = input->mouseY;
163 }
164}