rework key input handling, add more script events for UI and implement console history

This commit is contained in:
Eduardo Bart 2011-08-28 18:32:24 -03:00
parent 7242dfc9ee
commit 8aadea2a96
12 changed files with 494 additions and 314 deletions

1
TODO
View File

@ -4,4 +4,3 @@ hotkeys events in lua
make password text edit hidden
load modules from zip packages
ip/host/rsa configuration
console history

View File

@ -5,6 +5,8 @@ local logLocked = false
local commandEnv = createEnvironment()
local maxLines = 80
local numLines = 0
local commandHistory = { }
local currentHistoryIndex = 0
function Console.onLog(level, message, time)
-- avoid logging while reporting logs (would cause a infinite loop)
@ -47,9 +49,41 @@ function Console.addLine(text, color)
end
end
function Console.navigateCommand(step)
local numCommands = #commandHistory
if numCommands > 0 then
currentHistoryIndex = math.min(math.max(currentHistoryIndex + step, 0), numCommands)
local commandLineEdit = console:getChildById('commandLineEdit')
if currentHistoryIndex > 0 then
local command = commandHistory[numCommands - currentHistoryIndex + 1]
commandLineEdit:setText(command)
else
commandLineEdit:clearText()
end
end
end
function Console.create()
console = UI.loadAndDisplay("/console/console.otui")
console:hide()
console.onKeyPress = function(self, keyCode, keyChar, keyboardModifiers)
if keyboardModifiers == KeyboardNoModifier then
if keyCode == KeyReturn or keyCode == keyEnter then
local commandLineEdit = console:getChildById('commandLineEdit')
local command = commandLineEdit:getText()
Console.executeCommand(command)
commandLineEdit:clearText()
return true
elseif keyCode == KeyUp then
Console.navigateCommand(1)
return true
elseif keyCode == KeyDown then
Console.navigateCommand(-1)
return true
end
end
return false
end
Logger.setOnLog(Console.onLog)
Logger.fireOldMessages()
@ -72,6 +106,8 @@ function Console.hide()
end
function Console.executeCommand(command)
currentHistoryIndex = 0
table.insert(commandHistory, command)
Console.addLine(">> " .. command, "#ffffff")
local func, err = loadstring(command, "@")
if func then

View File

@ -23,14 +23,9 @@ RectPanel
text: >>
UILineEdit
id: commandBox
id: commandLineEdit
height: 16
anchors.bottom: parent.bottom
anchors.left: commandSymbolLabel.right
anchors.right: parent.right
font: terminus-14px-bold
onAction: |
function(self)
Console.executeCommand(self:getText())
self:clearText()
end

View File

