sdl2_ffi 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/README.md +31 -17
  4. data/bin/yard +16 -0
  5. data/bin/yardoc +16 -0
  6. data/bin/yri +16 -0
  7. data/graph +566 -0
  8. data/lib/enumerable_constants.rb +82 -0
  9. data/lib/sdl2.rb +74 -117
  10. data/lib/sdl2/audio.rb +10 -7
  11. data/lib/sdl2/clipboard.rb +3 -3
  12. data/lib/sdl2/events.rb +228 -168
  13. data/lib/sdl2/gem_version.rb +1 -1
  14. data/lib/sdl2/haptic.rb +366 -55
  15. data/lib/sdl2/hints.rb +36 -24
  16. data/lib/sdl2/image.rb +4 -10
  17. data/lib/sdl2/init.rb +21 -31
  18. data/lib/sdl2/joystick.rb +15 -12
  19. data/lib/sdl2/keycode.rb +261 -261
  20. data/lib/sdl2/library.rb +96 -0
  21. data/lib/sdl2/mouse.rb +22 -17
  22. data/lib/sdl2/pixel_format.rb +2 -1
  23. data/lib/sdl2/pixels.rb +114 -161
  24. data/lib/sdl2/rect.rb +14 -10
  25. data/lib/sdl2/render.rb +29 -13
  26. data/lib/sdl2/renderer.rb +9 -2
  27. data/lib/sdl2/rwops.rb +11 -7
  28. data/lib/sdl2/scancode.rb +246 -245
  29. data/lib/sdl2/stdinc.rb +213 -0
  30. data/lib/sdl2/surface.rb +23 -7
  31. data/lib/sdl2/ttf.rb +23 -19
  32. data/lib/sdl2/version.rb +8 -2
  33. data/lib/sdl2/video.rb +64 -73
  34. data/lib/sdl2/window.rb +143 -36
  35. data/lib/sdl2_ffi.rb +2 -1
  36. data/sdl2_ffi.gemspec +3 -1
  37. data/test/fixtures/an_example.png +0 -0
  38. data/test/fixtures/background.bmp +0 -0
  39. data/test/fixtures/hello.bmp +0 -0
  40. data/test/functional/examples/test_lazy_foo_examples.rb +123 -0
  41. data/test/functional/examples/test_readme_examples.rb +15 -0
  42. data/test/unit/sdl2/test_haptic.rb +17 -0
  43. data/test/unit/sdl2/test_hints.rb +9 -9
  44. data/test/unit/sdl2/test_init.rb +8 -8
  45. data/test/unit/sdl2/test_log.rb +1 -1
  46. data/test/unit/sdl2/test_pixel_format.rb +3 -1
  47. data/test/unit/sdl2/test_video.rb +3 -3
  48. data/test/unit/sdl2/test_window.rb +4 -4
  49. data/test/unit/test_scratch.rb +2 -2
  50. metadata +37 -16
