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