Remove the trace of a TODO file.
[gliv.git] / src / zoom_frame.c
blob449fcd8a45c15dc4eeeb81eeba6af8c80e823aaf
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 * See the COPYING file for license information.
18 * Guillaume Chazarain <guichaz@yahoo.fr>
21 /************************************
22 * The zoom frame with funky colors *
23 ************************************/
25 #include <gtk/gtkgl.h>
27 #include "gliv.h"
28 #include "zoom_frame.h"
29 #include "options.h"
30 #include "rendering.h"
31 #include "matrix.h"
33 extern rt_struct *rt;
34 extern GtkWidget *gl_widget;
36 /* Dimensions of the zoom frame. */
37 static gint zoom_frame_x, zoom_frame_y;
38 static gint zoom_frame_width, zoom_frame_height;
40 static gboolean zoom_frame_cleared = FALSE;
42 void draw_zoom_frame(gboolean draw)
45 * We keep the coordinates of the previous
46 * frame to erase it with a XOR.
48 static gint x = 0;
49 static gint y = 0;
50 static gint width = 0;
51 static gint height = 0;
52 static GdkGC *gc = NULL;
53 GdkDrawable *d;
55 d = gl_widget->window;
56 if (gc == NULL) {
57 /* First time. */
58 gc = gdk_gc_new(d);
59 gdk_gc_set_foreground(gc, &(gl_widget->style->white));
60 gdk_gc_set_function(gc, GDK_XOR);
63 if (draw)
64 /* Erase the previous frame. */
65 gdk_draw_rectangle(d, gc, FALSE, x, y, width, height);
67 /* Update saved coordinates. */
68 x = zoom_frame_x;
69 y = zoom_frame_y;
70 width = zoom_frame_width;
71 height = zoom_frame_height;
73 if (draw) {
74 /* Draw the new frame. */
75 gdk_draw_rectangle(d, gc, FALSE, x, y, width, height);
77 zoom_frame_cleared = FALSE;
79 gdk_gl_drawable_wait_gdk(gtk_widget_get_gl_drawable(gl_widget));
83 void set_zoom_frame(gint x, gint y, gint width, gint height)
85 if (width < 0) {
86 zoom_frame_x = x + width;
87 zoom_frame_width = -width;
88 } else {
89 zoom_frame_x = x;
90 zoom_frame_width = width;
93 if (height < 0) {
94 zoom_frame_y = y + height;
95 zoom_frame_height = -height;
96 } else {
97 zoom_frame_y = y;
98 zoom_frame_height = height;
102 void clear_zoom_frame(void)
104 if (zoom_frame_cleared == FALSE) {
105 set_zoom_frame(-1, -1, 0, 0);
106 draw_zoom_frame(FALSE);
107 zoom_frame_cleared = TRUE;
111 void zoom_frame(void)
113 gfloat x, y, zoom;
115 if (zoom_frame_width == 0 || zoom_frame_height == 0) {
116 /* To avoid division by zero. */
117 set_zoom_frame(-1, -1, 0, 0);
118 draw_zoom_frame(TRUE);
119 return;
122 zoom = MIN((gfloat) rt->wid_size->width / zoom_frame_width,
123 (gfloat) rt->wid_size->height / zoom_frame_height);
125 x = zoom_frame_x + zoom_frame_width / 2.0;
126 y = zoom_frame_y + zoom_frame_height / 2.0;
128 /* zoom. */
129 matrix_zoom(zoom, x, y);
131 /* center. */
132 matrix_move(rt->wid_size->width / 2.0 - x, rt->wid_size->height / 2.0 - y);
134 refresh(REFRESH_IMAGE | REFRESH_STATUS | APPEND_HISTORY);