Browse Source

sdl: fix touchscreen event handling by first applying mouse moves, then

button changes.
legacy
Sam Hocevar sam 13 years ago
parent
commit
bf5e4ba76e
2 changed files with 40 additions and 24 deletions
  1. +7
    -7
      src/input.cpp
  2. +33
    -17
      src/sdlinput.cpp

+ 7
- 7
src/input.cpp View File

@@ -112,7 +112,7 @@ void Input::SetMousePos(vec2i coord)
{ {
data->mouse = coord; data->mouse = coord;


WorldEntity *best = NULL;
WorldEntity *top = NULL;


for (int n = 0; n < data->nentities; n++) for (int n = 0; n < data->nentities; n++)
{ {
@@ -122,16 +122,16 @@ void Input::SetMousePos(vec2i coord)
|| coord.y >= data->entities[n]->bbox[1].y) || coord.y >= data->entities[n]->bbox[1].y)
continue; continue;


if (!best || best->bbox[1].z < data->entities[n]->bbox[1].z)
best = data->entities[n];
if (!top || top->bbox[1].z < data->entities[n]->bbox[1].z)
top = data->entities[n];
} }


for (int n = 0; n < data->nentities; n++) for (int n = 0; n < data->nentities; n++)
{ {
if (data->entities[n] == best)
if (data->entities[n] == top)
{ {
data->entities[n]->mousepos = (vec2i)((vec3i)coord - best->bbox[0]);
if (best != data->lastfocus)
data->entities[n]->mousepos = (vec2i)((vec3i)coord - top->bbox[0]);
if (top != data->lastfocus)
data->entities[n]->pressed = data->buttons; data->entities[n]->pressed = data->buttons;
else else
data->entities[n]->clicked = 0; data->entities[n]->clicked = 0;
@@ -146,7 +146,7 @@ void Input::SetMousePos(vec2i coord)
} }
} }


data->lastfocus = best;
data->lastfocus = top;
} }


void Input::SetMouseButton(int index) void Input::SetMouseButton(int index)


+ 33
- 17
src/sdlinput.cpp View File

@@ -29,7 +29,7 @@ class SdlInputData
friend class SdlInput; friend class SdlInput;


private: private:
int mx, my;
static vec2i GetMousePos();
}; };


/* /*
@@ -41,8 +41,6 @@ SdlInput::SdlInput()
{ {
SDL_Init(SDL_INIT_TIMER); SDL_Init(SDL_INIT_TIMER);


SDL_GetMouseState(&data->mx, &data->my);

gamegroup = GAMEGROUP_BEFORE; gamegroup = GAMEGROUP_BEFORE;
} }


@@ -51,30 +49,36 @@ void SdlInput::TickGame(float deltams)
Entity::TickGame(deltams); Entity::TickGame(deltams);


/* Handle mouse input */ /* Handle mouse input */
vec2i mouse;
if (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
{
SDL_GetMouseState(&mouse.x, &mouse.y);
mouse.y = Video::GetSize().y - 1 - mouse.y;
}
else
mouse.x = mouse.y = -1;
vec2i mouse = SdlInputData::GetMousePos();;
Input::SetMousePos(mouse); Input::SetMousePos(mouse);


/* Handle keyboard and WM events */ /* Handle keyboard and WM events */
SDL_Event event; SDL_Event event;
while (SDL_PollEvent(&event)) while (SDL_PollEvent(&event))
{ {
if (event.type == SDL_QUIT)
switch (event.type)
{
case SDL_QUIT:
Ticker::Shutdown(); Ticker::Shutdown();
break;
#if 0 #if 0
else if (event.type == SDL_KEYDOWN)
case SDL_KEYDOWN:
Input::KeyPressed(event.key.keysym.sym, deltams); Input::KeyPressed(event.key.keysym.sym, deltams);
break;
#endif #endif
else if (event.type == SDL_MOUSEBUTTONDOWN)
Input::SetMouseButton(event.button.button - 1);
else if (event.type == SDL_MOUSEBUTTONUP)
Input::UnsetMouseButton(event.button.button - 1);
case SDL_MOUSEBUTTONDOWN:
case SDL_MOUSEBUTTONUP:
{
vec2i newmouse = SdlInputData::GetMousePos();
if (newmouse != mouse)
Input::SetMousePos(mouse = newmouse);
if (event.type == SDL_MOUSEBUTTONDOWN)
Input::SetMouseButton(event.button.button - 1);
else
Input::UnsetMouseButton(event.button.button - 1);
break;
}
}
} }


/* Send the whole keyboard state to the input system */ /* Send the whole keyboard state to the input system */
@@ -91,5 +95,17 @@ SdlInput::~SdlInput()
delete data; delete data;
} }


vec2i SdlInputData::GetMousePos()
{
vec2i ret(-1, -1);

if (SDL_GetAppState() & SDL_APPMOUSEFOCUS)
{
SDL_GetMouseState(&ret.x, &ret.y);
ret.y = Video::GetSize().y - 1 - ret.y;
}
return ret;
}

} /* namespace lol */ } /* namespace lol */



Loading…
Cancel
Save