WIP key&mouse support.

This commit is contained in:
bkaradzic 2013-01-17 23:22:38 -08:00
parent a2057d65aa
commit 91446e05a4
5 changed files with 178 additions and 146 deletions

View file

@ -12,6 +12,7 @@ namespace entry
{
enum Enum
{
None,
Left,
Middle,
Right,
@ -144,6 +145,7 @@ namespace entry
int32_t m_my;
MouseButton::Enum m_button;
bool m_down;
bool m_move;
};
struct SizeEvent : public Event

View file

@ -61,80 +61,80 @@ namespace entry
: m_exit(false)
{
memset(s_translateKey, 0, sizeof(s_translateKey) );
initTranslateKey(XK_Escape, Key::Esc);
initTranslateKey(XK_Return, Key::Return);
initTranslateKey(XK_Tab, Key::Tab);
initTranslateKey(XK_BackSpace, Key::Backspace);
initTranslateKey(XK_space, Key::Space);
initTranslateKey(XK_Up, Key::Up);
initTranslateKey(XK_Down, Key::Down);
initTranslateKey(XK_Left, Key::Left);
initTranslateKey(XK_Right, Key::Right);
initTranslateKey(XK_Page_Up, Key::PageUp);
initTranslateKey(XK_Page_Down, Key::PageUp);
initTranslateKey(XK_Home, Key::Home);
initTranslateKey(XK_KP_End, Key::End);
initTranslateKey(XK_Print, Key::Print);
initTranslateKey(XK_equal, Key::Plus);
initTranslateKey(XK_minus, Key::Minus);
initTranslateKey(XK_F1, Key::F1);
initTranslateKey(XK_F2, Key::F2);
initTranslateKey(XK_F3, Key::F3);
initTranslateKey(XK_F4, Key::F4);
initTranslateKey(XK_F5, Key::F5);
initTranslateKey(XK_F6, Key::F6);
initTranslateKey(XK_F7, Key::F7);
initTranslateKey(XK_F8, Key::F8);
initTranslateKey(XK_F9, Key::F9);
initTranslateKey(XK_F10, Key::F10);
initTranslateKey(XK_F11, Key::F11);
initTranslateKey(XK_F12, Key::F12);
initTranslateKey(XK_KP_Insert, Key::NumPad0);
initTranslateKey(XK_KP_End, Key::NumPad1);
initTranslateKey(XK_KP_Down, Key::NumPad2);
initTranslateKey(XK_Escape, Key::Esc);
initTranslateKey(XK_Return, Key::Return);
initTranslateKey(XK_Tab, Key::Tab);
initTranslateKey(XK_BackSpace, Key::Backspace);
initTranslateKey(XK_space, Key::Space);
initTranslateKey(XK_Up, Key::Up);
initTranslateKey(XK_Down, Key::Down);
initTranslateKey(XK_Left, Key::Left);
initTranslateKey(XK_Right, Key::Right);
initTranslateKey(XK_Page_Up, Key::PageUp);
initTranslateKey(XK_Page_Down, Key::PageUp);
initTranslateKey(XK_Home, Key::Home);
initTranslateKey(XK_KP_End, Key::End);
initTranslateKey(XK_Print, Key::Print);
initTranslateKey(XK_equal, Key::Plus);
initTranslateKey(XK_minus, Key::Minus);
initTranslateKey(XK_F1, Key::F1);
initTranslateKey(XK_F2, Key::F2);
initTranslateKey(XK_F3, Key::F3);
initTranslateKey(XK_F4, Key::F4);
initTranslateKey(XK_F5, Key::F5);
initTranslateKey(XK_F6, Key::F6);
initTranslateKey(XK_F7, Key::F7);
initTranslateKey(XK_F8, Key::F8);
initTranslateKey(XK_F9, Key::F9);
initTranslateKey(XK_F10, Key::F10);
initTranslateKey(XK_F11, Key::F11);
initTranslateKey(XK_F12, Key::F12);
initTranslateKey(XK_KP_Insert, Key::NumPad0);
initTranslateKey(XK_KP_End, Key::NumPad1);
initTranslateKey(XK_KP_Down, Key::NumPad2);
initTranslateKey(XK_KP_Page_Down, Key::NumPad3);
initTranslateKey(XK_KP_Left, Key::NumPad4);
initTranslateKey(XK_KP_Begin, Key::NumPad5);
initTranslateKey(XK_KP_Right, Key::NumPad6);
initTranslateKey(XK_KP_Home, Key::NumPad7);
initTranslateKey(XK_KP_Up, Key::NumPad8);
initTranslateKey(XK_KP_Page_Up, Key::NumPad9);
initTranslateKey('0', Key::Key0);
initTranslateKey('1', Key::Key1);
initTranslateKey('2', Key::Key2);
initTranslateKey('3', Key::Key3);
initTranslateKey('4', Key::Key4);
initTranslateKey('5', Key::Key5);
initTranslateKey('6', Key::Key6);
initTranslateKey('7', Key::Key7);
initTranslateKey('8', Key::Key8);
initTranslateKey('9', Key::Key9);
initTranslateKey('a', Key::KeyA);
initTranslateKey('b', Key::KeyB);
initTranslateKey('c', Key::KeyC);
initTranslateKey('d', Key::KeyD);
initTranslateKey('e', Key::KeyE);
initTranslateKey('f', Key::KeyF);
initTranslateKey('g', Key::KeyG);
initTranslateKey('h', Key::KeyH);
initTranslateKey('i', Key::KeyI);
initTranslateKey('j', Key::KeyJ);
initTranslateKey('k', Key::KeyK);
initTranslateKey('l', Key::KeyL);
initTranslateKey('m', Key::KeyM);
initTranslateKey('n', Key::KeyN);
initTranslateKey('o', Key::KeyO);
initTranslateKey('p', Key::KeyP);
initTranslateKey('q', Key::KeyQ);
initTranslateKey('r', Key::KeyR);
initTranslateKey('s', Key::KeyS);
initTranslateKey('t', Key::KeyT);
initTranslateKey('u', Key::KeyU);
initTranslateKey('v', Key::KeyV);
initTranslateKey('w', Key::KeyW);
initTranslateKey('x', Key::KeyX);
initTranslateKey('y', Key::KeyY);
initTranslateKey('z', Key::KeyZ);
initTranslateKey(XK_KP_Left, Key::NumPad4);
initTranslateKey(XK_KP_Begin, Key::NumPad5);
initTranslateKey(XK_KP_Right, Key::NumPad6);
initTranslateKey(XK_KP_Home, Key::NumPad7);
initTranslateKey(XK_KP_Up, Key::NumPad8);
initTranslateKey(XK_KP_Page_Up, Key::NumPad9);
initTranslateKey('0', Key::Key0);
initTranslateKey('1', Key::Key1);
initTranslateKey('2', Key::Key2);
initTranslateKey('3', Key::Key3);
initTranslateKey('4', Key::Key4);
initTranslateKey('5', Key::Key5);
initTranslateKey('6', Key::Key6);
initTranslateKey('7', Key::Key7);
initTranslateKey('8', Key::Key8);
initTranslateKey('9', Key::Key9);
initTranslateKey('a', Key::KeyA);
initTranslateKey('b', Key::KeyB);
initTranslateKey('c', Key::KeyC);
initTranslateKey('d', Key::KeyD);
initTranslateKey('e', Key::KeyE);
initTranslateKey('f', Key::KeyF);
initTranslateKey('g', Key::KeyG);
initTranslateKey('h', Key::KeyH);
initTranslateKey('i', Key::KeyI);
initTranslateKey('j', Key::KeyJ);
initTranslateKey('k', Key::KeyK);
initTranslateKey('l', Key::KeyL);
initTranslateKey('m', Key::KeyM);
initTranslateKey('n', Key::KeyN);
initTranslateKey('o', Key::KeyO);
initTranslateKey('p', Key::KeyP);
initTranslateKey('q', Key::KeyQ);
initTranslateKey('r', Key::KeyR);
initTranslateKey('s', Key::KeyS);
initTranslateKey('t', Key::KeyT);
initTranslateKey('u', Key::KeyU);
initTranslateKey('v', Key::KeyV);
initTranslateKey('w', Key::KeyW);
initTranslateKey('x', Key::KeyX);
initTranslateKey('y', Key::KeyY);
initTranslateKey('z', Key::KeyZ);
}
int32_t run(int _argc, char** _argv)

View file

@ -34,6 +34,18 @@ namespace entry
m_queue.push(ev);
}
void postMouseEvent(int32_t _mx, int32_t _my)
{
MouseEvent* ev = new MouseEvent;
ev->m_type = Event::Mouse;
ev->m_mx = _mx;
ev->m_my = _my;
ev->m_button = MouseButton::None;
ev->m_down = false;
ev->m_move = true;
m_queue.push(ev);
}
void postMouseEvent(int32_t _mx, int32_t _my, MouseButton::Enum _button, bool _down)
{
MouseEvent* ev = new MouseEvent;
@ -42,6 +54,7 @@ namespace entry
ev->m_my = _my;
ev->m_button = _button;
ev->m_down = _down;
ev->m_move = false;
m_queue.push(ev);
}

