From 7ed7e9f755ec4b55f092b6dec90dd436ab36e83e Mon Sep 17 00:00:00 2001 From: Braden Obrzut Date: Sat, 22 Jan 2011 03:02:58 +0000 Subject: [PATCH] - Enable menu mouse navigation on SDL systems. SVN r3112 (trunk) --- src/menu/menu.cpp | 4 -- src/sdl/i_input.cpp | 82 +++++++++++++++++++++++---------------- wadsrc/static/menudef.txt | 6 +-- 3 files changed, 51 insertions(+), 41 deletions(-) diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index c8728515b..3161b68a5 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -507,11 +507,7 @@ bool M_Responder (event_t *ev) // do we want mouse input? if (ev->subtype >= EV_GUI_FirstMouseEvent && ev->subtype <= EV_GUI_LastMouseEvent) { - // FIXME: Mouse events in SDL code are mostly useless so mouse is - // disabled until that code is fixed - #ifdef _WIN32 if (!m_use_mouse) - #endif return true; } diff --git a/src/sdl/i_input.cpp b/src/sdl/i_input.cpp index 6e862e0a3..60467366e 100644 --- a/src/sdl/i_input.cpp +++ b/src/sdl/i_input.cpp @@ -299,54 +299,68 @@ void MessagePump (const SDL_Event &sev) case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: + case SDL_MOUSEMOTION: if (!GUICapture || sev.button.button == 4 || sev.button.button == 5) { - event.type = sev.type == SDL_MOUSEBUTTONDOWN ? EV_KeyDown : EV_KeyUp; - /* These button mappings work with my Gentoo system using the - * evdev driver and a Logitech MX510 mouse. Whether or not they - * carry over to other Linux systems, I have no idea, but I sure - * hope so. (Though buttons 11 and 12 are kind of useless, since - * they also trigger buttons 4 and 5.) - */ - switch (sev.button.button) + if(sev.type != SDL_MOUSEMOTION) { - case 1: event.data1 = KEY_MOUSE1; break; - case 2: event.data1 = KEY_MOUSE3; break; - case 3: event.data1 = KEY_MOUSE2; break; - case 4: event.data1 = KEY_MWHEELUP; break; - case 5: event.data1 = KEY_MWHEELDOWN; break; - case 6: event.data1 = KEY_MOUSE4; break; /* dunno; not generated by my mouse */ - case 7: event.data1 = KEY_MOUSE5; break; /* ditto */ - case 8: event.data1 = KEY_MOUSE4; break; - case 9: event.data1 = KEY_MOUSE5; break; - case 10: event.data1 = KEY_MOUSE6; break; - case 11: event.data1 = KEY_MOUSE7; break; - case 12: event.data1 = KEY_MOUSE8; break; - default: printf("SDL mouse button %s %d\n", - sev.type == SDL_MOUSEBUTTONDOWN ? "down" : "up", sev.button.button); break; - } - if (event.data1 != 0) - { - //DIKState[ActiveDIKState][event.data1] = (event.type == EV_KeyDown); - if (event.data1 == KEY_MWHEELUP || event.data1 == KEY_MWHEELDOWN) + event.type = sev.type == SDL_MOUSEBUTTONDOWN ? EV_KeyDown : EV_KeyUp; + /* These button mappings work with my Gentoo system using the + * evdev driver and a Logitech MX510 mouse. Whether or not they + * carry over to other Linux systems, I have no idea, but I sure + * hope so. (Though buttons 11 and 12 are kind of useless, since + * they also trigger buttons 4 and 5.) + */ + switch (sev.button.button) { - WheelMoved(&event); + case 1: event.data1 = KEY_MOUSE1; break; + case 2: event.data1 = KEY_MOUSE3; break; + case 3: event.data1 = KEY_MOUSE2; break; + case 4: event.data1 = KEY_MWHEELUP; break; + case 5: event.data1 = KEY_MWHEELDOWN; break; + case 6: event.data1 = KEY_MOUSE4; break; /* dunno; not generated by my mouse */ + case 7: event.data1 = KEY_MOUSE5; break; /* ditto */ + case 8: event.data1 = KEY_MOUSE4; break; + case 9: event.data1 = KEY_MOUSE5; break; + case 10: event.data1 = KEY_MOUSE6; break; + case 11: event.data1 = KEY_MOUSE7; break; + case 12: event.data1 = KEY_MOUSE8; break; + default: printf("SDL mouse button %s %d\n", + sev.type == SDL_MOUSEBUTTONDOWN ? "down" : "up", sev.button.button); break; } - else + if (event.data1 != 0) { - D_PostEvent(&event); + //DIKState[ActiveDIKState][event.data1] = (event.type == EV_KeyDown); + if (event.data1 == KEY_MWHEELUP || event.data1 == KEY_MWHEELDOWN) + { + WheelMoved(&event); + } + else + { + D_PostEvent(&event); + } } } } - else if (sev.button.button >= 1 && sev.button.button <= 3) + else if (sev.type == SDL_MOUSEMOTION || (sev.button.button >= 1 && sev.button.button <= 3)) { + int x, y; + SDL_GetMouseState (&x, &y); + + event.data1 = x; + event.data2 = y; event.type = EV_GUI_Event; - event.subtype = sev.type == SDL_MOUSEBUTTONDOWN ? EV_GUI_LButtonDown : EV_GUI_LButtonUp; - event.subtype += (sev.button.button - 1) * 3; + if(sev.type == SDL_MOUSEMOTION) + event.subtype = EV_GUI_MouseMove; + else + { + event.subtype = sev.type == SDL_MOUSEBUTTONDOWN ? EV_GUI_LButtonDown : EV_GUI_LButtonUp; + event.subtype += (sev.button.button - 1) * 3; + } D_PostEvent(&event); } break; - + case SDL_KEYDOWN: case SDL_KEYUP: if (sev.key.keysym.sym >= SDLK_LAST) diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 4ddf8dfb6..cb6844d93 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -526,10 +526,10 @@ OptionMenu "MouseOptions" { Title "MOUSE OPTIONS" Option "Enable mouse", "use_mouse", "YesNo" - IfOption(Windows) // GUI mouse not operable in SDL interface right now. + Option "Enable mouse in menus", "m_use_mouse", "MenuMouse", "use_mouse" + Option "Show back button", "m_show_backbutton", "Corners", "use_mouse" + IfOption(Windows) // No cursors on SDL right now. { - Option "Enable mouse in menus", "m_use_mouse", "MenuMouse", "use_mouse" - Option "Show back button", "m_show_backbutton", "Corners", "use_mouse" Option "Cursor", "vid_cursor", "Cursors" } StaticText ""