aboutsummaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/Actions.cpp169
-rw-r--r--gui/Actions.h84
-rw-r--r--gui/Key.cpp61
-rw-r--r--gui/Key.h49
-rw-r--r--gui/KeysDialog.cpp174
-rw-r--r--gui/KeysDialog.h50
-rw-r--r--gui/options.cpp18
-rw-r--r--gui/options.h8
8 files changed, 600 insertions, 13 deletions
diff --git a/gui/Actions.cpp b/gui/Actions.cpp
new file mode 100644
index 0000000000..58f96e7bbb
--- /dev/null
+++ b/gui/Actions.cpp
@@ -0,0 +1,169 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2005 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
+#include "stdafx.h"
+#include "gui/Actions.h"
+#include "gui/message.h"
+#include "scumm/scumm.h"
+#include "common/config-manager.h"
+
+#ifdef _WIN32_WCE
+ #include "backends/wince/CEActionsPocket.h"
+ #include "backends/wince/CEActionsSmartphone.h"
+#elif defined(__SYMBIAN32__)
+ #include "backends/epoc/SymbianActions.h"
+#endif
+
+namespace GUI {
+
+Actions* Actions::Instance() {
+ return _instance;
+}
+
+Actions::Actions(GameDetector &detector) :
+ _detector(&detector), _mapping_active(false), _initialized(false)
+{
+}
+
+
+Actions::~Actions() {
+}
+
+// call the correct object creator function according to the Factory Pattern
+void Actions::init(GameDetector &detector) {
+#ifdef _WIN32_WCE
+ // For WinCE: now use software + Factory pattern to create correct objects
+ if (!CEDevice::hasSmartphoneResolution())
+ CEActionsPocket::init(detector);
+ else
+ CEActionsSmartphone::init(detector);
+#elif defined(__SYMBIAN32__)
+ SymbianActions::init(detector);
+#endif
+}
+
+void Actions::initInstanceMain(OSystem *mainSystem) {
+ _mainSystem = mainSystem;
+}
+
+void Actions::initInstanceGame() {
+ _instance->_initialized = true;
+}
+
+
+bool Actions::initialized() {
+ return _initialized;
+}
+
+bool Actions::isActive(ActionType action) {
+ return false;
+}
+
+bool Actions::isEnabled(ActionType action) {
+ return _action_enabled[action];
+}
+
+void Actions::beginMapping(bool start) {
+ _mapping_active = start;
+}
+
+bool Actions::mappingActive() {
+ return _mapping_active;
+}
+
+bool Actions::performMapped(unsigned int keyCode, bool pushed) {
+ int i;
+
+ for (i=0; i<size(); i++) {
+ if (_action_mapping[i] == keyCode && _action_enabled[i])
+ return perform((ActionType)i, pushed);
+ }
+
+ return false;
+}
+
+bool Actions::loadMapping() {
+ const char *tempo;
+ int current_version;
+ int i;
+ current_version = ConfMan.getInt("action_mapping_version", domain());
+ if (current_version != version())
+ return false;
+ tempo = ConfMan.get("action_mapping", domain()).c_str();
+ if (tempo && strlen(tempo)) {
+ for (i=0; i<size(); i++) {
+ char x[7];
+ int j;
+ memset(x, 0, sizeof(x));
+ memcpy(x, tempo + 5 * i, 4);
+ sscanf(x, "%x", &j);
+ _action_mapping[i] = j;
+ }
+ return true;
+ }
+ else
+ return false;
+}
+
+bool Actions::saveMapping() {
+ char tempo[200];
+ int i;
+ tempo[0] = '\0';
+ ConfMan.set("action_mapping_version", version(), domain());
+ for (i=0; i<size(); i++) {
+ char x[10];
+ sprintf(x, "%.4x ", _action_mapping[i]);
+ strcat(tempo, x);
+ }
+ ConfMan.set("action_mapping", tempo, domain());
+ ConfMan.flushToDisk();
+ return true;
+}
+
+unsigned int Actions::getMapping(ActionType action) {
+ return _action_mapping[action];
+}
+
+
+void Actions::setMapping(ActionType action, unsigned int keyCode) {
+ int i;
+
+ for (i=0; i<size(); i++) {
+ if (_action_mapping[i] == keyCode)
+ _action_mapping[i] = 0;
+ }
+
+ _action_mapping[action] = keyCode;
+}
+
+Key& Actions::getKeyAction(ActionType action)
+{
+ return _key_action[action];
+}
+
+// Game detector
+GameDetector& Actions::gameDetector(){
+ return *_detector;
+}
+Actions *Actions::_instance = NULL;
+
+
+} // namespace GUI
diff --git a/gui/Actions.h b/gui/Actions.h
new file mode 100644
index 0000000000..235312fe2c
--- /dev/null
+++ b/gui/Actions.h
@@ -0,0 +1,84 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2005 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
+#ifndef ACTIONS_H
+#define ACTIONS_H
+
+#include "common/stdafx.h"
+#include "common/scummsys.h"
+#include "common/system.h"
+#include "base/gameDetector.h"
+#include "gui/Key.h"
+namespace GUI {
+
+#define MAX_ACTIONS 20
+
+typedef int ActionType;
+
+class Actions {
+
+public:
+ static Actions* Instance();
+ static void init(GameDetector &detector);
+ virtual void initInstanceMain(OSystem *mainSystem);
+ virtual void initInstanceGame();
+ bool initialized();
+
+ // Actions
+ virtual bool perform(ActionType action, bool pushed = true) = 0;
+ bool isActive(ActionType action);
+ bool isEnabled(ActionType action);
+ virtual Common::String actionName(ActionType action) = 0;
+ virtual int size() = 0;
+
+ // Mapping
+ void beginMapping(bool start);
+ bool mappingActive();
+ bool performMapped(unsigned int keyCode, bool pushed);
+ bool loadMapping();
+ bool saveMapping();
+ unsigned int getMapping(ActionType action);
+ void setMapping(ActionType action, unsigned int keyCode);
+ Key& getKeyAction(ActionType action);
+
+ // Action domain
+ virtual Common::String domain() = 0;
+ virtual int version() = 0;
+
+ virtual ~Actions();
+
+ // Game detector
+ GameDetector& gameDetector();
+protected:
+ Actions(GameDetector &detector);
+ static Actions* _instance;
+ OSystem *_mainSystem;
+ GameDetector *_detector;
+ Key _key_action[MAX_ACTIONS + 1];
+ bool _action_enabled[MAX_ACTIONS + 1];
+ unsigned int _action_mapping[MAX_ACTIONS + 1];
+ bool _mapping_active;
+ bool _initialized;
+};
+
+} // namespace GUI
+typedef GUI::Actions GUI_Actions;
+#endif
diff --git a/gui/Key.cpp b/gui/Key.cpp
new file mode 100644
index 0000000000..46d6096e7a
--- /dev/null
+++ b/gui/Key.cpp
@@ -0,0 +1,61 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2005 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
+#include "stdafx.h"
+#include "gui/Key.h"
+
+namespace GUI {
+
+Key::Key() :
+_ascii(0), _keycode(0), _flags(0) {
+}
+
+Key::Key(int ascii, int keycode, int flags) :
+_ascii(ascii), _keycode(keycode), _flags(flags) {
+}
+
+int Key::ascii() {
+ return _ascii;
+}
+
+int Key::keycode() {
+ return _keycode;
+}
+
+int Key::flags() {
+ return _flags;
+}
+
+
+void Key::setAscii(int ascii) {
+ _ascii = ascii;
+ _keycode = ascii; // default
+}
+
+void Key::setKeycode(int keycode) {
+ _keycode = keycode;
+}
+
+void Key::setFlags(int flags) {
+ _flags = flags;
+}
+
+} // namespace GUI
diff --git a/gui/Key.h b/gui/Key.h
new file mode 100644
index 0000000000..da91d977f7
--- /dev/null
+++ b/gui/Key.h
@@ -0,0 +1,49 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2005 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
+#ifndef KEY_H
+#define KEY_H
+
+#include "common/stdafx.h"
+#include "common/scummsys.h"
+#include "common/system.h"
+
+namespace GUI {
+
+class Key {
+public:
+ Key(int ascii, int keycode = 0, int flags = 0);
+ Key();
+ void setAscii(int ascii);
+ void setKeycode(int keycode);
+ void setFlags(int flags);
+ int ascii();
+ int keycode();
+ int flags();
+private:
+ int _ascii;
+ int _keycode;
+ int _flags;
+};
+
+} // namespace GUI
+
+#endif
diff --git a/gui/KeysDialog.cpp b/gui/KeysDialog.cpp
new file mode 100644
index 0000000000..04e6d26f6b
--- /dev/null
+++ b/gui/KeysDialog.cpp
@@ -0,0 +1,174 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2005 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
+#include "stdafx.h"
+#include "gui/KeysDialog.h"
+#include "gui/Actions.h"
+#include <sdl_keyboard.h>
+
+#ifdef _WIN32_WCE
+#include "CEDevice.h"
+#endif
+
+namespace GUI {
+
+/*
+using GUI::ListWidget;
+using GUI::kListNumberingZero;
+using GUI::WIDGET_CLEARBG;
+using GUI::kListSelectionChangedCmd;
+using GUI::kCloseCmd;
+using GUI::StaticTextWidget;
+using GUI::kTextAlignCenter;
+using GUI::CommandSender;
+*/
+
+enum {
+ kMapCmd = 'map ',
+ kOKCmd = 'ok '
+};
+
+KeysDialog::KeysDialog(const Common::String &title)
+ : GUI::Dialog(30, 20, 260, 160) {
+
+ GUI::WidgetSize ws = GUI::kNormalWidgetSize;
+
+//tmp
+// addButton(this, _w - (buttonWidth + 10), _h - buttonHeight - 8, "Choose", kChooseCmd, 0, ws);
+//tmp
+ addButton(this, 160, 20, "Map", kMapCmd, 0, ws); // Map
+ addButton(this, 160, 40, "OK", kOKCmd, 0, ws); // OK
+ addButton(this, 160, 60, "Cancel", kCloseCmd, 0, ws); // Cancel
+
+ _actionsList = new ListWidget(this, 10, 20, 140, 90);
+ _actionsList->setNumberingMode(kListNumberingZero);
+
+ _actionTitle = new StaticTextWidget(this, 10, 120, 240, 16, title, kTextAlignCenter);
+ _keyMapping = new StaticTextWidget(this, 10, 140, 240, 16, "", kTextAlignCenter);
+
+ _actionTitle->setFlags(WIDGET_CLEARBG);
+ _keyMapping->setFlags(WIDGET_CLEARBG);
+
+ // Get actions names
+ Common::StringList l;
+
+ for (int i = 0; i < Actions::Instance()->size(); i++)
+ l.push_back(Actions::Instance()->actionName((ActionType)i));
+
+ _actionsList->setList(l);
+
+ _actionSelected = -1;
+ Actions::Instance()->beginMapping(false);
+}
+
+void KeysDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
+ switch(cmd) {
+
+ case kListSelectionChangedCmd:
+ if (_actionsList->getSelected() >= 0) {
+ char selection[100];
+#ifdef __SYMBIAN32__
+ uint16 key = Actions::Instance()->getMapping(_actionsList->getSelected());
+ if(key != 0)
+ sprintf(selection, "Associated key : %s", SDL_GetKeyName((SDLKey)key));
+ else
+ sprintf(selection, "Associated key : none");
+#else
+ sprintf(selection, "Associated key : %s", CEDevice::getKeyName(Actions::Instance()->getMapping((ActionType)(_actionsList->getSelected()))).c_str());
+#endif
+ _keyMapping->setLabel(selection);
+ _keyMapping->draw();
+ }
+ break;
+ case kMapCmd:
+ if (_actionsList->getSelected() < 0) {
+ _actionTitle->setLabel("Please select an action");
+ }
+ else {
+ char selection[100];
+
+ _actionSelected = _actionsList->getSelected();
+#ifdef __SYMBIAN32__
+ uint16 key = Actions::Instance()->getMapping(_actionSelected);
+ if(key != 0)
+ sprintf(selection, "Associated key : %s", SDL_GetKeyName((SDLKey)key));
+ else
+ sprintf(selection, "Associated key : none");
+#else
+ sprintf(selection, "Associated key : %s", CEDevice::getKeyName(Actions::Instance()->getMapping((ActionType)_actionSelected)).c_str());
+#endif
+ _actionTitle->setLabel("Press the key to associate");
+ _keyMapping->setLabel(selection);
+ _keyMapping->draw();
+ Actions::Instance()->beginMapping(true);
+ _actionsList->setEnabled(false);
+ }
+ _actionTitle->draw();
+ break;
+ case kOKCmd:
+ Actions::Instance()->saveMapping();
+ close();
+ break;
+ case kCloseCmd:
+ Actions::Instance()->loadMapping();
+ close();
+ break;
+ }
+}
+
+void KeysDialog::handleKeyDown(uint16 ascii, int keycode, int modifiers){
+ if (!Actions::Instance()->mappingActive()) {
+ Dialog::handleKeyDown(ascii,keycode,modifiers);
+ }
+}
+
+void KeysDialog::handleKeyUp(uint16 ascii, int keycode, int modifiers) {
+#ifdef __SYMBIAN32__
+ if (Actions::Instance()->mappingActive()) {
+#else
+ // GAPI key was selected
+ if (modifiers == 0xff && Actions::Instance()->mappingActive()) {
+#endif
+ char selection[100];
+
+ Actions::Instance()->setMapping((ActionType)_actionSelected, ascii);
+#ifdef __SYMBIAN32__
+ if(ascii != 0)
+ sprintf(selection, "Associated key : %s", SDL_GetKeyName((SDLKey)ascii));
+ else
+ sprintf(selection, "Associated key : none");
+#else
+ sprintf(selection, "Associated key : %s", CEDevice::getKeyName(Actions::Instance()->getMapping((ActionType)_actionSelected)).c_str());
+#endif
+ _actionTitle->setLabel("Choose an action to map");
+ _keyMapping->setLabel(selection);
+ _keyMapping->draw();
+ _actionTitle->draw();
+ _actionSelected = -1;
+ _actionsList->setEnabled(true);
+ Actions::Instance()->beginMapping(false);
+ }
+ else {
+ Dialog::handleKeyUp(ascii,keycode,modifiers);
+ }
+}
+
+} // namespace GUI
diff --git a/gui/KeysDialog.h b/gui/KeysDialog.h
new file mode 100644
index 0000000000..b66ea4f1ed
--- /dev/null
+++ b/gui/KeysDialog.h
@@ -0,0 +1,50 @@
+/* ScummVM - Scumm Interpreter
+ * Copyright (C) 2001-2005 The ScummVM project
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * $Header$
+ *
+ */
+
+#ifndef KEYSDIALOG_H
+#define KEYSDIALOG_H
+
+#include "gui/newgui.h"
+#include "gui/dialog.h"
+#include "gui/ListWidget.h"
+#include "common/str.h"
+
+namespace GUI {
+
+class KeysDialog : public GUI::Dialog {
+public:
+ KeysDialog(const Common::String &title = "Choose an action to map");
+
+ virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
+ virtual void handleKeyUp(uint16 ascii, int keycode, int modifiers);
+ virtual void handleKeyDown(uint16 ascii, int keycode, int modifiers);
+
+protected:
+
+ GUI::ListWidget *_actionsList;
+ GUI::StaticTextWidget *_actionTitle;
+ GUI::StaticTextWidget *_keyMapping;
+ int _actionSelected;
+};
+
+} // namespace GUI
+
+#endif
diff --git a/gui/options.cpp b/gui/options.cpp
index c800e3921a..72372e881c 100644
--- a/gui/options.cpp
+++ b/gui/options.cpp
@@ -64,7 +64,7 @@ enum {
kChooseExtraDirCmd = 'chex'
};
-#ifdef _WIN32_WCE
+#ifdef SMALL_SCREEN_DEVICE
enum {
kChooseKeyMappingCmd = 'chma'
};
@@ -122,7 +122,7 @@ void OptionsDialog::open() {
_renderModePopUp->setSelected(sel);
}
-#ifndef _WIN32_WCE
+#ifndef SMALL_SCREEN_DEVICE
// Fullscreen setting
_fullscreenCheckbox->setState(ConfMan.getBool("fullscreen", _domain));
@@ -274,7 +274,7 @@ void OptionsDialog::setGraphicSettingsState(bool enabled) {
_gfxPopUp->setEnabled(enabled);
_renderModePopUp->setEnabled(enabled);
-#ifndef _WIN32_WCE
+#ifndef SMALL_SCREEN_DEVICE
_fullscreenCheckbox->setEnabled(enabled);
_aspectCheckbox->setEnabled(enabled);
#endif
@@ -350,7 +350,7 @@ int OptionsDialog::addGraphicControls(GuiObject *boss, int yoffset, WidgetSize w
_aspectCheckbox = addCheckbox(boss, x, yoffset, "Aspect ratio correction", 0, 0, ws);
yoffset += _aspectCheckbox->getHeight();
-#ifdef _WIN32_WCE
+#ifdef SMALL_SCREEN_DEVICE
_fullscreenCheckbox->setState(TRUE);
_fullscreenCheckbox->setEnabled(FALSE);
_aspectCheckbox->setEnabled(FALSE);
@@ -556,7 +556,7 @@ GlobalOptionsDialog::GlobalOptionsDialog()
yoffset += buttonHeight + 4;
#endif
-#ifdef _WIN32_WCE
+#ifdef SMALL_SCREEN_DEVICE
addButton(tab, 5, yoffset, "Keys", kChooseKeyMappingCmd, 0, ws);
yoffset += buttonHeight + 4;
#endif
@@ -575,8 +575,8 @@ GlobalOptionsDialog::GlobalOptionsDialog()
_dirBrowser = new BrowserDialog("Select directory for savegames", true);
_fileBrowser = new BrowserDialog("Select SoundFont", false);
-#ifdef _WIN32_WCE
- _keysDialog = new CEKeysDialog();
+#ifdef SMALL_SCREEN_DEVICE
+ _keysDialog = new KeysDialog();
#endif
}
@@ -584,7 +584,7 @@ GlobalOptionsDialog::~GlobalOptionsDialog() {
delete _dirBrowser;
delete _fileBrowser;
-#ifdef _WIN32_WCE
+#ifdef SMALL_SCREEN_DEVICE
delete _keysDialog;
#endif
}
@@ -664,7 +664,7 @@ void GlobalOptionsDialog::handleCommand(CommandSender *sender, uint32 cmd, uint3
draw();
}
break;
-#ifdef _WIN32_WCE
+#ifdef SMALL_SCREEN_DEVICE
case kChooseKeyMappingCmd:
_keysDialog->runModal();
break;
diff --git a/gui/options.h b/gui/options.h
index 107c903c2f..9a35fe8d12 100644
--- a/gui/options.h
+++ b/gui/options.h
@@ -24,8 +24,8 @@
#include "gui/dialog.h"
#include "common/str.h"
-#ifdef _WIN32_WCE
-#include "backends/wince/CEKeysDialog.h"
+#ifdef SMALL_SCREEN_DEVICE
+#include "gui/KeysDialog.h"
#endif
namespace GUI {
@@ -120,8 +120,8 @@ public:
protected:
BrowserDialog *_dirBrowser;
BrowserDialog *_fileBrowser;
-#ifdef _WIN32_WCE
- CEKeysDialog *_keysDialog;
+#ifdef SMALL_SCREEN_DEVICE
+ KeysDialog *_keysDialog;
#endif
StaticTextWidget *_savePath;
StaticTextWidget *_extraPath;