summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-02-15 21:13:47 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-02-15 21:13:47 (GMT)
commit64bd53f6a5413810dd8e36237cf5aaf9feee0be4 (patch)
tree3ec42f6762e9680c57c432314ab1467d09f73659 /meme/gui.c
parentff87a9e52408776b5f7fc32889b85d74e09857a7 (diff)
downloadmisc-64bd53f6a5413810dd8e36237cf5aaf9feee0be4.zip
misc-64bd53f6a5413810dd8e36237cf5aaf9feee0be4.tar.gz
misc-64bd53f6a5413810dd8e36237cf5aaf9feee0be4.tar.bz2
meme/: non-interactive screen dumps with -D ...
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c89
1 files changed, 82 insertions, 7 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 915ed3b..6cda8ca 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -191,6 +191,7 @@ static void calc_z_grad(int center, unsigned c_zoom)
int col;
uint8_t mid = DEPTH_RANGE >> 1;
+fprintf(stderr, "center %d zoom %u\n", center, c_zoom);
if (!zoom_z_grad)
zoom_z_grad = calloc(3*(z_max-z_min)+1, sizeof(Uint32));
for (i = 0; i <= 3*(z_max-z_min); i++) {
@@ -1057,13 +1058,26 @@ static void init_mouse_pos(void)
/* ----- Scaling ----------------------------------------------------------- */
-static void auto_scale(void)
+static void auto_center(void)
{
- x_orig = (x_min+x_max) >> 1;
- y_orig = (y_min+y_max) >> 1;
+ x_orig = (x_min + x_max) >> 1;
+ y_orig = (y_min + y_max) >> 1;
+}
+
+
+static void auto_zoom(bool full)
+{
+ float f = full ? 1 : 0.9;
+
+ for (zoom = 0; (x_max - x_min) >> zoom > xres * f ||
+ (y_max - y_min) >> zoom > yres * f; zoom++);
+}
+
- for (zoom = 0; (x_max-x_min) >> zoom > xres*0.9 ||
- (y_max-y_min) >> zoom > yres*0.9; zoom++);
+static void auto_scale(bool full)
+{
+ auto_center();
+ auto_zoom(full);
}
@@ -1385,7 +1399,7 @@ static bool event_loop(SDL_Surface **surf, const char *logfile,
break;
switch (event.key.keysym.unicode) {
case '*':
- auto_scale();
+ auto_scale(false);
return 0;
case '+':
zoom_in(mouse_x, mouse_y);
@@ -1415,6 +1429,67 @@ static bool event_loop(SDL_Surface **surf, const char *logfile,
}
+void gui_dump(struct overlay overlays[], unsigned n_overlays,
+ const struct dump_params *prm)
+{
+ SDL_Surface *surf;
+
+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ fprintf(stderr, "SDL_init: %s\n", SDL_GetError());
+ exit(1);
+ }
+ atexit(SDL_Quit);
+
+ surf = sdl_surface(SDL_SWSURFACE, prm->xres, prm->yres);
+
+ xres = surf->w;
+ yres = surf->h;
+
+ extrema();
+// init_mouse_pos();
+ init_z_grad();
+
+ if (prm->enhance) {
+ begin_contrast();
+ calc_z_grad(prm->enh_z - z_min, contrast_zoom - prm->enh_scale);
+ }
+ if (prm->middle) {
+ x_orig = prm->mx;
+ y_orig = prm->my;
+ } else {
+ auto_center();
+ }
+
+ if (!prm->zoom_abs)
+ auto_zoom(true);
+ if (prm->zoom_abs)
+ zoom = prm->zoom;
+ if (prm->zoom_rel)
+ zoom -= prm->zoom;
+
+ SDL_LockSurface(surf);
+ draw(surf);
+ draw_overlay(surf, n_overlays ? overlays : NULL);
+ draw_marker(surf);
+ SDL_UnlockSurface(surf);
+ SDL_UpdateRect(surf, 0, 0, 0, 0);
+
+ if (prm->cursor) {
+ cursor = find_nearest(prm->cx, prm->cy);
+ if (cursor) {
+ if (prm->profile) {
+ show_xz_profile(surf);
+ show_yz_profile(surf);
+ }
+ show_cursor(surf, cursor);
+ apply_changes(surf);
+ }
+ }
+
+ dump_screen(surf);
+}
+
+
void gui(const char *logfile, struct overlay overlays[], unsigned n_overlays)
{
SDL_Surface *surf;
@@ -1439,7 +1514,7 @@ void gui(const char *logfile, struct overlay overlays[], unsigned n_overlays)
extrema();
init_mouse_pos();
init_z_grad();
- auto_scale();
+ auto_scale(false);
if (n_overlays)
overlay = overlays;