summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-13 05:35:05 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-13 05:35:05 (GMT)
commit2fca07a9e40e29751a7714d7200f49048f73385b (patch)
tree85c43935d5475976855fc78fc4b81b2c505e2805 /meme/gui.c
parent26600675a81a9617ff70508ae86dbf7ab1652bd0 (diff)
downloadmisc-2fca07a9e40e29751a7714d7200f49048f73385b.zip
misc-2fca07a9e40e29751a7714d7200f49048f73385b.tar.gz
misc-2fca07a9e40e29751a7714d7200f49048f73385b.tar.bz2
meme/gui.c: add markers and distance measurements
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c98
1 files changed, 97 insertions, 1 deletions
diff --git a/meme/gui.c b/meme/gui.c
index d573f47..93a051e 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -31,9 +31,14 @@
#define CURSOR_R 5
+#define MARK_WIDTH 2
+#define MARK_LEN 20
+
#define EDGE_RGBA 0x000000ff
#define CURSOR_RGBA 0xff202080
#define PROFILE_RGBA 0x2020ffff
+#define MARK_A_RGBA 0x00ff00ff
+#define MARK_B_RGBA 0x3030ffff
#define DEPTH_RANGE 0xc0
#define DEPTH_OFFSET 0x30
@@ -456,6 +461,89 @@ static const struct vertex *find_nearest(int x, int y)
}
+/* ----- Markers ----------------------------------------------------------- */
+
+
+static const struct vertex *mark_a, *mark_b;
+static bool curr_mark;
+
+
+static void show_marker(SDL_Surface *s, const struct vertex *v, Uint32 color)
+{
+ int x = x_model2screen(v->x);
+ int y = y_model2screen(v->y);
+
+ change(s, x-MARK_LEN, y-MARK_WIDTH, 2*MARK_LEN+1, 2*MARK_WIDTH+1);
+ change(s, x-MARK_WIDTH, y-MARK_LEN, 2*MARK_WIDTH+1, 2*MARK_LEN+1);
+ thickLineColor(s, x-MARK_LEN, y, x+MARK_LEN, y, MARK_WIDTH, color);
+ thickLineColor(s, x, y-MARK_LEN, x, y+MARK_LEN, MARK_WIDTH, color);
+}
+
+
+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);
+}
+
+
+static bool select_marker(const struct vertex *v)
+{
+ if (v == mark_a) {
+ mark_a = NULL;
+ curr_mark = 0;
+ return 1;
+ }
+ if (v == mark_b) {
+ mark_b = NULL;
+ curr_mark = 1;
+ return 1;
+ }
+ if (!mark_a && !mark_b) {
+ curr_mark = 0;
+ return 0;
+ }
+ if (mark_a && mark_b)
+ return 0;
+ if (mark_a)
+ curr_mark = 1;
+ else
+ curr_mark = 0;
+ return 0;
+}
+
+
+static void set_marker(const struct vertex *v)
+{
+ double dx, dy, dz;
+
+ if (select_marker(v))
+ return;
+
+ if (curr_mark)
+ mark_b = cursor;
+ else
+ mark_a = cursor;
+
+ fprintf(stderr, "%c:\tX %.3f\tY %.3f\tZ %.3f\n",
+ curr_mark ? 'B' : 'A',
+ cursor->x/1000.0, cursor->y/1000.0, cursor->z/1000.0);
+ if (!mark_a || !mark_b)
+ return;
+
+ dx = abs(mark_a->x - mark_b->x) / 1000.0;
+ dy = abs(mark_a->y - mark_b->y) / 1000.0;
+ dz = abs(mark_a->z - mark_b->z) / 1000.0;
+
+ fprintf(stderr, "D:\tX %.3f\tY %.3f\tZ %.3f\n", dx, dy, dz);
+ fprintf(stderr, " \tXY %.3f\tXZ %.3f\tYZ %.3f\n",
+ hypot(dx, dy), hypot(dx, dz), hypot(dy, dz));
+ fprintf(stderr, " \tXYZ %.3f\n", hypot(hypot(dx, dy), dz));
+}
+
+
/* ----- Event handling ---------------------------------------------------- */
@@ -480,6 +568,11 @@ static void button_event(SDL_MouseButtonEvent *button)
int y = y_screen2model(button->y);
switch (button->button) {
+ case 1:
+ if (!cursor)
+ break;
+ set_marker(cursor);
+ break;
case 2:
x_orig = x;
y_orig = y;
@@ -676,6 +769,7 @@ static bool event_loop(SDL_Surface *s)
case SDL_MOUSEMOTION:
if (cursor)
hide_cursor(s);
+ show_markers(s);
cursor = NULL;
motion.s = s;
motion.event = event.motion;
@@ -738,10 +832,12 @@ fprintf(stderr, "%.3f s @ zoom %d\n", time_ms(&t)/1000.0, zoom);
SDL_UnlockSurface(surf);
SDL_UpdateRect(surf, 0, 0, 0, 0);
+ show_markers(surf);
if (cursor) {
show_cursor(surf, cursor);
- apply_changes(surf);
+// apply_changes(surf);
}
+ apply_changes(surf);
if (event_loop(surf))
break;