-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey_biding.c
71 lines (66 loc) · 2.13 KB
/
key_biding.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* key_biding.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jfortin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/03/03 17:43:54 by jfortin #+# #+# */
/* Updated: 2016/03/17 18:23:49 by jfortin ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int ft_key_hit(int keycode, t_env *e)
{
if (keycode == PLUS || keycode == MINUS)
e->itm = (keycode == PLUS ? 1 : -1);
if (keycode == ZERO || keycode == NUM_ZERO)
e->reset = 1;
if (keycode == SPACE)
e->bj = 1;
if (keycode == ONE || keycode == TWO)
e->av = (keycode == ONE ? "mandelbrot" : "julia");
if (keycode == THREE || keycode == FOUR)
e->av = (keycode == THREE ? "burning" : "mandelbis");
if (keycode == ONE || keycode == TWO || keycode == THREE || keycode == FOUR)
{
ft_ini_fract(e);
ft_settings(e);
}
if (!e->check)
ft_settings(e);
e->check = 1;
return (0);
}
int ft_key_release(int keycode, t_env *e)
{
if (keycode == ESC)
exit(1);
if (keycode == PLUS || keycode == MINUS)
e->itm = 0;
if (keycode == ZERO || keycode == NUM_ZERO)
e->reset = 0;
if (keycode == SPACE)
e->bj = 0;
return (0);
}
void ft_do_key_action(t_env *e)
{
if (e->itm == -1 && e->iter_max > 10)
e->iter_max -= 10;
if (e->itm == 1)
e->iter_max += 10;
if (e->reset == 1)
ft_ini_fract(e);
}
int ft_core(t_env *e)
{
if (e->check == 0)
return (0);
mlx_destroy_image(e->mlx, e->im);
e->im = mlx_new_image(e->mlx, IM_X, WIN_Y);
ft_do_key_action(e);
ft_print_fract(e);
mlx_put_image_to_window(e->mlx, e->win, e->im, 0, 0);
return (0);
}