}
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,
+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;
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);
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 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.
{
const int enough = 3000;
struct sample *result;
- int timelimit, depthlimit;
+ int depthlimit;
if (sample >= end)
return 0;
- timelimit = 24*60*60;
depthlimit = sample->depth.mm;
result = NULL;
for (;;) {
- int time, depth;
+ int depth;
sample++;
if (sample >= end)
return NULL;
- time = sample->time.seconds;
depth = sample->depth.mm;
- if (time > timelimit)
- break;
if (minmax) {
if (depth <= depthlimit) {
result = sample;
depthlimit = depth;
- /* Look up to ten minutes into the future */
- timelimit = time + 600;
}
return result;
}
-void plot_text_samples(struct dive *dive, struct graphics_context *gc,
- struct sample *a, struct sample *b)
+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->time.seconds - a->time.seconds < 3*60)
- return;
+ 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};
- max = next_minmax(a, b, 1);
- if (max) {
- text_render_options_t tro = {1.0, 0.2, 0.2, CENTER};
- int sec = max->time.seconds;
- depth_t depth = max->depth;
- const char *fmt;
- double d;
-
- min = next_minmax(max, b, 0);
- plot_text_samples(dive, gc, a, max);
- if (min) {
- plot_text_samples(dive, gc, max, min);
- plot_text_samples(dive, gc, min, b);
- } else
- plot_text_samples(dive, gc, max, b);
-
- switch (output_units.length) {
- case METERS:
- d = depth.mm / 1000.0;
- fmt = "%.1f";
+ for (;;) {
+ if (b <= a)
break;
- case FEET:
- d = to_feet(depth);
- fmt = "%.0f";
+ a = next_minmax(a, b, 1);
+ if (!a)
break;
- }
-
- plot_text(gc, &tro, sec, depth.mm, fmt, d);
- return;
+ 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);
}
}
gc->scalex = maxtime;
gc->scaley = maxdepth;
- cairo_set_font_size(gc->cr, 14);
-
- /*
- * We never take the last sample into account.
- * It should be a surface event anyway, although
- * there are buggy cases where it isn't..
- */
sample = dive->sample;
- end = dive->sample + dive->samples - 1;
+ end = dive->sample + dive->samples;
- plot_text_samples(dive, gc, sample, end);
+ plot_text_samples(gc, sample, end);
}
static void plot_depth_profile(struct dive *dive, struct graphics_context *gc)
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;
{
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";
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);