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 namespace GUI {
00029 
00030 enum {
00031     kMapCmd = 'map '
00032 };
00033 
00034 KeysDialog::KeysDialog(const Common::String &title)
00035     : GUI::Dialog("KeysDialog") {
00036 
00037     new ButtonWidget(this, "KeysDialog.Map", _("Map"), 0, kMapCmd);
00038     new ButtonWidget(this, "KeysDialog.Ok", _("OK"), 0, kOKCmd);
00039     new ButtonWidget(this, "KeysDialog.Cancel", _("Cancel"), 0, kCloseCmd);
00040 
00041     _actionsList = new ListWidget(this, "KeysDialog.List");
00042     _actionsList->setNumberingMode(kListNumberingZero);
00043 
00044     _actionTitle = new StaticTextWidget(this, "KeysDialog.Action", title);
00045     _keyMapping = new StaticTextWidget(this, "KeysDialog.Mapping", _("Select an action and click 'Map'"));
00046 
00047     _actionTitle->setFlags(WIDGET_CLEARBG);
00048     _keyMapping->setFlags(WIDGET_CLEARBG);
00049 
00050     // Get actions names
00051     ListWidget::StringArray l;
00052 
00053     for (int i = 0; i < Actions::Instance()->size(); i++)
00054         l.push_back(Actions::Instance()->actionName((ActionType)i));
00055 
00056     _actionsList->setList(l);
00057 
00058     _actionSelected = -1;
00059     Actions::Instance()->beginMapping(false);
00060 }
00061 
00062 void KeysDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00063     switch (cmd) {
00064 
00065     case kListSelectionChangedCmd:
00066         if (_actionsList->getSelected() >= 0) {
00067             Common::String selection;
00068 
00069             uint16 key = Actions::Instance()->getMapping(_actionsList->getSelected());
00070 #ifdef __SYMBIAN32__
00071             // ScummVM mappings for F1-F9 are different from SDL so remap back to sdl
00072             if (key >= Common::ASCII_F1 && key <= Common::ASCII_F9)
00073                 key = key - Common::ASCII_F1 + SDLK_F1;
00074 #endif
00075             if (key != 0)
00076                 selection = Common::String::format(_("Associated key : %s"), SDL_GetKeyName((SDLKey)key));
00077             else
00078                 selection = Common::String::format(_("Associated key : none"));
00079 
00080             _keyMapping->setLabel(selection);
00081             _keyMapping->markAsDirty();
00082         }
00083         break;
00084     case kMapCmd:
00085         if (_actionsList->getSelected() < 0) {
00086             _actionTitle->setLabel(_("Please select an action"));
00087         } else {
00088             Common::String selection;
00089 
00090             _actionSelected = _actionsList->getSelected();
00091             uint16 key = Actions::Instance()->getMapping(_actionSelected);
00092 #ifdef __SYMBIAN32__
00093             // ScummVM mappings for F1-F9 are different from SDL so remap back to sdl
00094             if (key >= Common::ASCII_F1 && key <= Common::ASCII_F9)
00095                 key = key - Common::ASCII_F1 + SDLK_F1;
00096 #endif
00097             if (key != 0)
00098                 selection = Common::String::format(_("Associated key : %s"), SDL_GetKeyName((SDLKey)key));
00099             else
00100                 selection = Common::String::format(_("Associated key : none"));
00101 
00102             _actionTitle->setLabel(_("Press the key to associate"));
00103             _keyMapping->setLabel(selection);
00104             _keyMapping->markAsDirty();
00105             Actions::Instance()->beginMapping(true);
00106             _actionsList->setEnabled(false);
00107         }
00108         _actionTitle->markAsDirty();
00109         break;
00110     case kOKCmd:
00111         Actions::Instance()->saveMapping();
00112         close();
00113         break;
00114     case kCloseCmd:
00115         Actions::Instance()->loadMapping();
00116         close();
00117         break;
00118     }
00119 }
00120 
00121 void KeysDialog::handleKeyDown(Common::KeyState state){
00122     if (!Actions::Instance()->mappingActive())
00123         Dialog::handleKeyDown(state);
00124 }
00125 
00126 void KeysDialog::handleKeyUp(Common::KeyState state) {
00127     if (Actions::Instance()->mappingActive()) {
00128         Common::String selection;
00129 
00130         Actions::Instance()->setMapping((ActionType)_actionSelected, state.ascii);
00131 
00132         if (state.ascii != 0)
00133             selection = Common::String::format(_("Associated key : %s"), SDL_GetKeyName((SDLKey) state.keycode));
00134         else
00135             selection = Common::String::format(_("Associated key : none"));
00136 
00137         _actionTitle->setLabel(_("Choose an action to map"));
00138         _keyMapping->setLabel(selection);
00139         _keyMapping->markAsDirty();
00140         _actionTitle->markAsDirty();
00141         _actionSelected = -1;
00142         _actionsList->setEnabled(true);
00143         Actions::Instance()->beginMapping(false);
00144     } else
00145         Dialog::handleKeyUp(state);
00146 }
00147 
00148 } // namespace GUI


Generated on Sat May 30 2020 05:01:05 for ResidualVM by doxygen 1.7.1
curved edge   curved edge