+typedef struct {
+ int size;
+ double r,g,b;
+ double hpos, vpos;
+} text_render_options_t;
+
+#define RIGHT (-1.0)
+#define CENTER (-0.5)
+#define LEFT (0.0)
+
+#define TOP (1)
+#define MIDDLE (0)
+#define BOTTOM (-1)
+
+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;
+ cairo_font_extents_t fe;
+ cairo_text_extents_t extents;
+ double dx, dy;
+ char buffer[80];
+ va_list args;
+
+ va_start(args, fmt);
+ vsnprintf(buffer, sizeof(buffer), fmt, args);
+ va_end(args);
+
+ cairo_set_font_size(cr, tro->size);
+ cairo_font_extents(cr, &fe);
+ cairo_text_extents(cr, buffer, &extents);
+ dx = tro->hpos * extents.width + extents.x_bearing;
+ dy = tro->vpos * extents.height + fe.descent;
+
+ move_to(gc, x, y);
+ cairo_rel_move_to(cr, dx, dy);
+
+ cairo_text_path(cr, buffer);
+ set_source_rgb(gc, 0, 0, 0);
+ cairo_stroke(cr);
+
+ move_to(gc, x, y);
+ cairo_rel_move_to(cr, dx, dy);
+
+ set_source_rgb(gc, tro->r, tro->g, tro->b);
+ cairo_show_text(cr, buffer);
+}
+
+static void plot_one_event(struct graphics_context *gc, struct plot_info *pi, struct event *event, const text_render_options_t *tro)
+{
+ int i, depth = 0;
+ int x,y;
+
+ for (i = 0; i < pi->nr; i++) {
+ struct plot_data *data = pi->entry + i;
+ if (event->time.seconds < data->sec)
+ break;
+ depth = data->depth;
+ }
+ /* draw a little tirangular marker and attach tooltip */
+ x = SCALEX(gc, event->time.seconds);
+ y = SCALEY(gc, depth);
+ set_source_rgba(gc, 1.0, 1.0, 0.1, 0.8);
+ cairo_move_to(gc->cr, x-15, y+6);
+ cairo_line_to(gc->cr, x-3 , y+6);
+ cairo_line_to(gc->cr, x-9, y-6);
+ cairo_line_to(gc->cr, x-15, y+6);
+ cairo_stroke_preserve(gc->cr);
+ cairo_fill(gc->cr);
+ set_source_rgba(gc, 0.0, 0.0, 0.0, 0.8);
+ cairo_move_to(gc->cr, x-9, y-3);
+ cairo_line_to(gc->cr, x-9, y+1);
+ cairo_move_to(gc->cr, x-9, y+4);
+ cairo_line_to(gc->cr, x-9, y+4);
+ cairo_stroke(gc->cr);
+ attach_tooltip(x-15, y-6, 12, 12, event->name);
+}
+
+static void plot_events(struct graphics_context *gc, struct plot_info *pi, struct dive *dive)
+{
+ static const text_render_options_t tro = {14, 1.0, 0.2, 0.2, CENTER, TOP};
+ struct event *event = dive->events;
+
+ if (gc->printer)
+ return;
+
+ while (event) {
+ plot_one_event(gc, pi, event, &tro);
+ event = event->next;
+ }
+}