1 // $Id: zoom_graphic_context.hxx,v 1.13 2003/07/24 21:33:11 grumbel Exp $
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef HEADER_ZOOM_GRAPHIC_CONTEXT_HXX
21 #define HEADER_ZOOM_GRAPHIC_CONTEXT_HXX
23 #include "vector2d.hxx"
24 #include "graphic_context.hxx"
26 /** A GraphicContext, that wraps another GraphicContext and adds
27 coordinate translation like zoom and scrolling */
28 class ZoomGraphicContext
: public GraphicContext
36 GraphicContext
* parent_gc
;
42 int translate_x (int);
43 int translate_y (int);
45 ZoomGraphicContext ();
46 ZoomGraphicContext (int x1_
, int y1_
, int x2_
, int y2_
);
48 void set_clip_rect (int x1_
, int y1_
, int x2_
, int y2_
);
50 /** Sets the clipping rectangles needed for the GC */
53 /** Resets the clipping to the old state */
56 void draw_lines (std::vector
<Line
>& lines
, Color color
, int wide
= 0);
57 void draw_line(float x1
, float y1
, float x2
, float y2
, Color color
, int wide
= 0);
58 void draw_rect(float x1
, float y1
, float x2
, float y2
, Color color
);
59 void draw_circle(float x
, float y
, float r
, Color color
);
60 void draw_circles(std::vector
<Circle
>& circles
, Color color
);
61 void draw_fill_circle(float x
, float y
, float r
, Color color
);
62 void draw_fill_rect(float x1
, float y1
, float x2
, float y2
, Color color
);
63 void draw_string(float x
, float y
, const std::string
& str
, Color color
= Color (0xFFFFFFFF));
64 void draw_string_centered(float x
, float y
, const std::string
& str
, Color color
= Color (0xFFFFFFFF));
69 void clear () { parent_gc
->clear (); }
71 /** FIXME: flip should be handled outsite of GraphicContext */
72 void flip () { parent_gc
->flip (); }
74 void set_parent_gc (GraphicContext
* gc
);
77 * Zoom Out the GraphicContext by one 'unit', using the x and y
80 * @param x x in screen coordinates
81 * @param y y in screen coordinates
83 * @return true if zoom was successfull, false if zoom boundaries
86 bool zoom_in (int x
, int y
);
89 * Zoom Into the GraphicContext by one 'unit', using the x and y
92 * @param x x in screen coordinates
93 * @param y y in screen coordinates
95 * @return true if zoom was successfull, false if zoom boundaries
98 bool zoom_out (int x
, int y
);
101 * Zoom into the given area, all coordinates in world units
103 * @param x1 left border in world coordinates
104 * @param y1 top border in world coordinates
105 * @param x2 right border in world coordinates
106 * @param y2 bottom border in world coordinates
108 void zoom_to (int x1
, int y1
, int x2
, int y2
);
110 /** Move to the given x and y world coordinates to the center of the
112 void move_to (float x
, float y
);
114 /** Allows a client application to make use of the partent GC in
115 case it wants to draw elements which should not get scaled */
116 GraphicContext
* get_parent_gc () { return parent_gc
; }
118 /** Move the current position relativly x/y width */
119 void translate_offset (int x
, int y
);
121 /** FIXME: What exactly is an offset?! */
122 void set_offset (float x
, float y
);
124 /** FIXME: What exactly is an offset?! */
125 float get_x_offset () { return x_offset
; }
127 /** FIXME: What exactly is an offset?! */
128 float get_y_offset () { return y_offset
; }
130 /** @return current zoom factor in use */
131 float get_zoom () const { return zoom
; }
133 /** Set the zoom factor, if zoom is to large/small false will
134 returned and zoom will be set to lowest/highest possible
136 bool set_zoom (const float& z
);
138 /** Convert a coordinate from screen units to world units */
139 float screen_to_world_x (float x
);
141 /** Convert a coordinate from screen units to world units */
142 float screen_to_world_y (float y
);
144 /** Convert a coordinate from world units to screen units */
145 float world_to_screen_x (float x
);
147 /** Convert a coordinate from world units to screen units */
148 float world_to_screen_y (float y
);
150 /** Convert a coordinate from screen units to world units */
151 Vector2d
screen_to_world (const Vector2d
&);
153 /** Convert a coordinate from world units to screen units */
154 Vector2d
world_to_screen (const Vector2d
&);
156 void flip (int x1
, int y1
, int x2
, int y2
);
158 void push_quick_draw() { parent_gc
->push_quick_draw(); }
159 void pop_quick_draw() { parent_gc
->pop_quick_draw(); }