First NIT release and new clean mercurial repository
[nit.git] / lib / sdl_nit.h
1 #ifndef __SDL_NIT
2 #define __SDL_NIT
3
4 /* This file is part of NIT ( http://www.nitlanguage.org ).
5 *
6 * Copyright 2006 Jean Privat <jean@pryen.org>
7 *
8 * This file is free software, which comes along with NIT. This software is
9 * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11 * PARTICULAR PURPOSE. You can modify it is you want, provided this header
12 * is kept unaltered, and a notification of the changes is added.
13 * You are allowed to redistribute it and sell it, alone or is a part of
14 * another product.
15 */
16 #include "SDL.h"
17 #include "SDL_image.h"
18
19 /* General*/
20 #define sdl_init(x) \
21 (atexit(SDL_Quit), SDL_Init(SDL_INIT_VIDEO))
22
23 /* Surface */
24 #define sdl_surface_width(x) (((SDL_Surface *)(x))->w)
25 #define sdl_surface_height(x) (((SDL_Surface *)(x))->h)
26
27 /* Video */
28 #define sdl_set_video_mode(x, w, h, d) \
29 (SDL_SetVideoMode(w, h, d, SDL_SWSURFACE | SDL_DOUBLEBUF))
30 #define sdl_set_fullscreen_video_mode(x, w, h, d) \
31 (SDL_SetVideoMode(w, h, d, SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN))
32
33 #define sdl_load_bmp_native(x, c) \
34 (IMG_Load(c))
35
36 #define sdl_blit_surface(s, d) \
37 (SDL_BlitSurface((s), NULL, d, NULL))
38 int sdl_blit_surface_xy(SDL_Surface * s, SDL_Surface * d, int x, int y);
39
40 #define sdl_clear_sruface(s) \
41 (SDL_FillRect((s), NULL, 0))
42
43 #define sdl_show_cursor_0(x) \
44 (SDL_ShowCursor(SDL_QUERY) == SDL_ENABLE)
45 #define sdl_show_cursor_1(x, b) \
46 (SDL_ShowCursor((b) ? SDL_ENABLE : SDL_DISABLE))
47
48 /* WM */
49 #define sdl_grab_0(x) \
50 (SDL_WM_GrabInput(SDL_QUERY) == SDL_GRAB_ON)
51 #define sdl_grab_1(x, b) \
52 (SDL_WM_GrabInput((b) ? SDL_GRAB_ON : SDL_GRAB_OFF))
53
54 /* Event */
55 #define sdl_evt_is_keyboard(x) \
56 ((((SDL_Event*)(x))->type == SDL_KEYDOWN) || ((((SDL_Event*)(x))->type == SDL_KEYUP)))
57 #define sdl_evt_as_keyboard(x) \
58 (sdl_evt_is_keyboard((x)) ? (x) : NULL)
59 #define sdl_evt_is_mouse_button(x) \
60 ((((SDL_Event*)(x))->type == SDL_MOUSEBUTTONDOWN) || ((((SDL_Event*)(x))->type == SDL_MOUSEBUTTONUP)))
61 #define sdl_evt_as_mouse_button(x) \
62 (sdl_evt_is_mouse_button((x)) ? (x) : NULL)
63 #define sdl_evt_is_mouse_motion(x) \
64 (((SDL_Event*)(x))->type == SDL_MOUSEMOTION)
65 #define sdl_evt_as_mouse_motion(x) \
66 (sdl_evt_is_mouse_motion((x)) ? (x) : NULL)
67 #define sdl_evt_is_expose(x) \
68 (((SDL_Event*)(x))->type == SDL_VIDEOEXPOSE)
69 #define sdl_evt_is_quit(x) \
70 (((SDL_Event*)(x))->type == SDL_QUIT)
71
72 #define sdl_keyboard_evt_state(x) \
73 (((SDL_KeyboardEvent*)(x))->state == SDL_PRESSED)
74 #define sdl_mouse_button_evt_state(x) \
75 (((SDL_MouseButtonEvent*)(x))->state == SDL_PRESSED)
76 #define sdl_mouse_button_evt_x(k) \
77 (((SDL_MouseButtonEvent*)(k))->x)
78 #define sdl_mouse_button_evt_y(k) \
79 (((SDL_MouseButtonEvent*)(k))->y)
80 #define sdl_mouse_button_evt_button(k) \
81 (((SDL_MouseButtonEvent*)(k))->button)
82 #define sdl_mouse_evt_x(k) \
83 (((SDL_MouseMotionEvent*)(k))->x)
84 #define sdl_mouse_evt_y(k) \
85 (((SDL_MouseMotionEvent*)(k))->y)
86 #define sdl_mouse_evt_xrel(k) \
87 (((SDL_MouseMotionEvent*)(k))->xrel)
88 #define sdl_mouse_evt_yrel(k) \
89 (((SDL_MouseMotionEvent*)(k))->yrel)
90
91 extern SDL_Event G_sdl_current_event;
92 #define sdl_current_event(x) \
93 (&G_sdl_current_event)
94 #define sdl_poll_next_event(x) \
95 (SDL_PollEvent(&G_sdl_current_event))
96
97 /* Time */
98
99 #define sdl_get_ticks(x) \
100 (SDL_GetTicks())
101 #define sdl_delay(x, i) \
102 (SDL_Delay((i)))
103 #endif