@@ -0,0 +1,213 @@
1
+ # TODO: Review stdinc stub.
2
+
3
+ require 'enumerable_constants'
4
+ require 'sdl2/library'
5
+
6
+ module SDL2
7
+
8
+ # Define a four character code as a Uint32
9
+ #MACRO: SDL_FOURCC(A, B, C, D) \
10
+ # ((SDL_static_cast(Uint32, SDL_static_cast(Uint8, (A))) << 0) | \
11
+ # (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (B))) << 8) | \
12
+ # (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (C))) << 16) | \
13
+ # (SDL_static_cast(Uint32, SDL_static_cast(Uint8, (D))) << 24))
14
+ def self.fourcc(*args)
15
+ bit_cnt = 0
16
+ result = 0
17
+ args.each do |arg|
18
+ arg = arg.codepoints[0] if arg.kind_of? String
19
+ result = result | (arg << bit_cnt)
20
+ bit_cnt += 8
21
+ end
22
+ return result
23
+ end
24
+
25
+
26
+ # These are for internal use mostly, they test the return result
27
+ # of a function that can return an error. They are designed to
28
+ # return TRUE if there is NOT_AN_ERROR
29
+
30
+ #Filter Proc, True when arg equals zero
31
+ TRUE_WHEN_ZERO = Proc.new do |result|
32
+ # Handles both Negative and Positive error values.
33
+ result == 0
34
+ end
35
+
36
+ TRUE_WHEN_NOT_ZERO = Proc.new do |result|
37
+ result != 0
38
+ end
39
+
40
+ # Filter Proc, True when arg not null?
41
+ TRUE_WHEN_NOT_NULL = Proc.new do |result|
42
+ # Anything but nil/null is considered valid.
43
+ (!result.null?)
44
+ end
45
+
46
+ TRUE_WHEN_TRUE = Proc.new do |result|
47
+ result == true
48
+ end
49
+
50
+ # NOTE: None of the SDL Memory Macros/Externals
51
+
52
+ # TODO: Review importing SDL's Memory management and ICONV routines?
53
+ # #define SDL_stack_alloc(type, count) (type*)SDL_malloc(sizeof(type)*(count))
54
+ # #define SDL_stack_free(data) SDL_free(data)
55
+ # #endif
56
+ #
57
+ # extern DECLSPEC void *SDLCALL SDL_malloc(size_t size);
58
+ # extern DECLSPEC void *SDLCALL SDL_calloc(size_t nmemb, size_t size);
59
+ # extern DECLSPEC void *SDLCALL SDL_realloc(void *mem, size_t size);
60
+ # extern DECLSPEC void SDLCALL SDL_free(void *mem);
61
+ #
62
+ # extern DECLSPEC char *SDLCALL SDL_getenv(const char *name);
63
+ # extern DECLSPEC int SDLCALL SDL_setenv(const char *name, const char *value, int overwrite);
64
+ #
65
+ # extern DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *));
66
+ #
67
+ # extern DECLSPEC int SDLCALL SDL_abs(int x);
68
+ #
69
+ # /* !!! F!IXME: these have side effects. You probably shouldn't use them. */
70
+ # /* !!! F!IXME: Maybe we do forceinline functions of SDL_mini, SDL_minf, etc? */
71
+ # #define SDL_min(x, y) (((x) < (y)) ? (x) : (y))
72
+ # #define SDL_max(x, y) (((x) > (y)) ? (x) : (y))
73
+ #
74
+ # extern DECLSPEC int SDLCALL SDL_isdigit(int x);
75
+ # extern DECLSPEC int SDLCALL SDL_isspace(int x);
76
+ # extern DECLSPEC int SDLCALL SDL_toupper(int x);
77
+ # extern DECLSPEC int SDLCALL SDL_tolower(int x);
78
+ #
79
+ # extern DECLSPEC void *SDLCALL SDL_memset(void *dst, int c, size_t len);
80
+ #
81
+ # #define SDL_zero(x) SDL_memset(&(x), 0, sizeof((x)))
82
+ # #define SDL_zerop(x) SDL_memset((x), 0, sizeof(*(x)))
83
+ #
84
+ # /* Note that memset() is a byte assignment and this is a 32-bit assignment, so they're not directly equivalent. */
85
+ # SDL_FORCE_INLINE void SDL_memset4(void *dst, int val, size_t dwords)
86
+ # {
87
+ # #if defined(__GNUC__) && defined(i386)
88
+ # int u0, u1, u2;
89
+ # __asm__ __volatile__ (
90
+ # "cld \n\t"
91
+ # "rep ; stosl \n\t"
92
+ # : "=&D" (u0), "=&a" (u1), "=&c" (u2)
93
+ # : "0" (dst), "1" (val), "2" (SDL_static_cast(Uint32, dwords))
94
+ # : "memory"
95
+ # );
96
+ # #else
97
+ # size_t _n = (dwords + 3) / 4;
98
+ # Uint32 *_p = SDL_static_cast(Uint32 *, dst);
99
+ # Uint32 _val = (val);
100
+ # if (dwords == 0)
101
+ # return;
102
+ # switch (dwords % 4)
103
+ # {
104
+ # case 0: do { *_p++ = _val;
105
+ # case 3: *_p++ = _val;
106
+ # case 2: *_p++ = _val;
107
+ # case 1: *_p++ = _val;
108
+ # } while ( --_n );
109
+ # }
110
+ # #endif
111
+ # }
112
+ #
113
+ #
114
+ # extern DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len);
115
+ #
116
+ # SDL_FORCE_INLINE void *SDL_memcpy4(void *dst, const void *src, size_t dwords)
117
+ # {
118
+ # return SDL_memcpy(dst, src, dwords * 4);
119
+ # }
120
+ #
121
+ # extern DECLSPEC void *SDLCALL SDL_memmove(void *dst, const void *src, size_t len);
122
+ # extern DECLSPEC int SDLCALL SDL_memcmp(const void *s1, const void *s2, size_t len);
123
+ #
124
+ # extern DECLSPEC size_t SDLCALL SDL_wcslen(const wchar_t *wstr);
125
+ # extern DECLSPEC size_t SDLCALL SDL_wcslcpy(wchar_t *dst, const wchar_t *src, size_t maxlen);
126
+ # extern DECLSPEC size_t SDLCALL SDL_wcslcat(wchar_t *dst, const wchar_t *src, size_t maxlen);
127
+ #
128
+ # extern DECLSPEC size_t SDLCALL SDL_strlen(const char *str);
129
+ # extern DECLSPEC size_t SDLCALL SDL_strlcpy(char *dst, const char *src, size_t maxlen);
130
+ # extern DECLSPEC size_t SDLCALL SDL_utf8strlcpy(char *dst, const char *src, size_t dst_bytes);
131
+ # extern DECLSPEC size_t SDLCALL SDL_strlcat(char *dst, const char *src, size_t maxlen);
132
+ # extern DECLSPEC char *SDLCALL SDL_strdup(const char *str);
133
+ # extern DECLSPEC char *SDLCALL SDL_strrev(char *str);
134
+ # extern DECLSPEC char *SDLCALL SDL_strupr(char *str);
135
+ # extern DECLSPEC char *SDLCALL SDL_strlwr(char *str);
136
+ # extern DECLSPEC char *SDLCALL SDL_strchr(const char *str, int c);
137
+ # extern DECLSPEC char *SDLCALL SDL_strrchr(const char *str, int c);
138
+ # extern DECLSPEC char *SDLCALL SDL_strstr(const char *haystack, const char *needle);
139
+ #
140
+ # extern DECLSPEC char *SDLCALL SDL_itoa(int value, char *str, int radix);
141
+ # extern DECLSPEC char *SDLCALL SDL_uitoa(unsigned int value, char *str, int radix);
142
+ # extern DECLSPEC char *SDLCALL SDL_ltoa(long value, char *str, int radix);
143
+ # extern DECLSPEC char *SDLCALL SDL_ultoa(unsigned long value, char *str, int radix);
144
+ # extern DECLSPEC char *SDLCALL SDL_lltoa(Sint64 value, char *str, int radix);
145
+ # extern DECLSPEC char *SDLCALL SDL_ulltoa(Uint64 value, char *str, int radix);
146
+ #
147
+ # extern DECLSPEC int SDLCALL SDL_atoi(const char *str);
148
+ # extern DECLSPEC double SDLCALL SDL_atof(const char *str);
149
+ # extern DECLSPEC long SDLCALL SDL_strtol(const char *str, char **endp, int base);
150
+ # extern DECLSPEC unsigned long SDLCALL SDL_strtoul(const char *str, char **endp, int base);
151
+ # extern DECLSPEC Sint64 SDLCALL SDL_strtoll(const char *str, char **endp, int base);
152
+ # extern DECLSPEC Uint64 SDLCALL SDL_strtoull(const char *str, char **endp, int base);
153
+ # extern DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp);
154
+ #
155
+ # extern DECLSPEC int SDLCALL SDL_strcmp(const char *str1, const char *str2);
156
+ # extern DECLSPEC int SDLCALL SDL_strncmp(const char *str1, const char *str2, size_t maxlen);
157
+ # extern DECLSPEC int SDLCALL SDL_strcasecmp(const char *str1, const char *str2);
158
+ # extern DECLSPEC int SDLCALL SDL_strncasecmp(const char *str1, const char *str2, size_t len);
159
+ #
160
+ # extern DECLSPEC int SDLCALL SDL_sscanf(const char *text, const char *fmt, ...);
161
+ # extern DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt, ...);
162
+ # extern DECLSPEC int SDLCALL SDL_vsnprintf(char *text, size_t maxlen, const char *fmt, va_list ap);
163
+ #
164
+ # #ifndef HAVE_M_PI
165
+ # #ifndef M_PI
166
+ # #define M_PI 3.14159265358979323846264338327950288 /* pi */
167
+ # #endif
168
+ # #endif
169
+ #
170
+ # extern DECLSPEC double SDLCALL SDL_atan(double x);
171
+ # extern DECLSPEC double SDLCALL SDL_atan2(double x, double y);
172
+ # extern DECLSPEC double SDLCALL SDL_ceil(double x);
173
+ # extern DECLSPEC double SDLCALL SDL_copysign(double x, double y);
174
+ # extern DECLSPEC double SDLCALL SDL_cos(double x);
175
+ # extern DECLSPEC float SDLCALL SDL_cosf(float x);
176
+ # extern DECLSPEC double SDLCALL SDL_fabs(double x);
177
+ # extern DECLSPEC double SDLCALL SDL_floor(double x);
178
+ # extern DECLSPEC double SDLCALL SDL_log(double x);
179
+ # extern DECLSPEC double SDLCALL SDL_pow(double x, double y);
180
+ # extern DECLSPEC double SDLCALL SDL_scalbn(double x, int n);
181
+ # extern DECLSPEC double SDLCALL SDL_sin(double x);
182
+ # extern DECLSPEC float SDLCALL SDL_sinf(float x);
183
+ # extern DECLSPEC double SDLCALL SDL_sqrt(double x);
184
+ #
185
+ # /* The SDL implementation of iconv() returns these error codes */
186
+ # #define SDL_ICONV_ERROR (size_t)-1
187
+ # #define SDL_ICONV_E2BIG (size_t)-2
188
+ # #define SDL_ICONV_EILSEQ (size_t)-3
189
+ # #define SDL_ICONV_EINVAL (size_t)-4
190
+ #
191
+ # /* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
192
+ # typedef struct _SDL_iconv_t *SDL_iconv_t;
193
+ # extern DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
194
+ # const char *fromcode);
195
+ # extern DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
196
+ # extern DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
197
+ # size_t * inbytesleft, char **outbuf,
198
+ # size_t * outbytesleft);
199
+ # /**
200
+ # * This function converts a string between encodings in one pass, returning a
201
+ # * string that must be freed with SDL_free() or NULL on error.
202
+ # */
203
+ # extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode,
204
+ # const char *fromcode,
205
+ # const char *inbuf,
206
+ # size_t inbytesleft);
207
+ # #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1)
208
+ # #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
209
+ # #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1)
210
+
211
+
212
+
213
+ end
@@ -3,7 +3,6 @@ require 'sdl2/rwops'
3
3
  require 'sdl2/pixels'
4
4
  require 'sdl2/rect'
5
5
  require 'sdl2/palette'
6
- require 'yinum'
7
6
 
8
7
  #require 'sdl2/pixel_format'
9
8
 
@@ -14,7 +13,7 @@ module SDL2
14
13
  #
15
14
  #\note This structure should be treated as read-only, except for \c pixels,
16
15
  # which, if not NULL, contains the raw pixel data for the surface.
17
- class Surface < FFI::Struct
16
+ class Surface < Struct
18
17
 
19
18
  private :[]
20
19
 
@@ -29,6 +28,8 @@ module SDL2
29
28
  :clip_rect, Rect,
30
29
  :map, :pointer,
31
30
  :refcount, :int
31
+
32
+ member_readers(*members)
32
33
 
33
34
  [:flags, :format, :w, :h, :pixels, :userdata, :locked, :lock_data, :clip_rect, :map, :refcount].each do |field|
34
35
  define_method field do
@@ -103,12 +104,14 @@ module SDL2
103
104
  self[:flags] & RLEACCEL != 0
104
105
  end
105
106
 
106
- def blit_from(src, src_rect, dst_rect)
107
- SDL2.blit!(src, src_rect, self, dst_rect)
107
+ # Blit from source to this surface
108
+ def blit_in(src, src_rect = nil, dst_rect = nil)
109
+ SDL2.blit_surface!(src, src_rect, self, dst_rect)
108
110
  end
109
111
 
110
- def blit_to(src_rect, dst, dst_rect)
111
- SDL2.blit!(self, src_rect, dst, dst_rect)
112
+ # Blit from this surface to dest
113
+ def blit_out(dest, dest_rect = nil, src_rect = nil)
114
+ SDL2.blit_surface!(self, src_rect, dest, dest_rect)
112
115
  end
113
116
 
114
117
  def set_rle(flag)
@@ -126,6 +129,11 @@ module SDL2
126
129
  SDL2.get_color_key!(self, key_s)
127
130
  return key_s[:value]
128
131
  end
132
+
133
+ # Convert existing surface into this surface's format
134
+ def convert(surface, flags = 0)
135
+ SDL2.convert_surface!(surface, self.format, flags)
136
+ end
129
137
  end
130
138
 
131
139
  callback :blit, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
@@ -142,6 +150,8 @@ module SDL2
142
150
  SDL2.load_bmp_rw(RWops.from_file(file, 'rb'), 1)
143
151
  end
144
152
 
153
+ returns_error(:load_bmp,TRUE_WHEN_NOT_NULL)
154
+
145
155
  api :SDL_SaveBMP_RW, [Surface.by_ref, RWops.by_ref, :int], :int
146
156
 
147
157
  def self.save_bmp(file)
@@ -159,25 +169,31 @@ module SDL2
159
169
  api :SDL_GetSurfaceBlendMode, [Surface.by_ref, BlendModeStruct.by_ref], :int, {error: true}
160
170
  api :SDL_SetClipRect, [Surface.by_ref, Rect.by_ref], :int, {error: true}
161
171
  api :SDL_GetClipRect, [Surface.by_ref, Rect.by_ref], :int, {error: true}
162
- api :SDL_ConvertSurface, [Surface.by_ref, PixelFormat.by_ref, :surface_flags], Surface.auto_ptr
172
+ api :SDL_ConvertSurface, [Surface.by_ref, PixelFormat.by_ref, :surface_flags], Surface.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
163
173
  api :SDL_ConvertSurfaceFormat, [Surface.by_ref, :pixel_format, :surface_flags], Surface.auto_ptr
164
174
  api :SDL_ConvertPixels, [:int, :int, :pixel_format, :pointer, :int, :pixel_format, :pointer, :int], :int, {error: true}
165
175
  api :SDL_FillRect, [Surface.by_ref, Rect.by_ref, :uint32], :int, {error: true}
166
176
  api :SDL_FillRects, [Surface.by_ref, Rect.by_ref, :count, :uint32], :int, {error: true}
167
177
  api :SDL_UpperBlit, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int, {error: true}
168
178
 
179
+ # using upper_blit
169
180
  def self.blit_surface(src, srcrect, dst, dstrect)
170
181
  upper_blit(src, srcrect, dst, dstrect)
171
182
  end
172
183
 
184
+ returns_error(:blit_surface, TRUE_WHEN_ZERO)
185
+
173
186
  api :SDL_LowerBlit, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
174
187
  api :SDL_SoftStretch, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
175
188
  api :SDL_UpperBlitScaled, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
176
189
 
190
+ # using upper_blit_scaled
177
191
  def self.blit_scaled(src, srcrect, dst, dstrect)
178
192
  upper_blit_scaled(src, srcrect, dst, dstrect)
179
193
  end
180
194
 
195
+ returns_error(:blit_scaled, TRUE_WHEN_ZERO)
196
+
181
197
  api :SDL_LowerBlitScaled, [Surface.by_ref, Rect.by_ref, Surface.by_ref, Rect.by_ref], :int
182
198
 
183
199
  end
@@ -1,11 +1,13 @@
1
1
  require 'sdl2'
2
2
  require 'sdl2/version'
3
+ require 'sdl2/rwops'
4
+ require 'sdl2/color'
3
5
  require 'sdl2/ttf/sdl_ttf_module'
4
6
  require 'active_support/inflector'
5
- require 'yinum'
7
+
6
8
 
7
9
  module SDL2
8
-
10
+ # The SDL_ttf interface. API prototypes are linked to this module.
9
11
  module TTF
10
12
 
11
13
  extend FFI::Library
@@ -16,7 +18,7 @@ module SDL2
16
18
  methodName = ActiveSupport::Inflector.underscore(camelCaseName).to_sym
17
19
  self.attach_function methodName, func_name, args, type
18
20
  return methodName
19
- end
21
+ end
20
22
 
21
23
  api :TTF_Linked_Version, [], Version.auto_ptr
22
24
 
@@ -39,30 +41,32 @@ module SDL2
39
41
  api :TTF_OpenFontRW, [RWops.by_ref, :int, :int], Font.auto_ptr
40
42
  api :TTF_OpenFontIndexRW, [RWops.by_ref, :int, :int, :long], Font.auto_ptr
41
43
 
42
- STYLE = Enum.new(:STYLE, {
43
- NORMAL: 0x00,
44
- BOLD: 0x01,
45
- ITALIC: 0x02,
46
- UNDERLINE: 0x04,
47
- STRIKETHROUGH: 0x08
48
- })
44
+ module STYLE
45
+ include EnumerableConstants
46
+ NORMAL = 0x00
47
+ BOLD = 0x01
48
+ ITALIC = 0x02
49
+ UNDERLINE = 0x04
50
+ STRIKETHROUGH = 0x08
51
+ end
49
52
 
50
- enum :font_style, STYLE.by_name
53
+ enum :font_style, STYLE.flatten_consts
51
54
 
52
55
  api :TTF_GetFontStyle, [Font.by_ref], :int
53
56
  api :TTF_SetFontStyle, [Font.by_ref, :int], :void
54
57
  api :TTF_GetFontOutline, [Font.by_ref], :int
55
58
  api :TTF_SetFontOutline, [Font.by_ref, :int], :void
56
59
 
57
- HINTING = Enum.new(:HINTING, {
58
- NORMAL: 0,
59
- LIGHT: 1,
60
- MONO: 2,
61
- NONE: 3
62
- })
63
- enum :hinting, HINTING.by_name
60
+ module HINTING
61
+ include EnumerableConstants
62
+ NORMAL = 0
63
+ LIGHT = 1
64
+ MONO = 2
65
+ NONE = 3
66
+ end
67
+ enum :hinting, HINTING.flatten_consts
64
68
 
65
- api :TTF_GetFontHinting, [Font.by_ref], :int
69
+ api :TTF_GetFontHinting, [Font.by_ref], :hinting
66
70
  api :TTF_SetFontHinting, [Font.by_ref, :int], :void
67
71
 
68
72
  api :TTF_FontHeight, [Font.by_ref], :int
@@ -2,32 +2,38 @@ require 'sdl2'
2
2
 
3
3
  module SDL2
4
4
 
5
+ # Used to identify linked versions of libraries.
6
+ # Used by SDL2, SDL_Image, SDL_ttf, and etc.
5
7
  class Version < FFI::Struct
6
8
  layout :major, :uint8,
7
9
  :minor, :uint8,
8
10
  :patch, :uint8
9
11
 
12
+ # Release memory held by a Version struct
10
13
  def self.release(pointer)
11
14
  pointer.free
12
15
  end
13
16
 
17
+ # The major X.0.0 part
14
18
  def major
15
19
  self[:major]
16
20
  end
17
21
 
22
+ # The minor 0.X.0 part
18
23
  def minor
19
24
  self[:minor]
20
25
  end
21
26
 
27
+ # the patch 0.0.X part
22
28
  def patch
23
29
  self[:patch]
24
30
  end
25
31
 
32
+ # Human-readable version string
26
33
  def to_s
27
- "SDL v#{major}.#{minor}.#{patch}"
34
+ "v#{major}.#{minor}.#{patch}"
28
35
  end
29
36
 
30
-
31
37
  end
32
38
 
33
39
  api :SDL_GetRevision, [], :string
@@ -1,4 +1,4 @@
1
- require 'sdl2'
1
+ require 'sdl2/stdinc'
2
2
  require 'sdl2/rect'
3
3
  require 'sdl2/window'
4
4
  require 'sdl2/display'
@@ -8,80 +8,71 @@ require 'sdl2/surface'
8
8
  #require 'sdl2/texture'
9
9
  require 'sdl2/syswm/info'
10
10
 
11
- #
12
11
  module SDL2
13
12
  typedef :int, :display_index
14
-
15
13
 
