1 // Copyright (C) 2003 Michael Bartl
2 // Copyright (C) 2003, 2004, 2005 Ulf Lorenz
3 // Copyright (C) 2004, 2005 Bryan Duff
4 // Copyright (C) 2004, 2005, 2006 Andrea Paternesi
5 // Copyright (C) 2006, 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++/trackable.h>
28 #include <sigc++/connection.h>
33 #include "input-events.h"
34 #include "map-tip-position.h"
35 #include "rectangle.h"
51 * The detailed map in which all the action takes place. Handles scrolling
52 * and mouse clicks via signals.
54 * Draws everything to a buffer to simplify scrolling, the buffer is then
55 * blitted to the screen. The current view of the map is kept track of both
56 * approximately (in tiles) and more precisely in pixels.
58 class BigMap: public sigc::trackable
65 void draw(Player *player, bool redraw_buffer = true);
67 // view the rectangle, measured in tiles
68 void set_view(Rectangle rect);
69 void screen_size_changed(Gtk::Allocation box);
71 // return a good position of a map tip given that it should be close to the
72 // tiles in tile_area without covering them
73 MapTipPosition map_tip_position(Rectangle tile_area);
74 MapTipPosition map_tip_position(Vector<int> tile);
76 // emitted when the view has changed because of user interactions
77 sigc::signal<void, Rectangle> view_changed;
79 // Emitted after a call to SmallMap::Draw.
81 * Classes that use BigMap must catch this signal to display the map.
83 sigc::signal<void, Glib::RefPtr<Gdk::Pixmap> > map_changed;
86 //! Save the whole map as one big image (bmp file).
87 bool saveAsBitmap(std::string filename);
89 //! Save the whole map, but not the game objects on top of it.
90 bool saveUnderlyingMapAsBitmap(std::string filename);
92 //! Save the current view as an image (bmp file).
93 bool saveViewAsBitmap(std::string filename);
96 Glib::RefPtr<Gdk::Pixmap> get_surface() const {return outgoing;}
98 MapRenderer* d_renderer;
100 Rectangle view; // approximate view of screen, in tiles
101 Vector<int> view_pos; // precise position of view in pixels
103 Glib::RefPtr<Gdk::Pixmap> buffer; // the buffer we draw things in
104 Glib::RefPtr<Gdk::Pixmap> outgoing; //goes out to the gtk::image
105 Glib::RefPtr<Gdk::GC> buffer_gc;
106 Glib::RefPtr<Gdk::Pixmap> magnified_buffer; // the zoomed buffer;
107 double magnification_factor; //how much we're zoomed
108 Rectangle buffer_view; // current view of the buffer, in tiles
114 Gtk::Allocation image;
117 Vector<int> mouse_pos_to_tile(Vector<int> pos);
118 // offset in pixels within tile
119 Vector<int> mouse_pos_to_tile_offset(Vector<int> pos);
120 Vector<int> tile_to_buffer_pos(Vector<int> tile);
121 Vector<int> get_view_pos_from_view();
123 void blit_object(const Location &obj, Vector<int> tile, PixMask* image, Glib::RefPtr<Gdk::Pixmap> surface, Glib::RefPtr<Gdk::GC> surface_gc);
125 virtual void after_draw() { }
128 void draw_stack(Stack *s, Glib::RefPtr<Gdk::Pixmap> surface, Glib::RefPtr<Gdk::GC> surface_gc);
130 void draw_buffer(Rectangle map_view, Glib::RefPtr<Gdk::Pixmap> surface, Glib::RefPtr<Gdk::GC> context);
131 void draw_buffer_tiles(Rectangle map_view, Glib::RefPtr<Gdk::Pixmap> surface, Glib::RefPtr<Gdk::GC> context);
133 void draw_buffer_tile(Vector<int> tile, Glib::RefPtr<Gdk::Pixmap> surface, Glib::RefPtr<Gdk::GC> context);
134 Glib::RefPtr<Gdk::Pixmap> magnify(Glib::RefPtr<Gdk::Pixmap> orig);
135 void clip_viewable_buffer(Glib::RefPtr<Gdk::Pixmap> pixmap, Glib::RefPtr<Gdk::GC> gc, Vector<int> pos, Glib::RefPtr<Gdk::Pixmap> out);