3
3
/* ::: :::::::: */
4
4
/* window_management.c :+: :+: :+: */
5
5
/* +:+ +:+ +:+ */
6
- /* By: ebabaogl <ebabaogl @student.42kocaeli.co +#+ +:+ +#+ */
6
+ /* By: obastug <obastug @student.42.fr> +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2025/01/02 15:09:01 by ebabaogl #+# #+# */
9
- /* Updated: 2025/01/02 15:37:30 by ebabaogl ### ########.fr */
9
+ /* Updated: 2025/01/04 16:36:14 by obastug ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
13
13
#include <stdlib.h>
14
14
#include "mlx.h"
15
15
#include "window.h"
16
+ #include "fdf.h"
16
17
17
- static int close_win (void * param )
18
+ void reset_camera (t_vars * vars )
19
+ {
20
+ int width_distance ;
21
+ int height_distance ;
22
+
23
+ width_distance = (PADDED_WIDTH / 2 ) / (vars -> line_count / 2 );
24
+ height_distance = (PADDED_HEIGHT / 2 ) / (vars -> line_len / 2 );
25
+ vars -> a_coef = 0 ;
26
+ vars -> d_coef = 0 ;
27
+ vars -> d_coef = 0 ;
28
+ vars -> s_coef = 0 ;
29
+ vars -> map_x = 0 ;
30
+ vars -> map_y = 0 ;
31
+ vars -> height = 1 ;
32
+ if (width_distance > height_distance )
33
+ vars -> distance = height_distance ;
34
+ else
35
+ vars -> distance = width_distance ;
36
+ }
37
+
38
+ int close_win (void * param )
18
39
{
19
40
t_mlx * mlx ;
20
41
@@ -25,10 +46,19 @@ static int close_win(void *param)
25
46
return (0 );
26
47
}
27
48
28
- static int esc_handler (int keycode , void * param )
49
+ int key_handler (int keycode , void * param )
29
50
{
51
+ t_vars * vars ;
52
+
53
+ vars = (t_vars * )param ;
54
+ (void )keycode ;
55
+ (void )vars ;
30
56
if (keycode == ESC_KEY )
31
- close_win (param );
57
+ {
58
+ close_win (vars -> mlx );
59
+ return (0 );
60
+ }
61
+ render_map (vars );
32
62
return (0 );
33
63
}
34
64
@@ -40,10 +70,5 @@ int init_win(t_mlx *mlx)
40
70
mlx -> win_ptr = mlx_new_window (mlx -> mlx_ptr , WIN_WIDTH , WIN_HEIGHT , "FdF!!1!!!1" );
41
71
if (!mlx -> win_ptr )
42
72
return (free (mlx -> mlx_ptr ), -1 );
43
- mlx_hook (mlx -> win_ptr , ON_DESTROY , 0 , close_win , mlx );
44
- mlx_key_hook (mlx -> win_ptr , esc_handler , mlx );
45
- mlx_loop (mlx -> mlx_ptr );
46
- mlx_destroy_display (mlx -> mlx_ptr );
47
- free (mlx -> mlx_ptr );
48
73
return (0 );
49
74
}
0 commit comments