keep mouse in window instead of setting cursor pos to center
This commit is contained in:
parent
bdd8db60c3
commit
181f8258fe
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#define PIXELS_PER_UNIT 256
|
#define PIXELS_PER_UNIT 256
|
||||||
|
|
||||||
#define GAME_FPS 50
|
#define GAME_FPS 30
|
||||||
|
|
||||||
#define USER_FRAME_LIMIT 300
|
#define USER_FRAME_LIMIT 300
|
||||||
|
|
||||||
@ -27,4 +27,4 @@
|
|||||||
#define AUDIO_ENABLED 0
|
#define AUDIO_ENABLED 0
|
||||||
#define VSYNC_ENABLED 0
|
#define VSYNC_ENABLED 0
|
||||||
|
|
||||||
#define MOUSE_SENSITIVITY 1.5
|
#define MOUSE_SENSITIVITY 1
|
||||||
|
|||||||
@ -289,6 +289,8 @@ u64 sys_window_get_internal_handle(struct sys_window *sys_window);
|
|||||||
void sys_window_cursor_set_pos(struct sys_window *sys_window, struct v2 pos);
|
void sys_window_cursor_set_pos(struct sys_window *sys_window, struct v2 pos);
|
||||||
void sys_window_cursor_show(struct sys_window *sys_window);
|
void sys_window_cursor_show(struct sys_window *sys_window);
|
||||||
void sys_window_cursor_hide(struct sys_window *sys_window);
|
void sys_window_cursor_hide(struct sys_window *sys_window);
|
||||||
|
void sys_window_cursor_enable_keep_in_window(struct sys_window *sys_window);
|
||||||
|
void sys_window_cursor_disable_keep_in_window(struct sys_window *sys_window);
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Mutex
|
* Mutex
|
||||||
|
|||||||
@ -33,10 +33,12 @@ struct win32_condition_variable {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum win32_window_cursor_set_flag {
|
enum win32_window_cursor_set_flag {
|
||||||
WIN32_WINDOW_CURSOR_SET_FLAG_NONE = 0x0,
|
WIN32_WINDOW_CURSOR_SET_FLAG_NONE = 0x0,
|
||||||
WIN32_WINDOW_CURSOR_SET_FLAG_POSITION = 0x1,
|
WIN32_WINDOW_CURSOR_SET_FLAG_POSITION = 0x1,
|
||||||
WIN32_WINDOW_CURSOR_SET_FLAG_HIDE = 0x2,
|
WIN32_WINDOW_CURSOR_SET_FLAG_HIDE = 0x2,
|
||||||
WIN32_WINDOW_CURSOR_SET_FLAG_SHOW = 0x4
|
WIN32_WINDOW_CURSOR_SET_FLAG_SHOW = 0x4,
|
||||||
|
WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_KEEP_IN_WINDOW = 0X8,
|
||||||
|
WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_KEEP_IN_WINDOW = 0X10
|
||||||
};
|
};
|
||||||
|
|
||||||
struct win32_window {
|
struct win32_window {
|
||||||
@ -597,6 +599,22 @@ INTERNAL void window_thread_entry_point(void *arg)
|
|||||||
SetCursorPos(p.x, p.y);
|
SetCursorPos(p.x, p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Stop keep in window */
|
||||||
|
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_KEEP_IN_WINDOW) {
|
||||||
|
ClipCursor(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Start keep in window */
|
||||||
|
if (cursor_flags & WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_KEEP_IN_WINDOW) {
|
||||||
|
RECT clip = {
|
||||||
|
.left = window->x,
|
||||||
|
.right = window->x + window->width,
|
||||||
|
.top = window->y,
|
||||||
|
.bottom = window->y + window->height
|
||||||
|
};
|
||||||
|
ClipCursor(&clip);
|
||||||
|
}
|
||||||
|
|
||||||
window->cursor_set_flags = 0;
|
window->cursor_set_flags = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -865,13 +883,13 @@ INTERNAL LRESULT CALLBACK win32_window_proc(HWND hwnd, UINT msg, WPARAM wparam,
|
|||||||
case WM_RBUTTONUP:
|
case WM_RBUTTONUP:
|
||||||
case WM_XBUTTONUP: {
|
case WM_XBUTTONUP: {
|
||||||
ReleaseCapture();
|
ReleaseCapture();
|
||||||
is_release = 1;
|
is_release = true;
|
||||||
} FALLTHROUGH;
|
} FALLTHROUGH;
|
||||||
case WM_LBUTTONDOWN:
|
case WM_LBUTTONDOWN:
|
||||||
case WM_MBUTTONDOWN:
|
case WM_MBUTTONDOWN:
|
||||||
case WM_RBUTTONDOWN:
|
case WM_RBUTTONDOWN:
|
||||||
case WM_XBUTTONDOWN: {
|
case WM_XBUTTONDOWN: {
|
||||||
if(is_release == 0) {
|
if(!is_release) {
|
||||||
SetCapture(hwnd);
|
SetCapture(hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1103,6 +1121,20 @@ void sys_window_cursor_hide(struct sys_window *sys_window)
|
|||||||
win32_window_wake(window);
|
win32_window_wake(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sys_window_cursor_enable_keep_in_window(struct sys_window *sys_window)
|
||||||
|
{
|
||||||
|
struct win32_window *window = (struct win32_window *)sys_window->handle;
|
||||||
|
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_ENABLE_KEEP_IN_WINDOW;
|
||||||
|
win32_window_wake(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sys_window_cursor_disable_keep_in_window(struct sys_window *sys_window)
|
||||||
|
{
|
||||||
|
struct win32_window *window = (struct win32_window *)sys_window->handle;
|
||||||
|
window->cursor_set_flags |= WIN32_WINDOW_CURSOR_SET_FLAG_DISABLE_KEEP_IN_WINDOW;
|
||||||
|
win32_window_wake(window);
|
||||||
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
* Mutex
|
* Mutex
|
||||||
* ========================== */
|
* ========================== */
|
||||||
|
|||||||
@ -80,7 +80,7 @@ struct ttf_decode_result ttf_decode(struct arena *arena, struct buffer encoded,
|
|||||||
|
|
||||||
IDWriteFactory5 *factory = L.factory;
|
IDWriteFactory5 *factory = L.factory;
|
||||||
|
|
||||||
/* TOOD: handle errors */
|
/* TODO: handle errors */
|
||||||
HRESULT error = 0;
|
HRESULT error = 0;
|
||||||
(UNUSED)error;
|
(UNUSED)error;
|
||||||
|
|
||||||
|
|||||||
@ -447,6 +447,7 @@ INTERNAL void user_update(void)
|
|||||||
/* Update mouse pos */
|
/* Update mouse pos */
|
||||||
if (event->kind == SYS_EVENT_KIND_MOUSE_MOVE) {
|
if (event->kind == SYS_EVENT_KIND_MOUSE_MOVE) {
|
||||||
L.screen_mouse = event->mouse_position;
|
L.screen_mouse = event->mouse_position;
|
||||||
|
//L.screen_mouse_delta = v2_add(L.screen_mouse_delta, event->mouse_delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update mouse delta */
|
/* Update mouse delta */
|
||||||
@ -503,6 +504,7 @@ INTERNAL void user_update(void)
|
|||||||
|
|
||||||
if (L.debug_camera) {
|
if (L.debug_camera) {
|
||||||
sys_window_cursor_show(L.window);
|
sys_window_cursor_show(L.window);
|
||||||
|
sys_window_cursor_disable_keep_in_window(L.window);
|
||||||
|
|
||||||
/* Pan view */
|
/* Pan view */
|
||||||
if (L.bind_states[USER_BIND_KIND_PAN].is_held) {
|
if (L.bind_states[USER_BIND_KIND_PAN].is_held) {
|
||||||
@ -546,9 +548,9 @@ INTERNAL void user_update(void)
|
|||||||
L.world_view.center = v2_add(L.world_view.center, offset);
|
L.world_view.center = v2_add(L.world_view.center, offset);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Keep cursor invisible at center of screen */
|
/* Keep cursor invisible and in screen */
|
||||||
sys_window_cursor_hide(L.window);
|
sys_window_cursor_hide(L.window);
|
||||||
sys_window_cursor_set_pos(L.window, L.screen_center);
|
sys_window_cursor_enable_keep_in_window(L.window);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================== *
|
/* ========================== *
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user