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
|
@@ -45,7 +45,9 @@ module SFML
|
|
|
45
45
|
:r, :g, :b, :a,
|
|
46
46
|
:size,
|
|
47
47
|
) do
|
|
48
|
+
# `true` if alive.
|
|
48
49
|
def alive? = age < lifetime
|
|
50
|
+
# Returns the normalized age.
|
|
49
51
|
def normalized_age = age / lifetime
|
|
50
52
|
end
|
|
51
53
|
|
|
@@ -61,8 +63,11 @@ module SFML
|
|
|
61
63
|
end
|
|
62
64
|
|
|
63
65
|
attr_reader :particles, :texture
|
|
66
|
+
# Returns the size.
|
|
64
67
|
def size = @particles.size
|
|
68
|
+
# `true` if empty.
|
|
65
69
|
def empty? = @particles.empty?
|
|
70
|
+
# `true` if full.
|
|
66
71
|
def full? = @particles.size >= @max
|
|
67
72
|
|
|
68
73
|
# Spawn a new particle. Silently dropped if the pool is full
|
|
@@ -12,6 +12,8 @@ module SFML
|
|
|
12
12
|
include Graphics::ShapeInspectable
|
|
13
13
|
CSFML_PREFIX = :sfRectangleShape
|
|
14
14
|
|
|
15
|
+
# Build a RectangleShape. Required: `size:` (Vector2 or `[w, h]`).
|
|
16
|
+
# All other styling/transform kwargs match CircleShape.
|
|
15
17
|
def initialize(size:, **opts)
|
|
16
18
|
ptr = C::Graphics.sfRectangleShape_create
|
|
17
19
|
raise GraphicsError, "sfRectangleShape_create returned NULL" if ptr.null?
|
|
@@ -29,31 +31,40 @@ module SFML
|
|
|
29
31
|
self.scale = opts[:scale] if opts.key?(:scale)
|
|
30
32
|
end
|
|
31
33
|
|
|
34
|
+
# Always 4 — the four corners.
|
|
32
35
|
def point_count = C::Graphics.sfRectangleShape_getPointCount(@handle)
|
|
33
36
|
|
|
37
|
+
# Current size as a Vector2.
|
|
34
38
|
def size
|
|
35
39
|
Vector2.from_native(C::Graphics.sfRectangleShape_getSize(@handle))
|
|
36
40
|
end
|
|
37
41
|
|
|
42
|
+
# Set the size — accepts Vector2 or `[w, h]`.
|
|
38
43
|
def size=(value)
|
|
39
44
|
vec = value.is_a?(Vector2) ? value : Vector2.new(*value)
|
|
40
45
|
C::Graphics.sfRectangleShape_setSize(@handle, vec.to_native_f)
|
|
41
46
|
end
|
|
42
47
|
|
|
48
|
+
# Interior fill color.
|
|
43
49
|
def fill_color = Color.from_native(C::Graphics.sfRectangleShape_getFillColor(@handle))
|
|
44
50
|
|
|
51
|
+
# Set the fill color.
|
|
45
52
|
def fill_color=(c)
|
|
46
53
|
C::Graphics.sfRectangleShape_setFillColor(@handle, c.to_native)
|
|
47
54
|
end
|
|
48
55
|
|
|
56
|
+
# Outline color (only visible when `#outline_thickness > 0`).
|
|
49
57
|
def outline_color = Color.from_native(C::Graphics.sfRectangleShape_getOutlineColor(@handle))
|
|
50
58
|
|
|
59
|
+
# Set the outline color.
|
|
51
60
|
def outline_color=(c)
|
|
52
61
|
C::Graphics.sfRectangleShape_setOutlineColor(@handle, c.to_native)
|
|
53
62
|
end
|
|
54
63
|
|
|
64
|
+
# Outline thickness in pixels — negative draws inward.
|
|
55
65
|
def outline_thickness = C::Graphics.sfRectangleShape_getOutlineThickness(@handle)
|
|
56
66
|
|
|
67
|
+
# Set the outline thickness.
|
|
57
68
|
def outline_thickness=(t)
|
|
58
69
|
C::Graphics.sfRectangleShape_setOutlineThickness(@handle, t.to_f)
|
|
59
70
|
end
|
|
@@ -39,14 +39,18 @@ module SFML
|
|
|
39
39
|
Vector2.new(v[:x], v[:y])
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# `true` if smooth.
|
|
42
43
|
def smooth? = C::Graphics.sfRenderTexture_isSmooth(@handle)
|
|
43
44
|
|
|
45
|
+
# Set the smooth.
|
|
44
46
|
def smooth=(value)
|
|
45
47
|
C::Graphics.sfRenderTexture_setSmooth(@handle, !!value)
|
|
46
48
|
end
|
|
47
49
|
|
|
50
|
+
# `true` if repeated.
|
|
48
51
|
def repeated? = C::Graphics.sfRenderTexture_isRepeated(@handle)
|
|
49
52
|
|
|
53
|
+
# Set the repeated.
|
|
50
54
|
def repeated=(value)
|
|
51
55
|
C::Graphics.sfRenderTexture_setRepeated(@handle, !!value)
|
|
52
56
|
end
|
|
@@ -74,8 +78,11 @@ module SFML
|
|
|
74
78
|
def active=(value)
|
|
75
79
|
C::Graphics.sfRenderTexture_setActive(@handle, value ? true : false)
|
|
76
80
|
end
|
|
81
|
+
# Returns the push gl states.
|
|
77
82
|
def push_gl_states = C::Graphics.sfRenderTexture_pushGLStates(@handle)
|
|
83
|
+
# Returns the pop gl states.
|
|
78
84
|
def pop_gl_states = C::Graphics.sfRenderTexture_popGLStates(@handle)
|
|
85
|
+
# Returns the reset gl states.
|
|
79
86
|
def reset_gl_states = C::Graphics.sfRenderTexture_resetGLStates(@handle)
|
|
80
87
|
|
|
81
88
|
# Pixel-space viewport / scissor for the given view (defaults
|
|
@@ -69,10 +69,14 @@ module SFML
|
|
|
69
69
|
# What we asked for at creation time, if anything (otherwise nil).
|
|
70
70
|
attr_reader :requested_context
|
|
71
71
|
|
|
72
|
+
# `true` while the window is still alive (hasn't been closed by
|
|
73
|
+
# `#close` or the user).
|
|
72
74
|
def open?
|
|
73
75
|
C::Graphics.sfRenderWindow_isOpen(@handle)
|
|
74
76
|
end
|
|
75
77
|
|
|
78
|
+
# Close the window — the next iteration of the main loop will
|
|
79
|
+
# see `#open? == false`.
|
|
76
80
|
def close
|
|
77
81
|
C::Graphics.sfRenderWindow_close(@handle)
|
|
78
82
|
self
|
|
@@ -94,6 +98,7 @@ module SFML
|
|
|
94
98
|
self
|
|
95
99
|
end
|
|
96
100
|
|
|
101
|
+
# Change the window's title bar text.
|
|
97
102
|
def title=(value)
|
|
98
103
|
C::Graphics.sfRenderWindow_setTitle(@handle, value.to_s)
|
|
99
104
|
end
|
|
@@ -119,14 +124,18 @@ module SFML
|
|
|
119
124
|
C::Graphics.sfRenderWindow_setMouseCursorGrabbed(@handle, grabbed ? true : false)
|
|
120
125
|
end
|
|
121
126
|
|
|
127
|
+
# Cap the render loop to `value` frames per second. Set 0 to
|
|
128
|
+
# disable the cap.
|
|
122
129
|
def framerate_limit=(value)
|
|
123
130
|
C::Graphics.sfRenderWindow_setFramerateLimit(@handle, Integer(value))
|
|
124
131
|
end
|
|
125
132
|
|
|
133
|
+
# Enable / disable vertical sync.
|
|
126
134
|
def vsync=(enabled)
|
|
127
135
|
C::Graphics.sfRenderWindow_setVerticalSyncEnabled(@handle, enabled ? true : false)
|
|
128
136
|
end
|
|
129
137
|
|
|
138
|
+
# Current window size in pixels as a Vector2.
|
|
130
139
|
def size
|
|
131
140
|
v = C::Graphics.sfRenderWindow_getSize(@handle)
|
|
132
141
|
Vector2.new(v[:x], v[:y])
|
|
@@ -176,6 +185,7 @@ module SFML
|
|
|
176
185
|
C::Graphics.sfRenderWindow_setMinimumSize(@handle, _vec2u_or_nil(value))
|
|
177
186
|
end
|
|
178
187
|
|
|
188
|
+
# Upper bound on user-driven resizes — see `#minimum_size=`.
|
|
179
189
|
def maximum_size=(value)
|
|
180
190
|
C::Graphics.sfRenderWindow_setMaximumSize(@handle, _vec2u_or_nil(value))
|
|
181
191
|
end
|
|
@@ -187,7 +197,11 @@ module SFML
|
|
|
187
197
|
end
|
|
188
198
|
|
|
189
199
|
# ---- Focus ----
|
|
200
|
+
|
|
201
|
+
# `true` if this window currently has OS-level keyboard focus.
|
|
190
202
|
def focused? = C::Graphics.sfRenderWindow_hasFocus(@handle)
|
|
203
|
+
# Ask the OS to give this window focus. Cooperative — most
|
|
204
|
+
# window managers won't steal focus unconditionally.
|
|
191
205
|
def request_focus = C::Graphics.sfRenderWindow_requestFocus(@handle)
|
|
192
206
|
|
|
193
207
|
# ---- OS-window state ----
|
|
@@ -195,10 +209,14 @@ module SFML
|
|
|
195
209
|
C::Graphics.sfRenderWindow_setVisible(@handle, value ? true : false)
|
|
196
210
|
end
|
|
197
211
|
|
|
212
|
+
# Toggle key repeat. With `true`, holding a key fires repeated
|
|
213
|
+
# `:key_pressed` events; with `false` only one fires per press.
|
|
198
214
|
def key_repeat_enabled=(value)
|
|
199
215
|
C::Graphics.sfRenderWindow_setKeyRepeatEnabled(@handle, value ? true : false)
|
|
200
216
|
end
|
|
201
217
|
|
|
218
|
+
# Dead-zone for joystick axis events in [0, 100]. Axes whose
|
|
219
|
+
# absolute value is below this are reported as 0.
|
|
202
220
|
def joystick_threshold=(value)
|
|
203
221
|
C::Graphics.sfRenderWindow_setJoystickThreshold(@handle, Float(value))
|
|
204
222
|
end
|
|
@@ -208,6 +226,7 @@ module SFML
|
|
|
208
226
|
Vector2.from_native(C::Graphics.sfRenderWindow_getPosition(@handle))
|
|
209
227
|
end
|
|
210
228
|
|
|
229
|
+
# Move the window's top-left corner in desktop coordinates.
|
|
211
230
|
def position=(value)
|
|
212
231
|
vec = value.is_a?(Vector2) ? value : Vector2.new(*value)
|
|
213
232
|
v = C::System::Vector2i.new
|
|
@@ -230,11 +249,18 @@ module SFML
|
|
|
230
249
|
# current thread — the only way to use SFML rendering from a
|
|
231
250
|
# non-main thread.
|
|
232
251
|
|
|
252
|
+
# Activate / deactivate the window's GL context on the current
|
|
253
|
+
# thread. Only one context can be active per thread at a time.
|
|
233
254
|
def active=(value)
|
|
234
255
|
C::Graphics.sfRenderWindow_setActive(@handle, value ? true : false)
|
|
235
256
|
end
|
|
257
|
+
# Save SFML's GL state before raw GL calls.
|
|
236
258
|
def push_gl_states = C::Graphics.sfRenderWindow_pushGLStates(@handle)
|
|
259
|
+
# Restore SFML's GL state after raw GL calls (paired with
|
|
260
|
+
# `#push_gl_states`).
|
|
237
261
|
def pop_gl_states = C::Graphics.sfRenderWindow_popGLStates(@handle)
|
|
262
|
+
# Re-initialise SFML's GL state from scratch — heavier hammer
|
|
263
|
+
# than push/pop.
|
|
238
264
|
def reset_gl_states = C::Graphics.sfRenderWindow_resetGLStates(@handle)
|
|
239
265
|
|
|
240
266
|
# Block until an event arrives or `timeout` (a SFML::Time)
|
data/lib/sfml/graphics/shape.rb
CHANGED
|
@@ -75,18 +75,23 @@ module SFML
|
|
|
75
75
|
|
|
76
76
|
def fill_color = Color.from_native(C::Graphics.sfShape_getFillColor(@handle))
|
|
77
77
|
|
|
78
|
+
# Set the fill color.
|
|
78
79
|
def fill_color=(c)
|
|
79
80
|
C::Graphics.sfShape_setFillColor(@handle, c.to_native)
|
|
80
81
|
end
|
|
81
82
|
|
|
83
|
+
# Returns the outline color.
|
|
82
84
|
def outline_color = Color.from_native(C::Graphics.sfShape_getOutlineColor(@handle))
|
|
83
85
|
|
|
86
|
+
# Set the outline color.
|
|
84
87
|
def outline_color=(c)
|
|
85
88
|
C::Graphics.sfShape_setOutlineColor(@handle, c.to_native)
|
|
86
89
|
end
|
|
87
90
|
|
|
91
|
+
# Returns the outline thickness.
|
|
88
92
|
def outline_thickness = C::Graphics.sfShape_getOutlineThickness(@handle)
|
|
89
93
|
|
|
94
|
+
# Set the outline thickness.
|
|
90
95
|
def outline_thickness=(t)
|
|
91
96
|
C::Graphics.sfShape_setOutlineThickness(@handle, t.to_f)
|
|
92
97
|
end
|
|
@@ -24,6 +24,7 @@ module SFML
|
|
|
24
24
|
self
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# Set the texture.
|
|
27
28
|
def texture=(tex)
|
|
28
29
|
set_texture(tex, reset_rect: false)
|
|
29
30
|
end
|
|
@@ -32,6 +33,7 @@ module SFML
|
|
|
32
33
|
Rect.from_native(_csfml(:getTextureRect, @handle))
|
|
33
34
|
end
|
|
34
35
|
|
|
36
|
+
# Set the texture rect.
|
|
35
37
|
def texture_rect=(rect)
|
|
36
38
|
raise ArgumentError, "texture_rect= requires a SFML::Rect" unless rect.is_a?(Rect)
|
|
37
39
|
native = C::Graphics::IntRect.new
|
data/lib/sfml/graphics/sprite.rb
CHANGED
|
@@ -28,14 +28,17 @@ module SFML
|
|
|
28
28
|
|
|
29
29
|
attr_reader :texture
|
|
30
30
|
|
|
31
|
+
# Set the texture.
|
|
31
32
|
def texture=(new_texture)
|
|
32
33
|
raise ArgumentError, "Sprite#texture= requires a SFML::Texture" unless new_texture.is_a?(Texture)
|
|
33
34
|
C::Graphics.sfSprite_setTexture(@handle, new_texture.handle, false)
|
|
34
35
|
@texture = new_texture
|
|
35
36
|
end
|
|
36
37
|
|
|
38
|
+
# Returns the color.
|
|
37
39
|
def color = Color.from_native(C::Graphics.sfSprite_getColor(@handle))
|
|
38
40
|
|
|
41
|
+
# Set the color.
|
|
39
42
|
def color=(c)
|
|
40
43
|
C::Graphics.sfSprite_setColor(@handle, c.to_native)
|
|
41
44
|
end
|
|
@@ -48,6 +51,7 @@ module SFML
|
|
|
48
51
|
Rect.from_native(C::Graphics.sfSprite_getTextureRect(@handle))
|
|
49
52
|
end
|
|
50
53
|
|
|
54
|
+
# Set the texture rect.
|
|
51
55
|
def texture_rect=(rect)
|
|
52
56
|
raise ArgumentError, "Sprite#texture_rect= requires a SFML::Rect" unless rect.is_a?(Rect)
|
|
53
57
|
native = C::Graphics::IntRect.new
|
|
@@ -48,6 +48,7 @@ module SFML
|
|
|
48
48
|
|
|
49
49
|
attr_reader :texture, :cols, :rows, :frame_w, :frame_h
|
|
50
50
|
|
|
51
|
+
# Returns the frame count.
|
|
51
52
|
def frame_count = @regions.size
|
|
52
53
|
|
|
53
54
|
# The pixel Rect for cell `index` (0 = top-left, increases
|
|
@@ -82,6 +83,7 @@ module SFML
|
|
|
82
83
|
)
|
|
83
84
|
end
|
|
84
85
|
|
|
86
|
+
# String representation for debugging.
|
|
85
87
|
def to_s = "#<SpriteSheet #{@cols}×#{@rows} (#{@frame_w}×#{@frame_h}px cells)>"
|
|
86
88
|
alias inspect to_s
|
|
87
89
|
|
data/lib/sfml/graphics/text.rb
CHANGED
|
@@ -23,6 +23,10 @@ module SFML
|
|
|
23
23
|
strike_through: 1 << 3,
|
|
24
24
|
}.freeze
|
|
25
25
|
|
|
26
|
+
# Build a Text. `font` must be an `SFML::Font`; `string` defaults
|
|
27
|
+
# to empty. Optional kwargs: `:character_size`, `:fill_color`,
|
|
28
|
+
# `:outline_color`, `:outline_thickness`, `:style`, plus the
|
|
29
|
+
# standard transform options.
|
|
26
30
|
def initialize(font, string = "", **opts)
|
|
27
31
|
raise ArgumentError, "Text requires a SFML::Font" unless font.is_a?(Font)
|
|
28
32
|
|
|
@@ -45,6 +49,7 @@ module SFML
|
|
|
45
49
|
|
|
46
50
|
attr_reader :font
|
|
47
51
|
|
|
52
|
+
# Replace the font used to render this Text.
|
|
48
53
|
def font=(new_font)
|
|
49
54
|
raise ArgumentError, "Text#font= requires a SFML::Font" unless new_font.is_a?(Font)
|
|
50
55
|
C::Graphics.sfText_setFont(@handle, new_font.handle)
|
|
@@ -69,6 +74,8 @@ module SFML
|
|
|
69
74
|
codepoints.pack("U*")
|
|
70
75
|
end
|
|
71
76
|
|
|
77
|
+
# Replace the displayed string. Accepts any Ruby String — UTF-8
|
|
78
|
+
# codepoints are converted to UTF-32 for CSFML internally.
|
|
72
79
|
def string=(value)
|
|
73
80
|
str = value.to_s.encode("UTF-8")
|
|
74
81
|
cps = str.unpack("U*") # array of integer codepoints
|
|
@@ -77,26 +84,34 @@ module SFML
|
|
|
77
84
|
C::Graphics.sfText_setUnicodeString(@handle, buf)
|
|
78
85
|
end
|
|
79
86
|
|
|
87
|
+
# Font size in pixels (e.g. 14, 18, 24).
|
|
80
88
|
def character_size = C::Graphics.sfText_getCharacterSize(@handle)
|
|
81
89
|
|
|
90
|
+
# Set the font size.
|
|
82
91
|
def character_size=(value)
|
|
83
92
|
C::Graphics.sfText_setCharacterSize(@handle, Integer(value))
|
|
84
93
|
end
|
|
85
94
|
|
|
95
|
+
# Body fill color.
|
|
86
96
|
def fill_color = Color.from_native(C::Graphics.sfText_getFillColor(@handle))
|
|
87
97
|
|
|
98
|
+
# Set the fill color.
|
|
88
99
|
def fill_color=(c)
|
|
89
100
|
C::Graphics.sfText_setFillColor(@handle, c.to_native)
|
|
90
101
|
end
|
|
91
102
|
|
|
103
|
+
# Outline color (only visible when `#outline_thickness > 0`).
|
|
92
104
|
def outline_color = Color.from_native(C::Graphics.sfText_getOutlineColor(@handle))
|
|
93
105
|
|
|
106
|
+
# Set the outline color.
|
|
94
107
|
def outline_color=(c)
|
|
95
108
|
C::Graphics.sfText_setOutlineColor(@handle, c.to_native)
|
|
96
109
|
end
|
|
97
110
|
|
|
111
|
+
# Outline thickness in pixels.
|
|
98
112
|
def outline_thickness = C::Graphics.sfText_getOutlineThickness(@handle)
|
|
99
113
|
|
|
114
|
+
# Set the outline thickness.
|
|
100
115
|
def outline_thickness=(t)
|
|
101
116
|
C::Graphics.sfText_setOutlineThickness(@handle, t.to_f)
|
|
102
117
|
end
|
|
@@ -128,6 +143,7 @@ module SFML
|
|
|
128
143
|
# default).
|
|
129
144
|
def letter_spacing = C::Graphics.sfText_getLetterSpacing(@handle)
|
|
130
145
|
|
|
146
|
+
# Set the letter-spacing multiplier.
|
|
131
147
|
def letter_spacing=(value)
|
|
132
148
|
C::Graphics.sfText_setLetterSpacing(@handle, Float(value))
|
|
133
149
|
end
|
|
@@ -135,6 +151,7 @@ module SFML
|
|
|
135
151
|
# The line-spacing multiplier (1.0 = default).
|
|
136
152
|
def line_spacing = C::Graphics.sfText_getLineSpacing(@handle)
|
|
137
153
|
|
|
154
|
+
# Set the line-spacing multiplier.
|
|
138
155
|
def line_spacing=(value)
|
|
139
156
|
C::Graphics.sfText_setLineSpacing(@handle, Float(value))
|
|
140
157
|
end
|
|
@@ -153,6 +170,8 @@ module SFML
|
|
|
153
170
|
C::Graphics.sfText_getTransform(@handle)
|
|
154
171
|
end
|
|
155
172
|
|
|
173
|
+
# Inverse of `#transform` — maps world-space coords back to
|
|
174
|
+
# the Text's local space.
|
|
156
175
|
def inverse_transform
|
|
157
176
|
C::Graphics.sfText_getInverseTransform(@handle)
|
|
158
177
|
end
|
|
@@ -120,18 +120,23 @@ module SFML
|
|
|
120
120
|
Vector2.from_native(C::Graphics.sfTexture_getSize(@handle))
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
+
# `true` if smooth.
|
|
123
124
|
def smooth? = C::Graphics.sfTexture_isSmooth(@handle)
|
|
124
125
|
|
|
126
|
+
# Set the smooth.
|
|
125
127
|
def smooth=(value)
|
|
126
128
|
C::Graphics.sfTexture_setSmooth(@handle, !!value)
|
|
127
129
|
end
|
|
128
130
|
|
|
131
|
+
# `true` if repeated.
|
|
129
132
|
def repeated? = C::Graphics.sfTexture_isRepeated(@handle)
|
|
130
133
|
|
|
134
|
+
# Set the repeated.
|
|
131
135
|
def repeated=(value)
|
|
132
136
|
C::Graphics.sfTexture_setRepeated(@handle, !!value)
|
|
133
137
|
end
|
|
134
138
|
|
|
139
|
+
# `true` if srgb.
|
|
135
140
|
def srgb? = C::Graphics.sfTexture_isSrgb(@handle)
|
|
136
141
|
|
|
137
142
|
# Generate mipmaps for this texture. Returns `true` if the
|
|
@@ -48,6 +48,7 @@ module SFML
|
|
|
48
48
|
|
|
49
49
|
attr_reader :texture, :source
|
|
50
50
|
|
|
51
|
+
# Returns the frame names.
|
|
51
52
|
def frame_names = @regions.keys
|
|
52
53
|
|
|
53
54
|
# @return [SFML::Rect] the pixel rect for frame `name`.
|
|
@@ -90,6 +91,7 @@ module SFML
|
|
|
90
91
|
# walk_frames = atlas.regions.select { |k, _| k.start_with?("walk-") }
|
|
91
92
|
def regions = @regions
|
|
92
93
|
|
|
94
|
+
# String representation for debugging.
|
|
93
95
|
def to_s = "#<TextureAtlas #{@regions.size} frames#{@source ? " from #{File.basename(@source)}" : ""}>"
|
|
94
96
|
alias inspect to_s
|
|
95
97
|
|
|
@@ -125,8 +125,10 @@ module SFML
|
|
|
125
125
|
C::Graphics.sfTransform_equal(@struct.pointer, other.struct.pointer)
|
|
126
126
|
end
|
|
127
127
|
alias eql? ==
|
|
128
|
+
# Returns the hash.
|
|
128
129
|
def hash = matrix.hash
|
|
129
130
|
|
|
131
|
+
# String representation for debugging.
|
|
130
132
|
def to_s = "Transform(#{matrix.map { |v| v.round(3) }.inspect})"
|
|
131
133
|
alias inspect to_s
|
|
132
134
|
|
|
@@ -11,48 +11,60 @@ module SFML
|
|
|
11
11
|
# negligible against any GPU work, but the wins on maintainability are
|
|
12
12
|
# large — adding a new shape becomes ~5 lines.
|
|
13
13
|
module Transformable
|
|
14
|
+
# Current 2D position as a Vector2.
|
|
14
15
|
def position
|
|
15
16
|
Vector2.from_native(_csfml(:getPosition, @handle))
|
|
16
17
|
end
|
|
17
18
|
|
|
19
|
+
# Move to absolute `[x, y]` — accepts Vector2 or `[x, y]` Array.
|
|
18
20
|
def position=(value)
|
|
19
21
|
_csfml(:setPosition, @handle, _coerce_vec2(value).to_native_f)
|
|
20
22
|
end
|
|
21
23
|
|
|
24
|
+
# Current rotation in degrees (counter-clockwise positive).
|
|
22
25
|
def rotation
|
|
23
26
|
_csfml(:getRotation, @handle)
|
|
24
27
|
end
|
|
25
28
|
|
|
29
|
+
# Set absolute rotation in degrees.
|
|
26
30
|
def rotation=(degrees)
|
|
27
31
|
_csfml(:setRotation, @handle, degrees.to_f)
|
|
28
32
|
end
|
|
29
33
|
|
|
34
|
+
# Current scale factors as a Vector2 (`[1, 1]` means original size).
|
|
30
35
|
def scale
|
|
31
36
|
Vector2.from_native(_csfml(:getScale, @handle))
|
|
32
37
|
end
|
|
33
38
|
|
|
39
|
+
# Set the scale — accepts Vector2 or `[sx, sy]` Array.
|
|
34
40
|
def scale=(value)
|
|
35
41
|
_csfml(:setScale, @handle, _coerce_vec2(value).to_native_f)
|
|
36
42
|
end
|
|
37
43
|
|
|
44
|
+
# The local origin (pivot for rotation/scale). Default is `[0, 0]`
|
|
45
|
+
# — set it to the centre of the bounding box for "rotate in place".
|
|
38
46
|
def origin
|
|
39
47
|
Vector2.from_native(_csfml(:getOrigin, @handle))
|
|
40
48
|
end
|
|
41
49
|
|
|
50
|
+
# Set the origin — accepts Vector2 or `[x, y]` Array.
|
|
42
51
|
def origin=(value)
|
|
43
52
|
_csfml(:setOrigin, @handle, _coerce_vec2(value).to_native_f)
|
|
44
53
|
end
|
|
45
54
|
|
|
55
|
+
# Translate by `offset` (relative move). Chainable — returns self.
|
|
46
56
|
def move(offset)
|
|
47
57
|
_csfml(:move, @handle, _coerce_vec2(offset).to_native_f)
|
|
48
58
|
self
|
|
49
59
|
end
|
|
50
60
|
|
|
61
|
+
# Rotate by `degrees` (relative). Chainable.
|
|
51
62
|
def rotate(degrees)
|
|
52
63
|
_csfml(:rotate, @handle, degrees.to_f)
|
|
53
64
|
self
|
|
54
65
|
end
|
|
55
66
|
|
|
67
|
+
# Multiply current scale by `factors` (relative scale). Chainable.
|
|
56
68
|
def scale_by(factors)
|
|
57
69
|
_csfml(:scale, @handle, _coerce_vec2(factors).to_native_f)
|
|
58
70
|
self
|
|
@@ -23,6 +23,9 @@ module SFML
|
|
|
23
23
|
PRIMITIVE_TYPES = %i[points lines line_strip triangles triangle_strip triangle_fan].freeze
|
|
24
24
|
PRIMITIVE_INDEX = PRIMITIVE_TYPES.each_with_index.to_h.freeze
|
|
25
25
|
|
|
26
|
+
# Build an empty VertexArray. `primitive_type` chooses how
|
|
27
|
+
# vertices form geometry (see class doc). `vertices` is an
|
|
28
|
+
# optional initial list — same as calling `#append` after.
|
|
26
29
|
def initialize(primitive_type = :points, vertices = nil)
|
|
27
30
|
ptr = C::Graphics.sfVertexArray_create
|
|
28
31
|
raise GraphicsError, "sfVertexArray_create returned NULL" if ptr.null?
|
|
@@ -32,10 +35,13 @@ module SFML
|
|
|
32
35
|
vertices&.each { |v| append(v) }
|
|
33
36
|
end
|
|
34
37
|
|
|
38
|
+
# Current primitive type as a Symbol (one of `PRIMITIVE_TYPES`).
|
|
35
39
|
def primitive_type
|
|
36
40
|
PRIMITIVE_TYPES[C::Graphics.sfVertexArray_getPrimitiveType(@handle)] || :unknown
|
|
37
41
|
end
|
|
38
42
|
|
|
43
|
+
# Change the primitive type. Raises `ArgumentError` for unknown
|
|
44
|
+
# symbols.
|
|
39
45
|
def primitive_type=(type)
|
|
40
46
|
code = PRIMITIVE_INDEX.fetch(type) do
|
|
41
47
|
raise ArgumentError,
|
|
@@ -44,22 +50,29 @@ module SFML
|
|
|
44
50
|
C::Graphics.sfVertexArray_setPrimitiveType(@handle, code)
|
|
45
51
|
end
|
|
46
52
|
|
|
53
|
+
# Number of vertices currently in the array.
|
|
47
54
|
def size = C::Graphics.sfVertexArray_getVertexCount(@handle)
|
|
48
55
|
alias length size
|
|
49
56
|
alias count size
|
|
50
57
|
|
|
58
|
+
# `true` if there are no vertices.
|
|
51
59
|
def empty? = size.zero?
|
|
52
60
|
|
|
61
|
+
# Remove all vertices. Chainable.
|
|
53
62
|
def clear
|
|
54
63
|
C::Graphics.sfVertexArray_clear(@handle)
|
|
55
64
|
self
|
|
56
65
|
end
|
|
57
66
|
|
|
67
|
+
# Resize to exactly `n` vertices, allocating defaults if growing.
|
|
68
|
+
# Useful when you want to index-assign into the array directly.
|
|
58
69
|
def resize(n)
|
|
59
70
|
C::Graphics.sfVertexArray_resize(@handle, Integer(n))
|
|
60
71
|
self
|
|
61
72
|
end
|
|
62
73
|
|
|
74
|
+
# Add a vertex at the end. Returns self so calls can chain
|
|
75
|
+
# (`va << v1 << v2`).
|
|
63
76
|
def append(vertex)
|
|
64
77
|
C::Graphics.sfVertexArray_append(@handle, vertex.to_native)
|
|
65
78
|
self
|
|
@@ -76,6 +89,8 @@ module SFML
|
|
|
76
89
|
Vertex.from_native(C::Graphics::Vertex.new(ptr))
|
|
77
90
|
end
|
|
78
91
|
|
|
92
|
+
# In-place vertex replacement. Bounds-checked on the Ruby side
|
|
93
|
+
# because CSFML's getter aborts the process for out-of-range.
|
|
79
94
|
def []=(index, vertex)
|
|
80
95
|
i = Integer(index)
|
|
81
96
|
# CSFML's sfVertexArray_getVertex aborts the process on out-of-range
|
|
@@ -95,12 +110,15 @@ module SFML
|
|
|
95
110
|
vertex
|
|
96
111
|
end
|
|
97
112
|
|
|
113
|
+
# Yield every vertex in order. Returns an Enumerator without a
|
|
114
|
+
# block — makes `va.map`, `va.select`, etc. work via Enumerable.
|
|
98
115
|
def each
|
|
99
116
|
return enum_for(:each) unless block_given?
|
|
100
117
|
size.times { |i| yield self[i] }
|
|
101
118
|
self
|
|
102
119
|
end
|
|
103
120
|
|
|
121
|
+
# Axis-aligned bounding box of all current vertices, as a Rect.
|
|
104
122
|
def bounds
|
|
105
123
|
Rect.from_native(C::Graphics.sfVertexArray_getBounds(@handle))
|
|
106
124
|
end
|
|
@@ -56,6 +56,7 @@ module SFML
|
|
|
56
56
|
update(vertices) if vertices && !vertices.empty?
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
# Returns the count.
|
|
59
60
|
def count = C::Graphics.sfVertexBuffer_getVertexCount(@handle)
|
|
60
61
|
alias size count
|
|
61
62
|
alias length count
|
|
@@ -64,6 +65,7 @@ module SFML
|
|
|
64
65
|
PRIMITIVE_TYPES[C::Graphics.sfVertexBuffer_getPrimitiveType(@handle)] || :unknown
|
|
65
66
|
end
|
|
66
67
|
|
|
68
|
+
# Set the primitive type.
|
|
67
69
|
def primitive_type=(type)
|
|
68
70
|
idx = PRIMITIVE_INDEX.fetch(type) do
|
|
69
71
|
raise ArgumentError, "Unknown primitive type: #{type.inspect}"
|
|
@@ -75,6 +77,7 @@ module SFML
|
|
|
75
77
|
USAGES[C::Graphics.sfVertexBuffer_getUsage(@handle)] || :unknown
|
|
76
78
|
end
|
|
77
79
|
|
|
80
|
+
# Set the usage.
|
|
78
81
|
def usage=(value)
|
|
79
82
|
idx = USAGE_INDEX.fetch(value) do
|
|
80
83
|
raise ArgumentError, "Unknown VertexBuffer usage: #{value.inspect}"
|
|
@@ -106,6 +109,7 @@ module SFML
|
|
|
106
109
|
self
|
|
107
110
|
end
|
|
108
111
|
|
|
112
|
+
# Returns the native handle.
|
|
109
113
|
def native_handle = C::Graphics.sfVertexBuffer_getNativeHandle(@handle)
|
|
110
114
|
|
|
111
115
|
# Bind this VBO as the active vertex buffer for the GL pipeline.
|
data/lib/sfml/graphics/view.rb
CHANGED
|
@@ -59,6 +59,7 @@ module SFML
|
|
|
59
59
|
Vector2.from_native(C::Graphics.sfView_getCenter(@handle))
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
# Set the center.
|
|
62
63
|
def center=(value)
|
|
63
64
|
C::Graphics.sfView_setCenter(@handle, _vec2(value).to_native_f)
|
|
64
65
|
end
|
|
@@ -67,6 +68,7 @@ module SFML
|
|
|
67
68
|
Vector2.from_native(C::Graphics.sfView_getSize(@handle))
|
|
68
69
|
end
|
|
69
70
|
|
|
71
|
+
# Set the size.
|
|
70
72
|
def size=(value)
|
|
71
73
|
C::Graphics.sfView_setSize(@handle, _vec2(value).to_native_f)
|
|
72
74
|
end
|
|
@@ -75,6 +77,7 @@ module SFML
|
|
|
75
77
|
C::Graphics.sfView_getRotation(@handle)
|
|
76
78
|
end
|
|
77
79
|
|
|
80
|
+
# Set the rotation.
|
|
78
81
|
def rotation=(degrees)
|
|
79
82
|
C::Graphics.sfView_setRotation(@handle, degrees.to_f)
|
|
80
83
|
end
|
|
@@ -86,6 +89,7 @@ module SFML
|
|
|
86
89
|
Rect.from_native(C::Graphics.sfView_getViewport(@handle))
|
|
87
90
|
end
|
|
88
91
|
|
|
92
|
+
# Set the viewport.
|
|
89
93
|
def viewport=(rect)
|
|
90
94
|
raise ArgumentError, "View#viewport= needs a SFML::Rect" unless rect.is_a?(Rect)
|
|
91
95
|
C::Graphics.sfView_setViewport(@handle, _to_floatrect(rect))
|
|
@@ -99,6 +103,7 @@ module SFML
|
|
|
99
103
|
Rect.from_native(C::Graphics.sfView_getScissor(@handle))
|
|
100
104
|
end
|
|
101
105
|
|
|
106
|
+
# Set the scissor.
|
|
102
107
|
def scissor=(rect)
|
|
103
108
|
raise ArgumentError, "View#scissor= needs a SFML::Rect" unless rect.is_a?(Rect)
|
|
104
109
|
C::Graphics.sfView_setScissor(@handle, _to_floatrect(rect))
|