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
data/lib/sfml/window/event.rb
CHANGED
|
@@ -17,28 +17,38 @@ module SFML
|
|
|
17
17
|
# extra1, extra2. (CSFML 2 called the last two x_button1/x_button2,
|
|
18
18
|
# but SFML 3 dropped the X-button terminology.)
|
|
19
19
|
MOUSE_BUTTONS = %i[left right middle extra1 extra2].freeze
|
|
20
|
+
# Mouse wheel axes — `:vertical` / `:horizontal`.
|
|
20
21
|
MOUSE_WHEELS = %i[vertical horizontal].freeze
|
|
21
22
|
|
|
23
|
+
# The type, data components.
|
|
22
24
|
attr_reader :type, :data
|
|
23
25
|
|
|
26
|
+
# Build directly (rare — `Event.from_native` is the usual path).
|
|
24
27
|
def initialize(type, data = {})
|
|
25
28
|
@type = type
|
|
26
29
|
@data = data.freeze
|
|
27
30
|
freeze
|
|
28
31
|
end
|
|
29
32
|
|
|
33
|
+
# Hash-style lookup into the event payload.
|
|
30
34
|
def [](key) = @data[key]
|
|
35
|
+
# Hash-style fetch with the standard fallback / block behaviour.
|
|
31
36
|
def fetch(*args, &) = @data.fetch(*args, &)
|
|
32
37
|
|
|
38
|
+
# Pattern-match hook — flattens `{type:, ...payload}` into one
|
|
39
|
+
# hash so callers can write `in {type: :key_pressed, code:}`.
|
|
33
40
|
def deconstruct_keys(_keys)
|
|
34
41
|
{ type: @type, **@data }
|
|
35
42
|
end
|
|
36
43
|
|
|
37
|
-
# `
|
|
44
|
+
# `respond_to?` answer for payload keys — keeps `#method_missing`
|
|
45
|
+
# safe under introspection.
|
|
38
46
|
def respond_to_missing?(name, _private = false)
|
|
39
47
|
@data.key?(name) || super
|
|
40
48
|
end
|
|
41
49
|
|
|
50
|
+
# Payload keys are exposed as method calls so `event.code` works
|
|
51
|
+
# alongside `event[:code]`.
|
|
42
52
|
def method_missing(name, *args)
|
|
43
53
|
return @data[name] if args.empty? && @data.key?(name)
|
|
44
54
|
super
|
|
@@ -60,6 +70,7 @@ module SFML
|
|
|
60
70
|
new(type_sym, data)
|
|
61
71
|
end
|
|
62
72
|
|
|
73
|
+
# Returns the self.
|
|
63
74
|
def self.decode(type_sym, ptr)
|
|
64
75
|
case type_sym
|
|
65
76
|
when :closed, :focus_lost, :focus_gained,
|
|
@@ -143,6 +154,7 @@ module SFML
|
|
|
143
154
|
end
|
|
144
155
|
end
|
|
145
156
|
|
|
157
|
+
# Frozen empty Hash — shared default for missing event payloads.
|
|
146
158
|
EMPTY = {}.freeze
|
|
147
159
|
private_constant :EMPTY
|
|
148
160
|
end
|
data/lib/sfml/window/joystick.rb
CHANGED
data/lib/sfml/window/keyboard.rb
CHANGED
|
@@ -14,6 +14,7 @@ module SFML
|
|
|
14
14
|
# The KEY_CODES / SCAN_CODES arrays are load-bearing: order matches
|
|
15
15
|
# the sfKeyCode / sfScancode enums in CSFML/Window/Keyboard.h.
|
|
16
16
|
module Keyboard
|
|
17
|
+
# All key symbols in CSFML `sfKeyCode` enum order.
|
|
17
18
|
KEY_CODES = %i[
|
|
18
19
|
a b c d e f g h i j k l m n o p q r s t u v w x y z
|
|
19
20
|
num0 num1 num2 num3 num4 num5 num6 num7 num8 num9
|
|
@@ -33,6 +34,7 @@ module SFML
|
|
|
33
34
|
pause
|
|
34
35
|
].freeze
|
|
35
36
|
|
|
37
|
+
# Key symbol → integer code Hash.
|
|
36
38
|
SYMBOL_TO_CODE = KEY_CODES.each_with_index.to_h.freeze
|
|
37
39
|
|
|
38
40
|
# Matches sfScancode in CSFML/Window/Keyboard.h exactly.
|
|
@@ -68,6 +70,7 @@ module SFML
|
|
|
68
70
|
scan_launch_application1 scan_launch_application2 scan_launch_mail scan_launch_media_select
|
|
69
71
|
].freeze
|
|
70
72
|
|
|
73
|
+
# Scancode symbol → integer code Hash.
|
|
71
74
|
SCAN_SYMBOL_TO_CODE = SCAN_CODES.each_with_index.to_h.freeze
|
|
72
75
|
|
|
73
76
|
# Friendly aliases users might reach for naturally.
|
|
@@ -83,11 +86,13 @@ module SFML
|
|
|
83
86
|
|
|
84
87
|
module_function
|
|
85
88
|
|
|
89
|
+
# Returns the code to symbol.
|
|
86
90
|
def code_to_symbol(code)
|
|
87
91
|
return :unknown if code < 0 || code >= KEY_CODES.length
|
|
88
92
|
KEY_CODES[code]
|
|
89
93
|
end
|
|
90
94
|
|
|
95
|
+
# Returns the symbol to code.
|
|
91
96
|
def symbol_to_code(symbol)
|
|
92
97
|
symbol = ALIASES.fetch(symbol, symbol)
|
|
93
98
|
SYMBOL_TO_CODE.fetch(symbol) do
|
|
@@ -96,11 +101,13 @@ module SFML
|
|
|
96
101
|
end
|
|
97
102
|
end
|
|
98
103
|
|
|
104
|
+
# Returns the scancode to symbol.
|
|
99
105
|
def scancode_to_symbol(code)
|
|
100
106
|
return :scan_unknown if code < 0 || code >= SCAN_CODES.length
|
|
101
107
|
SCAN_CODES[code]
|
|
102
108
|
end
|
|
103
109
|
|
|
110
|
+
# Returns the symbol to scancode.
|
|
104
111
|
def symbol_to_scancode(symbol)
|
|
105
112
|
SCAN_SYMBOL_TO_CODE.fetch(symbol) do
|
|
106
113
|
raise ArgumentError, "Unknown scancode symbol: #{symbol.inspect}. " \
|
data/lib/sfml/window/mouse.rb
CHANGED
|
@@ -11,7 +11,9 @@ module SFML
|
|
|
11
11
|
# Buttons are addressed by symbol; the raw sfMouseButton enum order is
|
|
12
12
|
# exposed via BUTTONS for users who need it.
|
|
13
13
|
module Mouse
|
|
14
|
+
# Recognised button symbols.
|
|
14
15
|
BUTTONS = %i[left right middle extra1 extra2].freeze
|
|
16
|
+
# Symbol → integer index for each button.
|
|
15
17
|
BUTTON_INDEX = BUTTONS.each_with_index.to_h.freeze
|
|
16
18
|
|
|
17
19
|
# Friendly aliases — SFML 2 used "X-button" terminology; some users
|
data/lib/sfml/window/sensor.rb
CHANGED
|
@@ -17,7 +17,9 @@ module SFML
|
|
|
17
17
|
# Sensor data also surfaces through the event loop as
|
|
18
18
|
# `{type: :sensor_changed, sensor: :accelerometer, value: Vector3}`.
|
|
19
19
|
module Sensor
|
|
20
|
+
# Recognised type symbols.
|
|
20
21
|
TYPES = C::Window::SENSOR_TYPES
|
|
22
|
+
# Type symbol → integer index Hash.
|
|
21
23
|
TYPE_INDEX = TYPES.each_with_index.to_h.freeze
|
|
22
24
|
|
|
23
25
|
module_function
|
|
@@ -27,14 +29,17 @@ module SFML
|
|
|
27
29
|
C::Window.sfSensor_isAvailable(_index(type))
|
|
28
30
|
end
|
|
29
31
|
|
|
32
|
+
# Returns the enable.
|
|
30
33
|
def enable(type)
|
|
31
34
|
C::Window.sfSensor_setEnabled(_index(type), true)
|
|
32
35
|
end
|
|
33
36
|
|
|
37
|
+
# Returns the disable.
|
|
34
38
|
def disable(type)
|
|
35
39
|
C::Window.sfSensor_setEnabled(_index(type), false)
|
|
36
40
|
end
|
|
37
41
|
|
|
42
|
+
# Returns the value.
|
|
38
43
|
def value(type)
|
|
39
44
|
v = C::Window.sfSensor_getValue(_index(type))
|
|
40
45
|
Vector3.new(v[:x], v[:y], v[:z])
|
|
@@ -4,6 +4,7 @@ module SFML
|
|
|
4
4
|
# SFML::VideoMode.new(800, 600)
|
|
5
5
|
# SFML::VideoMode.desktop_mode
|
|
6
6
|
class VideoMode
|
|
7
|
+
# The width, height, bits per pixel components.
|
|
7
8
|
attr_reader :width, :height, :bits_per_pixel
|
|
8
9
|
|
|
9
10
|
def initialize(width, height, bits_per_pixel = 32)
|
|
@@ -13,6 +14,7 @@ module SFML
|
|
|
13
14
|
freeze
|
|
14
15
|
end
|
|
15
16
|
|
|
17
|
+
# Returns the self.
|
|
16
18
|
def self.desktop_mode
|
|
17
19
|
from_native(C::Window.sfVideoMode_getDesktopMode)
|
|
18
20
|
end
|
|
@@ -46,10 +48,12 @@ module SFML
|
|
|
46
48
|
def to_s = "#<SFML::VideoMode #{@width}x#{@height}@#{@bits_per_pixel}>"
|
|
47
49
|
alias inspect to_s
|
|
48
50
|
|
|
51
|
+
# Returns the self.
|
|
49
52
|
def self.from_native(struct) # :nodoc:
|
|
50
53
|
new(struct[:size][:x], struct[:size][:y], struct[:bits_per_pixel])
|
|
51
54
|
end
|
|
52
55
|
|
|
56
|
+
# Returns the to native.
|
|
53
57
|
def to_native # :nodoc:
|
|
54
58
|
C::Window::VideoMode.new.tap do |m|
|
|
55
59
|
m[:size][:x] = @width
|
data/lib/sfml/window/window.rb
CHANGED
|
@@ -20,8 +20,11 @@ module SFML
|
|
|
20
20
|
# win.display
|
|
21
21
|
# end
|
|
22
22
|
class Window
|
|
23
|
+
# Default window style bitmask.
|
|
23
24
|
DEFAULT_STYLE = C::Window::Style::DEFAULT
|
|
24
25
|
|
|
26
|
+
# Construct a Window. Same constructor forms as `RenderWindow.new`
|
|
27
|
+
# (`(w, h, title, **opts)` or `(video_mode, title, **opts)`).
|
|
25
28
|
def initialize(*args, **opts)
|
|
26
29
|
mode, title = parse_args(args)
|
|
27
30
|
style = opts.fetch(:style, DEFAULT_STYLE)
|
|
@@ -43,16 +46,20 @@ module SFML
|
|
|
43
46
|
self.vsync = opts[:vsync] unless opts[:vsync].nil?
|
|
44
47
|
end
|
|
45
48
|
|
|
46
|
-
# `true`
|
|
49
|
+
# `true` while the window is alive (not closed by `#close` or
|
|
50
|
+
# the user).
|
|
47
51
|
def open?
|
|
48
52
|
C::Window.sfWindow_isOpen(@handle)
|
|
49
53
|
end
|
|
50
54
|
|
|
55
|
+
# Close the window.
|
|
51
56
|
def close
|
|
52
57
|
C::Window.sfWindow_close(@handle)
|
|
53
58
|
self
|
|
54
59
|
end
|
|
55
60
|
|
|
61
|
+
# Swap front/back buffers, presenting whatever was rendered
|
|
62
|
+
# since the last call.
|
|
56
63
|
def display
|
|
57
64
|
C::Window.sfWindow_display(@handle)
|
|
58
65
|
self
|
|
@@ -64,6 +71,8 @@ module SFML
|
|
|
64
71
|
Event.from_native(@event_buffer)
|
|
65
72
|
end
|
|
66
73
|
|
|
74
|
+
# Yields each pending event then returns. Without a block,
|
|
75
|
+
# returns an Enumerator.
|
|
67
76
|
def each_event
|
|
68
77
|
return enum_for(:each_event) unless block_given?
|
|
69
78
|
while (event = poll_event)
|
|
@@ -77,6 +86,7 @@ module SFML
|
|
|
77
86
|
C::Window.sfWindow_setTitle(@handle, value.to_s)
|
|
78
87
|
end
|
|
79
88
|
|
|
89
|
+
# Current window size as a `Vector2`.
|
|
80
90
|
def size
|
|
81
91
|
v = C::Window.sfWindow_getSize(@handle)
|
|
82
92
|
Vector2.new(v[:x], v[:y])
|
|
@@ -90,6 +100,7 @@ module SFML
|
|
|
90
100
|
C::Window.sfWindow_setSize(@handle, v)
|
|
91
101
|
end
|
|
92
102
|
|
|
103
|
+
# Window top-left in desktop coordinates.
|
|
93
104
|
def position
|
|
94
105
|
v = C::Window.sfWindow_getPosition(@handle)
|
|
95
106
|
Vector2.new(v[:x], v[:y])
|
|
@@ -123,6 +134,8 @@ module SFML
|
|
|
123
134
|
C::Window.sfWindow_setKeyRepeatEnabled(@handle, value ? true : false)
|
|
124
135
|
end
|
|
125
136
|
|
|
137
|
+
# Ask the OS to give this window focus. Cooperative — most
|
|
138
|
+
# window managers will defer until the user clicks.
|
|
126
139
|
def request_focus
|
|
127
140
|
C::Window.sfWindow_requestFocus(@handle)
|
|
128
141
|
end
|
|
@@ -140,6 +153,8 @@ module SFML
|
|
|
140
153
|
|
|
141
154
|
# ---- Mouse cursor ----
|
|
142
155
|
|
|
156
|
+
# Apply a `SFML::Cursor` as the visible mouse pointer over this
|
|
157
|
+
# window. Keeps a Ruby reference so the Cursor outlives the call.
|
|
143
158
|
def cursor=(cursor)
|
|
144
159
|
raise ArgumentError, "Window#cursor= requires a SFML::Cursor" unless cursor.is_a?(Cursor)
|
|
145
160
|
C::Window.sfWindow_setMouseCursor(@handle, cursor.handle)
|
|
@@ -158,6 +173,8 @@ module SFML
|
|
|
158
173
|
|
|
159
174
|
# ---- Misc state ----
|
|
160
175
|
|
|
176
|
+
# Dead-zone for joystick axis events in [0, 100]. Axes whose
|
|
177
|
+
# absolute value is below this are reported as 0.
|
|
161
178
|
def joystick_threshold=(value)
|
|
162
179
|
C::Window.sfWindow_setJoystickThreshold(@handle, Float(value))
|
|
163
180
|
end
|
|
@@ -240,6 +257,7 @@ module SFML
|
|
|
240
257
|
v
|
|
241
258
|
end
|
|
242
259
|
|
|
260
|
+
# Returns the parse args.
|
|
243
261
|
def parse_args(args)
|
|
244
262
|
case args.length
|
|
245
263
|
when 2
|