~ubuntu-branches/debian/sid/ardesia/sid

« back to all changes in this revision

Viewing changes to src/annotation_window_callbacks.c

  • Committer: Package Import Robot
  • Author(s): TANIGUCHI Takaki
  • Date: 2012-11-05 19:55:18 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20121105195518-ird6x2us0tui2q92
Tags: 1.1-1
* debian/watch: no longer use googlecode.d.n
* Imported Upstream version 1.1 (Closes: #620319, #692256)
* debian/control: add GTK+3 to B-D instead of GTK+2

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <annotation_window_callbacks.h>
31
31
#include <annotation_window.h>
32
32
#include <utils.h>
 
33
#include <input.h>
33
34
 
34
35
 
35
36
/* Return the pressure passing the event. */
36
 
static gdouble get_pressure (GdkEvent *ev)
 
37
static gdouble
 
38
get_pressure       (GdkEvent *ev)
37
39
{
38
40
  gdouble ret_value = 1.0;
39
41
  gdouble pressure = ret_value;
49
51
}
50
52
 
51
53
 
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
 
                 gpointer func_data)
 
56
on_configure       (GtkWidget      *widget,
 
57
                    GdkEventExpose *event,
 
58
                    gpointer        user_data)
57
59
{
58
 
  AnnotateData *data = (AnnotateData *) func_data;
59
 
 
60
 
  gint is_fullscreen = gdk_window_get_state (gtk_widget_get_window (widget)) & GDK_WINDOW_STATE_FULLSCREEN;
 
60
  AnnotateData *data = (AnnotateData *) user_data;
61
61
 
62
62
  if (data->debug)
63
63
    {
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));
65
67
    }
 
68
        
 
69
        GdkWindowState state = gdk_window_get_state (gtk_widget_get_window (widget));
 
70
  gint is_fullscreen = state & GDK_WINDOW_STATE_FULLSCREEN;
66
71
 
67
72
  if (!is_fullscreen)
68
73
    {
69
 
      return TRUE;
 
74
      return FALSE;
70
75
    }
71
76
 
72
77
  initialize_annotation_cairo_context (data);
73
 
 
 
78
  
 
79
  if (!data->is_grabbed)
 
80
    {
 
81
      return FALSE;
 
82
    }
 
83
        
74
84
  /* Postcondition; data->annotation_cairo_context is not NULL. */
 
85
  return TRUE;
 
86
}
 
87
 
 
88
 
 
89
/* On screen changed. */
 
90
G_MODULE_EXPORT void
 
91
on_screen_changed       (GtkWidget  *widget,
 
92
                         GdkScreen  *previous_screen,
 
93
                         gpointer    user_data)
 
94
{
 
95
  AnnotateData *data = (AnnotateData *) user_data;
 
96
 
 
97
  if (data->debug)
 
98
    {
 
99
      g_printerr("DEBUG: Annotation window get screen-changed event\n");
 
100
    }
 
101
 
 
102
  GdkScreen *screen = gtk_widget_get_screen (GTK_WIDGET (widget));
 
103
  GdkVisual *visual = gdk_screen_get_rgba_visual (screen);
 
104
  
 
105
  if (visual == NULL)
 
106
    {
 
107
      visual = gdk_screen_get_system_visual (screen);
 
108
    }
 
109
 
 
110
  gtk_widget_set_visual (widget, visual);
 
111
}
 
112
 
 
113
 
 
114
/* Expose event: this occurs when the window is shown. */
 
115
G_MODULE_EXPORT gboolean
 
116
on_expose          (GtkWidget *widget,
 
117
                    cairo_t   *cr,
 
118
                    gpointer   user_data)
 
119
{
 
120
  AnnotateData *data = (AnnotateData *) user_data;
 
121
  
 
122
  if (data->debug)
 
123
    {
 
124
      g_printerr ("DEBUG: Annotation window get expose event\n");
 
125
    }
 
126
 
75
127
  annotate_restore_surface ();
76
 
 
77
128
  return TRUE;
78
129
}
79
130
 
85
136
 
86
137
/* This is called when the button is pushed. */
87
138
G_MODULE_EXPORT gboolean
88
 
on_button_press (GtkWidget *win,
89
 
                 GdkEventButton *ev,
90
 
                 gpointer func_data)
 
139
on_button_press    (GtkWidget      *win,
 
140
                    GdkEventButton *ev,
 
141
                    gpointer        user_data)
91
142
92
143
 
93
 
  AnnotateData *data = (AnnotateData *) func_data;
 
144
  AnnotateData *data = (AnnotateData *) user_data;
 
145
  
 
146
  /* Get the data for this device. */
 
147
  AnnotateDeviceData *devdata = g_hash_table_lookup(data->devdatatable, ev->device);
 
148
  
94
149
  gdouble pressure = 1.0; 
95
 
 
96
 
  initialize_annotation_cairo_context(data);
97
 
 
 
150
  
 
151
  if (!data->is_grabbed)
 
152
    {
 
153
      return FALSE;
 
154
        }
 
155
        
98
156
  if (!ev)
99
157
    {
100
158
      g_printerr ("Device '%s': Invalid event; I ungrab all\n",
101
 
                  ev->device->name);
102
 
 
 
159
                   gdk_device_get_name (ev->device));
103
160
      annotate_release_grab ();
104
 
      return TRUE;
 
161
      return FALSE;
105
162
    }
106
 
 
 
163
        
107
164
  if (data->debug)
108
165
    {
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),
 
168
                  ev->button,
 
169
                  ev->x,
 
170
                  ev->y);
111
171
    }
112
172
 
113
173
#ifdef _WIN32
115
175
    {
116
176
      /* The point is inside the ardesia bar then ungrab. */
117
177
      annotate_release_grab ();
118
 
      return TRUE;
 
178
      return FALSE;
 
179
    }
 
180
    
 
181
  if (data->cur_context->type == ANNOTATE_PEN)
 
182
    {
 
183
      annotate_select_tool (data, ev->device, ev->state);
 
184
      data->old_paint_type = ANNOTATE_PEN; 
 
185
    }
 
186
  else
 
187
    {
 
188
      data->old_paint_type = ANNOTATE_ERASER;
119
189
    }
120
190
#endif
121
191
 
122
 
  annotate_coord_list_free ();
123
 
 
124
 
  annotate_unhide_cursor ();
125
 
 
126
 
  annotate_reset_cairo ();
127
 
 
128
192
  pressure = get_pressure ( (GdkEvent *) ev);
129
193
 
130
194
  if (pressure <= 0)
131
 
    { 
132
 
      return TRUE;
 
195
    {
 
196
      return FALSE;
133
197
    }
134
 
 
135
 
  annotate_draw_point (ev->x, ev->y, pressure);
136
 
 
137
 
  annotate_coord_list_prepend (ev->x, ev->y,
138
 
                               annotate_get_thickness (),
139
 
                               pressure);
 
198
        
 
199
  initialize_annotation_cairo_context(data);
 
200
 
 
201
  annotate_configure_pen_options (data);
 
202
 
 
203
  annotate_coord_dev_list_free (devdata);
 
204
 
 
205
  annotate_unhide_cursor ();
 
206
 
 
207
  annotate_draw_point (devdata, ev->x, ev->y, pressure);
 
208
 
 
209
  annotate_coord_list_prepend (devdata,
 
210
                               ev->x,
 
211
                               ev->y,
 
212
                               annotate_get_thickness (),
 
213
                               pressure);
140
214
 
141
215
  return TRUE;
142
216
}
144
218
 
145
219
/* This shots when the pointer is moving. */
146
220
G_MODULE_EXPORT gboolean
147
 
on_motion_notify (GtkWidget *win,
148
 
                  GdkEventMotion *ev,
149
 
                  gpointer func_data)
 
221
on_motion_notify   (GtkWidget       *win,
 
222
                    GdkEventMotion  *ev,
 
223
                    gpointer         user_data)
