52
/* Expose event: this occurs when the window is shown. */
54
/* On configure event. */
53
55
G_MODULE_EXPORT gboolean
54
on_expose (GtkWidget *widget,
55
GdkEventExpose *event,
56
on_configure (GtkWidget *widget,
57
GdkEventExpose *event,
58
AnnotateData *data = (AnnotateData *) func_data;
60
gint is_fullscreen = gdk_window_get_state (gtk_widget_get_window (widget)) & GDK_WINDOW_STATE_FULLSCREEN;
60
AnnotateData *data = (AnnotateData *) user_data;
64
g_printerr ("Expose event\n");
64
g_printerr("DEBUG: Annotation window get configure event (%d,%d)\n",
65
gtk_widget_get_allocated_width (widget),
66
gtk_widget_get_allocated_height (widget));
69
GdkWindowState state = gdk_window_get_state (gtk_widget_get_window (widget));
70
gint is_fullscreen = state & GDK_WINDOW_STATE_FULLSCREEN;
67
72
if (!is_fullscreen)
72
77
initialize_annotation_cairo_context (data);
79
if (!data->is_grabbed)
74
84
/* Postcondition; data->annotation_cairo_context is not NULL. */
89
/* On screen changed. */
91
on_screen_changed (GtkWidget *widget,
92
GdkScreen *previous_screen,
95
AnnotateData *data = (AnnotateData *) user_data;
99
g_printerr("DEBUG: Annotation window get screen-changed event\n");
102
GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (widget));
103
GdkVisual *visual = gdk_screen_get_rgba_visual (screen);
107
visual = gdk_screen_get_system_visual (screen);
110
gtk_widget_set_visual (widget, visual);
114
/* Expose event: this occurs when the window is shown. */
115
G_MODULE_EXPORT gboolean
116
on_expose (GtkWidget *widget,
120
AnnotateData *data = (AnnotateData *) user_data;
124
g_printerr ("DEBUG: Annotation window get expose event\n");
75
127
annotate_restore_surface ();
86
137
/* This is called when the button is pushed. */
87
138
G_MODULE_EXPORT gboolean
88
on_button_press (GtkWidget *win,
139
on_button_press (GtkWidget *win,
93
AnnotateData *data = (AnnotateData *) func_data;
144
AnnotateData *data = (AnnotateData *) user_data;
146
/* Get the data for this device. */
147
AnnotateDeviceData *devdata = g_hash_table_lookup(data->devdatatable, ev->device);
94
149
gdouble pressure = 1.0;
96
initialize_annotation_cairo_context(data);
151
if (!data->is_grabbed)
100
158
g_printerr ("Device '%s': Invalid event; I ungrab all\n",
159
gdk_device_get_name (ev->device));
103
160
annotate_release_grab ();
109
166
g_printerr ("Device '%s': Button %i Down at (x,y)= (%f : %f)\n",
110
ev->device->name, ev->button, ev->x, ev->y);
167
gdk_device_get_name (ev->device),
116
176
/* The point is inside the ardesia bar then ungrab. */
117
177
annotate_release_grab ();
181
if (data->cur_context->type == ANNOTATE_PEN)
183
annotate_select_tool (data, ev->device, ev->state);
184
data->old_paint_type = ANNOTATE_PEN;
188
data->old_paint_type = ANNOTATE_ERASER;
122
annotate_coord_list_free ();
124
annotate_unhide_cursor ();
126
annotate_reset_cairo ();
128
192
pressure = get_pressure ( (GdkEvent *) ev);
130
194
if (pressure <= 0)
135
annotate_draw_point (ev->x, ev->y, pressure);
137
annotate_coord_list_prepend (ev->x, ev->y,
138
annotate_get_thickness (),
199
initialize_annotation_cairo_context(data);
201
annotate_configure_pen_options (data);
203
annotate_coord_dev_list_free (devdata);
205
annotate_unhide_cursor ();
207
annotate_draw_point (devdata, ev->x, ev->y, pressure);
209
annotate_coord_list_prepend (devdata,
212
annotate_get_thickness (),
145
219
/* This shots when the pointer is moving. */
146
220
G_MODULE_EXPORT gboolean
147
on_motion_notify (GtkWidget *win,
221
on_motion_notify (GtkWidget *win,
151
AnnotateData *data = (AnnotateData *) func_data;
225
AnnotateData *data = (AnnotateData *) user_data;
227
/* Get the data for this device. */
228
AnnotateDeviceData *devdata = g_hash_table_lookup(data->devdatatable, ev->device);
152
230
GdkModifierType state = (GdkModifierType) ev->state;
153
231
gdouble selected_width = 0.0;
154
232
gdouble pressure = 1.0;
234
if (!data->is_grabbed)
158
241
g_printerr ("Device '%s': Invalid event; I ungrab all\n",
242
gdk_device_get_name (ev->device));
160
243
annotate_release_grab ();
170
g_printerr ("Device '%s': Move on the bar then ungrab\n",
253
g_printerr ("Device '%s': Move on the bar then ungrab\n",
254
gdk_device_get_name (ev->device));
174
257
/* The point is inside the ardesia bar then ungrab. */
175
258
annotate_release_grab ();
180
263
annotate_unhide_cursor ();
182
265
/* Only the first 5 buttons allowed. */
184
(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | GDK_BUTTON5_MASK)))
267
(GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK | GDK_BUTTON4_MASK | GDK_BUTTON5_MASK)))
186
269
/* The button is not pressed. */
191
273
initialize_annotation_cairo_context (data);
193
if ( (ev->device->source != GDK_SOURCE_MOUSE) &&
194
(data->cur_context->type != ANNOTATE_ERASER))
275
annotate_configure_pen_options (data);
277
/* Select the new color. */
278
annotate_modify_color (devdata, data, pressure);
280
if (data->cur_context->type != ANNOTATE_ERASER)
196
282
pressure = get_pressure ( (GdkEvent *) ev);
198
284
if (pressure <= 0)
203
289
/* If the point is already selected and higher pressure then print else jump it. */
204
if (data->coord_list)
206
AnnotatePoint *last_point = (AnnotatePoint *) g_slist_nth_data (data->coord_list, 0);
207
gdouble tollerance = data->thickness;
208
if (get_distance (last_point->x, last_point->y, ev->x, ev->y)<tollerance)
211
/* Seems that you are uprising the pen. */
212
if (pressure <= last_point->pressure)
214
/* Jump the point you are uprising the hand. */
217
else // pressure >= last_point->pressure
219
/* Seems that you are pressing the pen more. */
220
annotate_modify_color (data, pressure);
221
annotate_draw_line (ev->x, ev->y, TRUE);
222
/* Store the new pressure without allocate a new coordinate. */
223
last_point->pressure = pressure;
228
annotate_modify_color (data, pressure);
290
if (devdata->coord_list)
292
AnnotatePoint *last_point = (AnnotatePoint *) g_slist_nth_data (devdata->coord_list, 0);
293
gdouble tollerance = annotate_get_thickness ();
295
if (get_distance (last_point->x, last_point->y, ev->x, ev->y)<tollerance)
297
/* Seems that you are uprising the pen. */
298
if (pressure <= last_point->pressure)
300
/* Jump the point you are uprising the hand. */
303
else // pressure >= last_point->pressure
305
/* Seems that you are pressing the pen more. */
306
annotate_modify_color (devdata, data, pressure);
307
annotate_draw_line (devdata, ev->x, ev->y, TRUE);
308
/* Store the new pressure without allocate a new coordinate. */
309
last_point->pressure = pressure;
313
annotate_modify_color (devdata, data, pressure);
232
annotate_draw_line (ev->x, ev->y, TRUE);
234
annotate_coord_list_prepend (ev->x, ev->y, selected_width, pressure);
317
annotate_draw_line (devdata, ev->x, ev->y, TRUE);
318
annotate_coord_list_prepend (devdata, ev->x, ev->y, selected_width, pressure);
240
324
/* This shots when the button is released. */
241
325
G_MODULE_EXPORT gboolean
242
on_button_release (GtkWidget *win,
326
on_button_release (GtkWidget *win,
246
AnnotateData *data = (AnnotateData *) func_data;
247
guint lenght = g_slist_length (data->coord_list);
330
AnnotateData *data = (AnnotateData *) user_data;
332
/* Get the data for this device. */
333
AnnotateDeviceData *devdata = g_hash_table_lookup(data->devdatatable, ev->device);
335
guint lenght = g_slist_length (devdata->coord_list);
337
if (!data->is_grabbed)
251
344
g_printerr ("Device '%s': Invalid event; I ungrab all\n",
345
gdk_device_get_name (ev->device));
253
346
annotate_release_grab ();
259
352
g_printerr ("Device '%s': Button %i Up at (x,y)= (%.2f : %.2f)\n",
260
ev->device->name, ev->button, ev->x, ev->y);
353
gdk_device_get_name (ev->device),
354
ev->button, ev->x, ev->y);
265
358
if (inside_bar_window (ev->x_root, ev->y_root))
266
359
/* Point is in the ardesia bar. */
268
361
/* The last point was outside the bar then ungrab. */
269
362
annotate_release_grab ();
365
if (data->old_paint_type == ANNOTATE_PEN)
367
annotate_select_pen ();
275
371
initialize_annotation_cairo_context(data);
279
AnnotatePoint *first_point = (AnnotatePoint *) g_slist_nth_data (data->coord_list, lenght-1);
280
AnnotatePoint *last_point = (AnnotatePoint *) g_slist_nth_data (data->coord_list, 0);
375
AnnotatePoint *first_point = (AnnotatePoint *) g_slist_nth_data (devdata->coord_list, lenght-1);
376
AnnotatePoint *last_point = (AnnotatePoint *) g_slist_nth_data (devdata->coord_list, 0);
282
378
gdouble distance = get_distance (ev->x, ev->y, first_point->x, first_point->y);
284
380
/* This is the tolerance to force to close the path in a magnetic way. */
285
gdouble tollerance = data->thickness * 2;
383
/* If is applied some handled drawing mode then the tool is more tollerant. */
384
if ((data->rectify || data->roundify))
389
gdouble tollerance = annotate_get_thickness () * score;
286
391
gdouble pressure = last_point->pressure;
288
393
gboolean closed_path = FALSE;
290
395
/* If the distance between two point lesser than tolerance they are the same point for me. */
291
396
if (distance > tollerance)
293
398
/* Different point. */
294
cairo_line_to (data->annotation_cairo_context, ev->x, ev->y);
295
annotate_coord_list_prepend (ev->x, ev->y, data->thickness, pressure);
399
annotate_draw_line (devdata, ev->x, ev->y, TRUE);
400
annotate_coord_list_prepend (devdata, ev->x, ev->y, annotate_get_thickness (), pressure);
299
/* Rounded to be tha same point. */
404
/* Rounded to be the same point. */
300
405
closed_path = TRUE; // this seems to be a closed path
302
cairo_line_to (data->annotation_cairo_context, first_point->x, first_point->y);
303
annotate_coord_list_prepend (first_point->x, first_point->y, data->thickness, pressure);
406
annotate_draw_line (devdata, first_point->x, first_point->y, TRUE);
407
annotate_coord_list_prepend (devdata, first_point->x, first_point->y, annotate_get_thickness (), pressure);
306
410
if (data->cur_context->type != ANNOTATE_ERASER)
308
annotate_shape_recognize (closed_path);
412
annotate_shape_recognize (devdata, closed_path);
310
414
/* If is selected an arrow type then I draw the arrow. */
313
/* Print arrow at the end of the path. */
314
annotate_draw_arrow (distance);
417
/* Print arrow at the end of the path. */
418
annotate_draw_arrow (devdata, distance);
320
423
cairo_stroke_preserve (data->annotation_cairo_context);
322
425
annotate_add_savepoint ();
324
427
annotate_hide_cursor ();