OpenXcom  1.0
Open-source clone of the original X-Com
InteractiveSurface.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * OpenXcom is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include <SDL.h>
21 #include <map>
22 #include "Surface.h"
23 #include "State.h"
24 
25 namespace OpenXcom
26 {
27 
28 typedef void (State::* ActionHandler)(Action*);
29 
38 {
39 private:
40  static const int NUM_BUTTONS = 7;
41  static const SDLKey SDLK_ANY;
42  Uint8 _buttonsPressed;
43 protected:
44  std::map<Uint8, ActionHandler> _click, _press, _release;
45  ActionHandler _in, _over, _out;
46  std::map<SDLKey, ActionHandler> _keyPress, _keyRelease;
47  bool _isHovered, _isFocused, _listButton;
48 
50  bool isButtonPressed(Uint8 button = 0) const;
52  virtual bool isButtonHandled(Uint8 button = 0);
54  void setButtonPressed(Uint8 button, bool pressed);
55 public:
57  InteractiveSurface(int width, int height, int x = 0, int y = 0);
59  virtual ~InteractiveSurface();
61  void setVisible(bool visible);
63  virtual void handle(Action *action, State *state);
65  virtual void setFocus(bool focus);
67  bool isFocused() const;
69  virtual void unpress(State *state);
71  void onMouseClick(ActionHandler handler, Uint8 button = SDL_BUTTON_LEFT);
73  void onMousePress(ActionHandler handler, Uint8 button = 0);
75  void onMouseRelease(ActionHandler handler, Uint8 button = 0);
77  void onMouseIn(ActionHandler handler);
79  void onMouseOver(ActionHandler handler);
81  void onMouseOut(ActionHandler handler);
83  void onKeyboardPress(ActionHandler handler, SDLKey key = SDLK_ANY);
85  void onKeyboardRelease(ActionHandler handler, SDLKey key = SDLK_ANY);
87  virtual void mousePress(Action *action, State *state);
89  virtual void mouseRelease(Action *action, State *state);
91  virtual void mouseClick(Action *action, State *state);
93  virtual void mouseIn(Action *action, State *state);
95  virtual void mouseOver(Action *action, State *state);
97  virtual void mouseOut(Action *action, State *state);
99  virtual void keyboardPress(Action *action, State *state);
101  virtual void keyboardRelease(Action *action, State *state);
103  void setListButton();
104 };
105 
106 }
virtual void setFocus(bool focus)
Sets the focus of this surface.
Definition: InteractiveSurface.cpp:207
void onMouseRelease(ActionHandler handler, Uint8 button=0)
Hooks an action handler to a mouse release over the surface.
Definition: InteractiveSurface.cpp:443
void onMouseClick(ActionHandler handler, Uint8 button=SDL_BUTTON_LEFT)
Hooks an action handler to a mouse click on the surface.
Definition: InteractiveSurface.cpp:409
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:34
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
virtual bool isButtonHandled(Uint8 button=0)
Is this mouse button event handled?
Definition: InteractiveSurface.cpp:45
A game state that receives user input and reacts accordingly.
Definition: State.h:44
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
virtual void mouseOver(Action *action, State *state)
Processes a mouse hover event.
Definition: InteractiveSurface.cpp:331
void onMouseIn(ActionHandler handler)
Hooks an action handler to moving the mouse into the surface.
Definition: InteractiveSurface.cpp:459
virtual void mouseIn(Action *action, State *state)
Processes a mouse hover in event.
Definition: InteractiveSurface.cpp:316
void setListButton()
Check this surface to see if it&#39;s a textlist button.
Definition: InteractiveSurface.cpp:519
virtual void handle(Action *action, State *state)
Processes any pending events.
Definition: InteractiveSurface.cpp:106
void setButtonPressed(Uint8 button, bool pressed)
Set a mouse button&#39;s internal state.
Definition: InteractiveSurface.cpp:71
void onKeyboardRelease(ActionHandler handler, SDLKey key=SDLK_ANY)
Hooks an action handler to releasing a key when the surface is focused.
Definition: InteractiveSurface.cpp:504
virtual void mouseOut(Action *action, State *state)
Processes a mouse hover out event.
Definition: InteractiveSurface.cpp:346
bool isButtonPressed(Uint8 button=0) const
Is this mouse button pressed?
Definition: InteractiveSurface.cpp:59
bool isFocused() const
Gets the focus of this surface.
Definition: InteractiveSurface.cpp:217
void onMouseOver(ActionHandler handler)
Hooks an action handler to moving the mouse over the surface.
Definition: InteractiveSurface.cpp:468
void onMousePress(ActionHandler handler, Uint8 button=0)
Hooks an action handler to a mouse press over the surface.
Definition: InteractiveSurface.cpp:426
Element that is blit (rendered) onto the screen.
Definition: Surface.h:38
virtual void mouseClick(Action *action, State *state)
Processes a mouse click event.
Definition: InteractiveSurface.cpp:293
void onMouseOut(ActionHandler handler)
Hooks an action handler to moving the mouse out of the surface.
Definition: InteractiveSurface.cpp:477
void onKeyboardPress(ActionHandler handler, SDLKey key=SDLK_ANY)
Hooks an action handler to pressing a key when the surface is focused.
Definition: InteractiveSurface.cpp:487
virtual void mousePress(Action *action, State *state)
Processes a mouse button press event.
Definition: InteractiveSurface.cpp:247
virtual void keyboardRelease(Action *action, State *state)
Processes a keyboard key release event.
Definition: InteractiveSurface.cpp:386
virtual void mouseRelease(Action *action, State *state)
Processes a mouse button release event.
Definition: InteractiveSurface.cpp:270
virtual ~InteractiveSurface()
Cleans up the interactive surface.
Definition: InteractiveSurface.cpp:41
virtual void keyboardPress(Action *action, State *state)
Processes a keyboard key press event.
Definition: InteractiveSurface.cpp:361
void setVisible(bool visible)
Sets the surface&#39;s visibility.
Definition: InteractiveSurface.cpp:88
Definition: BaseInfoState.cpp:40
virtual void unpress(State *state)
Unpresses the surface.
Definition: InteractiveSurface.cpp:227