summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-14 05:39:48 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-14 05:39:48 (GMT)
commite2dc06ebc066399e7274a6627127f725e1f07b17 (patch)
treef901ec1c8f177a1bb1c5c5e08427b62c0636d345 /meme/gui.c
parentd29d97b74306e97353414023d768775c9593de81 (diff)
downloadmisc-e2dc06ebc066399e7274a6627127f725e1f07b17.zip
misc-e2dc06ebc066399e7274a6627127f725e1f07b17.tar.gz
misc-e2dc06ebc066399e7274a6627127f725e1f07b17.tar.bz2
meme/: show measurement results on screen
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c76
1 files changed, 76 insertions, 0 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 7c9ddf1..2e562b4 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -21,6 +21,7 @@
#include "time.h"
#include "mesh.h"
#include "plane.h"
+#include "text.h"
#define XRES 640
@@ -462,6 +463,35 @@ static const struct vertex *find_nearest(int x, int y)
}
+/* ----- Add text change --------------------------------------------------- */
+
+
+#include <stdarg.h>
+
+
+static void text_change(SDL_Surface *s, int x, int y, const char *fmt, ...)
+{
+ SDL_Surface *t;
+ SDL_Rect r;
+ va_list ap;
+
+ va_start(ap, fmt);
+ t = vtextf(fmt, ap);
+ va_end(ap);
+
+ change(s, x, y, t->w, t->h);
+ r.x = x;
+ r.y = y;
+ r.w = t->w;
+ r.h = t->h;
+ if (SDL_BlitSurface(t, NULL, s, &r)) {
+ fprintf(stderr, "SDL_BlitSurface failed\n");
+ exit(1);
+ }
+ SDL_FreeSurface(t);
+}
+
+
/* ----- Markers ----------------------------------------------------------- */
@@ -481,12 +511,58 @@ static void show_marker(SDL_Surface *s, const struct vertex *v, Uint32 color)
}
+static void show_meas(SDL_Surface *s, int x, int y,
+ const struct vertex *a, const struct vertex *b,
+ Uint32 color)
+{
+ float dx, dy, dz;
+
+ dx = abs(a->x - b->x) / 1000.0;
+ dy = abs(a->y - b->y) / 1000.0;
+ dz = abs(a->z - b->z) / 1000.0;
+
+#define LS 12
+
+ text_color(color);
+ if (dx) {
+ text_change(s, x, y, "X %7.3f", dx);
+ y += LS;
+ }
+ if (dy) {
+ text_change(s, x, y, "Y %7.3f", dy);
+ y += LS;
+ }
+ if (dz) {
+ text_change(s, x, y, "Z %7.3f", dz);
+ y += LS;
+ }
+ if (dx && dy) {
+ text_change(s, x, y, "XY %7.3f", hypotf(dx, dy));
+ y += LS;
+ }
+ if (dx && dz) {
+ text_change(s, x, y, "XZ %7.3f", hypotf(dx, dz));
+ y += LS;
+ }
+ if (dy && dz) {
+ text_change(s, x, y, "YZ %7.3f", hypotf(dy, dz));
+ y += LS;
+ }
+ if (dx && dy && dz) {
+ text_change(s, x, y, "3D %7.3f", hypotf(hypotf(dx, dy), dz));
+ y += LS;
+ }
+}
+
+
static void show_markers(SDL_Surface *s)
{
if (mark_a)
show_marker(s, mark_a, MARK_A_RGBA);
if (mark_b)
show_marker(s, mark_b, MARK_B_RGBA);
+ if (mark_a && mark_b)
+ show_meas(s, 10, 10, mark_a, mark_b, 0x000000ff);
}