From d88664ec42454842f38231aed5fbdfe621b53393 Mon Sep 17 00:00:00 2001 From: Cristian Vlasceanu Date: Thu, 28 Feb 2013 08:40:18 +0000 Subject: [PATCH] menuitemslider wrap-around and mouse wheel (http://forum.cubers.net/thread-6079-post-122565.html#pid122565). Wrap around behavior is toggled via "wrapslider" variable (default is off) git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@7262 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/menus.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/source/src/menus.cpp b/source/src/menus.cpp index 44868942..a2f130a3 100644 --- a/source/src/menus.cpp +++ b/source/src/menus.cpp @@ -562,6 +562,7 @@ struct mitemtextinput : mitemtext }; // slider item +VARP(wrapslider, 0, 0, 1); struct mitemslider : mitem { @@ -623,7 +624,12 @@ struct mitemslider : mitem void slide(bool right) { value += right ? step : -step; - value = min(max_, max(min_, value)); + if (wrapslider) + { + if (value > max_) value = min_; + if (value < min_) value = max_; + } + else value = min(max_, max(min_, value)); displaycurvalue(); if(action) { @@ -1029,6 +1035,13 @@ COMMAND(menuitemkeyinput, "ss"); COMMAND(menuitemcheckbox, "sss"); COMMAND(menuselectionbgcolor, "ssss"); +static bool iskeypressed(int key) +{ + int numkeys = 0; + Uint8* state = SDL_GetKeyState(&numkeys); + return key < numkeys && state[key] != 0; +} + bool menukey(int code, bool isdown, int unicode, SDLMod mod) { if(!curmenu) return false; @@ -1054,11 +1067,13 @@ bool menukey(int code, bool isdown, int unicode, SDLMod mod) break; case SDLK_UP: case SDL_AC_BUTTON_WHEELUP: + if(iskeypressed(SDLK_LCTRL)) return menukey(SDLK_LEFT, isdown, 0); if(!curmenu->allowinput) return false; menusel--; break; case SDLK_DOWN: case SDL_AC_BUTTON_WHEELDOWN: + if(iskeypressed(SDLK_LCTRL)) return menukey(SDLK_RIGHT, isdown, 0); if(!curmenu->allowinput) return false; menusel++; break;