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 ************************************/
26 #include "zoom_frame.h"
28 #include "rendering.h"
33 extern GtkWidget
*gl_widget
;
35 /* Dimensions of the zoom frame. */
36 static gint zoom_frame_x
, zoom_frame_y
;
37 static gint zoom_frame_width
, zoom_frame_height
;
39 static gboolean zoom_frame_cleared
= FALSE
;
41 #define TARGET_SIZE 10
43 /* This the box with the cross and the circle in it. */
44 static void draw_zoom_box(GdkDrawable
* d
, GdkGC
* gc
,
45 gint x
, gint y
, gint w
, gint h
, gboolean clear
)
47 static gint target
= 0;
49 gdk_draw_rectangle(d
, gc
, FALSE
, x
, y
, w
, h
);
51 if (w
> TARGET_SIZE
* 2 && h
> TARGET_SIZE
* 2) {
52 gint x_middle
= x
+ w
/ 2;
53 gint y_middle
= y
+ h
/ 2;
55 /* If we are clearing, we must reuse the same parameters. */
58 if (target
== 180 * 64)
62 gdk_draw_line(d
, gc
, x_middle
, y_middle
- TARGET_SIZE
/ 3,
63 x_middle
, y_middle
+ TARGET_SIZE
/ 3);
65 gdk_draw_line(d
, gc
, x_middle
- TARGET_SIZE
/ 3, y_middle
,
66 x_middle
+ TARGET_SIZE
/ 3, y_middle
);
68 gdk_draw_arc(d
, gc
, FALSE
,
69 x_middle
- TARGET_SIZE
, y_middle
- TARGET_SIZE
,
70 TARGET_SIZE
* 2, TARGET_SIZE
* 2, target
, 90 * 64);
72 gdk_draw_arc(d
, gc
, FALSE
,
73 x_middle
- TARGET_SIZE
, y_middle
- TARGET_SIZE
,
74 TARGET_SIZE
* 2, TARGET_SIZE
* 2,
75 target
+ 180 * 64, 90 * 64);
79 void draw_zoom_frame(void)
82 * We keep the coordinates of the previous
83 * frame to erase it with a XOR.
87 static gint width
= 0;
88 static gint height
= 0;
89 static GdkGC
*gc
= NULL
;
92 d
= gl_widget
->window
;
96 gdk_gc_set_foreground(gc
, &(gl_widget
->style
->white
));
97 gdk_gc_set_function(gc
, GDK_XOR
);
100 /* Erase the previous frame. */
101 draw_zoom_box(d
, gc
, x
, y
, width
, height
, TRUE
);
103 /* Update saved coordinates. */
106 width
= zoom_frame_width
;
107 height
= zoom_frame_height
;
109 /* Draw the new frame. */
110 draw_zoom_box(d
, gc
, x
, y
, width
, height
, FALSE
);
112 zoom_frame_cleared
= FALSE
;
114 gdk_gl_drawable_wait_gdk(gtk_widget_get_gl_drawable(gl_widget
));
117 void set_zoom_frame(gint x
, gint y
, gint width
, gint height
)
120 zoom_frame_x
= x
+ width
;
121 zoom_frame_width
= -width
;
124 zoom_frame_width
= width
;
128 zoom_frame_y
= y
+ height
;
129 zoom_frame_height
= -height
;
132 zoom_frame_height
= height
;
136 void clear_zoom_frame(void)
138 if (zoom_frame_cleared
== FALSE
) {
139 set_zoom_frame(-1, -1, 0, 0);
141 zoom_frame_cleared
= TRUE
;
145 void zoom_frame(void)
149 if (zoom_frame_width
== 0 || zoom_frame_height
== 0) {
150 /* To avoid division by zero. */
151 set_zoom_frame(-1, -1, 0, 0);
156 zoom
= MIN((gfloat
) rt
->wid_size
->width
/ zoom_frame_width
,
157 (gfloat
) rt
->wid_size
->height
/ zoom_frame_height
);
159 x
= zoom_frame_x
+ zoom_frame_width
/ 2.0;
160 y
= zoom_frame_y
+ zoom_frame_height
/ 2.0;
163 matrix_zoom(zoom
, x
, y
);
166 matrix_move(rt
->wid_size
->width
/ 2.0 - x
, rt
->wid_size
->height
/ 2.0 - y
);
168 refresh(REFRESH_IMAGE
| REFRESH_STATUS
| APPEND_HISTORY
);