1 /***************************************************************************
2  *   Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com>          *
3  *                                                                         *
4  *   Part of the Free Heroes2 Engine:                                      *
5  *   http://sourceforge.net/projects/fheroes2                              *
6  *                                                                         *
7  *   This program 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 2 of the License, or     *
10  *   (at your option) any later version.                                   *
11  *                                                                         *
12  *   This program 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 this program; if not, write to the                         *
19  *   Free Software Foundation, Inc.,                                       *
20  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
21  ***************************************************************************/
22 
23 #ifndef H2INTERFACE_GAMEAREA_H
24 #define H2INTERFACE_GAMEAREA_H
25 
26 #include "image.h"
27 #include "timing.h"
28 
29 namespace Interface
30 {
31     class Basic;
32 
33     enum ScollingType
34     {
35         SCROLL_NONE = 0x00,
36         SCROLL_LEFT = 0x01,
37         SCROLL_RIGHT = 0x02,
38         SCROLL_TOP = 0x04,
39         SCROLL_BOTTOM = 0x08
40     };
41 
42     enum RedrawLevelType
43     {
44         LEVEL_BOTTOM = 0x01,
45         LEVEL_TOP = 0x02,
46         LEVEL_HEROES = 0x04,
47         LEVEL_OBJECTS = 0x08,
48         LEVEL_FOG = 0x20,
49         LEVEL_ROUTES = 0x40,
50 
51         LEVEL_ALL = 0xFF
52     };
53 
54     class GameArea
55     {
56     public:
57         explicit GameArea( Basic & );
58 
59         void generate( const fheroes2::Size & screenSize, const bool withoutBorders );
60 
GetROI()61         const fheroes2::Rect & GetROI() const // returns visible Game Area ROI in pixels
62         {
63             return _windowROI;
64         }
65 
66         // Do NOT use this method directly in heavy computation loops
67         fheroes2::Rect GetVisibleTileROI( void ) const;
68 
69         void ShiftCenter( const fheroes2::Point & offset ); // in pixels
70 
71         int GetScrollCursor( void ) const;
72 
NeedScroll()73         bool NeedScroll() const
74         {
75             return scrollDirection != 0;
76         }
77 
78         void Scroll( void );
79         void SetScroll( int );
80 
81         void SetCenter( const fheroes2::Point & point );
82 
83         // Do not call this method unless it's needed for manual setup of the position
84         void SetCenterInPixels( const fheroes2::Point & point );
85 
86         void SetRedraw( void ) const;
87 
88         void Redraw( fheroes2::Image & dst, int flag, bool isPuzzleDraw = false ) const;
89 
90         void BlitOnTile( fheroes2::Image & dst, const fheroes2::Image & src, int32_t ox, int32_t oy, const fheroes2::Point & mp, bool flip = false,
91                          uint8_t alpha = 255 ) const;
92         void BlitOnTile( fheroes2::Image & dst, const fheroes2::Sprite & src, const fheroes2::Point & mp ) const;
93 
94         // Use this method to draw TIL images
95         void DrawTile( fheroes2::Image & src, const fheroes2::Image & dst, const fheroes2::Point & mp ) const;
96 
SetUpdateCursor(void)97         void SetUpdateCursor( void )
98         {
99             updateCursor = true;
100         }
101 
102         void QueueEventProcessing( void );
103 
104         fheroes2::Rect RectFixed( fheroes2::Point & dst, int rw, int rh ) const;
105 
106         static fheroes2::Image GenerateUltimateArtifactAreaSurface( const int32_t index, const fheroes2::Point & offset );
107 
108         int32_t GetValidTileIdFromPoint( const fheroes2::Point & point ) const; // returns -1 in case of invalid index (out of World Map)
109         fheroes2::Point GetRelativeTilePosition( const fheroes2::Point & tileId ) const; // in relation to screen
110 
ResetCursorPosition()111         void ResetCursorPosition()
112         {
113             _prevIndexPos = -1;
114         }
115 
116         void SetAreaPosition( int32_t, int32_t, int32_t, int32_t );
117 
118         fheroes2::Point getCurrentCenterInPixels() const;
119 
120     private:
121         Basic & interface;
122 
123         fheroes2::Rect _windowROI; // visible to draw area of World Map in pixels
124         fheroes2::Point _topLeftTileOffset; // offset of tiles to be drawn (from here we can find any tile ID)
125 
126         // boundaries for World Map
127         int32_t _minLeftOffset;
128         int32_t _maxLeftOffset;
129         int32_t _minTopOffset;
130         int32_t _maxTopOffset;
131 
132         fheroes2::Size _visibleTileCount; // number of tiles to be drawn on screen
133 
134         int32_t _prevIndexPos;
135         int scrollDirection;
136         bool updateCursor;
137 
138         fheroes2::Time scrollTime;
139 
140         fheroes2::Point _middlePoint() const; // returns middle point of window ROI
141         fheroes2::Point _getStartTileId() const;
142         void _setCenterToTile( const fheroes2::Point & tile ); // set center to the middle of tile (input is tile ID)
143     };
144 }
145 
146 #endif
147