X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=profile.c;h=39db599cec7246245d6cb4f936dc206ec4f5eb8c;hb=30d228f104b5f1eb2c8354460b19e0b367d899ee;hp=9ed76b6c246e60d30ee0c278f74ce6946514f56c;hpb=06399d7d2fcc583f7437eab843ac073ebc37ee95;p=ext%2Fsubsurface.git diff --git a/profile.c b/profile.c index 9ed76b6..39db599 100644 --- a/profile.c +++ b/profile.c @@ -57,12 +57,13 @@ static int round_depth_up(depth_t depth) } typedef struct { + int size; double r,g,b; 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, +static void plot_text(struct graphics_context *gc, const text_render_options_t *tro, double x, double y, const char *fmt, ...) { cairo_t *cr = gc->cr; @@ -75,6 +76,7 @@ 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; switch (tro->halign) { @@ -111,6 +113,26 @@ static void plot_text(struct graphics_context *gc, text_render_options_t *tro, cairo_show_text(cr, buffer); } +static void render_depth_sample(struct graphics_context *gc, struct sample *sample, const text_render_options_t *tro) +{ + int sec = sample->time.seconds; + depth_t depth = sample->depth; + const char *fmt; + double d; + + switch (output_units.length) { + case METERS: + d = depth.mm / 1000.0; + fmt = "%.1f"; + break; + case FEET: + d = to_feet(depth); + fmt = "%.0f"; + break; + } + plot_text(gc, tro, sec, depth.mm, fmt, d); +} + /* * Find the next minimum/maximum point. * @@ -130,12 +152,11 @@ static struct sample *next_minmax(struct sample *sample, struct sample *end, int result = NULL; for (;;) { - int time, depth; + int depth; sample++; if (sample >= end) return NULL; - time = sample->time.seconds; depth = sample->depth.mm; if (minmax) { @@ -158,39 +179,24 @@ static struct sample *next_minmax(struct sample *sample, struct sample *end, int return result; } -static void render_depth_sample(struct graphics_context *gc, struct sample *sample) -{ - text_render_options_t tro = {1.0, 0.2, 0.2, CENTER, TOP}; - int sec = sample->time.seconds; - depth_t depth = sample->depth; - const char *fmt; - double d; - - switch (output_units.length) { - case METERS: - d = depth.mm / 1000.0; - fmt = "%.1f"; - break; - case FEET: - d = to_feet(depth); - fmt = "%.0f"; - break; - } - plot_text(gc, &tro, sec, depth.mm, fmt, d); -} - static void plot_text_samples(struct graphics_context *gc, struct sample *a, struct sample *b) { + static const text_render_options_t deep = {14, 1.0, 0.2, 0.2, CENTER, TOP}; + static const text_render_options_t shallow = {14, 1.0, 0.2, 0.2, CENTER, BOTTOM}; + for (;;) { if (b <= a) break; a = next_minmax(a, b, 1); if (!a) - return; - render_depth_sample(gc, a); + break; + render_depth_sample(gc, a, &deep); a = next_minmax(a, b, 0); if (!a) break; + if (a->depth.mm < 2500) + continue; + render_depth_sample(gc, a, &shallow); } } @@ -206,8 +212,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; @@ -380,7 +384,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, TOP}; + 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; @@ -411,8 +415,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"; @@ -435,7 +437,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, TOP}; + 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);