Browse Source

input: support up to 32 mouse buttons.

legacy
Sam Hocevar sam 11 years ago
parent
commit
c1428fc1f9
5 changed files with 27 additions and 25 deletions
  1. +18
    -16
      src/input/input.cpp
  2. +1
    -1
      src/input/input.h
  3. +3
    -3
      src/worldentity.cpp
  4. +1
    -1
      src/worldentity.h
  5. +4
    -4
      tutorial/11_fractal.cpp

+ 18
- 16
src/input/input.cpp View File

@@ -47,7 +47,7 @@ public:


private: private:
ivec2 mouse; ivec2 mouse;
ivec3 buttons;
uint32_t buttons;


static int const MAX_ENTITIES = 100; static int const MAX_ENTITIES = 100;
WorldEntity *entities[MAX_ENTITIES]; WorldEntity *entities[MAX_ENTITIES];
@@ -293,7 +293,7 @@ ivec2 Input::GetMousePos()
return data->mouse; return data->mouse;
} }


ivec3 Input::GetMouseButtons()
uint32_t Input::GetMouseButtons()
{ {
return data->buttons; return data->buttons;
} }
@@ -425,15 +425,15 @@ void Input::SetMousePos(ivec2 coord)
if (top != data->lastfocus) if (top != data->lastfocus)
data->entities[n]->m_pressed = data->buttons; data->entities[n]->m_pressed = data->buttons;
else else
data->entities[n]->m_clicked = ivec3(0);
data->entities[n]->m_clicked = 0;
} }
else else
{ {
data->entities[n]->m_mousepos = ivec2(-1); data->entities[n]->m_mousepos = ivec2(-1);
/* FIXME */ /* 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) void Input::SetMouseButton(int index)
{ {
data->buttons[index] = 1;
uint32_t flag = 1 << index;
data->buttons |= flag;


if (data->lastfocus) 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) void Input::UnsetMouseButton(int index)
{ {
data->buttons[index] = 0;
uint32_t flag = 1 << index;
data->buttons &= ~flag;


if (data->lastfocus) 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;
} }
} }




+ 1
- 1
src/input/input.h View File

@@ -411,7 +411,7 @@ public:


/* These methods are general queries */ /* These methods are general queries */
static ivec2 GetMousePos(); static ivec2 GetMousePos();
static ivec3 GetMouseButtons();
static uint32_t GetMouseButtons();


//BH : Shouldn't use this //BH : Shouldn't use this
static int GetButtonState(int button); static int GetButtonState(int button);


+ 3
- 3
src/worldentity.cpp View File

@@ -33,9 +33,9 @@ WorldEntity::WorldEntity()


m_mousepos = ivec2(0); m_mousepos = ivec2(0);
m_mousebuttons = ivec3(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() WorldEntity::~WorldEntity()


+ 1
- 1
src/worldentity.h View File

@@ -35,7 +35,7 @@ public:


ivec2 m_mousepos; ivec2 m_mousepos;
ivec3 m_mousebuttons; ivec3 m_mousebuttons;
ivec3 m_pressed, m_clicked, m_released;
uint32_t m_pressed, m_clicked, m_released;


protected: protected:
WorldEntity(); WorldEntity();


+ 4
- 4
tutorial/11_fractal.cpp View File

@@ -171,9 +171,9 @@ public:


rcmplx worldmouse = m_center + rcmplx(ScreenToWorldOffset(m_mousepos)); rcmplx worldmouse = m_center + rcmplx(ScreenToWorldOffset(m_mousepos));


ivec3 buttons = Input::GetMouseButtons();
uint32_t buttons = Input::GetMouseButtons();
#if !defined __CELLOS_LV2__ && !defined _XBOX #if !defined __CELLOS_LV2__ && !defined _XBOX
if (buttons[1])
if (buttons & 0x2)
{ {
if (!m_drag) 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; m_zoom_speed += zoom * seconds;
if (m_zoom_speed / zoom > 5e-3f) if (m_zoom_speed / zoom > 5e-3f)
m_zoom_speed = zoom * 5e-3f; m_zoom_speed = zoom * 5e-3f;


Loading…
Cancel
Save