From: Lukas Jiriste Date: Wed, 17 Jan 2024 09:34:00 +0000 (+0100) Subject: Add zoom capability through keypad +/- keys X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=1fd0ebd6320e20aafc38aeabef26c28edd2670eb;p=42%2Ffract-ol.git Add zoom capability through keypad +/- keys --- diff --git a/event_handling.c b/event_handling.c index f568f0b..f6d6c39 100644 --- a/event_handling.c +++ b/event_handling.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/12/05 19:35:01 by ljiriste #+# #+# */ -/* Updated: 2024/01/16 14:24:40 by ljiriste ### ########.fr */ +/* Updated: 2024/01/17 10:31:31 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,9 @@ #include "fractol.h" #include "vect2.h" -#define MOVE_AMOUNT 0.1 +#define MOVE_AMOUNT 0.03 +#define ZOOM_OUT 0.5 +#define ZOOM_IN 2 int handle_key_press(int keycode, t_session *s) { @@ -30,24 +32,23 @@ int handle_key_press(int keycode, t_session *s) move_view(0, -MOVE_AMOUNT, s); else if (keycode == XK_Right || keycode == XK_d) move_view(MOVE_AMOUNT, 0, s); - if (keycode != XK_Escape && s->view.draw_whole) + else if (keycode == XK_KP_Add) + change_zoom(&s->view, (t_vect2){.x = s->img.width / 2, .y = s->img.height / 2}, ZOOM_IN); + else if (keycode == XK_KP_Subtract) + change_zoom(&s->view, (t_vect2){.x = s->img.width / 2, .y = s->img.height / 2}, ZOOM_OUT); + if (keycode != XK_Escape) draw_fractal(s); return (0); } int handle_mouse_press(int button, int x, int y, t_session *s) { - double delta_zoom; - if (button == Button4) - delta_zoom = 0.5; + change_zoom(&s->view, (t_vect2){.x = x, .y = y}, ZOOM_OUT); else if (button == Button5) - delta_zoom = 2; + change_zoom(&s->view, (t_vect2){.x = x, .y = y}, ZOOM_IN); if (button == Button4 || button == Button5) - { - change_zoom(&s->view, (t_vect2){.x = x, .y = y}, delta_zoom); draw_fractal(s); - } return (0); }