]> git.tdb.fi Git - ext/subsurface.git/blobdiff - profile.c
Add font size to the text_render_options structure
[ext/subsurface.git] / profile.c
index 706f60ba0d6fea984ca9c7bd73109ef6ed96aa7e..c2433930fe7c4c49aa1ced4f4f1a37fc65a2f2e4 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -57,8 +57,10 @@ static int round_depth_up(depth_t depth)
 }
 
 typedef struct {
+       int size;
        double r,g,b;
-       enum {CENTER,LEFT} allign;
+       enum {CENTER,LEFT} halign;
+       enum {MIDDLE,TOP,BOTTOM} valign;
 } text_render_options_t;
 
 static void plot_text(struct graphics_context *gc, text_render_options_t *tro,
@@ -74,11 +76,28 @@ static void plot_text(struct graphics_context *gc, text_render_options_t *tro,
        vsnprintf(buffer, sizeof(buffer), fmt, args);
        va_end(args);
 
+       cairo_set_font_size(cr, tro->size);
        cairo_text_extents(cr, buffer, &extents);
        dx = 0;
-       if (tro->allign == CENTER)
+       switch (tro->halign) {
+       case CENTER:
                dx = -(extents.width/2 + extents.x_bearing);
-       dy = extents.height * 1.2;
+               break;
+       case LEFT:
+               dx = 0;
+               break;
+       }
+       switch (tro->valign) {
+       case TOP:
+               dy = extents.height * 1.2;
+               break;
+       case BOTTOM:
+               dy = -extents.height * 0.8;
+               break;
+       case MIDDLE:
+               dy = 0;
+               break;
+       }
 
        move_to(gc, x, y);
        cairo_rel_move_to(cr, dx, dy);
@@ -95,7 +114,7 @@ static void plot_text(struct graphics_context *gc, text_render_options_t *tro,
 }
 
 /*
- * Find the next maximum point in a 10-minute window.
+ * Find the next minimum/maximum point.
  *
  * We exit early if we hit "enough" of a depth reversal,
  * which is roughly 10 feet.
@@ -143,7 +162,7 @@ static struct sample *next_minmax(struct sample *sample, struct sample *end, int
 
 static void render_depth_sample(struct graphics_context *gc, struct sample *sample)
 {
-       text_render_options_t tro = {1.0, 0.2, 0.2, CENTER};
+       text_render_options_t tro = {14, 1.0, 0.2, 0.2, CENTER, TOP};
        int sec = sample->time.seconds;
        depth_t depth = sample->depth;
        const char *fmt;
@@ -164,21 +183,16 @@ static void render_depth_sample(struct graphics_context *gc, struct sample *samp
 
 static void plot_text_samples(struct graphics_context *gc, struct sample *a, struct sample *b)
 {
-       struct sample *max, *min;
-
-       if (b <= a)
-               return;
-       if (b[-1].time.seconds - a->time.seconds < 3*60)
-               return;
-
-       max = next_minmax(a, b, 1);
-       if (max) {
-               render_depth_sample(gc, max);
-               min = next_minmax(max, b, 0);
-               if (min) {
-                       plot_text_samples(gc, min, b);
+       for (;;) {
+               if (b <= a)
+                       break;
+               a = next_minmax(a, b, 1);
+               if (!a)
                        return;
-               }
+               render_depth_sample(gc, a);
+               a = next_minmax(a, b, 0);
+               if (!a)
+                       break;
        }
 }
 
@@ -194,8 +208,6 @@ static void plot_depth_text(struct dive *dive, struct graphics_context *gc)
        gc->scalex = maxtime;
        gc->scaley = maxdepth;
 
-       cairo_set_font_size(gc->cr, 14);
-
        sample = dive->sample;
        end = dive->sample + dive->samples;
 
@@ -368,7 +380,7 @@ static double calculate_airuse(struct dive *dive)
 
 static void plot_info(struct dive *dive, struct graphics_context *gc)
 {
-       text_render_options_t tro = {0.2, 1.0, 0.2, LEFT};
+       text_render_options_t tro = {10, 0.2, 1.0, 0.2, LEFT, TOP};
        const double liters_per_cuft = 28.317;
        const char *unit;
        double airuse;
@@ -399,8 +411,6 @@ static void plot_cylinder_pressure_text(struct dive *dive, struct graphics_conte
 {
        pressure_t startp, endp;
 
-       cairo_set_font_size(gc->cr, 10);
-
        if (get_cylinder_pressure_range(dive, gc, &startp, &endp)) {
                int start, end;
                const char *unit = "bar";
@@ -423,7 +433,7 @@ static void plot_cylinder_pressure_text(struct dive *dive, struct graphics_conte
                        break;
                }
 
-               text_render_options_t tro = {0.2, 1.0, 0.2, LEFT};
+               text_render_options_t tro = {10, 0.2, 1.0, 0.2, LEFT, TOP};
                plot_text(gc, &tro, 0, startp.mbar, "%d %s", start, unit);
                plot_text(gc, &tro, dive->duration.seconds, endp.mbar,
                          "%d %s", end, unit);