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
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.
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.
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
26 #include <sigc++/signal.h>
27 #include <sigc++/connection.h>
28 #include <sigc++/trackable.h>
30 #include "overviewmap.h"
32 #include "rectangle.h"
33 #include "input-events.h"
35 //! Draw a miniature map graphic and a white box around the selected region.
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.
44 class SmallMap: public OverviewMap
47 //! Default constructor. Make a new SmallMap.
52 //! Set whether or not the map can be clicked on.
54 * @note This is useful when it's not our turn and we want to prevent the
55 * user from clicking on the SmallMap.
57 void set_input_locked(bool locked) { input_locked = locked; }
59 void set_slide_speed(guint32 interval) {sleep_interval = interval;};
61 // Methods that operate on the class data and modify the class.
63 //! Set the portion of the SmallMap that has a white box around it.
65 * @note This method does not perform animation. The white box disappears
66 * from it's previous location and a new one is drawn.
68 * @param new_view The portion of the map graphic to highlight.
70 void set_view(Rectangle new_view);
72 Rectangle get_view() const {return view;};
74 //! Zip to the selected portion of the SmallMap from the old position.
76 * Move the white box to the specified region in an animated fashion.
78 * @param new_view The portion of the map graphic to highlight.
80 void slide_view(Rectangle new_view);
82 //! Realize the given mouse button event.
83 void mouse_button_event(MouseButtonEvent e);
85 //! Realize the given mouse motion event.
86 void mouse_motion_event(MouseMotionEvent e);
88 //! Center the view on the given map position.
90 * @param pos The position to move the little white box to. The
91 * referenced tile is in the center of the little white
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
97 void center_view_on_tile(Vector<int> pos, bool slide);
99 //! Center the view on the given pixel of the map graphic.
101 * @param pos The position to move the little white box to. The
102 * referenced pixel is in the center of the little white
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
108 void center_view_on_pixel(Vector<int> pos, bool slide);
110 //! Move the view one tile in the given direction.
111 void move_map_in_dir(Vector<int> dir);
115 // Emitted when the white box is redrawn after a call to SmallMap::set_view.
117 * Classes that use SmallMap must catch this signal to display the change
118 * in position of the little white box.
120 sigc::signal<void, Rectangle> view_changed;
122 //! Emitted during sliding animation after a call to Smallmap::slide_view.
124 * Classes that use SmallMap must catch this signal to display the
125 * animation of the little white box.
127 sigc::signal<void, Rectangle> view_slid;
129 // Emitted after a call to SmallMap::Draw.
131 * Classes that use SmallMap must catch this signal to display the map.
133 sigc::signal<void, Glib::RefPtr<Gdk::Pixmap>, Gdk::Rectangle> map_changed;
136 //! Draw the selection rectangle that shows the viewed portion of the map.
137 void draw_selection();
139 //! Draw the City objects and little white box onto the mini-map graphic.
141 * This method is automatically called by the SmallMap::draw method.
143 virtual void after_draw();
147 //! The position and size of the little white box.
149 * This rectangle represents the selected portion of the map.
153 //! Whether or not to ignore mouse clicks and movement.
155 * When this is set to true, the SmallMap will ignore mouse clicks and also
160 //! When sliding the box, it sleeps this long per frame (in microseconds).
161 guint32 sleep_interval;