summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-02-14 03:54:57 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-02-14 03:55:32 (GMT)
commitd5afcf56635da6a906dc7343fed6576720b809ba (patch)
tree7bf699aadec0e766347b175f8dd3510c10c82293 /meme/gui.c
parent72e6384adec350a300e7c508ee027f3ec8b5857c (diff)
downloadmisc-d5afcf56635da6a906dc7343fed6576720b809ba.zip
misc-d5afcf56635da6a906dc7343fed6576720b809ba.tar.gz
misc-d5afcf56635da6a906dc7343fed6576720b809ba.tar.bz2
meme/: add marker system (for documentation); option -m marker.gp to add markers
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 4133db6..239ac3c 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -23,6 +23,7 @@
#include "time.h"
#include "mesh.h"
#include "overlay.h"
+#include "marker.h"
#include "plane.h"
#include "gaux.h"
#include "screen.h"
@@ -49,11 +50,14 @@
#define EQUAL_RGBA 0xf080ffff
#define OVERLAY_MIX_RGBA 0xffc01060
#define OVERLAY_ALONE_RGBA 0xffc010ff
+#define MARKER_LINE_RGBA 0x00ff00ff
#define DEPTH_RANGE 0xc0
#define DEPTH_OFFSET 0x30
+struct marker marker;
+
static int x_orig, y_orig;
static Sint16 xres, yres;
static int x_min, x_max, y_min, y_max, z_min, z_max;
@@ -897,7 +901,6 @@ static void marker_next(void)
/* ----- Overlay ----------------------------------------------------------- */
-
static Sint16 ovl_x, ovl_y;
static int ovl_ok;
@@ -939,6 +942,56 @@ static void draw_overlay(SDL_Surface *s, const struct overlay *over)
}
+/* ----- Markers ----------------------------------------------------------- */
+
+
+#define TEXT_OFFSET_X -4
+#define TEXT_OFFSET_Y -5
+#define TEXT_DIST 10
+
+
+static void marker_line(void *user, int xa, int ya, int xb, int yb)
+{
+ SDL_Surface *s = user;
+ Sint16 ax = 0, ay = 0, bx = 0, by = 0;
+
+ if (coord(xa, ya, &ax, &ay) && coord(xb, yb, &bx, &by) <= 0)
+ return;
+ aalineColor(s, ax, ay, bx, by, MARKER_LINE_RGBA);
+}
+
+
+static void marker_text(void *user, int x, int y, float nx, float ny,
+ const char *txt)
+{
+ SDL_Surface *s = user;
+ Sint16 xx = 0, yy = 0;
+ SDL_Surface *t;
+ SDL_Rect r;
+
+ if (coord(x, y, &xx, &yy) <= 0)
+ return;
+
+ t = text(txt);
+ r.x = xx + TEXT_OFFSET_X + TEXT_DIST * nx;
+ r.y = yy + TEXT_OFFSET_Y + TEXT_DIST * ny;
+
+ r.w = t->w;
+ r.h = t->h;
+ if (SDL_BlitSurface(t, NULL, s, &r)) {
+ fprintf(stderr, "SDL_BlitSurface: %s \n", SDL_GetError());
+ exit(1);
+ }
+ SDL_FreeSurface(t);
+}
+
+
+static void draw_marker(SDL_Surface *s)
+{
+ marker_draw(&marker, marker_line, marker_text, s);
+}
+
+
/* ----- Last mouse position ---------------------------------------------- */
@@ -1269,6 +1322,7 @@ static bool event_loop(SDL_Surface **surf, const char *logfile,
case SDLK_r:
for (i = 0; i != n_overlays; i++)
overlay_reload(overlays + i);
+ marker_reload(&marker);
return 0;
case SDLK_1:
if (n_overlays)
@@ -1359,6 +1413,7 @@ fprintf(stderr, "%.3f s @ zoom %d\n", time_ms(&t)/1000.0, zoom);
if (show_overlay)
draw_overlay(surf, overlay);
SDL_UnlockSurface(surf);
+ draw_marker(surf);
SDL_UpdateRect(surf, 0, 0, 0, 0);
show_markers(surf);