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 ();
205 tool_signal (tool, TOOL_CLICK, data);
208 update_drawing (tbo);
209 tbo_window_update_status (tbo, (int)event->x, (int)event->y);
214 on_release_cb (GtkWidget *widget,
215 GdkEventButton *event,
219 void **data = malloc (sizeof(void *)*3);
221 event->x = event->x / ZOOM;
222 event->y = event->y / ZOOM;
227 tool = get_selected_tool ();
228 tool_signal (tool, TOOL_RELEASE, data);
231 update_drawing (tbo);
232 tbo_window_update_status (tbo, (int)event->x, (int)event->y);
237 get_drawing_area (int width, int height)
242 drawing = gtk_layout_new(NULL, NULL);
243 gtk_layout_set_size (GTK_LAYOUT (drawing), width+2, height+2);
249 darea_connect_signals (TboWindow *tbo, GtkWidget *drawing)
251 gtk_widget_add_events (drawing, GDK_BUTTON_PRESS_MASK |
252 GDK_BUTTON_RELEASE_MASK |
253 GDK_POINTER_MOTION_MASK);
255 g_signal_connect(drawing, "expose-event",
256 G_CALLBACK (on_expose_cb), tbo);
258 g_signal_connect (drawing, "button_press_event",
259 G_CALLBACK (on_click_cb), tbo);
261 g_signal_connect (drawing, "button_release_event",
262 G_CALLBACK (on_release_cb), tbo);
264 g_signal_connect (drawing, "motion_notify_event",
265 G_CALLBACK (on_move_cb), tbo);
268 gtk_drag_dest_set (drawing, GTK_DEST_DEFAULT_ALL, TARGET_LIST, N_TARGETS, GDK_ACTION_COPY);
269 g_signal_connect (drawing, "drag-data-received", G_CALLBACK(drag_data_received_handl), tbo);
273 darea_disconnect_signals (TboWindow *tbo, GtkWidget *drawing)
275 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_expose_cb), tbo);
276 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_click_cb), tbo);
277 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_release_cb), tbo);
278 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK (on_move_cb), tbo);
279 g_signal_handlers_disconnect_by_func (drawing, G_CALLBACK(drag_data_received_handl), tbo);
283 update_drawing (TboWindow *tbo)
285 gtk_widget_queue_draw_area (tbo->drawing,
287 tbo->drawing->allocation.width,
288 tbo->drawing->allocation.height);
292 set_frame_view (Frame *frame)
303 void tbo_drawing_zoom_in (TboWindow *tbo)
306 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
307 update_drawing (tbo);
310 void tbo_drawing_zoom_out (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_100 (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_fit (TboWindow *tbo)
328 w = tbo->drawing->allocation.width;
329 h = tbo->drawing->allocation.height;
331 z1 = fabs ((float)w / (float)tbo->comic->width);
332 z2 = fabs ((float)h / (float)tbo->comic->height);
333 ZOOM = z1 < z2 ? z1 : z2;
335 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
336 update_drawing (tbo);
340 tbo_drawing_get_zoom ()
346 set_key_binder (gboolean binder)
352 tbo_drawing_adjust_scroll (TboWindow *tbo)
354 gtk_layout_set_size (GTK_LAYOUT (tbo->drawing), tbo->comic->width*ZOOM, tbo->comic->height*ZOOM);
355 update_drawing (tbo);