X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=profile.c;h=f898be74580d04e80b03926428df962e8d2f32c5;hb=ee56021dfbc3bcc12f5917cdf481cc96c51a2b89;hp=3649bc1319aae494d42632e688a2d61cda03ff54;hpb=eed9538101a97142d8327119b9539f847f818198;p=ext%2Fsubsurface.git diff --git a/profile.c b/profile.c index 3649bc1..f898be7 100644 --- a/profile.c +++ b/profile.c @@ -8,16 +8,21 @@ int selected_dive = 0; #define ROUND_UP(x,y) ((((x)+(y)-1)/(y))*(y)) -#define MAX(x,y) ((x) > (y) ? (x) : (y)) +/* + * When showing dive profiles, we scale things to the + * current dive. However, we don't scale past less than + * 30 minutes or 90 ft, just so that small dives show + * up as such. + */ static int round_seconds_up(int seconds) { - return MAX(30, ROUND_UP(seconds, 60*10)); + return MAX(30*60, ROUND_UP(seconds, 60*10)); } static int round_feet_up(int feet) { - return MAX(45, ROUND_UP(feet+5, 15)); + return MAX(90, ROUND_UP(feet+5, 15)); } /* Scale to 0,0 -> maxx,maxy */ @@ -29,6 +34,7 @@ static void plot(cairo_t *cr, int w, int h, struct dive *dive, int samples, stru double topx, topy, maxx, maxy; double scalex, scaley; int maxtime, maxdepth; + int begins, sec, depth; topx = w / 20.0; topy = h / 20.0; @@ -63,11 +69,21 @@ static void plot(cairo_t *cr, int w, int h, struct dive *dive, int samples, stru /* Depth profile */ cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.80); + begins = sample->time.seconds; cairo_move_to(cr, SCALE(sample->time.seconds, to_feet(sample->depth))); for (i = 1; i < dive->samples; i++) { sample++; - cairo_line_to(cr, SCALE(sample->time.seconds, to_feet(sample->depth))); + sec = sample->time.seconds; + depth = to_feet(sample->depth); + cairo_line_to(cr, SCALE(sec, depth)); } + scaley = 1.0; + cairo_line_to(cr, SCALE(sec, 0)); + cairo_line_to(cr, SCALE(begins, 0)); + cairo_close_path(cr); + cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.20); + cairo_fill_preserve(cr); + cairo_set_source_rgba(cr, 1, 0.2, 0.2, 0.80); cairo_stroke(cr); /* Bounding box last */