16
- enum :window_flags, [
17
- :fullscreen, Window::FULLSCREEN,
18
- :opengl, Window::OPENGL,
19
- :shown, Window::SHOWN,
20
- :hidden, Window::HIDDEN,
21
- :borderless, Window::BORDERLESS,
22
- :minimized, Window::MINIMIZED,
23
- :maximized, Window::MAXIMIZED,
24
- :input_grabbed, Window::INPUT_GRABBED,
25
- :input_focus, Window::INPUT_FOCUS,
26
- :mouse_focus, Window::MOUSE_FOCUS,
27
- :fullscreen_desktop, Window::FULLSCREEN_DESKTOP,
28
- :foreign, Window::FOREIGN
29
- ]
14
+ enum :window_flags, WINDOW.flatten_consts
30
15
  # TODO: SDL_video.h lines 113~129
31
-
32
- # line: 134~155
33
- enum :window_event_id, [
34
- :none,
35
- :shown,
36
- :hidden,
37
- :exposed,
38
- :moved,
39
- :resized,
40
- :size_changed,
41
- :minimized,
42
- :maximized,
43
- :restored,
44
- :enter,
45
- :leave,
46
- :focus_gained,
47
- :focus_lost,
48
- :close
49
- ]
50
- # line 160
16
+ enum :window_event_id, WINDOWEVENT.flatten_consts
17
+
18
+ enum :windowpos, WINDOWPOS.flatten_consts
19
+
51
20
  typedef :pointer, :gl_context
21
+
22
+ # OpenGL configuration attributes
23
+ module GLattr
24
+ include EnumerableConstants
25
+ RED_SIZE = next_const_value
26
+ GREEN_SIZE = next_const_value
27
+ BLUE_SIZE = next_const_value
28
+ ALPHA_SIZE = next_const_value
29
+ BUFFER_SIZE = next_const_value
30
+ DOUBLEBUFFER = next_const_value
31
+ DEPTH_SIZE = next_const_value
32
+ STENCIL_SIZE = next_const_value
33
+ ACCUM_RED_SIZE = next_const_value
34
+ ACCUM_GREEN_SIZE = next_const_value
35
+ ACCUM_BLUE_SIZE = next_const_value
36
+ ACCUM_ALPHA_SIZE = next_const_value
37
+ STEREO = next_const_value
38
+ MULTISAMPLEBUFFERS = next_const_value
39
+ MULTISAMPLESAMPLES = next_const_value
40
+ ACCELERATED_VISUAL = next_const_value
41
+ RETAINED_BACKING = next_const_value
42
+ CONTEXT_MAJOR_VERSION = next_const_value
43
+ CONTEXT_MINOR_VERSION = next_const_value
44
+ CONTEXT_EGL = next_const_value
45
+ CONTEXT_FLAGS = next_const_value
46
+ CONTEXT_PROFILE_MASK = next_const_value
47
+ SHARE_WITH_CURRENT_CONTEXT = next_const_value
48
+ end
49
+
52
50
  # lines 165~190
53
- enum :gl_attr, [
54
- :red_size,
55
- :green_size,
56
- :blue_size,
57
- :alpha_size,
58
- :buffer_size,
59
- :doublebuffer,
60
- :depth_size,
61
- :stencil_size,
62
- :accum_red_size,
63
- :accum_green_size,
64
- :accum_blue_size,
65
- :accum_alpha_size,
66
- :stereo,
67
- :multisamplebuffers,
68
- :multisamplesamples,
69
- :accelerated_visual,
70
- :retained_backing,
71
- :context_major_version,
72
- :context_minor_version,
73
- :context_egl,
74
- :context_flags,
75
- :context_profile_mask,
76
- :share_with_current_context
77
- ]
78
- # lines 192~197
79
- enum :gl_profile, [:core, 0x0001, :compatibility, 0x0002, :es, 0x0004]
51
+ enum :gl_attr, GLattr.flatten_consts
52
+
53
+ # OpenGL Profile Values
54
+ module GLprofile
55
+ include EnumerableConstants
56
+ CORE = 0x0001
57
+ COMPATIBILITY = 0x0002
58
+ ES = 0x0004
59
+ end
60
+ enum :gl_profile, GLprofile.flatten_consts
61
+
62
+ # OpenGL Context Values
63
+ module GLcontextFlag
64
+ include EnumerableConstants
65
+ DEBUG = 0x001
66
+ FORWARD_COMPATIBLE = 0x0002
67
+ ROBUST_ACCESS = 0x0004
68
+ RESET_ISOLATION = 0x0008
69
+ end
80
70
  # lines 199~205
