diff options
author | chai <chaifix@163.com> | 2020-07-12 01:55:45 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2020-07-12 01:55:45 +0800 |
commit | ec7aa42781a9108901fbde7210d8285bbbeaf5fc (patch) | |
tree | 9a17690248cf855c0bb31c057f24159d4f81eafe /src | |
parent | e849a07762a2feb3f124a08d50adeed52f085d5b (diff) |
*capture
Diffstat (limited to 'src')
-rw-r--r-- | src/core/clip.c | 1 | ||||
-rw-r--r-- | src/extend/camera.c | 85 | ||||
-rw-r--r-- | src/extern/wog.c | 56 | ||||
-rw-r--r-- | src/extern/wog.h | 6 | ||||
-rw-r--r-- | src/main.c | 3 |
5 files changed, 114 insertions, 37 deletions
diff --git a/src/core/clip.c b/src/core/clip.c index eb42fb7..2880448 100644 --- a/src/core/clip.c +++ b/src/core/clip.c @@ -2,6 +2,7 @@ #include "shader.h" #include "../util/type.h" +// LUT static LinearInterpolator clip_interpolator[REG_TOTAL] = { ssrS_lerpnum, ssrS_lerpnum, diff --git a/src/extend/camera.c b/src/extend/camera.c index 2e66afc..016b1d5 100644 --- a/src/extend/camera.c +++ b/src/extend/camera.c @@ -4,10 +4,17 @@ typedef enum { CursorType_Arrow = 0, - CursorType_Hand = 1, - CursorType_Eye = 2 + CursorType_Hand, + CursorType_Eye, + CursorType_ZoomIn, + CursorType_ZoomOut, }CursorType; +static Wog_Cursor cursor_hand; +static Wog_Cursor cursor_eye; +static Wog_Cursor cursor_zoomIn; +static Wog_Cursor cursor_zoomOut; + // A unity editor style camera typedef struct Camera { Transform transform; @@ -30,6 +37,8 @@ typedef struct Camera { /*window*/ wog_Window* wnd; CursorType cursor; + /*wheel scroll icon*/ + float wheel_scroll; } Camera; Camera* camera_create(wog_Window* wnd, CameraConfig* config) { @@ -58,6 +67,13 @@ Camera* camera_create(wog_Window* wnd, CameraConfig* config) { cam->euler = config->euler; cam->wnd = wnd; + cam->wheel_scroll = 0; + + cursor_hand = LoadImageA(NULL, "PanView.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); + cursor_eye = LoadImageA(NULL, "OrbitView.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); + cursor_zoomIn = LoadImageA(NULL, "ZoomIn.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); + cursor_zoomOut = LoadImageA(NULL, "ZoomOut.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE); + return cam; } @@ -92,7 +108,8 @@ void camera_getprojmatrix(Camera* cam, Mat4* out) { } static void _onwheelscroll(Camera* cam, int wheel, float dt) { - Quat rot; transform_getrotation(&cam->transform, &rot); + Quat rot; + transform_getrotation(&cam->transform, &rot); Vec3 forward = {0,0,-1}; internal_quat_applytovec3(&rot, &forward, &forward); internal_vec3_scale(&forward, cam->zoom_speed * wheel * dt * (cam->speedup ? cam->speedupv : 1), &forward); @@ -131,9 +148,39 @@ static void _onmovearound(Camera* cam, float dt) { cam->is_viewdirty = TRUE; } +#define setMouseCursor(enumValue, icon)\ + if (cam->cursor != enumValue) \ + { \ + wog_setcursorImage(cam->wnd, icon); \ + cam->cursor = enumValue; \ + } + +#define setMouseArrow()\ + if (cam->cursor != CursorType_Arrow) \ + { \ + wog_setcursor(cam->wnd, IDC_ARROW); \ + cam->cursor = CursorType_Arrow; \ + } + + void camera_onevent(Camera* cam, wog_Event* e, float dt) { - if(e == NULL) return ; - if (e->type == WOG_EMOUSEWHEEL) {//zoom in\zoom out + if(e == NULL || e->type == WOG_EUNKNOWN) + return ; + if(e->type == WOG_EMOUSEMOTION) + return ; + //printf("%d\n",e->type); + if (e->type == WOG_EMOUSEWHEEL) { + if (e->wheel > 0) + { + setMouseCursor(CursorType_ZoomIn, cursor_zoomIn); + } + else if (e->wheel < 0) + { + setMouseCursor(CursorType_ZoomOut, cursor_zoomOut); + } + if(cam->wheel_scroll <= 0) + wog_setMouseCapture(cam->wnd); + cam->wheel_scroll = 0.3; _onwheelscroll(cam, e->wheel, dt); } else if (e->type == WOG_EMOUSEBUTTONDOWN) { @@ -141,21 +188,13 @@ void camera_onevent(Camera* cam, wog_Event* e, float dt) { cam->look_around = TRUE; cam->mouse_prev.x = e->pos.x; cam->mouse_prev.y = e->pos.y; - if (cam->cursor != CursorType_Eye) - { - wog_setcursorImage(cam->wnd, "OrbitView.ico"); - cam->cursor = CursorType_Eye; - } + setMouseCursor(CursorType_Eye, cursor_eye); } if (!cam->move_around && e->button == WOG_MOUSE_MIDDLE) { cam->move_around = TRUE; cam->mouse_prev.x = e->pos.x; cam->mouse_prev.y = e->pos.y; - if (cam->cursor != CursorType_Hand) - { - wog_setcursorImage(cam->wnd, "PanView.ico"); - cam->cursor = CursorType_Hand; - } + setMouseCursor(CursorType_Hand, cursor_hand); } } else if (e->type == WOG_EMOUSEBUTTONUP) { @@ -163,11 +202,7 @@ void camera_onevent(Camera* cam, wog_Event* e, float dt) { cam->look_around = FALSE; if (e->button == WOG_MOUSE_MIDDLE) cam->move_around = FALSE; - if (cam->cursor != CursorType_Arrow) - { - wog_setcursor(cam->wnd, IDC_ARROW); - cam->cursor = CursorType_Arrow; - } + setMouseArrow(); } else if (e->type == WOG_EKEYDOWN) { if (!cam->speedup && e->key == VK_SHIFT) @@ -177,9 +212,19 @@ void camera_onevent(Camera* cam, wog_Event* e, float dt) { if (e->key == VK_SHIFT) cam->speedup = FALSE; } + else + { + } } void camera_onupdate(Camera* cam, float dt) { + cam->wheel_scroll -= dt; + if (cam->wheel_scroll + dt > 0 && cam->wheel_scroll <= 0) + { + setMouseArrow(); + wog_releaseMouseCapture(cam->wnd); + } + if (cam->look_around) _onlookaround(cam, dt); if (cam->move_around) 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); } diff --git a/src/extern/wog.h b/src/extern/wog.h index 2052d07..c5e5c06 100644 --- a/src/extern/wog.h +++ b/src/extern/wog.h @@ -207,7 +207,11 @@ void wog_registerQuitCallback(wog_Callback cal); wog_Surface* wog_getsurface(wog_Window* wnd); void wog_setcursor(wog_Window* wnd, unsigned int cursor); -void wog_setcursorImage(wog_Window* wnd, const char* path); +//void wog_setcursorImage(wog_Window* wnd, const char* path); +typedef HANDLE Wog_Cursor; +void wog_setcursorImage(wog_Window* wnd, Wog_Cursor icon); +void wog_setMouseCapture(wog_Window* wnd); +void wog_releaseMouseCapture(wog_Window* wnd); #endif
\ No newline at end of file @@ -103,7 +103,8 @@ int main(int argc, char* argv[]) { wog_Event e; while (1) { /*handle events*/ - while (wog_pollEvent(wnd, &e)) { + //while (wog_pollEvent(wnd, &e)) { + if (wog_pollEvent(wnd, &e)) { camera_onevent(scene.main_camera, &e, _dt); gizmo_onevent(&e, _dt); if (e.type == WOG_ECLOSE) { |