00001 #ifndef Impala_Visualization_KeyBindings_h
00002 #define Impala_Visualization_KeyBindings_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 namespace Impala {
00018 namespace Visualization {
00019
00020 #ifndef Impala_Basis_String_h
00021 #include "Basis/String.h"
00022 #endif
00023
00024 typedef std::vector<String> KeyBindings;
00025
00026 void ParseKeyBindingStr(String& str, int& c, int& state)
00027 {
00028 int modState = 0;
00029 int modIdx;
00030 String modStr;
00031
00032 state = c = 0;
00033 if ((modIdx=str.find('#'))!=String::npos)
00034 {
00035 modStr = str.substr(0,modIdx);
00036 if (modStr == "ctrl")
00037 modState |= oglControl;
00038 else if (modStr == "shift")
00039 modState |= oglShift;
00040 else if (modStr == "ctrl-shift" || modStr == "shift-ctrl")
00041 modState |= oglControl | oglShift;
00042 }
00043
00044 state = modState;
00045
00046 int charIdx = modIdx ? modIdx+1 : 0;
00047 String charStr = str.substr(charIdx);
00048 if (charStr.length()==1)
00049 {
00050 c = charStr[0];
00051 if (modState & oglControl)
00052 {
00053 c = toupper(c);
00054 c -= 'A'-1;
00055 }
00056 }
00057 else if (charStr[0] == 'f' && charStr[1] == 'n')
00058 {
00059 int fnNr = atoi(charStr.substr(2));
00060 c = oglFUNC(fnNr);
00061 }
00062 else if (charStr == "pageup")
00063 c = oglPAGEUP;
00064 else if (charStr == "pagedown")
00065 c = oglPAGEDOWN;
00066 else if (charStr == "up")
00067 c = oglUP;
00068 else if (charStr == "down")
00069 c = oglDOWN;
00070 else if (charStr == "right")
00071 c = oglRIGHT;
00072 else if (charStr == "left")
00073 c = oglLEFT;
00074 else if (charStr == "home")
00075 c = oglHOME;
00076 else if (charStr == "end")
00077 c = oglEND;
00078 else if (charStr == "insert")
00079 c = oglINSERT;
00080 else if (charStr == "delete")
00081 c = oglDELETE;
00082 }
00083
00084 String GetKeyBinding(String name, String dflt)
00085 {
00086 CmdOptions& options = CmdOptions::GetInstance();
00087 String str = options.GetString(name, dflt);
00088 return str;
00089 }
00090
00091 bool CheckKeyBinding(KeyBindings& kb, int idx, int c, int state)
00092 {
00093 int cVal, stateVal;
00094 String str = kb[idx];
00095 ParseKeyBindingStr(str,cVal,stateVal);
00096 if (!stateVal && isupper(c))
00097 stateVal = oglShift;
00098 return (c==cVal && (state==stateVal));
00099 }
00100
00101 }
00102 }
00103
00104 #endif // Impala_Visualization_KeyBindings_h