summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2014-09-27 14:17:16 (GMT)
committerWerner Almesberger <werner@almesberger.net>2014-09-27 14:17:16 (GMT)
commitdd371c04336bc3b52e5c21292f13e088bd9a2bee (patch)
tree32263f662b61db6b23f1521685a7965b79851c1b /meme/gui.c
parentfaecddaef752d8ff47863b13cd5e7a1e960b89a9 (diff)
downloadmisc-dd371c04336bc3b52e5c21292f13e088bd9a2bee.zip
misc-dd371c04336bc3b52e5c21292f13e088bd9a2bee.tar.gz
misc-dd371c04336bc3b52e5c21292f13e088bd9a2bee.tar.bz2
meme/gui.c, README: keep track of last mouse position; + and - keys zoom in/out
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c40
1 files changed, 33 insertions, 7 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 769e899..e351c76 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -833,6 +833,26 @@ static void clear_markers(void)
}
+/* ----- Last mouse position ---------------------------------------------- */
+
+
+static int mouse_x, mouse_y;
+
+
+static void update_mouse_pos(Uint16 x, Uint16 y)
+{
+ mouse_x = x_screen2model(x);
+ mouse_y = y_screen2model(y);
+}
+
+
+static void init_mouse_pos(void)
+{
+ mouse_x = (x_min+x_max)/2;
+ mouse_y = (y_min+y_max)/2;
+}
+
+
/* ----- Scaling ----------------------------------------------------------- */
@@ -896,9 +916,6 @@ static void motion_event(SDL_Surface *s, SDL_MouseMotionEvent *motion)
static void button_event(SDL_MouseButtonEvent *button)
{
- int x = x_screen2model(button->x);
- int y = y_screen2model(button->y);
-
switch (button->button) {
case 1:
if (!cursor)
@@ -906,17 +923,17 @@ static void button_event(SDL_MouseButtonEvent *button)
set_marker(cursor);
break;
case 2:
- x_orig = x;
- y_orig = y;
+ x_orig = mouse_x;
+ y_orig = mouse_y;
break;
case 3:
clear_markers();
break;
case 4: /* wheel forward */
- zoom_in(x, y);
+ zoom_in(mouse_x, mouse_y);
break;
case 5: /* wheel backward */
- zoom_out(x, y);
+ zoom_out(mouse_x, mouse_y);
break;
}
}
@@ -1094,6 +1111,7 @@ static bool event_loop(SDL_Surface **surf)
switch (event.type) {
case SDL_MOUSEMOTION:
+ update_mouse_pos(event.motion.x, event.motion.y);
if (cursor)
hide_cursor(s);
show_markers(s);
@@ -1104,6 +1122,7 @@ static bool event_loop(SDL_Surface **surf)
50);
break;
case SDL_MOUSEBUTTONDOWN:
+ update_mouse_pos(event.button.x, event.button.y);
button_event(&event.button);
return 0;
case SDL_VIDEORESIZE:
@@ -1137,6 +1156,12 @@ static bool event_loop(SDL_Surface **surf)
case '*':
auto_scale();
return 0;
+ case '+':
+ zoom_in(mouse_x, mouse_y);
+ return 0;
+ case '-':
+ zoom_out(mouse_x, mouse_y);
+ return 0;
}
break;
case SDL_KEYUP:
@@ -1181,6 +1206,7 @@ void gui(void)
SDL_EnableUNICODE(1);
extrema();
+ init_mouse_pos();
init_z_grad();
auto_scale();