-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwin_init.c
More file actions
78 lines (72 loc) · 2.2 KB
/
win_init.c
File metadata and controls
78 lines (72 loc) · 2.2 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* win_init.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbreton <dbreton@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/12/19 19:15:07 by dbreton #+# #+# */
/* Updated: 2015/12/22 18:04:00 by dbreton ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
void win_reset(t_mlx *s)
{
s->zoom = 500;
s->c_r = -0.5;
s->c_i = 0.5;
s->x_start = WIN_MAX_X / 2;
s->y_start = WIN_MAX_Y / 2;
s->max_ite = 10;
}
int expose_hook(t_mlx *s)
{
if (s->img != NULL)
mlx_destroy_image(s->mlx, s->img);
if ((s->img = mlx_new_image(s->mlx, WIN_MAX_X, WIN_MAX_Y)) != NULL)
{
s->max_ite = round(sqrt(s->zoom));
if (s->type == 1)
mandle_set(s);
else if (s->type == 2)
julia_set(s);
else if (s->type == 3)
sierp_carp_set(s);
mlx_clear_window(s->mlx, s->win);
mlx_put_image_to_window(s->mlx, s->win, s->img, 0, 0);
}
return (0);
}
int mouse_hook(int btn, int x, int y, t_mlx *s)
{
mouse_zoom_handler(btn, x, y, s);
expose_hook(s);
return (0);
}
int key_hook(int key, t_mlx *s)
{
key_win_handler(key, s);
frac_select(key, s);
expose_hook(s);
return (0);
}
void win_init(t_mlx s)
{
if ((s.mlx = mlx_init()) != NULL)
{
s.win = mlx_new_window(s.mlx, WIN_MAX_X, WIN_MAX_Y, "42 Fractol");
s.img = mlx_new_image(s.mlx, WIN_MAX_X, WIN_MAX_Y);
if (s.win != NULL && s.img != NULL)
{
win_reset(&s);
s.color = 1;
s.f_lock = 1;
mlx_expose_hook(s.win, &expose_hook, &s);
mlx_key_hook(s.win, &key_hook, &s);
mlx_mouse_hook(s.win, &mouse_hook, &s);
mlx_hook(s.win, MOTION_NOTIFY, PTR_MOTION_MASK,
&ptr_motion_hook, &s);
mlx_loop(s.mlx);
}
}
}