150
224
{
151
 
  AnnotateData *data = (AnnotateData *) func_data;
 
225
  AnnotateData *data = (AnnotateData *) user_data;
 
226
  
 
227
  /* Get the data for this device. */
 
228
  AnnotateDeviceData *devdata = g_hash_table_lookup(data->devdatatable, ev->device);
 
229
  
152
230
  GdkModifierType state = (GdkModifierType) ev->state;
153
231
  gdouble selected_width = 0.0;
154
232
  gdouble pressure = 1.0; 
155
233
 
 
234
  if (!data->is_grabbed)
 
235
    {
 
236
      return FALSE;
 
237
        }
 
238
        
156
239
  if (!ev)
157
240
    {
158
241
      g_printerr ("Device '%s': Invalid event; I ungrab all\n",
159
 
                  ev->device->name);
 
242
                  gdk_device_get_name (ev->device));
160
243
      annotate_release_grab ();
161
 
      return TRUE;
 
244
      return FALSE;
162
245
    }
163
246
  
164
247
#ifdef _WIN32
166
249
    {
167
250
 
168
251
      if (data->debug)
169
 
        {
170
 
          g_printerr ("Device '%s': Move on the bar then ungrab\n",
171
 
                      ev->device->name);
172
 
        }
 
252
        {
 
253
          g_printerr ("Device '%s': Move on the bar then ungrab\n",
 
254
          gdk_device_get_name (ev->device));
 
255
        }
173
256
 
174
257
      /* The point is inside the ardesia bar then ungrab. */
175
258
      annotate_release_grab ();
176
 
      return TRUE;
 
259
      return FALSE;
177
260
    }
178
261
#endif
179
262
 
180
263
  annotate_unhide_cursor ();
181
 
 
 
264
  
182
265
  /* Only the first 5 buttons allowed. */
183
266
  if (! (state & 
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)))
185
268
    {
186
269
      /* The button is not pressed. */
187
 
      return TRUE;
 
270
      return FALSE;
188
271
    }
189
272
 
190
 
 
191
273
  initialize_annotation_cairo_context (data);
192
274
 
193
 
  if ( (ev->device->source != GDK_SOURCE_MOUSE) &&
194
 
       (data->cur_context->type != ANNOTATE_ERASER))
 
275
  annotate_configure_pen_options (data);
 
276
  
 
277
  /* Select the new color. */
 
278
  annotate_modify_color (devdata, data, pressure);
 
279
  
 
280
  if (data->cur_context->type != ANNOTATE_ERASER)
195
281
    {
196
282
      pressure = get_pressure ( (GdkEvent *) ev);
197
283
 
198
284
      if (pressure <= 0)
199
 
        {
200
 
          return TRUE;
201
 
        }
 
285
        {
 
286
          return FALSE;
 
287
        }
202
288
 
203
289
      /* If the point is already selected and higher pressure then print else jump it. */
204
 
      if (data->coord_list)
205
 
        {
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)
209
 
            {
210
 
 
211
 
              /* Seems that you are uprising the pen. */
212
 
              if (pressure <= last_point->pressure)
213
 
                {
214
 
                  /* Jump the point you are uprising the hand. */
215
 
                  return TRUE;
216
 
                }
217
 
              else // pressure >= last_point->pressure
218
 
                {
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;
224
 
                  return TRUE;
225
 
                }
226
 
 
227
 
            }
228
 
          annotate_modify_color (data, pressure);
229
 
        }
 
290
      if (devdata->coord_list)
 
291
        {
 
292
          AnnotatePoint *last_point = (AnnotatePoint *) g_slist_nth_data (devdata->coord_list, 0);
 
293
          gdouble tollerance = annotate_get_thickness ();
 
294
          
 
295
          if (get_distance (last_point->x, last_point->y, ev->x, ev->y)<tollerance)
 
296
            {
 
297
              /* Seems that you are uprising the pen. */
 
298
              if (pressure <= last_point->pressure)
 
299
                {
 
300
                  /* Jump the point you are uprising the hand. */
 
301
                  return FALSE;
 
302
                }
 
303
              else // pressure >= last_point->pressure
 
304
                {
 
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;
 
310
                  return TRUE;
 
311
                }
 
312
            }
 
313
          annotate_modify_color (devdata, data, pressure);
 
314
        }
230
315
    }
231
316
 
232
 
  annotate_draw_line (ev->x, ev->y, TRUE);
233
 
 
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);
235
319
 
236
320
  return TRUE;
237
321
}
239
323
 
240
324
/* This shots when the button is released. */
241
325
G_MODULE_EXPORT gboolean
242
 
on_button_release (GtkWidget *win,
243
 
                   GdkEventButton *ev,
244
 
                   gpointer func_data)
 
