initial commit, lordsawar source, slightly modified
[lordsawar] / src / smallmap.h
1 // Copyright (C) 2001, 2002, 2003 Michael Bartl
2 // Copyright (C) 2002, 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2004, 2005 Andrea Paternesi
4 // Copyright (C) 2004 Thomas Plonka
5 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
6 // Copyright (C) 2007 Ole Laursen
7 //
8 //  This program is free software; you can redistribute it and/or modify
9 //  it under the terms of the GNU General Public License as published by
10 //  the Free Software Foundation; either version 3 of the License, or
11 //  (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU Library General Public License for more details.
17 //
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
21 //  02110-1301, USA.
22
23 #ifndef SMALLMAP_H
24 #define SMALLMAP_H
25
26 #include <sigc++/signal.h>
27 #include <sigc++/connection.h>
28 #include <sigc++/trackable.h>
29
30 #include "overviewmap.h"
31
32 #include "rectangle.h"
33 #include "input-events.h"
34
35 //! Draw a miniature map graphic and a white box around the selected region.
36 /**
37  * SmallMap is the image at the top right of the game screen which provides an
38  * overview of the whole game map.  It draws City objects on top of the graphic
39  * that the OverviewMap class provides.  It is interactive in that it handles 
40  * mouse clicks, moving of the currently visible portion and changes of the 
41  * underlying map.  It draws an animation of the selection rectangle as it 
42  * moves to the next selected region.
43  */
44 class SmallMap: public OverviewMap
45 {
46 public:
47     //! Default constructor.  Make a new SmallMap.
48     SmallMap();
49
50     // Set Methods
51   
52     //! Set whether or not the map can be clicked on.
53     /**
54      * @note This is useful when it's not our turn and we want to prevent the
55      *       user from clicking on the SmallMap.
56      */
57     void set_input_locked(bool locked) { input_locked = locked; }
58
59     void set_slide_speed(guint32 interval) {sleep_interval = interval;};
60
61     // Methods that operate on the class data and modify the class.
62  
63     //! Set the portion of the SmallMap that has a white box around it.
64     /**
65      * @note This method does not perform animation.  The white box disappears
66      * from it's previous location and a new one is drawn.
67      *
68      * @param new_view  The portion of the map graphic to highlight.
69      */
70     void set_view(Rectangle new_view);
71
72     Rectangle get_view() const {return view;};
73
74     //! Zip to the selected portion of the SmallMap from the old position.
75     /**
76      * Move the white box to the specified region in an animated fashion.
77      *
78      * @param new_view  The portion of the map graphic to highlight.
79      */
80     void slide_view(Rectangle new_view);
81
82     //! Realize the given mouse button event.
83     void mouse_button_event(MouseButtonEvent e);
84
85     //! Realize the given mouse motion event.
86     void mouse_motion_event(MouseMotionEvent e);
87
88     //! Center the view on the given map position.
89     /**
90      * @param pos        The position to move the little white box to.  The
91      *                   referenced tile is in the center of the little white
92      *                   box.
93      * @param slide      Whether or not to animate the movement of the little
94      *                   white box from it's current location to it's new
95      *                   given location.
96      */
97     void center_view_on_tile(Vector<int> pos, bool slide);
98
99     //! Center the view on the given pixel of the map graphic.
100     /**
101      * @param pos        The position to move the little white box to.  The
102      *                   referenced pixel is in the center of the little white
103      *                   box. 
104      * @param slide      Whether or not to animate the movement of the little
105      *                   white box from it's current location to it's new
106      *                   given location.
107      */
108     void center_view_on_pixel(Vector<int> pos, bool slide);
109
110     //! Move the view one tile in the given direction.
111     void move_map_in_dir(Vector<int> dir);
112
113     // Signals
114  
115     // Emitted when the white box is redrawn after a call to SmallMap::set_view.
116     /**
117      * Classes that use SmallMap must catch this signal to display the change
118      * in position of the little white box.
119      */
120     sigc::signal<void, Rectangle> view_changed;
121
122     //! Emitted during sliding animation after a call to Smallmap::slide_view.
123     /**
124      * Classes that use SmallMap must catch this signal to display the 
125      * animation of the little white box.
126      */
127     sigc::signal<void, Rectangle> view_slid;
128
129     // Emitted after a call to SmallMap::Draw.
130     /**
131      * Classes that use SmallMap must catch this signal to display the map.
132      */
133     sigc::signal<void, Glib::RefPtr<Gdk::Pixmap>, Gdk::Rectangle> map_changed;
134
135 private:
136     //! Draw the selection rectangle that shows the viewed portion of the map.
137     void draw_selection();
138
139     //! Draw the City objects and little white box onto the mini-map graphic.
140     /**
141      * This method is automatically called by the SmallMap::draw method.
142      */
143     virtual void after_draw();
144
145     // DATA
146  
147     //! The position and size of the little white box.
148     /**
149      * This rectangle represents the selected portion of the map.
150      */
151     Rectangle view;
152
153     //! Whether or not to ignore mouse clicks and movement.
154     /**
155      * When this is set to true, the SmallMap will ignore mouse clicks and also
156      * mouse drags.
157      */
158     bool input_locked;
159
160     //! When sliding the box, it sleeps this long per frame (in microseconds).
161     guint32 sleep_interval;
162 };
163
164 #endif