4 #include <gdk/gdkkeysyms.h>
6 #include <glib/gi18n.h>
9 #include "ui-toolbar.h"
11 #include "tbo-window.h"
12 #include "ui-drawing.h"
18 #include "frame-tool.h"
19 #include "selector-tool.h"
20 #include "doodle-tool.h"
24 Frame *FRAME_VIEW = NULL;
25 float ZOOM_STEP = 0.05;
27 gboolean KEY_BINDER = TRUE;
30 tbo_drawing_draw_page (cairo_t *cr, Page *page, int w, int h)
36 cairo_set_source_rgb(cr, 1, 1, 1);
37 cairo_rectangle(cr, 0, 0, w, h);
40 for (frame_list = tbo_page_get_frames (page); frame_list; frame_list = frame_list->next)
43 frame = (Frame *)frame_list->data;
44 tbo_frame_draw (frame, cr);
49 tbo_drawing_draw (cairo_t *cr, TboWindow *tbo)
57 w = tbo->comic->width;
58 h = tbo->comic->height;
60 cairo_set_source_rgb(cr, 1, 1, 1);
61 cairo_rectangle(cr, 0, 0, w*ZOOM, h*ZOOM);
64 cairo_scale (cr, ZOOM, ZOOM);
66 page = tbo_comic_get_current_page (tbo->comic);
70 for (frame_list = tbo_page_get_frames (page); frame_list; frame_list = frame_list->next)
73 frame = (Frame *)frame_list->data;
74 tbo_frame_draw (frame, cr);
79 tbo_frame_draw_scaled (FRAME_VIEW, cr, w, h);
84 on_key_cb (GtkWidget *widget,
89 void **data = malloc (sizeof(void *)*3);
94 tool = get_selected_tool ();
95 tool_signal (tool, TOOL_KEY, data);
99 tbo_window_update_status (tbo, 0, 0);
103 switch (event->keyval)
106 tbo_drawing_zoom_in (tbo);
109 tbo_drawing_zoom_out (tbo);
112 tbo_drawing_zoom_100 (tbo);
115 tbo_drawing_zoom_fit (tbo);
118 set_selected_tool_and_action (SELECTOR, tbo);
121 set_selected_tool_and_action (TEXT, tbo);
124 set_selected_tool_and_action (DOODLE, tbo);
127 set_selected_tool_and_action (FRAME, tbo);
137 on_expose_cb (GtkWidget *widget,
138 GdkEventExpose *event,
145 cr = gdk_cairo_create(GTK_LAYOUT (widget)->bin_window);
147 cairo_set_source_rgb (cr, 0, 0, 0);
148 cairo_rectangle (cr, 0, 0, widget->allocation.width,
149 widget->allocation.height);
152 tbo_drawing_draw (cr, tbo);
154 // Update drawing helpers
155 tool = get_selected_tool ();
156 tool_signal (tool, TOOL_DRAWING, cr);
164 on_move_cb (GtkWidget *widget,
165 GdkEventMotion *event,
170 void **data = malloc (sizeof(void *)*3);
172 event->x = event->x / ZOOM;
173 event->y = event->y / ZOOM;
177 tool = get_selected_tool ();
178 tool_signal (tool, TOOL_MOVE, data);
181 update_drawing (tbo);
182 tbo_window_update_status (tbo, (int)event->x, (int)event->y);
187 on_click_cb (GtkWidget *widget,
188 GdkEventButton *event,
192 void **data = malloc (sizeof(void *)*3);
194 event->x = event->x / ZOOM;
195 event->y = event->y / ZOOM;
199 tool = get_selected_tool ();
200 tool_signal (tool, TOOL_CLICK, data);
203 update_drawing (tbo);
204 tbo_window_update_status (tbo, (int)event->x, (int)event->y);
209 on_release_cb (GtkWidget *widget,
210 GdkEventButton *event,
214 void **data = malloc (sizeof(void *)*3);
216 event->x = event->x / ZOOM;
217 event->y = event->y / ZOOM;
222 tool = get_selected_tool ();
223 tool_signal (tool, TOOL_RELEASE, data);
226 update_drawing (tbo);
227 tbo_window_update_status (tbo, (int)event->x, (int)event->y);
232 get_drawing_area (int width, int height)
237 drawing = gtk_layout_new(NULL, NULL);
238 gtk_layout_set_size (GTK_LAYOUT (drawing), width+2, height+2);
244 darea_connect_signals (TboWindow *tbo, GtkWidget *drawing)
246 gtk_widget_add_events (drawing, GDK_BUTTON_PRESS_MASK |
247 GDK_BUTTON_RELEASE_MASK |
248 GDK_POINTER_MOTION_MASK);
250 g_signal_connect(drawing, "expose-event",
251 G_CALLBACK (on_expose_cb), tbo);
253 g_signal_connect (drawing, "button_press_event",
254 G_CALLBACK (on_click_cb), tbo);
256 g_signal_connect (drawing, "button_release_event",
257 G_CALLBACK (on_release_cb), tbo);
259 g_signal_connect (drawing, "motion_notify_event",
260 G_CALLBACK (on_move_cb), tbo);
263 gtk_drag_dest_set (drawing, GTK_DEST_DEFAULT_ALL, TARGET_LIST, N_TARGETS, GDK_ACTION_COPY);
264 g_signal_connect (drawing, "drag-data-received", G_CALLBACK(drag_data_received_handl), tbo);
268 darea_disconnect_signals (TboWindow *tbo, GtkWidget *drawing)
270 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_expose_cb), tbo);
271 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_click_cb), tbo);
272 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_release_cb), tbo);
273 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_move_cb), tbo);
274 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK(drag_data_received_handl), tbo);
278 update_drawing (TboWindow *tbo)
280 gtk_widget_queue_draw_area (tbo->drawing,
282 tbo->drawing->allocation.width,
283 tbo->drawing->allocation.height);
287 set_frame_view (Frame *frame)
298 void tbo_drawing_zoom_in (TboWindow *tbo)
301 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
302 update_drawing (tbo);
305 void tbo_drawing_zoom_out (TboWindow *tbo)
308 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
309 update_drawing (tbo);
312 void tbo_drawing_zoom_100 (TboWindow *tbo)
315 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
316 update_drawing (tbo);
319 void tbo_drawing_zoom_fit (TboWindow *tbo)
323 w = tbo->drawing->allocation.width;
324 h = tbo->drawing->allocation.height;
326 z1 = fabs ((float)w / (float)tbo->comic->width);
327 z2 = fabs ((float)h / (float)tbo->comic->height);
328 ZOOM = z1 < z2 ? z1 : z2;
330 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
331 update_drawing (tbo);
335 tbo_drawing_get_zoom ()
341 set_key_binder (gboolean binder)