-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_event.c
106 lines (101 loc) · 2.97 KB
/
ft_event.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_event.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nhamid <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/17 20:12:43 by nhamid #+# #+# */
/* Updated: 2019/03/18 11:26:14 by nhamid ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractal.h"
void ft_destroy(t_params *params)
{
mlx_destroy_image(params->mlx_ptr, params->img_ptr);
mlx_clear_window(params->mlx_ptr, params->win_ptr);
params->img_ptr = mlx_new_image(params->mlx_ptr, 700, 500);
params->data = (int *)mlx_get_data_addr(params->img_ptr,
¶ms->bpp, ¶ms->s_l, ¶ms->endian);
if (params->type == 1)
ft_pthread_julia(params);
else if (params->type == 0)
ft_pthread_mandel(params);
else if (params->type == 2)
{
params->var = -2;
ft_pthread_mandel(params);
}
else if (params->type == 3)
ft_pthread_ship(params);
mlx_put_image_to_window(params->mlx_ptr,
params->win_ptr, params->img_ptr, 0, 0);
}
void key_event(int keycode, t_params *params)
{
if (keycode == 126)
params->fy -= (4 / params->zoom);
else if (keycode == 125)
params->fy += (4 / params->zoom);
else if (keycode == 124)
params->fx += (4 / params->zoom);
else if (keycode == 123)
params->fx -= (4 / params->zoom);
else if (keycode == 69)
params->it += 2;
else if (keycode == 78)
if (params->it != 0)
params->it -= 1;
ft_destroy(params);
}
void change_fract(int keycode, t_params *params)
{
if (keycode == 83)
{
params->type = 0;
params->var = 2;
ft_destroy(params);
}
else if (keycode == 84)
{
params->type = 1;
params->ft = 1;
ft_destroy(params);
}
else if (keycode == 85)
{
params->type = 2;
params->var = -2;
ft_destroy(params);
}
else if (keycode == 86)
{
params->type = 3;
ft_destroy(params);
}
}
int key_press(int keycode, t_params *params)
{
if ((keycode == 126 || keycode == 125 || keycode == 123 ||
keycode == 124 || keycode == 69 || keycode == 78) && params->ft != 1)
key_event(keycode, params);
else if (keycode == 8 && params->ft != 1)
{
params->color = rand() % (0xffffff - 150);
ft_destroy(params);
}
else if (keycode == 83 || keycode == 84
|| keycode == 85 || keycode == 86)
{
params->ft = 0;
init_params(params);
change_fract(keycode, params);
}
else if (keycode == 53)
{
mlx_destroy_image(params->mlx_ptr, params->img_ptr);
mlx_destroy_window(params->mlx_ptr, params->win_ptr);
exit(0);
}
return (0);
}