-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrubysdl.h
141 lines (121 loc) · 4.38 KB
/
rubysdl.h
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
Ruby/SDL Ruby extension library for SDL
Copyright (C) 2001-2007 Ohbayashi Ippei
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <SDL.h>
#define RUBY_DONT_SUBST
#include <ruby.h>
#include <stdio.h>
/* Macros */
#define GLOBAL_DEFINE_GET_STRUCT(struct_name, fun, klass, klassstr) \
struct_name* fun(VALUE obj) \
{ \
struct_name* st; \
\
if(!rb_obj_is_kind_of(obj, klass)){ \
rb_raise(rb_eTypeError, "wrong argument type %s (expected " klassstr ")", \
rb_obj_classname(obj)); \
} \
Data_Get_Struct(obj, struct_name, st); \
return st; \
}
#define DEFINE_GET_STRUCT(struct_name, fun, klass, klassstr) \
static GLOBAL_DEFINE_GET_STRUCT(struct_name, fun, klass, klassstr)
#define SetRect(Rect,X,Y,W,H) \
do{ \
Rect.x=NUM2INT(X); \
Rect.y=NUM2INT(Y); \
Rect.w=NUM2INT(W); \
Rect.h=NUM2INT(H); \
}while(0) \
#ifdef ENABLE_M17N
#define ExportStringValueToEnc(v,enc) \
do { \
SafeStringValue(v); \
(v) = rb_str_export_to_enc((v),(enc)); \
StringValueCStr(v); \
} while (0)
#else
#define ExportStringValueToEnc(v,enc) \
do { \
SafeStringValue(v); \
StringValueCStr(v); \
} while (0)
#endif
#ifdef ENABLE_M17N_FILESYSTEM
#define ExportFilenameStringValue(v) \
ExportStringValueToEnc(v,rb_filesystem_encoding())
#else
#define ExportFilenameStringValue(v) \
do { \
SafeStringValue(v); \
StringValueCStr(v); \
} while(0)
#endif
#define INT2BOOL(x) ((x)?Qtrue:Qfalse)
#ifdef DEF_GLOBAL
#define GLOBAL(typ, var, val) typ var = val
#else
#define GLOBAL(typ, var, val) extern typ var
#endif
/* Global variables */
#define eSDLError rubysdl_eSDLError
GLOBAL(VALUE, eSDLError, Qnil);
#ifdef ENABLE_M17N
#define ENC_STR_NEW2(str, enc) rb_enc_str_new((str), strlen((str)), (enc))
#include "ruby/encoding.h"
#define utf8_enc rubysdl_utf8_enc
#define eucjp_enc rubysdl_eucjp_enc
#define iso2022jp_enc rubysdl_iso2022jp_enc
#define sjis_enc rubysdl_sjis_enc
GLOBAL(rb_encoding*, utf8_enc, NULL);
GLOBAL(rb_encoding*, eucjp_enc, NULL);
GLOBAL(rb_encoding*, iso2022jp_enc, NULL);
GLOBAL(rb_encoding*, sjis_enc, NULL);
#endif
/* Global functions */
#define VALUE2COLOR rubysdl_VALUE2COLOR
Uint32 VALUE2COLOR(VALUE color,SDL_PixelFormat *format);
void rubysdl_putPixel(SDL_Surface *surface, Sint16 x, Sint16 y, Uint32 color);
Uint32 rubysdl_getPixel(SDL_Surface *surface, Sint16 x, Sint16 y);
int rubysdl_is_quit(void);
SDL_RWops* rubysdl_RWops_from_ruby_obj(VALUE obj);
#define Surface_create rubysdl_Surface_create
VALUE Surface_create(SDL_Surface* surface);
#define Get_SDL_Surface rubysdl_Get_SDL_Surface
SDL_Surface* Get_SDL_Surface(VALUE obj);
#ifdef HAVE_SDLSKK
#include <SDL_ttf.h>
#define Get_TTF_Font rubysdl_Get_TTF_Font
TTF_Font* Get_TTF_Font(VALUE obj);
#endif
/* declaration of initialize functions */
VALUE rubysdl_init_video(VALUE mSDL);
void rubysdl_init_sge(VALUE mSDL, VALUE cSurface);
void rubysdl_init_GL(VALUE mSDL);
void rubysdl_init_image(VALUE mSDL, VALUE cSurface);
void rubysdl_init_Event(VALUE mSDL);
void rubysdl_init_Key(VALUE mSDL);
void rubysdl_init_Mouse(VALUE mSDL);
void rubysdl_init_Joystick(VALUE mSDL);
void rubysdl_init_CD(VALUE mSDL);
void rubysdl_init_time(VALUE mSDL);
void rubysdl_init_WM(VALUE mSDL);
void rubysdl_init_Kanji(VALUE mSDL);
void rubysdl_init_TTF(VALUE mSDL);
void rubysdl_quit_TTF(void);
void rubysdl_init_Mixer(VALUE mSDL);
void rubysdl_quit_Mixer(void);
void rubysdl_init_MPEG(VALUE mSDL);
void rubysdl_init_SKK(VALUE mSDL);