@ -16,3 +16,118 @@ LogFatal = 4
ActiveFocusReason = 2
EmptyFunction = function() end
-- KeyCodes
KeyUnknown = 0
KeyEscape = 1
KeyTab = 2
KeyBackspace = 3
KeyReturn = 4
KeyEnter = 5
KeyInsert = 6
KeyDelete = 7
KeyPause = 8
KeyPrintScreen = 9
KeyHome = 10
KeyEnd = 11
KeyPageUp = 12
KeyPageDown = 13
KeyUp = 14
KeyDown = 15
KeyLeft = 16
KeyRight = 17
KeyNumLock = 18
KeyScrollLock = 19
KeyCapsLock = 20
KeyCtrl = 21
KeyShift = 22
KeyAlt = 23
KeyAltGr = 24
KeyMeta = 25
KeyMenu = 26
KeySpace = 32 -- ' '
KeyExclamation = 33 -- !
KeyQuote = 34 -- "
KeyNumberSign = 35 -- #
KeyDollar = 36 -- $
KeyPercent = 37 -- %
KeyAmpersand = 38 -- &
KeyApostrophe = 39 -- '
KeyLeftParen = 40 -- (
KeyRightParen = 41 -- )
KeyAsterisk = 42 -- *
KeyPlus = 43 -- +
KeyComma = 44 --
KeyMinus = 45 -- -
KeyPeriod = 46 -- .
KeySlash = 47 -- /
Key0 = 48 -- 0
Key1 = 49 -- 1
Key2 = 50 -- 2
Key3 = 51 -- 3
Key4 = 52 -- 4
Key5 = 53 -- 5
Key6 = 54 -- 6
Key7 = 55 -- 7
Key8 = 56 -- 8
Key9 = 57 -- 9
KeyColon = 58 -- :
KeySemicolon = 59 -- ;
KeyLess = 60 -- <
KeyEqual = 61 -- =
KeyGreater = 62 -- >
KeyQuestion = 63 -- ?
KeyAtSign = 64 -- @
KeyA = 65 -- a
KeyB = 66 -- b
KeyC = 67 -- c
KeyD = 68 -- d
KeyE = 69 -- e
KeyF = 70 -- f
KeyG = 71 -- g
KeyH = 72 -- h
KeyI = 73 -- i
KeyJ = 74 -- j
KeyK = 75 -- k
KeyL = 76 -- l
KeyM = 77 -- m
KeyN = 78 -- n
KeyO = 79 -- o
KeyP = 80 -- p
KeyQ = 81 -- q
KeyR = 82 -- r
KeyS = 83 -- s
KeyT = 84 -- t
KeyU = 85 -- u
KeyV = 86 -- v
KeyW = 87 -- w
KeyX = 88 -- x
KeyY = 89 -- y
KeyZ = 90 -- z
KeyLeftBracket = 91 -- [
KeyBackslash = 92 -- '\'
KeyRightBracket = 93 -- ]
KeyCaret = 94 -- ^
KeyUnderscore = 95 -- _
KeyGrave = 96 -- `
KeyLeftCurly = 123 -- {
KeyBar = 124 -- |
KeyRightCurly = 125 -- }
KeyTilde = 126 -- ~
KeyF1 = 128
KeyF2 = 129
KeyF3 = 130
KeyF4 = 131
KeyF5 = 132
KeyF6 = 134
KeyF7 = 135
KeyF8 = 136
KeyF9 = 137
KeyF10 = 138
KeyF11 = 139
KeyF12 = 140
KeyboardNoModifier = 0
KeyboardCtrlModifier = 1
KeyboardAltModifier = 2
KeyboardShiftModifier = 4

View File

@ -0,0 +1,14 @@
function string:split(sep)
local t = { }
local function helper(word)
table.insert(t, word)
return ""
end
if not self:gsub("%w+", helper):find("%S") then
return t
end
end
function string:starts(start)
return self:sub(1, #start) == start
end

View File

@ -0,0 +1,34 @@
function table.dump(t, depth)
if not depth then depth = 0 end
for k,v in pairs(t) do
str = string.rep(' ', depth * 2) .. k .. ': '
if type(v) ~= "table" then
print(str .. v)
else
print(str)
table.dump(v, depth+1)
end
end
end
function table.copy(t)
local res = {}
for k,v in pairs(t) do
res[k] = v
end
return res
end
function table.selective_copy(t, keys)
local res = { }
for i,v in ipairs(keys) do
res[v] = t[v]
end
return res
end
function table.merge(t, src)
for k,v in pairs(src) do
t[k] = v
end
end

View File

@ -49,6 +49,117 @@ namespace Fw
lightGray = 0xffc0c0c0
};
enum Key : uint8 {
KeyUnknown = 0,
KeyEscape = 1,
KeyTab = 2,
KeyBackspace = 3,
KeyReturn = 4,
KeyEnter = 5,
KeyInsert = 6,
KeyDelete = 7,
KeyPause = 8,
KeyPrintScreen = 9,
KeyHome = 10,
KeyEnd = 11,
KeyPageUp = 12,
KeyPageDown = 13,
KeyUp = 14,
KeyDown = 15,
KeyLeft = 16,
KeyRight = 17,
KeyNumLock = 18,
KeyScrollLock = 19,
KeyCapsLock = 20,
KeyCtrl = 21,
KeyShift = 22,
KeyAlt = 23,
KeyAltGr = 24,
KeyMeta = 25,
KeyMenu = 26,
KeySpace = 32, // ' '
KeyExclamation = 33, // !
KeyQuote = 34, // "
KeyNumberSign = 35, // #
KeyDollar = 36, // $
KeyPercent = 37, // %
KeyAmpersand = 38, // &
KeyApostrophe = 39, // '
KeyLeftParen = 40, // (
KeyRightParen = 41, // )
KeyAsterisk = 42, // *
KeyPlus = 43, // +
KeyComma = 44, // ,
KeyMinus = 45, // -
KeyPeriod = 46, // .
KeySlash = 47, // /
Key0 = 48, // 0
Key1 = 49, // 1
Key2 = 50, // 2
Key3 = 51, // 3
Key4 = 52, // 4
Key5 = 53, // 5
Key6 = 54, // 6
Key7 = 55, // 7
Key8 = 56, // 8
Key9 = 57, // 9
KeyColon = 58, // :
KeySemicolon = 59, // ;
KeyLess = 60, // <
KeyEqual = 61, // =
KeyGreater = 62, // >
KeyQuestion = 63, // ?
KeyAtSign = 64, // @
KeyA = 65, // a
KeyB = 66, // b
KeyC = 67, // c
KeyD = 68, // d
KeyE = 69, // e
KeyF = 70, // f
KeyG = 71, // g
KeyH = 72, // h
KeyI = 73, // i
KeyJ = 74, // j
KeyK = 75, // k
KeyL = 76, // l
KeyM = 77, // m
KeyN = 78, // n
KeyO = 79, // o
KeyP = 80, // p
KeyQ = 81, // q
KeyR = 82, // r
KeyS = 83, // s
KeyT = 84, // t
KeyU = 85, // u
KeyV = 86, // v
KeyW = 87, // w
KeyX = 88, // x
KeyY = 89, // y
KeyZ = 90, // z
KeyLeftBracket = 91, // [
KeyBackslash = 92, // '\'
KeyRightBracket = 93, // ]
KeyCaret = 94, // ^
KeyUnderscore = 95, // _
KeyGrave = 96, // `
KeyLeftCurly = 123, // {
KeyBar = 124, // |
KeyRightCurly = 125, // }
KeyTilde = 126, // ~
KeyF1 = 128,
KeyF2 = 129,
KeyF3 = 130,
KeyF4 = 131,
KeyF5 = 132,
KeyF6 = 134,
KeyF7 = 135,
KeyF8 = 136,
KeyF9 = 137,
KeyF10 = 138,
KeyF11 = 139,
KeyF12 = 140
};
enum LogLevel {
LogDebug = 0,
LogInfo,

View File

@ -25,155 +25,6 @@
#include <framework/global.h>
//TODO: move the next enums to const.h
enum InputKeyCode {
KC_UNKNOWN = 0x00,
KC_ESCAPE = 0x01,
KC_1 = 0x02,
KC_2 = 0x03,
KC_3 = 0x04,
KC_4 = 0x05,
KC_5 = 0x06,
KC_6 = 0x07,
KC_7 = 0x08,
KC_8 = 0x09,
KC_9 = 0x0A,
KC_0 = 0x0B,
KC_MINUS = 0x0C, // - on main keyboard
KC_EQUALS = 0x0D,
KC_BACK = 0x0E, // backspace
KC_TAB = 0x0F,
KC_Q = 0x10,
KC_W = 0x11,
KC_E = 0x12,
KC_R = 0x13,
KC_T = 0x14,
KC_Y = 0x15,
KC_U = 0x16,
KC_I = 0x17,
KC_O = 0x18,
KC_P = 0x19,
KC_LBRACKET = 0x1A,
KC_RBRACKET = 0x1B,
KC_RETURN = 0x1C, // Enter on main keyboard
KC_LCONTROL = 0x1D,
KC_A = 0x1E,
KC_S = 0x1F,
KC_D = 0x20,
KC_F = 0x21,
KC_G = 0x22,
KC_H = 0x23,
KC_J = 0x24,
KC_K = 0x25,
KC_L = 0x26,
KC_SEMICOLON = 0x27,
KC_APOSTROPHE = 0x28,
KC_GRAVE = 0x29, // accent
KC_LSHIFT = 0x2A,
KC_BACKSLASH = 0x2B,
KC_Z = 0x2C,
KC_X = 0x2D,
KC_C = 0x2E,
KC_V = 0x2F,
KC_B = 0x30,
KC_N = 0x31,
KC_M = 0x32,
KC_COMMA = 0x33,
KC_PERIOD = 0x34, // . on main keyboard
KC_SLASH = 0x35, // / on main keyboard
KC_RSHIFT = 0x36,
KC_MULTIPLY = 0x37, // * on numeric keypad
KC_LALT = 0x38, // left Alt
KC_SPACE = 0x39,
KC_CAPITAL = 0x3A,
KC_F1 = 0x3B,
KC_F2 = 0x3C,
KC_F3 = 0x3D,
KC_F4 = 0x3E,
KC_F5 = 0x3F,
KC_F6 = 0x40,
KC_F7 = 0x41,
KC_F8 = 0x42,
KC_F9 = 0x43,
KC_F10 = 0x44,
KC_NUMLOCK = 0x45,
KC_SCROLL = 0x46, // Scroll Lock
KC_NUMPAD7 = 0x47,
KC_NUMPAD8 = 0x48,
KC_NUMPAD9 = 0x49,
KC_SUBTRACT = 0x4A, // - on numeric keypad
KC_NUMPAD4 = 0x4B,
KC_NUMPAD5 = 0x4C,
KC_NUMPAD6 = 0x4D,
KC_ADD = 0x4E, // + on numeric keypad
KC_NUMPAD1 = 0x4F,
KC_NUMPAD2 = 0x50,
KC_NUMPAD3 = 0x51,
KC_NUMPAD0 = 0x52,
KC_DECIMAL = 0x53, // . on numeric keypad
KC_OEM_102 = 0x56, // < > | on UK/Germany keyboards
KC_F11 = 0x57,
KC_F12 = 0x58,
KC_F13 = 0x64, // (NEC PC98)
KC_F14 = 0x65, // (NEC PC98)
KC_F15 = 0x66, // (NEC PC98)
KC_KANA = 0x70, // (Japanese keyboard)
KC_ABNT_C1 = 0x73, // / ? on Portugese (Brazilian) keyboards
KC_CONVERT = 0x79, // (Japanese keyboard)
KC_NOCONVERT = 0x7B, // (Japanese keyboard)
KC_YEN = 0x7D, // (Japanese keyboard)
KC_ABNT_C2 = 0x7E, // Numpad . on Portugese (Brazilian) keyboards
KC_NUMPADEQUALS= 0x8D, // = on numeric keypad (NEC PC98)
KC_PREVTRACK = 0x90, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard)
KC_AT = 0x91, // (NEC PC98)
KC_COLON = 0x92, // (NEC PC98)
KC_UNDERLINE = 0x93, // (NEC PC98)
KC_KANJI = 0x94, // (Japanese keyboard)
KC_STOP = 0x95, // (NEC PC98)
KC_AX = 0x96, // (Japan AX)
KC_UNLABELED = 0x97, // (J3100)
KC_NEXTTRACK = 0x99, // Next Track
KC_NUMPADENTER = 0x9C, // Enter on numeric keypad
KC_RCONTROL = 0x9D,
KC_MUTE = 0xA0, // Mute
KC_CALCULATOR = 0xA1, // Calculator
KC_PLAYPAUSE = 0xA2, // Play / Pause
KC_MEDIASTOP = 0xA4, // Media Stop
KC_VOLUMEDOWN = 0xAE, // Volume -
KC_VOLUMEUP = 0xB0, // Volume +
KC_WEBHOME = 0xB2, // Web home
KC_NUMPADCOMMA = 0xB3, // , on numeric keypad (NEC PC98)
KC_DIVIDE = 0xB5, // / on numeric keypad
KC_SYSRQ = 0xB7,
KC_RALT = 0xB8, // right Alt
KC_PAUSE = 0xC5, // Pause
KC_HOME = 0xC7, // Home on arrow keypad
KC_UP = 0xC8, // UpArrow on arrow keypad
KC_PGUP = 0xC9, // PgUp on arrow keypad
KC_LEFT = 0xCB, // LeftArrow on arrow keypad
KC_RIGHT = 0xCD, // RightArrow on arrow keypad
KC_END = 0xCF, // End on arrow keypad
KC_DOWN = 0xD0, // DownArrow on arrow keypad
KC_PGDOWN = 0xD1, // PgDn on arrow keypad
KC_INSERT = 0xD2, // Insert on arrow keypad
KC_DELETE = 0xD3, // Delete on arrow keypad
KC_LWIN = 0xDB, // Left Windows key
KC_RWIN = 0xDC, // Right Windows key
KC_APPS = 0xDD, // AppMenu key
KC_POWER = 0xDE, // System Power
KC_SLEEP = 0xDF, // System Sleep
KC_WAKE = 0xE3, // System Wake
KC_WEBSEARCH = 0xE5, // Web Search
KC_WEBFAVORITES= 0xE6, // Web Favorites
KC_WEBREFRESH = 0xE7, // Web Refresh
KC_WEBSTOP = 0xE8, // Web Stop
KC_WEBFORWARD = 0xE9, // Web Forward
KC_WEBBACK = 0xEA, // Web Back
KC_MYCOMPUTER = 0xEB, // My Computer
KC_MAIL = 0xEC, // Mail
KC_MEDIASELECT = 0xED // Media Select
};
enum PlatformEventType {
EventNone = 0,
EventMouseAction = 1,
@ -203,7 +54,7 @@ struct PlatformEvent {
Point mousePos;
Point mouseMoved;
char keychar;
uchar keycode;
Fw::Key keycode;
bool ctrl;
bool shift;
bool alt;

View File

@ -62,7 +62,7 @@ struct X11PlatformPrivate {
int y;
int lastTicks;
std::string clipboardText;
std::map<int, uchar> keyMap;
std::map<int, Fw::Key> keyMap;
PlatformEvent inputEvent;
} x11;
@ -89,145 +89,154 @@ void Platform::init(PlatformListener* platformListener, const char *appName)
x11.maximizeOnFirstShow = false;
m_listener = platformListener;
// setup keymap
x11.keyMap[XK_1] = KC_1;
x11.keyMap[XK_2] = KC_2;
x11.keyMap[XK_3] = KC_3;
x11.keyMap[XK_4] = KC_4;
x11.keyMap[XK_5] = KC_5;
x11.keyMap[XK_6] = KC_6;
x11.keyMap[XK_7] = KC_7;
x11.keyMap[XK_8] = KC_8;
x11.keyMap[XK_9] = KC_9;
x11.keyMap[XK_0] = KC_0;
x11.keyMap[XK_Escape] = Fw::KeyEscape;
x11.keyMap[XK_Tab] = Fw::KeyTab;
x11.keyMap[XK_Return] = Fw::KeyReturn;
x11.keyMap[XK_BackSpace] = Fw::KeyBackspace;
x11.keyMap[XK_BackSpace] = KC_BACK;
x11.keyMap[XK_Page_Up] = Fw::KeyPageUp;
x11.keyMap[XK_Page_Down] = Fw::KeyPageDown;
x11.keyMap[XK_Home] = Fw::KeyHome;
x11.keyMap[XK_End] = Fw::KeyEnd;
x11.keyMap[XK_Insert] = Fw::KeyInsert;
x11.keyMap[XK_Delete] = Fw::KeyDelete;
x11.keyMap[XK_minus] = KC_MINUS;
x11.keyMap[XK_equal] = KC_EQUALS;
x11.keyMap[XK_space] = KC_SPACE;
x11.keyMap[XK_comma] = KC_COMMA;
x11.keyMap[XK_period] = KC_PERIOD;
x11.keyMap[XK_Up] = Fw::KeyUp;
x11.keyMap[XK_Down] = Fw::KeyDown;
x11.keyMap[XK_Left] = Fw::KeyLeft;
x11.keyMap[XK_Right] = Fw::KeyRight;
x11.keyMap[XK_backslash] = KC_BACKSLASH;
x11.keyMap[XK_slash] = KC_SLASH;
x11.keyMap[XK_bracketleft] = KC_LBRACKET;
x11.keyMap[XK_bracketright] = KC_RBRACKET;
x11.keyMap[XK_Num_Lock] = Fw::KeyNumLock;
x11.keyMap[XK_Scroll_Lock] = Fw::KeyScrollLock;
x11.keyMap[XK_Caps_Lock] = Fw::KeyCapsLock;
x11.keyMap[XK_Print] = Fw::KeyPrintScreen;
x11.keyMap[XK_Pause] = Fw::KeyPause;
x11.keyMap[XK_Escape] = KC_ESCAPE;
x11.keyMap[XK_Caps_Lock] = KC_CAPITAL;
x11.keyMap[XK_Control_L] = Fw::KeyCtrl;
x11.keyMap[XK_Control_R] = Fw::KeyCtrl;
x11.keyMap[XK_Shift_R] = Fw::KeyShift;
x11.keyMap[XK_Shift_L] = Fw::KeyShift;
x11.keyMap[XK_Alt_R] = Fw::KeyAlt;
x11.keyMap[XK_Alt_L] = Fw::KeyAltGr;
x11.keyMap[XK_Meta_L] = Fw::KeyMeta;
x11.keyMap[XK_Meta_R] = Fw::KeyMeta;
x11.keyMap[XK_Menu] = Fw::KeyMenu;
x11.keyMap[XK_Tab] = KC_TAB;
x11.keyMap[XK_Return] = KC_RETURN;
x11.keyMap[XK_Control_L] = KC_LCONTROL;
x11.keyMap[XK_Control_R] = KC_RCONTROL;
x11.keyMap[XK_colon] = KC_COLON;
x11.keyMap[XK_semicolon] = KC_SEMICOLON;
x11.keyMap[XK_apostrophe] = KC_APOSTROPHE;
x11.keyMap[XK_grave] = KC_GRAVE;
x11.keyMap[XK_b] = KC_B;
x11.keyMap[XK_a] = KC_A;
x11.keyMap[XK_c] = KC_C;
x11.keyMap[XK_d] = KC_D;
x11.keyMap[XK_e] = KC_E;
x11.keyMap[XK_f] = KC_F;
x11.keyMap[XK_g] = KC_G;
x11.keyMap[XK_h] = KC_H;
x11.keyMap[XK_i] = KC_I;
x11.keyMap[XK_j] = KC_J;
x11.keyMap[XK_k] = KC_K;
x11.keyMap[XK_l] = KC_L;
x11.keyMap[XK_m] = KC_M;
x11.keyMap[XK_n] = KC_N;
x11.keyMap[XK_o] = KC_O;
x11.keyMap[XK_p] = KC_P;
x11.keyMap[XK_q] = KC_Q;
x11.keyMap[XK_r] = KC_R;
x11.keyMap[XK_s] = KC_S;
x11.keyMap[XK_t] = KC_T;
x11.keyMap[XK_u] = KC_U;
x11.keyMap[XK_v] = KC_V;
x11.keyMap[XK_w] = KC_W;
x11.keyMap[XK_x] = KC_X;
x11.keyMap[XK_y] = KC_Y;
x11.keyMap[XK_z] = KC_Z;
x11.keyMap[XK_F1] = KC_F1;
x11.keyMap[XK_F2] = KC_F2;
x11.keyMap[XK_F3] = KC_F3;
x11.keyMap[XK_F4] = KC_F4;
x11.keyMap[XK_F5] = KC_F5;
x11.keyMap[XK_F6] = KC_F6;
x11.keyMap[XK_F7] = KC_F7;
x11.keyMap[XK_F8] = KC_F8;
x11.keyMap[XK_F9] = KC_F9;
x11.keyMap[XK_F10] = KC_F10;
x11.keyMap[XK_F11] = KC_F11;
x11.keyMap[XK_F12] = KC_F12;
x11.keyMap[XK_F13] = KC_F13;
x11.keyMap[XK_F14] = KC_F14;
x11.keyMap[XK_F15] = KC_F15;
// ascii characters
x11.keyMap[XK_space] = Fw::KeySpace;
x11.keyMap[XK_exclam] = Fw::KeyExclamation;
x11.keyMap[XK_quotedbl] = Fw::KeyQuote;
x11.keyMap[XK_numbersign] = Fw::KeyNumberSign;
x11.keyMap[XK_dollar] = Fw::KeyDollar;
x11.keyMap[XK_percent] = Fw::KeyPercent;
x11.keyMap[XK_ampersand] = Fw::KeyAmpersand;
x11.keyMap[XK_apostrophe] = Fw::KeyApostrophe;
x11.keyMap[XK_parenleft] = Fw::KeyLeftParen;
x11.keyMap[XK_parenright] = Fw::KeyRightParen;
x11.keyMap[XK_asterisk] = Fw::KeyAsterisk;
x11.keyMap[XK_plus] = Fw::KeyPlus;
x11.keyMap[XK_comma] = Fw::KeyComma;
x11.keyMap[XK_minus] = Fw::KeyMinus;
x11.keyMap[XK_period] = Fw::KeyPeriod;
x11.keyMap[XK_slash] = Fw::KeySlash;
x11.keyMap[XK_1] = Fw::Key1;
x11.keyMap[XK_2] = Fw::Key2;
x11.keyMap[XK_3] = Fw::Key3;
x11.keyMap[XK_4] = Fw::Key4;
x11.keyMap[XK_5] = Fw::Key5;
x11.keyMap[XK_6] = Fw::Key6;
x11.keyMap[XK_7] = Fw::Key7;
x11.keyMap[XK_8] = Fw::Key8;
x11.keyMap[XK_9] = Fw::Key9;
x11.keyMap[XK_0] = Fw::Key0;
x11.keyMap[XK_colon] = Fw::KeyColon;
x11.keyMap[XK_semicolon] = Fw::KeySemicolon;
x11.keyMap[XK_less] = Fw::KeyLess;
x11.keyMap[XK_equal] = Fw::KeyEqual;
x11.keyMap[XK_greater] = Fw::KeyGreater;
x11.keyMap[XK_question] = Fw::KeyQuestion;
x11.keyMap[XK_at] = Fw::KeyAtSign;
x11.keyMap[XK_a] = Fw::KeyA;
x11.keyMap[XK_b] = Fw::KeyB;
x11.keyMap[XK_c] = Fw::KeyC;
x11.keyMap[XK_d] = Fw::KeyD;
x11.keyMap[XK_e] = Fw::KeyE;
x11.keyMap[XK_f] = Fw::KeyF;
x11.keyMap[XK_g] = Fw::KeyG;
x11.keyMap[XK_h] = Fw::KeyH;
x11.keyMap[XK_i] = Fw::KeyI;
x11.keyMap[XK_j] = Fw::KeyJ;
x11.keyMap[XK_k] = Fw::KeyK;
x11.keyMap[XK_l] = Fw::KeyL;
x11.keyMap[XK_m] = Fw::KeyM;
x11.keyMap[XK_n] = Fw::KeyN;
x11.keyMap[XK_o] = Fw::KeyO;
x11.keyMap[XK_p] = Fw::KeyP;
x11.keyMap[XK_q] = Fw::KeyQ;
x11.keyMap[XK_r] = Fw::KeyR;
x11.keyMap[XK_s] = Fw::KeyS;
x11.keyMap[XK_t] = Fw::KeyT;
x11.keyMap[XK_u] = Fw::KeyU;
x11.keyMap[XK_v] = Fw::KeyV;
x11.keyMap[XK_w] = Fw::KeyW;
x11.keyMap[XK_x] = Fw::KeyX;
x11.keyMap[XK_y] = Fw::KeyY;
x11.keyMap[XK_z] = Fw::KeyZ;
x11.keyMap[XK_bracketleft] = Fw::KeyLeftBracket;
x11.keyMap[XK_backslash] = Fw::KeyBackslash;
x11.keyMap[XK_bracketright] = Fw::KeyRightBracket;
x11.keyMap[XK_asciicircum] = Fw::KeyCaret;
x11.keyMap[XK_underscore] = Fw::KeyUnderscore;
x11.keyMap[XK_grave] = Fw::KeyGrave;
x11.keyMap[XK_braceleft] = Fw::KeyLeftCurly;
x11.keyMap[XK_bar] = Fw::KeyBar;
x11.keyMap[XK_braceright] = Fw::KeyRightCurly;
x11.keyMap[XK_asciitilde] = Fw::KeyTilde;
// keypad
x11.keyMap[XK_KP_0] = KC_NUMPAD0;
x11.keyMap[XK_KP_1] = KC_NUMPAD1;
x11.keyMap[XK_KP_2] = KC_NUMPAD2;
x11.keyMap[XK_KP_3] = KC_NUMPAD3;
x11.keyMap[XK_KP_4] = KC_NUMPAD4;
x11.keyMap[XK_KP_5] = KC_NUMPAD5;
x11.keyMap[XK_KP_6] = KC_NUMPAD6;
x11.keyMap[XK_KP_7] = KC_NUMPAD7;
x11.keyMap[XK_KP_8] = KC_NUMPAD8;
x11.keyMap[XK_KP_9] = KC_NUMPAD9;
x11.keyMap[XK_KP_Add] = KC_ADD;
x11.keyMap[XK_KP_Subtract] = KC_SUBTRACT;
x11.keyMap[XK_KP_Decimal] = KC_DECIMAL;
x11.keyMap[XK_KP_Equal] = KC_NUMPADEQUALS;
x11.keyMap[XK_KP_Divide] = KC_DIVIDE;
x11.keyMap[XK_KP_Multiply] = KC_MULTIPLY;
x11.keyMap[XK_KP_Enter] = KC_RETURN;
x11.keyMap[XK_KP_Add] = Fw::KeyPlus;
x11.keyMap[XK_KP_Subtract] = Fw::KeyMinus;
x11.keyMap[XK_KP_Decimal] = Fw::KeyPeriod;
x11.keyMap[XK_KP_Divide] = Fw::KeySlash;
x11.keyMap[XK_KP_Multiply] = Fw::KeyAsterisk;
x11.keyMap[XK_KP_Enter] = Fw::KeyEnter;
// keypad with numlock off
x11.keyMap[XK_KP_Home] = KC_NUMPAD7;
x11.keyMap[XK_KP_Up] = KC_NUMPAD8;
x11.keyMap[XK_KP_Page_Up] = KC_NUMPAD9;
x11.keyMap[XK_KP_Left] = KC_NUMPAD4;
x11.keyMap[XK_KP_Begin] = KC_NUMPAD5;
x11.keyMap[XK_KP_Right] = KC_NUMPAD6;
x11.keyMap[XK_KP_End] = KC_NUMPAD1;
x11.keyMap[XK_KP_Down] = KC_NUMPAD2;
x11.keyMap[XK_KP_Page_Down] = KC_NUMPAD3;
x11.keyMap[XK_KP_Insert] = KC_NUMPAD0;
x11.keyMap[XK_KP_Delete] = KC_DECIMAL;
x11.keyMap[XK_KP_Up] = Fw::KeyUp;
x11.keyMap[XK_KP_Down] = Fw::KeyDown;
x11.keyMap[XK_KP_Left] = Fw::KeyLeft;
x11.keyMap[XK_KP_Right] = Fw::KeyRight;
x11.keyMap[XK_KP_Page_Up] = Fw::KeyPageUp;
x11.keyMap[XK_KP_Page_Down] = Fw::KeyPageDown;
x11.keyMap[XK_KP_Home] = Fw::KeyHome;
x11.keyMap[XK_KP_End] = Fw::KeyEnd;
x11.keyMap[XK_KP_Insert] = Fw::KeyInsert;
x11.keyMap[XK_KP_Delete] = Fw::KeyDelete;
x11.keyMap[XK_Up] = KC_UP;
x11.keyMap[XK_Down] = KC_DOWN;
x11.keyMap[XK_Left] = KC_LEFT;
x11.keyMap[XK_Right] = KC_RIGHT;
// keypad with numlock on
x11.keyMap[XK_KP_0] = Fw::Key0;
x11.keyMap[XK_KP_1] = Fw::Key1;
x11.keyMap[XK_KP_2] = Fw::Key2;
x11.keyMap[XK_KP_3] = Fw::Key3;
x11.keyMap[XK_KP_4] = Fw::Key4;
x11.keyMap[XK_KP_5] = Fw::Key5;
x11.keyMap[XK_KP_6] = Fw::Key6;
x11.keyMap[XK_KP_7] = Fw::Key7;
x11.keyMap[XK_KP_8] = Fw::Key8;
x11.keyMap[XK_KP_9] = Fw::Key9;
x11.keyMap[XK_Page_Up] = KC_PGUP;
x11.keyMap[XK_Page_Down] = KC_PGDOWN;
x11.keyMap[XK_Home] = KC_HOME;
x11.keyMap[XK_End] = KC_END;
x11.keyMap[XK_Num_Lock] = KC_NUMLOCK;
x11.keyMap[XK_Print] = KC_SYSRQ;
x11.keyMap[XK_Scroll_Lock] = KC_SCROLL;
x11.keyMap[XK_Pause] = KC_PAUSE;
x11.keyMap[XK_Shift_R] = KC_RSHIFT;
x11.keyMap[XK_Shift_L] = KC_LSHIFT;
x11.keyMap[XK_Alt_R] = KC_RALT;
x11.keyMap[XK_Alt_L] = KC_LALT;
x11.keyMap[XK_Insert] = KC_INSERT;
x11.keyMap[XK_Delete] = KC_DELETE;
x11.keyMap[XK_Super_L] = KC_LWIN;
x11.keyMap[XK_Super_R] = KC_RWIN;
x11.keyMap[XK_Menu] = KC_APPS;
x11.keyMap[XK_F1] = Fw::KeyF1;
x11.keyMap[XK_F2] = Fw::KeyF2;
x11.keyMap[XK_F3] = Fw::KeyF3;
x11.keyMap[XK_F4] = Fw::KeyF4;
x11.keyMap[XK_F5] = Fw::KeyF5;
x11.keyMap[XK_F6] = Fw::KeyF6;
x11.keyMap[XK_F7] = Fw::KeyF7;
x11.keyMap[XK_F8] = Fw::KeyF8;
x11.keyMap[XK_F9] = Fw::KeyF9;
x11.keyMap[XK_F10] = Fw::KeyF10;
x11.keyMap[XK_F11] = Fw::KeyF11;
x11.keyMap[XK_F12] = Fw::KeyF12;
// try to set a latin1 locales otherwise fallback to standard C locale
static char locales[][32] = { "en_US.iso88591", "iso88591", "en_US", "C" };
@ -369,12 +378,12 @@ void Platform::poll()
if(x11.keyMap.find(keysym) != x11.keyMap.end())
inputEvent.keycode = x11.keyMap[keysym];
else
inputEvent.keycode = KC_UNKNOWN;
inputEvent.keycode = Fw::KeyUnknown;
inputEvent.keycode = x11.keyMap[keysym];
inputEvent.type = (event.type == KeyPress) ? EventKeyDown : EventKeyUp;
if(inputEvent.keycode != KC_UNKNOWN || inputEvent.keychar != 0)
if(inputEvent.keycode != Fw::KeyUnknown || inputEvent.keychar != 0)
m_listener->onPlatformEvent(inputEvent);
break;
}

View File

@ -235,10 +235,8 @@ void UILineEdit::setText(const std::string& text)
{
if(m_text != text) {
m_text = text;
if(m_cursorPos >= 0) {
m_cursorPos = 0;
blinkCursor();
}
m_cursorPos = text.length();
blinkCursor();
update();
}
}
@ -391,24 +389,24 @@ void UILineEdit::onFocusChange(bool focused, Fw::FocusReason reason)
bool UILineEdit::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
{
if(keyCode == KC_DELETE) // erase right character
if(keyCode == Fw::KeyDelete) // erase right character
removeCharacter(true);
else if(keyCode == KC_BACK) // erase left character {
else if(keyCode == Fw::KeyBackspace) // erase left character {
removeCharacter(false);
else if(keyCode == KC_RIGHT) // move cursor right
else if(keyCode == Fw::KeyRight) // move cursor right
moveCursor(true);
else if(keyCode == KC_LEFT) // move cursor left
else if(keyCode == Fw::KeyLeft) // move cursor left
moveCursor(false);
else if(keyCode == KC_HOME) // move cursor to first character
else if(keyCode == Fw::KeyHome) // move cursor to first character
setCursorPos(0);
else if(keyCode == KC_END) // move cursor to last character
else if(keyCode == Fw::KeyEnd) // move cursor to last character
setCursorPos(m_text.length());
else if(keyCode == KC_V && keyboardModifiers == Fw::KeyboardCtrlModifier)
else if(keyCode == Fw::KeyV && keyboardModifiers == Fw::KeyboardCtrlModifier)
appendText(g_platform.getClipboardText());
else if(keyCode == KC_TAB) {
else if(keyCode == Fw::KeyTab) {
if(UIWidgetPtr parent = getParent())
parent->focusNextChild(Fw::TabFocusReason);
} else if(keyCode == KC_RETURN) {
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
if(m_onAction)
m_onAction();
} else if(keyChar != 0)

View File

@ -750,21 +750,24 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
void UIWidget::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
{
callLuaField("onGeometryUpdate", oldRect, newRect);
}
void UIWidget::onFocusChange(bool focused, Fw::FocusReason reason)
{
callLuaField("onHoverChange", focused, reason);
}
void UIWidget::onHoverChange(bool hovered)
{
callLuaField("onHoverChange", hovered);
}
bool UIWidget::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
{
if(callLuaField<bool>("onKeyPress", keyCode, keyChar, keyboardModifiers))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@ -787,6 +790,9 @@ bool UIWidget::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
bool UIWidget::onKeyRelease(uchar keyCode, char keyChar, int keyboardModifiers)
{
if(callLuaField<bool>("onKeyRelease", keyCode, keyChar, keyboardModifiers))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@ -809,6 +815,9 @@ bool UIWidget::onKeyRelease(uchar keyCode, char keyChar, int keyboardModifiers)
bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
{
if(callLuaField<bool>("onMousePress", mousePos, button))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@ -840,6 +849,9 @@ bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
{
if(callLuaField<bool>("onMouseRelease", mousePos, button))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@ -866,6 +878,9 @@ bool UIWidget::onMouseRelease(const Point& mousePos, Fw::MouseButton button)
bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
{
if(callLuaField<bool>("onMouseMove", mousePos, mouseMoved))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {
@ -887,6 +902,9 @@ bool UIWidget::onMouseMove(const Point& mousePos, const Point& mouseMoved)
bool UIWidget::onMouseWheel(const Point& mousePos, Fw::MouseWheelDirection direction)
{
if(callLuaField<bool>("onMouseWheel", mousePos, direction))
return true;
// do a backup of children list, because it may change while looping it
UIWidgetList children;
for(const UIWidgetPtr& child : m_children) {

View File

@ -294,25 +294,25 @@ void OTClient::onPlatformEvent(const PlatformEvent& event)
if(event.type == EventKeyDown) {
if(!event.ctrl && !event.alt && !event.shift) {
if(event.keycode == KC_UP)
if(event.keycode == Fw::KeyUp)
g_game.walk(Otc::North);
else if(event.keycode == KC_RIGHT)
else if(event.keycode == Fw::KeyRight)
g_game.walk(Otc::East);
else if(event.keycode == KC_DOWN)
else if(event.keycode == Fw::KeyDown)
g_game.walk(Otc::South);
else if(event.keycode == KC_LEFT)
else if(event.keycode == Fw::KeyLeft)
g_game.walk(Otc::West);
}
else if(event.ctrl && !event.alt && !event.shift) {
if(event.keycode == KC_UP)
if(event.keycode == Fw::KeyUp)
g_game.turn(Otc::North);
else if(event.keycode == KC_RIGHT)
else if(event.keycode == Fw::KeyRight)
g_game.turn(Otc::East);
else if(event.keycode == KC_DOWN)
else if(event.keycode == Fw::KeyDown)
g_game.turn(Otc::South);
else if(event.keycode == KC_LEFT)
else if(event.keycode == Fw::KeyLeft)
g_game.turn(Otc::West);
else if(event.keycode == KC_APOSTROPHE) {
else if(event.keycode == Fw::KeyApostrophe) {
// TODO: move these events to lua
UIWidgetPtr console = g_ui.getRootWidget()->getChildById("consolePanel");
if(!console->isExplicitlyVisible()) {