-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.c
95 lines (90 loc) · 3.02 KB
/
hooks.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* hooks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mhedeon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/08/07 16:24:47 by mhedeon #+# #+# */
/* Updated: 2018/08/20 21:22:43 by mhedeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
int deal_key_mm(int key, t_mlx *mlx)
{
if (key == KEY_ESC)
{
destroy_window(mlx);
exit_mm();
}
return (1);
}
int deal_mouse_mm(int key, int x, int y)
{
if (key == MOUSE_CLICK)
{
if ((x > 175 && x < 338) && (y > 251 && y < 314))
window("Tricorn");
else if ((x > 175 && x < 338) && (y > 337 && y < 399))
window("Bocal");
else if ((x > 175 && x < 338) && (y > 424 && y < 487))
window("Mushroom");
else if ((x > 175 && x < 338) && (y > 510 && y < 572))
window("Perpendicular Mandelbrot");
else if ((x > 461 && x < 624) && (y > 251 && y < 314))
window("Julia set");
else if ((x > 461 && x < 624) && (y > 337 && y < 399))
window("Mandelbrot set");
else if ((x > 461 && x < 624) && (y > 424 && y < 487))
window("Burning ship");
else if ((x > 461 && x < 624) && (y > 510 && y < 572))
window("Black hole");
}
return (1);
}
int deal_key(int key, t_mlx *mlx)
{
if (key == KEY_PLUS)
mlx->fract->max_itter += 100;
else if (key == KEY_MINUS)
mlx->fract->max_itter = (mlx->fract->max_itter - 100) < 60 ?
mlx->fract->max_itter : mlx->fract->max_itter - 100;
else if (key == KEY_SPACE)
mlx->fract->j_move *= -1;
else if (key == KEY_H)
mlx->help *= -1;
else if (key == KEY_R)
init_fract(mlx);
else if (key == ARROW_RIGHT)
mlx->fract->color = (mlx->fract->color + 1) % 7;
else if (key == ARROW_LEFT)
mlx->fract->color = mlx->fract->color == 0 ?
6 : mlx->fract->color - 1;
else
move_fract(key, mlx->fract);
ft_bzero((void *)mlx->img->img, mlx->img->size * WIN_HEIGHT);
draw_fract(mlx);
if (key == KEY_ESC)
destroy_window(mlx);
return (1);
}
int deal_mouse(int key, int x, int y, t_mlx *mlx)
{
if (key == WHEEL_DOWN)
{
if (mlx->fract->delta_re < mlx->fract->ds_re ||
mlx->fract->delta_im < mlx->fract->ds_im)
mlx->fract->max_itter -= 1;
good_zoom(mlx->fract, 0.93, x, WIN_HEIGHT - y);
}
else if (key == WHEEL_UP)
{
if (mlx->fract->delta_re < mlx->fract->ds_re ||
mlx->fract->delta_im < mlx->fract->ds_im)
mlx->fract->max_itter += 1;
good_zoom(mlx->fract, 1.07, x, WIN_HEIGHT - y);
}
ft_bzero((void *)mlx->img->img, mlx->img->size * WIN_HEIGHT);
draw_fract(mlx);
return (1);
}