]> git.tdb.fi Git - ext/subsurface.git/blob - profile.c
I'm trying to figure something out that prints reasonably..
[ext/subsurface.git] / profile.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdarg.h>
4 #include <string.h>
5 #include <time.h>
6
7 #include "dive.h"
8 #include "display.h"
9 #include "divelist.h"
10
11 int selected_dive = 0;
12
13 /* Plot info with smoothing and one-, two- and three-minute minimums and maximums */
14 struct plot_info {
15         int nr;
16         int maxtime;
17         struct plot_data {
18                 int sec;
19                 int val;
20                 int smoothed;
21                 struct plot_data *min[3];
22                 struct plot_data *max[3];
23                 int avg[3];
24         } entry[];
25 };
26 #define plot_info_size(nr) (sizeof(struct plot_info) + (nr)*sizeof(struct plot_data))
27
28 /* Scale to 0,0 -> maxx,maxy */
29 #define SCALEX(gc,x)  (((x)-gc->leftx)/(gc->rightx-gc->leftx)*gc->maxx)
30 #define SCALEY(gc,y)  (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy)
31 #define SCALE(gc,x,y) SCALEX(gc,x),SCALEY(gc,y)
32
33 static void move_to(struct graphics_context *gc, double x, double y)
34 {
35         cairo_move_to(gc->cr, SCALE(gc, x, y));
36 }
37
38 static void line_to(struct graphics_context *gc, double x, double y)
39 {
40         cairo_line_to(gc->cr, SCALE(gc, x, y));
41 }
42
43 static void set_source_rgba(struct graphics_context *gc, double r, double g, double b, double a)
44 {
45         if (gc->printer) {
46                 /* Black is white and white is black */
47                 double sum = r+g+b;
48                 if (sum > 2)
49                         r = g = b = 0;
50                 else if (sum < 1)
51                         r = g = b = 1;
52         }
53         cairo_set_source_rgba(gc->cr, r, g, b, a);
54 }
55
56 static void set_source_rgb(struct graphics_context *gc, double r, double g, double b)
57 {
58         set_source_rgba(gc, r, g, b, 1);
59 }
60
61 #define ROUND_UP(x,y) ((((x)+(y)-1)/(y))*(y))
62
63 /*
64  * When showing dive profiles, we scale things to the
65  * current dive. However, we don't scale past less than
66  * 30 minutes or 90 ft, just so that small dives show
67  * up as such.
68  */
69 static int round_seconds_up(int seconds)
70 {
71         return MAX(30*60, ROUND_UP(seconds, 60*10));
72 }
73
74 static int round_depth_up(depth_t depth)
75 {
76         unsigned mm = depth.mm;
77         /* Minimum 30m */
78         return MAX(30000, ROUND_UP(mm+3000, 10000));
79 }
80
81 typedef struct {
82         int size;
83         double r,g,b;
84         enum {CENTER,LEFT} halign;
85         enum {MIDDLE,TOP,BOTTOM} valign;
86 } text_render_options_t;
87
88 static void plot_text(struct graphics_context *gc, const text_render_options_t *tro,
89                       double x, double y, const char *fmt, ...)
90 {
91         cairo_t *cr = gc->cr;
92         cairo_text_extents_t extents;
93         double dx, dy;
94         char buffer[80];
95         va_list args;
96
97         va_start(args, fmt);
98         vsnprintf(buffer, sizeof(buffer), fmt, args);
99         va_end(args);
100
101         cairo_set_font_size(cr, tro->size);
102         cairo_text_extents(cr, buffer, &extents);
103         dx = 0;
104         switch (tro->halign) {
105         case CENTER:
106                 dx = -(extents.width/2 + extents.x_bearing);
107                 break;
108         case LEFT:
109                 dx = 0;
110                 break;
111         }
112         switch (tro->valign) {
113         case TOP:
114                 dy = extents.height * 1.2;
115                 break;
116         case BOTTOM:
117                 dy = -extents.height * 0.8;
118                 break;
119         case MIDDLE:
120                 dy = 0;
121                 break;
122         }
123
124         move_to(gc, x, y);
125         cairo_rel_move_to(cr, dx, dy);
126
127         cairo_text_path(cr, buffer);
128         set_source_rgb(gc, 0, 0, 0);
129         cairo_stroke(cr);
130
131         move_to(gc, x, y);
132         cairo_rel_move_to(cr, dx, dy);
133
134         set_source_rgb(gc, tro->r, tro->g, tro->b);
135         cairo_show_text(cr, buffer);
136 }
137
138 static void render_depth_sample(struct graphics_context *gc, struct plot_data *entry, const text_render_options_t *tro)
139 {
140         int sec = entry->sec;
141         depth_t depth = { entry->val };
142         const char *fmt;
143         double d;
144
145         switch (output_units.length) {
146         case METERS:
147                 d = depth.mm / 1000.0;
148                 fmt = "%.1f";
149                 break;
150         case FEET:
151                 d = to_feet(depth);
152                 fmt = "%.0f";
153                 break;
154         }
155         plot_text(gc, tro, sec, depth.mm, fmt, d);
156 }
157
158 static void plot_text_samples(struct graphics_context *gc, struct plot_info *pi)
159 {
160         static const text_render_options_t deep = {14, 1.0, 0.2, 0.2, CENTER, TOP};
161         static const text_render_options_t shallow = {14, 1.0, 0.2, 0.2, CENTER, BOTTOM};
162         int i;
163
164         for (i = 0; i < pi->nr; i++) {
165                 struct plot_data *entry = pi->entry + i;
166
167                 if (entry->val < 2000)
168                         continue;
169
170                 if (entry == entry->max[2])
171                         render_depth_sample(gc, entry, &deep);
172
173                 if (entry == entry->min[2])
174                         render_depth_sample(gc, entry, &shallow);
175         }
176 }
177
178 static void plot_depth_text(struct dive *dive, struct graphics_context *gc, struct plot_info *pi)
179 {
180         int maxtime, maxdepth;
181
182         /* Get plot scaling limits */
183         maxtime = round_seconds_up(dive->duration.seconds);
184         maxdepth = round_depth_up(dive->maxdepth);
185
186         gc->leftx = 0; gc->rightx = maxtime;
187         gc->topy = 0; gc->bottomy = maxdepth;
188
189         plot_text_samples(gc, pi);
190 }
191
192 static void plot_smoothed_profile(struct graphics_context *gc, struct plot_info *pi)
193 {
194         int i;
195         struct plot_data *entry = pi->entry;
196
197         cairo_set_source_rgba(gc->cr, 1, 0.2, 0.2, 0.20);
198         move_to(gc, entry->sec, entry->smoothed);
199         for (i = 1; i < pi->nr; i++) {
200                 entry++;
201                 line_to(gc, entry->sec, entry->smoothed);
202         }
203         cairo_stroke(gc->cr);
204 }
205
206 static void plot_minmax_profile_minute(struct graphics_context *gc, struct plot_info *pi,
207                                 int index, double a)
208 {
209         int i;
210         struct plot_data *entry = pi->entry;
211
212         cairo_set_source_rgba(gc->cr, 1, 0.2, 1, a);
213         move_to(gc, entry->sec, entry->min[index]->val);
214         for (i = 1; i < pi->nr; i++) {
215                 entry++;
216                 line_to(gc, entry->sec, entry->min[index]->val);
217         }
218         for (i = 1; i < pi->nr; i++) {
219                 line_to(gc, entry->sec, entry->max[index]->val);
220                 entry--;
221         }
222         cairo_close_path(gc->cr);
223         cairo_fill(gc->cr);
224 }
225
226 static void plot_minmax_profile(struct graphics_context *gc, struct plot_info *pi)
227 {
228         if (gc->printer)
229                 return;
230         plot_minmax_profile_minute(gc, pi, 2, 0.1);
231         plot_minmax_profile_minute(gc, pi, 1, 0.1);
232         plot_minmax_profile_minute(gc, pi, 0, 0.1);
233 }
234
235 static void plot_depth_profile(struct dive *dive, struct graphics_context *gc, struct plot_info *pi)
236 {
237         int i;
238         cairo_t *cr = gc->cr;
239         int begins, sec, depth;
240         struct plot_data *entry;
241         int maxtime, maxdepth, marker;
242
243         /* Get plot scaling limits */
244         maxtime = round_seconds_up(dive->duration.seconds);
245         maxdepth = round_depth_up(dive->maxdepth);
246
247         /* Time markers: every 5 min */
248         gc->leftx = 0; gc->rightx = maxtime;
249         gc->topy = 0; gc->bottomy = 1.0;
250         for (i = 5*60; i < maxtime; i += 5*60) {
251                 move_to(gc, i, 0);
252                 line_to(gc, i, 1);
253         }
254
255         /* Depth markers: every 30 ft or 10 m*/
256         gc->leftx = 0; gc->rightx = 1.0;
257         gc->topy = 0; gc->bottomy = maxdepth;
258         switch (output_units.length) {
259         case METERS: marker = 10000; break;
260         case FEET: marker = 9144; break;        /* 30 ft */
261         }
262
263         set_source_rgba(gc, 1, 1, 1, 0.5);
264         for (i = marker; i < maxdepth; i += marker) {
265                 move_to(gc, 0, i);
266                 line_to(gc, 1, i);
267         }
268         cairo_stroke(cr);
269
270         /* Show mean depth */
271         set_source_rgba(gc, 1, 0.2, 0.2, 0.40);
272         move_to(gc, 0, dive->meandepth.mm);
273         line_to(gc, 1, dive->meandepth.mm);
274         cairo_stroke(cr);
275
276         gc->leftx = 0; gc->rightx = maxtime;
277
278         plot_smoothed_profile(gc, pi);
279         plot_minmax_profile(gc, pi);
280
281         entry = pi->entry;
282         set_source_rgba(gc, 1, 0.2, 0.2, 0.80);
283         begins = entry->sec;
284         move_to(gc, entry->sec, entry->val);
285         for (i = 1; i < pi->nr; i++) {
286                 entry++;
287                 sec = entry->sec;
288                 if (sec <= maxtime) {
289                         depth = entry->val;
290                         line_to(gc, sec, depth);
291                 }
292         }
293         gc->topy = 0; gc->bottomy = 1.0;
294         line_to(gc, MIN(sec,maxtime), 0);
295         line_to(gc, begins, 0);
296         cairo_close_path(cr);
297         set_source_rgba(gc, 1, 0.2, 0.2, 0.20);
298         cairo_fill_preserve(cr);
299         set_source_rgba(gc, 1, 0.2, 0.2, 0.80);
300         cairo_stroke(cr);
301 }
302
303 static int setup_temperature_limits(struct dive *dive, struct graphics_context *gc)
304 {
305         int i;
306         int maxtime, mintemp, maxtemp;
307
308         /* Get plot scaling limits */
309         maxtime = round_seconds_up(dive->duration.seconds);
310         mintemp = INT_MAX;
311         maxtemp = 0;
312         for (i = 0; i < dive->samples; i++) {
313                 struct sample *sample = dive->sample+i;
314                 int mkelvin = sample->temperature.mkelvin;
315                 if (!mkelvin)
316                         continue;
317                 if (mkelvin > maxtemp)
318                         maxtemp = mkelvin;
319                 if (mkelvin < mintemp)
320                         mintemp = mkelvin;
321         }
322
323         gc->leftx = 0; gc->rightx = maxtime;
324         /* Show temperatures in roughly the lower third */
325         gc->topy = maxtemp + (maxtemp - mintemp)*2;
326         gc->bottomy = mintemp - (maxtemp - mintemp)/2;
327
328         return maxtemp > mintemp;
329 }
330
331 static void plot_temperature_text(struct dive *dive, struct graphics_context *gc)
332 {
333         int i;
334         static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP};
335
336         int last = 0;
337
338         if (!setup_temperature_limits(dive, gc))
339                 return;
340
341         for (i = 0; i < dive->samples; i++) {
342                 const char *unit;
343                 struct sample *sample = dive->sample+i;
344                 int mkelvin = sample->temperature.mkelvin;
345                 int sec, deg;
346                 if (!mkelvin)
347                         continue;
348                 sec = sample->time.seconds;
349                 if (sec < last)
350                         continue;
351                 last = sec + 300;
352                 if (output_units.temperature == FAHRENHEIT) {
353                         deg = to_F(sample->temperature);
354                         unit = "F";
355                 } else {
356                         deg = to_C(sample->temperature);
357                         unit = "C";
358                 }
359                 plot_text(gc, &tro, sec, mkelvin, "%d %s", deg, unit);
360         }
361 }
362
363 static void plot_temperature_profile(struct dive *dive, struct graphics_context *gc)
364 {
365         int i;
366         cairo_t *cr = gc->cr;
367         int last = 0;
368
369         if (!setup_temperature_limits(dive, gc))
370                 return;
371
372         set_source_rgba(gc, 0.2, 0.2, 1.0, 0.8);
373         for (i = 0; i < dive->samples; i++) {
374                 struct sample *sample = dive->sample+i;
375                 int mkelvin = sample->temperature.mkelvin;
376                 if (!mkelvin) {
377                         if (!last)
378                                 continue;
379                         mkelvin = last;
380                 }
381                 if (last)
382                         line_to(gc, sample->time.seconds, mkelvin);
383                 else
384                         move_to(gc, sample->time.seconds, mkelvin);
385                 last = mkelvin;
386         }
387         cairo_stroke(cr);
388 }
389
390 /* gets both the actual start and end pressure as well as the scaling factors */
391 static int get_cylinder_pressure_range(struct dive *dive, struct graphics_context *gc,
392         pressure_t *startp, pressure_t *endp)
393 {
394         int i;
395         int min, max;
396
397         gc->leftx = 0; gc->rightx = round_seconds_up(dive->duration.seconds);
398
399         max = 0;
400         min = 5000000;
401         if (startp)
402                 startp->mbar = endp->mbar = 0;
403
404         for (i = 0; i < dive->samples; i++) {
405                 int mbar;
406                 struct sample *sample = dive->sample + i;
407
408                 /* FIXME! We only track cylinder 0 right now */
409                 if (sample->cylinderindex)
410                         continue;
411                 mbar = sample->cylinderpressure.mbar;
412                 if (!mbar)
413                         continue;
414                 if (mbar < min)
415                         min = mbar;
416                 if (mbar > max)
417                         max = mbar;
418         }
419         if (startp)
420                 startp->mbar = max;
421         if (endp)
422                 endp->mbar = min;
423         if (!max)
424                 return 0;
425         gc->topy = 0; gc->bottomy = max * 1.5;
426         return 1;
427 }
428
429 static void plot_cylinder_pressure(struct dive *dive, struct graphics_context *gc)
430 {
431         int i, sec = -1;
432
433         if (!get_cylinder_pressure_range(dive, gc, NULL, NULL))
434                 return;
435
436         cairo_set_source_rgba(gc->cr, 0.2, 1.0, 0.2, 0.80);
437
438         move_to(gc, 0, dive->cylinder[0].start.mbar);
439         for (i = 1; i < dive->samples; i++) {
440                 int mbar;
441                 struct sample *sample = dive->sample + i;
442
443                 mbar = sample->cylinderpressure.mbar;
444                 if (!mbar)
445                         continue;
446                 sec = sample->time.seconds;
447                 if (sec <= dive->duration.seconds)
448                         line_to(gc, sec, mbar);
449         }
450         /*
451          * We may have "surface time" events, in which case we don't go
452          * back to dive duration
453          */
454         if (sec < dive->duration.seconds)
455                 line_to(gc, dive->duration.seconds, dive->cylinder[0].end.mbar);
456         cairo_stroke(gc->cr);
457 }
458
459 /*
460  * Return air usage (in liters).
461  */
462 static double calculate_airuse(struct dive *dive)
463 {
464         double airuse = 0;
465         int i;
466
467         for (i = 0; i < MAX_CYLINDERS; i++) {
468                 cylinder_t *cyl = dive->cylinder + i;
469                 int size = cyl->type.size.mliter;
470                 double kilo_atm;
471
472                 if (!size)
473                         continue;
474
475                 kilo_atm = (cyl->start.mbar - cyl->end.mbar) / 1013250.0;
476
477                 /* Liters of air at 1 atm == milliliters at 1k atm*/
478                 airuse += kilo_atm * size;
479         }
480         return airuse;
481 }
482
483 static void plot_info(struct dive *dive, struct graphics_context *gc)
484 {
485         text_render_options_t tro = {10, 0.2, 1.0, 0.2, LEFT, TOP};
486         const double liters_per_cuft = 28.317;
487         const char *unit, *desc;
488         double airuse;
489
490         airuse = calculate_airuse(dive);
491         if (!airuse)
492                 return;
493
494         /* I really need to start addign some unit setting thing */
495         switch (output_units.volume) {
496         case LITER:
497                 unit = "l";
498                 break;
499         case CUFT:
500                 unit = "cuft";
501                 airuse /= liters_per_cuft;
502                 break;
503         }
504         plot_text(gc, &tro, 0.8, 0.8, "vol: %4.2f %s", airuse, unit);
505         if (dive->duration.seconds) {
506                 double pressure = 1 + (dive->meandepth.mm / 10000.0);
507                 double sac = airuse / pressure * 60 / dive->duration.seconds;
508                 plot_text(gc, &tro, 0.8, 0.85, "SAC: %4.2f %s/min", sac, unit);
509         }
510         desc = dive->cylinder[0].type.description;
511         if (desc || dive->cylinder[0].gasmix.o2.permille) {
512                 int o2 = dive->cylinder[0].gasmix.o2.permille / 10;
513                 if (!desc)
514                         desc = "";
515                 if (!o2)
516                         o2 = 21;
517                 plot_text(gc, &tro, 0.8, 0.9, "%s (%d%%)", desc, o2);
518         }
519 }
520
521 static void plot_cylinder_pressure_text(struct dive *dive, struct graphics_context *gc)
522 {
523         pressure_t startp, endp;
524
525         if (get_cylinder_pressure_range(dive, gc, &startp, &endp)) {
526                 int start, end;
527                 const char *unit = "bar";
528
529                 switch (output_units.pressure) {
530                 case PASCAL:
531                         start = startp.mbar * 100;
532                         end = startp.mbar * 100;
533                         unit = "pascal";
534                         break;
535                 case BAR:
536                         start = (startp.mbar + 500) / 1000;
537                         end = (endp.mbar + 500) / 1000;
538                         unit = "bar";
539                         break;
540                 case PSI:
541                         start = to_PSI(startp);
542                         end = to_PSI(endp);
543                         unit = "psi";
544                         break;
545                 }
546
547                 text_render_options_t tro = {10, 0.2, 1.0, 0.2, LEFT, TOP};
548                 plot_text(gc, &tro, 0, startp.mbar, "%d %s", start, unit);
549                 plot_text(gc, &tro, dive->duration.seconds, endp.mbar,
550                           "%d %s", end, unit);
551         }
552 }
553
554 static void analyze_plot_info_minmax_minute(struct plot_data *entry, struct plot_data *first, struct plot_data *last, int index)
555 {
556         struct plot_data *p = entry;
557         int time = entry->sec;
558         int seconds = 90*(index+1);
559         struct plot_data *min, *max;
560         int avg, nr;
561
562         /* Go back 'seconds' in time */
563         while (p > first) {
564                 if (p[-1].sec < time - seconds)
565                         break;
566                 p--;
567         }
568
569         /* Then go forward until we hit an entry past the time */
570         min = max = p;
571         avg = p->val;
572         nr = 1;
573         while (++p < last) {
574                 int val = p->val;
575                 if (p->sec > time + seconds)
576                         break;
577                 avg += val;
578                 nr ++;
579                 if (val < min->val)
580                         min = p;
581                 if (val > max->val)
582                         max = p;
583         }
584         entry->min[index] = min;
585         entry->max[index] = max;
586         entry->avg[index] = (avg + nr/2) / nr;
587 }
588
589 static void analyze_plot_info_minmax(struct plot_data *entry, struct plot_data *first, struct plot_data *last)
590 {
591         analyze_plot_info_minmax_minute(entry, first, last, 0);
592         analyze_plot_info_minmax_minute(entry, first, last, 1);
593         analyze_plot_info_minmax_minute(entry, first, last, 2);
594 }
595
596 static struct plot_info *analyze_plot_info(struct plot_info *pi)
597 {
598         int i;
599         int nr = pi->nr;
600
601         /* Smoothing function: 5-point triangular smooth */
602         for (i = 2; i < nr-2; i++) {
603                 struct plot_data *entry = pi->entry+i;
604                 int val;
605
606                 val = entry[-2].val + 2*entry[-1].val + 3*entry[0].val + 2*entry[1].val + entry[2].val;
607                 entry->smoothed = (val+4) / 9;
608         }
609
610         /* One-, two- and three-minute minmax data */
611         for (i = 0; i < nr; i++) {
612                 struct plot_data *entry = pi->entry +i;
613                 analyze_plot_info_minmax(entry, pi->entry, pi->entry+nr);
614         }
615         
616         return pi;
617 }
618
619 /*
620  * Create a plot-info with smoothing and ranged min/max
621  *
622  * This also makes sure that we have extra empty events on both
623  * sides, so that you can do end-points without having to worry
624  * about it.
625  */
626 static struct plot_info *depth_plot_info(struct dive *dive)
627 {
628         int i, nr = dive->samples + 4, sec;
629         size_t alloc_size = plot_info_size(nr);
630         struct plot_info *pi;
631
632         pi = malloc(alloc_size);
633         if (!pi)
634                 return pi;
635         memset(pi, 0, alloc_size);
636         pi->nr = nr;
637         sec = 0;
638         for (i = 0; i < dive->samples; i++) {
639                 struct sample *sample = dive->sample+i;
640                 struct plot_data *entry = pi->entry + i + 2;
641
642                 sec = entry->sec = sample->time.seconds;
643                 entry->val = sample->depth.mm;
644         }
645         /* Fill in the last two entries with empty values but valid times */
646         i = dive->samples + 2;
647         pi->entry[i].sec = sec + 20;
648         pi->entry[i+1].sec = sec + 40;
649
650         return analyze_plot_info(pi);
651 }
652
653 void plot(struct graphics_context *gc, int w, int h, struct dive *dive)
654 {
655         double topx, topy;
656         struct plot_info *pi = depth_plot_info(dive);
657
658         topx = w / 20.0;
659         topy = h / 20.0;
660         cairo_translate(gc->cr, topx, topy);
661         cairo_set_line_width(gc->cr, 2);
662         cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND);
663         cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND);
664
665         /*
666          * We can use "cairo_translate()" because that doesn't
667          * scale line width etc. But the actual scaling we need
668          * do set up ourselves..
669          *
670          * Snif. What a pity.
671          */
672         gc->maxx = (w - 2*topx);
673         gc->maxy = (h - 2*topy);
674
675         /* Temperature profile */
676         plot_temperature_profile(dive, gc);
677
678         /* Cylinder pressure plot */
679         plot_cylinder_pressure(dive, gc);
680
681         /* Depth profile */
682         plot_depth_profile(dive, gc, pi);
683
684         /* Text on top of all graphs.. */
685         plot_temperature_text(dive, gc);
686         plot_depth_text(dive, gc, pi);
687         plot_cylinder_pressure_text(dive, gc);
688
689         /* And info box in the lower right corner.. */
690         gc->leftx = 0; gc->rightx = 1.0;
691         gc->topy = 0; gc->bottomy = 1.0;
692         plot_info(dive, gc);
693
694         /* Bounding box last */
695         set_source_rgb(gc, 1, 1, 1);
696         move_to(gc, 0, 0);
697         line_to(gc, 0, 1);
698         line_to(gc, 1, 1);
699         line_to(gc, 1, 0);
700         cairo_close_path(gc->cr);
701         cairo_stroke(gc->cr);
702
703 }
704
705 static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
706 {
707         struct dive *dive = current_dive;
708         struct graphics_context gc = { .printer = 0 };
709         int w,h;
710
711         w = widget->allocation.width;
712         h = widget->allocation.height;
713
714         gc.cr = gdk_cairo_create(widget->window);
715         set_source_rgb(&gc, 0, 0, 0);
716         cairo_paint(gc.cr);
717
718         if (dive)
719                 plot(&gc, w, h, dive);
720
721         cairo_destroy(gc.cr);
722
723         return FALSE;
724 }
725
726 GtkWidget *dive_profile_widget(void)
727 {
728         GtkWidget *da;
729
730         da = gtk_drawing_area_new();
731         gtk_widget_set_size_request(da, 350, 250);
732         g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
733
734         return da;
735 }