ソースを参照

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

button changes.
legacy
Sam Hocevar sam 13年前
コミット
bf5e4ba76e
2個のファイルの変更40行の追加24行の削除
  1. +7
    -7
      src/input.cpp
  2. +33
    -17
      src/sdlinput.cpp

+ 7
- 7
src/input.cpp ファイルの表示

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

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

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)
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++)
{
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;
else
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)


+ 33
- 17
src/sdlinput.cpp ファイルの表示

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

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

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

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

gamegroup = GAMEGROUP_BEFORE;
}

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

/* 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);

/* Handle keyboard and WM events */
SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
switch (event.type)
{
case SDL_QUIT:
Ticker::Shutdown();
break;
#if 0
else if (event.type == SDL_KEYDOWN)
case SDL_KEYDOWN:
Input::KeyPressed(event.key.keysym.sym, deltams);
break;
#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 */
@@ -91,5 +95,17 @@ SdlInput::~SdlInput()
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 */


読み込み中…
キャンセル
保存