-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_handel_bonus.c
115 lines (109 loc) · 2.67 KB
/
key_handel_bonus.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* key_handel_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoumni <mmoumni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/01 15:13:07 by mmoumni #+# #+# */
/* Updated: 2022/01/04 08:24:34 by mmoumni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
#include "keys_bonus.h"
int close_win(t_fdf *param)
{
mlx_destroy_image(param->mlx_ptr, param->img_ptr);
mlx_destroy_window(param->mlx_ptr, param->win_ptr);
free(param->mlx_ptr);
exit(0);
}
int key_zoom(int key, t_fdf *param)
{
if (key == ZOOM_IN)
{
param->zoom += 2;
param->x_pos -= 10;
param->y_pos -= 10;
}
else if (key == ZOOM_OUT)
{
if (param->zoom < 2)
param->zoom = 1;
else
{
param->zoom -= 2;
param->x_pos += 10;
param->y_pos += 10;
}
}
else if (key == ESC)
{
mlx_destroy_image(param->mlx_ptr, param->img_ptr);
mlx_destroy_window(param->mlx_ptr, param->win_ptr);
free(param->mlx_ptr);
exit(0);
}
return (0);
}
int translate_rot_map(int key, t_fdf *param)
{
if (key == UP)
param->y_pos -= 20;
else if (key == DOWN)
param->y_pos += 20;
else if (key == LEFT)
param->x_pos -= 20;
else if (key == RIGHT)
param->x_pos += 20;
else if (key == X)
{
param->rot = 1;
param->alpha += 0.2;
}
else if (key == Y)
{
param->rot = 2;
param->beta += 0.2;
}
else if (key == Z)
{
param->rot = 3;
param->teta += 0.2;
}
return (0);
}
int altitude_and_proj(int key, t_fdf *param)
{
if (key == PLUS_ALT)
{
param->altitude += 2;
}
else if (key == MINUS_ALT)
{
param->altitude -= 2;
}
if (key == THREE_D)
{
param->project = 1;
}
else if (key == TWO_D)
{
param->project = 0;
}
return (0);
}
int event_key(int key, t_fdf *param)
{
key_zoom(key, param);
translate_rot_map(key, param);
altitude_and_proj(key, param);
mlx_clear_window((param)->mlx_ptr, (param)->win_ptr);
mlx_destroy_image(param->mlx_ptr, param->img_ptr);
param->img_ptr = mlx_new_image(param->mlx_ptr, WIDTH, HEIGHT);
ft_draw((param));
mlx_put_image_to_window((param)->mlx_ptr, (param)->win_ptr, \
(param)->img_ptr, 0, 0);
print_info(param);
return (0);
}