Add zoom capability through keypad +/- keys
authorLukas Jiriste <ljiriste@student.42prague.com>
Wed, 17 Jan 2024 09:34:00 +0000 (10:34 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Wed, 17 Jan 2024 09:34:00 +0000 (10:34 +0100)
event_handling.c

index f568f0b9f5d2296eac625b61a795c563bf2557d3..f6d6c3917a84399b83dc495b1f7c9e3dcc64b87c 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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);
 }