mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-05-08 23:06:16 +00:00
action map remap for mac
Mac now automatically remaps keys and modifies the incoming string to reflect it automatically converts: Ctrl -> Cmd Alt -> Option if you absolutely need a specific set on macos you will still need to check the platform in script and set the required key otherwise this will allow menus to be built with just providing the windows key or the mac key and it will display correclty for the platform.
This commit is contained in:
parent
8de2458610
commit
496895d60c
3 changed files with 89 additions and 27 deletions
|
|
@ -466,23 +466,41 @@ bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor*
|
|||
pObjectString = pSpace + 1;
|
||||
pSpace[0] = '\0';
|
||||
|
||||
char* pModifier = dStrtok(copyBuffer, "-");
|
||||
while (pModifier != NULL) {
|
||||
if (dStricmp(pModifier, "shift") == 0) {
|
||||
pDescriptor->flags |= SI_SHIFT;
|
||||
} else if (dStricmp(pModifier, "ctrl") == 0) {
|
||||
pDescriptor->flags |= SI_CTRL;
|
||||
} else if (dStricmp(pModifier, "alt") == 0) {
|
||||
pDescriptor->flags |= SI_ALT;
|
||||
} else if (dStricmp(pModifier, "cmd") == 0) {
|
||||
pDescriptor->flags |= SI_ALT;
|
||||
} else if (dStricmp(pModifier, "opt") == 0) {
|
||||
pDescriptor->flags |= SI_MAC_OPT;
|
||||
}
|
||||
|
||||
pModifier = dStrtok(NULL, "-");
|
||||
}
|
||||
} else {
|
||||
char* pModifier = dStrtok(copyBuffer, "-");
|
||||
while (pModifier != NULL)
|
||||
{
|
||||
#if defined(TORQUE_OS_MAC)
|
||||
if (dStricmp(pModifier, "ctrl") == 0 || dStricmp(pModifier, "cmd") == 0)
|
||||
{
|
||||
pDescriptor->flags |= SI_CTRL; // On Mac, map Ctrl/Cmd to the standard Mac command key
|
||||
}
|
||||
else if (dStricmp(pModifier, "shift") == 0)
|
||||
{
|
||||
pDescriptor->flags |= SI_SHIFT;
|
||||
}
|
||||
else if (dStricmp(pModifier, "alt") == 0 || dStricmp(pModifier, "opt") == 0)
|
||||
{
|
||||
pDescriptor->flags |= SI_MAC_OPT;
|
||||
}
|
||||
#else
|
||||
if (dStricmp(pModifier, "ctrl") == 0 || (dStricmp(pModifier, "cmd") == 0)
|
||||
{
|
||||
pDescriptor->flags |= SI_CTRL;
|
||||
}
|
||||
else if (dStricmp(pModifier, "shift") == 0)
|
||||
{
|
||||
pDescriptor->flags |= SI_SHIFT;
|
||||
}
|
||||
else if (dStricmp(pModifier, "alt") == 0 || dStricmp(pModifier, "opt") == 0)
|
||||
{
|
||||
pDescriptor->flags |= SI_ALT;
|
||||
}
|
||||
#endif
|
||||
pModifier = dStrtok(NULL, "-");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No.
|
||||
pDescriptor->flags = 0;
|
||||
pObjectString = copyBuffer;
|
||||
|
|
@ -492,6 +510,47 @@ bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor*
|
|||
//
|
||||
AssertFatal(dStrlen(pObjectString) != 0, "Error, no key was specified!");
|
||||
|
||||
// rebuild normalized modifier string from parsed flags
|
||||
String newString;
|
||||
|
||||
#if defined(TORQUE_OS_MAC)
|
||||
|
||||
if (pDescriptor->flags & SI_ALT || pDescriptor->flags & SI_CTRL)
|
||||
newString += "Cmd";
|
||||
|
||||
if (pDescriptor->flags & SI_MAC_OPT)
|
||||
{
|
||||
if (newString.length()) newString += "-";
|
||||
newString += "Opt";
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
if (pDescriptor->flags & SI_CTRL)
|
||||
newString += "Ctrl";
|
||||
|
||||
if (pDescriptor->flags & SI_ALT)
|
||||
{
|
||||
if (newString.length()) newString += "-";
|
||||
newString += "Alt";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
if (pDescriptor->flags & SI_SHIFT)
|
||||
{
|
||||
if (newString.length()) newString += "-";
|
||||
newString += "Shift";
|
||||
}
|
||||
|
||||
// rebuild full event string
|
||||
if (newString.length())
|
||||
newString = String::ToString("%s %s", newString.c_str(), pObjectString).c_str();
|
||||
else
|
||||
newString = String::ToString("%s", pObjectString).c_str();
|
||||
|
||||
dStrcpy(const_cast<char*>(pEventString), newString.c_str(), newString.length()+1);
|
||||
|
||||
if (dStrlen(pObjectString) == 1)
|
||||
{
|
||||
if (dIsDecentChar(*pObjectString)) // includes foreign chars
|
||||
|
|
@ -544,16 +603,7 @@ bool ActionMap::createEventDescriptor(const char* pEventString, EventDescriptor*
|
|||
}
|
||||
}
|
||||
}
|
||||
// Didn't find an ascii match. Check the virtual map table
|
||||
//for (U32 j = 0; gVirtualMap[j].code != 0xFFFFFFFF; j++)
|
||||
//{
|
||||
// if (dStricmp(pObjectString, gVirtualMap[j].pDescription) == 0)
|
||||
// {
|
||||
// pDescriptor->eventType = gVirtualMap[j].type;
|
||||
// pDescriptor->eventCode = gVirtualMap[j].code;
|
||||
// return true;
|
||||
// }
|
||||
//}
|
||||
|
||||
InputEventManager::VirtualMapData* data = INPUTMGR->findVirtualMap(pObjectString);
|
||||
if(data)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue