OpenXcom  1.0
Open-source clone of the original X-Com
Camera.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 "Position.h"
21 
22 namespace OpenXcom
23 {
24 
25 class Action;
26 class State;
27 class Timer;
28 class Map;
29 
33 class Camera
34 {
35 private:
36  Timer *_scrollMouseTimer, *_scrollKeyTimer;
37  int _spriteWidth, _spriteHeight;
38  int _mapsize_x, _mapsize_y, _mapsize_z;
39  int _screenWidth, _screenHeight;
40  Position _mapOffset, _center;
41  int _scrollMouseX, _scrollMouseY, _scrollKeyX, _scrollKeyY;
42  bool _scrollTrigger;
43  int _visibleMapHeight;
44  bool _showAllLayers;
45  Map *_map;
46 public:
47  static const int SCROLL_BORDER = 5;
48  static const int SCROLL_DIAGONAL_EDGE = 60;
50  Camera(int spriteWidth, int spriteHeight, int mapsize_x, int mapsize_y, int mapsize_z, Map *map, int visibleMapHeight);
52  ~Camera();
54  void setScrollTimer(Timer *mouse, Timer *key);
56  void mousePress(Action *action, State *state);
58  void mouseRelease(Action *action, State *state);
60  void mouseOver(Action *action, State *state);
62  void keyboardPress(Action *action, State *state);
64  void keyboardRelease(Action *action, State *state);
66  void scrollMouse();
68  void scrollKey();
70  void scrollXY(int x, int y, bool redraw);
72  void jumpXY(int x, int y);
74  void up();
76  void down();
78  void setViewLevel(int viewlevel);
80  void convertMapToScreen(Position mapPos, Position *screenPos) const;
82  void convertVoxelToScreen(Position voxelPos, Position *screenPos) const;
84  void convertScreenToMap(int screenX, int screenY, int *mapX, int *mapY) const;
86  void centerOnPosition(Position pos, bool redraw = true);
90  int getViewLevel() const;
92  int getMapSizeX() const;
94  int getMapSizeY() const;
96  Position getMapOffset() const;
98  void setMapOffset(const Position& pos);
100  int toggleShowAllLayers();
102  bool getShowAllLayers() const;
104  bool isOnScreen(Position mapPos, const bool unitWalking, const int unitSize, const bool boundary) const;
106  void resize();
108  void stopMouseScrolling();
109 };
110 
111 }
void resize()
Resize the viewable area.
Definition: Camera.cpp:610
void convertMapToScreen(Position mapPos, Position *screenPos) const
Converts map coordinates to screen coordinates.
Definition: Camera.cpp:461
~Camera()
Cleans up the camera.
Definition: Camera.cpp:48
bool isOnScreen(Position mapPos, const bool unitWalking, const int unitSize, const bool boundary) const
Checks if map coordinates X,Y,Z are on screen.
Definition: Camera.cpp:558
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
Position getCenterPosition()
Gets map&#39;s center position.
Definition: Camera.cpp:425
void jumpXY(int x, int y)
Jumps the view (when projectile in motion).
Definition: Camera.cpp:356
void scrollXY(int x, int y, bool redraw)
Scrolls the view a certain amount.
Definition: Camera.cpp:326
A game state that receives user input and reacts accordingly.
Definition: State.h:44
Timer used to run code in fixed intervals.
Definition: Timer.h:35
int getMapSizeX() const
Gets the map size x.
Definition: Camera.cpp:499
Class handling camera movement, either by mouse or by events on the battlescape.
Definition: Camera.h:33
int getMapSizeY() const
Gets the map size y.
Definition: Camera.cpp:508
void convertScreenToMap(int screenX, int screenY, int *mapX, int *mapY) const
Converts screen coordinates to map coordinates.
Definition: Camera.cpp:438
void mouseOver(Action *action, State *state)
Special handling for mouse over.
Definition: Camera.cpp:119
void mousePress(Action *action, State *state)
Special handling for mouse press.
Definition: Camera.cpp:69
void scrollMouse()
Scrolls the view for mouse-scrolling.
Definition: Camera.cpp:307
void keyboardPress(Action *action, State *state)
Special handling for key presses.
Definition: Camera.cpp:228
void scrollKey()
Scrolls the view for keyboard-scrolling.
Definition: Camera.cpp:315
void centerOnPosition(Position pos, bool redraw=true)
Center map on a position.
Definition: Camera.cpp:406
Interactive map of the battlescape.
Definition: Map.h:44
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:40
void setScrollTimer(Timer *mouse, Timer *key)
Sets the camera&#39;s scroll timers.
Definition: Camera.cpp:58
void up()
Moves map layer up.
Definition: Camera.cpp:367
Position getMapOffset() const
Get the map x/y screen offset.
Definition: Camera.cpp:517
void setMapOffset(const Position &pos)
Sets the map x/y screen offset.
Definition: Camera.cpp:526
bool getShowAllLayers() const
Checks if the camera is showing all map layers.
Definition: Camera.cpp:545
void mouseRelease(Action *action, State *state)
Special handling for mouse release.
Definition: Camera.cpp:94
Easy handling of X-Y-Z coordinates.
Definition: Position.h:28
void setViewLevel(int viewlevel)
Sets the view level.
Definition: Camera.cpp:394
void down()
Move map layer down.
Definition: Camera.cpp:380
void convertVoxelToScreen(Position voxelPos, Position *screenPos) const
Converts voxel coordinates to screen coordinates.
Definition: Camera.cpp:473
void stopMouseScrolling()
stop mouse scrolling.
Definition: Camera.cpp:617
int toggleShowAllLayers()
Toggles showing all map layers.
Definition: Camera.cpp:535
int getViewLevel() const
Gets the map displayed level.
Definition: Camera.cpp:490
Definition: BaseInfoState.cpp:40
void keyboardRelease(Action *action, State *state)
Special handling for key releases.
Definition: Camera.cpp:269