aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
Diffstat (limited to 'backends')
-rw-r--r--backends/keymapper/action.cpp21
-rw-r--r--backends/keymapper/action.h8
-rw-r--r--backends/keymapper/hardware-key.h108
-rw-r--r--backends/keymapper/keymap.cpp30
-rw-r--r--backends/keymapper/keymap.h19
-rw-r--r--backends/keymapper/keymapper.cpp9
-rw-r--r--backends/keymapper/keymapper.h9
-rw-r--r--backends/keymapper/remap-dialog.cpp22
-rw-r--r--backends/keymapper/types.h1
-rw-r--r--backends/platform/sdl/graphics.cpp212
-rw-r--r--backends/platform/sdl/hardwarekeys.cpp307
-rw-r--r--backends/platform/sdl/sdl.cpp4
-rw-r--r--backends/platform/sdl/sdl.h27
13 files changed, 570 insertions, 207 deletions
diff --git a/backends/keymapper/action.cpp b/backends/keymapper/action.cpp
index 3feb593f19..4633f20df3 100644
--- a/backends/keymapper/action.cpp
+++ b/backends/keymapper/action.cpp
@@ -32,9 +32,9 @@
namespace Common {
Action::Action(Keymap *boss, const char *i, String des, ActionType typ,
- KeyType prefKey, int pri, int flg)
+ KeyType prefKey, int pri)
: _boss(boss), description(des), type(typ), preferredKey(prefKey),
- priority(pri), flags(flg), _hwKey(0) {
+ priority(pri), _hwKey(0) {
assert(i);
assert(_boss);
@@ -43,14 +43,21 @@ Action::Action(Keymap *boss, const char *i, String des, ActionType typ,
_boss->addAction(this);
}
-void Action::mapKey(const HardwareKey *key) {
+void Action::mapKey(const HardwareKey *key, byte flags) {
if (_hwKey)
+ {
_boss->unregisterMapping(this);
+ delete _hwKey;
+ }
- _hwKey = key;
-
- if (_hwKey)
- _boss->registerMapping(this, _hwKey);
+ if (key) {
+ _hwKey = new HardwareKey(*key);
+ if (flags)
+ _hwKey->key.flags = flags & _hwKey->modMask;
+ if (_hwKey)
+ _boss->registerMapping(this, _hwKey);
+ } else
+ _hwKey = NULL;
}
const HardwareKey *Action::getMappedKey() const {
diff --git a/backends/keymapper/action.h b/backends/keymapper/action.h
index 31576e2960..c78a526414 100644
--- a/backends/keymapper/action.h
+++ b/backends/keymapper/action.h
@@ -54,19 +54,17 @@ struct Action {
ActionType type;
KeyType preferredKey;
int priority;
- int group;
- int flags;
private:
/** Hardware key that is mapped to this Action */
- const HardwareKey *_hwKey;
+ HardwareKey *_hwKey;
Keymap *_boss;
public:
Action(Keymap *boss, const char *id, String des = "",
ActionType typ = kGenericActionType,
KeyType prefKey = kGenericKeyType,
- int pri = 0, int flg = 0 );
+ int pri = 0);
void addEvent(const Event &evt) {
events.push_back(evt);
@@ -105,7 +103,7 @@ public:
return _boss;
}
- void mapKey(const HardwareKey *key);
+ void mapKey(const HardwareKey *key, byte flags = 0);
const HardwareKey *getMappedKey() const;
};
diff --git a/backends/keymapper/hardware-key.h b/backends/keymapper/hardware-key.h
index 8ddeada51e..70168def2d 100644
--- a/backends/keymapper/hardware-key.h
+++ b/backends/keymapper/hardware-key.h
@@ -31,12 +31,47 @@
#ifdef ENABLE_KEYMAPPER
#include "backends/keymapper/types.h"
+#include "common/str.h"
+#include "common/keyboard.h"
+#include "common/list.h"
+#include "common/util.h"
namespace Common {
#define HWKEY_ID_SIZE (30)
+
+// Structure for describing specific key+modifier combos mapped to actions,
+// to allow for modifiers to work properly without having to define the whole
+// hardware key set an additional time for each possible modifier combination
+struct ActionKey {
+ KeyCode keycode;
+ byte flags;
+
+ ActionKey () {
+ keycode = KEYCODE_INVALID;
+ flags = 0;
+ }
+
+ ActionKey (const KeyState &key) {
+ keycode = key.keycode;
+ flags = key.flags;
+ }
+
+
+ ActionKey (KeyCode ky, byte f) {
+ keycode = ky;
+ flags = f;
+ }
+
+ bool operator ==(const ActionKey &x) const {
+ return keycode == x.keycode && flags == x.flags;
+ }
+
+};
+
+
/**
* Describes an available hardware key
*/
@@ -51,19 +86,45 @@ struct HardwareKey {
* The KeyState that is generated by the back-end
* when this hardware key is pressed.
*/
- KeyState key;
+ ActionKey key;
KeyType type;
ActionType preferredAction;
- HardwareKey(const char *i, KeyState ky = KeyState(), String desc = "",
+ // Mask of modifiers that can possibly apply to this key.
+ byte modMask;
+
+ HardwareKey(const char *i, ActionKey ky = ActionKey(), String desc = "", byte mods = ~0,
KeyType typ = kGenericKeyType, ActionType prefAct = kGenericActionType)
- : key(ky), description(desc), type(typ), preferredAction(prefAct) {
+ : key(ky), description(desc), type(typ), preferredAction(prefAct), modMask(mods) {
assert(i);
strncpy(hwKeyId, i, HWKEY_ID_SIZE);
}
};
+/**
+* Describes an available hardware modifier
+*/
+struct HardwareMod {
+ /** unique id used for saving/loading to config */
+ char hwModId[HWKEY_ID_SIZE];
+
+ /** Human readable description */
+ String description;
+
+ /**
+ * The modifier flags that are generated by the
+ * back-end when this modifier key is pressed.
+ */
+ byte modFlags;
+
+ HardwareMod(const char *i, byte mf, String desc = "")
+ : modFlags(mf), description(desc) {
+ assert(i);
+ strncpy(hwModId, i, HWKEY_ID_SIZE);
+ }
+};
+
/**
* Simple class to encapsulate a device's set of HardwareKeys.
@@ -80,6 +141,11 @@ public:
delete *it;
}
+ void addHardwareMod(HardwareMod *mod) {
+ checkForMod(mod);
+ _mods.push_back(mod);
+ }
+
void addHardwareKey(HardwareKey *key) {
checkForKey(key);
_keys.push_back(key);
@@ -95,11 +161,31 @@ public:
return 0;
}
- const HardwareKey *findHardwareKey(const KeyState& keystate) const {
+ const HardwareKey *findHardwareKey(const ActionKey& keystate) const {
List<const HardwareKey*>::const_iterator it;
for (it = _keys.begin(); it != _keys.end(); it++) {
- if ((*it)->key == keystate)
+ if ((*it)->key.keycode == keystate.keycode)
+ return (*it);
+ }
+ return 0;
+ }
+
+ const HardwareMod *findHardwareMod(const char *id) const {
+ List<const HardwareMod*>::const_iterator it;
+
+ for (it = _mods.begin(); it != _mods.end(); it++) {
+ if (strncmp((*it)->hwModId, id, HWKEY_ID_SIZE) == 0)
+ return (*it);
+ }
+ return 0;
+ }
+
+ const HardwareMod *findHardwareMod(const ActionKey& keystate) const {
+ List<const HardwareMod*>::const_iterator it;
+
+ for (it = _mods.begin(); it != _mods.end(); it++) {
+ if ((*it)->modFlags == keystate.flags)
return (*it);
}
return 0;
@@ -127,7 +213,19 @@ private:
}
}
+ void checkForMod(HardwareMod *mod) {
+ List<const HardwareMod*>::iterator it;
+
+ for (it = _mods.begin(); it != _mods.end(); it++) {
+ if (strncmp((*it)->hwModId, mod->hwModId, HWKEY_ID_SIZE) == 0)
+ error("Error adding HardwareMod '%s' - id of %s already in use!", mod->description.c_str(), mod->hwModId);
+ else if ((*it)->modFlags == mod->modFlags)
+ error("Error adding HardwareMod '%s' - modFlags already in use!", mod->description.c_str());
+ }
+ }
+
List<const HardwareKey*> _keys;
+ List<const HardwareMod*> _mods;
};
diff --git a/backends/keymapper/keymap.cpp b/backends/keymapper/keymap.cpp
index 95b64f88e7..f082640f2c 100644
--- a/backends/keymapper/keymap.cpp
+++ b/backends/keymapper/keymap.cpp
@@ -60,7 +60,7 @@ void Keymap::addAction(Action *action) {
}
void Keymap::registerMapping(Action *action, const HardwareKey *hwKey) {
- HashMap<KeyState, Action*>::iterator it;
+ HashMap<ActionKey, Action*>::iterator it;
it = _keymap.find(hwKey->key);
@@ -105,8 +105,8 @@ const Action *Keymap::findAction(const char *id) const {
return 0;
}
-Action *Keymap::getMappedAction(const KeyState& ks) const {
- HashMap<KeyState, Action*>::iterator it;
+Action *Keymap::getMappedAction(const ActionKey& ks) const {
+ HashMap<ActionKey, Action*>::iterator it;
it = _keymap.find(ks);
@@ -127,6 +127,10 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
ConfigManager::Domain::iterator it;
String prefix = KEYMAP_KEY_PREFIX + _name + "_";
+ uint32 modId = 0;
+ char hwId[HWKEY_ID_SIZE+1];
+ memset(hwId,0,HWKEY_ID_SIZE+1);
+
for (it = _configDomain->begin(); it != _configDomain->end(); it++) {
const String& key = it->_key;
@@ -145,15 +149,15 @@ void Keymap::loadMappings(const HardwareKeySet *hwKeys) {
continue;
}
- const HardwareKey *hwKey = hwKeys->findHardwareKey(it->_value.c_str());
+ sscanf(it->_value.c_str(),"%d,%s",&modId,hwId);
+ const HardwareKey *hwKey = hwKeys->findHardwareKey(hwId);
if (!hwKey) {
warning("HardwareKey with ID %s not known", it->_value.c_str());
_configDomain->erase(key);
continue;
}
-
- ua->mapKey(hwKey);
+ ua->mapKey(hwKey,modId);
}
}
@@ -171,13 +175,19 @@ void Keymap::saveMappings() {
String actId((*it)->id, (*it)->id + actIdLen);
char hwId[HWKEY_ID_SIZE+1];
-
memset(hwId, 0, HWKEY_ID_SIZE+1);
+ char modId[4];
+ memset(modId, 0, 4);
+
if ((*it)->getMappedKey()) {
memcpy(hwId, (*it)->getMappedKey()->hwKeyId, HWKEY_ID_SIZE);
+ sprintf(modId,"%d",(*it)->getMappedKey()->key.flags);
}
- _configDomain->setVal(prefix + actId, hwId);
+ String val = modId;
+ val += ',';
+ val += hwId;
+ _configDomain->setVal(prefix + actId, val);
}
}
@@ -230,7 +240,7 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
// First mapping pass:
// - Match if a key's preferred action type is the same as the action's
- // type, or vice versa.
+ // type, or vice versa.
// - Priority is given to:
// - keys that match action types over key types.
// - keys that have not been used by parent maps.
@@ -323,7 +333,7 @@ void Keymap::automaticMapping(HardwareKeySet *hwKeys) {
}
}
-Action *Keymap::getParentMappedAction(KeyState key) {
+Action *Keymap::getParentMappedAction(const ActionKey &key) {
if (_parent) {
Action *act = _parent->getMappedAction(key);
diff --git a/backends/keymapper/keymap.h b/backends/keymapper/keymap.h
index 615fd9097d..f4ad8d110d 100644
--- a/backends/keymapper/keymap.h
+++ b/backends/keymapper/keymap.h
@@ -36,6 +36,7 @@
#include "common/keyboard.h"
#include "common/list.h"
#include "backends/keymapper/action.h"
+#include "backends/keymapper/hardware-key.h"
namespace Common {
@@ -53,6 +54,17 @@ template<> struct Hash<KeyState>
}
};
+/**
+ * Hash function for ActionKey
+ */
+template<> struct Hash<ActionKey>
+ : public UnaryFunction<ActionKey, uint> {
+
+ uint operator()(const ActionKey &val) const {
+ return (uint)val.keycode | ((uint)val.flags << 24);
+ }
+};
+
class Keymap {
public:
Keymap(const String& name, Keymap *parent = 0) : _name(name), _parent(parent) {}
@@ -77,7 +89,7 @@ public:
* @param key the key that is mapped to the required Action
* @return a pointer to the Action or 0 if no
*/
- Action *getMappedAction(const KeyState& ks) const;
+ Action *getMappedAction(const ActionKey& ks) const;
void setConfigDomain(ConfigManager::Domain *dom);
@@ -90,7 +102,6 @@ public:
/**
* Save this keymap's mappings to the config manager
* @note Changes are *not* flushed to disk, to do so call ConfMan.flushToDisk()
- * @note Changes are *not* flushed to disk, to do so call ConfMan.flushToDisk()
*/
void saveMappings();
@@ -136,12 +147,12 @@ private:
void internalMapKey(Action *action, HardwareKey *hwKey);
- Action *getParentMappedAction(KeyState key);
+ Action *getParentMappedAction(const ActionKey &key);
String _name;
Keymap *_parent;
List<Action*> _actions;
- HashMap<KeyState, Action*> _keymap;
+ HashMap<ActionKey, Action*> _keymap;
ConfigManager::Domain *_configDomain;
};
diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp
index c0c454168c..704affb3fe 100644
--- a/backends/keymapper/keymapper.cpp
+++ b/backends/keymapper/keymapper.cpp
@@ -190,7 +190,6 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) {
return false;
Action *action = 0;
-
if (keyDown) {
// Search for key in active keymap stack
for (int i = _activeMaps.size() - 1; i >= 0; --i) {
@@ -205,7 +204,7 @@ bool Keymapper::mapKey(const KeyState& key, bool keyDown) {
if (action)
_keysDown[key] = action;
} else {
- HashMap<KeyState, Action*>::iterator it = _keysDown.find(key);
+ HashMap<ActionKey, Action*>::iterator it = _keysDown.find(key);
if (it != _keysDown.end()) {
action = it->_value;
@@ -268,10 +267,14 @@ void Keymapper::executeAction(const Action *action, bool keyDown) {
}
}
-const HardwareKey *Keymapper::findHardwareKey(const KeyState& key) {
+const HardwareKey *Keymapper::findHardwareKey(const ActionKey& key) {
return (_hardwareKeys) ? _hardwareKeys->findHardwareKey(key) : 0;
}
+const HardwareMod *Keymapper::findHardwareMod(const ActionKey& key) {
+ return (_hardwareKeys) ? _hardwareKeys->findHardwareMod(key) : 0;
+}
+
} // end of namespace Common
#endif // #ifdef ENABLE_KEYMAPPER
diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h
index f492882ca2..24c76fb09f 100644
--- a/backends/keymapper/keymapper.h
+++ b/backends/keymapper/keymapper.h
@@ -168,7 +168,12 @@ public:
/**
* Return a HardwareKey pointer for the given key state
*/
- const HardwareKey *findHardwareKey(const KeyState& key);
+ const HardwareKey *findHardwareKey(const ActionKey& key);
+
+ /**
+ * Return a HardwareMod pointer for the given key state
+ */
+ const HardwareMod *findHardwareMod(const ActionKey& key);
Domain& getGlobalDomain() { return _globalDomain; }
Domain& getGameDomain() { return _gameDomain; }
@@ -193,7 +198,7 @@ private:
bool _enabled;
Stack<MapRecord> _activeMaps;
- HashMap<KeyState, Action*> _keysDown;
+ HashMap<ActionKey, Action*> _keysDown;
};
diff --git a/backends/keymapper/remap-dialog.cpp b/backends/keymapper/remap-dialog.cpp
index 0440acdd0a..0a93785c08 100644
--- a/backends/keymapper/remap-dialog.cpp
+++ b/backends/keymapper/remap-dialog.cpp
@@ -240,11 +240,12 @@ void RemapDialog::handleKeyUp(Common::KeyState state) {
if (_activeRemapAction) {
const HardwareKey *hwkey = _keymapper->findHardwareKey(state);
- debug(0, "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags);
+ debug( "Key: %d, %d (%c), %x", state.keycode, state.ascii, (state.ascii ? state.ascii : ' '), state.flags);
if (hwkey) {
- _activeRemapAction->mapKey(hwkey);
+ _activeRemapAction->mapKey(hwkey,state.flags);
_activeRemapAction->getParent()->saveMappings();
+
_changes = true;
stopRemapping();
}
@@ -359,8 +360,21 @@ void RemapDialog::refreshKeymap() {
const HardwareKey *mappedKey = info.action->getMappedKey();
if (mappedKey)
- widg.keyButton->setLabel(mappedKey->description);
- else
+ {
+ Common::String description = "";
+ if (mappedKey->key.flags)
+ {
+ byte flags = mappedKey->key.flags;
+ if (flags & KBD_CTRL)
+ description += "Ctrl+";
+ if (flags & KBD_SHIFT)
+ description += "Shift+";
+ if (flags & KBD_ALT)
+ description += "Alt+";
+ }
+ description += mappedKey->description;
+ widg.keyButton->setLabel(description);
+ } else
widg.keyButton->setLabel("-");
widg.actionText->setVisible(true);
diff --git a/backends/keymapper/types.h b/backends/keymapper/types.h
index 7ad4c0e538..3cce79ee9a 100644
--- a/backends/keymapper/types.h
+++ b/backends/keymapper/types.h
@@ -43,6 +43,7 @@ enum KeyType {
kTriggerRightKeyType,
kStartKeyType,
kSelectKeyType,
+ kModiferKeyType,
/* ... */
kKeyTypeMax
diff --git a/backends/platform/sdl/graphics.cpp b/backends/platform/sdl/graphics.cpp
index f3e4ce626b..3bfe8f5c98 100644
--- a/backends/platform/sdl/graphics.cpp
+++ b/backends/platform/sdl/graphics.cpp
@@ -26,6 +26,9 @@
#include "backends/platform/sdl/sdl.h"
#include "common/mutex.h"
#include "common/util.h"
+#ifdef ENABLE_RGB_COLOR
+#include "common/list.h"
+#endif
#include "graphics/font.h"
#include "graphics/fontman.h"
#include "graphics/scaler.h"
@@ -97,6 +100,9 @@ void OSystem_SDL::beginGFXTransaction(void) {
_transactionDetails.needUpdatescreen = false;
_transactionDetails.normal1xScaler = false;
+#ifdef ENABLE_RGB_COLOR
+ _transactionDetails.formatChanged = false;
+#endif
_oldVideoMode = _videoMode;
}
@@ -120,6 +126,13 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) {
_videoMode.mode = _oldVideoMode.mode;
_videoMode.scaleFactor = _oldVideoMode.scaleFactor;
+#ifdef ENABLE_RGB_COLOR
+ } else if (_videoMode.format != _oldVideoMode.format) {
+ errors |= kTransactionFormatNotSupported;
+
+ _videoMode.format = _oldVideoMode.format;
+ _screenFormat = _videoMode.format;
+#endif
} else if (_videoMode.screenWidth != _oldVideoMode.screenWidth || _videoMode.screenHeight != _oldVideoMode.screenHeight) {
errors |= kTransactionSizeChangeFailed;
@@ -143,7 +156,11 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) {
}
}
+#ifdef ENABLE_RGB_COLOR
+ if (_transactionDetails.sizeChanged || _transactionDetails.formatChanged) {
+#else
if (_transactionDetails.sizeChanged) {
+#endif
unloadGFXMode();
if (!loadGFXMode()) {
if (_oldVideoMode.setup) {
@@ -186,12 +203,94 @@ OSystem::TransactionError OSystem_SDL::endGFXTransaction(void) {
} else if (_transactionDetails.needUpdatescreen) {
setGraphicsModeIntern();
internUpdateScreen();
- }
+ }
_transactionMode = kTransactionNone;
return (TransactionError)errors;
}
+#ifdef ENABLE_RGB_COLOR
+const Graphics::PixelFormat RGBList[] = {
+#ifdef ENABLE_32BIT
+ // RGBA8888, ARGB8888, RGB888
+ Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0),
+ Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24),
+ Graphics::PixelFormat(3, 8, 8, 8, 0, 16, 8, 0, 0),
+#endif
+ // RGB565, XRGB1555, RGB555, RGBA4444, ARGB4444
+ Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0),
+ Graphics::PixelFormat(2, 5, 5, 5, 1, 10, 5, 0, 15),
+ Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0),
+ Graphics::PixelFormat(2, 4, 4, 4, 4, 12, 8, 4, 0),
+ Graphics::PixelFormat(2, 4, 4, 4, 4, 8, 4, 0, 12)
+};
+const Graphics::PixelFormat BGRList[] = {
+#ifdef ENABLE_32BIT
+ // ABGR8888, BGRA8888, BGR888
+ Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24),
+ Graphics::PixelFormat(4, 8, 8, 8, 8, 8, 16, 24, 0),
+ Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 8, 16, 0),
+#endif
+ // BGR565, XBGR1555, BGR555, ABGR4444, BGRA4444
+ Graphics::PixelFormat(2, 5, 6, 5, 0, 0, 5, 11, 0),
+ Graphics::PixelFormat(2, 5, 5, 5, 1, 0, 5, 10, 15),
+ Graphics::PixelFormat(2, 5, 5, 5, 0, 0, 5, 10, 0),
+ Graphics::PixelFormat(2, 4, 4, 4, 4, 0, 4, 8, 12),
+ Graphics::PixelFormat(2, 4, 4, 4, 4, 4, 8, 12, 0)
+};
+
+// TODO: prioritize matching alpha masks
+Common::List<Graphics::PixelFormat> OSystem_SDL::getSupportedFormats() {
+ static Common::List<Graphics::PixelFormat> list;
+ static bool inited = false;
+
+ if (inited)
+ return list;
+
+ bool BGR = false;
+ int listLength = ARRAYSIZE(RGBList);
+
+ Graphics::PixelFormat format = Graphics::PixelFormat::createFormatCLUT8();
+ if (_hwscreen) {
+ // Get our currently set hardware format
+ format = Graphics::PixelFormat(_hwscreen->format->BytesPerPixel,
+ 8 - _hwscreen->format->Rloss, 8 - _hwscreen->format->Gloss,
+ 8 - _hwscreen->format->Bloss, 8 - _hwscreen->format->Aloss,
+ _hwscreen->format->Rshift, _hwscreen->format->Gshift,
+ _hwscreen->format->Bshift, _hwscreen->format->Ashift);
+
+ // Workaround to MacOSX SDL not providing an accurate Aloss value.
+ if (_hwscreen->format->Amask == 0)
+ format.aLoss = 8;
+
+ // Push it first, as the prefered format.
+ list.push_back(format);
+
+ if (format.bShift > format.rShift)
+ BGR = true;
+
+ // Mark that we don't need to do this any more.
+ inited = true;
+ }
+
+ for (int i = 0; i < listLength; i++) {
+ if (inited && (RGBList[i].bytesPerPixel > format.bytesPerPixel))
+ continue;
+ if (BGR) {
+ if (BGRList[i] != format)
+ list.push_back(BGRList[i]);
+ list.push_back(RGBList[i]);
+ } else {
+ if (RGBList[i] != format)
+ list.push_back(RGBList[i]);
+ list.push_back(BGRList[i]);
+ }
+ }
+ list.push_back(Graphics::PixelFormat::createFormatCLUT8());
+ return list;
+}
+#endif
+
bool OSystem_SDL::setGraphicsMode(int mode) {
Common::StackLock lock(_graphicsMutex);
@@ -340,9 +439,27 @@ int OSystem_SDL::getGraphicsMode() const {
return _videoMode.mode;
}
-void OSystem_SDL::initSize(uint w, uint h) {
+void OSystem_SDL::initSize(uint w, uint h, const Graphics::PixelFormat *format) {
assert(_transactionMode == kTransactionActive);
+#ifdef ENABLE_RGB_COLOR
+ //avoid redundant format changes
+ Graphics::PixelFormat newFormat;
+ if (!format)
+ newFormat = Graphics::PixelFormat::createFormatCLUT8();
+ else
+ newFormat = *format;
+
+ assert(newFormat.bytesPerPixel > 0);
+
+ if (newFormat != _videoMode.format)
+ {
+ _videoMode.format = newFormat;
+ _transactionDetails.formatChanged = true;
+ _screenFormat = newFormat;
+ }
+#endif
+
// Avoid redundant res changes
if ((int)w == _videoMode.screenWidth && (int)h == _videoMode.screenHeight)
return;
@@ -426,9 +543,21 @@ bool OSystem_SDL::loadGFXMode() {
//
// Create the surface that contains the 8 bit game data
//
+#ifdef ENABLE_RGB_COLOR
+ _screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight,
+ _screenFormat.bytesPerPixel << 3,
+ ((1 << _screenFormat.rBits()) - 1) << _screenFormat.rShift ,
+ ((1 << _screenFormat.gBits()) - 1) << _screenFormat.gShift ,
+ ((1 << _screenFormat.bBits()) - 1) << _screenFormat.bShift ,
+ ((1 << _screenFormat.aBits()) - 1) << _screenFormat.aShift );
+ if (_screen == NULL)
+ error("allocating _screen failed");
+
+#else
_screen = SDL_CreateRGBSurface(SDL_SWSURFACE, _videoMode.screenWidth, _videoMode.screenHeight, 8, 0, 0, 0, 0);
if (_screen == NULL)
error("allocating _screen failed");
+#endif
//
// Create the surface that contains the scaled graphics in 16 bit mode
@@ -571,8 +700,8 @@ bool OSystem_SDL::hotswapGFXMode() {
// Keep around the old _screen & _overlayscreen so we can restore the screen data
// after the mode switch.
SDL_Surface *old_screen = _screen;
- SDL_Surface *old_overlayscreen = _overlayscreen;
_screen = NULL;
+ SDL_Surface *old_overlayscreen = _overlayscreen;
_overlayscreen = NULL;
// Release the HW screen surface
@@ -878,8 +1007,19 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int
if (SDL_LockSurface(_screen) == -1)
error("SDL_LockSurface failed: %s", SDL_GetError());
+#ifdef ENABLE_RGB_COLOR
+ byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth * _screenFormat.bytesPerPixel + x * _screenFormat.bytesPerPixel;
+ if (_videoMode.screenWidth == w && pitch == w * _screenFormat.bytesPerPixel) {
+ memcpy(dst, src, h*w*_screenFormat.bytesPerPixel);
+ } else {
+ do {
+ memcpy(dst, src, w * _screenFormat.bytesPerPixel);
+ src += pitch;
+ dst += _videoMode.screenWidth * _screenFormat.bytesPerPixel;
+ } while (--h);
+ }
+#else
byte *dst = (byte *)_screen->pixels + y * _videoMode.screenWidth + x;
-
if (_videoMode.screenWidth == pitch && pitch == w) {
memcpy(dst, src, h*w);
} else {
@@ -889,6 +1029,7 @@ void OSystem_SDL::copyRectToScreen(const byte *src, int pitch, int x, int y, int
dst += _videoMode.screenWidth;
} while (--h);
}
+#endif
// Unlock the screen surface
SDL_UnlockSurface(_screen);
@@ -912,7 +1053,11 @@ Graphics::Surface *OSystem_SDL::lockScreen() {
_framebuffer.w = _screen->w;
_framebuffer.h = _screen->h;
_framebuffer.pitch = _screen->pitch;
+#ifdef ENABLE_RGB_COLOR
+ _framebuffer.bytesPerPixel = _screenFormat.bytesPerPixel;
+#else
_framebuffer.bytesPerPixel = 1;
+#endif
return &_framebuffer;
}
@@ -1096,6 +1241,11 @@ int16 OSystem_SDL::getWidth() {
void OSystem_SDL::setPalette(const byte *colors, uint start, uint num) {
assert(colors);
+#ifdef ENABLE_RGB_COLOR
+ if (_screenFormat.bytesPerPixel > 1)
+ return; //not using a paletted pixel format
+#endif
+
// Setting the palette before _screen is created is allowed - for now -
// since we don't actually set the palette until the screen is updated.
// But it could indicate a programming error, so let's warn about it.
@@ -1149,10 +1299,10 @@ void OSystem_SDL::setCursorPalette(const byte *colors, uint start, uint num) {
}
_cursorPaletteDisabled = false;
-
blitCursor();
}
+
void OSystem_SDL::setShakePos(int shake_pos) {
assert (_transactionMode == kTransactionNone);
@@ -1357,7 +1507,17 @@ void OSystem_SDL::warpMouse(int x, int y) {
}
}
-void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale) {
+void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
+#ifdef ENABLE_RGB_COLOR
+ if (!format)
+ _cursorFormat = Graphics::PixelFormat::createFormatCLUT8();
+ else if (format->bytesPerPixel <= _screenFormat.bytesPerPixel)
+ _cursorFormat = *format;
+ keycolor &= (1 << (_cursorFormat.bytesPerPixel << 3)) - 1;
+#else
+ keycolor &= 0xFF;
+#endif
+
if (w == 0 || h == 0)
return;
@@ -1391,16 +1551,26 @@ void OSystem_SDL::setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x,
}
free(_mouseData);
-
+#ifdef ENABLE_RGB_COLOR
+ _mouseData = (byte *)malloc(w * h * _cursorFormat.bytesPerPixel);
+ memcpy(_mouseData, buf, w * h * _cursorFormat.bytesPerPixel);
+#else
_mouseData = (byte *)malloc(w * h);
memcpy(_mouseData, buf, w * h);
+#endif
+
blitCursor();
}
void OSystem_SDL::blitCursor() {
byte *dstPtr;
const byte *srcPtr = _mouseData;
+#ifdef ENABLE_RGB_COLOR
+ uint32 color;
+ uint32 colormask = (1 << (_cursorFormat.bytesPerPixel << 3)) - 1;
+#else
byte color;
+#endif
int w, h, i, j;
if (!_mouseOrigSurface || !_mouseData)
@@ -1434,13 +1604,29 @@ void OSystem_SDL::blitCursor() {
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
- color = *srcPtr;
- if (color != _mouseKeyColor) { // transparent, don't draw
- *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format,
- palette[color].r, palette[color].g, palette[color].b);
+#ifdef ENABLE_RGB_COLOR
+ if (_cursorFormat.bytesPerPixel > 1) {
+ color = (*(uint32 *) srcPtr) & colormask;
+ if (color != _mouseKeyColor) { // transparent, don't draw
+ uint8 r,g,b;
+ _cursorFormat.colorToRGB(color,r,g,b);
+ *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format,
+ r, g, b);
+ }
+ dstPtr += 2;
+ srcPtr += _cursorFormat.bytesPerPixel;
+ } else {
+#endif
+ color = *srcPtr;
+ if (color != _mouseKeyColor) { // transparent, don't draw
+ *(uint16 *)dstPtr = SDL_MapRGB(_mouseOrigSurface->format,
+ palette[color].r, palette[color].g, palette[color].b);
+ }
+ dstPtr += 2;
+ srcPtr++;
+#ifdef ENABLE_RGB_COLOR
}
- dstPtr += 2;
- srcPtr++;
+#endif
}
dstPtr += _mouseOrigSurface->pitch - w * 2;
}
diff --git a/backends/platform/sdl/hardwarekeys.cpp b/backends/platform/sdl/hardwarekeys.cpp
index 1a8124bbf3..af9b0ba319 100644
--- a/backends/platform/sdl/hardwarekeys.cpp
+++ b/backends/platform/sdl/hardwarekeys.cpp
@@ -37,168 +37,178 @@ struct Key {
uint16 ascii;
const char *desc;
KeyType preferredAction;
- bool shiftable;
+ int32 modableMask;
};
static const Key keys[] = {
- {"BACKSPACE", KEYCODE_BACKSPACE, ASCII_BACKSPACE, "Backspace", kActionKeyType, false},
- {"TAB", KEYCODE_TAB, ASCII_TAB, "Tab", kActionKeyType, false},
- {"CLEAR", KEYCODE_CLEAR, 0, "Clear", kActionKeyType, false},
- {"RETURN", KEYCODE_RETURN, ASCII_RETURN, "Return", kActionKeyType, false},
- {"PAUSE", KEYCODE_PAUSE, 0, "Pause", kActionKeyType, false},
- {"ESCAPE", KEYCODE_ESCAPE, ASCII_ESCAPE, "Esc", kStartKeyType, false},
- {"SPACE", KEYCODE_SPACE, ASCII_SPACE, "Space", kActionKeyType, false},
- {"EXCLAIM", KEYCODE_EXCLAIM, '!', "!", kActionKeyType, false},
- {"QUOTEDBL", KEYCODE_QUOTEDBL, '"', "\"", kActionKeyType, false},
- {"HASH", KEYCODE_HASH, '#', "#", kActionKeyType, false},
- {"DOLLAR", KEYCODE_DOLLAR, '$', "$", kActionKeyType, false},
- {"AMPERSAND", KEYCODE_AMPERSAND, '&', "&", kActionKeyType, false},
- {"QUOTE", KEYCODE_QUOTE, '\'', "'", kActionKeyType, false},
- {"LEFTPAREN", KEYCODE_LEFTPAREN, '(', "(", kActionKeyType, false},
- {"RIGHTPAREN", KEYCODE_RIGHTPAREN, ')', ")", kActionKeyType, false},
- {"ASTERISK", KEYCODE_ASTERISK, '*', "*", kActionKeyType, false},
- {"PLUS", KEYCODE_PLUS, '+', "+", kActionKeyType, false},
- {"COMMA", KEYCODE_COMMA, ',', ",", kActionKeyType, false},
- {"MINUS", KEYCODE_MINUS, '-', "-", kActionKeyType, false},
- {"PERIOD", KEYCODE_PERIOD, '.', ".", kActionKeyType, false},
- {"SLASH", KEYCODE_SLASH, '/', "/", kActionKeyType, false},
- {"0", KEYCODE_0, '0', "0", kActionKeyType, false},
- {"1", KEYCODE_1, '1', "1", kActionKeyType, false},
- {"2", KEYCODE_2, '2', "2", kActionKeyType, false},
- {"3", KEYCODE_3, '3', "3", kActionKeyType, false},
- {"4", KEYCODE_4, '4', "4", kActionKeyType, false},
- {"5", KEYCODE_5, '5', "5", kActionKeyType, false},
- {"6", KEYCODE_6, '6', "6", kActionKeyType, false},
- {"7", KEYCODE_7, '7', "7", kActionKeyType, false},
- {"8", KEYCODE_8, '8', "8", kActionKeyType, false},
- {"9", KEYCODE_9, '9', "9", kActionKeyType, false},
- {"COLON", KEYCODE_COLON, ':', ":", kActionKeyType, false},
- {"SEMICOLON", KEYCODE_SEMICOLON, ';', ";", kActionKeyType, false},
- {"LESS", KEYCODE_LESS, '<', "<", kActionKeyType, false},
- {"EQUALS", KEYCODE_EQUALS, '=', "=", kActionKeyType, false},
- {"GREATER", KEYCODE_GREATER, '>', ">", kActionKeyType, false},
- {"QUESTION", KEYCODE_QUESTION, '?', "?", kActionKeyType, false},
- {"AT", KEYCODE_AT, '@', "@", kActionKeyType, false},
-
- {"LEFTBRACKET", KEYCODE_LEFTBRACKET, '[', "[", kActionKeyType, false},
- {"BACKSLASH", KEYCODE_BACKSLASH, '\\', "\\", kActionKeyType, false},
- {"RIGHTBRACKET", KEYCODE_RIGHTBRACKET, ']', "]", kActionKeyType, false},
- {"CARET", KEYCODE_CARET, '^', "^", kActionKeyType, false},
- {"UNDERSCORE", KEYCODE_UNDERSCORE, '_', "_", kActionKeyType, false},
- {"BACKQUOTE", KEYCODE_BACKQUOTE, '`', "`", kActionKeyType, false},
- {"a", KEYCODE_a, 'a', "a", kActionKeyType, true},
- {"b", KEYCODE_b, 'b', "b", kActionKeyType, true},
- {"c", KEYCODE_c, 'c', "c", kActionKeyType, true},
- {"d", KEYCODE_d, 'd', "d", kActionKeyType, true},
- {"e", KEYCODE_e, 'e', "e", kActionKeyType, true},
- {"f", KEYCODE_f, 'f', "f", kActionKeyType, true},
- {"g", KEYCODE_g, 'g', "g", kActionKeyType, true},
- {"h", KEYCODE_h, 'h', "h", kActionKeyType, true},
- {"i", KEYCODE_i, 'i', "i", kActionKeyType, true},
- {"j", KEYCODE_j, 'j', "j", kActionKeyType, true},
- {"k", KEYCODE_k, 'k', "k", kActionKeyType, true},
- {"l", KEYCODE_l, 'l', "l", kActionKeyType, true},
- {"m", KEYCODE_m, 'm', "m", kActionKeyType, true},
- {"n", KEYCODE_n, 'n', "n", kActionKeyType, true},
- {"o", KEYCODE_o, 'o', "o", kActionKeyType, true},
- {"p", KEYCODE_p, 'p', "p", kActionKeyType, true},
- {"q", KEYCODE_q, 'q', "q", kActionKeyType, true},
- {"r", KEYCODE_r, 'r', "r", kActionKeyType, true},
- {"s", KEYCODE_s, 's', "s", kActionKeyType, true},
- {"t", KEYCODE_t, 't', "t", kActionKeyType, true},
- {"u", KEYCODE_u, 'u', "u", kActionKeyType, true},
- {"v", KEYCODE_v, 'v', "v", kActionKeyType, true},
- {"w", KEYCODE_w, 'w', "w", kActionKeyType, true},
- {"x", KEYCODE_x, 'x', "x", kActionKeyType, true},
- {"y", KEYCODE_y, 'y', "y", kActionKeyType, true},
- {"z", KEYCODE_z, 'z', "z", kActionKeyType, true},
- {"DELETE", KEYCODE_DELETE, 0, "Del", kActionKeyType, false},
+ {"BACKSPACE", KEYCODE_BACKSPACE, ASCII_BACKSPACE, "Backspace", kActionKeyType, ~0},
+ {"TAB", KEYCODE_TAB, ASCII_TAB, "Tab", kActionKeyType, ~0},
+ {"CLEAR", KEYCODE_CLEAR, 0, "Clear", kActionKeyType, ~0},
+ {"RETURN", KEYCODE_RETURN, ASCII_RETURN, "Return", kActionKeyType, ~0},
+ {"PAUSE", KEYCODE_PAUSE, 0, "Pause", kActionKeyType, ~0},
+ {"ESCAPE", KEYCODE_ESCAPE, ASCII_ESCAPE, "Esc", kStartKeyType, ~0},
+ {"SPACE", KEYCODE_SPACE, ASCII_SPACE, "Space", kActionKeyType, ~0},
+ {"EXCLAIM", KEYCODE_EXCLAIM, '!', "!", kActionKeyType, ~0},
+ {"QUOTEDBL", KEYCODE_QUOTEDBL, '"', "\"", kActionKeyType, ~0},
+ {"HASH", KEYCODE_HASH, '#', "#", kActionKeyType, ~0},
+ {"DOLLAR", KEYCODE_DOLLAR, '$', "$", kActionKeyType, ~0},
+ {"AMPERSAND", KEYCODE_AMPERSAND, '&', "&", kActionKeyType, ~0},
+ {"QUOTE", KEYCODE_QUOTE, '\'', "'", kActionKeyType, ~0},
+ {"LEFTPAREN", KEYCODE_LEFTPAREN, '(', "(", kActionKeyType, ~0},
+ {"RIGHTPAREN", KEYCODE_RIGHTPAREN, ')', ")", kActionKeyType, ~0},
+ {"ASTERISK", KEYCODE_ASTERISK, '*', "*", kActionKeyType, ~0},
+ {"PLUS", KEYCODE_PLUS, '+', "+", kActionKeyType, ~0},
+ {"COMMA", KEYCODE_COMMA, ',', ",", kActionKeyType, ~0},
+ {"MINUS", KEYCODE_MINUS, '-', "-", kActionKeyType, ~0},
+ {"PERIOD", KEYCODE_PERIOD, '.', ".", kActionKeyType, ~0},
+ {"SLASH", KEYCODE_SLASH, '/', "/", kActionKeyType, ~0},
+ {"0", KEYCODE_0, '0', "0", kActionKeyType, ~0},
+ {"1", KEYCODE_1, '1', "1", kActionKeyType, ~0},
+ {"2", KEYCODE_2, '2', "2", kActionKeyType, ~0},
+ {"3", KEYCODE_3, '3', "3", kActionKeyType, ~0},
+ {"4", KEYCODE_4, '4', "4", kActionKeyType, ~0},
+ {"5", KEYCODE_5, '5', "5", kActionKeyType, ~0},
+ {"6", KEYCODE_6, '6', "6", kActionKeyType, ~0},
+ {"7", KEYCODE_7, '7', "7", kActionKeyType, ~0},
+ {"8", KEYCODE_8, '8', "8", kActionKeyType, ~0},
+ {"9", KEYCODE_9, '9', "9", kActionKeyType, ~0},
+ {"COLON", KEYCODE_COLON, ':', ":", kActionKeyType, ~0},
+ {"SEMICOLON", KEYCODE_SEMICOLON, ';', ";", kActionKeyType, ~0},
+ {"LESS", KEYCODE_LESS, '<', "<", kActionKeyType, ~0},
+ {"EQUALS", KEYCODE_EQUALS, '=', "=", kActionKeyType, ~0},
+ {"GREATER", KEYCODE_GREATER, '>', ">", kActionKeyType, ~0},
+ {"QUESTION", KEYCODE_QUESTION, '?', "?", kActionKeyType, ~0},
+ {"AT", KEYCODE_AT, '@', "@", kActionKeyType, ~0},
+
+ {"LEFTBRACKET", KEYCODE_LEFTBRACKET, '[', "[", kActionKeyType, ~0},
+ {"BACKSLASH", KEYCODE_BACKSLASH, '\\', "\\", kActionKeyType, ~0},
+ {"RIGHTBRACKET", KEYCODE_RIGHTBRACKET, ']', "]", kActionKeyType, ~0},
+ {"CARET", KEYCODE_CARET, '^', "^", kActionKeyType, ~0},
+ {"UNDERSCORE", KEYCODE_UNDERSCORE, '_', "_", kActionKeyType, ~0},
+ {"BACKQUOTE", KEYCODE_BACKQUOTE, '`', "`", kActionKeyType, ~0},
+ {"a", KEYCODE_a, 'a', "A", kActionKeyType, ~0},
+ {"b", KEYCODE_b, 'b', "B", kActionKeyType, ~0},
+ {"c", KEYCODE_c, 'c', "C", kActionKeyType, ~0},
+ {"d", KEYCODE_d, 'd', "D", kActionKeyType, ~0},
+ {"e", KEYCODE_e, 'e', "E", kActionKeyType, ~0},
+ {"f", KEYCODE_f, 'f', "F", kActionKeyType, ~0},
+ {"g", KEYCODE_g, 'g', "G", kActionKeyType, ~0},
+ {"h", KEYCODE_h, 'h', "H", kActionKeyType, ~0},
+ {"i", KEYCODE_i, 'i', "I", kActionKeyType, ~0},
+ {"j", KEYCODE_j, 'j', "J", kActionKeyType, ~0},
+ {"k", KEYCODE_k, 'k', "K", kActionKeyType, ~0},
+ {"l", KEYCODE_l, 'l', "L", kActionKeyType, ~0},
+ {"m", KEYCODE_m, 'm', "M", kActionKeyType, ~0},
+ {"n", KEYCODE_n, 'n', "N", kActionKeyType, ~0},
+ {"o", KEYCODE_o, 'o', "O", kActionKeyType, ~0},
+ {"p", KEYCODE_p, 'p', "P", kActionKeyType, ~0},
+ {"q", KEYCODE_q, 'q', "Q", kActionKeyType, ~0},
+ {"r", KEYCODE_r, 'r', "R", kActionKeyType, ~0},
+ {"s", KEYCODE_s, 's', "S", kActionKeyType, ~0},
+ {"t", KEYCODE_t, 't', "T", kActionKeyType, ~0},
+ {"u", KEYCODE_u, 'u', "U", kActionKeyType, ~0},
+ {"v", KEYCODE_v, 'v', "V", kActionKeyType, ~0},
+ {"w", KEYCODE_w, 'w', "W", kActionKeyType, ~0},
+ {"x", KEYCODE_x, 'x', "X", kActionKeyType, ~0},
+ {"y", KEYCODE_y, 'y', "Y", kActionKeyType, ~0},
+ {"z", KEYCODE_z, 'z', "Z", kActionKeyType, ~0},
+ {"DELETE", KEYCODE_DELETE, 0, "Del", kActionKeyType, ~0},
// Numeric keypad
- {"KP0", KEYCODE_KP0, 0, "KP0", kActionKeyType, false},
- {"KP1", KEYCODE_KP1, 0, "KP1", kActionKeyType, false},
- {"KP2", KEYCODE_KP2, 0, "KP2", kActionKeyType, false},
- {"KP3", KEYCODE_KP3, 0, "KP3", kActionKeyType, false},
- {"KP4", KEYCODE_KP4, 0, "KP4", kActionKeyType, false},
- {"KP5", KEYCODE_KP5, 0, "KP5", kActionKeyType, false},
- {"KP6", KEYCODE_KP6, 0, "KP6", kActionKeyType, false},
- {"KP7", KEYCODE_KP7, 0, "KP7", kActionKeyType, false},
- {"KP8", KEYCODE_KP8, 0, "KP8", kActionKeyType, false},
- {"KP9", KEYCODE_KP9, 0, "KP9", kActionKeyType, false},
- {"KP_PERIOD", KEYCODE_KP_PERIOD, 0, "KP.", kActionKeyType, false},
- {"KP_DIVIDE", KEYCODE_KP_DIVIDE, 0, "KP/", kActionKeyType, false},
- {"KP_MULTIPLY", KEYCODE_KP_MULTIPLY, 0, "KP*", kActionKeyType, false},
- {"KP_MINUS", KEYCODE_KP_MINUS, 0, "KP-", kActionKeyType, false},
- {"KP_PLUS", KEYCODE_KP_PLUS, 0, "KP+", kActionKeyType, false},
- {"KP_ENTER", KEYCODE_KP_ENTER, 0, "KP Enter", kActionKeyType, false},
- {"KP_EQUALS", KEYCODE_KP_EQUALS, 0, "KP=", kActionKeyType, false},
+ {"KP0", KEYCODE_KP0, 0, "KP0", kActionKeyType, ~0},
+ {"KP1", KEYCODE_KP1, 0, "KP1", kActionKeyType, ~0},
+ {"KP2", KEYCODE_KP2, 0, "KP2", kActionKeyType, ~0},
+ {"KP3", KEYCODE_KP3, 0, "KP3", kActionKeyType, ~0},
+ {"KP4", KEYCODE_KP4, 0, "KP4", kActionKeyType, ~0},
+ {"KP5", KEYCODE_KP5, 0, "KP5", kActionKeyType, ~0},
+ {"KP6", KEYCODE_KP6, 0, "KP6", kActionKeyType, ~0},
+ {"KP7", KEYCODE_KP7, 0, "KP7", kActionKeyType, ~0},
+ {"KP8", KEYCODE_KP8, 0, "KP8", kActionKeyType, ~0},
+ {"KP9", KEYCODE_KP9, 0, "KP9", kActionKeyType, ~0},
+ {"KP_PERIOD", KEYCODE_KP_PERIOD, 0, "KP.", kActionKeyType, ~0},
+ {"KP_DIVIDE", KEYCODE_KP_DIVIDE, 0, "KP/", kActionKeyType, ~0},
+ {"KP_MULTIPLY", KEYCODE_KP_MULTIPLY, 0, "KP*", kActionKeyType, ~0},
+ {"KP_MINUS", KEYCODE_KP_MINUS, 0, "KP-", kActionKeyType, ~0},
+ {"KP_PLUS", KEYCODE_KP_PLUS, 0, "KP+", kActionKeyType, ~0},
+ {"KP_ENTER", KEYCODE_KP_ENTER, 0, "KP Enter", kActionKeyType, ~0},
+ {"KP_EQUALS", KEYCODE_KP_EQUALS, 0, "KP=", kActionKeyType, ~0},
// Arrows + Home/End pad
- {"UP", KEYCODE_UP, 0, "Up", kDirUpKeyType, false},
- {"DOWN", KEYCODE_DOWN, 0, "Down", kDirDownKeyType, false},
- {"RIGHT", KEYCODE_RIGHT, 0, "Right", kDirRightKeyType, false},
- {"LEFT", KEYCODE_LEFT, 0, "Left", kDirLeftKeyType, false},
- {"INSERT", KEYCODE_INSERT, 0, "Insert", kActionKeyType, false},
- {"HOME", KEYCODE_HOME, 0, "Home", kActionKeyType, false},
- {"END", KEYCODE_END, 0, "End", kActionKeyType, false},
- {"PAGEUP", KEYCODE_PAGEUP, 0, "PgUp", kActionKeyType, false},
- {"PAGEDOWN", KEYCODE_PAGEDOWN, 0, "PgDn", kActionKeyType, false},
+ {"UP", KEYCODE_UP, 0, "Up", kDirUpKeyType, ~0},
+ {"DOWN", KEYCODE_DOWN, 0, "Down", kDirDownKeyType, ~0},
+ {"RIGHT", KEYCODE_RIGHT, 0, "Right", kDirRightKeyType, ~0},
+ {"LEFT", KEYCODE_LEFT, 0, "Left", kDirLeftKeyType, ~0},
+ {"INSERT", KEYCODE_INSERT, 0, "Insert", kActionKeyType, ~0},
+ {"HOME", KEYCODE_HOME, 0, "Home", kActionKeyType, ~0},
+ {"END", KEYCODE_END, 0, "End", kActionKeyType, ~0},
+ {"PAGEUP", KEYCODE_PAGEUP, 0, "PgUp", kActionKeyType, ~0},
+ {"PAGEDOWN", KEYCODE_PAGEDOWN, 0, "PgDn", kActionKeyType, ~0},
// Function keys
- {"F1", KEYCODE_F1, ASCII_F1, "F1", kActionKeyType, false},
- {"F2", KEYCODE_F2, ASCII_F2, "F2", kActionKeyType, false},
- {"F3", KEYCODE_F3, ASCII_F3, "F3", kActionKeyType, false},
- {"F4", KEYCODE_F4, ASCII_F4, "F4", kActionKeyType, false},
- {"F5", KEYCODE_F5, ASCII_F5, "F5", kActionKeyType, false},
- {"F6", KEYCODE_F6, ASCII_F6, "F6", kActionKeyType, false},
- {"F7", KEYCODE_F7, ASCII_F7, "F7", kActionKeyType, false},
- {"F8", KEYCODE_F8, ASCII_F8, "F8", kActionKeyType, false},
- {"F9", KEYCODE_F9, ASCII_F9, "F9", kActionKeyType, false},
- {"F10", KEYCODE_F10, ASCII_F10, "F10", kActionKeyType, false},
- {"F11", KEYCODE_F11, ASCII_F11, "F11", kActionKeyType, false},
- {"F12", KEYCODE_F12, ASCII_F12, "F12", kActionKeyType, false},
- {"F13", KEYCODE_F13, 0, "F13", kActionKeyType, false},
- {"F14", KEYCODE_F14, 0, "F14", kActionKeyType, false},
- {"F15", KEYCODE_F15, 0, "F15", kActionKeyType, false},
+ {"F1", KEYCODE_F1, ASCII_F1, "F1", kActionKeyType, ~0},
+ {"F2", KEYCODE_F2, ASCII_F2, "F2", kActionKeyType, ~0},
+ {"F3", KEYCODE_F3, ASCII_F3, "F3", kActionKeyType, ~0},
+ {"F4", KEYCODE_F4, ASCII_F4, "F4", kActionKeyType, ~0},
+ {"F5", KEYCODE_F5, ASCII_F5, "F5", kActionKeyType, ~0},
+ {"F6", KEYCODE_F6, ASCII_F6, "F6", kActionKeyType, ~0},
+ {"F7", KEYCODE_F7, ASCII_F7, "F7", kActionKeyType, ~0},
+ {"F8", KEYCODE_F8, ASCII_F8, "F8", kActionKeyType, ~0},
+ {"F9", KEYCODE_F9, ASCII_F9, "F9", kActionKeyType, ~0},
+ {"F10", KEYCODE_F10, ASCII_F10, "F10", kActionKeyType, ~0},
+ {"F11", KEYCODE_F11, ASCII_F11, "F11", kActionKeyType, ~0},
+ {"F12", KEYCODE_F12, ASCII_F12, "F12", kActionKeyType, ~0},
+ {"F13", KEYCODE_F13, 0, "F13", kActionKeyType, ~0},
+ {"F14", KEYCODE_F14, 0, "F14", kActionKeyType, ~0},
+ {"F15", KEYCODE_F15, 0, "F15", kActionKeyType, ~0},
+
+
+ // Modifier keys pressed alone
+ {"RSHIFT", KEYCODE_RSHIFT, 0, "Right Shift", kModiferKeyType, ~KBD_SHIFT},
+ {"LSHIFT", KEYCODE_LSHIFT, 0, "Left Shift", kModiferKeyType, ~KBD_SHIFT},
+ {"RCTRL", KEYCODE_RCTRL, 0, "Right Ctrl", kModiferKeyType, ~KBD_CTRL},
+ {"LCTRL", KEYCODE_LCTRL, 0, "Left Ctrl", kModiferKeyType, ~KBD_CTRL},
+ {"RALT", KEYCODE_RALT, 0, "Right Alt", kModiferKeyType, ~KBD_ALT},
+ {"LALT", KEYCODE_LALT, 0, "Left Alt", kModiferKeyType, ~KBD_ALT},
+
// Miscellaneous function keys
- {"HELP", KEYCODE_HELP, 0, "Help", kActionKeyType, false},
- {"PRINT", KEYCODE_PRINT, 0, "Print", kActionKeyType, false},
- {"SYSREQ", KEYCODE_SYSREQ, 0, "SysRq", kActionKeyType, false},
- {"BREAK", KEYCODE_BREAK, 0, "Break", kActionKeyType, false},
- {"MENU", KEYCODE_MENU, 0, "Menu", kActionKeyType, false},
+ {"HELP", KEYCODE_HELP, 0, "Help", kActionKeyType, ~0},
+ {"PRINT", KEYCODE_PRINT, 0, "Print", kActionKeyType, ~0},
+ {"SYSREQ", KEYCODE_SYSREQ, 0, "SysRq", kActionKeyType, ~0},
+ {"BREAK", KEYCODE_BREAK, 0, "Break", kActionKeyType, ~0},
+ {"MENU", KEYCODE_MENU, 0, "Menu", kActionKeyType, ~0},
// Power Macintosh power key
- {"POWER", KEYCODE_POWER, 0, "Power", kActionKeyType, false},
+ {"POWER", KEYCODE_POWER, 0, "Power", kActionKeyType, ~0},
// Some european keyboards
- {"EURO", KEYCODE_EURO, 0, "Euro", kActionKeyType, false},
+ {"EURO", KEYCODE_EURO, 0, "Euro", kActionKeyType, ~0},
// Atari keyboard has Undo
- {"UNDO", KEYCODE_UNDO, 0, "Undo", kActionKeyType, false},
- {0, KEYCODE_INVALID, 0, 0, kGenericKeyType, false}
+ {"UNDO", KEYCODE_UNDO, 0, "Undo", kActionKeyType, ~0},
+ {0, KEYCODE_INVALID, 0, 0, kGenericKeyType, ~0}
};
struct Mod {
byte flag;
const char *id;
const char *desc;
- bool shiftable;
};
static const Mod modifiers[] = {
- { 0, "", "", false },
- { KBD_CTRL, "C+", "Ctrl+", false },
- { KBD_ALT, "A+", "Alt+", false },
- { KBD_SHIFT, "", "", true },
- { KBD_CTRL | KBD_ALT, "C+A+", "Ctrl+Alt+", false },
- { KBD_SHIFT | KBD_CTRL, "S+C+", "Shift+Ctrl+", true },
- { KBD_SHIFT | KBD_CTRL | KBD_ALT, "C+A+", "Ctrl+Alt+", true },
- { 0, 0, 0, false }
+ { 0, "", "" },
+ { KBD_CTRL, "C+", "Ctrl+" },
+ { KBD_ALT, "A+", "Alt+" },
+ { KBD_SHIFT, "S+", "Shift+" },
+ { 0, 0, 0 }
};
#endif
Common::HardwareKeySet *OSystem_SDL::getHardwareKeySet() {
#ifdef ENABLE_KEYMAPPER
- HardwareKeySet *keySet = new HardwareKeySet();
+ static HardwareKeySet *keySet = new HardwareKeySet();
+ static bool keySetInited = false;
+ if (keySet && keySetInited)
+ return keySet;
+
const Key *key;
const Mod *mod;
char fullKeyId[50];
@@ -206,24 +216,21 @@ Common::HardwareKeySet *OSystem_SDL::getHardwareKeySet() {
uint16 ascii;
for (mod = modifiers; mod->id; mod++) {
- for (key = keys; key->hwId; key++) {
- ascii = key->ascii;
-
- if (mod->shiftable && key->shiftable) {
- snprintf(fullKeyId, 50, "%s%c", mod->id, toupper(key->hwId[0]));
- snprintf(fullKeyDesc, 100, "%s%c", mod->desc, toupper(key->desc[0]));
- ascii = toupper(key->ascii);
- } else if (mod->shiftable) {
- snprintf(fullKeyId, 50, "S+%s%s", mod->id, key->hwId);
- snprintf(fullKeyDesc, 100, "Shift+%s%s", mod->desc, key->desc);
- } else {
- snprintf(fullKeyId, 50, "%s%s", mod->id, key->hwId);
- snprintf(fullKeyDesc, 100, "%s%s", mod->desc, key->desc);
- }
-
- keySet->addHardwareKey(new HardwareKey(fullKeyId, KeyState(key->keycode, ascii, mod->flag), fullKeyDesc, key->preferredAction ));
- }
+ snprintf(fullKeyId, 50, "S+%s", mod->id);
+ snprintf(fullKeyDesc, 100, "Shift+%s", mod->desc);
+
+ keySet->addHardwareMod(new HardwareMod(fullKeyId, mod->flag, fullKeyDesc));
}
+ for (key = keys; key->hwId; key++) {
+ ascii = key->ascii;
+
+ snprintf(fullKeyId, 50, "%s", key->hwId);
+ snprintf(fullKeyDesc, 100, "%s", key->desc);
+
+ keySet->addHardwareKey(new HardwareKey(fullKeyId, ActionKey(key->keycode, 0), fullKeyDesc, key->modableMask, key->preferredAction));
+ }
+
+ keySetInited = true;
return keySet;
diff --git a/backends/platform/sdl/sdl.cpp b/backends/platform/sdl/sdl.cpp
index 7b3cf4eaa1..b6b46af9d7 100644
--- a/backends/platform/sdl/sdl.cpp
+++ b/backends/platform/sdl/sdl.cpp
@@ -222,6 +222,10 @@ OSystem_SDL::OSystem_SDL()
_osdSurface(0), _osdAlpha(SDL_ALPHA_TRANSPARENT), _osdFadeStartTime(0),
#endif
_hwscreen(0), _screen(0), _tmpscreen(0),
+#ifdef ENABLE_RGB_COLOR
+ _screenFormat(Graphics::PixelFormat::createFormatCLUT8()),
+ _cursorFormat(Graphics::PixelFormat::createFormatCLUT8()),
+#endif
_overlayVisible(false),
_overlayscreen(0), _tmpscreen2(0),
_samplesPerSec(0),
diff --git a/backends/platform/sdl/sdl.h b/backends/platform/sdl/sdl.h
index 2a5fda30bd..6c8a721701 100644
--- a/backends/platform/sdl/sdl.h
+++ b/backends/platform/sdl/sdl.h
@@ -93,9 +93,17 @@ public:
void beginGFXTransaction(void);
TransactionError endGFXTransaction(void);
- // Set the size of the video bitmap.
- // Typically, 320x200
- virtual void initSize(uint w, uint h); // overloaded by CE backend
+#ifdef ENABLE_RGB_COLOR
+ // Game screen
+ virtual Graphics::PixelFormat getScreenFormat() const { return _screenFormat; }
+
+ // Highest supported
+ virtual Common::List<Graphics::PixelFormat> getSupportedFormats();
+#endif
+
+ // Set the size and format of the video bitmap.
+ // Typically, 320x200 CLUT8
+ virtual void initSize(uint w, uint h, const Graphics::PixelFormat *format); // overloaded by CE backend
virtual int getScreenChangeID() const { return _screenChangeCount; }
@@ -124,7 +132,7 @@ public:
virtual void warpMouse(int x, int y); // overloaded by CE backend (FIXME)
// Set the bitmap that's used when drawing the cursor.
- virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, byte keycolor, int cursorTargetScale); // overloaded by CE backend (FIXME)
+ virtual void setMouseCursor(const byte *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format); // overloaded by CE backend (FIXME)
// Set colors of cursor palette
void setCursorPalette(const byte *colors, uint start, uint num);
@@ -186,6 +194,7 @@ public:
// Overlay
virtual Graphics::PixelFormat getOverlayFormat() const { return _overlayFormat; }
+
virtual void showOverlay();
virtual void hideOverlay();
virtual void clearOverlay();
@@ -239,6 +248,10 @@ protected:
// unseen game screen
SDL_Surface *_screen;
+#ifdef ENABLE_RGB_COLOR
+ Graphics::PixelFormat _screenFormat;
+ Graphics::PixelFormat _cursorFormat;
+#endif
// temporary screen (for scalers)
SDL_Surface *_tmpscreen;
@@ -272,6 +285,9 @@ protected:
bool needHotswap;
bool needUpdatescreen;
bool normal1xScaler;
+#ifdef ENABLE_RGB_COLOR
+ bool formatChanged;
+#endif
};
TransactionDetails _transactionDetails;
@@ -287,6 +303,9 @@ protected:
int screenWidth, screenHeight;
int overlayWidth, overlayHeight;
+#ifdef ENABLE_RGB_COLOR
+ Graphics::PixelFormat format;
+#endif
int hardwareWidth, hardwareHeight;
};
VideoState _videoMode, _oldVideoMode;