-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdl_driver.c
84 lines (76 loc) · 2.56 KB
/
sdl_driver.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sdl_driver.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pvan-erp <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/04/03 21:40:48 by pvan-erp #+# #+# */
/* Updated: 2017/04/03 21:40:49 by pvan-erp ### ########.fr */
/* */
/* ************************************************************************** */
#include "fractol.h"
#include "sdl_handlers.h"
static int is_big_endian(void)
{
const unsigned int end = 1;
return (*(((char *)&end) + 3));
}
void sdl_loop(t_sdl *sdl)
{
SDL_Event e;
draw(sdl);
while (1)
{
while (SDL_PollEvent(&e))
{
switch (e.type)
{
case SDL_QUIT:
return;
case SDL_KEYDOWN:
key_hook(e.key.keysym.sym, sdl);
break;
case SDL_MOUSEBUTTONDOWN:
mouse_hook(e.button.button, e.button.x, e.button.y, sdl);
break;
case SDL_MOUSEWHEEL:
wheel_hook(e.wheel.y, sdl);
break;
case SDL_MOUSEMOTION:
if (!strcmp(((t_frac *)sdl->data)->name, "julia"))
{
motion_hook(e.motion.x, e.motion.y, sdl);
}
break;
}
}
SDL_UpdateWindowSurface(sdl->win);
}
}
void sdl_driver(t_sdl *sdl)
{
char *wname;
wname = malloc(strlen(((t_frac *)sdl->data)->name) + 11);
strcpy(wname, "fractol - ");
strcat(wname, ((t_frac *)sdl->data)->name);
//wname = strjoin("fractol - ", ((t_frac *)sdl->data)->name);
SDL_Init(SDL_INIT_VIDEO);
//sdl->id = sdl_init();
sdl->win = SDL_CreateWindow(wname, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, sdl->wsize.x, sdl->wsize.y, 0);
free(wname);
//strdel(&wname);
sdl->img.id = SDL_GetWindowSurface(sdl->win);
sdl->img.bppx = 32;
sdl->img.lsize = sdl->wsize.y * sdl->img.bppx / 4;
sdl->img.endian = is_big_endian();
//sdl->img.start = sdl_get_data_addr(sdl->img.id, &sdl->img.bppx, &sdl->img.lsize, &sdl->img.endian);
// sdl_mouse_hook(sdl->win, mouse_hook, &sdl);
// sdl_key_hook(sdl->win, key_hook, &sdl);
// sdl_expose_hook(sdl->win, expose_hook, &sdl);
if (!strcmp(((t_frac *)sdl->data)->name, "julia"))
{
//sdl_hook(sdl->win, 6, 0, motion_hook, &sdl);
}
sdl_loop(sdl);
}