]> git.tdb.fi Git - ext/subsurface.git/blob - profile.c
Don't draw temperature plot past the end of the dive
[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                 if (sample->time.seconds > dive->duration.seconds)
376                         break; /* let's not plot surface temp events */
377                 int mkelvin = sample->temperature.mkelvin;
378                 if (!mkelvin) {
379                         if (!last)
380                                 continue;
381                         mkelvin = last;
382                 }
383                 if (last)
384                         line_to(gc, sample->time.seconds, mkelvin);
385                 else
386                         move_to(gc, sample->time.seconds, mkelvin);
387                 last = mkelvin;
388         }
389         cairo_stroke(cr);
390 }
391
392 /* gets both the actual start and end pressure as well as the scaling factors */
393 static int get_cylinder_pressure_range(struct dive *dive, struct graphics_context *gc,
394         pressure_t *startp, pressure_t *endp)
395 {
396         int i;
397         int min, max;
398
399         gc->leftx = 0; gc->rightx = round_seconds_up(dive->duration.seconds);
400
401         max = 0;
402         min = 5000000;
403         if (startp)
404                 startp->mbar = endp->mbar = 0;
405
406         for (i = 0; i < dive->samples; i++) {
407                 int mbar;
408                 struct sample *sample = dive->sample + i;
409
410                 /* FIXME! We only track cylinder 0 right now */
411                 if (sample->cylinderindex)
412                         continue;
413                 mbar = sample->cylinderpressure.mbar;
414                 if (!mbar)
415                         continue;
416                 if (mbar < min)
417                         min = mbar;
418                 if (mbar > max)
419                         max = mbar;
420         }
421         if (startp)
422                 startp->mbar = max;
423         if (endp)
424                 endp->mbar = min;
425         if (!max)
426                 return 0;
427         gc->topy = 0; gc->bottomy = max * 1.5;
428         return 1;
429 }
430
431 static void plot_cylinder_pressure(struct dive *dive, struct graphics_context *gc)
432 {
433         int i, sec = -1;
434
435         if (!get_cylinder_pressure_range(dive, gc, NULL, NULL))
436                 return;
437
438         cairo_set_source_rgba(gc->cr, 0.2, 1.0, 0.2, 0.80);
439
440         move_to(gc, 0, dive->cylinder[0].start.mbar);
441         for (i = 1; i < dive->samples; i++) {
442                 int mbar;
443                 struct sample *sample = dive->sample + i;
444
445                 mbar = sample->cylinderpressure.mbar;
446                 if (!mbar)
447                         continue;
448                 sec = sample->time.seconds;
449                 if (sec <= dive->duration.seconds)
450                         line_to(gc, sec, mbar);
451         }
452         /*
453          * We may have "surface time" events, in which case we don't go
454          * back to dive duration
455          */
456         if (sec < dive->duration.seconds)
457                 line_to(gc, dive->duration.seconds, dive->cylinder[0].end.mbar);
458         cairo_stroke(gc->cr);
459 }
460
461 /*
462  * Return air usage (in liters).
463  */
464 static double calculate_airuse(struct dive *dive)
465 {
466         double airuse = 0;
467         int i;
468
469         for (i = 0; i < MAX_CYLINDERS; i++) {
470                 cylinder_t *cyl = dive->cylinder + i;
471                 int size = cyl->type.size.mliter;
472                 double kilo_atm;
473
474                 if (!size)
475                         continue;
476
477                 kilo_atm = (cyl->start.mbar - cyl->end.mbar) / 1013250.0;
478
479                 /* Liters of air at 1 atm == milliliters at 1k atm*/
480                 airuse += kilo_atm * size;
481         }
482         return airuse;
483 }
484
485 static void plot_info(struct dive *dive, struct graphics_context *gc)
486 {
487         text_render_options_t tro = {10, 0.2, 1.0, 0.2, LEFT, TOP};
488         const double liters_per_cuft = 28.317;
489         const char *unit, *desc;
490         double airuse;
491
492         airuse = calculate_airuse(dive);
493         if (!airuse)
494                 return;
495
496         /* I really need to start addign some unit setting thing */
497         switch (output_units.volume) {
498         case LITER:
499                 unit = "l";
500                 break;
501         case CUFT:
502                 unit = "cuft";
503                 airuse /= liters_per_cuft;
504                 break;
505         }
506         plot_text(gc, &tro, 0.8, 0.8, "vol: %4.2f %s", airuse, unit);
507         if (dive->duration.seconds) {
508                 double pressure = 1 + (dive->meandepth.mm / 10000.0);
509                 double sac = airuse / pressure * 60 / dive->duration.seconds;
510                 plot_text(gc, &tro, 0.8, 0.85, "SAC: %4.2f %s/min", sac, unit);
511         }
512         desc = dive->cylinder[0].type.description;
513         if (desc || dive->cylinder[0].gasmix.o2.permille) {
514                 int o2 = dive->cylinder[0].gasmix.o2.permille / 10;
515                 if (!desc)
516                         desc = "";
517                 if (!o2)
518                         o2 = 21;
519                 plot_text(gc, &tro, 0.8, 0.9, "%s (%d%%)", desc, o2);
520         }
521 }
522
523 static void plot_cylinder_pressure_text(struct dive *dive, struct graphics_context *gc)
524 {
525         pressure_t startp, endp;
526
527         if (get_cylinder_pressure_range(dive, gc, &startp, &endp)) {
528                 int start, end;
529                 const char *unit = "bar";
530
531                 switch (output_units.pressure) {
532                 case PASCAL:
533                         start = startp.mbar * 100;
534                         end = startp.mbar * 100;
535                         unit = "pascal";
536                         break;
537                 case BAR:
538                         start = (startp.mbar + 500) / 1000;
539                         end = (endp.mbar + 500) / 1000;
540                         unit = "bar";
541                         break;
542                 case PSI:
543                         start = to_PSI(startp);
544                         end = to_PSI(endp);
545                         unit = "psi";
546                         break;
547                 }
548
549                 text_render_options_t tro = {10, 0.2, 1.0, 0.2, LEFT, TOP};
550                 plot_text(gc, &tro, 0, startp.mbar, "%d %s", start, unit);
551                 plot_text(gc, &tro, dive->duration.seconds, endp.mbar,
552                           "%d %s", end, unit);
553         }
554 }
555
556 static void analyze_plot_info_minmax_minute(struct plot_data *entry, struct plot_data *first, struct plot_data *last, int index)
557 {
558         struct plot_data *p = entry;
559         int time = entry->sec;
560         int seconds = 90*(index+1);
561         struct plot_data *min, *max;
562         int avg, nr;
563
564         /* Go back 'seconds' in time */
565         while (p > first) {
566                 if (p[-1].sec < time - seconds)
567                         break;
568                 p--;
569         }
570
571         /* Then go forward until we hit an entry past the time */
572         min = max = p;
573         avg = p->val;
574         nr = 1;
575         while (++p < last) {
576                 int val = p->val;
577                 if (p->sec > time + seconds)
578                         break;
579                 avg += val;
580                 nr ++;
581                 if (val < min->val)
582                         min = p;
583                 if (val > max->val)
584                         max = p;
585         }
586         entry->min[index] = min;
587         entry->max[index] = max;
588         entry->avg[index] = (avg + nr/2) / nr;
589 }
590
591 static void analyze_plot_info_minmax(struct plot_data *entry, struct plot_data *first, struct plot_data *last)
592 {
593         analyze_plot_info_minmax_minute(entry, first, last, 0);
594         analyze_plot_info_minmax_minute(entry, first, last, 1);
595         analyze_plot_info_minmax_minute(entry, first, last, 2);
596 }
597
598 static struct plot_info *analyze_plot_info(struct plot_info *pi)
599 {
600         int i;
601         int nr = pi->nr;
602
603         /* Smoothing function: 5-point triangular smooth */
604         for (i = 2; i < nr-2; i++) {
605                 struct plot_data *entry = pi->entry+i;
606                 int val;
607
608                 val = entry[-2].val + 2*entry[-1].val + 3*entry[0].val + 2*entry[1].val + entry[2].val;
609                 entry->smoothed = (val+4) / 9;
610         }
611
612         /* One-, two- and three-minute minmax data */
613         for (i = 0; i < nr; i++) {
614                 struct plot_data *entry = pi->entry +i;
615                 analyze_plot_info_minmax(entry, pi->entry, pi->entry+nr);
616         }
617         
618         return pi;
619 }
620
621 /*
622  * Create a plot-info with smoothing and ranged min/max
623  *
624  * This also makes sure that we have extra empty events on both
625  * sides, so that you can do end-points without having to worry
626  * about it.
627  */
628 static struct plot_info *depth_plot_info(struct dive *dive)
629 {
630         int i, nr = dive->samples + 4, sec;
631         size_t alloc_size = plot_info_size(nr);
632         struct plot_info *pi;
633
634         pi = malloc(alloc_size);
635         if (!pi)
636                 return pi;
637         memset(pi, 0, alloc_size);
638         pi->nr = nr;
639         sec = 0;
640         for (i = 0; i < dive->samples; i++) {
641                 struct sample *sample = dive->sample+i;
642                 struct plot_data *entry = pi->entry + i + 2;
643
644                 sec = entry->sec = sample->time.seconds;
645                 entry->val = sample->depth.mm;
646         }
647         /* Fill in the last two entries with empty values but valid times */
648         i = dive->samples + 2;
649         pi->entry[i].sec = sec + 20;
650         pi->entry[i+1].sec = sec + 40;
651
652         return analyze_plot_info(pi);
653 }
654
655 void plot(struct graphics_context *gc, int w, int h, struct dive *dive)
656 {
657         double topx, topy;
658         struct plot_info *pi = depth_plot_info(dive);
659
660         topx = w / 20.0;
661         topy = h / 20.0;
662         cairo_translate(gc->cr, topx, topy);
663         cairo_set_line_width(gc->cr, 2);
664         cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND);
665         cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND);
666
667         /*
668          * We can use "cairo_translate()" because that doesn't
669          * scale line width etc. But the actual scaling we need
670          * do set up ourselves..
671          *
672          * Snif. What a pity.
673          */
674         gc->maxx = (w - 2*topx);
675         gc->maxy = (h - 2*topy);
676
677         /* Temperature profile */
678         plot_temperature_profile(dive, gc);
679
680         /* Cylinder pressure plot */
681         plot_cylinder_pressure(dive, gc);
682
683         /* Depth profile */
684         plot_depth_profile(dive, gc, pi);
685
686         /* Text on top of all graphs.. */
687         plot_temperature_text(dive, gc);
688         plot_depth_text(dive, gc, pi);
689         plot_cylinder_pressure_text(dive, gc);
690
691         /* And info box in the lower right corner.. */
692         gc->leftx = 0; gc->rightx = 1.0;
693         gc->topy = 0; gc->bottomy = 1.0;
694         plot_info(dive, gc);
695
696         /* Bounding box last */
697         set_source_rgb(gc, 1, 1, 1);
698         move_to(gc, 0, 0);
699         line_to(gc, 0, 1);
700         line_to(gc, 1, 1);
701         line_to(gc, 1, 0);
702         cairo_close_path(gc->cr);
703         cairo_stroke(gc->cr);
704
705 }
706
707 static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
708 {
709         struct dive *dive = current_dive;
710         struct graphics_context gc = { .printer = 0 };
711         int w,h;
712
713         w = widget->allocation.width;
714         h = widget->allocation.height;
715
716         gc.cr = gdk_cairo_create(widget->window);
717         set_source_rgb(&gc, 0, 0, 0);
718         cairo_paint(gc.cr);
719
720         if (dive)
721                 plot(&gc, w, h, dive);
722
723         cairo_destroy(gc.cr);
724
725         return FALSE;
726 }
727
728 GtkWidget *dive_profile_widget(void)
729 {
730         GtkWidget *da;
731
732         da = gtk_drawing_area_new();
733         gtk_widget_set_size_request(da, 350, 250);
734         g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
735
736         return da;
737 }