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>
28 #include "zoom_frame.h"
30 #include "rendering.h"
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.
50 static gint width
= 0;
51 static gint height
= 0;
52 static GdkGC
*gc
= NULL
;
55 d
= gl_widget
->window
;
59 gdk_gc_set_foreground(gc
, &(gl_widget
->style
->white
));
60 gdk_gc_set_function(gc
, GDK_XOR
);
64 /* Erase the previous frame. */
65 gdk_draw_rectangle(d
, gc
, FALSE
, x
, y
, width
, height
);
67 /* Update saved coordinates. */
70 width
= zoom_frame_width
;
71 height
= zoom_frame_height
;
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
)
86 zoom_frame_x
= x
+ width
;
87 zoom_frame_width
= -width
;
90 zoom_frame_width
= width
;
94 zoom_frame_y
= y
+ height
;
95 zoom_frame_height
= -height
;
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)
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
);
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;
129 matrix_zoom(zoom
, x
, y
);
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
);