SDLRuby 0.1.0

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 (122) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +31 -0
  5. data/Rakefile +12 -0
  6. data/lib/SDLRuby/audio.rb +65 -0
  7. data/lib/SDLRuby/cursor.rb +46 -0
  8. data/lib/SDLRuby/display.rb +79 -0
  9. data/lib/SDLRuby/event/accessor.rb +127 -0
  10. data/lib/SDLRuby/event/type.rb +75 -0
  11. data/lib/SDLRuby/event.rb +80 -0
  12. data/lib/SDLRuby/font.rb +227 -0
  13. data/lib/SDLRuby/hint.rb +36 -0
  14. data/lib/SDLRuby/image/image.rb +23 -0
  15. data/lib/SDLRuby/image/include/SDL_image.h.rb +61 -0
  16. data/lib/SDLRuby/image.rb +69 -0
  17. data/lib/SDLRuby/keyboard.rb +58 -0
  18. data/lib/SDLRuby/mixer/channel.rb +43 -0
  19. data/lib/SDLRuby/mixer/chunk.rb +49 -0
  20. data/lib/SDLRuby/mixer/controller.rb +44 -0
  21. data/lib/SDLRuby/mixer/include/SDL_mixer.h.rb +95 -0
  22. data/lib/SDLRuby/mixer/sdl_mixer.rb +60 -0
  23. data/lib/SDLRuby/mixer.rb +87 -0
  24. data/lib/SDLRuby/mouse.rb +52 -0
  25. data/lib/SDLRuby/music.rb +158 -0
  26. data/lib/SDLRuby/palette.rb +49 -0
  27. data/lib/SDLRuby/pixel_formatter.rb +67 -0
  28. data/lib/SDLRuby/rect.rb +11 -0
  29. data/lib/SDLRuby/renderer/accessor.rb +70 -0
  30. data/lib/SDLRuby/renderer/drawer.rb +107 -0
  31. data/lib/SDLRuby/renderer/renderer_info.rb +27 -0
  32. data/lib/SDLRuby/renderer.rb +101 -0
  33. data/lib/SDLRuby/rw_ops/rw_object.rb +128 -0
  34. data/lib/SDLRuby/rw_ops.rb +216 -0
  35. data/lib/SDLRuby/sdl/include/SDL.h.rb +33 -0
  36. data/lib/SDLRuby/sdl/include/SDL_audio.h.rb +49 -0
  37. data/lib/SDLRuby/sdl/include/SDL_blendmode.h.rb +6 -0
  38. data/lib/SDLRuby/sdl/include/SDL_clipboard.h.rb +10 -0
  39. data/lib/SDLRuby/sdl/include/SDL_config.h.rb +13 -0
  40. data/lib/SDLRuby/sdl/include/SDL_cpuinfo.h.rb +27 -0
  41. data/lib/SDLRuby/sdl/include/SDL_endian.h.rb +3 -0
  42. data/lib/SDLRuby/sdl/include/SDL_error.h.rb +9 -0
  43. data/lib/SDLRuby/sdl/include/SDL_events.h.rb +32 -0
  44. data/lib/SDLRuby/sdl/include/SDL_filesystem.h.rb +6 -0
  45. data/lib/SDLRuby/sdl/include/SDL_gamecontroller.h.rb +66 -0
  46. data/lib/SDLRuby/sdl/include/SDL_gesture.h.rb +12 -0
  47. data/lib/SDLRuby/sdl/include/SDL_guid.h.rb +7 -0
  48. data/lib/SDLRuby/sdl/include/SDL_hints.h.rb +14 -0
  49. data/lib/SDLRuby/sdl/include/SDL_joystick.h.rb +69 -0
  50. data/lib/SDLRuby/sdl/include/SDL_keyboard.h.rb +26 -0
  51. data/lib/SDLRuby/sdl/include/SDL_keycode.h.rb +7 -0
  52. data/lib/SDLRuby/sdl/include/SDL_locale.h.rb +6 -0
  53. data/lib/SDLRuby/sdl/include/SDL_main.h.rb +3 -0
  54. data/lib/SDLRuby/sdl/include/SDL_messagebox.h.rb +10 -0
  55. data/lib/SDLRuby/sdl/include/SDL_misc.h.rb +5 -0
  56. data/lib/SDLRuby/sdl/include/SDL_mouse.h.rb +26 -0
  57. data/lib/SDLRuby/sdl/include/SDL_pixels.h.rb +25 -0
  58. data/lib/SDLRuby/sdl/include/SDL_platform.h.rb +3 -0
  59. data/lib/SDLRuby/sdl/include/SDL_power.h.rb +6 -0
  60. data/lib/SDLRuby/sdl/include/SDL_rect.h.rb +17 -0
  61. data/lib/SDLRuby/sdl/include/SDL_render.h.rb +94 -0
  62. data/lib/SDLRuby/sdl/include/SDL_revision.h.rb +2 -0
  63. data/lib/SDLRuby/sdl/include/SDL_rwops.h.rb +34 -0
  64. data/lib/SDLRuby/sdl/include/SDL_scancode.h.rb +5 -0
  65. data/lib/SDLRuby/sdl/include/SDL_sensor.h.rb +25 -0
  66. data/lib/SDLRuby/sdl/include/SDL_shape.h.rb +13 -0
  67. data/lib/SDLRuby/sdl/include/SDL_stdinc.h.rb +24 -0
  68. data/lib/SDLRuby/sdl/include/SDL_surface.h.rb +37 -0
  69. data/lib/SDLRuby/sdl/include/SDL_system.h.rb +6 -0
  70. data/lib/SDLRuby/sdl/include/SDL_syswm.h.rb +16 -0
  71. data/lib/SDLRuby/sdl/include/SDL_timer.h.rb +13 -0
  72. data/lib/SDLRuby/sdl/include/SDL_touch.h.rb +15 -0
  73. data/lib/SDLRuby/sdl/include/SDL_types.h.rb +3 -0
  74. data/lib/SDLRuby/sdl/include/SDL_version.h.rb +6 -0
  75. data/lib/SDLRuby/sdl/include/SDL_video.h.rb +117 -0
  76. data/lib/SDLRuby/sdl/sdl.rb +55 -0
  77. data/lib/SDLRuby/sdl/sdl_audio.rb +75 -0
  78. data/lib/SDLRuby/sdl/sdl_blendmode.rb +10 -0
  79. data/lib/SDLRuby/sdl/sdl_error.rb +5 -0
  80. data/lib/SDLRuby/sdl/sdl_events.rb +470 -0
  81. data/lib/SDLRuby/sdl/sdl_hints.rb +9 -0
  82. data/lib/SDLRuby/sdl/sdl_keyboard.rb +12 -0
  83. data/lib/SDLRuby/sdl/sdl_locale.rb +8 -0
  84. data/lib/SDLRuby/sdl/sdl_message_box.rb +7 -0
  85. data/lib/SDLRuby/sdl/sdl_mouse.rb +32 -0
  86. data/lib/SDLRuby/sdl/sdl_palette.rb +12 -0
  87. data/lib/SDLRuby/sdl/sdl_pixels.rb +138 -0
  88. data/lib/SDLRuby/sdl/sdl_rect.rb +11 -0
  89. data/lib/SDLRuby/sdl/sdl_render.rb +35 -0
  90. data/lib/SDLRuby/sdl/sdl_rw_ops.rb +29 -0
  91. data/lib/SDLRuby/sdl/sdl_scancode.rb +255 -0
  92. data/lib/SDLRuby/sdl/sdl_surface.rb +27 -0
  93. data/lib/SDLRuby/sdl/sdl_version.rb +5 -0
  94. data/lib/SDLRuby/sdl/sdl_video.rb +104 -0
  95. data/lib/SDLRuby/sdl.rb +192 -0
  96. data/lib/SDLRuby/sdl_error.rb +8 -0
  97. data/lib/SDLRuby/surface/pixel_format.rb +51 -0
  98. data/lib/SDLRuby/surface/surface_renderer.rb +26 -0
  99. data/lib/SDLRuby/surface.rb +179 -0
  100. data/lib/SDLRuby/text_input.rb +38 -0
  101. data/lib/SDLRuby/texture.rb +93 -0
  102. data/lib/SDLRuby/ttf/include/SDL_ttf.h.rb +54 -0
  103. data/lib/SDLRuby/ttf/ttf.rb +41 -0
  104. data/lib/SDLRuby/ttf.rb +54 -0
  105. data/lib/SDLRuby/version.rb +5 -0
  106. data/lib/SDLRuby/window/accessor.rb +125 -0
  107. data/lib/SDLRuby/window/controller.rb +53 -0
  108. data/lib/SDLRuby/window/display_info.rb +48 -0
  109. data/lib/SDLRuby/window/flag.rb +42 -0
  110. data/lib/SDLRuby/window/hit_tester.rb +61 -0
  111. data/lib/SDLRuby/window/input.rb +68 -0
  112. data/lib/SDLRuby/window/shaper.rb +68 -0
  113. data/lib/SDLRuby/window/surfacer.rb +37 -0
  114. data/lib/SDLRuby/window/window_renderer.rb +31 -0
  115. data/lib/SDLRuby/window.rb +90 -0
  116. data/lib/SDLRuby.rb +16 -0
  117. data/sig/SDLRuby/event.rbs +104 -0
  118. data/sig/SDLRuby/pixel_formmater.rbs +24 -0
  119. data/sig/SDLRuby/rect.rbs +5 -0
  120. data/sig/SDLRuby/sdl.rbs +606 -0
  121. data/sig/SDLRuby.rbs +4 -0
  122. metadata +168 -0