326
on_button_release  (GtkWidget       *win,
 
327
                    GdkEventButton  *ev,
 
328
                    gpointer         user_data)
245
329
{
246
 
  AnnotateData *data = (AnnotateData *) func_data;
247
 
  guint lenght = g_slist_length (data->coord_list);
 
330
  AnnotateData *data = (AnnotateData *) user_data;
 
331
  
 
332
  /* Get the data for this device. */
 
333
  AnnotateDeviceData *devdata = g_hash_table_lookup(data->devdatatable, ev->device);
 
334
  
 
335
  guint lenght = g_slist_length (devdata->coord_list);
248
336
 
 
337
  if (!data->is_grabbed)
 
338
    {
 
339
      return FALSE;
 
340
    }
 
341
        
249
342
  if (!ev)
250
343
    {
251
344
      g_printerr ("Device '%s': Invalid event; I ungrab all\n",
252
 
                  ev->device->name);
 
345
                   gdk_device_get_name (ev->device));
253
346
      annotate_release_grab ();
254
 
      return TRUE;
 
347
      return FALSE;
255
348
    }
256
349
 
257
350
  if (data->debug)
258
351
    {
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);
261
355
    }
262
356
 
263
357
#ifdef _WIN32
264
 
 
265
358
  if (inside_bar_window (ev->x_root, ev->y_root))
266
359
    /* Point is in the ardesia bar. */
267
360
    {
268
361
      /* The last point was outside the bar then ungrab. */
269
362
      annotate_release_grab ();
270
 
      return TRUE;
271
 
    }
272
 
 
 
363
      return FALSE;
 
364
    }
 
365
  if (data->old_paint_type == ANNOTATE_PEN)
 
366
    {
 
367
      annotate_select_pen ();
 
368
    }
273
369
#endif
274
370
 
275
371
  initialize_annotation_cairo_context(data);
276
372
 
277
373
  if (lenght > 2)
278
 
    { 
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);
 
374
    {
 
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);
281
377
 
282
378
      gdouble distance = get_distance (ev->x, ev->y, first_point->x, first_point->y);
283
 
 
 
379
 
284
380
      /* This is the tolerance to force to close the path in a magnetic way. */
285
 
      gdouble tollerance = data->thickness * 2;
 
381
      gint score = 3;
 
382
      
 
383
      /* If is applied some handled drawing mode then the tool is more tollerant. */
 
384
      if ((data->rectify || data->roundify))
 
385
        {
 
386
          score = 6;
 
387
        }
 
388
        
 
389
      gdouble tollerance = annotate_get_thickness () * score;
 
390
 
286
391
      gdouble pressure = last_point->pressure;   
287
392
 
288
393
      gboolean closed_path = FALSE;
289
 
         
 
394
 
290
395
      /* If the distance between two point lesser than tolerance they are the same point for me. */
291
396
      if (distance > tollerance)
292
397
        {
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);
296
 
        }
 
399
          annotate_draw_line (devdata, ev->x, ev->y, TRUE);
 
400
          annotate_coord_list_prepend (devdata, ev->x, ev->y, annotate_get_thickness (), pressure);
 
401
        }
297
402
      else
298
403
        {
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
301
 
 
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);
304
408
        }
305
409
 
306
410
      if (data->cur_context->type != ANNOTATE_ERASER)
307
 
        { 
308
 
          annotate_shape_recognize (closed_path);
 
411
        {
 
412
          annotate_shape_recognize (devdata, closed_path);
309
413
 
310
414
          /* If is selected an arrow type then I draw the arrow. */
311
415
          if (data->arrow)
312
416
            {
313
 
              /* Print arrow at the end of the path. */
314
 
              annotate_draw_arrow (distance);
315
 
            }
316
 
 
317
 
        }
 
417
              /* Print arrow at the end of the path. */
 
418
              annotate_draw_arrow (devdata, distance);
 
419
            }
 
420
        }
318
421
    }
319
422
 
320
423
  cairo_stroke_preserve (data->annotation_cairo_context);
321
 
  
 
424
 
322
425
  annotate_add_savepoint ();
323
426
 
324
427
  annotate_hide_cursor ();
329
432
 
