summaryrefslogtreecommitdiff
path: root/src/extern/wog.c
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-07-12 01:55:45 +0800
committerchai <chaifix@163.com>2020-07-12 01:55:45 +0800
commitec7aa42781a9108901fbde7210d8285bbbeaf5fc (patch)
tree9a17690248cf855c0bb31c057f24159d4f81eafe /src/extern/wog.c
parente849a07762a2feb3f124a08d50adeed52f085d5b (diff)
*capture
Diffstat (limited to 'src/extern/wog.c')
-rw-r--r--src/extern/wog.c56
1 files changed, 41 insertions, 15 deletions
diff --git a/src/extern/wog.c b/src/extern/wog.c
index eeb38e3..4892f99 100644
--- a/src/extern/wog.c
+++ b/src/extern/wog.c
@@ -45,6 +45,7 @@ typedef struct wog_Window
#if WOG_API == WOG_GDI
wog_Surface* surface; // render buffer
#endif
+ int mouse_capture; // mouse capture count
}wog_Window;
#if WOG_API == WOG_GL
@@ -55,6 +56,24 @@ typedef struct wog_GLContext
#endif
+// A mouse capture count is used
+void wog_setMouseCapture(wog_Window* wnd)
+{
+ if (wnd->mouse_capture <= 0)
+ {
+ SetCapture(wnd->hwnd);
+ wnd->mouse_capture = 0;
+ }
+ ++wnd->mouse_capture;
+}
+
+void wog_releaseMouseCapture(wog_Window* wnd)
+{
+ --wnd->mouse_capture;
+ if (wnd->mouse_capture <= 0)
+ ReleaseCapture();
+}
+
void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
{
UINT uMsg;
@@ -115,7 +134,6 @@ void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
zero_mem(e, sizeof(wog_Event));
e->type = WOG_EMOUSEMOTION;
wog_getMouse(window, &e->pos.x, &e->pos.y);
-
return ;
}
@@ -125,7 +143,7 @@ void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
zero_mem(e, sizeof(wog_Event));
e->type = WOG_EMOUSEWHEEL;
e->wheel = zDelta > 0 ? 1 : -1;
- return ;
+ return ;
}
case WM_LBUTTONDOWN:
@@ -134,8 +152,8 @@ void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
e->type = WOG_EMOUSEBUTTONDOWN;
e->button = WOG_MOUSE_LBUTTON;
wog_getMouse(window, &e->pos.x, &e->pos.y);
- SetCapture(hWnd);
- return ;
+ wog_setMouseCapture(window);
+ return ;
}
case WM_RBUTTONDOWN:
@@ -144,8 +162,8 @@ void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
e->type = WOG_EMOUSEBUTTONDOWN;
e->button = WOG_MOUSE_RBUTTON;
wog_getMouse(window, &e->pos.x, &e->pos.y);
- SetCapture(hWnd);
- return ;
+ wog_setMouseCapture(window);
+ return ;
}
case WM_MBUTTONDOWN:
@@ -154,8 +172,8 @@ void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
e->type = WOG_EMOUSEBUTTONDOWN;
e->button = WOG_MOUSE_MIDDLE;
wog_getMouse(window, &e->pos.x, &e->pos.y);
- SetCapture(hWnd);
- return ;
+ wog_setMouseCapture(window);
+ return ;
}
case WM_LBUTTONUP:
@@ -164,7 +182,7 @@ void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
e->type = WOG_EMOUSEBUTTONUP;
e->button = WOG_MOUSE_LBUTTON;
wog_getMouse(window, &e->pos.x, &e->pos.y);
- ReleaseCapture();
+ wog_releaseMouseCapture(window);
return ;
}
@@ -174,8 +192,8 @@ void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
e->type = WOG_EMOUSEBUTTONUP;
e->button = WOG_MOUSE_RBUTTON;
wog_getMouse(window, &e->pos.x, &e->pos.y);
- ReleaseCapture();
- return ;
+ wog_releaseMouseCapture(window);
+ return ;
}
case WM_MBUTTONUP:
@@ -184,8 +202,8 @@ void wog_handleEvent(wog_Window* window, MSG* msg, wog_Event* e)
e->type = WOG_EMOUSEBUTTONUP;
e->button = WOG_MOUSE_MIDDLE;
wog_getMouse(window, &e->pos.x, &e->pos.y);
- ReleaseCapture();
- return ;
+ wog_releaseMouseCapture(window);
+ return ;
}
break;
@@ -391,6 +409,8 @@ wog_Window* wog_createWindow(const char* title, int width, int height, int x, in
return 0;
}
+ wnd->mouse_capture = 0;
+
#if WOG_API == WOG_GDI
create_surface(wnd, client_w, client_h);
#endif
@@ -684,7 +704,13 @@ void wog_setcursor(wog_Window* wnd, unsigned int cursor)
SetCursor(LoadCursor(NULL, cursor));
}
-void wog_setcursorImage(wog_Window* wnd, const char* path)
+//void wog_setcursorImage(wog_Window* wnd, const char* path)
+//{
+// SetCursor(LoadImageA(NULL, path, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE));
+// printf("wog_setcursorImage\n");
+//}
+
+void wog_setcursorImage(wog_Window* wnd, Wog_Cursor icon)
{
- SetCursor(LoadImageA(NULL, path, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE));
+ SetCursor(icon);
}