-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfractol_key.c
80 lines (74 loc) · 2.3 KB
/
fractol_key.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fractol_key.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpeters <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/06 22:18:21 by tpeters #+# #+# */
/* Updated: 2022/11/06 22:32:27 by tpeters ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
static void arrow_key_press(int kc, t_vars *vars)
{
double tmp;
if (kc == XK_RIGHT || kc == XK_LEFT)
{
tmp = (vars->x_len / WIDTH) * MOVE * (1 - (kc == XK_LEFT) * 2);
vars->xmin += tmp;
vars->xmax += tmp;
move_array(vars, -MOVE + 2 * MOVE * (kc == XK_LEFT), 0);
}
if (kc == XK_UP || kc == XK_DOWN)
{
tmp = (vars->y_len / HEIGHT) * MOVE * (1 - ((kc == XK_DOWN) * 2));
vars->ymin += tmp;
vars->ymax += tmp;
move_array(vars, 0, MOVE - 2 * MOVE * (kc == XK_DOWN));
}
calc_len(vars);
}
static void toggle_rects(t_vars *vars)
{
vars->show_rects = !vars->show_rects;
init_depth_array(vars->depths);
}
static int second_key_press(int kc, struct s_for_each_pixel *s)
{
if (kc == XK_M)
{
s->f = mandel;
s->vars->is_newton = 0;
init_depth_array(s->vars->depths);
}
if (kc == XK_J)
{
s->f = julia;
s->vars->is_newton = 0;
init_depth_array(s->vars->depths);
}
if (kc == XK_N)
{
s->f = newton;
s->vars->is_newton = 1;
init_depth_array(s->vars->depths);
}
return (0);
}
int key_press(int kc, struct s_for_each_pixel *s)
{
if (kc == XK_ESCAPE)
quit(s->vars);
if (kc == XK_LEFT || kc == XK_DOWN || kc == XK_UP || kc == XK_RIGHT)
arrow_key_press(kc, s->vars);
if (kc == XK_P)
s->vars->get_mouse_move = !s->vars->get_mouse_move;
if (kc == XK_L)
inc_max_dep(s->vars);
if (kc == XK_K)
dec_max_dep(s->vars);
if (kc == XK_R)
toggle_rects(s->vars);
return (second_key_press(kc, s));
}