-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_event.c
75 lines (68 loc) · 2.6 KB
/
get_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_event.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mpauw <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/05/09 14:35:35 by mpauw #+# #+# */
/* Updated: 2018/06/26 14:44:26 by mpauw ### ########.fr */
/* */
/* ************************************************************************** */
#include "rt.h"
static int loop_hook(t_event *event)
{
if (event->redraw)
{
mlx_put_image_to_window(event->mlx, event->win,
(event->img).img_ptr, 0, 0);
event->redraw = 0;
}
return (1);
}
void init_loop(t_event *event)
{
mlx_key_hook(event->win, &key_pressed, event);
mlx_key_hook(event->menu_win, &key_pressed, event);
mlx_loop_hook(event->mlx, &loop_hook, event);
mlx_loop(event->mlx);
}
void init_image(void *mlx, int width_scr, int height_scr, t_img *img)
{
int bpp;
int size_line;
int endian;
img->img_ptr = mlx_new_image(mlx, width_scr, height_scr);
img->width = width_scr;
img->height = height_scr;
img->img_arr = mlx_get_data_addr(img->img_ptr, &bpp, &size_line, &endian);
img->bpp = bpp;
img->size_line = size_line;
img->size_line_int = size_line / (bpp / 8);
img->endian = endian;
}
t_event get_event(t_scene scene)
{
t_event event;
event.mlx = mlx_init();
event.sub_menu = 0;
event.win = mlx_new_window(event.mlx, scene.width,
scene.height, scene.name);
event.menu_win = mlx_new_window(event.mlx, MENU_WIDTH, MENU_HEIGHT, "Menu");
event.scene = scene;
init_image(event.mlx, scene.width, scene.height, &(event.img));
init_image(event.mlx, MENU_WIDTH, MENU_HEIGHT, &(event.menu_img));
event.t_select = KEY_L;
event.id_select = KEY_0;
event.redraw = 0;
if (!((scene.cam)->p_array = (t_pixel *)malloc(sizeof(t_pixel) *
scene.width * scene.height * scene.max_anti_a *
scene.max_anti_a)) || !((scene.cam)->pixel_set =
(int *)malloc(sizeof(int) * scene.width * scene.height *
scene.max_anti_a * scene.max_anti_a)))
error(1);
ft_bzero((scene.cam)->pixel_set, sizeof(int) * scene.width * scene.height *
scene.max_anti_a * scene.max_anti_a);
(scene.cam)->selected = 1;
return (event);
}