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

Actions.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/Actions.h"
00024 #include "gui/message.h"
00025 #include "common/config-manager.h"
00026 
00027 #ifdef _WIN32_WCE
00028     #include "backends/platform/wince/CEActionsPocket.h"
00029     #include "backends/platform/wince/CEActionsSmartphone.h"
00030     #include "backends/platform/wince/CEDevice.h"
00031 #elif defined(__SYMBIAN32__)
00032     #include "backends/platform/symbian/src/SymbianActions.h"
00033 #endif
00034 
00035 namespace GUI {
00036 
00037 Actions* Actions::Instance() {
00038     return _instance;
00039 }
00040 
00041 Actions::Actions() :
00042     _mapping_active(false), _initialized(false) {
00043 }
00044 
00045 
00046 Actions::~Actions() {
00047 }
00048 
00049 // call the correct object creator function according to the Factory Pattern
00050 void Actions::init() {
00051 #ifdef _WIN32_WCE
00052     // For WinCE: now use software + Factory pattern to create correct objects
00053     if (!CEDevice::isSmartphone())
00054         CEActionsPocket::init();
00055     else
00056         CEActionsSmartphone::init();
00057 #elif defined(__SYMBIAN32__)
00058     SymbianActions::init();
00059 #endif
00060 }
00061 
00062 void Actions::initInstanceMain(OSystem *mainSystem) {
00063     _mainSystem = mainSystem;
00064 }
00065 
00066 void Actions::initInstanceGame() {
00067     _instance->_initialized = true;
00068 }
00069 
00070 
00071 bool Actions::initialized() {
00072     return _initialized;
00073 }
00074 
00075 bool Actions::isActive(ActionType action) {
00076     return false;
00077 }
00078 
00079 bool Actions::isEnabled(ActionType action) {
00080     return _action_enabled[action];
00081 }
00082 
00083 void Actions::beginMapping(bool start) {
00084     _mapping_active = start;
00085 }
00086 
00087 bool Actions::mappingActive() {
00088     return _mapping_active;
00089 }
00090 
00091 bool Actions::performMapped(unsigned int keyCode, bool pushed) {
00092     int i;
00093 
00094     for (i = 0; i < size(); ++i) {
00095         if (_action_mapping[i] == keyCode && _action_enabled[i])
00096                 return perform((ActionType)i, pushed);
00097     }
00098 
00099     return false;
00100 }
00101 
00102 bool Actions::loadMapping() {
00103     const char *tempo;
00104     int current_version;
00105     int i;
00106     current_version = ConfMan.getInt("action_mapping_version", domain());
00107     if (current_version != version())
00108         return false;
00109     tempo = ConfMan.get("action_mapping", domain()).c_str();
00110     if (tempo && strlen(tempo)) {
00111         for (i = 0; i < size(); ++i) {
00112             char x[7];
00113             int j;
00114             memset(x, 0, sizeof(x));
00115             memcpy(x, tempo + 5 * i, 4);
00116             sscanf(x, "%x", &j);
00117             _action_mapping[i] = j;
00118         }
00119         return true;
00120     } else
00121         return false;
00122 }
00123 
00124 bool Actions::saveMapping() {
00125     char tempo[200];
00126     int i;
00127     tempo[0] = '\0';
00128     ConfMan.setInt("action_mapping_version", version(), domain());
00129     for (i = 0; i < size(); ++i) {
00130         char x[10];
00131         sprintf(x, "%.4x ", _action_mapping[i]);
00132         strcat(tempo, x);
00133     }
00134     ConfMan.set("action_mapping", tempo, domain());
00135     ConfMan.flushToDisk();
00136     return true;
00137 }
00138 
00139 unsigned int Actions::getMapping(ActionType action) {
00140     return _action_mapping[action];
00141 }
00142 
00143 
00144 void Actions::setMapping(ActionType action, unsigned int keyCode) {
00145     int i;
00146 
00147     for (i = 0; i < size(); ++i) {
00148         if (_action_mapping[i] == keyCode)
00149             _action_mapping[i] = 0;
00150     }
00151 
00152     _action_mapping[action] = keyCode;
00153 }
00154 
00155 Key& Actions::getKeyAction(ActionType action) {
00156     return _key_action[action];
00157 }
00158 
00159 Actions *Actions::_instance = NULL;
00160 
00161 
00162 } // namespace GUI


Generated on Sat Jul 13 2019 05:01:17 for ResidualVM by doxygen 1.7.1
curved edge   curved edge