diff --git a/include/ege.h b/include/ege.h index 133adaf..36e427f 100644 --- a/include/ege.h +++ b/include/ege.h @@ -567,6 +567,8 @@ enum key_code_e key_mouse_l = 0x01, key_mouse_r = 0x02, key_mouse_m = 0x04, + key_mouse_x1 = 0x05, + key_mouse_x2 = 0x06, key_back = 0x08, key_tab = 0x09, key_enter = 0x0d, @@ -722,9 +724,11 @@ enum mouse_msg_e enum mouse_flag_e { - mouse_flag_left = 1, - mouse_flag_right = 2, - mouse_flag_mid = 4, + mouse_flag_left = 0x001, + mouse_flag_right = 0x002, + mouse_flag_mid = 0x004, + mouse_flag_x1 = 0x008, + mouse_flag_x2 = 0x010, mouse_flag_shift = 0x100, mouse_flag_ctrl = 0x200 }; @@ -736,9 +740,13 @@ struct mouse_msg mouse_msg_e msg; unsigned int flags; int wheel; + bool is_left() const {return (flags & mouse_flag_left) != 0;} bool is_right() const {return (flags & mouse_flag_right) != 0;} bool is_mid() const {return (flags & mouse_flag_mid) != 0;} + bool is_x1() const {return (flags & mouse_flag_x1) != 0;} + bool is_x2() const {return (flags & mouse_flag_x2) != 0;} + bool is_down() const {return msg == mouse_msg_down;} bool is_up() const {return msg == mouse_msg_up;} bool is_move() const {return msg == mouse_msg_move;} @@ -753,6 +761,8 @@ struct MOUSEMSG bool mkLButton; bool mkMButton; bool mkRButton; + bool mkXButton1; + bool mkXButton2; short x; short y; short wheel; diff --git a/src/ege_head.h b/src/ege_head.h index 44c07b9..29fa864 100644 --- a/src/ege_head.h +++ b/src/ege_head.h @@ -200,7 +200,7 @@ struct _graph_setting HANDLE threadui_handle; /* 鼠标状态记录 */ - int mouse_state_l, mouse_state_m, mouse_state_r; + int mouse_state_l, mouse_state_m, mouse_state_r, mouse_state_x1, mouse_state_x2; int mouse_last_x, mouse_last_y; int mouse_lastclick_x, mouse_lastclick_y; int mouse_lastup_x, mouse_lastup_y; diff --git a/src/graphics.cpp b/src/graphics.cpp index 65e437f..25a4217 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -442,7 +442,8 @@ static void push_mouse_msg(struct _graph_setting* pg, UINT message, WPARAM wpara msg.message = message; msg.wParam = wparam; msg.lParam = lparam; - msg.mousekey = (pg->mouse_state_m << 2) | (pg->mouse_state_r << 1) | (pg->mouse_state_l << 0); + msg.mousekey = (pg->mouse_state_m << 2) | (pg->mouse_state_r << 1) | (pg->mouse_state_l << 0) + | (pg->mouse_state_x1 << 3) | (pg->mouse_state_x1 << 4); msg.time = ::GetTickCount(); pg->msgmouse_queue->push(msg); } @@ -559,12 +560,29 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l push_mouse_msg(pg, message, wParam, lParam); } break; + case WM_XBUTTONDOWN: + case WM_XBUTTONDBLCLK: + pg->mouse_lastclick_x = (short int)((UINT)lParam & 0xFFFF); + pg->mouse_lastclick_y = (short int)((UINT)lParam >> 16); + + if ((wParam >> 16) & 0x0001) { + pg->keystatemap[VK_XBUTTON1] = 1; + } else if ((wParam >> 16) & 0x0002){ + pg->keystatemap[VK_XBUTTON2] = 1; + } + SetCapture(hWnd); + pg->mouse_state_x1 = 1; + if (hWnd == pg->hwnd) { + push_mouse_msg(pg, message, wParam, lParam); + } + break; case WM_LBUTTONUP: pg->mouse_lastup_x = (short int)((UINT)lParam & 0xFFFF); pg->mouse_lastup_y = (short int)((UINT)lParam >> 16); pg->mouse_state_l = 0; pg->keystatemap[VK_LBUTTON] = 0; - if (pg->mouse_state_l == 0 && pg->mouse_state_m == 0 && pg->mouse_state_r == 0) { + if (pg->mouse_state_l == 0 && pg->mouse_state_m == 0 && pg->mouse_state_r == 0 + && pg->mouse_state_x1 && pg->mouse_state_x2) { ReleaseCapture(); } if (hWnd == pg->hwnd) { @@ -576,7 +594,8 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l pg->mouse_lastup_y = (short int)((UINT)lParam >> 16); pg->mouse_state_m = 0; pg->keystatemap[VK_MBUTTON] = 0; - if (pg->mouse_state_l == 0 && pg->mouse_state_m == 0 && pg->mouse_state_r == 0) { + if (pg->mouse_state_l == 0 && pg->mouse_state_m == 0 && pg->mouse_state_r == 0 + && pg->mouse_state_x1 && pg->mouse_state_x2) { ReleaseCapture(); } if (hWnd == pg->hwnd) { @@ -588,7 +607,27 @@ static LRESULT CALLBACK wndproc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l pg->mouse_lastup_y = (short int)((UINT)lParam >> 16); pg->mouse_state_r = 0; pg->keystatemap[VK_RBUTTON] = 0; - if (pg->mouse_state_l == 0 && pg->mouse_state_m == 0 && pg->mouse_state_r == 0) { + if (pg->mouse_state_l == 0 && pg->mouse_state_m == 0 && pg->mouse_state_r == 0 + && pg->mouse_state_x1 && pg->mouse_state_x2) { + ReleaseCapture(); + } + if (hWnd == pg->hwnd) { + push_mouse_msg(pg, message, wParam, lParam); + } + break; + case WM_XBUTTONUP: + pg->mouse_lastup_x = (short int)((UINT)lParam & 0xFFFF); + pg->mouse_lastup_y = (short int)((UINT)lParam >> 16); + + if ((wParam >> 16) & 0x0001) { + pg->mouse_state_x1 = 0; + pg->keystatemap[VK_XBUTTON1] = 0; + } else if ((wParam >> 16) & 0x0002){ + pg->mouse_state_x2 = 0; + pg->keystatemap[VK_XBUTTON2] = 0; + } + if (pg->mouse_state_l == 0 && pg->mouse_state_m == 0 && pg->mouse_state_r == 0 + && pg->mouse_state_x1 && pg->mouse_state_x2) { ReleaseCapture(); } if (hWnd == pg->hwnd) { diff --git a/src/mouse.cpp b/src/mouse.cpp index 1d29004..898fac7 100644 --- a/src/mouse.cpp +++ b/src/mouse.cpp @@ -79,28 +79,59 @@ mouse_msg getmouse() mmsg.x = (short)((int)msg.lParam & 0xFFFF); mmsg.y = (short)((unsigned)msg.lParam >> 16); mmsg.msg = mouse_msg_move; - if (msg.message == WM_LBUTTONDOWN) { + + switch (msg.message) { + case WM_LBUTTONDOWN: mmsg.msg = mouse_msg_down; mmsg.flags |= mouse_flag_left; - } else if (msg.message == WM_RBUTTONDOWN) { - mmsg.msg = mouse_msg_down; - mmsg.flags |= mouse_flag_right; - } else if (msg.message == WM_MBUTTONDOWN) { - mmsg.msg = mouse_msg_down; - mmsg.flags |= mouse_flag_mid; - } else if (msg.message == WM_LBUTTONUP) { + break; + case WM_LBUTTONUP: mmsg.msg = mouse_msg_up; mmsg.flags |= mouse_flag_left; - } else if (msg.message == WM_RBUTTONUP) { + break; + case WM_RBUTTONDOWN: + mmsg.msg = mouse_msg_down; + mmsg.flags |= mouse_flag_right; + break; + case WM_RBUTTONUP: mmsg.msg = mouse_msg_up; mmsg.flags |= mouse_flag_right; - } else if (msg.message == WM_MBUTTONUP) { + break; + case WM_MBUTTONDOWN: + mmsg.msg = mouse_msg_down; + mmsg.flags |= mouse_flag_mid; + break; + case WM_MBUTTONUP: mmsg.msg = mouse_msg_up; mmsg.flags |= mouse_flag_mid; - } else if (msg.message == WM_MOUSEWHEEL) { + break; + case WM_MOUSEWHEEL: mmsg.msg = mouse_msg_wheel; mmsg.wheel = (short)((unsigned)msg.wParam >> 16); + break; + case WM_XBUTTONDOWN: + mmsg.msg = mouse_msg_down; + + if ((msg.wParam >> 16) & 0x0001) { + mmsg.flags |= mouse_flag_x1; + } else if ((msg.wParam >> 16) & 0x0002) { + mmsg.flags |= mouse_flag_x2; + } + + break; + case WM_XBUTTONUP: + mmsg.msg = mouse_msg_up; + + if ((msg.wParam >> 16) & 0x0001) { + mmsg.flags |= mouse_flag_x1; + } else if ((msg.wParam >> 16) & 0x0002) { + mmsg.flags |= mouse_flag_x2; + } + break; + + default:break; } + return mmsg; } } while (!pg->exit_window && !pg->exit_flag && waitdealmessage(pg)); @@ -126,15 +157,26 @@ MOUSEMSG GetMouseMsg() mmsg.mkShift = ((msg.wParam & MK_SHIFT) != 0); mmsg.x = (short)((int)msg.lParam & 0xFFFF); mmsg.y = (short)((unsigned)msg.lParam >> 16); - if (msg.mousekey & 1) { + if (msg.mousekey & 0x01) { mmsg.mkLButton = 1; } - if (msg.mousekey & 4) { + + if (msg.mousekey & 0x02) { + mmsg.mkRButton = 1; + } + + if (msg.mousekey & 0x04) { mmsg.mkMButton = 1; } - if (msg.mousekey & 2) { - mmsg.mkRButton = 1; + + if (msg.mousekey & 0x08) { + mmsg.mkXButton1 = 1; } + + if (msg.mousekey & 0x10) { + mmsg.mkXButton2 = 1; + } + if (msg.message == WM_MOUSEWHEEL) { mmsg.wheel = (short)((unsigned)msg.wParam >> 16); }