SDLRuby 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -22
  3. data/LICENSE.txt +21 -21
  4. data/README.md +31 -31
  5. data/Rakefile +12 -12
  6. data/SDLRuby.gemspec +38 -0
  7. data/examples/alert.rb +8 -0
  8. data/examples/window.rb +7 -0
  9. data/lib/SDLRuby/event/accessor.rb +2 -2
  10. data/lib/SDLRuby/event.rb +101 -101
  11. data/lib/SDLRuby/image/include/SDL_image.h.rb +61 -61
  12. data/lib/SDLRuby/mixer/include/SDL_mixer.h.rb +95 -95
  13. data/lib/SDLRuby/rw_ops/rw_object.rb +34 -34
  14. data/lib/SDLRuby/rw_ops.rb +91 -91
  15. data/lib/SDLRuby/sdl/include/SDL.h.rb +44 -44
  16. data/lib/SDLRuby/sdl/include/SDL_audio.h.rb +160 -160
  17. data/lib/SDLRuby/sdl/include/SDL_blendmode.h.rb +30 -30
  18. data/lib/SDLRuby/sdl/include/SDL_clipboard.h.rb +10 -10
  19. data/lib/SDLRuby/sdl/include/SDL_config.h.rb +13 -13
  20. data/lib/SDLRuby/sdl/include/SDL_cpuinfo.h.rb +27 -27
  21. data/lib/SDLRuby/sdl/include/SDL_endian.h.rb +12 -12
  22. data/lib/SDLRuby/sdl/include/SDL_error.h.rb +28 -28
  23. data/lib/SDLRuby/sdl/include/SDL_events.h.rb +472 -472
  24. data/lib/SDLRuby/sdl/include/SDL_filesystem.h.rb +6 -6
  25. data/lib/SDLRuby/sdl/include/SDL_gamecontroller.h.rb +147 -147
  26. data/lib/SDLRuby/sdl/include/SDL_gesture.h.rb +12 -12
  27. data/lib/SDLRuby/sdl/include/SDL_guid.h.rb +13 -13
  28. data/lib/SDLRuby/sdl/include/SDL_hints.h.rb +199 -199
  29. data/lib/SDLRuby/sdl/include/SDL_joystick.h.rb +131 -131
  30. data/lib/SDLRuby/sdl/include/SDL_keyboard.h.rb +35 -35
  31. data/lib/SDLRuby/sdl/include/SDL_keycode.h.rb +292 -292
  32. data/lib/SDLRuby/sdl/include/SDL_locale.h.rb +13 -13
  33. data/lib/SDLRuby/sdl/include/SDL_main.h.rb +3 -3
  34. data/lib/SDLRuby/sdl/include/SDL_messagebox.h.rb +58 -58
  35. data/lib/SDLRuby/sdl/include/SDL_misc.h.rb +5 -5
  36. data/lib/SDLRuby/sdl/include/SDL_mouse.h.rb +57 -57
  37. data/lib/SDLRuby/sdl/include/SDL_pixels.h.rb +285 -285
  38. data/lib/SDLRuby/sdl/include/SDL_platform.h.rb +3 -3
  39. data/lib/SDLRuby/sdl/include/SDL_power.h.rb +6 -6
  40. data/lib/SDLRuby/sdl/include/SDL_rect.h.rb +46 -46
  41. data/lib/SDLRuby/sdl/include/SDL_render.h.rb +131 -131
  42. data/lib/SDLRuby/sdl/include/SDL_revision.h.rb +2 -2
  43. data/lib/SDLRuby/sdl/include/SDL_rwops.h.rb +78 -78
  44. data/lib/SDLRuby/sdl/include/SDL_scancode.h.rb +252 -252
  45. data/lib/SDLRuby/sdl/include/SDL_sensor.h.rb +25 -25
  46. data/lib/SDLRuby/sdl/include/SDL_shape.h.rb +40 -40
  47. data/lib/SDLRuby/sdl/include/SDL_stdinc.h.rb +62 -62
  48. data/lib/SDLRuby/sdl/include/SDL_surface.h.rb +100 -100
  49. data/lib/SDLRuby/sdl/include/SDL_system.h.rb +6 -6
  50. data/lib/SDLRuby/sdl/include/SDL_syswm.h.rb +10 -10
  51. data/lib/SDLRuby/sdl/include/SDL_timer.h.rb +21 -21
  52. data/lib/SDLRuby/sdl/include/SDL_touch.h.rb +15 -15
  53. data/lib/SDLRuby/sdl/include/SDL_types.h.rb +3 -3
  54. data/lib/SDLRuby/sdl/include/SDL_version.h.rb +14 -14
  55. data/lib/SDLRuby/sdl/include/SDL_video.h.rb +264 -264
  56. data/lib/SDLRuby/sdl.rb +218 -218
  57. data/lib/SDLRuby/ttf/include/SDL_ttf.h.rb +54 -54
  58. data/lib/SDLRuby/version.rb +5 -5
  59. data/lib/SDLRuby/window/surfacer.rb +37 -37
  60. data/lib/SDLRuby.rb +32 -16
  61. data/sig/SDLRuby.rbs +4 -4
  62. data/sig/lib/SDLRuby/event/accessor.rbs +157 -157
  63. data/sig/lib/SDLRuby/event/type.rbs +67 -67
  64. data/sig/lib/SDLRuby/event.rbs +47 -47
  65. data/sig/lib/SDLRuby/keyboard.rbs +25 -25
  66. data/sig/lib/SDLRuby/mouse.rbs +35 -35
  67. data/sig/lib/SDLRuby/sdl.rbs +655 -655
  68. data/sig/lib/SDLRuby/timer.rbs +7 -7
  69. metadata +6 -3
