OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
State.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 
20 #ifndef OPENXCOM_STATE_H
21 #define OPENXCOM_STATE_H
22 
23 #include <vector>
24 #include <string>
25 #include <SDL.h>
26 
27 namespace OpenXcom
28 {
29 
30 class Game;
31 class Surface;
32 class InteractiveSurface;
33 class Action;
34 class LocalizedText;
35 
44 class State
45 {
46  friend class Timer;
47 
48 protected:
49  Game *_game;
50  std::vector<Surface*> _surfaces;
51  bool _screen;
52  InteractiveSurface *_modal;
53  SDL_Color _palette[256];
54 public:
56  State(Game* game);
58  virtual ~State();
60  void add(Surface *surface);
62  bool isScreen() const;
64  void toggleScreen();
66  virtual void init();
68  virtual void handle(Action *action);
70  virtual void think();
72  virtual void blit();
74  void hideAll();
76  void showAll();
78  void resetAll();
80  const LocalizedText &tr(const std::string &id) const;
82  LocalizedText tr(const std::string &id, unsigned n) const;
84  void redrawText();
86  void centerAllSurfaces();
88  void lowerAllSurfaces();
90  void applyBattlescapeTheme();
92  void setModal(InteractiveSurface *surface);
94  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256, bool immediately = true);
96  void setPalette(const std::string &palette, int backpals = -1);
98  SDL_Color *const getPalette();
100  virtual void resize(int &dX, int &dY);
102  virtual void recenter(int dX, int dY);
103 };
104 
105 }
106 
107 #endif
const LocalizedText & tr(const std::string &id) const
Get the localized text.
Definition: State.cpp:214
void setModal(InteractiveSurface *surface)
Sets a modal surface.
Definition: State.cpp:339
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:34
void centerAllSurfaces()
center all surfaces relative to the screen.
Definition: State.cpp:234
virtual void recenter(int dX, int dY)
Re-orients all the surfaces in the state.
Definition: State.cpp:408
A game state that receives user input and reacts accordingly.
Definition: State.h:44
bool isScreen() const
Gets whether the state is a full-screen.
Definition: State.cpp:95
Timer used to run code in fixed intervals.
Definition: Timer.h:37
Surface that the user can interact with.
Definition: InteractiveSurface.h:39
void hideAll()
Hides all the state surfaces.
Definition: State.cpp:176
virtual void think()
Runs state functionality every cycle.
Definition: State.cpp:135
void showAll()
Shws all the state surfaces.
Definition: State.cpp:185
SDL_Color *const getPalette()
Gets the state's 8bpp palette.
Definition: State.cpp:387
A string that is already translated.
Definition: LocalizedText.h:45
void toggleScreen()
Toggles whether the state is a full-screen.
Definition: State.cpp:105
void applyBattlescapeTheme()
switch the colours to use the battlescape palette.
Definition: State.cpp:257
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256, bool immediately=true)
Changes a set of colors on the state's 8bpp palette.
Definition: State.cpp:351
void resetAll()
Resets all the state surfaces.
Definition: State.cpp:195
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
virtual void init()
Initializes the state.
Definition: State.cpp:118
virtual void blit()
Blits the state to the screen.
Definition: State.cpp:167
virtual void handle(Action *action)
Handles any events.
Definition: State.cpp:146
The core of the game engine, manages the game's entire contents and structure.
Definition: Game.h:44
virtual void resize(int &dX, int &dY)
Let the state know the window has been resized.
Definition: State.cpp:398
void lowerAllSurfaces()
lower all surfaces by half the screen height.
Definition: State.cpp:246
State(Game *game)
Creates a new state linked to a game.
Definition: State.cpp:48
void add(Surface *surface)
Adds a child element to the state.
Definition: State.cpp:75
void redrawText()
redraw all the text-type surfaces.
Definition: State.cpp:317
virtual ~State()
Cleans up the state.
Definition: State.cpp:57