OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Camera.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_CAMERA_H
20 #define OPENXCOM_CAMERA_H
21 
22 #include "Position.h"
23 
24 namespace OpenXcom
25 {
26 
27 class Action;
28 class State;
29 class Timer;
30 class Map;
31 
35 class Camera
36 {
37 private:
38  Timer *_scrollMouseTimer, *_scrollKeyTimer;
39  int _spriteWidth, _spriteHeight;
40  int _mapsize_x, _mapsize_y, _mapsize_z;
41  int _screenWidth, _screenHeight;
42  Position _mapOffset, _center;
43  int _scrollMouseX, _scrollMouseY, _scrollKeyX, _scrollKeyY;
44  bool _scrollTrigger;
45  int _visibleMapHeight;
46  bool _showAllLayers;
47  void minMaxInt(int *value, const int minValue, const int maxValue) const;
48  Map *_map;
49 public:
50  static const int SCROLL_BORDER = 5;
51  static const int SCROLL_DIAGONAL_EDGE = 60;
53  Camera(int spriteWidth, int spriteHeight, int mapsize_x, int mapsize_y, int mapsize_z, Map *map, int visibleMapHeight);
55  ~Camera();
57  void setScrollTimer(Timer *mouse, Timer *key);
59  void mousePress(Action *action, State *state);
61  void mouseRelease(Action *action, State *state);
63  void mouseOver(Action *action, State *state);
65  void keyboardPress(Action *action, State *state);
67  void keyboardRelease(Action *action, State *state);
69  void scrollMouse();
71  void scrollKey();
73  void scrollXY(int x, int y, bool redraw);
75  void jumpXY(int x, int y);
77  void up();
79  void down();
81  void setViewLevel(int viewlevel);
83  void convertMapToScreen(const Position &mapPos, Position *screenPos) const;
85  void convertVoxelToScreen(const Position &voxelPos, Position *screenPos) const;
87  void convertScreenToMap(int screenX, int screenY, int *mapX, int *mapY) const;
89  void centerOnPosition(const Position &pos, bool redraw = true);
93  int getViewLevel() const;
95  int getMapSizeX() const;
97  int getMapSizeY() const;
101  void setMapOffset(Position pos);
103  int toggleShowAllLayers();
105  bool getShowAllLayers() const;
107  bool isOnScreen(const Position &mapPos, const bool unitWalking) const;
109  void resize();
111  void stopMouseScrolling();
112 };
113 }
114 #endif
void resize()
Resize the viewable area.
Definition: Camera.cpp:601
~Camera()
Cleans up the camera.
Definition: Camera.cpp:49
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:34
Position getCenterPosition()
Gets map's center position.
Definition: Camera.cpp:445
void jumpXY(int x, int y)
Jumps the view (when projectile in motion).
Definition: Camera.cpp:375
void scrollXY(int x, int y, bool redraw)
Scrolls the view a certain amount.
Definition: Camera.cpp:345
A game state that receives user input and reacts accordingly.
Definition: State.h:44
void convertMapToScreen(const Position &mapPos, Position *screenPos) const
Converts map coordinates to screen coordinates.
Definition: Camera.cpp:481
Timer used to run code in fixed intervals.
Definition: Timer.h:37
int getMapSizeY() const
Gets the map size y.
Definition: Camera.cpp:528
Class handling camera movement, either by mouse or by events on the battlescape.
Definition: Camera.h:35
int getViewLevel() const
Gets the map displayed level.
Definition: Camera.cpp:510
int getMapSizeX() const
Gets the map size x.
Definition: Camera.cpp:519
void convertScreenToMap(int screenX, int screenY, int *mapX, int *mapY) const
Converts screen coordinates to map coordinates.
Definition: Camera.cpp:458
bool isOnScreen(const Position &mapPos, const bool unitWalking) const
Checks if map coordinates X,Y,Z are on screen.
Definition: Camera.cpp:576
void mouseOver(Action *action, State *state)
Special handling for mouse over.
Definition: Camera.cpp:138
void mousePress(Action *action, State *state)
Special handling for mouse press.
Definition: Camera.cpp:88
void scrollMouse()
Scrolls the view for mouse-scrolling.
Definition: Camera.cpp:326
void keyboardPress(Action *action, State *state)
Special handling for key presses.
Definition: Camera.cpp:247
void centerOnPosition(const Position &pos, bool redraw=true)
Center map on a position.
Definition: Camera.cpp:426
void scrollKey()
Scrolls the view for keyboard-scrolling.
Definition: Camera.cpp:334
Interactive map of the battlescape.
Definition: Map.h:46
Camera(int spriteWidth, int spriteHeight, int mapsize_x, int mapsize_y, int mapsize_z, Map *map, int visibleMapHeight)
Creates a new camera.
Definition: Camera.cpp:41
bool getShowAllLayers() const
Checks if the camera is showing all map layers.
Definition: Camera.cpp:565
void setScrollTimer(Timer *mouse, Timer *key)
Sets the camera's scroll timers.
Definition: Camera.cpp:59
Position getMapOffset()
Get the map x/y screen offset.
Definition: Camera.cpp:537
void up()
Moves map layer up.
Definition: Camera.cpp:386
void setMapOffset(Position pos)
Sets the map x/y screen offset.
Definition: Camera.cpp:546
void convertVoxelToScreen(const Position &voxelPos, Position *screenPos) const
Converts voxel coordinates to screen coordinates.
Definition: Camera.cpp:493
void mouseRelease(Action *action, State *state)
Special handling for mouse release.
Definition: Camera.cpp:113
Easy handling of X-Y-Z coordinates.
Definition: Position.h:30
void setViewLevel(int viewlevel)
Sets the view level.
Definition: Camera.cpp:413
void down()
Move map layer down.
Definition: Camera.cpp:399
void stopMouseScrolling()
stop mouse scrolling.
Definition: Camera.cpp:608
int toggleShowAllLayers()
Toggles showing all map layers.
Definition: Camera.cpp:555
void keyboardRelease(Action *action, State *state)
Special handling for key releases.
Definition: Camera.cpp:288