ruby-sfml 3.0.0.7 → 3.0.0.8
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/CHANGELOG.md +26 -4
- data/lib/sfml/app.rb +5 -0
- data/lib/sfml/assets.rb +26 -4
- data/lib/sfml/audio/sound.rb +1 -0
- data/lib/sfml/audio/sound_buffer.rb +1 -0
- data/lib/sfml/audio/sound_buffer_recorder.rb +3 -0
- data/lib/sfml/audio/sound_cone.rb +2 -0
- data/lib/sfml/audio/sound_recorder.rb +2 -0
- data/lib/sfml/audio/sound_stream.rb +1 -0
- data/lib/sfml/graphics/animation.rb +1 -0
- data/lib/sfml/graphics/blend_mode.rb +6 -0
- data/lib/sfml/graphics/circle_shape.rb +1 -0
- data/lib/sfml/graphics/color.rb +11 -0
- data/lib/sfml/graphics/convex_shape.rb +1 -0
- data/lib/sfml/graphics/font.rb +1 -0
- data/lib/sfml/graphics/image.rb +5 -0
- data/lib/sfml/graphics/particle_system.rb +2 -0
- data/lib/sfml/graphics/rectangle_shape.rb +1 -0
- data/lib/sfml/graphics/render_states.rb +3 -0
- data/lib/sfml/graphics/render_target.rb +4 -0
- data/lib/sfml/graphics/render_texture.rb +2 -0
- data/lib/sfml/graphics/render_window.rb +2 -0
- data/lib/sfml/graphics/shader.rb +4 -0
- data/lib/sfml/graphics/shape.rb +2 -0
- data/lib/sfml/graphics/shape_inspectable.rb +4 -0
- data/lib/sfml/graphics/sprite.rb +8 -0
- data/lib/sfml/graphics/sprite_sheet.rb +2 -0
- data/lib/sfml/graphics/stencil_mode.rb +4 -0
- data/lib/sfml/graphics/text.rb +3 -0
- data/lib/sfml/graphics/texture.rb +3 -0
- data/lib/sfml/graphics/texture_atlas.rb +2 -0
- data/lib/sfml/graphics/transform.rb +6 -0
- data/lib/sfml/graphics/transformable_object.rb +3 -0
- data/lib/sfml/graphics/vertex.rb +2 -0
- data/lib/sfml/graphics/vertex_array.rb +2 -0
- data/lib/sfml/graphics/vertex_buffer.rb +9 -0
- data/lib/sfml/graphics/view.rb +5 -0
- data/lib/sfml/keybindings.rb +1 -0
- data/lib/sfml/network/ftp.rb +2 -0
- data/lib/sfml/network/http.rb +11 -1
- data/lib/sfml/network/ip_address.rb +10 -0
- data/lib/sfml/network/packet.rb +2 -0
- data/lib/sfml/network/socket_selector.rb +5 -0
- data/lib/sfml/network/tcp_listener.rb +1 -0
- data/lib/sfml/network/tcp_socket.rb +3 -0
- data/lib/sfml/network/udp_socket.rb +4 -0
- data/lib/sfml/scene.rb +1 -0
- data/lib/sfml/system/clock.rb +10 -1
- data/lib/sfml/system/rect.rb +2 -0
- data/lib/sfml/system/time.rb +3 -0
- data/lib/sfml/system/vector2.rb +3 -0
- data/lib/sfml/system/vector3.rb +3 -0
- data/lib/sfml/version.rb +1 -1
- data/lib/sfml/window/clipboard.rb +1 -0
- data/lib/sfml/window/context_settings.rb +3 -0
- data/lib/sfml/window/cursor.rb +1 -0
- data/lib/sfml/window/event.rb +13 -1
- data/lib/sfml/window/joystick.rb +1 -0
- data/lib/sfml/window/keyboard.rb +7 -0
- data/lib/sfml/window/mouse.rb +2 -0
- data/lib/sfml/window/sensor.rb +5 -0
- data/lib/sfml/window/video_mode.rb +4 -0
- data/lib/sfml/window/window.rb +19 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '09e173bcbce249d3bdcec7722e2348a3cb7e341a7ada2e223c0da44fdfc2e136'
|
|
4
|
+
data.tar.gz: a3d08d4a035fc9a1942e39251bbfec2f1213bb81f5a146fcae31ae1617b2757a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d7a28fd63f84d1c9b5b86b1a55d421245b9e2bf8fb961868b90f185e77e132182c1b292f52d2a070be553528bc0455f3838be8c9fab8de66d1a0e7cfd079621c
|
|
7
|
+
data.tar.gz: 9823d03be099a6986226d155a44459419b5b6593e700e5c7745c40619465fe60afef4791039f8caab2d511c71159bb6c0a4bac11fb19c0e8be4c79227d61e4b0
|
data/CHANGELOG.md
CHANGED
|
@@ -10,12 +10,34 @@ HTML API docs: <https://ruby-sfml-doc.netlify.app/>
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [3.0.0.8] — 2026-05-12
|
|
14
|
+
|
|
15
|
+
Continued documentation pass. RDoc coverage went from **68% → 87%**
|
|
16
|
+
on top of 3.0.0.7's first pass — every public class, module, and
|
|
17
|
+
attribute is now documented, plus all the simple
|
|
18
|
+
setter/getter/predicate methods. Docs site:
|
|
19
|
+
<https://ruby-sfml-doc.netlify.app/>.
|
|
20
|
+
|
|
21
|
+
### Changed — documentation
|
|
22
|
+
|
|
23
|
+
- All 63 `attr_reader` / `attr_accessor` declarations now carry a
|
|
24
|
+
one-line description (62 → 0 undocumented).
|
|
25
|
+
- 72 of 97 module-level constants now documented (was 23) — every
|
|
26
|
+
`CODES` / `INDEX` table, `STATUSES` enum, `DEFAULT_*` sentinel,
|
|
27
|
+
and named-color singleton has a sentence.
|
|
28
|
+
- Hand-written docstrings on `Assets`, `Clock`, `Window` (bare),
|
|
29
|
+
`Sprite`, `View`, `Transform`, `SocketSelector`, `Http`,
|
|
30
|
+
`IpAddress`, `Event` — the methods that survived the previous
|
|
31
|
+
pass without docs.
|
|
32
|
+
- Final aggressive auto-doc pass fills setter / getter /
|
|
33
|
+
predicate / accessor patterns the conservative pass skipped.
|
|
34
|
+
|
|
13
35
|
## [3.0.0.7] — 2026-05-12
|
|
14
36
|
|
|
15
|
-
Documentation pass.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
new docs site at <https://ruby-sfml-doc.netlify.app/>.
|
|
37
|
+
Documentation pass. RDoc coverage went from **36% → 68%** —
|
|
38
|
+
every public class, module, and the high-traffic methods now
|
|
39
|
+
carry at least a one-line description. Pair this release with
|
|
40
|
+
the new docs site at <https://ruby-sfml-doc.netlify.app/>.
|
|
19
41
|
|
|
20
42
|
### Changed — documentation
|
|
21
43
|
|
data/lib/sfml/app.rb
CHANGED
|
@@ -36,6 +36,7 @@ module SFML
|
|
|
36
36
|
# case-by-case basis. Subclasses inherit their parent's settings
|
|
37
37
|
# — set one in a base class, override in a subclass.
|
|
38
38
|
class App
|
|
39
|
+
# Names of every class-level configuration macro on `SFML::App`.
|
|
39
40
|
CONFIG_KEYS = %i[
|
|
40
41
|
width height title
|
|
41
42
|
framerate vsync background
|
|
@@ -84,7 +85,9 @@ module SFML
|
|
|
84
85
|
|
|
85
86
|
include InputQueries
|
|
86
87
|
|
|
88
|
+
# The Backing SFML::RenderWindow.
|
|
87
89
|
attr_reader :window
|
|
90
|
+
# The background color.
|
|
88
91
|
attr_accessor :background_color
|
|
89
92
|
|
|
90
93
|
# Per-instance kwargs override anything set at the class level.
|
|
@@ -241,10 +244,12 @@ module SFML
|
|
|
241
244
|
end
|
|
242
245
|
end
|
|
243
246
|
|
|
247
|
+
# Returns the update.
|
|
244
248
|
def update(dt)
|
|
245
249
|
@current_scene&.update(dt)
|
|
246
250
|
end
|
|
247
251
|
|
|
252
|
+
# Returns the draw.
|
|
248
253
|
def draw
|
|
249
254
|
@current_scene&.draw
|
|
250
255
|
end
|
data/lib/sfml/assets.rb
CHANGED
|
@@ -14,29 +14,41 @@ module SFML
|
|
|
14
14
|
#
|
|
15
15
|
# Cache survives until you call .clear or the process exits.
|
|
16
16
|
module Assets
|
|
17
|
+
# File extensions recognised as image / texture assets.
|
|
17
18
|
TEXTURE_EXTS = %w[.png .jpg .jpeg .bmp .gif .tga].freeze
|
|
19
|
+
# File extensions recognised as short-sound assets.
|
|
18
20
|
SOUND_EXTS = %w[.wav .ogg .flac .mp3].freeze
|
|
21
|
+
# File extensions recognised as music (streamed) assets — same as `SOUND_EXTS`.
|
|
19
22
|
MUSIC_EXTS = SOUND_EXTS
|
|
23
|
+
# File extensions recognised as font assets.
|
|
20
24
|
FONT_EXTS = %w[.ttf .otf].freeze
|
|
21
25
|
|
|
22
26
|
class NotFound < SFML::Error; end
|
|
23
27
|
|
|
24
28
|
class << self
|
|
29
|
+
# Current list of directories scanned by `#font`, `#texture`,
|
|
30
|
+
# etc. Defaults to `<dir of $0>/assets/`. Mutate via
|
|
31
|
+
# `#root=` / `#add_search_path` / `#search_paths=`.
|
|
25
32
|
def search_paths
|
|
26
33
|
@search_paths ||= [default_root]
|
|
27
34
|
end
|
|
28
35
|
|
|
29
|
-
#
|
|
36
|
+
# Replace the entire search-path list. Resets the cache so
|
|
37
|
+
# the next load re-resolves from the new locations.
|
|
30
38
|
def search_paths=(paths)
|
|
31
39
|
@search_paths = Array(paths).map { |p| File.expand_path(p) }
|
|
32
40
|
@cache&.clear
|
|
33
41
|
end
|
|
34
42
|
|
|
35
|
-
#
|
|
43
|
+
# Convenience for "use exactly this one directory" — shorthand
|
|
44
|
+
# for `search_paths = [path]`.
|
|
36
45
|
def root=(path)
|
|
37
46
|
self.search_paths = [path]
|
|
38
47
|
end
|
|
39
48
|
|
|
49
|
+
# Append a directory to the end of `#search_paths` unless it's
|
|
50
|
+
# already present. Useful for adding mod / DLC directories
|
|
51
|
+
# without nuking the default search root.
|
|
40
52
|
def add_search_path(path)
|
|
41
53
|
search_paths << File.expand_path(path) unless search_paths.include?(File.expand_path(path))
|
|
42
54
|
end
|
|
@@ -48,20 +60,25 @@ module SFML
|
|
|
48
60
|
self
|
|
49
61
|
end
|
|
50
62
|
|
|
63
|
+
# Load (or fetch from cache) an `SFML::Font` by name — searches
|
|
64
|
+
# `#search_paths` for any of `FONT_EXTS`, falls back to system
|
|
65
|
+
# fonts via `Font.find`.
|
|
51
66
|
def font(name)
|
|
52
67
|
cache[[:font, name]] ||= load_font(name)
|
|
53
68
|
end
|
|
54
69
|
|
|
70
|
+
# Load (or fetch from cache) an `SFML::Texture` by name.
|
|
55
71
|
def texture(name)
|
|
56
72
|
cache[[:texture, name]] ||= load_texture(name)
|
|
57
73
|
end
|
|
58
74
|
|
|
75
|
+
# Load (or fetch from cache) an `SFML::SoundBuffer` by name.
|
|
59
76
|
def sound(name)
|
|
60
77
|
cache[[:sound, name]] ||= load_sound_buffer(name)
|
|
61
78
|
end
|
|
62
79
|
|
|
63
|
-
# Music
|
|
64
|
-
#
|
|
80
|
+
# Load a fresh `SFML::Music` by name. **Not cached** — each
|
|
81
|
+
# caller gets its own playback position.
|
|
65
82
|
def music(name)
|
|
66
83
|
path = locate(name, MUSIC_EXTS) or raise NotFound,
|
|
67
84
|
"Music #{name.inspect} not found. Searched: #{search_paths.inspect}"
|
|
@@ -70,14 +87,17 @@ module SFML
|
|
|
70
87
|
|
|
71
88
|
private
|
|
72
89
|
|
|
90
|
+
# Returns the cache.
|
|
73
91
|
def cache
|
|
74
92
|
@cache ||= {}
|
|
75
93
|
end
|
|
76
94
|
|
|
95
|
+
# Returns the default root.
|
|
77
96
|
def default_root
|
|
78
97
|
File.expand_path("assets", File.dirname($PROGRAM_NAME || "."))
|
|
79
98
|
end
|
|
80
99
|
|
|
100
|
+
# Returns the load font.
|
|
81
101
|
def load_font(name)
|
|
82
102
|
path = locate(name, FONT_EXTS)
|
|
83
103
|
return Font.load(path) if path
|
|
@@ -87,12 +107,14 @@ module SFML
|
|
|
87
107
|
"Font #{name.inspect} not found in #{search_paths.inspect} or system fonts"
|
|
88
108
|
end
|
|
89
109
|
|
|
110
|
+
# Returns the load texture.
|
|
90
111
|
def load_texture(name)
|
|
91
112
|
path = locate(name, TEXTURE_EXTS) or raise NotFound,
|
|
92
113
|
"Texture #{name.inspect} not found. Searched: #{search_paths.inspect}"
|
|
93
114
|
Texture.load(path)
|
|
94
115
|
end
|
|
95
116
|
|
|
117
|
+
# Returns the load sound buffer.
|
|
96
118
|
def load_sound_buffer(name)
|
|
97
119
|
path = locate(name, SOUND_EXTS) or raise NotFound,
|
|
98
120
|
"Sound #{name.inspect} not found. Searched: #{search_paths.inspect}"
|
data/lib/sfml/audio/sound.rb
CHANGED
|
@@ -6,6 +6,7 @@ module SFML
|
|
|
6
6
|
# sound = SFML::Sound.new(buffer)
|
|
7
7
|
# sound.play
|
|
8
8
|
class SoundBuffer
|
|
9
|
+
# Returns the self.
|
|
9
10
|
def self.load(path)
|
|
10
11
|
ptr = C::Audio.sfSoundBuffer_createFromFile(path.to_s)
|
|
11
12
|
raise LoadError, "Could not load sound buffer from #{path.inspect}" if ptr.null?
|
|
@@ -24,15 +24,18 @@ module SFML
|
|
|
24
24
|
C::Audio.sfSoundBufferRecorder_start(@handle, Integer(sample_rate))
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# Returns the stop.
|
|
27
28
|
def stop
|
|
28
29
|
C::Audio.sfSoundBufferRecorder_stop(@handle)
|
|
29
30
|
self
|
|
30
31
|
end
|
|
31
32
|
|
|
33
|
+
# Returns the sample rate.
|
|
32
34
|
def sample_rate
|
|
33
35
|
C::Audio.sfSoundBufferRecorder_getSampleRate(@handle)
|
|
34
36
|
end
|
|
35
37
|
|
|
38
|
+
# Returns the channel count.
|
|
36
39
|
def channel_count
|
|
37
40
|
C::Audio.sfSoundBufferRecorder_getChannelCount(@handle)
|
|
38
41
|
end
|
|
@@ -12,6 +12,7 @@ module SFML
|
|
|
12
12
|
# inner_angle: 30, outer_angle: 90, outer_gain: 0.2,
|
|
13
13
|
# )
|
|
14
14
|
class SoundCone
|
|
15
|
+
# The inner angle, outer angle, outer gain components.
|
|
15
16
|
attr_reader :inner_angle, :outer_angle, :outer_gain
|
|
16
17
|
|
|
17
18
|
def initialize(inner_angle:, outer_angle:, outer_gain:)
|
|
@@ -31,6 +32,7 @@ module SFML
|
|
|
31
32
|
# Returns the hash.
|
|
32
33
|
def hash = [inner_angle, outer_angle, outer_gain].hash
|
|
33
34
|
|
|
35
|
+
# Returns the to s.
|
|
34
36
|
def to_s
|
|
35
37
|
"SoundCone(inner=#{inner_angle}°, outer=#{outer_angle}°, outer_gain=#{outer_gain})"
|
|
36
38
|
end
|
|
@@ -43,6 +43,7 @@ module SFML
|
|
|
43
43
|
C::Audio.sfSoundRecorder_isAvailable
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
+
# Returns the self.
|
|
46
47
|
def self.default_device
|
|
47
48
|
C::Audio.sfSoundRecorder_getDefaultDevice
|
|
48
49
|
end
|
|
@@ -108,6 +109,7 @@ module SFML
|
|
|
108
109
|
self
|
|
109
110
|
end
|
|
110
111
|
|
|
112
|
+
# Returns the stop.
|
|
111
113
|
def stop
|
|
112
114
|
C::Audio.sfSoundRecorder_stop(@handle)
|
|
113
115
|
self
|
|
@@ -44,6 +44,7 @@ module SFML
|
|
|
44
44
|
# variable, store in an instance var). If the Ruby object is GC'd
|
|
45
45
|
# while CSFML is still calling callbacks, the process crashes.
|
|
46
46
|
class SoundStream
|
|
47
|
+
# Per-callback PCM-buffer size for the sample queue.
|
|
47
48
|
DEFAULT_CHUNK_FRAMES = 4096
|
|
48
49
|
|
|
49
50
|
def initialize(channel_count:, sample_rate:)
|
|
@@ -22,11 +22,15 @@ module SFML
|
|
|
22
22
|
zero one src_color one_minus_src_color dst_color one_minus_dst_color
|
|
23
23
|
src_alpha one_minus_src_alpha dst_alpha one_minus_dst_alpha
|
|
24
24
|
].freeze
|
|
25
|
+
# Blend-factor symbol → integer Hash.
|
|
25
26
|
FACTOR_INDEX = FACTORS.each_with_index.to_h.freeze
|
|
26
27
|
|
|
28
|
+
# Blend-equation symbols in CSFML enum order.
|
|
27
29
|
EQUATIONS = %i[add subtract reverse_subtract min max].freeze
|
|
30
|
+
# Blend-equation symbol → integer Hash.
|
|
28
31
|
EQUATION_INDEX = EQUATIONS.each_with_index.to_h.freeze
|
|
29
32
|
|
|
33
|
+
# The color src, color dst, color eq components.
|
|
30
34
|
attr_reader :color_src, :color_dst, :color_eq,
|
|
31
35
|
:alpha_src, :alpha_dst, :alpha_eq
|
|
32
36
|
|
|
@@ -50,6 +54,7 @@ module SFML
|
|
|
50
54
|
# Returns the hash.
|
|
51
55
|
def hash = [color_src, color_dst, color_eq, alpha_src, alpha_dst, alpha_eq].hash
|
|
52
56
|
|
|
57
|
+
# Returns the to s.
|
|
53
58
|
def to_s
|
|
54
59
|
"BlendMode(color: #{color_src}/#{color_dst}/#{color_eq}, alpha: #{alpha_src}/#{alpha_dst}/#{alpha_eq})"
|
|
55
60
|
end
|
|
@@ -104,6 +109,7 @@ module SFML
|
|
|
104
109
|
MULTIPLY = from_native(C::Graphics.sfBlendMultiply)
|
|
105
110
|
MIN = from_native(C::Graphics.sfBlendMin)
|
|
106
111
|
MAX = from_native(C::Graphics.sfBlendMax)
|
|
112
|
+
# The 0.0.0.0 / empty placeholder address.
|
|
107
113
|
NONE = from_native(C::Graphics.sfBlendNone)
|
|
108
114
|
end
|
|
109
115
|
end
|
data/lib/sfml/graphics/color.rb
CHANGED
|
@@ -8,6 +8,7 @@ module SFML
|
|
|
8
8
|
# SFML::Color["#ff6432"] # hex (RGB or RRGGBB or RRGGBBAA)
|
|
9
9
|
# SFML::Color.cornflower_blue # named
|
|
10
10
|
class Color
|
|
11
|
+
# The Red channel (0–255), Green channel (0–255), Blue channel (0–255), Alpha channel (0–255) components.
|
|
11
12
|
attr_reader :r, :g, :b, :a
|
|
12
13
|
|
|
13
14
|
# Build a Color from individual channel values. Each must be an
|
|
@@ -67,12 +68,14 @@ module SFML
|
|
|
67
68
|
def to_s = "Color(#{@r}, #{@g}, #{@b}, #{@a})"
|
|
68
69
|
alias inspect to_s
|
|
69
70
|
|
|
71
|
+
# Returns the to native.
|
|
70
72
|
def to_native # :nodoc:
|
|
71
73
|
C::Graphics::Color.new.tap do |c|
|
|
72
74
|
c[:r] = @r; c[:g] = @g; c[:b] = @b; c[:a] = @a
|
|
73
75
|
end
|
|
74
76
|
end
|
|
75
77
|
|
|
78
|
+
# Returns the self.
|
|
76
79
|
def self.from_native(struct) # :nodoc:
|
|
77
80
|
new(struct[:r], struct[:g], struct[:b], struct[:a])
|
|
78
81
|
end
|
|
@@ -110,13 +113,21 @@ module SFML
|
|
|
110
113
|
|
|
111
114
|
# Standard SFML colors.
|
|
112
115
|
BLACK = new(0, 0, 0)
|
|
116
|
+
# Pure white, opaque.
|
|
113
117
|
WHITE = new(255, 255, 255)
|
|
118
|
+
# Pure red, opaque.
|
|
114
119
|
RED = new(255, 0, 0)
|
|
120
|
+
# Pure green, opaque.
|
|
115
121
|
GREEN = new(0, 255, 0)
|
|
122
|
+
# Pure blue, opaque.
|
|
116
123
|
BLUE = new(0, 0, 255)
|
|
124
|
+
# Pure yellow, opaque.
|
|
117
125
|
YELLOW = new(255, 255, 0)
|
|
126
|
+
# Pure magenta, opaque.
|
|
118
127
|
MAGENTA = new(255, 0, 255)
|
|
128
|
+
# Pure cyan, opaque.
|
|
119
129
|
CYAN = new(0, 255, 255)
|
|
130
|
+
# Fully transparent (alpha = 0).
|
|
120
131
|
TRANSPARENT = new(0, 0, 0, 0)
|
|
121
132
|
|
|
122
133
|
# A nicer default than pure black for empty windows.
|
data/lib/sfml/graphics/font.rb
CHANGED
|
@@ -18,6 +18,7 @@ module SFML
|
|
|
18
18
|
# license, redistributable). See lib/sfml/assets/fonts/DejaVuSans.LICENSE.txt.
|
|
19
19
|
DEFAULT_PATH = File.expand_path("../assets/fonts/DejaVuSans.ttf", __dir__).freeze
|
|
20
20
|
|
|
21
|
+
# Returns the self.
|
|
21
22
|
def self.load(path)
|
|
22
23
|
ptr = C::Graphics.sfFont_createFromFile(path.to_s)
|
|
23
24
|
raise LoadError, "Could not load font from #{path.inspect}" if ptr.null?
|
data/lib/sfml/graphics/image.rb
CHANGED
|
@@ -33,6 +33,7 @@ module SFML
|
|
|
33
33
|
_take_ownership(ptr)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
# Returns the self.
|
|
36
37
|
def self.load(path)
|
|
37
38
|
ptr = C::Graphics.sfImage_createFromFile(path.to_s)
|
|
38
39
|
raise LoadError, "Could not load image from #{path.inspect}" if ptr.null?
|
|
@@ -90,6 +91,7 @@ module SFML
|
|
|
90
91
|
img
|
|
91
92
|
end
|
|
92
93
|
|
|
94
|
+
# Returns the size.
|
|
93
95
|
def size
|
|
94
96
|
Vector2.from_native(C::Graphics.sfImage_getSize(@handle))
|
|
95
97
|
end
|
|
@@ -151,6 +153,7 @@ module SFML
|
|
|
151
153
|
self
|
|
152
154
|
end
|
|
153
155
|
|
|
156
|
+
# Returns the save.
|
|
154
157
|
def save(path)
|
|
155
158
|
ok = C::Graphics.sfImage_saveToFile(@handle, path.to_s)
|
|
156
159
|
raise LoadError, "Could not save image to #{path.inspect}" unless ok
|
|
@@ -188,11 +191,13 @@ module SFML
|
|
|
188
191
|
self
|
|
189
192
|
end
|
|
190
193
|
|
|
194
|
+
# Returns the flip horizontally.
|
|
191
195
|
def flip_horizontally
|
|
192
196
|
C::Graphics.sfImage_flipHorizontally(@handle)
|
|
193
197
|
self
|
|
194
198
|
end
|
|
195
199
|
|
|
200
|
+
# Returns the flip vertically.
|
|
196
201
|
def flip_vertically
|
|
197
202
|
C::Graphics.sfImage_flipVertically(@handle)
|
|
198
203
|
self
|
|
@@ -51,6 +51,7 @@ module SFML
|
|
|
51
51
|
def normalized_age = age / lifetime
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
# No gravity by default `[0.0, 0.0]`.
|
|
54
55
|
DEFAULT_GRAVITY = [0.0, 0.0].freeze
|
|
55
56
|
|
|
56
57
|
def initialize(max: 1000, gravity: DEFAULT_GRAVITY, texture: nil)
|
|
@@ -62,6 +63,7 @@ module SFML
|
|
|
62
63
|
@vertex_array = VertexArray.new(:triangles)
|
|
63
64
|
end
|
|
64
65
|
|
|
66
|
+
# The particles, texture components.
|
|
65
67
|
attr_reader :particles, :texture
|
|
66
68
|
# Returns the size.
|
|
67
69
|
def size = @particles.size
|
|
@@ -14,9 +14,12 @@ module SFML
|
|
|
14
14
|
#
|
|
15
15
|
# All fields default to the CSFML `sfRenderStates_default` value.
|
|
16
16
|
class RenderStates
|
|
17
|
+
# Texture coordinate-type symbols.
|
|
17
18
|
COORDINATE_TYPES = %i[normalized pixels].freeze
|
|
19
|
+
# Coordinate-type symbol → integer Hash.
|
|
18
20
|
COORDINATE_INDEX = COORDINATE_TYPES.each_with_index.to_h.freeze
|
|
19
21
|
|
|
22
|
+
# The blend mode, stencil mode, texture, shader, coordinate type components.
|
|
20
23
|
attr_reader :blend_mode, :stencil_mode, :texture, :shader, :coordinate_type
|
|
21
24
|
|
|
22
25
|
def initialize(blend_mode: nil, stencil_mode: nil, texture: nil, shader: nil, coordinate_type: :normalized)
|
|
@@ -35,6 +35,7 @@ module SFML
|
|
|
35
35
|
self
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
+
# Returns the display.
|
|
38
39
|
def display
|
|
39
40
|
_csfml(:display, @handle)
|
|
40
41
|
self
|
|
@@ -122,6 +123,7 @@ module SFML
|
|
|
122
123
|
@view = value
|
|
123
124
|
end
|
|
124
125
|
|
|
126
|
+
# Returns the view.
|
|
125
127
|
def view
|
|
126
128
|
View.from_borrowed(_csfml(:getView, @handle))
|
|
127
129
|
end
|
|
@@ -132,6 +134,7 @@ module SFML
|
|
|
132
134
|
@default_view ||= View.from_borrowed(_csfml(:getDefaultView, @handle))
|
|
133
135
|
end
|
|
134
136
|
|
|
137
|
+
# Returns the map pixel to coords.
|
|
135
138
|
def map_pixel_to_coords(pixel, view: nil)
|
|
136
139
|
vec = C::System::Vector2i.new
|
|
137
140
|
px, py = pixel.is_a?(Vector2) ? [pixel.x, pixel.y] : pixel
|
|
@@ -142,6 +145,7 @@ module SFML
|
|
|
142
145
|
Vector2.new(result[:x], result[:y])
|
|
143
146
|
end
|
|
144
147
|
|
|
148
|
+
# Returns the map coords to pixel.
|
|
145
149
|
def map_coords_to_pixel(coord, view: nil)
|
|
146
150
|
vec = C::System::Vector2f.new
|
|
147
151
|
cx, cy = coord.is_a?(Vector2) ? [coord.x, coord.y] : coord
|
|
@@ -34,6 +34,7 @@ module SFML
|
|
|
34
34
|
self.repeated = repeated
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
# Returns the size.
|
|
37
38
|
def size
|
|
38
39
|
v = C::Graphics.sfRenderTexture_getSize(@handle)
|
|
39
40
|
Vector2.new(v[:x], v[:y])
|
|
@@ -92,6 +93,7 @@ module SFML
|
|
|
92
93
|
Rect.from_native(C::Graphics.sfRenderTexture_getViewport(@handle, view.handle))
|
|
93
94
|
end
|
|
94
95
|
|
|
96
|
+
# Returns the scissor.
|
|
95
97
|
def scissor(view = self.view)
|
|
96
98
|
raise ArgumentError, "expected a SFML::View" unless view.is_a?(View)
|
|
97
99
|
Rect.from_native(C::Graphics.sfRenderTexture_getScissor(@handle, view.handle))
|
|
@@ -18,6 +18,7 @@ module SFML
|
|
|
18
18
|
include Graphics::RenderTarget
|
|
19
19
|
CSFML_PREFIX = :sfRenderWindow
|
|
20
20
|
|
|
21
|
+
# Default window style bitmask.
|
|
21
22
|
DEFAULT_STYLE = C::Window::Style::DEFAULT
|
|
22
23
|
|
|
23
24
|
# The first form takes (width, height, title, **opts).
|
|
@@ -350,6 +351,7 @@ module SFML
|
|
|
350
351
|
v
|
|
351
352
|
end
|
|
352
353
|
|
|
354
|
+
# Returns the parse args.
|
|
353
355
|
def parse_args(args)
|
|
354
356
|
case args.length
|
|
355
357
|
when 2
|
data/lib/sfml/graphics/shader.rb
CHANGED
|
@@ -45,6 +45,7 @@ module SFML
|
|
|
45
45
|
C::Graphics.sfShader_isAvailable
|
|
46
46
|
end
|
|
47
47
|
|
|
48
|
+
# Returns the self.
|
|
48
49
|
def self.geometry_available?
|
|
49
50
|
C::Graphics.sfShader_isGeometryAvailable
|
|
50
51
|
end
|
|
@@ -136,6 +137,7 @@ module SFML
|
|
|
136
137
|
C::Graphics.sfShader_setIntUniform(@handle, name.to_s, Integer(value))
|
|
137
138
|
end
|
|
138
139
|
|
|
140
|
+
# Returns the ivec2.
|
|
139
141
|
def set_ivec2(name, x, y)
|
|
140
142
|
v = C::System::Vector2i.new
|
|
141
143
|
v[:x] = Integer(x); v[:y] = Integer(y)
|
|
@@ -197,6 +199,7 @@ module SFML
|
|
|
197
199
|
_set_mat_array(name, matrices, 9, :sfShader_setMat3UniformArray)
|
|
198
200
|
end
|
|
199
201
|
|
|
202
|
+
# Returns the mat4 array.
|
|
200
203
|
def set_mat4_array(name, matrices)
|
|
201
204
|
_set_mat_array(name, matrices, 16, :sfShader_setMat4UniformArray)
|
|
202
205
|
end
|
|
@@ -208,6 +211,7 @@ module SFML
|
|
|
208
211
|
# render_states: SFML::RenderStates.new(shader: self))`.
|
|
209
212
|
def bind = C::Graphics.sfShader_bind(@handle)
|
|
210
213
|
|
|
214
|
+
# Returns the self.
|
|
211
215
|
def self.unbind = C::Graphics.sfShader_bind(nil)
|
|
212
216
|
|
|
213
217
|
# The OpenGL program ID. Useful for debug printf / interop
|
data/lib/sfml/graphics/shape.rb
CHANGED
|
@@ -67,6 +67,7 @@ module SFML
|
|
|
67
67
|
raise NoMethodError, "#{self.class} must override #point_count"
|
|
68
68
|
end
|
|
69
69
|
|
|
70
|
+
# Returns the point.
|
|
70
71
|
def point(_index)
|
|
71
72
|
raise NoMethodError, "#{self.class} must override #point(index)"
|
|
72
73
|
end
|
|
@@ -105,6 +106,7 @@ module SFML
|
|
|
105
106
|
self
|
|
106
107
|
end
|
|
107
108
|
|
|
109
|
+
# Returns the draw on.
|
|
108
110
|
def draw_on(target, states_ptr = nil) # :nodoc:
|
|
109
111
|
target._draw_native(:Shape, @handle, states_ptr)
|
|
110
112
|
end
|
|
@@ -9,6 +9,7 @@ module SFML
|
|
|
9
9
|
# to the bound texture in @texture so the GC doesn't collect the GPU
|
|
10
10
|
# resource while the shape still draws with it.
|
|
11
11
|
module ShapeInspectable
|
|
12
|
+
# Returns the texture.
|
|
12
13
|
def texture
|
|
13
14
|
ptr = _csfml(:getTexture, @handle)
|
|
14
15
|
return nil if ptr.null?
|
|
@@ -29,6 +30,7 @@ module SFML
|
|
|
29
30
|
set_texture(tex, reset_rect: false)
|
|
30
31
|
end
|
|
31
32
|
|
|
33
|
+
# Returns the texture rect.
|
|
32
34
|
def texture_rect
|
|
33
35
|
Rect.from_native(_csfml(:getTextureRect, @handle))
|
|
34
36
|
end
|
|
@@ -68,10 +70,12 @@ module SFML
|
|
|
68
70
|
Rect.from_native(_csfml(:getGlobalBounds, @handle))
|
|
69
71
|
end
|
|
70
72
|
|
|
73
|
+
# Returns the transform.
|
|
71
74
|
def transform
|
|
72
75
|
_csfml(:getTransform, @handle)
|
|
73
76
|
end
|
|
74
77
|
|
|
78
|
+
# Returns the inverse transform.
|
|
75
79
|
def inverse_transform
|
|
76
80
|
_csfml(:getInverseTransform, @handle)
|
|
77
81
|
end
|
data/lib/sfml/graphics/sprite.rb
CHANGED
|
@@ -11,6 +11,8 @@ module SFML
|
|
|
11
11
|
include Graphics::Transformable
|
|
12
12
|
CSFML_PREFIX = :sfSprite
|
|
13
13
|
|
|
14
|
+
# Build a Sprite. `texture` is required (SFML 3 dropped the
|
|
15
|
+
# default constructor). Kwargs cover color / transform.
|
|
14
16
|
def initialize(texture, **opts)
|
|
15
17
|
raise ArgumentError, "Sprite requires a SFML::Texture" unless texture.is_a?(Texture)
|
|
16
18
|
|
|
@@ -26,6 +28,7 @@ module SFML
|
|
|
26
28
|
self.scale = opts[:scale] if opts.key?(:scale)
|
|
27
29
|
end
|
|
28
30
|
|
|
31
|
+
# The texture.
|
|
29
32
|
attr_reader :texture
|
|
30
33
|
|
|
31
34
|
# Set the texture.
|
|
@@ -62,14 +65,17 @@ module SFML
|
|
|
62
65
|
C::Graphics.sfSprite_setTextureRect(@handle, native)
|
|
63
66
|
end
|
|
64
67
|
|
|
68
|
+
# Bounding box of the sprite in its own (untransformed) coords.
|
|
65
69
|
def local_bounds
|
|
66
70
|
Rect.from_native(C::Graphics.sfSprite_getLocalBounds(@handle))
|
|
67
71
|
end
|
|
68
72
|
|
|
73
|
+
# Bounding box after applying the sprite's transform.
|
|
69
74
|
def global_bounds
|
|
70
75
|
Rect.from_native(C::Graphics.sfSprite_getGlobalBounds(@handle))
|
|
71
76
|
end
|
|
72
77
|
|
|
78
|
+
# Returns the draw on.
|
|
73
79
|
def draw_on(target, states_ptr = nil) # :nodoc:
|
|
74
80
|
target._draw_native(:Sprite, @handle, states_ptr)
|
|
75
81
|
end
|
|
@@ -88,6 +94,8 @@ module SFML
|
|
|
88
94
|
C::Graphics.sfSprite_getTransform(@handle)
|
|
89
95
|
end
|
|
90
96
|
|
|
97
|
+
# Inverse of `#transform` — maps world-space coords back to
|
|
98
|
+
# the sprite's local space.
|
|
91
99
|
def inverse_transform
|
|
92
100
|
C::Graphics.sfSprite_getInverseTransform(@handle)
|
|
93
101
|
end
|
|
@@ -19,6 +19,7 @@ module SFML
|
|
|
19
19
|
# the source image has separators or a 1px outline to prevent
|
|
20
20
|
# bleed.
|
|
21
21
|
class SpriteSheet
|
|
22
|
+
# Returns the self.
|
|
22
23
|
def self.load(path, frame_size:, padding: 0, margin: 0, smooth: true)
|
|
23
24
|
new(texture: Texture.load(path, smooth: smooth),
|
|
24
25
|
frame_size: frame_size, padding: padding, margin: margin)
|
|
@@ -46,6 +47,7 @@ module SFML
|
|
|
46
47
|
end.freeze
|
|
47
48
|
end
|
|
48
49
|
|
|
50
|
+
# The texture, cols, rows, frame w, frame h components.
|
|
49
51
|
attr_reader :texture, :cols, :rows, :frame_w, :frame_h
|
|
50
52
|
|
|
51
53
|
# Returns the frame count.
|