mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
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 <dirk@hohndel.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
e88695ff72
commit
dfe5133b57
1 changed files with 43 additions and 7 deletions
48
profile.c
48
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,6 +45,7 @@ static void plot_text(cairo_t *cr, double x, double y, const char *fmt, ...)
|
|||
|
||||
cairo_text_extents(cr, buffer, &extents);
|
||||
|
||||
if (tro->allign == CENTER)
|
||||
x -= extents.width/2 + extents.x_bearing;
|
||||
y += extents.height * 1.2;
|
||||
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue