summaryrefslogtreecommitdiffstats
path: root/profile.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-11-11 13:20:32 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-11 14:44:10 +0100
commit01e8984d7d3b6da1196766b3b411151a5a7a5053 (patch)
treeecea8ec90dcf28b23ec45fad582ded34fbdedc3c /profile.c
parentfe4f13f184ffb97ee4b6dbd4138a9d8ae3aabd14 (diff)
downloadsubsurface-01e8984d7d3b6da1196766b3b411151a5a7a5053.tar.gz
Create tool-tip with depth/pressure for the whole profile area
This extends on our current tooltip logic (which shows events when you mouse over them) to show tooltips for the whole profile area. If you mouse over an event, that is still shown in the tooltip, but even in the absense of events, the tooltip will be active, and mousing over the profile area will show the time, depth and pressure. This can certainly be improved upon further, but even in this form it is useful. Fixes #9 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'profile.c')
-rw-r--r--profile.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/profile.c b/profile.c
index 065934746..c8ce440d6 100644
--- a/profile.c
+++ b/profile.c
@@ -900,6 +900,8 @@ static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi
maxtime = get_maxtime(pi);
maxdepth = get_maxdepth(pi);
+ gc->maxtime = maxtime;
+
/* Time markers: at most every 10 seconds, but no more than 12 markers.
* We start out with 10 seconds and increment up to 30 minutes,
* depending on the dive time.
@@ -1908,11 +1910,12 @@ static void plot_set_scale(scale_mode_t scale)
}
}
-void plot(struct graphics_context *gc, cairo_rectangle_t *drawing_area, struct dive *dive, scale_mode_t scale)
+void plot(struct graphics_context *gc, struct dive *dive, scale_mode_t scale)
{
struct plot_info *pi;
static struct sample fake[4];
struct sample *sample = dive->sample;
+ cairo_rectangle_t *drawing_area = &gc->drawing_area;
int nr = dive->samples;
plot_set_scale(scale);
@@ -1994,5 +1997,41 @@ void plot(struct graphics_context *gc, cairo_rectangle_t *drawing_area, struct d
plot_depth_scale(gc, pi);
- free(pi);
+ if (gc->printer) {
+ free(pi);
+ } else {
+ free(gc->plot_info);
+ gc->plot_info = pi;
+ }
+}
+
+static void plot_string(struct plot_data *entry, char *buf, size_t bufsize)
+{
+ int depth_decimals, pressure;
+ const char *depth_unit, *pressure_unit;
+ double depth;
+
+ depth = get_depth_units(entry->depth, &depth_decimals, &depth_unit);
+ pressure = get_pressure_units(GET_PRESSURE(entry), &pressure_unit);
+
+ snprintf(buf, bufsize, "%.*f %s\n%d %s",
+ depth_decimals, depth, depth_unit,
+ pressure, pressure_unit);
+}
+
+void get_plot_details(struct graphics_context *gc, int time, char *buf, size_t bufsize)
+{
+ struct plot_info *pi = gc->plot_info;
+
+ *buf = 0;
+ if (pi) {
+ int i;
+ for (i = 0; i < pi->nr; i++) {
+ struct plot_data *entry = pi->entry + i;
+ if (entry->sec >= time) {
+ plot_string(entry, buf, bufsize);
+ break;
+ }
+ }
+ }
}