ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

KeysDialog.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "gui/KeysDialog.h"
00024 #include "gui/Actions.h"
00025 #include "common/translation.h"
00026 #include <SDL_keyboard.h>
00027 
00028 #ifdef _WIN32_WCE
00029 #include "CEDevice.h"
00030 #endif
00031 
00032 namespace GUI {
00033 
00034 enum {
00035     kMapCmd = 'map '
00036 };
00037 
00038 KeysDialog::KeysDialog(const Common::String &title)
00039     : GUI::Dialog("KeysDialog") {
00040 
00041     new ButtonWidget(this, "KeysDialog.Map", _("Map"), 0, kMapCmd);
00042     new ButtonWidget(this, "KeysDialog.Ok", _("OK"), 0, kOKCmd);
00043     new ButtonWidget(this, "KeysDialog.Cancel", _("Cancel"), 0, kCloseCmd);
00044 
00045     _actionsList = new ListWidget(this, "KeysDialog.List");
00046     _actionsList->setNumberingMode(kListNumberingZero);
00047 
00048     _actionTitle = new StaticTextWidget(this, "KeysDialog.Action", title);
00049     _keyMapping = new StaticTextWidget(this, "KeysDialog.Mapping", _("Select an action and click 'Map'"));
00050 
00051     _actionTitle->setFlags(WIDGET_CLEARBG);
00052     _keyMapping->setFlags(WIDGET_CLEARBG);
00053 
00054     // Get actions names
00055     ListWidget::StringArray l;
00056 
00057     for (int i = 0; i < Actions::Instance()->size(); i++)
00058         l.push_back(Actions::Instance()->actionName((ActionType)i));
00059 
00060     _actionsList->setList(l);
00061 
00062     _actionSelected = -1;
00063     Actions::Instance()->beginMapping(false);
00064 }
00065 
00066 void KeysDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00067     switch (cmd) {
00068 
00069     case kListSelectionChangedCmd:
00070         if (_actionsList->getSelected() >= 0) {
00071             Common::String selection;
00072 
00073             uint16 key = Actions::Instance()->getMapping(_actionsList->getSelected());
00074 #ifdef __SYMBIAN32__
00075             // ScummVM mappings for F1-F9 are different from SDL so remap back to sdl
00076             if (key >= Common::ASCII_F1 && key <= Common::ASCII_F9)
00077                 key = key - Common::ASCII_F1 + SDLK_F1;
00078 #endif
00079             if (key != 0)
00080                 selection = Common::String::format(_("Associated key : %s"), SDL_GetKeyName((SDLKey)key));
00081             else
00082                 selection = Common::String::format(_("Associated key : none"));
00083 
00084             _keyMapping->setLabel(selection);
00085             _keyMapping->markAsDirty();
00086         }
00087         break;
00088     case kMapCmd:
00089         if (_actionsList->getSelected() < 0) {
00090             _actionTitle->setLabel(_("Please select an action"));
00091         } else {
00092             Common::String selection;
00093 
00094             _actionSelected = _actionsList->getSelected();
00095             uint16 key = Actions::Instance()->getMapping(_actionSelected);
00096 #ifdef __SYMBIAN32__
00097             // ScummVM mappings for F1-F9 are different from SDL so remap back to sdl
00098             if (key >= Common::ASCII_F1 && key <= Common::ASCII_F9)
00099                 key = key - Common::ASCII_F1 + SDLK_F1;
00100 #endif
00101             if (key != 0)
00102                 selection = Common::String::format(_("Associated key : %s"), SDL_GetKeyName((SDLKey)key));
00103             else
00104                 selection = Common::String::format(_("Associated key : none"));
00105 
00106             _actionTitle->setLabel(_("Press the key to associate"));
00107             _keyMapping->setLabel(selection);
00108             _keyMapping->markAsDirty();
00109             Actions::Instance()->beginMapping(true);
00110             _actionsList->setEnabled(false);
00111         }
00112         _actionTitle->markAsDirty();
00113         break;
00114     case kOKCmd:
00115         Actions::Instance()->saveMapping();
00116         close();
00117         break;
00118     case kCloseCmd:
00119         Actions::Instance()->loadMapping();
00120         close();
00121         break;
00122     }
00123 }
00124 
00125 void KeysDialog::handleKeyDown(Common::KeyState state){
00126     if (!Actions::Instance()->mappingActive())
00127         Dialog::handleKeyDown(state);
00128 }
00129 
00130 void KeysDialog::handleKeyUp(Common::KeyState state) {
00131 #ifdef __SYMBIAN32__
00132     if (Actions::Instance()->mappingActive()) {
00133 #else
00134     if (state.flags == 0xff  && Actions::Instance()->mappingActive()) { // GAPI key was selected
00135 #endif
00136         Common::String selection;
00137 
00138         Actions::Instance()->setMapping((ActionType)_actionSelected, state.ascii);
00139 
00140         if (state.ascii != 0)
00141             selection = Common::String::format(_("Associated key : %s"), SDL_GetKeyName((SDLKey) state.keycode));
00142         else
00143             selection = Common::String::format(_("Associated key : none"));
00144 
00145         _actionTitle->setLabel(_("Choose an action to map"));
00146         _keyMapping->setLabel(selection);
00147         _keyMapping->markAsDirty();
00148         _actionTitle->markAsDirty();
00149         _actionSelected = -1;
00150         _actionsList->setEnabled(true);
00151         Actions::Instance()->beginMapping(false);
00152     } else
00153         Dialog::handleKeyUp(state);
00154 }
00155 
00156 } // namespace GUI


Generated on Sat Mar 23 2019 05:01:45 for ResidualVM by doxygen 1.7.1
curved edge   curved edge