diff --git a/src/input/input.cpp b/src/input/input.cpp index 22b80312..23b48b49 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -47,7 +47,7 @@ public: private: ivec2 mouse; - ivec3 buttons; + uint32_t buttons; static int const MAX_ENTITIES = 100; WorldEntity *entities[MAX_ENTITIES]; @@ -293,7 +293,7 @@ ivec2 Input::GetMousePos() return data->mouse; } -ivec3 Input::GetMouseButtons() +uint32_t Input::GetMouseButtons() { return data->buttons; } @@ -425,15 +425,15 @@ void Input::SetMousePos(ivec2 coord) if (top != data->lastfocus) data->entities[n]->m_pressed = data->buttons; else - data->entities[n]->m_clicked = ivec3(0); + data->entities[n]->m_clicked = 0; } else { data->entities[n]->m_mousepos = ivec2(-1); /* FIXME */ - data->entities[n]->m_released = ivec3(0); - data->entities[n]->m_pressed = ivec3(0); - data->entities[n]->m_clicked = ivec3(0); + data->entities[n]->m_released = 0; + data->entities[n]->m_pressed = 0; + data->entities[n]->m_clicked = 0; } } @@ -442,27 +442,29 @@ void Input::SetMousePos(ivec2 coord) void Input::SetMouseButton(int index) { - data->buttons[index] = 1; + uint32_t flag = 1 << index; + data->buttons |= flag; if (data->lastfocus) { - if (!data->lastfocus->m_pressed[index]) - data->lastfocus->m_clicked[index] = 1; - data->lastfocus->m_pressed[index] = 1; - data->lastfocus->m_released[index] = 0; + if (!(data->lastfocus->m_pressed & flag)) + data->lastfocus->m_clicked |= flag; + data->lastfocus->m_pressed |= flag; + data->lastfocus->m_released &= ~flag; } } void Input::UnsetMouseButton(int index) { - data->buttons[index] = 0; + uint32_t flag = 1 << index; + data->buttons &= ~flag; if (data->lastfocus) { - if (data->lastfocus->m_pressed[index]) - data->lastfocus->m_released[index] = 1; - data->lastfocus->m_pressed[index] = 0; - data->lastfocus->m_clicked[index] = 0; + if (!(data->lastfocus->m_pressed & flag)) + data->lastfocus->m_released |= flag; + data->lastfocus->m_pressed &= ~flag; + data->lastfocus->m_clicked &= ~flag; } } diff --git a/src/input/input.h b/src/input/input.h index 560786de..ffa1f40a 100644 --- a/src/input/input.h +++ b/src/input/input.h @@ -411,7 +411,7 @@ public: /* These methods are general queries */ static ivec2 GetMousePos(); - static ivec3 GetMouseButtons(); + static uint32_t GetMouseButtons(); //BH : Shouldn't use this static int GetButtonState(int button); diff --git a/src/worldentity.cpp b/src/worldentity.cpp index 1a052371..5bfcb623 100644 --- a/src/worldentity.cpp +++ b/src/worldentity.cpp @@ -33,9 +33,9 @@ WorldEntity::WorldEntity() m_mousepos = ivec2(0); m_mousebuttons = ivec3(0); - m_pressed = ivec3(0); - m_clicked = ivec3(0); - m_released = ivec3(0); + m_pressed = 0; + m_clicked = 0; + m_released = 0; } WorldEntity::~WorldEntity() diff --git a/src/worldentity.h b/src/worldentity.h index 4c6cc11a..0153f6e2 100644 --- a/src/worldentity.h +++ b/src/worldentity.h @@ -35,7 +35,7 @@ public: ivec2 m_mousepos; ivec3 m_mousebuttons; - ivec3 m_pressed, m_clicked, m_released; + uint32_t m_pressed, m_clicked, m_released; protected: WorldEntity(); diff --git a/tutorial/11_fractal.cpp b/tutorial/11_fractal.cpp index 267a0c5c..90799f47 100644 --- a/tutorial/11_fractal.cpp +++ b/tutorial/11_fractal.cpp @@ -171,9 +171,9 @@ public: rcmplx worldmouse = m_center + rcmplx(ScreenToWorldOffset(m_mousepos)); - ivec3 buttons = Input::GetMouseButtons(); + uint32_t buttons = Input::GetMouseButtons(); #if !defined __CELLOS_LV2__ && !defined _XBOX - if (buttons[1]) + if (buttons & 0x2) { if (!m_drag) { @@ -201,9 +201,9 @@ public: } } - if ((buttons[0] || buttons[2]) && m_mousepos.x != -1) + if (buttons & 0x5 && m_mousepos.x != -1) { - double zoom = buttons[0] ? -0.5 : 0.5; + double zoom = (buttons & 0x1) ? -0.5 : 0.5; m_zoom_speed += zoom * seconds; if (m_zoom_speed / zoom > 5e-3f) m_zoom_speed = zoom * 5e-3f;