View file

@ -77,80 +77,80 @@ namespace entry
, m_exit(false)
{
memset(s_translateKey, 0, sizeof(s_translateKey) );
s_translateKey[VK_ESCAPE] = Key::Esc;
s_translateKey[VK_RETURN] = Key::Return;
s_translateKey[VK_TAB] = Key::Tab;
s_translateKey[VK_BACK] = Key::Backspace;
s_translateKey[VK_SPACE] = Key::Space;
s_translateKey[VK_UP] = Key::Up;
s_translateKey[VK_DOWN] = Key::Down;
s_translateKey[VK_LEFT] = Key::Left;
s_translateKey[VK_RIGHT] = Key::Right;
s_translateKey[VK_PRIOR] = Key::PageUp;
s_translateKey[VK_NEXT] = Key::PageUp;
s_translateKey[VK_HOME] = Key::Home;
s_translateKey[VK_END] = Key::End;
s_translateKey[VK_SNAPSHOT] = Key::Print;
s_translateKey[VK_OEM_PLUS] = Key::Plus;
s_translateKey[VK_ESCAPE] = Key::Esc;
s_translateKey[VK_RETURN] = Key::Return;
s_translateKey[VK_TAB] = Key::Tab;
s_translateKey[VK_BACK] = Key::Backspace;
s_translateKey[VK_SPACE] = Key::Space;
s_translateKey[VK_UP] = Key::Up;
s_translateKey[VK_DOWN] = Key::Down;
s_translateKey[VK_LEFT] = Key::Left;
s_translateKey[VK_RIGHT] = Key::Right;
s_translateKey[VK_PRIOR] = Key::PageUp;
s_translateKey[VK_NEXT] = Key::PageUp;
s_translateKey[VK_HOME] = Key::Home;
s_translateKey[VK_END] = Key::End;
s_translateKey[VK_SNAPSHOT] = Key::Print;
s_translateKey[VK_OEM_PLUS] = Key::Plus;
s_translateKey[VK_OEM_MINUS] = Key::Minus;
s_translateKey[VK_F1] = Key::F1;
s_translateKey[VK_F2] = Key::F2;
s_translateKey[VK_F3] = Key::F3;
s_translateKey[VK_F4] = Key::F4;
s_translateKey[VK_F5] = Key::F5;
s_translateKey[VK_F6] = Key::F6;
s_translateKey[VK_F7] = Key::F7;
s_translateKey[VK_F8] = Key::F8;
s_translateKey[VK_F9] = Key::F9;
s_translateKey[VK_F10] = Key::F10;
s_translateKey[VK_F11] = Key::F11;
s_translateKey[VK_F12] = Key::F12;
s_translateKey[VK_NUMPAD0] = Key::NumPad0;
s_translateKey[VK_NUMPAD1] = Key::NumPad1;
s_translateKey[VK_NUMPAD2] = Key::NumPad2;
s_translateKey[VK_NUMPAD3] = Key::NumPad3;
s_translateKey[VK_NUMPAD4] = Key::NumPad4;
s_translateKey[VK_NUMPAD5] = Key::NumPad5;
s_translateKey[VK_NUMPAD6] = Key::NumPad6;
s_translateKey[VK_NUMPAD7] = Key::NumPad7;
s_translateKey[VK_NUMPAD8] = Key::NumPad8;
s_translateKey[VK_NUMPAD9] = Key::NumPad9;
s_translateKey['0'] = Key::Key0;
s_translateKey['1'] = Key::Key1;
s_translateKey['2'] = Key::Key2;
s_translateKey['3'] = Key::Key3;
s_translateKey['4'] = Key::Key4;
s_translateKey['5'] = Key::Key5;
s_translateKey['6'] = Key::Key6;
s_translateKey['7'] = Key::Key7;
s_translateKey['8'] = Key::Key8;
s_translateKey['9'] = Key::Key9;
s_translateKey['A'] = Key::KeyA;
s_translateKey['B'] = Key::KeyB;
s_translateKey['C'] = Key::KeyC;
s_translateKey['D'] = Key::KeyD;
s_translateKey['E'] = Key::KeyE;
s_translateKey['F'] = Key::KeyF;
s_translateKey['G'] = Key::KeyG;
s_translateKey['H'] = Key::KeyH;
s_translateKey['I'] = Key::KeyI;
s_translateKey['J'] = Key::KeyJ;
s_translateKey['K'] = Key::KeyK;
s_translateKey['L'] = Key::KeyL;
s_translateKey['M'] = Key::KeyM;
s_translateKey['N'] = Key::KeyN;
s_translateKey['O'] = Key::KeyO;
s_translateKey['P'] = Key::KeyP;
s_translateKey['Q'] = Key::KeyQ;
s_translateKey['R'] = Key::KeyR;
s_translateKey['S'] = Key::KeyS;
s_translateKey['T'] = Key::KeyT;
s_translateKey['U'] = Key::KeyU;
s_translateKey['V'] = Key::KeyV;
s_translateKey['W'] = Key::KeyW;
s_translateKey['X'] = Key::KeyX;
s_translateKey['Y'] = Key::KeyY;
s_translateKey['Z'] = Key::KeyZ;
s_translateKey[VK_F1] = Key::F1;
s_translateKey[VK_F2] = Key::F2;
s_translateKey[VK_F3] = Key::F3;
s_translateKey[VK_F4] = Key::F4;
s_translateKey[VK_F5] = Key::F5;
s_translateKey[VK_F6] = Key::F6;
s_translateKey[VK_F7] = Key::F7;
s_translateKey[VK_F8] = Key::F8;
s_translateKey[VK_F9] = Key::F9;
s_translateKey[VK_F10] = Key::F10;
s_translateKey[VK_F11] = Key::F11;
s_translateKey[VK_F12] = Key::F12;
s_translateKey[VK_NUMPAD0] = Key::NumPad0;
s_translateKey[VK_NUMPAD1] = Key::NumPad1;
s_translateKey[VK_NUMPAD2] = Key::NumPad2;
s_translateKey[VK_NUMPAD3] = Key::NumPad3;
s_translateKey[VK_NUMPAD4] = Key::NumPad4;
s_translateKey[VK_NUMPAD5] = Key::NumPad5;
s_translateKey[VK_NUMPAD6] = Key::NumPad6;
s_translateKey[VK_NUMPAD7] = Key::NumPad7;
s_translateKey[VK_NUMPAD8] = Key::NumPad8;
s_translateKey[VK_NUMPAD9] = Key::NumPad9;
s_translateKey['0'] = Key::Key0;
s_translateKey['1'] = Key::Key1;
s_translateKey['2'] = Key::Key2;
s_translateKey['3'] = Key::Key3;
s_translateKey['4'] = Key::Key4;
s_translateKey['5'] = Key::Key5;
s_translateKey['6'] = Key::Key6;
s_translateKey['7'] = Key::Key7;
s_translateKey['8'] = Key::Key8;
s_translateKey['9'] = Key::Key9;
s_translateKey['A'] = Key::KeyA;
s_translateKey['B'] = Key::KeyB;
s_translateKey['C'] = Key::KeyC;
s_translateKey['D'] = Key::KeyD;
s_translateKey['E'] = Key::KeyE;
s_translateKey['F'] = Key::KeyF;
s_translateKey['G'] = Key::KeyG;
s_translateKey['H'] = Key::KeyH;
s_translateKey['I'] = Key::KeyI;
s_translateKey['J'] = Key::KeyJ;
s_translateKey['K'] = Key::KeyK;
s_translateKey['L'] = Key::KeyL;
s_translateKey['M'] = Key::KeyM;
s_translateKey['N'] = Key::KeyN;
s_translateKey['O'] = Key::KeyO;
s_translateKey['P'] = Key::KeyP;
s_translateKey['Q'] = Key::KeyQ;
s_translateKey['R'] = Key::KeyR;
s_translateKey['S'] = Key::KeyS;
s_translateKey['T'] = Key::KeyT;
s_translateKey['U'] = Key::KeyU;
s_translateKey['V'] = Key::KeyV;
s_translateKey['W'] = Key::KeyW;
s_translateKey['X'] = Key::KeyX;
s_translateKey['Y'] = Key::KeyY;
s_translateKey['Z'] = Key::KeyZ;
}
int32_t main(int _argc, char** _argv)
@ -344,6 +344,14 @@ namespace entry
}
break;
case WM_MOUSEMOVE:
{
int32_t mx = GET_X_LPARAM(_lparam);
int32_t my = GET_Y_LPARAM(_lparam);
m_eventQueue.postMouseEvent(mx, my);
}
break;
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK:

View file

@ -23,6 +23,15 @@ inline bool processEvents(uint32_t& _width, uint32_t& _height, uint32_t& _debug)
case Event::Exit:
return true;
case Event::Mouse:
{
// const MouseEvent* mouse = static_cast<const MouseEvent*>(ev);
// if (mouse->m_move)
// {
// }
}
break;
case Event::Key:
{
const KeyEvent* key = static_cast<const KeyEvent*>(ev);