From: <be...@us...> - 2011-12-17 12:01:12
|
Revision: 612 http://freesynd.svn.sourceforge.net/freesynd/?rev=612&view=rev Author: benblan Date: 2011-12-17 12:01:04 +0000 (Sat, 17 Dec 2011) Log Message: ----------- keyboard feature #1 : - unicode activation - refactoring of key management - Textfield is not functional - Buttons hotkeys definition through labels is not functional Modified Paths: -------------- freesynd/branches/trunk-r608-feature-3202739/NEWS freesynd/branches/trunk-r608-feature-3202739/README freesynd/branches/trunk-r608-feature-3202739/src/app.cpp freesynd/branches/trunk-r608-feature-3202739/src/common.h freesynd/branches/trunk-r608-feature-3202739/src/keys.h freesynd/branches/trunk-r608-feature-3202739/src/menus/briefmenu.cpp freesynd/branches/trunk-r608-feature-3202739/src/menus/confmenu.cpp freesynd/branches/trunk-r608-feature-3202739/src/menus/gameplaymenu.cpp freesynd/branches/trunk-r608-feature-3202739/src/menus/mainmenu.cpp freesynd/branches/trunk-r608-feature-3202739/src/menus/mapmenu.cpp freesynd/branches/trunk-r608-feature-3202739/src/menus/menu.cpp freesynd/branches/trunk-r608-feature-3202739/src/menus/menu.h freesynd/branches/trunk-r608-feature-3202739/src/menus/menumanager.cpp freesynd/branches/trunk-r608-feature-3202739/src/menus/researchmenu.cpp freesynd/branches/trunk-r608-feature-3202739/src/menus/widget.cpp freesynd/branches/trunk-r608-feature-3202739/src/menus/widget.h freesynd/branches/trunk-r608-feature-3202739/src/system_sdl.cpp freesynd/branches/trunk-r608-feature-3202739/src/system_sdl.h Modified: freesynd/branches/trunk-r608-feature-3202739/NEWS =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/NEWS 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/NEWS 2011-12-17 12:01:04 UTC (rev 612) @@ -24,6 +24,7 @@ inserting a '&' caracter before the letter in the button label in the language file. Works only for letters. * Menus are now created when first accessed not all once. + * In the Map menu, pressing PageUp or PageDown increases/decreases tax from 10% Known issues with this release ------------------------------ Modified: freesynd/branches/trunk-r608-feature-3202739/README =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/README 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/README 2011-12-17 12:01:04 UTC (rev 612) @@ -54,10 +54,11 @@ * Left : Puts the selector on the next mission. * Right : Puts the selector on the previous mission. * + / - : Increase / decrease tax rate on selected country by 1%. - If control key is held, the rates will change by 10%. + If control key is held while clicking with the mouse on the button , the rates will change by 10%. (Rates above 30% will downgrade the population status to rebellious and the mission will have to be played again. Rates below 30% will upgrade the population status to "very happy".) + * Page Up / Page Down : Increase / decrease tax rate on selected country by 10%. - In game: * F1 : Turns music on/off. @@ -67,6 +68,10 @@ * Ctrl + 0 : Inverts the selection. * Ctrl + Left Click : Sets a waypoint for the selected agents. * Left,Right,Up,Down : Scrolls the map. + + - Debug Mode : + * In any menu : + * Ctrl-Q : in any menu, instantly ends the application Contact ------- Modified: freesynd/branches/trunk-r608-feature-3202739/src/app.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/app.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/app.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -476,22 +476,6 @@ menus_.keyEvent(key, modKeys); return; } - - // TODO : this part is never reached because the app - // is either playing a Fli or showing a menu - // Maybe checked if menus has treated the current event - // and if not run this code -#ifdef _DEBUG - switch (key) { - case KEY_ESCAPE: - case KEY_q: - quit(); - break; - - default: - break; - } -#endif } /*! Modified: freesynd/branches/trunk-r608-feature-3202739/src/common.h =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/common.h 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/common.h 2011-12-17 12:01:04 UTC (rev 612) @@ -31,7 +31,6 @@ #include <cassert> #include "utils/singleton.h" -#include "keys.h" #include "version.h" // TODO: Add a configuration scheme to allow setting these during runtime Modified: freesynd/branches/trunk-r608-feature-3202739/src/keys.h =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/keys.h 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/keys.h 2011-12-17 12:01:04 UTC (rev 612) @@ -25,86 +25,42 @@ #ifndef KEYS_H #define KEYS_H +#include "common.h" + /*! * All available key codes. */ -enum Key { - KEY_UNKNOWN = 0, - KEY_ESCAPE = 1, - KEY_BACKSPACE = 2, - KEY_SPACE = 3, - KEY_RETURN = 4, +enum KeyFunc { + KFC_UNKNOWN = 0, + KFC_ESCAPE = 1, + KFC_BACKSPACE = 2, + KFC_RETURN = 4, - KEY_BACKQUOTE = 5, - KEY_PLUS = 6, - KEY_COMMA = 7, - KEY_MINUS = 8, - KEY_PERIOD = 9, - KEY_SLASH = 10, - // Arrows + Home/End pad - KEY_UP = 11, - KEY_DOWN = 12, - KEY_RIGHT = 13, - KEY_LEFT = 14, - KEY_INSERT = 15, - KEY_HOME = 16, - KEY_END = 17, - KEY_PAGEUP = 18, - KEY_PAGEDOWN = 19, - KEY_DELETE = 20, + KFC_UP = 11, + KFC_DOWN = 12, + KFC_RIGHT = 13, + KFC_LEFT = 14, + KFC_INSERT = 15, + KFC_HOME = 16, + KFC_END = 17, + KFC_PAGEUP = 18, + KFC_PAGEDOWN = 19, + KFC_DELETE = 20, // Function keys - KEY_F1 = 21, - KEY_F2 = 22, - KEY_F3 = 23, - KEY_F4 = 24, - KEY_F5 = 25, - KEY_F6 = 26, - KEY_F7 = 27, - KEY_F8 = 28, - KEY_F9 = 29, - KEY_F10 = 30, - KEY_F11 = 31, - KEY_F12 = 32, - - KEY_0 = 40, - KEY_1 = 41, - KEY_2 = 42, - KEY_3 = 43, - KEY_4 = 44, - KEY_5 = 45, - KEY_6 = 46, - KEY_7 = 47, - KEY_8 = 48, - KEY_9 = 49, - - KEY_a = 50, - KEY_b = 51, - KEY_c = 52, - KEY_d = 53, - KEY_e = 54, - KEY_f = 55, - KEY_g = 56, - KEY_h = 57, - KEY_i = 58, - KEY_j = 59, - KEY_k = 60, - KEY_l = 61, - KEY_m = 62, - KEY_n = 63, - KEY_o = 64, - KEY_p = 65, - KEY_q = 66, - KEY_r = 67, - KEY_s = 68, - KEY_t = 69, - KEY_u = 70, - KEY_v = 71, - KEY_w = 72, - KEY_x = 73, - KEY_y = 74, - KEY_z = 75 + KFC_F1 = 21, + KFC_F2 = 22, + KFC_F3 = 23, + KFC_F4 = 24, + KFC_F5 = 25, + KFC_F6 = 26, + KFC_F7 = 27, + KFC_F8 = 28, + KFC_F9 = 29, + KFC_F10 = 30, + KFC_F11 = 31, + KFC_F12 = 32 }; //! Valid key modifiers @@ -122,4 +78,38 @@ const int KMD_SHIFT = KMD_LSHIFT | KMD_RSHIFT; const int KMD_ALT = KMD_LALT | KMD_RALT; +/*! + * All available key codes. + */ +typedef struct Key { + KeyFunc keyFunc; + uint16 unicode; /**< translated character */ + + bool equals(Key & other) { + return (other.keyFunc == keyFunc && other.unicode == unicode); + } +} Key; + +// A list of macros to ease unicode comparisons (case insensitive) +#define isLetterA(codePoint) codePoint == 0x0061 || codePoint == 0x0041 +#define isLetterD(codePoint) codePoint == 0x0064 || codePoint == 0x0044 +#define isLetterG(codePoint) codePoint == 0x0067 || codePoint == 0x0047 +#define isLetterH(codePoint) codePoint == 0x0068 || codePoint == 0x0048 +#define isLetterQ(codePoint) codePoint == 0x0071 || codePoint == 0x0051 + +#define K_PLUS 0x002B +#define K_MINUS 0x002D +#define K_SPACE 0x0020 + +#define K_DGT_0 0x0030 +#define K_DGT_1 0x0031 +#define K_DGT_2 0x0032 +#define K_DGT_3 0x0033 +#define K_DGT_4 0x0034 +#define K_DGT_5 0x0035 +#define K_DGT_6 0x0036 +#define K_DGT_7 0x0037 +#define K_DGT_8 0x0038 +#define K_DGT_9 0x0039 + #endif Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/briefmenu.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/briefmenu.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/briefmenu.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -46,9 +46,9 @@ // Briefing scroll button nextButId_ = addImageOption(461, 316, Sprite::MSPR_RIGHT_ARROW2_D, Sprite::MSPR_RIGHT_ARROW2_L); - registerHotKey(KEY_RIGHT, nextButId_); + registerHotKey(KFC_RIGHT, nextButId_); prevButId_ = addImageOption(427, 316, Sprite::MSPR_LEFT_ARROW2_D, Sprite::MSPR_LEFT_ARROW2_L, false); - registerHotKey(KEY_LEFT, prevButId_); + registerHotKey(KFC_LEFT, prevButId_); // Accept button addOption(17, 347, 128, 25, "#MENU_ACC_BUT", FontManager::SIZE_2, MENU_SELECT); Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/confmenu.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/confmenu.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/confmenu.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -203,10 +203,10 @@ bool ConfMenu::handleUnknownKey(Key key, const int modKeys) { if (currPanel_ != PNL_MAIN) { - if (key == KEY_ESCAPE) { + if (key.keyFunc == KFC_ESCAPE) { showMainPanel(); return true; - } else if (key == KEY_RETURN) { + } else if (key.keyFunc == KFC_RETURN) { if (currPanel_ == PNL_LOGO) { toAcceptColourId_ = tempColourId_; toAcceptLogo_ = tempLogo_; Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/gameplaymenu.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/gameplaymenu.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/gameplaymenu.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -884,12 +884,12 @@ } #ifdef _DEBUG - if (key == KEY_h) { + if (isLetterH(key.unicode)) { mission_->setStatus(Mission::COMPLETED); return true; } - if (key == KEY_g) { + if (isLetterG(key.unicode)) { mission_->setStatus(Mission::FAILED); return true; } @@ -897,7 +897,7 @@ // SPACE is pressed when the mission failed or succeeded to return // to menu - if (key == KEY_SPACE) { + if (key.unicode == K_SPACE) { if (mission_->completed() || mission_->failed()) { if (mission_->completed()) { g_Session.completeSelectedBlock(); @@ -912,7 +912,7 @@ menu_manager_->gotoMenu(Menu::MENU_DEBRIEF); return true; } - } else if (key == KEY_ESCAPE) { + } else if (key.keyFunc == KFC_ESCAPE) { // Abort mission mission_->setStatus(Mission::ABORTED); // Return false so when can still go to parent menu with escape @@ -923,48 +923,48 @@ * selection and all 4 agents. Ctrl + 0 inverts selection. * Individual keys select the specified agent unless ctrl is pressed - * then they add/remove agent from current selection. */ - if (key == KEY_0 || key == KEY_BACKQUOTE) { + if (key.unicode == K_DGT_0) { /* This code is exactly the same as for clicking on "group-button" * as you can see above. */ selectAllAgents(ctrl); change = true; } - else if (key == KEY_1) { + else if (key.unicode == K_DGT_1) { if ((selectable_agents_ & (1 << 0)) != 0) { selectAgent(0, ctrl); change = true; } } - else if (key == KEY_2) { + else if (key.unicode == K_DGT_2) { if ((selectable_agents_ & (1 << 1)) != 0) { selectAgent(1, ctrl); change = true; } } - else if (key == KEY_3) { + else if (key.unicode == K_DGT_3) { if ((selectable_agents_ & (1 << 2)) != 0) { selectAgent(2, ctrl); change = true; } } - else if (key == KEY_4) { + else if (key.unicode == K_DGT_4) { if ((selectable_agents_ & (1 << 3)) != 0) { selectAgent(3, ctrl); change = true; } - } else if (key == KEY_LEFT) { // Scroll the map to the left + } else if (key.keyFunc == KFC_LEFT) { // Scroll the map to the left scroll_x_ = -SCROLL_STEP; - } else if (key == KEY_RIGHT) { // Scroll the map to the right + } else if (key.keyFunc == KFC_RIGHT) { // Scroll the map to the right scroll_x_ = SCROLL_STEP; - } else if (key == KEY_UP) { // Scroll the map to the top + } else if (key.keyFunc == KFC_UP) { // Scroll the map to the top scroll_y_ = -SCROLL_STEP; - } else if (key == KEY_DOWN) { // Scroll the map to the bottom + } else if (key.keyFunc == KFC_DOWN) { // Scroll the map to the bottom scroll_y_ = SCROLL_STEP; - } else if (key == KEY_F1) { // Music Control + } else if (key.keyFunc == KFC_F1) { // Music Control g_App.music().toggleMusic(); - } else if (key == KEY_F2) { // Sound Control + } else if (key.keyFunc == KFC_F2) { // Sound Control g_App.gameSounds().toggleSound(); - } else if (key == KEY_d) { // all agents are killed with 'd' + } else if (isLetterD(key.unicode)) { // all agents are killed with 'd' for (int i = 8; i < mission_->numPeds(); i++) mission_->ped(i)->setHealth(0); } else { Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/mainmenu.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/mainmenu.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/mainmenu.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -34,15 +34,15 @@ addStatic(0, 40, g_Screen.gameScreenWidth(), "#MAIN_TITLE", FontManager::SIZE_4, false); int id = addOption(201, 130, 300, 25, "#MAIN_CONF", FontManager::SIZE_3, MENU_CONF, true, false); - registerHotKey(KEY_F1, id); + registerHotKey(KFC_F1, id); id = addOption(201, 164, 300, 25, "#MAIN_BEGIN", FontManager::SIZE_3, MENU_MAP, true, false); - registerHotKey(KEY_F2, id); + registerHotKey(KFC_F2, id); id = addOption(201, 198, 300, 25, "#MAIN_LOAD_SAVE", FontManager::SIZE_3, MENU_LDSAVE, true, false); - registerHotKey(KEY_F3, id); + registerHotKey(KFC_F3, id); resetButId_ = addOption(201, 232, 300, 25, "#MAIN_RESET", FontManager::SIZE_3, MENU_MAIN, true, false); - registerHotKey(KEY_F4, resetButId_); + registerHotKey(KFC_F4, resetButId_); quitButId_ = addOption(201, 266, 300, 25, "#MAIN_QUIT", FontManager::SIZE_3, MENU_NO_MENU, true, false); - registerHotKey(KEY_F5, quitButId_); + registerHotKey(KFC_F5, quitButId_); } void MainMenu::handleShow() Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/mapmenu.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/mapmenu.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/mapmenu.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -128,9 +128,9 @@ // Tax cursors txtTaxPctId_ = addStatic(350, 346, "@ 30%", FontManager::SIZE_1, true); decrTaxButId_ = addImageOption(375, 346, Sprite::MSPR_TAX_DECR, Sprite::MSPR_TAX_DECR, false); - registerHotKey(KEY_MINUS, decrTaxButId_); + registerHotKey(K_MINUS, decrTaxButId_); incrTaxButId_ = addImageOption(435, 346, Sprite::MSPR_TAX_INCR, Sprite::MSPR_TAX_INCR, false); - registerHotKey(KEY_PLUS, incrTaxButId_); + registerHotKey(K_PLUS, incrTaxButId_); // 64 x 44 x 50 // Load map block informations @@ -422,15 +422,27 @@ bool MapMenu::handleUnknownKey(Key key, const int modKeys) { bool consumed = false; - if (key == KEY_0) { + if (key.unicode == K_DGT_0) { g_Session.setSelectedBlockId(0); consumed = true; - } else if (key == KEY_LEFT && (g_Session.getSelectedBlockId() > 0)) { + } else if (key.keyFunc == KFC_LEFT && (g_Session.getSelectedBlockId() > 0)) { g_Session.setSelectedBlockId(g_Session.getSelectedBlockId() - 1); consumed = true; - } else if (key == KEY_RIGHT && g_Session.getSelectedBlockId() < 49) { + } else if (key.keyFunc == KFC_RIGHT && g_Session.getSelectedBlockId() < 49) { g_Session.setSelectedBlockId(g_Session.getSelectedBlockId() + 1); consumed = true; + } else if (key.keyFunc == KFC_PAGEUP) { + // Pressing PageUp increase tax of 10 percents + Block blk = g_Session.getBlock(g_Session.getSelectedBlockId()); + if (blk.status == BLK_FINISHED) { + consumed = g_Session.addToTaxRate(10); + } + } else if (key.keyFunc == KFC_PAGEDOWN ) { + // Pressing PageDown decrease tax of 10 percents + Block blk = g_Session.getBlock(g_Session.getSelectedBlockId()); + if (blk.status == BLK_FINISHED) { + consumed = g_Session.addToTaxRate(-10); + } } if (consumed) { Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/menu.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/menu.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/menu.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -194,9 +194,9 @@ Option *pOption = new Option(this, x, y, width, height, text, getMenuFont(size), to, visible, centered, dark_widget, light_widget); actions_.push_back(pOption); - if (pOption->getHotKey() != KEY_UNKNOWN) { + if (pOption->getHotKey().keyFunc != KFC_UNKNOWN || pOption->getHotKey().unicode != 0) { // The option already has an acceleration key - registerHotKey(pOption->getHotKey(), pOption->getId()); + registerHotKey(pOption->getHotKey().unicode, pOption->getId()); } return pOption->getId(); @@ -317,14 +317,29 @@ /*! * Adds an acceleration key to the given option so it can be activated by that key. + * If id is not an existing option id, then nothing is done. + * \param code The hot key + * \param optId The option id + */ +void Menu::registerHotKey(KeyFunc code, int optId) { + Option *pOption = getOption(optId); + if (pOption) { + HotKey hc(code, 0, pOption); + hotKeys_.push_back(hc); + } +} + +/*! + * Adds an acceleration key to the given option so it can be activated by that key. * If id is not an option id, then nothing is done. - * \param key The hot key + * \param unicode The hot key * \param optId The option id */ -void Menu::registerHotKey(Key key, int optId) { +void Menu::registerHotKey(uint16 unicode, int optId) { Option *pOption = getOption(optId); if (pOption) { - hotKeys_[key] = pOption; + HotKey hc(KFC_UNKNOWN, unicode, pOption); + hotKeys_.push_back(hc); } } @@ -355,22 +370,34 @@ } // Then look for a mapped key to execute an action - if (hotKeys_.find(key) != hotKeys_.end()) { - Option *opt = hotKeys_[key]; - - if (opt->isVisible() && opt->isenabled()) { - opt->executeAction(modKeys); + for (std::list < HotKey >::iterator it = hotKeys_.begin(); + it != hotKeys_.end(); it++) { + if ((*it).key.equals(key)) { + Option *opt = (*it).pOption; + if (opt->isVisible() && opt->isenabled()) { + opt->executeAction(modKeys); + } + return; + } + } + + // Finally pass the event to the menu instance + if (!handleUnknownKey(key, modKeys)) { + // Menu has not consummed key event : + // Pressing Escape changes the current menu to its parent(like a back) + if (key.keyFunc == KFC_ESCAPE) { + menu_manager_->gotoMenu(parentId_); + return; } - return; + // In debug, allow to quit the application from anywhere + // by pressing CTRL-Q +#ifdef _DEBUG + if ((modKeys & KMD_CTRL) && isLetterQ(key.unicode)) { + g_App.quit(); + } +#endif } - - // Pressing Escape changes the current menu to its parent(like a back) - // if menu has not already consummed key event - if (!handleUnknownKey(key, modKeys) && key == KEY_ESCAPE) { - menu_manager_->gotoMenu(parentId_); - return; - } } /*! Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/menu.h =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/menu.h 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/menu.h 2011-12-17 12:01:04 UTC (rev 612) @@ -101,8 +101,10 @@ ActionWidget * getActionWidget(int buttonId); //! Returns the Option with the given id Option * getOption(int buttonId); - //! Adds a mapping between a Key and an Option - void registerHotKey(Key key, int optId); + //! Adds a mapping between a Function Key and an Option + void registerHotKey(KeyFunc key, int optId); + //! Adds a mapping between a Printable Key and an Option + void registerHotKey(uint16 unicode, int optId); void render(); //! Does common actions before leaving @@ -173,6 +175,17 @@ GameFont *gameFont(); protected: + class HotKey { + public: + HotKey(KeyFunc code, uint16 unicode, Option *pOpt) { + key.keyFunc = code; + key.unicode = unicode; + pOption = pOpt; + } + Key key; + Option *pOption; + }; + MenuManager *menu_manager_; /*! A unique id to identify this menu.*/ int id_; @@ -184,7 +197,7 @@ /*! The list of all dynamic widgets (Option).*/ std::list<ActionWidget *> actions_; /*! An association between key and option for hotkeys.*/ - std::map<Key, Option *> hotKeys_; + std::list<HotKey> hotKeys_; /*! A group of mutual exclusive ToggleAction.*/ Group group_; /*! The id of the widget that currently has focus.*/ Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/menumanager.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/menumanager.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/menumanager.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -432,20 +432,21 @@ } bool MenuManager::isPrintableKey(Key key) { - return (key >= KEY_a && key <= KEY_z) || + /*return (key >= KEY_a && key <= KEY_z) || (key >= KEY_0 && key <= KEY_9) || - (key == KEY_SPACE); + (key == KEY_SPACE);*/ + return false; } char MenuManager::getKeyAsChar(Key key) { - if (key >= KEY_a && key <= KEY_z) { + /*if (key >= KEY_a && key <= KEY_z) { return key - KEY_a + 'A'; } else if (key >= KEY_0 && key <= KEY_9) { return key - KEY_0 + '0'; } else if(key == KEY_SPACE) { return ' '; - } + }*/ - return 0; + return 'a'; } Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/researchmenu.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/researchmenu.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/researchmenu.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -72,9 +72,9 @@ fundMaxTxtId_ = addStatic(20, 143, "", FontManager::SIZE_1, true); // Search maximum incrFundId_ = addOption(16, 210, 129, 25, "#RES_INC_FUND_BUT", FontManager::SIZE_2, MENU_NO_MENU, false); - registerHotKey(KEY_PLUS, incrFundId_); + registerHotKey(K_PLUS, incrFundId_); decrFundId_ = addOption(16, 260, 129, 25, "#RES_DEC_FUND_BUT", FontManager::SIZE_2, MENU_NO_MENU, false); - registerHotKey(KEY_MINUS, decrFundId_); + registerHotKey(K_MINUS, decrFundId_); fundCurrLblId_ = addStatic(16, 242, 129, "", FontManager::SIZE_2, true); // Current Funding label searchTitleLblId_ = addStatic(158, 86, "", FontManager::SIZE_2, true); // Current search title Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/widget.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/widget.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/widget.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -152,28 +152,14 @@ } } -/*! - * Returns the Key associated with the given caracter. - * \param c a caracter between a and z. No space. - * \returns KEY_UNKNOWN if caracter is not a letter - */ -Key Option::getKeyForChar(char c) { - Key ret = KEY_UNKNOWN; - if ('a' <= c && 'z' >= c) { - ret = static_cast < Key > (KEY_a + (c - 'a')); - } else if ('A' <= c && 'Z' >= c) { - ret = static_cast < Key > (KEY_a + (c - 'A')); - } - return ret; -} - Option::Option(Menu *peer, int x, int y, int width, int height, const char *text, MenuFont *pFont, int to, bool visible, bool centered, int darkWidgetId, int lightWidgetId) : ActionWidget(peer, x, y, width, height, visible), text_(x, y, width - 4, text, pFont, false, true, centered) { to_ = to; darkWidget_ = NULL; lightWidget_ = NULL; - hotKey_ = KEY_UNKNOWN; + hotKey_.keyFunc = KFC_UNKNOWN; + hotKey_.unicode = 0; // If button label contains a '&' caracter, then the next // caracter is the acceleration key for that button @@ -183,8 +169,8 @@ if (pos != std::string::npos ) { // check if the caracter is not the last one if (pos < (lbl.size() - 1)) { - char c = lbl.at(pos + 1); - hotKey_ = getKeyForChar(c); + // TODO : retrouver le codePoint + hotKey_.unicode = 0; // remove the '&' from the string lbl.erase(pos, 1); } @@ -518,17 +504,17 @@ } bool TextField::handleKey(Key key, const int modKeys) { - if (key == KEY_LEFT) { + if (key.keyFunc == KFC_LEFT) { // Move caret to the left until start of the text if (caretPosition_ > 0) { caretPosition_--; } - } else if (key == KEY_RIGHT) { + } else if (key.keyFunc == KFC_RIGHT) { // Move caret to the right until the end of the text if (caretPosition_ < text_.getText().size()) { caretPosition_++; } - } else if (key == KEY_BACKSPACE) { + } else if (key.keyFunc == KFC_BACKSPACE) { // Erase one character before caret if (caretPosition_ > 0) { std::string str = text_.getText(); @@ -536,16 +522,16 @@ text_.setText(str.c_str()); caretPosition_--; } - } else if (key == KEY_DELETE) { + } else if (key.keyFunc == KFC_DELETE) { if (caretPosition_ < text_.getText().size()) { std::string str = text_.getText(); str.erase(caretPosition_, 1); //text_.getText().erase(caretPosition_, 1); text_.setText(str.c_str()); } - } else if (key == KEY_HOME) { + } else if (key.keyFunc == KFC_HOME) { caretPosition_ = 0; - } else if (key == KEY_END) { + } else if (key.keyFunc == KFC_END) { caretPosition_ = text_.getText().size(); } else if (MenuManager::isPrintableKey(key)) { if (text_.getText().size() < maxSize_) { Modified: freesynd/branches/trunk-r608-feature-3202739/src/menus/widget.h =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/menus/widget.h 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/menus/widget.h 2011-12-17 12:01:04 UTC (rev 612) @@ -26,6 +26,7 @@ #include <string> #include <list> +#include "keys.h" #include "gfx/fontmanager.h" #include "utils/seqmodel.h" @@ -216,8 +217,6 @@ */ class Option : public ActionWidget { public: - //! Returns the Key associated with the given caracter. - static Key getKeyForChar(char c); //! Constructs a new button. Option(Menu *peer, int x, int y, int width, int height, const char *text, MenuFont *pFont, Modified: freesynd/branches/trunk-r608-feature-3202739/src/system_sdl.cpp =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/system_sdl.cpp 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/system_sdl.cpp 2011-12-17 12:01:04 UTC (rev 612) @@ -88,6 +88,7 @@ // Keyboard init SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableUNICODE(1); // Audio initialisation if (!Audio::init()) { @@ -169,28 +170,27 @@ } /*! - * Using the keysym parameter, verify if this is a key that is - * used in the game and returns the corresponding entry in the Key enumaration. - * \ returns If key code is not valid, returns KEY_UNKNOWN. + * Using the keysym parameter, verify if the given key is a function key (ie + * a not printable key) returns the corresponding entry in the KeyFunc enumeration. + * \returns If key code is not a function key, returns KEY_UNKNOWN. */ -Key SystemSDL::checkValidKey(SDL_keysym keysym) { - Key key = KEY_UNKNOWN; +KeyFunc SystemSDL::checkKeyFunc(SDL_keysym keysym) { + KeyFunc key = KFC_UNKNOWN; switch(keysym.sym) { - case SDLK_ESCAPE: key = KEY_ESCAPE; break; - case SDLK_BACKSPACE: key = KEY_BACKSPACE; break; - case SDLK_RETURN: key = KEY_RETURN; break; - case SDLK_SPACE: key = KEY_SPACE; break; - case SDLK_BACKQUOTE: key = KEY_BACKQUOTE; break; - case SDLK_DELETE: key = KEY_DELETE; break; + case SDLK_ESCAPE: key = KFC_ESCAPE; break; + case SDLK_BACKSPACE: key = KFC_BACKSPACE; break; + case SDLK_RETURN: key = KFC_RETURN; break; + case SDLK_DELETE: key = KFC_DELETE; break; case SDLK_UP: case SDLK_DOWN: case SDLK_RIGHT: case SDLK_LEFT: + case SDLK_INSERT: case SDLK_HOME: case SDLK_END: case SDLK_PAGEUP: case SDLK_PAGEDOWN: - key = static_cast < Key > (KEY_UP + (keysym.sym - SDLK_UP)); + key = static_cast < KeyFunc > (KFC_UP + (keysym.sym - SDLK_UP)); break; case SDLK_F1: case SDLK_F2: @@ -204,31 +204,8 @@ case SDLK_F10: case SDLK_F11: case SDLK_F12: - key = static_cast < Key > (KEY_F1 + (keysym.sym - SDLK_F1)); + key = static_cast < KeyFunc > (KFC_F1 + (keysym.sym - SDLK_F1)); break; - - case SDLK_a:case SDLK_b:case SDLK_c:case SDLK_d:case SDLK_e: - case SDLK_f:case SDLK_g:case SDLK_h:case SDLK_i:case SDLK_j: - case SDLK_k:case SDLK_l:case SDLK_m:case SDLK_n:case SDLK_o: - case SDLK_p:case SDLK_q:case SDLK_r:case SDLK_s:case SDLK_t: - case SDLK_u:case SDLK_v:case SDLK_w:case SDLK_x:case SDLK_y:case SDLK_z: - key = static_cast < Key > (KEY_a + (keysym.sym - SDLK_a)); - break; - - case SDLK_0:case SDLK_1:case SDLK_2:case SDLK_3:case SDLK_4: - case SDLK_5:case SDLK_6:case SDLK_7:case SDLK_8:case SDLK_9: - key = static_cast < Key > (KEY_0 + (keysym.sym - SDLK_0)); - break; - - case SDLK_KP0:case SDLK_KP1:case SDLK_KP2:case SDLK_KP3:case SDLK_KP4: - case SDLK_KP5:case SDLK_KP6:case SDLK_KP7:case SDLK_KP8:case SDLK_KP9: - key = static_cast < Key > (KEY_0 + (keysym.sym - SDLK_KP0)); - break; - - case SDLK_PLUS:case SDLK_COMMA:case SDLK_MINUS:case SDLK_PERIOD: - case SDLK_SLASH: - key = static_cast < Key > (KEY_PLUS + (keysym.sym - SDLK_PLUS)); - break; default: // unused key break; @@ -280,19 +257,19 @@ isKeyMod = true; break; default: + // We pass the event only if it's not a allowed modifier key + // Plus, the application receives event only when key is pressed + // not released. + Key key; + key.unicode = 0; + key.keyFunc = checkKeyFunc(event.key.keysym); + if (key.keyFunc == KFC_UNKNOWN) { + key.unicode = event.key.keysym.unicode; + } + g_App.keyEvent(key, keyModState_); break; - } - - // We pass the event only if it's not a allowed modifier key - // Plus, the application receives event only when key is pressed - // not released. - if (!isKeyMod) { - Key key = checkValidKey(event.key.keysym); - if (key != KEY_UNKNOWN) { - g_App.keyEvent(key, keyModState_); - } - } - } + } // end inner bracket + } // end case SDL_KEYDOWN break; case SDL_KEYUP: { Modified: freesynd/branches/trunk-r608-feature-3202739/src/system_sdl.h =================================================================== --- freesynd/branches/trunk-r608-feature-3202739/src/system_sdl.h 2011-12-10 14:50:29 UTC (rev 611) +++ freesynd/branches/trunk-r608-feature-3202739/src/system_sdl.h 2011-12-17 12:01:04 UTC (rev 612) @@ -28,7 +28,7 @@ #include <SDL.h> -#include "common.h" +#include "keys.h" #include "system.h" //! Implementation of the System interface for SDL. @@ -73,8 +73,8 @@ //! Loads the graphic file that contains the cursor sprites. bool loadCursorSprites(); - //! Returns a Key for the given SDL key code - Key checkValidKey(SDL_keysym sym); + //! Checks if the given SDL key code maps to a function key + KeyFunc checkKeyFunc(SDL_keysym sym); protected: /*! A constant that holds the cursor icon width and height.*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |