ruby-sfml 3.0.0.6 → 3.0.0.7
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.
- checksums.yaml +4 -4
- data/.rdoc_options +44 -0
- data/CHANGELOG.md +40 -3
- data/README.md +71 -25
- data/lib/sfml/app.rb +5 -0
- data/lib/sfml/assets.rb +2 -0
- data/lib/sfml/audio/listener.rb +7 -0
- data/lib/sfml/audio/music.rb +51 -0
- data/lib/sfml/audio/sound.rb +41 -0
- data/lib/sfml/audio/sound_buffer.rb +4 -0
- data/lib/sfml/audio/sound_buffer_recorder.rb +2 -0
- data/lib/sfml/audio/sound_cone.rb +1 -0
- data/lib/sfml/audio/sound_recorder.rb +5 -0
- data/lib/sfml/audio/sound_stream.rb +46 -0
- data/lib/sfml/graphics/animation.rb +10 -0
- data/lib/sfml/graphics/blend_mode.rb +1 -0
- data/lib/sfml/graphics/circle_shape.rb +16 -0
- data/lib/sfml/graphics/color.rb +31 -0
- data/lib/sfml/graphics/convex_shape.rb +9 -0
- data/lib/sfml/graphics/font.rb +2 -0
- data/lib/sfml/graphics/image.rb +2 -0
- data/lib/sfml/graphics/particle_system.rb +5 -0
- data/lib/sfml/graphics/rectangle_shape.rb +11 -0
- data/lib/sfml/graphics/render_target.rb +1 -0
- data/lib/sfml/graphics/render_texture.rb +7 -0
- data/lib/sfml/graphics/render_window.rb +26 -0
- data/lib/sfml/graphics/shape.rb +5 -0
- data/lib/sfml/graphics/shape_inspectable.rb +2 -0
- data/lib/sfml/graphics/sprite.rb +4 -0
- data/lib/sfml/graphics/sprite_sheet.rb +2 -0
- data/lib/sfml/graphics/stencil_mode.rb +1 -0
- data/lib/sfml/graphics/text.rb +19 -0
- data/lib/sfml/graphics/texture.rb +5 -0
- data/lib/sfml/graphics/texture_atlas.rb +2 -0
- data/lib/sfml/graphics/transform.rb +2 -0
- data/lib/sfml/graphics/transformable.rb +12 -0
- data/lib/sfml/graphics/vertex_array.rb +18 -0
- data/lib/sfml/graphics/vertex_buffer.rb +4 -0
- data/lib/sfml/graphics/view.rb +5 -0
- data/lib/sfml/network/ftp.rb +34 -0
- data/lib/sfml/network/http.rb +1 -0
- data/lib/sfml/network/ip_address.rb +1 -0
- data/lib/sfml/network/packet.rb +28 -0
- data/lib/sfml/network/socket_selector.rb +1 -0
- data/lib/sfml/network/tcp_listener.rb +3 -0
- data/lib/sfml/network/tcp_socket.rb +4 -0
- data/lib/sfml/network/udp_socket.rb +3 -0
- data/lib/sfml/scene.rb +2 -0
- data/lib/sfml/system/clock.rb +1 -0
- data/lib/sfml/system/rect.rb +27 -5
- data/lib/sfml/system/time.rb +22 -2
- data/lib/sfml/system/vector2.rb +42 -2
- data/lib/sfml/system/vector3.rb +45 -2
- data/lib/sfml/version.rb +1 -1
- data/lib/sfml/window/clipboard.rb +1 -0
- data/lib/sfml/window/context_settings.rb +1 -0
- data/lib/sfml/window/event.rb +2 -0
- data/lib/sfml/window/joystick.rb +3 -0
- data/lib/sfml/window/sensor.rb +1 -0
- data/lib/sfml/window/video_mode.rb +2 -0
- data/lib/sfml/window/window.rb +12 -0
- data/ruby-sfml.gemspec +6 -2
- metadata +3 -2
data/lib/sfml/audio/sound.rb
CHANGED
|
@@ -26,19 +26,29 @@ module SFML
|
|
|
26
26
|
|
|
27
27
|
attr_reader :buffer
|
|
28
28
|
|
|
29
|
+
# Replace the `SoundBuffer` this Sound is bound to. Stopping
|
|
30
|
+
# first is recommended — otherwise the change takes effect mid-frame.
|
|
29
31
|
def buffer=(new_buffer)
|
|
30
32
|
raise ArgumentError, "Sound#buffer= requires a SFML::SoundBuffer" unless new_buffer.is_a?(SoundBuffer)
|
|
31
33
|
C::Audio.sfSound_setBuffer(@handle, new_buffer.handle)
|
|
32
34
|
@buffer = new_buffer
|
|
33
35
|
end
|
|
34
36
|
|
|
37
|
+
# Start playback. If the sound was paused, resumes from there.
|
|
38
|
+
# If it was already playing, restarts from the beginning.
|
|
35
39
|
def play = C::Audio.sfSound_play(@handle)
|
|
40
|
+
# Pause playback. `#play` resumes from this point; `#stop` rewinds.
|
|
36
41
|
def pause = C::Audio.sfSound_pause(@handle)
|
|
42
|
+
# Stop playback and rewind to the start.
|
|
37
43
|
def stop = C::Audio.sfSound_stop(@handle)
|
|
38
44
|
|
|
45
|
+
# Playback state — one of `:stopped`, `:paused`, `:playing`.
|
|
39
46
|
def status = C::Audio::STATUSES[C::Audio.sfSound_getStatus(@handle)]
|
|
47
|
+
# Convenience predicate for `status == :playing`.
|
|
40
48
|
def playing? = status == :playing
|
|
49
|
+
# Convenience predicate for `status == :paused`.
|
|
41
50
|
def paused? = status == :paused
|
|
51
|
+
# Convenience predicate for `status == :stopped`.
|
|
42
52
|
def stopped? = status == :stopped
|
|
43
53
|
|
|
44
54
|
# Current playback head as a SFML::Time. Reads from the underlying
|
|
@@ -64,6 +74,7 @@ module SFML
|
|
|
64
74
|
Vector3.new(v[:x], v[:y], v[:z])
|
|
65
75
|
end
|
|
66
76
|
|
|
77
|
+
# Set the 3D velocity — accepts a Vector3 or `[x, y, z]`.
|
|
67
78
|
def velocity=(value)
|
|
68
79
|
vec = value.is_a?(Vector3) ? value : Vector3.new(*value)
|
|
69
80
|
packed = C::System::Vector3f.new
|
|
@@ -74,6 +85,7 @@ module SFML
|
|
|
74
85
|
# Per-source Doppler scale. 1.0 is realistic; bump it up for an
|
|
75
86
|
# exaggerated Doppler shift, drop to 0 to disable per-source.
|
|
76
87
|
def doppler_factor = C::Audio.sfSound_getDopplerFactor(@handle)
|
|
88
|
+
# Set the per-source Doppler scale. See `#doppler_factor`.
|
|
77
89
|
def doppler_factor=(v) C::Audio.sfSound_setDopplerFactor(@handle, v.to_f); end
|
|
78
90
|
|
|
79
91
|
# The direction the sound's cone points. Used together with
|
|
@@ -83,6 +95,7 @@ module SFML
|
|
|
83
95
|
Vector3.new(v[:x], v[:y], v[:z])
|
|
84
96
|
end
|
|
85
97
|
|
|
98
|
+
# Set the direction vector — accepts Vector3 or `[x, y, z]`.
|
|
86
99
|
def direction=(value)
|
|
87
100
|
vec = value.is_a?(Vector3) ? value : Vector3.new(*value)
|
|
88
101
|
packed = C::System::Vector3f.new
|
|
@@ -95,6 +108,8 @@ module SFML
|
|
|
95
108
|
SoundCone.from_native(C::Audio.sfSound_getCone(@handle))
|
|
96
109
|
end
|
|
97
110
|
|
|
111
|
+
# Set the cone. Accepts a `SoundCone` or a Hash with
|
|
112
|
+
# `inner_angle`, `outer_angle`, `outer_gain`.
|
|
98
113
|
def cone=(value)
|
|
99
114
|
cone =
|
|
100
115
|
case value
|
|
@@ -123,23 +138,31 @@ module SFML
|
|
|
123
138
|
C::Audio.sfSound_setEffectProcessor(@handle, @effect_cb, nil)
|
|
124
139
|
end
|
|
125
140
|
|
|
141
|
+
# `true` if the sound restarts after reaching the end.
|
|
126
142
|
def looping?
|
|
127
143
|
@looping
|
|
128
144
|
end
|
|
129
145
|
|
|
146
|
+
# Toggle looping playback. With `true`, the sound restarts from
|
|
147
|
+
# the start after every play-through.
|
|
130
148
|
def looping=(value)
|
|
131
149
|
@looping = value ? true : false
|
|
132
150
|
C::Audio.sfSound_setLooping(@handle, @looping)
|
|
133
151
|
end
|
|
134
152
|
|
|
153
|
+
# Playback volume in [0, 100] — 100 = unattenuated.
|
|
135
154
|
def volume = C::Audio.sfSound_getVolume(@handle)
|
|
136
155
|
|
|
156
|
+
# Set the playback volume in [0, 100].
|
|
137
157
|
def volume=(value)
|
|
138
158
|
C::Audio.sfSound_setVolume(@handle, value.to_f)
|
|
139
159
|
end
|
|
140
160
|
|
|
161
|
+
# Pitch multiplier. 1.0 = normal, 2.0 = octave up, 0.5 = octave
|
|
162
|
+
# down. Also shifts playback duration proportionally.
|
|
141
163
|
def pitch = C::Audio.sfSound_getPitch(@handle)
|
|
142
164
|
|
|
165
|
+
# Set the pitch multiplier — see `#pitch`.
|
|
143
166
|
def pitch=(value)
|
|
144
167
|
C::Audio.sfSound_setPitch(@handle, value.to_f)
|
|
145
168
|
end
|
|
@@ -158,25 +181,35 @@ module SFML
|
|
|
158
181
|
Vector3.from_native(C::Audio.sfSound_getPosition(@handle))
|
|
159
182
|
end
|
|
160
183
|
|
|
184
|
+
# Set the 3D position — accepts Vector3 or `[x, y, z]`.
|
|
161
185
|
def position=(value)
|
|
162
186
|
vec = value.is_a?(Vector3) ? value : Vector3.new(*value)
|
|
163
187
|
C::Audio.sfSound_setPosition(@handle, vec.to_native_f)
|
|
164
188
|
end
|
|
165
189
|
|
|
190
|
+
# Falloff sharpness with distance. 0 = no falloff, 1 = realistic
|
|
191
|
+
# (1/distance), higher = steeper.
|
|
166
192
|
def attenuation = C::Audio.sfSound_getAttenuation(@handle)
|
|
167
193
|
|
|
194
|
+
# Set the attenuation — see `#attenuation`.
|
|
168
195
|
def attenuation=(value)
|
|
169
196
|
C::Audio.sfSound_setAttenuation(@handle, value.to_f)
|
|
170
197
|
end
|
|
171
198
|
|
|
199
|
+
# Distance below which volume is not attenuated.
|
|
172
200
|
def min_distance = C::Audio.sfSound_getMinDistance(@handle)
|
|
173
201
|
|
|
202
|
+
# Set the min-distance — see `#min_distance`.
|
|
174
203
|
def min_distance=(value)
|
|
175
204
|
C::Audio.sfSound_setMinDistance(@handle, value.to_f)
|
|
176
205
|
end
|
|
177
206
|
|
|
207
|
+
# If `true`, `#position` is interpreted relative to the listener
|
|
208
|
+
# (useful for HUD/UI sounds that should stay glued to the
|
|
209
|
+
# camera).
|
|
178
210
|
def relative_to_listener? = C::Audio.sfSound_isRelativeToListener(@handle)
|
|
179
211
|
|
|
212
|
+
# Toggle listener-relative positioning.
|
|
180
213
|
def relative_to_listener=(value)
|
|
181
214
|
C::Audio.sfSound_setRelativeToListener(@handle, value ? true : false)
|
|
182
215
|
end
|
|
@@ -193,6 +226,7 @@ module SFML
|
|
|
193
226
|
# Stereo pan in [-1.0, 1.0]: -1 = full left, 0 = centre, 1 = full right.
|
|
194
227
|
def pan = C::Audio.sfSound_getPan(@handle)
|
|
195
228
|
|
|
229
|
+
# Set the stereo pan — see `#pan`.
|
|
196
230
|
def pan=(v)
|
|
197
231
|
C::Audio.sfSound_setPan(@handle, v.to_f)
|
|
198
232
|
end
|
|
@@ -203,12 +237,15 @@ module SFML
|
|
|
203
237
|
# the listener's local SFX volume).
|
|
204
238
|
def min_gain = C::Audio.sfSound_getMinGain(@handle)
|
|
205
239
|
|
|
240
|
+
# Set the min-gain floor — see `#min_gain`.
|
|
206
241
|
def min_gain=(v)
|
|
207
242
|
C::Audio.sfSound_setMinGain(@handle, v.to_f)
|
|
208
243
|
end
|
|
209
244
|
|
|
245
|
+
# The upper gain bound — see `#min_gain`.
|
|
210
246
|
def max_gain = C::Audio.sfSound_getMaxGain(@handle)
|
|
211
247
|
|
|
248
|
+
# Set the max-gain cap — see `#max_gain`.
|
|
212
249
|
def max_gain=(v)
|
|
213
250
|
C::Audio.sfSound_setMaxGain(@handle, v.to_f)
|
|
214
251
|
end
|
|
@@ -216,6 +253,7 @@ module SFML
|
|
|
216
253
|
# The distance beyond which the source is fully attenuated.
|
|
217
254
|
def max_distance = C::Audio.sfSound_getMaxDistance(@handle)
|
|
218
255
|
|
|
256
|
+
# Set the max-distance — see `#max_distance`.
|
|
219
257
|
def max_distance=(v)
|
|
220
258
|
C::Audio.sfSound_setMaxDistance(@handle, v.to_f)
|
|
221
259
|
end
|
|
@@ -224,6 +262,7 @@ module SFML
|
|
|
224
262
|
# mix time. Off → the sound plays as a simple stereo source.
|
|
225
263
|
def spatialization_enabled? = C::Audio.sfSound_isSpatializationEnabled(@handle)
|
|
226
264
|
|
|
265
|
+
# Toggle 3D spatialisation — see `#spatialization_enabled?`.
|
|
227
266
|
def spatialization_enabled=(v)
|
|
228
267
|
C::Audio.sfSound_setSpatializationEnabled(@handle, v ? true : false)
|
|
229
268
|
end
|
|
@@ -235,6 +274,8 @@ module SFML
|
|
|
235
274
|
C::Audio.sfSound_getDirectionalAttenuationFactor(@handle)
|
|
236
275
|
end
|
|
237
276
|
|
|
277
|
+
# Set the directional-attenuation factor — see
|
|
278
|
+
# `#directional_attenuation_factor`.
|
|
238
279
|
def directional_attenuation_factor=(v)
|
|
239
280
|
C::Audio.sfSound_setDirectionalAttenuationFactor(@handle, v.to_f)
|
|
240
281
|
end
|
|
@@ -79,9 +79,13 @@ module SFML
|
|
|
79
79
|
sb
|
|
80
80
|
end
|
|
81
81
|
|
|
82
|
+
# Returns the duration.
|
|
82
83
|
def duration = Time.from_native(C::Audio.sfSoundBuffer_getDuration(@handle))
|
|
84
|
+
# Returns the sample rate.
|
|
83
85
|
def sample_rate = C::Audio.sfSoundBuffer_getSampleRate(@handle)
|
|
86
|
+
# Returns the channel count.
|
|
84
87
|
def channel_count = C::Audio.sfSoundBuffer_getChannelCount(@handle)
|
|
88
|
+
# Returns the sample count.
|
|
85
89
|
def sample_count = C::Audio.sfSoundBuffer_getSampleCount(@handle)
|
|
86
90
|
|
|
87
91
|
# The decoded 16-bit signed samples as a Ruby Array of
|
|
@@ -37,6 +37,7 @@ module SFML
|
|
|
37
37
|
C::Audio.sfSoundBufferRecorder_getChannelCount(@handle)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
# Set the channel count.
|
|
40
41
|
def channel_count=(value)
|
|
41
42
|
C::Audio.sfSoundBufferRecorder_setChannelCount(@handle, Integer(value))
|
|
42
43
|
end
|
|
@@ -60,6 +61,7 @@ module SFML
|
|
|
60
61
|
name unless name.nil? || name.empty?
|
|
61
62
|
end
|
|
62
63
|
|
|
64
|
+
# Set the device.
|
|
63
65
|
def device=(name)
|
|
64
66
|
ok = C::Audio.sfSoundBufferRecorder_setDevice(@handle, name.to_s)
|
|
65
67
|
raise AudioError, "could not select recording device #{name.inspect}" unless ok
|
|
@@ -113,15 +113,20 @@ module SFML
|
|
|
113
113
|
self
|
|
114
114
|
end
|
|
115
115
|
|
|
116
|
+
# Returns the sample rate.
|
|
116
117
|
def sample_rate = C::Audio.sfSoundRecorder_getSampleRate(@handle)
|
|
118
|
+
# Returns the channel count.
|
|
117
119
|
def channel_count = C::Audio.sfSoundRecorder_getChannelCount(@handle)
|
|
118
120
|
|
|
121
|
+
# Set the channel count.
|
|
119
122
|
def channel_count=(n)
|
|
120
123
|
C::Audio.sfSoundRecorder_setChannelCount(@handle, Integer(n))
|
|
121
124
|
end
|
|
122
125
|
|
|
126
|
+
# Returns the device.
|
|
123
127
|
def device = C::Audio.sfSoundRecorder_getDevice(@handle)
|
|
124
128
|
|
|
129
|
+
# Set the device.
|
|
125
130
|
def device=(name)
|
|
126
131
|
C::Audio.sfSoundRecorder_setDevice(@handle, name.to_s) ||
|
|
127
132
|
raise(AudioError, "sfSoundRecorder_setDevice failed for #{name.inspect}")
|
|
@@ -94,16 +94,26 @@ module SFML
|
|
|
94
94
|
|
|
95
95
|
# ---- Public playback API ------------------------------------------
|
|
96
96
|
|
|
97
|
+
# Start streaming. Triggers the audio thread to start polling
|
|
98
|
+
# `#on_get_data` for chunks. Returns self.
|
|
97
99
|
def play = (C::Audio.sfSoundStream_play(@handle); self)
|
|
100
|
+
# Pause streaming. `#play` resumes from here.
|
|
98
101
|
def pause = (C::Audio.sfSoundStream_pause(@handle); self)
|
|
102
|
+
# Stop streaming and reset internal state.
|
|
99
103
|
def stop = (C::Audio.sfSoundStream_stop(@handle); self)
|
|
100
104
|
|
|
105
|
+
# Playback state — `:stopped`, `:paused`, or `:playing`.
|
|
101
106
|
def status = C::Audio::STATUSES[C::Audio.sfSoundStream_getStatus(@handle)]
|
|
107
|
+
# `status == :playing`.
|
|
102
108
|
def playing? = status == :playing
|
|
109
|
+
# `status == :paused`.
|
|
103
110
|
def paused? = status == :paused
|
|
111
|
+
# `status == :stopped`.
|
|
104
112
|
def stopped? = status == :stopped
|
|
105
113
|
|
|
114
|
+
# Channel count this stream produces (1 = mono, 2 = stereo).
|
|
106
115
|
def channel_count = C::Audio.sfSoundStream_getChannelCount(@handle)
|
|
116
|
+
# Sample rate in Hz.
|
|
107
117
|
def sample_rate = C::Audio.sfSoundStream_getSampleRate(@handle)
|
|
108
118
|
|
|
109
119
|
# Cached on the Ruby side; some OpenAL backends (notably the
|
|
@@ -113,37 +123,47 @@ module SFML
|
|
|
113
123
|
@looping == true
|
|
114
124
|
end
|
|
115
125
|
|
|
126
|
+
# Toggle looping playback.
|
|
116
127
|
def looping=(value)
|
|
117
128
|
@looping = !!value
|
|
118
129
|
C::Audio.sfSoundStream_setLooping(@handle, @looping)
|
|
119
130
|
end
|
|
120
131
|
|
|
132
|
+
# Playback volume in [0, 100].
|
|
121
133
|
def volume = C::Audio.sfSoundStream_getVolume(@handle)
|
|
122
134
|
|
|
135
|
+
# Set the volume.
|
|
123
136
|
def volume=(value)
|
|
124
137
|
C::Audio.sfSoundStream_setVolume(@handle, value.to_f)
|
|
125
138
|
end
|
|
126
139
|
|
|
140
|
+
# Pitch multiplier. 1.0 = normal.
|
|
127
141
|
def pitch = C::Audio.sfSoundStream_getPitch(@handle)
|
|
128
142
|
|
|
143
|
+
# Set the pitch.
|
|
129
144
|
def pitch=(value)
|
|
130
145
|
C::Audio.sfSoundStream_setPitch(@handle, value.to_f)
|
|
131
146
|
end
|
|
132
147
|
|
|
148
|
+
# Current playback head as `SFML::Time`.
|
|
133
149
|
def playing_offset
|
|
134
150
|
Time.from_native(C::Audio.sfSoundStream_getPlayingOffset(@handle))
|
|
135
151
|
end
|
|
136
152
|
|
|
153
|
+
# Seek to `value` (`SFML::Time` or numeric seconds). Triggers
|
|
154
|
+
# `#on_seek` on the subclass.
|
|
137
155
|
def playing_offset=(value)
|
|
138
156
|
t = value.is_a?(Time) ? value : Time.seconds(value.to_f)
|
|
139
157
|
C::Audio.sfSoundStream_setPlayingOffset(@handle, t.to_native)
|
|
140
158
|
end
|
|
141
159
|
|
|
160
|
+
# 3D position as a Vector3.
|
|
142
161
|
def position
|
|
143
162
|
v = C::Audio.sfSoundStream_getPosition(@handle)
|
|
144
163
|
Vector3.new(v[:x], v[:y], v[:z])
|
|
145
164
|
end
|
|
146
165
|
|
|
166
|
+
# Set the 3D position — accepts Vector3 or `[x, y, z]`.
|
|
147
167
|
def position=(value)
|
|
148
168
|
v = value.is_a?(Vector3) ? value : Vector3.new(*value)
|
|
149
169
|
packed = C::System::Vector3f.new
|
|
@@ -151,61 +171,79 @@ module SFML
|
|
|
151
171
|
C::Audio.sfSoundStream_setPosition(@handle, packed)
|
|
152
172
|
end
|
|
153
173
|
|
|
174
|
+
# Falloff sharpness with distance — see `Sound#attenuation`.
|
|
154
175
|
def attenuation = C::Audio.sfSoundStream_getAttenuation(@handle)
|
|
155
176
|
|
|
177
|
+
# Set the attenuation.
|
|
156
178
|
def attenuation=(value)
|
|
157
179
|
C::Audio.sfSoundStream_setAttenuation(@handle, value.to_f)
|
|
158
180
|
end
|
|
159
181
|
|
|
182
|
+
# Distance below which volume is not attenuated.
|
|
160
183
|
def min_distance = C::Audio.sfSoundStream_getMinDistance(@handle)
|
|
161
184
|
|
|
185
|
+
# Set the min-distance.
|
|
162
186
|
def min_distance=(value)
|
|
163
187
|
C::Audio.sfSoundStream_setMinDistance(@handle, value.to_f)
|
|
164
188
|
end
|
|
165
189
|
|
|
190
|
+
# `true` if `#position` is interpreted relative to the listener.
|
|
166
191
|
def relative_to_listener? = C::Audio.sfSoundStream_isRelativeToListener(@handle)
|
|
167
192
|
|
|
193
|
+
# Toggle listener-relative positioning.
|
|
168
194
|
def relative_to_listener=(value)
|
|
169
195
|
C::Audio.sfSoundStream_setRelativeToListener(@handle, !!value)
|
|
170
196
|
end
|
|
171
197
|
|
|
172
198
|
# ---- 3D-audio surface (mirror of Sound / Music) -------------------
|
|
173
199
|
|
|
200
|
+
# Stereo pan in [-1.0, 1.0].
|
|
174
201
|
def pan = C::Audio.sfSoundStream_getPan(@handle)
|
|
175
202
|
|
|
203
|
+
# Set the stereo pan.
|
|
176
204
|
def pan=(value)
|
|
177
205
|
C::Audio.sfSoundStream_setPan(@handle, value.to_f)
|
|
178
206
|
end
|
|
179
207
|
|
|
208
|
+
# Distance beyond which the source is fully attenuated.
|
|
180
209
|
def max_distance = C::Audio.sfSoundStream_getMaxDistance(@handle)
|
|
181
210
|
|
|
211
|
+
# Set the max-distance.
|
|
182
212
|
def max_distance=(value)
|
|
183
213
|
C::Audio.sfSoundStream_setMaxDistance(@handle, value.to_f)
|
|
184
214
|
end
|
|
185
215
|
|
|
216
|
+
# Lower gain bound.
|
|
186
217
|
def min_gain = C::Audio.sfSoundStream_getMinGain(@handle)
|
|
187
218
|
|
|
219
|
+
# Set the min-gain floor.
|
|
188
220
|
def min_gain=(value)
|
|
189
221
|
C::Audio.sfSoundStream_setMinGain(@handle, value.to_f)
|
|
190
222
|
end
|
|
191
223
|
|
|
224
|
+
# Upper gain bound.
|
|
192
225
|
def max_gain = C::Audio.sfSoundStream_getMaxGain(@handle)
|
|
193
226
|
|
|
227
|
+
# Set the max-gain cap.
|
|
194
228
|
def max_gain=(value)
|
|
195
229
|
C::Audio.sfSoundStream_setMaxGain(@handle, value.to_f)
|
|
196
230
|
end
|
|
197
231
|
|
|
232
|
+
# `true` if 3D positional / Doppler / cone math is applied.
|
|
198
233
|
def spatialization_enabled? = C::Audio.sfSoundStream_isSpatializationEnabled(@handle)
|
|
199
234
|
|
|
235
|
+
# Toggle 3D spatialisation.
|
|
200
236
|
def spatialization_enabled=(value)
|
|
201
237
|
C::Audio.sfSoundStream_setSpatializationEnabled(@handle, !!value)
|
|
202
238
|
end
|
|
203
239
|
|
|
240
|
+
# The direction vector for the cone.
|
|
204
241
|
def direction
|
|
205
242
|
v = C::Audio.sfSoundStream_getDirection(@handle)
|
|
206
243
|
Vector3.new(v[:x], v[:y], v[:z])
|
|
207
244
|
end
|
|
208
245
|
|
|
246
|
+
# Set the direction — accepts Vector3 or `[x, y, z]`.
|
|
209
247
|
def direction=(value)
|
|
210
248
|
vec = value.is_a?(Vector3) ? value : Vector3.new(*value)
|
|
211
249
|
packed = C::System::Vector3f.new
|
|
@@ -213,10 +251,12 @@ module SFML
|
|
|
213
251
|
C::Audio.sfSoundStream_setDirection(@handle, packed)
|
|
214
252
|
end
|
|
215
253
|
|
|
254
|
+
# Directional-attenuation cone.
|
|
216
255
|
def cone
|
|
217
256
|
SoundCone.from_native(C::Audio.sfSoundStream_getCone(@handle))
|
|
218
257
|
end
|
|
219
258
|
|
|
259
|
+
# Set the cone. Accepts a `SoundCone` or Hash.
|
|
220
260
|
def cone=(value)
|
|
221
261
|
cone =
|
|
222
262
|
case value
|
|
@@ -228,11 +268,13 @@ module SFML
|
|
|
228
268
|
C::Audio.sfSoundStream_setCone(@handle, cone.to_native)
|
|
229
269
|
end
|
|
230
270
|
|
|
271
|
+
# 3D velocity in world units / second.
|
|
231
272
|
def velocity
|
|
232
273
|
v = C::Audio.sfSoundStream_getVelocity(@handle)
|
|
233
274
|
Vector3.new(v[:x], v[:y], v[:z])
|
|
234
275
|
end
|
|
235
276
|
|
|
277
|
+
# Set the velocity — accepts Vector3 or `[x, y, z]`.
|
|
236
278
|
def velocity=(value)
|
|
237
279
|
vec = value.is_a?(Vector3) ? value : Vector3.new(*value)
|
|
238
280
|
packed = C::System::Vector3f.new
|
|
@@ -240,16 +282,20 @@ module SFML
|
|
|
240
282
|
C::Audio.sfSoundStream_setVelocity(@handle, packed)
|
|
241
283
|
end
|
|
242
284
|
|
|
285
|
+
# Per-source Doppler scale.
|
|
243
286
|
def doppler_factor = C::Audio.sfSoundStream_getDopplerFactor(@handle)
|
|
244
287
|
|
|
288
|
+
# Set the Doppler factor.
|
|
245
289
|
def doppler_factor=(value)
|
|
246
290
|
C::Audio.sfSoundStream_setDopplerFactor(@handle, value.to_f)
|
|
247
291
|
end
|
|
248
292
|
|
|
293
|
+
# Multiplier on the Listener's directional attenuation cone.
|
|
249
294
|
def directional_attenuation_factor
|
|
250
295
|
C::Audio.sfSoundStream_getDirectionalAttenuationFactor(@handle)
|
|
251
296
|
end
|
|
252
297
|
|
|
298
|
+
# Set the directional-attenuation factor.
|
|
253
299
|
def directional_attenuation_factor=(value)
|
|
254
300
|
C::Audio.sfSoundStream_setDirectionalAttenuationFactor(@handle, value.to_f)
|
|
255
301
|
end
|
|
@@ -57,6 +57,7 @@ module SFML
|
|
|
57
57
|
# meaningful for non-looping animations).
|
|
58
58
|
def done? = @done
|
|
59
59
|
|
|
60
|
+
# `true` if playing.
|
|
60
61
|
def playing? = !@done
|
|
61
62
|
|
|
62
63
|
# Advance by `dt` (a `SFML::Time` or seconds Float). Updates
|
|
@@ -107,14 +108,23 @@ module SFML
|
|
|
107
108
|
# Sprite stays accessible via `#sprite` for advanced cases
|
|
108
109
|
# (color, scale_by, custom blend states, etc.).
|
|
109
110
|
def position = @sprite.position
|
|
111
|
+
# Set the position.
|
|
110
112
|
def position=(v); @sprite.position = v; end
|
|
113
|
+
# Returns the rotation.
|
|
111
114
|
def rotation = @sprite.rotation
|
|
115
|
+
# Set the rotation.
|
|
112
116
|
def rotation=(v); @sprite.rotation = v; end
|
|
117
|
+
# Returns the scale.
|
|
113
118
|
def scale = @sprite.scale
|
|
119
|
+
# Set the scale.
|
|
114
120
|
def scale=(v); @sprite.scale = v; end
|
|
121
|
+
# Returns the origin.
|
|
115
122
|
def origin = @sprite.origin
|
|
123
|
+
# Set the origin.
|
|
116
124
|
def origin=(v); @sprite.origin = v; end
|
|
125
|
+
# Returns the color.
|
|
117
126
|
def color = @sprite.color
|
|
127
|
+
# Set the color.
|
|
118
128
|
def color=(v); @sprite.color = v; end
|
|
119
129
|
end
|
|
120
130
|
end
|
|
@@ -13,6 +13,10 @@ module SFML
|
|
|
13
13
|
include Graphics::ShapeInspectable
|
|
14
14
|
CSFML_PREFIX = :sfCircleShape
|
|
15
15
|
|
|
16
|
+
# Build a CircleShape. `radius` defaults to 10 px. Any of the
|
|
17
|
+
# standard styling / transform kwargs can be passed (`fill_color`,
|
|
18
|
+
# `outline_color`, `outline_thickness`, `texture`, `texture_rect`,
|
|
19
|
+
# `position`, `origin`, `rotation`, `scale`, `point_count`).
|
|
16
20
|
def initialize(radius: 10.0, **opts)
|
|
17
21
|
ptr = C::Graphics.sfCircleShape_create
|
|
18
22
|
raise GraphicsError, "sfCircleShape_create returned NULL" if ptr.null?
|
|
@@ -31,32 +35,44 @@ module SFML
|
|
|
31
35
|
self.scale = opts[:scale] if opts.key?(:scale)
|
|
32
36
|
end
|
|
33
37
|
|
|
38
|
+
# Radius in pixels.
|
|
34
39
|
def radius = C::Graphics.sfCircleShape_getRadius(@handle)
|
|
35
40
|
|
|
41
|
+
# Set the radius.
|
|
36
42
|
def radius=(value)
|
|
37
43
|
C::Graphics.sfCircleShape_setRadius(@handle, value.to_f)
|
|
38
44
|
end
|
|
39
45
|
|
|
46
|
+
# Number of points used to approximate the circle. Default 30
|
|
47
|
+
# (smooth); set to 3-8 for a regular polygon (triangle, square, ...).
|
|
40
48
|
def point_count = C::Graphics.sfCircleShape_getPointCount(@handle)
|
|
41
49
|
|
|
50
|
+
# Set the point count — see `#point_count`.
|
|
42
51
|
def point_count=(n)
|
|
43
52
|
C::Graphics.sfCircleShape_setPointCount(@handle, Integer(n))
|
|
44
53
|
end
|
|
45
54
|
|
|
55
|
+
# Interior fill color.
|
|
46
56
|
def fill_color = Color.from_native(C::Graphics.sfCircleShape_getFillColor(@handle))
|
|
47
57
|
|
|
58
|
+
# Set the fill color.
|
|
48
59
|
def fill_color=(c)
|
|
49
60
|
C::Graphics.sfCircleShape_setFillColor(@handle, c.to_native)
|
|
50
61
|
end
|
|
51
62
|
|
|
63
|
+
# Outline color (only visible when `#outline_thickness > 0`).
|
|
52
64
|
def outline_color = Color.from_native(C::Graphics.sfCircleShape_getOutlineColor(@handle))
|
|
53
65
|
|
|
66
|
+
# Set the outline color.
|
|
54
67
|
def outline_color=(c)
|
|
55
68
|
C::Graphics.sfCircleShape_setOutlineColor(@handle, c.to_native)
|
|
56
69
|
end
|
|
57
70
|
|
|
71
|
+
# Outline thickness in pixels. Outline is drawn outward by default —
|
|
72
|
+
# set negative for inward.
|
|
58
73
|
def outline_thickness = C::Graphics.sfCircleShape_getOutlineThickness(@handle)
|
|
59
74
|
|
|
75
|
+
# Set the outline thickness.
|
|
60
76
|
def outline_thickness=(t)
|
|
61
77
|
C::Graphics.sfCircleShape_setOutlineThickness(@handle, t.to_f)
|
|
62
78
|
end
|
data/lib/sfml/graphics/color.rb
CHANGED
|
@@ -10,6 +10,8 @@ module SFML
|
|
|
10
10
|
class Color
|
|
11
11
|
attr_reader :r, :g, :b, :a
|
|
12
12
|
|
|
13
|
+
# Build a Color from individual channel values. Each must be an
|
|
14
|
+
# Integer in [0, 255]; alpha defaults to 255 (opaque).
|
|
13
15
|
def initialize(r, g, b, a = 255)
|
|
14
16
|
@r = Integer(r)
|
|
15
17
|
@g = Integer(g)
|
|
@@ -18,9 +20,18 @@ module SFML
|
|
|
18
20
|
freeze
|
|
19
21
|
end
|
|
20
22
|
|
|
23
|
+
# Opaque RGB constructor — alias for `.new(r, g, b)`.
|
|
21
24
|
def self.rgb(r, g, b) = new(r, g, b, 255)
|
|
25
|
+
# RGBA constructor — alias for `.new(r, g, b, a)`.
|
|
22
26
|
def self.rgba(r, g, b, a) = new(r, g, b, a)
|
|
23
27
|
|
|
28
|
+
# Parse a hex color string. Accepts `#RGB` (each digit doubled),
|
|
29
|
+
# `#RRGGBB` (opaque), or `#RRGGBBAA` (with alpha). The leading
|
|
30
|
+
# `#` is optional.
|
|
31
|
+
#
|
|
32
|
+
# SFML::Color["#ff6432"] #=> Color(255, 100, 50, 255)
|
|
33
|
+
# SFML::Color["#ff643280"] #=> Color(255, 100, 50, 128)
|
|
34
|
+
# SFML::Color["#abc"] #=> Color(170, 187, 204, 255)
|
|
24
35
|
def self.[](hex)
|
|
25
36
|
str = hex.to_s.delete_prefix("#")
|
|
26
37
|
case str.length
|
|
@@ -35,17 +46,24 @@ module SFML
|
|
|
35
46
|
end
|
|
36
47
|
end
|
|
37
48
|
|
|
49
|
+
# Value equality — all four channels must match.
|
|
38
50
|
def ==(other)
|
|
39
51
|
other.is_a?(Color) && @r == other.r && @g == other.g && @b == other.b && @a == other.a
|
|
40
52
|
end
|
|
41
53
|
alias eql? ==
|
|
54
|
+
# Hash key support.
|
|
42
55
|
def hash = [@r, @g, @b, @a].hash
|
|
43
56
|
|
|
57
|
+
# `[r, g, b, a]`.
|
|
44
58
|
def to_a = [@r, @g, @b, @a]
|
|
59
|
+
# `{r:, g:, b:, a:}`.
|
|
45
60
|
def to_h = { r: @r, g: @g, b: @b, a: @a }
|
|
61
|
+
# Pattern-match support for `in [r, g, b, a]`.
|
|
46
62
|
def deconstruct = to_a
|
|
63
|
+
# Pattern-match support for `in {r:, g:, b:, a:}`.
|
|
47
64
|
def deconstruct_keys(_keys) = to_h
|
|
48
65
|
|
|
66
|
+
# String representation for debugging.
|
|
49
67
|
def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})"
|
|
50
68
|
alias inspect to_s
|
|
51
69
|
|
|
@@ -75,6 +93,7 @@ module SFML
|
|
|
75
93
|
self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native))
|
|
76
94
|
end
|
|
77
95
|
|
|
96
|
+
# Saturating channel-wise subtraction — values clamp at 0.
|
|
78
97
|
def -(other)
|
|
79
98
|
raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color)
|
|
80
99
|
self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native))
|
|
@@ -103,16 +122,28 @@ module SFML
|
|
|
103
122
|
# A nicer default than pure black for empty windows.
|
|
104
123
|
CORNFLOWER_BLUE = new(100, 149, 237)
|
|
105
124
|
|
|
125
|
+
# Convenience accessors for the standard named colors, also
|
|
126
|
+
# available as `Color::BLACK` etc. for use in constants.
|
|
106
127
|
class << self
|
|
128
|
+
# Returns the BLACK singleton.
|
|
107
129
|
def black = BLACK
|
|
130
|
+
# Returns the WHITE singleton.
|
|
108
131
|
def white = WHITE
|
|
132
|
+
# Returns the RED singleton.
|
|
109
133
|
def red = RED
|
|
134
|
+
# Returns the GREEN singleton.
|
|
110
135
|
def green = GREEN
|
|
136
|
+
# Returns the BLUE singleton.
|
|
111
137
|
def blue = BLUE
|
|
138
|
+
# Returns the YELLOW singleton.
|
|
112
139
|
def yellow = YELLOW
|
|
140
|
+
# Returns the MAGENTA singleton.
|
|
113
141
|
def magenta = MAGENTA
|
|
142
|
+
# Returns the CYAN singleton.
|
|
114
143
|
def cyan = CYAN
|
|
144
|
+
# Returns the TRANSPARENT singleton (alpha = 0).
|
|
115
145
|
def transparent = TRANSPARENT
|
|
146
|
+
# Returns the CORNFLOWER_BLUE singleton — handy default for empty windows.
|
|
116
147
|
def cornflower_blue = CORNFLOWER_BLUE
|
|
117
148
|
end
|
|
118
149
|
end
|
|
@@ -16,6 +16,8 @@ module SFML
|
|
|
16
16
|
include Graphics::ShapeInspectable
|
|
17
17
|
CSFML_PREFIX = :sfConvexShape
|
|
18
18
|
|
|
19
|
+
# Build a ConvexShape. `points:` may be passed up-front (Array of
|
|
20
|
+
# `[x, y]` / Vector2) or omitted and set later via `#points=`.
|
|
19
21
|
def initialize(points: nil, **opts)
|
|
20
22
|
ptr = C::Graphics.sfConvexShape_create
|
|
21
23
|
raise GraphicsError, "sfConvexShape_create returned NULL" if ptr.null?
|
|
@@ -33,6 +35,7 @@ module SFML
|
|
|
33
35
|
self.scale = opts[:scale] if opts.key?(:scale)
|
|
34
36
|
end
|
|
35
37
|
|
|
38
|
+
# Number of polygon vertices currently set.
|
|
36
39
|
def point_count = C::Graphics.sfConvexShape_getPointCount(@handle)
|
|
37
40
|
|
|
38
41
|
# Returns the polygon vertices as an Array of Vector2.
|
|
@@ -58,20 +61,26 @@ module SFML
|
|
|
58
61
|
C::Graphics.sfConvexShape_setPoint(@handle, Integer(index), vec.to_native_f)
|
|
59
62
|
end
|
|
60
63
|
|
|
64
|
+
# Interior fill color.
|
|
61
65
|
def fill_color = Color.from_native(C::Graphics.sfConvexShape_getFillColor(@handle))
|
|
62
66
|
|
|
67
|
+
# Set the fill color.
|
|
63
68
|
def fill_color=(c)
|
|
64
69
|
C::Graphics.sfConvexShape_setFillColor(@handle, c.to_native)
|
|
65
70
|
end
|
|
66
71
|
|
|
72
|
+
# Outline color (only visible when `#outline_thickness > 0`).
|
|
67
73
|
def outline_color = Color.from_native(C::Graphics.sfConvexShape_getOutlineColor(@handle))
|
|
68
74
|
|
|
75
|
+
# Set the outline color.
|
|
69
76
|
def outline_color=(c)
|
|
70
77
|
C::Graphics.sfConvexShape_setOutlineColor(@handle, c.to_native)
|
|
71
78
|
end
|
|
72
79
|
|
|
80
|
+
# Outline thickness in pixels — negative draws inward.
|
|
73
81
|
def outline_thickness = C::Graphics.sfConvexShape_getOutlineThickness(@handle)
|
|
74
82
|
|
|
83
|
+
# Set the outline thickness.
|
|
75
84
|
def outline_thickness=(t)
|
|
76
85
|
C::Graphics.sfConvexShape_setOutlineThickness(@handle, t.to_f)
|
|
77
86
|
end
|
data/lib/sfml/graphics/font.rb
CHANGED
data/lib/sfml/graphics/image.rb
CHANGED