Pārlūkot izejas kodu

input: support up to 32 mouse buttons.

legacy
Sam Hocevar sam pirms 11 gadiem
vecāks
revīzija
c1428fc1f9
5 mainītis faili ar 27 papildinājumiem un 25 dzēšanām
  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 Parādīt failu

@@ -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;
}
}



+ 1
- 1
src/input/input.h Parādīt failu

@@ -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);


+ 3
- 3
src/worldentity.cpp Parādīt failu

@@ -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()


+ 1
- 1
src/worldentity.h Parādīt failu

@@ -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();


+ 4
- 4
tutorial/11_fractal.cpp Parādīt failu

@@ -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;


Notiek ielāde…
Atcelt
Saglabāt