ruby-sfml 3.0.0.4 → 3.0.0.5
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 +99 -0
- data/lib/sfml/audio/music.rb +14 -0
- data/lib/sfml/audio/sound_buffer.rb +13 -0
- data/lib/sfml/audio/sound_recorder.rb +126 -13
- data/lib/sfml/audio/sound_stream.rb +103 -0
- data/lib/sfml/c/audio.rb +47 -0
- data/lib/sfml/c/graphics.rb +146 -4
- data/lib/sfml/c/network.rb +45 -5
- data/lib/sfml/c/system.rb +12 -0
- data/lib/sfml/c/window.rb +20 -2
- data/lib/sfml/graphics/circle_shape.rb +3 -0
- data/lib/sfml/graphics/color.rb +30 -0
- data/lib/sfml/graphics/convex_shape.rb +3 -0
- data/lib/sfml/graphics/font.rb +19 -0
- data/lib/sfml/graphics/image.rb +12 -0
- data/lib/sfml/graphics/rectangle_shape.rb +5 -0
- data/lib/sfml/graphics/shader.rb +86 -0
- data/lib/sfml/graphics/shape.rb +114 -0
- data/lib/sfml/graphics/shape_inspectable.rb +92 -0
- data/lib/sfml/graphics/texture.rb +46 -10
- data/lib/sfml/graphics/transformable_object.rb +48 -0
- data/lib/sfml/graphics/vertex_array.rb +12 -0
- data/lib/sfml/graphics/vertex_buffer.rb +12 -0
- data/lib/sfml/network/packet.rb +123 -0
- data/lib/sfml/network/tcp_socket.rb +19 -0
- data/lib/sfml/network/udp_socket.rb +23 -0
- data/lib/sfml/system/input_stream.rb +88 -0
- data/lib/sfml/version.rb +1 -1
- data/lib/sfml/window/context.rb +56 -0
- data/lib/sfml/window/keyboard.rb +92 -4
- data/lib/sfml/window/video_mode.rb +22 -0
- data/lib/sfml.rb +6 -0
- metadata +7 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module SFML
|
|
2
|
+
# Headless OpenGL context — for compiling shaders, generating
|
|
3
|
+
# textures, or doing GL work without a window. SFML attaches the
|
|
4
|
+
# context to whichever thread constructed it.
|
|
5
|
+
#
|
|
6
|
+
# ctx = SFML::Context.new
|
|
7
|
+
# ctx.active = true
|
|
8
|
+
# # … raw GL work / shader compile …
|
|
9
|
+
# ctx.active = false
|
|
10
|
+
#
|
|
11
|
+
# CSFML always returns a non-NULL context on creation (it falls back
|
|
12
|
+
# to a pbuffer / EGL surface if no display is available), so the
|
|
13
|
+
# constructor doesn't raise.
|
|
14
|
+
class Context
|
|
15
|
+
def initialize
|
|
16
|
+
ptr = C::Window.sfContext_create
|
|
17
|
+
raise Error, "sfContext_create returned NULL" if ptr.null?
|
|
18
|
+
@handle = FFI::AutoPointer.new(ptr, C::Window.method(:sfContext_destroy))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Activate / deactivate this context on the current thread. Only
|
|
22
|
+
# one context can be current per thread; setting another active
|
|
23
|
+
# implicitly deactivates this one.
|
|
24
|
+
def active=(value)
|
|
25
|
+
C::Window.sfContext_setActive(@handle, !!value)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# The settings the GL driver actually granted (might differ from
|
|
29
|
+
# what you asked for if the driver couldn't meet every
|
|
30
|
+
# constraint).
|
|
31
|
+
def settings
|
|
32
|
+
ContextSettings.from_native(C::Window.sfContext_getSettings(@handle))
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# ID of the context currently active on this thread, or 0 if
|
|
36
|
+
# none. Useful for "am I in the GL context I expect?" assertions.
|
|
37
|
+
def self.active_context_id
|
|
38
|
+
C::Window.sfContext_getActiveContextId
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Is `extension_name` (e.g. "GL_ARB_compute_shader") supported by
|
|
42
|
+
# the active context?
|
|
43
|
+
def self.extension_available?(extension_name)
|
|
44
|
+
C::Window.sfContext_isExtensionAvailable(extension_name.to_s)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Look up a raw GL function pointer by name. Useful when
|
|
48
|
+
# interoping with a GL extension that SFML doesn't wrap. Returns
|
|
49
|
+
# an FFI::Pointer (nil pointer if the function isn't loaded).
|
|
50
|
+
def self.gl_function(name)
|
|
51
|
+
C::Window.sfContext_getFunction(name.to_s)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
attr_reader :handle # :nodoc:
|
|
55
|
+
end
|
|
56
|
+
end
|
data/lib/sfml/window/keyboard.rb
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
module SFML
|
|
2
2
|
# Keyboard key code <-> symbol translation, plus Keyboard.key_pressed?(:esc).
|
|
3
3
|
#
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
4
|
+
# Two concepts:
|
|
5
|
+
# * **Key** — logical / layout-dependent. `:a` on a QWERTY keyboard
|
|
6
|
+
# is the physical Q on AZERTY. Use this for "what does the user
|
|
7
|
+
# mean" (text input, layout-aware shortcuts).
|
|
8
|
+
# * **Scancode** — physical / layout-independent. The key at the
|
|
9
|
+
# position you expect WASD to be will always be `:scan_w` /
|
|
10
|
+
# `:scan_a` / `:scan_s` / `:scan_d`. Use this for "the WASD keys"
|
|
11
|
+
# that should stay in the same physical place regardless of
|
|
12
|
+
# keyboard layout. Standard in modern games.
|
|
13
|
+
#
|
|
14
|
+
# The KEY_CODES / SCAN_CODES arrays are load-bearing: order matches
|
|
15
|
+
# the sfKeyCode / sfScancode enums in CSFML/Window/Keyboard.h.
|
|
7
16
|
module Keyboard
|
|
8
17
|
KEY_CODES = %i[
|
|
9
18
|
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
|
|
@@ -26,6 +35,41 @@ module SFML
|
|
|
26
35
|
|
|
27
36
|
SYMBOL_TO_CODE = KEY_CODES.each_with_index.to_h.freeze
|
|
28
37
|
|
|
38
|
+
# Matches sfScancode in CSFML/Window/Keyboard.h exactly.
|
|
39
|
+
# sfScanUnknown is -1, represented here by :scan_unknown via #scancode_to_symbol.
|
|
40
|
+
SCAN_CODES = %i[
|
|
41
|
+
scan_a scan_b scan_c scan_d scan_e scan_f scan_g scan_h
|
|
42
|
+
scan_i scan_j scan_k scan_l scan_m scan_n scan_o scan_p
|
|
43
|
+
scan_q scan_r scan_s scan_t scan_u scan_v scan_w scan_x scan_y scan_z
|
|
44
|
+
scan_num1 scan_num2 scan_num3 scan_num4 scan_num5
|
|
45
|
+
scan_num6 scan_num7 scan_num8 scan_num9 scan_num0
|
|
46
|
+
scan_enter scan_escape scan_backspace scan_tab scan_space
|
|
47
|
+
scan_hyphen scan_equal scan_l_bracket scan_r_bracket scan_backslash
|
|
48
|
+
scan_semicolon scan_apostrophe scan_grave scan_comma scan_period scan_slash
|
|
49
|
+
scan_f1 scan_f2 scan_f3 scan_f4 scan_f5 scan_f6
|
|
50
|
+
scan_f7 scan_f8 scan_f9 scan_f10 scan_f11 scan_f12
|
|
51
|
+
scan_f13 scan_f14 scan_f15 scan_f16 scan_f17 scan_f18
|
|
52
|
+
scan_f19 scan_f20 scan_f21 scan_f22 scan_f23 scan_f24
|
|
53
|
+
scan_caps_lock scan_print_screen scan_scroll_lock scan_pause
|
|
54
|
+
scan_insert scan_home scan_page_up scan_delete scan_end scan_page_down
|
|
55
|
+
scan_right scan_left scan_down scan_up
|
|
56
|
+
scan_num_lock scan_numpad_divide scan_numpad_multiply scan_numpad_minus
|
|
57
|
+
scan_numpad_plus scan_numpad_equal scan_numpad_enter scan_numpad_decimal
|
|
58
|
+
scan_numpad1 scan_numpad2 scan_numpad3 scan_numpad4 scan_numpad5
|
|
59
|
+
scan_numpad6 scan_numpad7 scan_numpad8 scan_numpad9 scan_numpad0
|
|
60
|
+
scan_non_us_backslash scan_application scan_execute scan_mode_change
|
|
61
|
+
scan_help scan_menu scan_select scan_redo scan_undo
|
|
62
|
+
scan_cut scan_copy scan_paste
|
|
63
|
+
scan_volume_mute scan_volume_up scan_volume_down
|
|
64
|
+
scan_media_play_pause scan_media_stop scan_media_next_track scan_media_previous_track
|
|
65
|
+
scan_l_control scan_l_shift scan_l_alt scan_l_system
|
|
66
|
+
scan_r_control scan_r_shift scan_r_alt scan_r_system
|
|
67
|
+
scan_back scan_forward scan_refresh scan_stop scan_search scan_favorites scan_home_page
|
|
68
|
+
scan_launch_application1 scan_launch_application2 scan_launch_mail scan_launch_media_select
|
|
69
|
+
].freeze
|
|
70
|
+
|
|
71
|
+
SCAN_SYMBOL_TO_CODE = SCAN_CODES.each_with_index.to_h.freeze
|
|
72
|
+
|
|
29
73
|
# Friendly aliases users might reach for naturally.
|
|
30
74
|
ALIASES = {
|
|
31
75
|
esc: :escape,
|
|
@@ -52,9 +96,53 @@ module SFML
|
|
|
52
96
|
end
|
|
53
97
|
end
|
|
54
98
|
|
|
55
|
-
|
|
99
|
+
def scancode_to_symbol(code)
|
|
100
|
+
return :scan_unknown if code < 0 || code >= SCAN_CODES.length
|
|
101
|
+
SCAN_CODES[code]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def symbol_to_scancode(symbol)
|
|
105
|
+
SCAN_SYMBOL_TO_CODE.fetch(symbol) do
|
|
106
|
+
raise ArgumentError, "Unknown scancode symbol: #{symbol.inspect}. " \
|
|
107
|
+
"See SFML::Keyboard::SCAN_CODES."
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# SFML::Keyboard.key_pressed?(:escape) — logical key.
|
|
56
112
|
def key_pressed?(symbol)
|
|
57
113
|
C::Window.sfKeyboard_isKeyPressed(symbol_to_code(symbol))
|
|
58
114
|
end
|
|
115
|
+
|
|
116
|
+
# SFML::Keyboard.scancode_pressed?(:scan_w) — physical key
|
|
117
|
+
# regardless of keyboard layout.
|
|
118
|
+
def scancode_pressed?(symbol)
|
|
119
|
+
C::Window.sfKeyboard_isScancodePressed(symbol_to_scancode(symbol))
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Map a physical scancode to whatever logical key it produces under
|
|
123
|
+
# the current OS keyboard layout. Returns a key symbol (or
|
|
124
|
+
# :unknown for unmappable scancodes).
|
|
125
|
+
def localize(scancode)
|
|
126
|
+
code_to_symbol(C::Window.sfKeyboard_localize(symbol_to_scancode(scancode)))
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Inverse of #localize — find the physical scancode that *would*
|
|
130
|
+
# produce this logical key under the current layout. Returns a
|
|
131
|
+
# scancode symbol.
|
|
132
|
+
def delocalize(key)
|
|
133
|
+
scancode_to_symbol(C::Window.sfKeyboard_delocalize(symbol_to_code(key)))
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Human-readable description for a scancode under the current
|
|
137
|
+
# layout — e.g. `:scan_w` → `"W"` on QWERTY, `"Z"` on AZERTY.
|
|
138
|
+
def description(scancode)
|
|
139
|
+
C::Window.sfKeyboard_getDescription(symbol_to_scancode(scancode))
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# On-screen / virtual keyboard toggle. No-op on desktop platforms;
|
|
143
|
+
# meaningful on mobile/touchscreen builds.
|
|
144
|
+
def virtual_keyboard_visible=(value)
|
|
145
|
+
C::Window.sfKeyboard_setVirtualKeyboardVisible(!!value)
|
|
146
|
+
end
|
|
59
147
|
end
|
|
60
148
|
end
|
|
@@ -17,6 +17,28 @@ module SFML
|
|
|
17
17
|
from_native(C::Window.sfVideoMode_getDesktopMode)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
+
# All video modes the current display supports for true-fullscreen
|
|
21
|
+
# window creation, sorted from most to least pixels. Filter by
|
|
22
|
+
# bpp or aspect ratio in Ruby as needed.
|
|
23
|
+
def self.fullscreen_modes
|
|
24
|
+
count_buf = FFI::MemoryPointer.new(:size_t)
|
|
25
|
+
array_ptr = C::Window.sfVideoMode_getFullscreenModes(count_buf)
|
|
26
|
+
n = count_buf.read(:size_t)
|
|
27
|
+
return [] if array_ptr.null? || n.zero?
|
|
28
|
+
|
|
29
|
+
stride = C::Window::VideoMode.size
|
|
30
|
+
Array.new(n) do |i|
|
|
31
|
+
from_native(C::Window::VideoMode.new(array_ptr + i * stride))
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Does the display actually support this mode at fullscreen?
|
|
36
|
+
# Always `true` for windowed-mode use (only fullscreen is constrained
|
|
37
|
+
# to the OS's allowed mode list).
|
|
38
|
+
def valid?
|
|
39
|
+
C::Window.sfVideoMode_isValid(to_native)
|
|
40
|
+
end
|
|
41
|
+
|
|
20
42
|
def size = Vector2.new(@width, @height)
|
|
21
43
|
|
|
22
44
|
def to_s = "#<SFML::VideoMode #{@width}x#{@height}@#{@bits_per_pixel}>"
|
data/lib/sfml.rb
CHANGED
|
@@ -71,6 +71,7 @@ require "sfml/system/clock"
|
|
|
71
71
|
require "sfml/system/vector2"
|
|
72
72
|
require "sfml/system/vector3"
|
|
73
73
|
require "sfml/system/rect"
|
|
74
|
+
require "sfml/system/input_stream"
|
|
74
75
|
require "sfml/window/keyboard"
|
|
75
76
|
require "sfml/window/mouse"
|
|
76
77
|
require "sfml/window/joystick"
|
|
@@ -82,14 +83,18 @@ require "sfml/window/video_mode"
|
|
|
82
83
|
require "sfml/window/event"
|
|
83
84
|
require "sfml/window/context_settings"
|
|
84
85
|
require "sfml/window/window"
|
|
86
|
+
require "sfml/window/context"
|
|
85
87
|
require "sfml/graphics/color"
|
|
86
88
|
require "sfml/graphics/transformable"
|
|
89
|
+
require "sfml/graphics/shape_inspectable"
|
|
90
|
+
require "sfml/graphics/transformable_object"
|
|
87
91
|
require "sfml/graphics/image"
|
|
88
92
|
require "sfml/graphics/texture"
|
|
89
93
|
require "sfml/graphics/sprite"
|
|
90
94
|
require "sfml/graphics/circle_shape"
|
|
91
95
|
require "sfml/graphics/rectangle_shape"
|
|
92
96
|
require "sfml/graphics/convex_shape"
|
|
97
|
+
require "sfml/graphics/shape"
|
|
93
98
|
require "sfml/graphics/vertex"
|
|
94
99
|
require "sfml/graphics/vertex_array"
|
|
95
100
|
require "sfml/graphics/vertex_buffer"
|
|
@@ -114,6 +119,7 @@ require "sfml/audio/sound_recorder"
|
|
|
114
119
|
require "sfml/audio/sound_buffer_recorder"
|
|
115
120
|
require "sfml/audio/sound_stream"
|
|
116
121
|
require "sfml/network/ip_address"
|
|
122
|
+
require "sfml/network/packet"
|
|
117
123
|
require "sfml/network/tcp_socket"
|
|
118
124
|
require "sfml/network/tcp_listener"
|
|
119
125
|
require "sfml/network/udp_socket"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-sfml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.0.
|
|
4
|
+
version: 3.0.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mykhailo Melnyk
|
|
@@ -110,12 +110,15 @@ files:
|
|
|
110
110
|
- lib/sfml/graphics/render_texture.rb
|
|
111
111
|
- lib/sfml/graphics/render_window.rb
|
|
112
112
|
- lib/sfml/graphics/shader.rb
|
|
113
|
+
- lib/sfml/graphics/shape.rb
|
|
114
|
+
- lib/sfml/graphics/shape_inspectable.rb
|
|
113
115
|
- lib/sfml/graphics/sprite.rb
|
|
114
116
|
- lib/sfml/graphics/stencil_mode.rb
|
|
115
117
|
- lib/sfml/graphics/text.rb
|
|
116
118
|
- lib/sfml/graphics/texture.rb
|
|
117
119
|
- lib/sfml/graphics/transform.rb
|
|
118
120
|
- lib/sfml/graphics/transformable.rb
|
|
121
|
+
- lib/sfml/graphics/transformable_object.rb
|
|
119
122
|
- lib/sfml/graphics/vertex.rb
|
|
120
123
|
- lib/sfml/graphics/vertex_array.rb
|
|
121
124
|
- lib/sfml/graphics/vertex_buffer.rb
|
|
@@ -124,18 +127,21 @@ files:
|
|
|
124
127
|
- lib/sfml/network/ftp.rb
|
|
125
128
|
- lib/sfml/network/http.rb
|
|
126
129
|
- lib/sfml/network/ip_address.rb
|
|
130
|
+
- lib/sfml/network/packet.rb
|
|
127
131
|
- lib/sfml/network/socket_selector.rb
|
|
128
132
|
- lib/sfml/network/tcp_listener.rb
|
|
129
133
|
- lib/sfml/network/tcp_socket.rb
|
|
130
134
|
- lib/sfml/network/udp_socket.rb
|
|
131
135
|
- lib/sfml/scene.rb
|
|
132
136
|
- lib/sfml/system/clock.rb
|
|
137
|
+
- lib/sfml/system/input_stream.rb
|
|
133
138
|
- lib/sfml/system/rect.rb
|
|
134
139
|
- lib/sfml/system/time.rb
|
|
135
140
|
- lib/sfml/system/vector2.rb
|
|
136
141
|
- lib/sfml/system/vector3.rb
|
|
137
142
|
- lib/sfml/version.rb
|
|
138
143
|
- lib/sfml/window/clipboard.rb
|
|
144
|
+
- lib/sfml/window/context.rb
|
|
139
145
|
- lib/sfml/window/context_settings.rb
|
|
140
146
|
- lib/sfml/window/cursor.rb
|
|
141
147
|
- lib/sfml/window/event.rb
|