From: Dirk Hohndel Date: Tue, 6 Sep 2011 22:00:56 +0000 (-0700) Subject: Print starting and ending pressures X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=dfe5133b579d1ee999080de68041d0009aa4b5d5;p=ext%2Fsubsurface.git Print starting and ending pressures This is very simplistic as far as placement of the text goes. It makes the plot_text function somewhat more generic. Signed-off-by: Dirk Hohndel Signed-off-by: Linus Torvalds --- diff --git a/profile.c b/profile.c index f10e856..f0a4c70 100644 --- a/profile.c +++ b/profile.c @@ -27,7 +27,13 @@ static int round_feet_up(int feet) return MAX(90, ROUND_UP(feet+5, 15)); } -static void plot_text(cairo_t *cr, double x, double y, const char *fmt, ...) +typedef struct { + double r,g,b; + enum {CENTER,LEFT} allign; +} text_render_options_t; + +static void plot_text(cairo_t *cr, text_render_options_t *tro, + double x, double y, const char *fmt, ...) { cairo_text_extents_t extents; char buffer[80]; @@ -39,7 +45,8 @@ static void plot_text(cairo_t *cr, double x, double y, const char *fmt, ...) cairo_text_extents(cr, buffer, &extents); - x -= extents.width/2 + extents.x_bearing; + if (tro->allign == CENTER) + x -= extents.width/2 + extents.x_bearing; y += extents.height * 1.2; cairo_move_to(cr, x, y); @@ -48,7 +55,7 @@ static void plot_text(cairo_t *cr, double x, double y, const char *fmt, ...) cairo_stroke(cr); cairo_move_to(cr, x, y); - cairo_set_source_rgb(cr, 1, 0, 0); + cairo_set_source_rgb(cr, tro->r, tro->g, tro->b); cairo_show_text(cr, buffer); } @@ -126,11 +133,12 @@ static void plot_depth_text(struct dive *dive, cairo_t *cr, cairo_set_source_rgb(cr, 1, 0.2, 0.2); i = 0; while ((i = next_minmax(dive, i, 1)) != 0) { + text_render_options_t tro = {1.0, 0.2, 0.2, CENTER}; struct sample *sample = dive->sample+i; int sec = sample->time.seconds; int depth = to_feet(sample->depth); - plot_text(cr, SCALE(sec, depth), "%d ft", depth); + plot_text(cr, &tro, SCALE(sec, depth), "%d ft", depth); i = next_minmax(dive, i, 0); if (!i) break; @@ -202,18 +210,23 @@ static void plot_depth_profile(struct dive *dive, cairo_t *cr, cairo_stroke(cr); } -static int get_cylinder_pressure_range(struct dive *dive, double *scalex, double *scaley) +/* gets both the actual start and end pressure as well as the scaling factors */ +static int get_cylinder_pressure_range(struct dive *dive, double *scalex, double *scaley, + double *startp, double *endp) { int i; double min, max; + double bar; *scalex = round_seconds_up(dive->duration.seconds); max = 0; min = 5000; + if (startp) + *startp = *endp = 0.0; + for (i = 0; i < dive->samples; i++) { struct sample *sample = dive->sample + i; - double bar; /* FIXME! We only track cylinder 0 right now */ if (sample->cylinderindex) @@ -221,11 +234,15 @@ static int get_cylinder_pressure_range(struct dive *dive, double *scalex, double if (!sample->cylinderpressure.mbar) continue; bar = sample->cylinderpressure.mbar; + if (bar != 0.0 && startp && *startp == 0.0) + *startp = bar; if (bar < min) min = bar; if (bar > max) max = bar; } + if (endp) + *endp = bar; if (!max) return 0; *scaley = max * 1.5; @@ -238,7 +255,7 @@ static void plot_cylinder_pressure(struct dive *dive, cairo_t *cr, int i, sec = -1; double scalex, scaley; - if (!get_cylinder_pressure_range(dive, &scalex, &scaley)) + if (!get_cylinder_pressure_range(dive, &scalex, &scaley, NULL, NULL)) return; cairo_set_source_rgba(cr, 0.2, 1.0, 0.2, 0.80); @@ -263,6 +280,24 @@ static void plot_cylinder_pressure(struct dive *dive, cairo_t *cr, cairo_stroke(cr); } + +static void plot_cylinder_pressure_text(struct dive *dive, cairo_t *cr, + double topx, double topy, double maxx, double maxy) +{ + double scalex, scaley; + double startp,endp; + + cairo_set_font_size(cr, 10); + + if (get_cylinder_pressure_range(dive, &scalex, &scaley, + &startp, &endp)) { + text_render_options_t tro = {0.2, 1.0, 0.2, LEFT}; + plot_text(cr, &tro, SCALE(0, startp), "%3.0f bar", startp/1000.0); + plot_text(cr, &tro, SCALE(dive->duration.seconds, endp), + "%3.0f bar", endp/1000.0); + } +} + static void plot(cairo_t *cr, int w, int h, struct dive *dive) { double topx, topy, maxx, maxy; @@ -281,6 +316,7 @@ static void plot(cairo_t *cr, int w, int h, struct dive *dive) /* Text on top of all graphs.. */ plot_depth_text(dive, cr, topx, topy, maxx, maxy); + plot_cylinder_pressure_text(dive, cr, topx, topy, maxx, maxy); /* Bounding box last */ scalex = scaley = 1.0;