From d4dbb9333666a2a0c752ecee49b4f70b8e4c1371 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 11 May 2020 17:28:50 +0200 Subject: work --- src/input.h | 1 + src/platform.h | 3 +++ src/windows/platform.c | 67 +++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 56 insertions(+), 15 deletions(-) diff --git a/src/input.h b/src/input.h index 21f4df9..189df68 100644 --- a/src/input.h +++ b/src/input.h @@ -171,6 +171,7 @@ typedef struct t_mouse_input s8 left_state; s8 right_state; s8 scroll_state; + bool last_state_released; } mouse_input; typedef enum t_keyboard_input_mode diff --git a/src/platform.h b/src/platform.h index 14118d2..f7ff050 100644 --- a/src/platform.h +++ b/src/platform.h @@ -168,6 +168,7 @@ typedef enum t_window_flags FLAGS_TOPMOST = 2, FLAGS_GLOBAL_MOUSE = 4, FLAGS_HIDDEN = 8, + FLAGS_NO_TASKBAR = 16, } window_flags; // NOT IMPLEMENTED ON LINUX: USE FLAGS_NONE @@ -179,6 +180,8 @@ bool platform_window_is_valid(platform_window *window); #define platform_open_window(name, width, height, max_w, max_h, min_w, min_h) platform_open_window_ex(name,width,height,max_w,max_h,min_w,min_h, 0) platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 max_w, u16 max_h, u16 min_w, u16 min_h, s32 flags); void platform_get_focus(platform_window *window); +void platform_show_window(platform_window *window); +void platform_hide_window(platform_window *window); bool platform_set_clipboard(platform_window *window, char *buffer); bool platform_get_clipboard(platform_window *window, char *buffer); void platform_window_set_size(platform_window *window, u16 width, u16 height); diff --git a/src/windows/platform.c b/src/windows/platform.c index 3290af8..fee91c7 100644 --- a/src/windows/platform.c +++ b/src/windows/platform.c @@ -16,6 +16,7 @@ #include #include #include +#include #include //#include #include "../external/LooplessSizeMove.c" @@ -373,7 +374,7 @@ LRESULT CALLBACK main_window_callback(HWND window, UINT message, WPARAM wparam, } else if (message == WM_KILLFOCUS) { - if (current_mouse_to_handle) + if (current_mouse_to_handle && !(current_window_to_handle->flags & FLAGS_GLOBAL_MOUSE)) { current_mouse_to_handle->x = MOUSE_OFFSCREEN; current_mouse_to_handle->y = MOUSE_OFFSCREEN; @@ -415,7 +416,7 @@ LRESULT CALLBACK main_window_callback(HWND window, UINT message, WPARAM wparam, bool is_middle_down = wparam & MK_MBUTTON; u64 ev_time = platform_get_time(TIME_FULL, TIME_MILI_S); - static u64 last_ev_time = 0; + static u64 last_ev_time = 0; if (message == WM_MOUSEWHEEL) { @@ -427,20 +428,24 @@ LRESULT CALLBACK main_window_callback(HWND window, UINT message, WPARAM wparam, current_mouse_to_handle->scroll_state = SCROLL_UP; } - if (is_left_down) + if (!(current_window_to_handle->flags & FLAGS_GLOBAL_MOUSE)) { - if (ev_time - last_ev_time < 200) + if (is_left_down) { - current_mouse_to_handle->left_state |= MOUSE_DOUBLE_CLICK; + if (ev_time - last_ev_time < 200) + { + current_mouse_to_handle->left_state |= MOUSE_DOUBLE_CLICK; + } + + current_mouse_to_handle->left_state |= MOUSE_DOWN; + current_mouse_to_handle->left_state |= MOUSE_CLICK; + + current_mouse_to_handle->total_move_x = 0; + current_mouse_to_handle->total_move_y = 0; + last_ev_time = ev_time; } - - current_mouse_to_handle->left_state |= MOUSE_DOWN; - current_mouse_to_handle->left_state |= MOUSE_CLICK; - - current_mouse_to_handle->total_move_x = 0; - current_mouse_to_handle->total_move_y = 0; - last_ev_time = ev_time; } + if (is_right_down) { current_mouse_to_handle->right_state |= MOUSE_DOWN; @@ -530,6 +535,16 @@ void platform_get_focus(platform_window *window) SetFocus(window->window_handle); } +void platform_show_window(platform_window *window) +{ + ShowWindow(window->window_handle, SW_SHOW); +} + +void platform_hide_window(platform_window *window) +{ + ShowWindow(window->window_handle, SW_HIDE); +} + platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 max_w, u16 max_h, u16 min_w, u16 min_h, s32 flags) { debug_print_elapsed_title("window creation"); @@ -588,6 +603,10 @@ platform_window platform_open_window_ex(char *name, u16 width, u16 height, u16 m { style &= ~WS_VISIBLE; } + if (flags & FLAGS_NO_TASKBAR) + { + ex_style |= WS_EX_TOOLWINDOW; + } window.window_handle = CreateWindowEx(ex_style, window.window_class.lpszClassName, @@ -775,16 +794,34 @@ void platform_handle_events(platform_window *window, mouse_input *mouse, keyboar #ifndef MODE_TEST if (current_window_to_handle->has_focus || current_window_to_handle->flags & FLAGS_GLOBAL_MOUSE) { - if((GetKeyState(VK_LBUTTON) & 0x100) == 0) + if((GetAsyncKeyState(VK_LBUTTON) & 0x8000) == 0) { - current_mouse_to_handle->left_state = MOUSE_RELEASE; + if (!current_mouse_to_handle->last_state_released) + { + current_mouse_to_handle->left_state = MOUSE_RELEASE; + current_mouse_to_handle->last_state_released = true; + } + } + else + { + current_mouse_to_handle->left_state |= MOUSE_DOWN; + + if (current_mouse_to_handle->last_state_released) + { + current_mouse_to_handle->left_state |= MOUSE_CLICK; + current_mouse_to_handle->last_state_released = false; + } } RECT rec; GetWindowRect(window->window_handle, &rec); POINT p; GetCursorPos(&p); - mouse->x = p.x - rec.left - GetSystemMetrics(SM_CYSIZEFRAME); + + if (current_window_to_handle->flags & FLAGS_GLOBAL_MOUSE) + mouse->x = p.x - rec.left; + else + mouse->x = p.x - rec.left - GetSystemMetrics(SM_CYSIZEFRAME); if (current_window_to_handle->flags & FLAGS_BORDERLESS) mouse->y = p.y - rec.top; -- cgit v1.2.3-70-g09d2