@@ -0,0 +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
@@ -0,0 +1,60 @@
1
+ module SDLRuby
2
+ module Mixer
3
+ typealias "Uint8", "uint8_t"
4
+ typealias "Uint16", "uint16_t"
5
+ typealias "Uint32", "uint32_t"
6
+ typealias "Sint16", "int16_t"
7
+ typealias "SDL_bool", "int"
8
+ typealias "Mix_EffectFunc_t", "void*"
9
+ typealias "Mix_EffectDone_t", "void*"
10
+
11
+ require_relative 'include/SDL_mixer.h'
12
+
13
+ MIX_INIT_FLAC = 0x00000001
14
+ MIX_INIT_MOD = 0x00000002
15
+ MIX_INIT_MP3 = 0x00000008
16
+ MIX_INIT_OGG = 0x00000010
17
+ MIX_INIT_MID = 0x00000020
18
+ MIX_INIT_OPUS = 0x00000040
19
+
20
+ MIX_CHANNELS = 8
21
+
22
+ MIX_DEFAULT_FREQUENCY = 44100
23
+ #if SDL_BYTEORDER == SDL_LIL_ENDIAN
24
+ MIX_DEFAULT_FORMAT = AUDIO_S16LSB
25
+ #else
26
+ # MIX_DEFAULT_FORMAT = AUDIO_S16MSB
27
+ #endif
28
+
29
+ MIX_DEFAULT_CHANNELS = 2
30
+ MIX_MAX_VOLUME = SDL_MIX_MAXVOLUME
31
+
32
+ Mix_Chunk = struct(
33
+ [
34
+ "int allocated",
35
+ "Uint8 *abuf",
36
+ "Uint32 alen",
37
+ "Uint8 volume"
38
+ ]
39
+ )
40
+
41
+ MIX_NO_FADING = 0
42
+ MIX_FADING_OUT = 1
43
+ MIX_FADING_IN = 2
44
+
45
+ MUS_NONE = 0
46
+ MUS_CMD = 1
47
+ MUS_WAV = 2
48
+ MUS_MOD = 3
49
+ MUS_MID = 4
50
+ MUS_OGG = 5
51
+ MUS_MP3 = 6
52
+ MUS_MP3_MAD_UNUSED = 7
53
+ MUS_FLAC = 8
54
+ MUS_MODPLUG_UNUSED = 9
55
+ MUS_OPUS = 10
56
+
57
+ MIX_FREE_MUSIC = import_symbol("Mix_FreeMusic").to_int
58
+ MIX_FREE_CHUNK = import_symbol("Mix_FreeChunk").to_int
59
+ end
60
+ end
@@ -0,0 +1,87 @@
1
+ require 'fiddle/import'
2
+
3
+ module SDLRuby
4
+ module Mixer
5
+ include SDL
6
+ extend Fiddle::Importer
7
+
8
+ dlload "SDL2_mixer"
9
+
10
+ require_relative 'mixer/sdl_mixer'
11
+
12
+ require_relative 'mixer/channel'
13
+ require_relative 'mixer/chunk'
14
+ require_relative 'mixer/controller'
15
+
16
+ class << self
17
+ include Controller, SDL
18
+
19
+ def close = Mixer.Mix_CloseAudio
20
+
21
+ def decoders = Chunk.decoders
22
+
23
+ def init(flags = nil)
24
+ num = flags || 0 |
25
+ MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3 |
26
+ MIX_INIT_OGG | MIX_INIT_MID | MIX_INIT_OPUS
27
+
28
+ Mixer.Mix_Init(num)
29
+ end
30
+
31
+ def load_chank(...) = Chunk.load(...)
32
+
33
+ def master_volume = Mixer.Mix_MasterVolume(-1)
34
+
35
+ def master_volume=(v)
36
+ Mixer.Mix_MasterVolume(v)
37
+ end
38
+
39
+ def open(device = nil,
40
+ allow_changes: true, channels: 2, chunksize: 2048,
41
+ format: MIX_DEFAULT_FORMAT, frequency: 48_000)
42
+
43
+ err = Mixer.Mix_OpenAudioDevice(
44
+ frequency, format, channels, chunksize, device,
45
+ allow_changes ? SDL_AUDIO_ALLOW_ANY_CHANGE : 0
46
+ )
47
+ raise SDLError if err < 0
48
+ end
49
+
50
+ def quit = Mixer.Mix_Quit
51
+
52
+ def reserve_channels=(num)
53
+ Mixer.Mix_ReserveChannels(num)
54
+ end
55
+
56
+ def spec
57
+ fq, ft, ch = SDL.tmp_value("int", "Uint16", "int")
58
+
59
+ if Mixer.Mix_QuerySpec(fq, ft, ch) == 1
60
+ { frequency: fq.value, format: ft.value, channels: ch.value }
61
+ end
62
+ end
63
+
64
+ def to_int = -1
65
+
66
+ def version = SDL_version.new(Mixer.Mix_Linked_Version).to_a.join(".")
67
+ end
68
+
69
+ # Channel manage
70
+ #
71
+ @channels = []
72
+
73
+ class << self
74
+ def [](channel)
75
+ raise IndexError if channel < 0 || channels <= channel
76
+ @channels[channel] ||= Channel.new(channel)
77
+ end
78
+
79
+ def channels = Mixer.Mix_AllocateChannels(-1)
80
+
81
+ def channels=(num)
82
+ @channels.slice!(num..)
83
+ Mixer.Mix_AllocateChannels(num)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,52 @@
1
+ module SDLRuby
2
+ module Mouse
3
+ @global_x, @global_y = *SDL.tmp_value("int", "int")
4
+ @relative_x, @relative_y = *SDL.tmp_value("int", "int")
5
+ @x, @y = *SDL.tmp_value("int", "int")
6
+
7
+ class << self
8
+ include SDL
9
+
10
+ def to_button_ary(num)
11
+ [
12
+ num & SDL_BUTTON_LMASK != 0,
13
+ num & SDL_BUTTON_MMASK != 0,
14
+ num & SDL_BUTTON_RMASK != 0,
15
+ num & SDL_BUTTON_X1MASK != 0,
16
+ num & SDL_BUTTON_X2MASK != 0
17
+ ]
18
+ end
19
+
20
+ def capture=(b)
21
+ err = SDL.SDL_CaptureMouse(b ? 1 : 0)
22
+ raise SDLError if err < 0
23
+ end
24
+
25
+ def global_pos=(xy)
26
+ err = SDL.SDL_WarpMouseGlobal(*xy)
27
+ raise SDLError if err < 0
28
+ end
29
+
30
+ def global_state = [
31
+ SDL.SDL_GetGlobalMouseState(@global_x, @global_y),
32
+ @global_x.value, @global_y.value
33
+ ]
34
+
35
+ def relative=(b)
36
+ err = SDL.SDL_SetRelativeMouseMode(b ? 1 : 0)
37
+ raise SDLError if err < 0
38
+ end
39
+
40
+ def relative? = SDL.SDL_GetRelativeMouseMode == 1
41
+
42
+ def relative_state = [
43
+ SDL.SDL_GetRelativeMouseState(@relative_x, @relative_y),
44
+ @relative_x.value, @relative_y.value
45
+ ]
46
+
47
+ def state = [
48
+ SDL.SDL_GetMouseState(@x, @y), @x.value, @y.value
49
+ ]
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,158 @@
1
+ require_relative 'mixer'
2
+
3
+ module SDLRuby
4
+ class Music
5
+ module Information
6
+ include Mixer
7
+
8
+ def album = Mixer.Mix_GetMusicAlbumTag(self).to_s
9
+
10
+ def artist = Mixer.Mix_GetMusicArtistTag(self).to_s
11
+
12
+ def copyright = Mixer.Mix_GetMusicCopyrightTag(self).to_s
13
+
14
+ def duration = Mixer.Mix_MusicDuration(self)
15
+
16
+ def loop_end_time = Mixer.Mix_GetMusicLoopEndTime(self)
17
+
18
+ def loop_length_time = Mixer.Mix_GetMusicLoopLengthTime(self)
19
+
20
+ def loop_start_time = Mixer.Mix_GetMusicLoopStartTime(self)
21
+
22
+ def name = Mixer.Mix_GetMusicTitle(self).to_s
23
+
24
+ def pos = Mixer.Mix_GetMusicPosition(self)
25
+
26
+ def title = Mixer.Mix_GetMusicTitleTag(self).to_s
27
+
28
+ def type
29
+ case Mixer.Mix_GetMusicType(self)
30
+ when MUS_NONE then nil
31
+ when MUS_CMD then "CMD"
32
+ when MUS_WAV then "WAVE"
33
+ when MUS_MOD then "MOD"
34
+ when MUS_MID then "MIDI"
35
+ when MUS_OGG then "OGG"
36
+ when MUS_MP3 then "MP3"
37
+ when MUS_MP3_MAD_UNUSED then "MP3_MAD_UNUSED"
38
+ when MUS_FLAC then "FLAC"
39
+ when MUS_MODPLUG_UNUSED then "MODPLUG_UNUSED"
40
+ when MUS_OPUS then "OPUS"
41
+ else
42
+ nil
43
+ end
44
+ end
45
+
46
+ def volume = Mixer.Mix_GetMusicVolume(self)
47
+ end
48
+
49
+ include Information
50
+
51
+ class << self
52
+ include Information, Mixer
53
+
54
+ def decoders
55
+ Mixer.Mix_GetNumMusicDecoders.times.map do |idx|
56
+ ptr = Mixer.Mix_GetMusicDecoder(idx)
57
+ ptr.null? ? nil : ptr.to_s
58
+ end
59
+ end
60
+
61
+ def fading? = Mixer.Mix_FadingMusic != MIX_NO_FADING
62
+
63
+ def fading_in? = Mixer.Mix_FadingMusic == MIX_FADING_IN
64
+
65
+ def fading_out? = Mixer.Mix_FadingMusic == MIX_FADING_OUT
66
+
67
+ def halt = Mixer.Mix_HaltMusic
68
+
69
+ def fade_out(sec) = Mixer.Mix_FadeOutMusic(sec * 1000)
70
+
71
+ def load(file, type: MUS_NONE)
72
+ if String === file
73
+ rw = SDL.SDL_RWFromFile(file, "rb")
74
+ free = 1
75
+ elsif file.respond_to?(:to_path)
76
+ rw = SDL.SDL_RWFromFile(file.to_path, "rb")
77
+ free = 1
78
+ else
79
+ rw = RWOps[file]
80
+ free = 0
81
+ end
82
+
83
+ ptr = Mixer.Mix_LoadMUSType_RW(rw, type, free)
84
+ raise SDLError if ptr.null?
85
+
86
+ new(ptr)
87
+ end
88
+
89
+ # MOD形成の場合のみ
90
+ def order=(i)
91
+ err = Mixer.Mix_ModMusicJumpToOrder(i)
92
+ raise SDLError if err < 0
93
+ end
94
+
95
+ def playing? = Mixer.Mix_PlayingMusic == 1
96
+
97
+ def pause = Mixer.Mix_PauseMusic
98
+
99
+ def paused? = Mixer.Mix_PausedMusic == 1
100
+
101
+ def pos=(sec)
102
+ err = Mixer.Mix_SetMusicPosition(sec)
103
+ raise SDLError if err < 0
104
+ end
105
+
106
+ def resume = Mixer.Mix_ResumeMusic
107
+
108
+ def rewind = Mixer.Mix_RewindMusic
109
+
110
+ def volume=(v)
111
+ Mixer.Mix_VolumeMusic(v)
112
+ end
113
+
114
+ private def to_ptr = nil
115
+
116
+ # MIDI
117
+ #
118
+ def sound_fonts_path
119
+ ptr = Mixer.Mix_GetSoundFonts
120
+ ptr.null? ? nil : ptr.to_s
121
+ end
122
+
123
+ # セミコロン区切りで複数のパスを指定できます。
124
+ def sound_fonts_path=(paths)
125
+ err = Mixer.Mix_SetSoundFonts(paths)
126
+ raise SDLError if err == 0
127
+ end
128
+
129
+ def timidity_config_path
130
+ ptr = Mixer.Mix_GetTimidityCfg
131
+ ptr.null? ? nil : ptr.to_s
132
+ end
133
+
134
+ def timidity_config_path=(path)
135
+ err = Mixer.Mix_SetTimidityCfg(path)
136
+ raise SDLError if err == 0
137
+ end
138
+ end
139
+
140
+ def initialize(ptr)
141
+ ptr.free = MIX_FREE_MUSIC
142
+ @ptr = ptr
143
+ end
144
+
145
+ # loops が 0 の時は1回のみ再生する。それ以外は1も含めて指定した回数を再生する。
146
+ # fade_in_time はミリ秒で指定する。
147
+ # non_block はフェードアウト中にブロックせずに即座に新しい音楽を再生する。
148
+ #
149
+ def play(loops: 0, fade_in_time: 0, pos: 0, non_block: nil)
150
+ Music.halt if non_block
151
+
152
+ err = Mixer.Mix_FadeInMusicPos(self, loops, fade_in_time * 1000, pos)
153
+ raise SDLError if err < 0
154
+ end
155
+
156
+ def to_ptr = @ptr
157
+ end
158
+ end
@@ -0,0 +1,49 @@
1
+ module SDLRuby
2
+ class Palette
3
+ include SDL
4
+ extend Forwardable
5
+
6
+ class << self
7
+ def create(n)
8
+ ptr = SDL.SDL_AllocPalette(n)
9
+ raise SDLError if ptr.null?
10
+ new(ptr)
11
+ end
12
+ end
13
+
14
+ def initialize(ptr, add_ref: nil)
15
+ @st = SDL_Palette.new(ptr, SDL_FREE_PALETTE)
16
+ @st.refcount += 1 if add_ref
17
+ end
18
+
19
+ def_delegator :@st, :ncolors, :size
20
+ def_delegators :@st, :refcount, :to_ptr, :version
21
+
22
+ def ==(other)
23
+ (other.respond_to?(:to_ptr) && @st.to_ptr == other.to_ptr) ||
24
+ (Palette === other && other.respond_to?(:to_a) && to_a == other.to_a)
25
+ end
26
+
27
+ def [](n)
28
+ raise ArgumentError if n < 0 || n >= size
29
+ SDL_Color.new(@st.colors + SDL_Palette.size * n).to_a
30
+ end
31
+
32
+ def []=(n, obj)
33
+ c = SDL_Color.malloc(Fiddle::RUBY_FREE)
34
+ c.r, c.g, c.b, c.a = *obj
35
+ err = SDL.SDL_SetPaletteColors(self, c, n, 1)
36
+ raise SDLError if err < 0
37
+ end
38
+
39
+ def each
40
+ if block_given?
41
+ size.times { |n| yield(self[n]) }
42
+ else
43
+ to_enum
44
+ end
45
+ end
46
+
47
+ def to_a = each.to_a
48
+ end
49
+ end
@@ -0,0 +1,67 @@
1
+ module SDLRuby
2
+ module PixelFormatter
3
+ include SDL
4
+
5
+ INDEXED_PIXELFORMATS = [
6
+ SDL_PIXELFORMAT_INDEX1LSB, SDL_PIXELFORMAT_INDEX1MSB,
7
+ SDL_PIXELFORMAT_INDEX4LSB, SDL_PIXELFORMAT_INDEX4MSB,
8
+ SDL_PIXELFORMAT_INDEX8
9
+ ].freeze
10
+
11
+ ALPHA_PIXELFORMATS = [
12
+ SDL_PIXELFORMAT_ARGB4444, SDL_PIXELFORMAT_RGBA4444,
13
+ SDL_PIXELFORMAT_ABGR4444, SDL_PIXELFORMAT_BGRA4444,
14
+ SDL_PIXELFORMAT_ARGB1555, SDL_PIXELFORMAT_RGBA5551,
15
+ SDL_PIXELFORMAT_ABGR1555, SDL_PIXELFORMAT_BGRA5551,
16
+ SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
17
+ SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGRA8888,
18
+ SDL_PIXELFORMAT_ARGB2101010
19
+ ].freeze
20
+
21
+ class << self
22
+ def alpha?(x) = ALPHA_PIXELFORMATS.include?(x)
23
+
24
+ def bits_per_pixel(x) = fourcc?(x) ? nil : x >> 8 & 0xFF
25
+
26
+ def bytes_per_pixel(x)
27
+ if fourcc?(x)
28
+ x == SDL_PIXELFORMAT_YUY2 ||
29
+ x == SDL_PIXELFORMAT_UYVY ||
30
+ x == SDL_PIXELFORMAT_YVYU ? 2 : 1
31
+ else
32
+ x >> 0 & 0xFF
33
+ end
34
+ end
35
+
36
+ def format_name(x) = SDL.SDL_GetPixelFormatName(x).to_s
37
+
38
+ def fourcc?(x)
39
+ if x != 0 && x >> 28 & 0x0F != 1
40
+ [x].pack("L")
41
+ end
42
+ end
43
+
44
+ def indexed_color?(x) = INDEXED_PIXELFORMATS.include?(x)
45
+
46
+ def rgb_color?(x) = !(fourcc?(x) || indexed_color?(x) || alpha?(x))
47
+ end
48
+
49
+ def alpha? = PixelFormatter.alpha?(format)
50
+
51
+ def bits_per_pixel = PixelFormatter.bits_per_pixel(format)
52
+
53
+ alias depth bits_per_pixel
54
+
55
+ def bytes_per_pixel = PixelFormatter.bytes_per_pixel(format)
56
+
57
+ def format_name = PixelFormatter.format_name(format)
58
+
59
+ alias pixel_format_name format_name
60
+
61
+ def fourcc? = PixelFormatter.fourcc?(format)
62
+
63
+ def indexed_color? = PixelFormatter.indexed_color?(format)
64
+
65
+ def rgb_color? = PixelFormatter.rgb_color?(format)
66
+ end
67
+ end
@@ -0,0 +1,11 @@
1
+ module SDLRuby
2
+ class Rect < SDL::SDL_Rect
3
+ class << self
4
+ def [](*rect)
5
+ st = malloc(Fiddle::RUBY_FREE)
6
+ st.x, st.y, st.w, st.h = *rect
7
+ st
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,70 @@
1
+ module SDLRuby
2
+ module Renderer
3
+ module Accessor
4
+ def integer_scale? = SDL.SDL_RenderGetIntegerScale(renderer) != 0
5
+
6
+ def integer_scale=(b)
7
+ err = SDL.SDL_RenderSetIntegerScale(renderer, b ? 1 : 0)
8
+ raise SDLError if err < 0
9
+ end
10
+
11
+ def logical_size
12
+ w, h = SDL.tmp_value("int", "int")
13
+ SDL.SDL_RenderGetLogicalSize(renderer, w, h)
14
+ [w.value, h.value]
15
+ end
16
+
17
+ def logical_size=(wh)
18
+ err = SDL.SDL_RenderSetLogicalSize(renderer, *wh)
19
+ raise SDLError if err < 0
20
+ end
21
+
22
+ def output_size
23
+ x, y = SDL.tmp_value("int", "int")
24
+ err = SDL.SDL_GetRendererOutputSize(renderer, x, y)
25
+ raise SDLError if err < 0
26
+
27
+ [x.value, y.value]
28
+ end
29
+
30
+ def scale
31
+ x, y = SDL.tmp_value("float", "float")
32
+ SDL.SDL_RenderGetScale(renderer, x, y)
33
+ [x.value, y.value]
34
+ end
35
+
36
+ def scale=(xy)
37
+ err = SDL.SDL_RenderSetScale(renderer, x, y)
38
+ raise SDLError if err < 0
39
+ end
40
+
41
+ # ウィンドウ座標から対応する論理座標を戻す。
42
+ def to_logical_pos(x, y)
43
+ xp, yp = SDL.tmp_value("float", "float")
44
+ SDL.SDL_RenderWindowToLogical(renderer, x, y, xp, yp)
45
+
46
+ [xp.value, yp.value]
47
+ end
48
+
49
+ # 論理座標から対応するウィンドウの実座標を戻す。
50
+ #
51
+ def to_renderer_pos(x, y)
52
+ xp, yp = SDL.tmp_value("float", "float")
53
+ SDL.SDL_RenderLogicalToWindow(renderer, x, y, xp, yp)
54
+
55
+ [xp.value, yp.value]
56
+ end
57
+
58
+ def viewport
59
+ r = Rect[]
60
+ SDL.SDL_RenderGetViewport(renderer, r)
61
+ r.to_a
62
+ end
63
+
64
+ def viewport=(rect)
65
+ err = SDL.SDL_RenderSetViewport(renderer, Rect[*rect])
66
+ raise SDLError if err < 0
67
+ end
68
+ end
69
+ end
70
+ end