00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "xrb_input_events.hpp"
00012
00013 #include "xrb_keymap.hpp"
00014 #include "xrb_screen.hpp"
00015 #include "xrb_util.hpp"
00016
00017 namespace Xrb
00018 {
00019
00020 EventInput::~EventInput () { }
00021
00022 EventKey::EventKey (
00023 Key::Code code,
00024 Key::Modifier modifier,
00025 Float time,
00026 EventType event_type)
00027 :
00028 EventInput(time, event_type)
00029 {
00030
00031 m_code = Singleton::KeyMap().MappedKey(code);
00032
00033 m_modifier = modifier;
00034
00035
00036 if (code >= Key::SPACE && code < Key::DELETE)
00037 m_modified_ascii = char(code);
00038 else
00039 m_modified_ascii = '\0';
00040
00041
00042 if ((m_modifier&Key::MOD_CAPS) != 0)
00043 m_modified_ascii = toupper(m_modified_ascii);
00044
00045
00046 if ((m_modifier&(Key::MOD_LSHIFT|Key::MOD_RSHIFT)) != 0)
00047 m_modified_ascii = Util::ShiftedAscii(m_modified_ascii);
00048
00049
00050 if ((m_modifier&Key::MOD_NUM) != 0)
00051 {
00052 switch (code)
00053 {
00054 case Key::KP0: m_modified_ascii = '0'; break;
00055 case Key::KP1: m_modified_ascii = '1'; break;
00056 case Key::KP2: m_modified_ascii = '2'; break;
00057 case Key::KP3: m_modified_ascii = '3'; break;
00058 case Key::KP4: m_modified_ascii = '4'; break;
00059 case Key::KP5: m_modified_ascii = '5'; break;
00060 case Key::KP6: m_modified_ascii = '6'; break;
00061 case Key::KP7: m_modified_ascii = '7'; break;
00062 case Key::KP8: m_modified_ascii = '8'; break;
00063 case Key::KP9: m_modified_ascii = '9'; break;
00064 case Key::KP_PERIOD: m_modified_ascii = '.'; break;
00065 default: break;
00066 }
00067 }
00068
00069
00070 switch (code)
00071 {
00072 case Key::KP_DIVIDE: m_modified_ascii = '/'; break;
00073 case Key::KP_MULTIPLY: m_modified_ascii = '*'; break;
00074 case Key::KP_MINUS: m_modified_ascii = '-'; break;
00075 case Key::KP_PLUS: m_modified_ascii = '+'; break;
00076 case Key::KP_EQUALS: m_modified_ascii = '='; break;
00077 default: break;
00078 }
00079 }
00080
00081 EventKey::~EventKey () { }
00082
00083 EventMouse::EventMouse (
00084 ScreenCoordVector2 const &position,
00085 Key::Modifier modifier,
00086 Float time,
00087 EventType event_type)
00088 :
00089 EventInput(time, event_type),
00090 m_position(position),
00091 m_modifier(modifier)
00092 { }
00093
00094 EventMouse::~EventMouse () { }
00095
00096 EventMouseButton::EventMouseButton (
00097 Key::Code button_code,
00098 ScreenCoordVector2 const &position,
00099 Key::Modifier modifier,
00100 Float time,
00101 EventType event_type)
00102 :
00103 EventMouse(position, modifier, time, event_type),
00104 m_button_code(button_code)
00105 { }
00106
00107 EventMouseButton::~EventMouseButton () { }
00108
00109 EventMouseMotion::EventMouseMotion (
00110 bool is_left_mouse_button_pressed,
00111 bool is_middle_mouse_button_pressed,
00112 bool is_right_mouse_button_pressed,
00113 ScreenCoordVector2 const &position,
00114 ScreenCoordVector2 const &delta,
00115 Key::Modifier modifier,
00116 Float time)
00117 :
00118 EventMouse(position, modifier, time, MOUSEMOTION),
00119 m_is_left_mouse_button_pressed(is_left_mouse_button_pressed),
00120 m_is_middle_mouse_button_pressed(is_middle_mouse_button_pressed),
00121 m_is_right_mouse_button_pressed(is_right_mouse_button_pressed),
00122 m_delta(delta)
00123 { }
00124
00125 }