330
433
/* Device touch. */
331
434
G_MODULE_EXPORT gboolean
332
 
on_proximity_in (GtkWidget *widget,
333
 
                 GdkEventProximity *ev,
334
 
                 gpointer func_data)
 
435
on_proximity_in    (GtkWidget          *widget,
 
436
                    GdkEventProximity  *ev,
 
437
                    gpointer            user_data)
335
438
{
336
 
  /*
337
 
   * @TODO This message does not arrive on windows; why?
338
 
   * is it a driver problem, gtk or what is happening.
339
 
   */
340
 
  AnnotateData *data = (AnnotateData *) func_data;
 
439
  AnnotateData *data = (AnnotateData *) user_data;
341
440
 
 
441
  if (!data->is_grabbed)
 
442
    {
 
443
      return FALSE;
 
444
    }
 
445
        
342
446
  if (data->debug)
343
447
    {
344
 
      g_printerr ("Proximity in device %s\n", ev->device->name);
 
448
      g_printerr ("Proximity in device %s\n", gdk_device_get_name (ev->device));
345
449
    }
346
450
 
347
451
  initialize_annotation_cairo_context(data);
351
455
      GdkModifierType state = (GdkModifierType) NULL;
352
456
 
353
457
      /* Get the modifier state. */
354
 
      gdk_window_get_pointer (gtk_widget_get_window (widget), (gint *) NULL, (gint *) NULL, &state);
 
458
      gdk_window_get_device_position (gtk_widget_get_window (widget),
 
459
                                      ev->device, (gint *) NULL,
 
460
                                      (gint *) NULL,
 
461
                                      &state);
 
462
 
355
463
      annotate_select_tool (data, ev->device, state);
356
464
      data->old_paint_type = ANNOTATE_PEN; 
357
465
    }
366
474
 
367
475
/* Device lease. */
368
476
G_MODULE_EXPORT gboolean
369
 
on_proximity_out (GtkWidget *win,
370
 
                  GdkEventProximity *ev,
371
 
                  gpointer func_data)
 
477
on_proximity_out   (GtkWidget          *win,
 
478
                    GdkEventProximity  *ev,
 
479
                    gpointer            user_data)
372
480
{
373
481
 
374
 
  /*
375
 
   * @TODO This message does not arrive on windows; why?
376
 
   * is it a driver problem, gtk or what is happening.
377
 
   */
378
 
  AnnotateData *data = (AnnotateData *) func_data;
 
482
  AnnotateData *data = (AnnotateData *) user_data;
379
483
 
 
484
  if (!data->is_grabbed)
 
485
    {
 
486
      return FALSE;
 
487
        }
 
488
        
380
489
  if (data->debug)
381
490
    {
382
 
      g_printerr ("Proximity out device %s\n", ev->device->name);
 
491
      g_printerr ("Proximity out device %s\n", gdk_device_get_name (ev->device));
383
492
    }
384
493
 
385
494
  initialize_annotation_cairo_context(data);
389
498
      annotate_select_pen ();
390
499
    }
391
500
 
392
 
  return TRUE;
 
501
  return FALSE;
 
502
}
 
503
 
 
504
 
 
505
/* On device added. */
 
506
void on_device_removed  (GdkDeviceManager  *device_manager,
 
507
                         GdkDevice         *device,
 
508
                         gpointer           user_data)
 
509
{
 
510
  AnnotateData *data = (AnnotateData *) user_data;
 
511
 
 
512
  if(data->debug)
 
513
    {
 
514
      g_printerr("DEBUG: device '%s' removed\n", gdk_device_get_name(device));
 
515
    }
 
516
    
 
517
  remove_input_device (data, device);
 
518
}
 
519
 
 
520
 
 
521
/* On device removed. */
 
522
void on_device_added    (GdkDeviceManager  *device_manager,
 
523
                         GdkDevice         *device,
 
524
                         gpointer           user_data)
 
525
{
 
526
  AnnotateData *data = (AnnotateData *) user_data;
 
527
 
 
528
  if(data->debug)
 
529
    {
 
530
      g_printerr("DEBUG: device '%s' added\n", gdk_device_get_name(device));
 
531
    }
 
532
 
 
533
  add_input_device (data, device);
393
534
}
394
535
 
395
536