From: Lukas Jiriste Date: Thu, 18 Apr 2024 07:57:14 +0000 (+0200) Subject: Fix centering and movement for small windows X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=7d053fce995c6ae7e41c4503f9ee30a4bff832ce;p=42%2Ffract-ol.git Fix centering and movement for small windows Centering was calculated based on default values hence it was wrong for different sizes of window. Solved by moving the calculation after argument parsing. Movement was impossible for small windows, as the calculated movement was smaller than a pixel which got rounded to 0. Solved by assigning signum of movement when 0 is calculated. --- diff --git a/main.c b/main.c index e5134e9..9f5071e 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/10/27 14:29:26 by ljiriste #+# #+# */ -/* Updated: 2024/04/10 14:03:23 by ljiriste ### ########.fr */ +/* Updated: 2024/04/18 09:54:31 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -168,7 +168,11 @@ void move_view(t_session *s, float move_amount_right, float move_amount_up) int y_pix_change; x_pix_change = round(move_amount_right * s->img.height); + if (x_pix_change == 0) + x_pix_change = (move_amount_right > 0) - (move_amount_right < 0); y_pix_change = -round(move_amount_up * s->img.height); + if (y_pix_change == 0) + y_pix_change = -((move_amount_up > 0) - (move_amount_up < 0)); s->view.window_coord.x += x_pix_change * s->view.pixel_size.x; s->view.window_coord.y -= y_pix_change * s->view.pixel_size.y; move_img(&s->img, x_pix_change, y_pix_change); @@ -227,7 +231,6 @@ void set_default(t_session *s) s->img.width = 1000; s->img.height = 1000; s->img.undersample_max = 5; - init_view(s); return ; } @@ -265,6 +268,7 @@ int parse_args(int argc, char **argv, t_session *s) return (1); ++i; } + init_view(s); return (0); }