-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinputs_outputs.c
122 lines (112 loc) · 3.21 KB
/
inputs_outputs.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
116
117
118
119
120
121
122
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* inputs_outputs.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acostaz <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/21 16:16:57 by acostaz #+# #+# */
/* Updated: 2019/04/08 14:35:46 by acostaz ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
/*
** Used at beginning of program or to reset most changes to initial values
*/
void clear_setup(t_data *e)
{
e->speed = 5;
e->angle = 0;
e->scale = e->mode ? 150 : 500;
e->zoom = 10 * (WIN_W + WIN_H) / (e->line_nbr + e->col_nbr);
(e->top).x = WIN_W / 2;
(e->top).y = WIN_H / 2;
}
/*
** Ugly necessary function
*/
static void process_colors(t_data *e, int *key)
{
if (key[KEY_PAD_0])
e->display = 0;
if (key[KEY_PAD_1])
e->display = 1;
if (key[KEY_PAD_2])
e->display = 2;
if (key[KEY_PAD_3])
e->display = 3;
if (key[KEY_PAD_4])
e->display = 4;
if (key[KEY_PAD_5])
e->display = 5;
if (key[KEY_PAD_6])
e->display = 6;
if (key[KEY_PAD_7])
e->display = 7;
if (key[KEY_PAD_8])
e->display = 8;
if (key[KEY_PAD_9])
e->display = 9;
if (key[KEY_PAD_MULTIPLY])
e->display = 10;
}
/*
** Deals with every movement-related events
*/
static void process_movement(t_data *e, int *key)
{
if (key[KEY_LEFT] || key[KEY_RIGHT])
e->angle += ((key[KEY_RIGHT] - key[KEY_LEFT]) * 0.1);
if (key[KEY_UP] && e->zoom < 1000000)
{
e->zoom *= 1.1;
if (e->mode == 0)
e->scale *= 1.1;
}
if (key[KEY_DOWN] && e->zoom > 10 * (WIN_W + WIN_H) /
(e->line_nbr + e->col_nbr))
{
e->zoom /= 1.1;
if (e->mode == 0)
e->scale /= 1.1;
}
if (key[KEY_PG_UP] && !(e->mode == 1 && e->scale > 950))
e->scale += 50;
if (key[KEY_PG_DOWN] && !(e->mode == 1 && e->scale < -950))
e->scale -= 50;
if (key[KEY_W] || key[KEY_S])
(e->top).y += (key[KEY_S] - key[KEY_W]) * e->speed;
if (key[KEY_A] || key[KEY_D])
(e->top).x += (key[KEY_D] - key[KEY_A]) * e->speed;
if (key[KEY_PAD_ADD] || (key[KEY_PAD_SUB] && e->speed > 0))
e->speed += (key[KEY_PAD_ADD] - key[KEY_PAD_SUB]);
}
/*
** Main function for events' management
*/
int process_win(void *param)
{
int *key;
t_data *e;
e = (t_data*)param;
key = e->keyboard;
if (key[KEY_ESC])
free_and_exit(e);
if (key[KEY_CLEAR] || (key[KEY_1] && e->mode == 1) ||
(key[KEY_2] && e->mode == 0))
{
if (key[KEY_1] || key[KEY_2])
e->mode = key[KEY_1] ? 0 : 1;
clear_setup(e);
}
e->menu = key[KEY_M];
process_movement(e, key);
process_colors(e, key);
ft_bzero(&(e->image[WIN_W * 400]), WIN_W * (WIN_H - 200) * 4);
print_grid(e, e->col_nbr * e->line_nbr);
print_menu_win(e);
mlx_put_image_to_window(e->mlx, e->win, e->img_addr, 0, 0);
print_borders(e);
print_menu(e);
return (0);
}