81
- enum :gl_context_flag, [:debug, 0x0001, :forward_compatible, 0x0002, :robust_access, 0x0004, :reset_isolation, 0x0008]
71
+ enum :gl_context_flag, GLcontextFlag.flatten_consts
82
72
 
83
73
  # This interface represents SDL_video.h function prototypes, lines 208~
84
- api :SDL_GetNumVideoDrivers, [], :int
74
+
75
+ api :SDL_GetNumVideoDrivers, [], :int
85
76
  api :SDL_GetVideoDriver, [:int], :string
86
77
  api :SDL_VideoInit, [:string], :int
87
78
  api :SDL_VideoQuit, [], :void
@@ -98,7 +89,7 @@ module SDL2
98
89
  api :SDL_SetWindowDisplayMode, [Window.by_ref, :uint32], :int
99
90
  api :SDL_GetWindowDisplayMode, [Window.by_ref, Display::Mode.by_ref], :int
100
91
  api :SDL_GetWindowPixelFormat, [Window.by_ref], :uint32
101
- api :SDL_CreateWindow, [:string, :int, :int, :int, :int, :uint32], Window.auto_ptr
92
+ api :SDL_CreateWindow, [:string, :int, :int, :int, :int, :window_flags], Window.auto_ptr, {error: true, filter: TRUE_WHEN_NOT_NULL}
102
93
  api :SDL_CreateWindowFrom, [:pointer], Window.auto_ptr
103
94
  api :SDL_GetWindowFromID, [:uint32], Window.by_ref
104
95
  api :SDL_GetWindowID, [Window.by_ref], :uint32
@@ -125,8 +116,8 @@ module SDL2
125
116
  api :SDL_RestoreWindow, [Window.by_ref], :void
126
117
  api :SDL_SetWindowFullscreen, [Window.by_ref, :uint32], :int
127
118
  api :SDL_GetWindowSurface, [Window.by_ref], Surface.by_ref
128
- api :SDL_UpdateWindowSurface, [Window.by_ref], :int
129
- api :SDL_UpdateWindowSurfaceRects, [Window.by_ref, Rect.by_ref, :int], :int
119
+ api :SDL_UpdateWindowSurface, [Window.by_ref], :int, {error: true}
120
+ api :SDL_UpdateWindowSurfaceRects, [Window.by_ref, Rect.by_ref, :int], :int, {error: true}
130
121
  api :SDL_GetWindowGrab, [Window.by_ref], :bool
131
122
  api :SDL_SetWindowGrab, [Window.by_ref, :bool], :void
132
123
  api :SDL_GetWindowBrightness, [Window.by_ref], :float
@@ -134,16 +125,16 @@ module SDL2
134
125
  api :SDL_GetWindowGammaRamp, [Window.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref], :int
135
126
  api :SDL_SetWindowGammaRamp, [Window.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref, UInt16Struct.by_ref], :int
136
127
  api :SDL_DestroyWindow, [Window.by_ref], :void
137
- api :SDL_IsScreenSaverEnabled, [], :bool
128
+ api :SDL_IsScreenSaverEnabled, [], :bool
138
129
  api :SDL_DisableScreenSaver, [], :void
139
- api :SDL_EnableScreenSaver, [], :void
130
+ api :SDL_EnableScreenSaver, [], :void
140
131
  api :SDL_GL_LoadLibrary, [:string], :int
141
132
  api :SDL_GL_GetProcAddress, [:string], :pointer
142
133
  api :SDL_GL_UnloadLibrary, [], :void
143
134
  api :SDL_GL_ExtensionSupported, [:string], :bool
144
135
  api :SDL_GL_SetAttribute, [:gl_attr, IntStruct], :int
145
- api :SDL_GL_GetAttribute, [:gl_attr, IntStruct.by_ref], :int
146
- api :SDL_GL_CreateContext, [Window.by_ref], :gl_context
136
+ api :SDL_GL_GetAttribute, [:gl_attr, IntStruct.by_ref], :int
137
+ api :SDL_GL_CreateContext, [Window.by_ref], :gl_context
147
138
  api :SDL_GL_MakeCurrent, [Window.by_ref, :gl_context], :int
148
139
  api :SDL_GL_GetCurrentWindow, [], Window.by_ref
149
140
  api :SDL_GL_GetCurrentContext, [], :gl_context