@@ -1,95 +1,95 @@
1
- module SDLRuby::Mixer
2
- typealias "Mix_Music", "struct _Mix_Music"
3
- typealias "MIX_InitFlags", "int"
4
- typealias "Mix_Fading", "int"
5
- typealias "Mix_MusicType", "int"
6
- extern "const SDL_version * Mix_Linked_Version(void)"
7
- extern "int Mix_Init(int flags)"
8
- extern "void Mix_Quit(void)"
9
- extern "int Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize)"
10
- extern "int Mix_OpenAudioDevice(int frequency, Uint16 format, int channels, int chunksize, const char*device, int allowed_changes)"
11
- extern "int Mix_QuerySpec(int *frequency, Uint16 *format, int *channels)"
12
- extern "int Mix_AllocateChannels(int numchans)"
13
- extern "Mix_Chunk * Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)"
14
- extern "Mix_Chunk * Mix_LoadWAV(const char *file)"
15
- extern "Mix_Music * Mix_LoadMUS(const char *file)"
16
- extern "Mix_Music * Mix_LoadMUS_RW(SDL_RWops *src, int freesrc)"
17
- extern "Mix_Music * Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc)"
18
- extern "Mix_Chunk * Mix_QuickLoad_WAV(Uint8 *mem)"
19
- extern "Mix_Chunk * Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len)"
20
- extern "void Mix_FreeChunk(Mix_Chunk *chunk)"
21
- extern "void Mix_FreeMusic(Mix_Music *music)"
22
- extern "int Mix_GetNumChunkDecoders(void)"
23
- extern "const char * Mix_GetChunkDecoder(int index)"
24
- extern "SDL_bool Mix_HasChunkDecoder(const char *name)"
25
- extern "int Mix_GetNumMusicDecoders(void)"
26
- extern "const char * Mix_GetMusicDecoder(int index)"
27
- extern "SDL_bool Mix_HasMusicDecoder(const char *name)"
28
- extern "Mix_MusicType Mix_GetMusicType(const Mix_Music *music)"
29
- extern "const char * Mix_GetMusicTitle(const Mix_Music *music)"
30
- extern "const char * Mix_GetMusicTitleTag(const Mix_Music *music)"
31
- extern "const char * Mix_GetMusicArtistTag(const Mix_Music *music)"
32
- extern "const char * Mix_GetMusicAlbumTag(const Mix_Music *music)"
33
- extern "const char * Mix_GetMusicCopyrightTag(const Mix_Music *music)"
34
- extern "void * Mix_GetMusicHookData(void)"
35
- extern "int Mix_RegisterEffect(int chan, Mix_EffectFunc_t f, Mix_EffectDone_t d, void *arg)"
36
- extern "int Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f)"
37
- extern "int Mix_UnregisterAllEffects(int channel)"
38
- extern "int Mix_SetPanning(int channel, Uint8 left, Uint8 right)"
39
- extern "int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance)"
40
- extern "int Mix_SetDistance(int channel, Uint8 distance)"
41
- extern "int Mix_SetReverseStereo(int channel, int flip)"
42
- extern "int Mix_ReserveChannels(int num)"
43
- extern "int Mix_GroupChannel(int which, int tag)"
44
- extern "int Mix_GroupChannels(int from, int to, int tag)"
45
- extern "int Mix_GroupAvailable(int tag)"
46
- extern "int Mix_GroupCount(int tag)"
47
- extern "int Mix_GroupOldest(int tag)"
48
- extern "int Mix_GroupNewer(int tag)"
49
- extern "int Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops)"
50
- extern "int Mix_PlayChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ticks)"
51
- extern "int Mix_PlayMusic(Mix_Music *music, int loops)"
52
- extern "int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)"
53
- extern "int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position)"
54
- extern "int Mix_FadeInChannel(int channel, Mix_Chunk *chunk, int loops, int ms)"
55
- extern "int Mix_FadeInChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ms, int ticks)"
56
- extern "int Mix_Volume(int channel, int volume)"
57
- extern "int Mix_VolumeChunk(Mix_Chunk *chunk, int volume)"
58
- extern "int Mix_VolumeMusic(int volume)"
59
- extern "int Mix_GetMusicVolume(Mix_Music *music)"
60
- extern "int Mix_MasterVolume(int volume)"
61
- extern "int Mix_HaltChannel(int channel)"
62
- extern "int Mix_HaltGroup(int tag)"
63
- extern "int Mix_HaltMusic(void)"
64
- extern "int Mix_ExpireChannel(int channel, int ticks)"
65
- extern "int Mix_FadeOutChannel(int which, int ms)"
66
- extern "int Mix_FadeOutGroup(int tag, int ms)"
67
- extern "int Mix_FadeOutMusic(int ms)"
68
- extern "Mix_Fading Mix_FadingMusic(void)"
69
- extern "Mix_Fading Mix_FadingChannel(int which)"
70
- extern "void Mix_Pause(int channel)"
71
- extern "void Mix_Resume(int channel)"
72
- extern "int Mix_Paused(int channel)"
73
- extern "void Mix_PauseMusic(void)"
74
- extern "void Mix_ResumeMusic(void)"
75
- extern "void Mix_RewindMusic(void)"
76
- extern "int Mix_PausedMusic(void)"
77
- extern "int Mix_ModMusicJumpToOrder(int order)"
78
- extern "int Mix_SetMusicPosition(double position)"
79
- extern "double Mix_GetMusicPosition(Mix_Music *music)"
80
- extern "double Mix_MusicDuration(Mix_Music *music)"
81
- extern "double Mix_GetMusicLoopStartTime(Mix_Music *music)"
82
- extern "double Mix_GetMusicLoopEndTime(Mix_Music *music)"
83
- extern "double Mix_GetMusicLoopLengthTime(Mix_Music *music)"
84
- extern "int Mix_Playing(int channel)"
85
- extern "int Mix_PlayingMusic(void)"
86
- extern "int Mix_SetMusicCMD(const char *command)"
87
- extern "int Mix_SetSynchroValue(int value)"
88
- extern "int Mix_GetSynchroValue(void)"
89
- extern "int Mix_SetSoundFonts(const char *paths)"
90
- extern "const char* Mix_GetSoundFonts(void)"
91
- extern "int Mix_SetTimidityCfg(const char *path)"
92
- extern "const char* Mix_GetTimidityCfg(void)"
93
- extern "Mix_Chunk * Mix_GetChunk(int channel)"
94
- extern "void Mix_CloseAudio(void)"
95
- end
1
+ module SDLRuby::Mixer
2
+ typealias "Mix_Music", "struct _Mix_Music"
3
+ typealias "MIX_InitFlags", "int"
4
+ typealias "Mix_Fading", "int"
5
+ typealias "Mix_MusicType", "int"
6
+ extern "const SDL_version * Mix_Linked_Version(void)"
7
+ extern "int Mix_Init(int flags)"
8
+ extern "void Mix_Quit(void)"
9
+ extern "int Mix_OpenAudio(int frequency, Uint16 format, int channels, int chunksize)"
10
+ extern "int Mix_OpenAudioDevice(int frequency, Uint16 format, int channels, int chunksize, const char*device, int allowed_changes)"
11
+ extern "int Mix_QuerySpec(int *frequency, Uint16 *format, int *channels)"
12
+ extern "int Mix_AllocateChannels(int numchans)"
13
+ extern "Mix_Chunk * Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)"
14
+ extern "Mix_Chunk * Mix_LoadWAV(const char *file)"
15
+ extern "Mix_Music * Mix_LoadMUS(const char *file)"
16
+ extern "Mix_Music * Mix_LoadMUS_RW(SDL_RWops *src, int freesrc)"
17
+ extern "Mix_Music * Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc)"
18
+ extern "Mix_Chunk * Mix_QuickLoad_WAV(Uint8 *mem)"
19
+ extern "Mix_Chunk * Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len)"
20
+ extern "void Mix_FreeChunk(Mix_Chunk *chunk)"
21
+ extern "void Mix_FreeMusic(Mix_Music *music)"
22
+ extern "int Mix_GetNumChunkDecoders(void)"
23
+ extern "const char * Mix_GetChunkDecoder(int index)"
24
+ extern "SDL_bool Mix_HasChunkDecoder(const char *name)"
25
+ extern "int Mix_GetNumMusicDecoders(void)"
26
+ extern "const char * Mix_GetMusicDecoder(int index)"
27
+ extern "SDL_bool Mix_HasMusicDecoder(const char *name)"
28
+ extern "Mix_MusicType Mix_GetMusicType(const Mix_Music *music)"
29
+ extern "const char * Mix_GetMusicTitle(const Mix_Music *music)"
30
+ extern "const char * Mix_GetMusicTitleTag(const Mix_Music *music)"
31
+ extern "const char * Mix_GetMusicArtistTag(const Mix_Music *music)"
32
+ extern "const char * Mix_GetMusicAlbumTag(const Mix_Music *music)"
33
+ extern "const char * Mix_GetMusicCopyrightTag(const Mix_Music *music)"
34
+ extern "void * Mix_GetMusicHookData(void)"
35
+ extern "int Mix_RegisterEffect(int chan, Mix_EffectFunc_t f, Mix_EffectDone_t d, void *arg)"
36
+ extern "int Mix_UnregisterEffect(int channel, Mix_EffectFunc_t f)"
37
+ extern "int Mix_UnregisterAllEffects(int channel)"
38
+ extern "int Mix_SetPanning(int channel, Uint8 left, Uint8 right)"
39
+ extern "int Mix_SetPosition(int channel, Sint16 angle, Uint8 distance)"
40
+ extern "int Mix_SetDistance(int channel, Uint8 distance)"
41
+ extern "int Mix_SetReverseStereo(int channel, int flip)"
42
+ extern "int Mix_ReserveChannels(int num)"
43
+ extern "int Mix_GroupChannel(int which, int tag)"
44
+ extern "int Mix_GroupChannels(int from, int to, int tag)"
45
+ extern "int Mix_GroupAvailable(int tag)"
46
+ extern "int Mix_GroupCount(int tag)"
47
+ extern "int Mix_GroupOldest(int tag)"
48
+ extern "int Mix_GroupNewer(int tag)"
49
+ extern "int Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops)"
50
+ extern "int Mix_PlayChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ticks)"
51
+ extern "int Mix_PlayMusic(Mix_Music *music, int loops)"
52
+ extern "int Mix_FadeInMusic(Mix_Music *music, int loops, int ms)"
53
+ extern "int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position)"
54
+ extern "int Mix_FadeInChannel(int channel, Mix_Chunk *chunk, int loops, int ms)"
55
+ extern "int Mix_FadeInChannelTimed(int channel, Mix_Chunk *chunk, int loops, int ms, int ticks)"
56
+ extern "int Mix_Volume(int channel, int volume)"
57
+ extern "int Mix_VolumeChunk(Mix_Chunk *chunk, int volume)"
58
+ extern "int Mix_VolumeMusic(int volume)"
59
+ extern "int Mix_GetMusicVolume(Mix_Music *music)"
60
+ extern "int Mix_MasterVolume(int volume)"
61
+ extern "int Mix_HaltChannel(int channel)"
62
+ extern "int Mix_HaltGroup(int tag)"
63
+ extern "int Mix_HaltMusic(void)"
64
+ extern "int Mix_ExpireChannel(int channel, int ticks)"
65
+ extern "int Mix_FadeOutChannel(int which, int ms)"
66
+ extern "int Mix_FadeOutGroup(int tag, int ms)"
67
+ extern "int Mix_FadeOutMusic(int ms)"
68
+ extern "Mix_Fading Mix_FadingMusic(void)"
69
+ extern "Mix_Fading Mix_FadingChannel(int which)"
70
+ extern "void Mix_Pause(int channel)"
71
+ extern "void Mix_Resume(int channel)"
72
+ extern "int Mix_Paused(int channel)"
73
+ extern "void Mix_PauseMusic(void)"
74
+ extern "void Mix_ResumeMusic(void)"
75
+ extern "void Mix_RewindMusic(void)"
76
+ extern "int Mix_PausedMusic(void)"
77
+ extern "int Mix_ModMusicJumpToOrder(int order)"
78
+ extern "int Mix_SetMusicPosition(double position)"
79
+ extern "double Mix_GetMusicPosition(Mix_Music *music)"
80
+ extern "double Mix_MusicDuration(Mix_Music *music)"
81
+ extern "double Mix_GetMusicLoopStartTime(Mix_Music *music)"
82
+ extern "double Mix_GetMusicLoopEndTime(Mix_Music *music)"
83
+ extern "double Mix_GetMusicLoopLengthTime(Mix_Music *music)"
84
+ extern "int Mix_Playing(int channel)"
85
+ extern "int Mix_PlayingMusic(void)"
86
+ extern "int Mix_SetMusicCMD(const char *command)"
87
+ extern "int Mix_SetSynchroValue(int value)"
88
+ extern "int Mix_GetSynchroValue(void)"
89
+ extern "int Mix_SetSoundFonts(const char *paths)"
90
+ extern "const char* Mix_GetSoundFonts(void)"
91
+ extern "int Mix_SetTimidityCfg(const char *path)"
92
+ extern "const char* Mix_GetTimidityCfg(void)"
93
+ extern "Mix_Chunk * Mix_GetChunk(int channel)"
94
+ extern "void Mix_CloseAudio(void)"
95
+ end
@@ -1,34 +1,34 @@
1
- require_relative '../rw/read_closure'
2
- require_relative '../rw/seek_closure'
3
- require_relative '../rw/size_closure'
4
- require_relative '../rw/write_closure'
5
- require_relative 'mem_close'
6
-
7
- module SDLRuby
8
- class RWOps
9
- class RWObject
10
- include Fiddle, SDL
11
-
12
- # 引数objに与えたオブジェクトはSDLからcloseを呼び出されてもクローズしない。
13
- # このインスタンスを単独で扱う場合は使い終わったらclose関数を呼び出す必要がある。
14
- # そうしなければポインターは開放されずメモリーリークする。
15
- #
16
- def initialize(obj)
17
- ptr = SDL.SDL_AllocRW
18
- raise SDLError if ptr.null?
19
-
20
- @st = SDL_RWops.new(ptr)
21
-
22
- # SDLではSDL_RWopsポインターの開放はclose関数ポインターを呼び出して行う仕様となっている。
23
- #
24
- @st.close = MEM_CLOSE
25
- @st.read = @read = RW::ReadClosure.new(obj)
26
- @st.seek = @seek = RW::SeekClosure.new(obj)
27
- @st.size = @size = RW::SizeClosure.new(obj)
28
- @st.write = @write = RW::WriteClosure.new(obj)
29
- end
30
-
31
- def to_ptr = @st.to_ptr
32
- end
33
- end
34
- end
1
+ require_relative '../rw/read_closure'
2
+ require_relative '../rw/seek_closure'
3
+ require_relative '../rw/size_closure'
4
+ require_relative '../rw/write_closure'
5
+ require_relative 'mem_close'
6
+
7
+ module SDLRuby
8
+ class RWOps
9
+ class RWObject
10
+ include Fiddle, SDL
11
+
12
+ # 引数objに与えたオブジェクトはSDLからcloseを呼び出されてもクローズしない。
13
+ # このインスタンスを単独で扱う場合は使い終わったらclose関数を呼び出す必要がある。
14
+ # そうしなければポインターは開放されずメモリーリークする。
15
+ #
16
+ def initialize(obj)
17
+ ptr = SDL.SDL_AllocRW
18
+ raise SDLError if ptr.null?
19
+
20
+ @st = SDL_RWops.new(ptr)
21
+
22
+ # SDLではSDL_RWopsポインターの開放はclose関数ポインターを呼び出して行う仕様となっている。
23
+ #
24
+ @st.close = MEM_CLOSE
25
+ @st.read = @read = RW::ReadClosure.new(obj)
26
+ @st.seek = @seek = RW::SeekClosure.new(obj)
27
+ @st.size = @size = RW::SizeClosure.new(obj)
28
+ @st.write = @write = RW::WriteClosure.new(obj)
29
+ end
30
+
31
+ def to_ptr = @st.to_ptr
32
+ end
33
+ end
34
+ end
@@ -1,91 +1,91 @@
1
- require 'stringio'
2
- require_relative 'rw/operational'
3
- require_relative 'rw_ops/rw_object'
4
-
5
- module SDLRuby
6
- class RWOps
7
- include Fiddle, RW::Operational, SDL
8
-
9
- class << self
10
- def [](obj)
11
- return obj if obj.kind_of?(RWOps)
12
-
13
- case obj
14
- in Fiddle::Pointer
15
- ptr = if obj.frozen?
16
- SDL.SDL_RWFromConstMem(obj, obj.size)
17
- else
18
- SDL.SDL_RWFromMem(obj, obj.size)
19
- end
20
- raise SDLError if ptr.null?
21
- in String
22
- obj = RWObject.new(StringIO.new(obj))
23
- ptr = obj.to_ptr
24
- else
25
- obj = RWObject.new(obj)
26
- ptr = obj.to_ptr
27
- end
28
-
29
- rw = allocate
30
- rw.__send__(:initialize, ptr, obj)
31
- rw
32
- end
33
-
34
- def new(file, mode = "rb")
35
- path = if file.instance_of?(String)
36
- file
37
- elsif file.respond_to?(:to_path)
38
- file.to_path
39
- end
40
- ptr = SDL.SDL_RWFromFile(path, mode)
41
- raise SDLError if ptr.null?
42
-
43
- rw = super(ptr)
44
-
45
- if block_given?
46
- begin
47
- yield(rw)
48
- ensure
49
- rw.close
50
- end
51
- else
52
- rw
53
- end
54
- end
55
-
56
- alias open new
57
- end
58
-
59
- def initialize(ptr, obj = nil)
60
- @obj = obj
61
-
62
- @st = SDL_RWops.new(ptr)
63
-
64
- # ポインターへC実装のfree関数を与えるため、終了時のGC処理でコアダンプしない。
65
- #
66
- @st.to_ptr.free = @st["close"]
67
-
68
- # close関数の差し替えをすることで、SDLがcloseを行ってもRuby側に伝達できる。
69
- # int (*close) (SDL_RWops *context)
70
- #
71
- @st["close"] = @close = Closure::BlockCaller.new(TYPE_INT, [TYPE_VOIDP]) do |_|
72
- # call_free はclose関数の戻り値が渡されないためcloseの失敗は分からない。
73
- to_ptr.call_free
74
-
75
- if $DEBUG
76
- warn format("SDL_RWops(0x%016x) closed", to_ptr.to_int)
77
- end
78
-
79
- 0
80
- end
81
- end
82
-
83
- def initialize_copy(other)
84
- raise SDLError, "closed stream" if closed?
85
-
86
- super
87
- end
88
-
89
- def to_ptr = @st.to_ptr
90
- end
91
- end
1
+ require 'stringio'
2
+ require_relative 'rw/operational'
3
+ require_relative 'rw_ops/rw_object'
4
+
5
+ module SDLRuby
6
+ class RWOps
7
+ include Fiddle, RW::Operational, SDL
8
+
9
+ class << self
10
+ def [](obj)
11
+ return obj if obj.kind_of?(RWOps)
12
+
13
+ case obj
14
+ in Fiddle::Pointer
15
+ ptr = if obj.frozen?
16
+ SDL.SDL_RWFromConstMem(obj, obj.size)
17
+ else
18
+ SDL.SDL_RWFromMem(obj, obj.size)
19
+ end
20
+ raise SDLError if ptr.null?
21
+ in String
22
+ obj = RWObject.new(StringIO.new(obj))
23
+ ptr = obj.to_ptr
24
+ else
25
+ obj = RWObject.new(obj)
26
+ ptr = obj.to_ptr
27
+ end
28
+
29
+ rw = allocate
30
+ rw.__send__(:initialize, ptr, obj)
31
+ rw
32
+ end
33
+
34
+ def new(file, mode = "rb")
35
+ path = if file.instance_of?(String)
36
+ file
37
+ elsif file.respond_to?(:to_path)
38
+ file.to_path
39
+ end
40
+ ptr = SDL.SDL_RWFromFile(path, mode)
41
+ raise SDLError if ptr.null?
42
+
43
+ rw = super(ptr)
44
+
45
+ if block_given?
46
+ begin
47
+ yield(rw)
48
+ ensure
49
+ rw.close
50
+ end
51
+ else
52
+ rw
53
+ end
54
+ end
55
+
56
+ alias open new
57
+ end
58
+
59
+ def initialize(ptr, obj = nil)
60
+ @obj = obj
61
+
62
+ @st = SDL_RWops.new(ptr)
63
+
64
+ # ポインターへC実装のfree関数を与えるため、終了時のGC処理でコアダンプしない。
65
+ #
66
+ @st.to_ptr.free = @st["close"]
67
+
68
+ # close関数の差し替えをすることで、SDLがcloseを行ってもRuby側に伝達できる。
69
+ # int (*close) (SDL_RWops *context)
70
+ #
71
+ @st["close"] = @close = Closure::BlockCaller.new(TYPE_INT, [TYPE_VOIDP]) do |_|
72
+ # call_free はclose関数の戻り値が渡されないためcloseの失敗は分からない。
73
+ to_ptr.call_free
74
+
75
+ if $DEBUG
76
+ warn format("SDL_RWops(0x%016x) closed", to_ptr.to_int)
77
+ end
78
+
79
+ 0
80
+ end
81
+ end
82
+
83
+ def initialize_copy(other)
84
+ raise SDLError, "closed stream" if closed?
85
+
86
+ super
87
+ end
88
+
89
+ def to_ptr = @st.to_ptr
90
+ end
91
+ end
@@ -1,44 +1,44 @@
1
- module SDLRuby::SDL
2
- require_relative 'SDL_main.h.rb'
3
- require_relative 'SDL_stdinc.h.rb'
4
- require_relative 'SDL_audio.h.rb'
5
- require_relative 'SDL_clipboard.h.rb'
6
- require_relative 'SDL_cpuinfo.h.rb'
7
- require_relative 'SDL_endian.h.rb'
8
- require_relative 'SDL_error.h.rb'
9
- require_relative 'SDL_events.h.rb'
10
- require_relative 'SDL_filesystem.h.rb'
11
- require_relative 'SDL_gamecontroller.h.rb'
12
- require_relative 'SDL_guid.h.rb'
13
- require_relative 'SDL_hints.h.rb'
14
- require_relative 'SDL_joystick.h.rb'
15
- require_relative 'SDL_messagebox.h.rb'
16
- require_relative 'SDL_power.h.rb'
17
- require_relative 'SDL_render.h.rb'
18
- require_relative 'SDL_rwops.h.rb'
19
- require_relative 'SDL_sensor.h.rb'
20
- require_relative 'SDL_shape.h.rb'
21
- require_relative 'SDL_system.h.rb'
22
- require_relative 'SDL_timer.h.rb'
23
- require_relative 'SDL_version.h.rb'
24
- require_relative 'SDL_video.h.rb'
25
- require_relative 'SDL_locale.h.rb'
26
- require_relative 'SDL_misc.h.rb'
27
-
28
- SDL_INIT_TIMER = 0x00000001
29
- SDL_INIT_AUDIO = 0x00000010
30
- SDL_INIT_VIDEO = 0x00000020
31
- SDL_INIT_JOYSTICK = 0x00000200
32
- SDL_INIT_HAPTIC = 0x00001000
33
- SDL_INIT_GAMECONTROLLER = 0x00002000
34
- SDL_INIT_EVENTS = 0x00004000
35
- SDL_INIT_SENSOR = 0x00008000
36
- SDL_INIT_NOPARACHUTE = 0x00100000
37
- SDL_INIT_EVERYTHING = ( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR )
38
-
39
- extern "int SDL_Init(Uint32 flags)"
40
- extern "int SDL_InitSubSystem(Uint32 flags)"
41
- extern "void SDL_QuitSubSystem(Uint32 flags)"
42
- extern "Uint32 SDL_WasInit(Uint32 flags)"
43
- extern "void SDL_Quit(void)"
44
- end
1
+ module SDLRuby::SDL
2
+ require_relative 'SDL_main.h.rb'
3
+ require_relative 'SDL_stdinc.h.rb'
4
+ require_relative 'SDL_audio.h.rb'
5
+ require_relative 'SDL_clipboard.h.rb'
6
+ require_relative 'SDL_cpuinfo.h.rb'
7
+ require_relative 'SDL_endian.h.rb'
8
+ require_relative 'SDL_error.h.rb'
9
+ require_relative 'SDL_events.h.rb'
10
+ require_relative 'SDL_filesystem.h.rb'
11
+ require_relative 'SDL_gamecontroller.h.rb'
12
+ require_relative 'SDL_guid.h.rb'
13
+ require_relative 'SDL_hints.h.rb'
14
+ require_relative 'SDL_joystick.h.rb'
15
+ require_relative 'SDL_messagebox.h.rb'
16
+ require_relative 'SDL_power.h.rb'
17
+ require_relative 'SDL_render.h.rb'
18
+ require_relative 'SDL_rwops.h.rb'
19
+ require_relative 'SDL_sensor.h.rb'
20
+ require_relative 'SDL_shape.h.rb'
21
+ require_relative 'SDL_system.h.rb'
22
+ require_relative 'SDL_timer.h.rb'
23
+ require_relative 'SDL_version.h.rb'
24
+ require_relative 'SDL_video.h.rb'
25
+ require_relative 'SDL_locale.h.rb'
26
+ require_relative 'SDL_misc.h.rb'
27
+
28
+ SDL_INIT_TIMER = 0x00000001
29
+ SDL_INIT_AUDIO = 0x00000010
30
+ SDL_INIT_VIDEO = 0x00000020
31
+ SDL_INIT_JOYSTICK = 0x00000200
32
+ SDL_INIT_HAPTIC = 0x00001000
33
+ SDL_INIT_GAMECONTROLLER = 0x00002000
34
+ SDL_INIT_EVENTS = 0x00004000
35
+ SDL_INIT_SENSOR = 0x00008000
36
+ SDL_INIT_NOPARACHUTE = 0x00100000
37
+ SDL_INIT_EVERYTHING = ( SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER | SDL_INIT_SENSOR )
38
+
39
+ extern "int SDL_Init(Uint32 flags)"
40
+ extern "int SDL_InitSubSystem(Uint32 flags)"
41
+ extern "void SDL_QuitSubSystem(Uint32 flags)"
42
+ extern "Uint32 SDL_WasInit(Uint32 flags)"
43
+ extern "void SDL_Quit(void)"
44
+ end