OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
InteractiveSurface.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_INTERACTIVE_SURFACE_H
20 #define OPENXCOM_INTERACTIVE_SURFACE_H
21 
22 #include <SDL.h>
23 #include <map>
24 #include "Surface.h"
25 #include "State.h"
26 
27 namespace OpenXcom
28 {
29 
30 typedef void (State::* ActionHandler)(Action*);
31 
40 {
41 private:
42  static const int NUM_BUTTONS = 7;
43  static const SDLKey SDLK_ANY;
44  Uint8 _buttonsPressed;
45 protected:
46  std::map<Uint8, ActionHandler> _click, _press, _release;
47  ActionHandler _in, _over, _out;
48  std::map<SDLKey, ActionHandler> _keyPress, _keyRelease;
49  bool _isHovered, _isFocused, _listButton;
50 
52  bool isButtonPressed(Uint8 button = 0);
54  virtual bool isButtonHandled(Uint8 button = 0);
56  void setButtonPressed(Uint8 button, bool pressed);
57 public:
59  InteractiveSurface(int width, int height, int x = 0, int y = 0);
61  virtual ~InteractiveSurface();
63  void setVisible(bool visible);
65  virtual void handle(Action *action, State *state);
67  virtual void setFocus(bool focus);
69  bool isFocused() const;
71  virtual void unpress(State *state);
73  void onMouseClick(ActionHandler handler, Uint8 button = SDL_BUTTON_LEFT);
75  void onMousePress(ActionHandler handler, Uint8 button = 0);
77  void onMouseRelease(ActionHandler handler, Uint8 button = 0);
79  void onMouseIn(ActionHandler handler);
81  void onMouseOver(ActionHandler handler);
83  void onMouseOut(ActionHandler handler);
85  void onKeyboardPress(ActionHandler handler, SDLKey key = SDLK_ANY);
87  void onKeyboardRelease(ActionHandler handler, SDLKey key = SDLK_ANY);
89  virtual void mousePress(Action *action, State *state);
91  virtual void mouseRelease(Action *action, State *state);
93  virtual void mouseClick(Action *action, State *state);
95  virtual void mouseIn(Action *action, State *state);
97  virtual void mouseOver(Action *action, State *state);
99  virtual void mouseOut(Action *action, State *state);
101  virtual void keyboardPress(Action *action, State *state);
103  virtual void keyboardRelease(Action *action, State *state);
105  void setListButton();
106 };
107 
108 }
109 
110 #endif
virtual void setFocus(bool focus)
Sets the focus of this surface.
Definition: InteractiveSurface.cpp:208
void onMouseRelease(ActionHandler handler, Uint8 button=0)
Hooks an action handler to a mouse release over the surface.
Definition: InteractiveSurface.cpp:444
void onMouseClick(ActionHandler handler, Uint8 button=SDL_BUTTON_LEFT)
Hooks an action handler to a mouse click on the surface.
Definition: InteractiveSurface.cpp:410
InteractiveSurface(int width, int height, int x=0, int y=0)
Creates a new interactive surface with the specified size and position.
Definition: InteractiveSurface.cpp:35
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:34
virtual bool isButtonHandled(Uint8 button=0)
Is this mouse button event handled?
Definition: InteractiveSurface.cpp:46
A game state that receives user input and reacts accordingly.
Definition: State.h:44
Surface that the user can interact with.
Definition: InteractiveSurface.h:39
virtual void mouseOver(Action *action, State *state)
Processes a mouse hover event.
Definition: InteractiveSurface.cpp:332
void onMouseIn(ActionHandler handler)
Hooks an action handler to moving the mouse into the surface.
Definition: InteractiveSurface.cpp:460
virtual void mouseIn(Action *action, State *state)
Processes a mouse hover in event.
Definition: InteractiveSurface.cpp:317
void setListButton()
Check this surface to see if it's a textlist button.
Definition: InteractiveSurface.cpp:520
virtual void handle(Action *action, State *state)
Processes any pending events.
Definition: InteractiveSurface.cpp:107
void setButtonPressed(Uint8 button, bool pressed)
Set a mouse button's internal state.
Definition: InteractiveSurface.cpp:72
void onKeyboardRelease(ActionHandler handler, SDLKey key=SDLK_ANY)
Hooks an action handler to releasing a key when the surface is focused.
Definition: InteractiveSurface.cpp:505
virtual void mouseOut(Action *action, State *state)
Processes a mouse hover out event.
Definition: InteractiveSurface.cpp:347
void onMouseOver(ActionHandler handler)
Hooks an action handler to moving the mouse over the surface.
Definition: InteractiveSurface.cpp:469
bool isButtonPressed(Uint8 button=0)
Is this mouse button pressed?
Definition: InteractiveSurface.cpp:60
void onMousePress(ActionHandler handler, Uint8 button=0)
Hooks an action handler to a mouse press over the surface.
Definition: InteractiveSurface.cpp:427
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
virtual void mouseClick(Action *action, State *state)
Processes a mouse click event.
Definition: InteractiveSurface.cpp:294
void onMouseOut(ActionHandler handler)
Hooks an action handler to moving the mouse out of the surface.
Definition: InteractiveSurface.cpp:478
void onKeyboardPress(ActionHandler handler, SDLKey key=SDLK_ANY)
Hooks an action handler to pressing a key when the surface is focused.
Definition: InteractiveSurface.cpp:488
virtual void mousePress(Action *action, State *state)
Processes a mouse button press event.
Definition: InteractiveSurface.cpp:248
virtual void keyboardRelease(Action *action, State *state)
Processes a keyboard key release event.
Definition: InteractiveSurface.cpp:387
bool isFocused() const
Gets the focus of this surface.
Definition: InteractiveSurface.cpp:218
virtual void mouseRelease(Action *action, State *state)
Processes a mouse button release event.
Definition: InteractiveSurface.cpp:271
virtual ~InteractiveSurface()
Cleans up the interactive surface.
Definition: InteractiveSurface.cpp:42
virtual void keyboardPress(Action *action, State *state)
Processes a keyboard key press event.
Definition: InteractiveSurface.cpp:362
void setVisible(bool visible)
Sets the surface's visibility.
Definition: InteractiveSurface.cpp:89
virtual void unpress(State *state)
Unpresses the surface.
Definition: InteractiveSurface.cpp:228