From e9583b8a62d2f1bae72e206f0ff09f49f39ecb43 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 2 Feb 2011 00:56:53 +0000 Subject: [PATCH] Implement the title screen. Click on it to start a game. --- src/input.cpp | 36 +++++++++++++++++++++++++++++++----- src/worldentity.h | 1 + 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index d6597fbd..62209f45 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -30,9 +30,10 @@ static class InputData public: InputData() - : mouse(-1, -1), - buttons(0, 0, 0), - nentities(0) + : mouse(-1), + buttons(0), + nentities(0), + lastfocus(0) { } private: @@ -42,6 +43,7 @@ private: static int const MAX_ENTITIES = 100; WorldEntity *entities[MAX_ENTITIES]; int nentities; + WorldEntity *lastfocus; } inputdata; @@ -120,23 +122,47 @@ void Input::SetMousePos(int2 coord) for (int n = 0; n < data->nentities; n++) { if (data->entities[n] == best) + { data->entities[n]->mousepos = (int2)((int3)coord - best->bbox[0]); + if (best != data->lastfocus) + data->entities[n]->pressed = data->buttons; + } else + { data->entities[n]->mousepos = int2(-1); + /* FIXME */ + data->entities[n]->released = 0; + data->entities[n]->pressed = 0; + data->entities[n]->clicked = 0; + } } + + data->lastfocus = best; } void Input::SetMouseButton(int index) { data->buttons[index] = 1; - /* FIXME: parse all subscribed entities and update them */ + if (data->lastfocus) + { + if (!data->lastfocus->pressed[index]) + data->lastfocus->clicked[index] = 1; + data->lastfocus->pressed[index] = 1; + data->lastfocus->released[index] = 0; + } } void Input::UnsetMouseButton(int index) { data->buttons[index] = 0; - /* FIXME: parse all subscribed entities and update them */ + if (data->lastfocus) + { + if (data->lastfocus->pressed[index]) + data->lastfocus->released[index] = 1; + data->lastfocus->pressed[index] = 0; + data->lastfocus->clicked[index] = 0; + } } diff --git a/src/worldentity.h b/src/worldentity.h index d70c7372..02a4c208 100644 --- a/src/worldentity.h +++ b/src/worldentity.h @@ -28,6 +28,7 @@ public: int2 mousepos; int3 mousebuttons; + int3 pressed, clicked, released; protected: WorldEntity();