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"
23 #include "tbo-tooltip.h"
26 Frame *FRAME_VIEW = NULL;
27 float ZOOM_STEP = 0.05;
29 gboolean KEY_BINDER = TRUE;
32 tbo_drawing_draw_page (cairo_t *cr, Page *page, int w, int h)
38 cairo_set_source_rgb(cr, 1, 1, 1);
39 cairo_rectangle(cr, 0, 0, w, h);
42 for (frame_list = tbo_page_get_frames (page); frame_list; frame_list = frame_list->next)
45 frame = (Frame *)frame_list->data;
46 tbo_frame_draw (frame, cr);
51 tbo_drawing_draw (cairo_t *cr, TboWindow *tbo)
59 w = tbo->comic->width;
60 h = tbo->comic->height;
62 cairo_set_source_rgb(cr, 1, 1, 1);
63 cairo_rectangle(cr, 0, 0, w*ZOOM, h*ZOOM);
66 cairo_scale (cr, ZOOM, ZOOM);
68 page = tbo_comic_get_current_page (tbo->comic);
72 for (frame_list = tbo_page_get_frames (page); frame_list; frame_list = frame_list->next)
75 frame = (Frame *)frame_list->data;
76 tbo_frame_draw (frame, cr);
81 tbo_frame_draw_scaled (FRAME_VIEW, cr, w, h);
86 on_key_cb (GtkWidget *widget,
91 void **data = malloc (sizeof(void *)*3);
96 tool = get_selected_tool ();
97 tool_signal (tool, TOOL_KEY, data);
100 update_drawing (tbo);
101 tbo_window_update_status (tbo, 0, 0);
105 switch (event->keyval)
108 tbo_drawing_zoom_in (tbo);
111 tbo_drawing_zoom_out (tbo);
114 tbo_drawing_zoom_100 (tbo);
117 tbo_drawing_zoom_fit (tbo);
120 set_selected_tool_and_action (SELECTOR, tbo);
123 set_selected_tool_and_action (TEXT, tbo);
126 set_selected_tool_and_action (DOODLE, tbo);
129 set_selected_tool_and_action (FRAME, tbo);
139 on_expose_cb (GtkWidget *widget,
140 GdkEventExpose *event,
147 cr = gdk_cairo_create(GTK_LAYOUT (widget)->bin_window);
149 cairo_set_source_rgb (cr, 0, 0, 0);
150 cairo_rectangle (cr, 0, 0, widget->allocation.width,
151 widget->allocation.height);
154 tbo_drawing_draw (cr, tbo);
156 tbo_tooltip_draw (cr);
158 // Update drawing helpers
159 tool = get_selected_tool ();
160 tool_signal (tool, TOOL_DRAWING, cr);
168 on_move_cb (GtkWidget *widget,
169 GdkEventMotion *event,
174 void **data = malloc (sizeof(void *)*3);
176 event->x = event->x / ZOOM;
177 event->y = event->y / ZOOM;
181 tool = get_selected_tool ();
182 tool_signal (tool, TOOL_MOVE, data);
185 update_drawing (tbo);
186 tbo_window_update_status (tbo, (int)event->x, (int)event->y);
192 on_click_cb (GtkWidget *widget,
193 GdkEventButton *event,
197 void **data = malloc (sizeof(void *)*3);
199 event->x = event->x / ZOOM;
200 event->y = event->y / ZOOM;
204 tool = get_selected_tool ();
208 set_selected_tool_and_action (SELECTOR, tbo);
211 tool_signal (tool, TOOL_CLICK, data);
215 update_drawing (tbo);
216 tbo_window_update_status (tbo, (int)event->x, (int)event->y);
221 on_release_cb (GtkWidget *widget,
222 GdkEventButton *event,
226 void **data = malloc (sizeof(void *)*3);
228 event->x = event->x / ZOOM;
229 event->y = event->y / ZOOM;
234 tool = get_selected_tool ();
235 tool_signal (tool, TOOL_RELEASE, data);
238 update_drawing (tbo);
239 tbo_window_update_status (tbo, (int)event->x, (int)event->y);
244 get_drawing_area (int width, int height)
249 drawing = gtk_layout_new(NULL, NULL);
250 gtk_layout_set_size (GTK_LAYOUT (drawing), width+2, height+2);
256 darea_connect_signals (TboWindow *tbo, GtkWidget *drawing)
258 gtk_widget_add_events (drawing, GDK_BUTTON_PRESS_MASK |
259 GDK_BUTTON_RELEASE_MASK |
260 GDK_POINTER_MOTION_MASK);
262 g_signal_connect(drawing, "expose-event",
263 G_CALLBACK (on_expose_cb), tbo);
265 g_signal_connect (drawing, "button_press_event",
266 G_CALLBACK (on_click_cb), tbo);
268 g_signal_connect (drawing, "button_release_event",
269 G_CALLBACK (on_release_cb), tbo);
271 g_signal_connect (drawing, "motion_notify_event",
272 G_CALLBACK (on_move_cb), tbo);
275 gtk_drag_dest_set (drawing, GTK_DEST_DEFAULT_ALL, TARGET_LIST, N_TARGETS, GDK_ACTION_COPY);
276 g_signal_connect (drawing, "drag-data-received", G_CALLBACK(drag_data_received_handl), tbo);
280 darea_disconnect_signals (TboWindow *tbo, GtkWidget *drawing)
282 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_expose_cb), tbo);
283 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_click_cb), tbo);
284 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_release_cb), tbo);
285 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_move_cb), tbo);
286 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK(drag_data_received_handl), tbo);
290 update_drawing (TboWindow *tbo)
292 gtk_widget_queue_draw_area (tbo->drawing,
294 tbo->drawing->allocation.width,
295 tbo->drawing->allocation.height);
299 set_frame_view (Frame *frame)
310 void tbo_drawing_zoom_in (TboWindow *tbo)
313 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
314 update_drawing (tbo);
317 void tbo_drawing_zoom_out (TboWindow *tbo)
320 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
321 update_drawing (tbo);
324 void tbo_drawing_zoom_100 (TboWindow *tbo)
327 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
328 update_drawing (tbo);
331 void tbo_drawing_zoom_fit (TboWindow *tbo)
335 w = tbo->drawing->allocation.width;
336 h = tbo->drawing->allocation.height;
338 z1 = fabs ((float)w / (float)tbo->comic->width);
339 z2 = fabs ((float)h / (float)tbo->comic->height);
340 ZOOM = z1 < z2 ? z1 : z2;
342 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
343 update_drawing (tbo);
347 tbo_drawing_get_zoom ()
353 set_key_binder (gboolean binder)
359 tbo_drawing_adjust_scroll (TboWindow *tbo)
361 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
362 update_drawing (tbo);