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
data/lib/sfml/c/graphics.rb
CHANGED
|
@@ -66,6 +66,12 @@ module SFML
|
|
|
66
66
|
attach_variable :sfRenderStates_default, RenderStates
|
|
67
67
|
attach_variable :sfTransform_Identity, Transform
|
|
68
68
|
|
|
69
|
+
attach_function :sfColor_fromInteger, [:uint32], Color.by_value
|
|
70
|
+
attach_function :sfColor_toInteger, [Color.by_value], :uint32
|
|
71
|
+
attach_function :sfColor_add, [Color.by_value, Color.by_value], Color.by_value
|
|
72
|
+
attach_function :sfColor_subtract, [Color.by_value, Color.by_value], Color.by_value
|
|
73
|
+
attach_function :sfColor_modulate, [Color.by_value, Color.by_value], Color.by_value
|
|
74
|
+
|
|
69
75
|
attach_function :sfTransform_combine, [:pointer, :pointer], :void
|
|
70
76
|
attach_function :sfTransform_translate, [:pointer, System::Vector2f.by_value], :void
|
|
71
77
|
attach_function :sfTransform_rotate, [:pointer, :float], :void
|
|
@@ -153,6 +159,26 @@ module SFML
|
|
|
153
159
|
layout :x, :int32, :y, :int32, :z, :int32, :w, :int32
|
|
154
160
|
end
|
|
155
161
|
|
|
162
|
+
class GlslBvec2 < FFI::Struct
|
|
163
|
+
layout :x, :bool, :y, :bool
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
class GlslBvec3 < FFI::Struct
|
|
167
|
+
layout :x, :bool, :y, :bool, :z, :bool
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
class GlslBvec4 < FFI::Struct
|
|
171
|
+
layout :x, :bool, :y, :bool, :z, :bool, :w, :bool
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
class GlslMat3 < FFI::Struct
|
|
175
|
+
layout :array, [:float, 9]
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
class GlslMat4 < FFI::Struct
|
|
179
|
+
layout :array, [:float, 16]
|
|
180
|
+
end
|
|
181
|
+
|
|
156
182
|
class Vertex < FFI::Struct
|
|
157
183
|
layout :position, System::Vector2f,
|
|
158
184
|
:color, Color,
|
|
@@ -222,10 +248,17 @@ module SFML
|
|
|
222
248
|
System::Vector2i.by_value
|
|
223
249
|
|
|
224
250
|
# ---- Texture ----
|
|
225
|
-
attach_function :sfTexture_create,
|
|
226
|
-
attach_function :
|
|
227
|
-
attach_function :
|
|
228
|
-
attach_function :
|
|
251
|
+
attach_function :sfTexture_create, [System::Vector2u.by_value], :texture_t
|
|
252
|
+
attach_function :sfTexture_createSrgb, [System::Vector2u.by_value], :texture_t
|
|
253
|
+
attach_function :sfTexture_createFromFile, [:string, :pointer], :texture_t
|
|
254
|
+
attach_function :sfTexture_createSrgbFromFile, [:string, :pointer], :texture_t
|
|
255
|
+
attach_function :sfTexture_createFromImage, [:image_t, :pointer], :texture_t
|
|
256
|
+
attach_function :sfTexture_createSrgbFromImage,[:image_t, :pointer], :texture_t
|
|
257
|
+
attach_function :sfTexture_createFromMemory, [:pointer, :size_t, :pointer], :texture_t
|
|
258
|
+
attach_function :sfTexture_createSrgbFromMemory,[:pointer, :size_t, :pointer], :texture_t
|
|
259
|
+
attach_function :sfTexture_createFromStream, [:pointer, :pointer], :texture_t
|
|
260
|
+
attach_function :sfTexture_createSrgbFromStream,[:pointer, :pointer], :texture_t
|
|
261
|
+
attach_function :sfTexture_resizeSrgb, [:texture_t, System::Vector2u.by_value], :bool
|
|
229
262
|
attach_function :sfTexture_copy, [:texture_t], :texture_t
|
|
230
263
|
attach_function :sfTexture_resize, [:texture_t, System::Vector2u.by_value], :bool
|
|
231
264
|
attach_function :sfTexture_swap, [:texture_t, :texture_t], :void
|
|
@@ -259,6 +292,7 @@ module SFML
|
|
|
259
292
|
attach_function :sfImage_createFromPixels, [System::Vector2u.by_value, :pointer], :image_t
|
|
260
293
|
attach_function :sfImage_createFromFile, [:string], :image_t
|
|
261
294
|
attach_function :sfImage_createFromMemory, [:pointer, :size_t], :image_t
|
|
295
|
+
attach_function :sfImage_createFromStream, [:pointer], :image_t
|
|
262
296
|
attach_function :sfImage_copy, [:image_t], :image_t
|
|
263
297
|
attach_function :sfImage_copyImage, [:image_t, :image_t, System::Vector2u.by_value, IntRect.by_value, :bool], :bool
|
|
264
298
|
attach_function :sfImage_destroy, [:image_t], :void
|
|
@@ -318,6 +352,17 @@ module SFML
|
|
|
318
352
|
attach_function :sfCircleShape_move, [:circle_shape_t, System::Vector2f.by_value], :void
|
|
319
353
|
attach_function :sfCircleShape_rotate, [:circle_shape_t, :float], :void
|
|
320
354
|
attach_function :sfCircleShape_scale, [:circle_shape_t, System::Vector2f.by_value], :void
|
|
355
|
+
attach_function :sfCircleShape_copy, [:circle_shape_t], :circle_shape_t
|
|
356
|
+
attach_function :sfCircleShape_getPoint, [:circle_shape_t, :size_t], System::Vector2f.by_value
|
|
357
|
+
attach_function :sfCircleShape_getGeometricCenter, [:circle_shape_t], System::Vector2f.by_value
|
|
358
|
+
attach_function :sfCircleShape_getLocalBounds, [:circle_shape_t], FloatRect.by_value
|
|
359
|
+
attach_function :sfCircleShape_getGlobalBounds, [:circle_shape_t], FloatRect.by_value
|
|
360
|
+
attach_function :sfCircleShape_getTransform, [:circle_shape_t], Transform.by_value
|
|
361
|
+
attach_function :sfCircleShape_getInverseTransform,[:circle_shape_t], Transform.by_value
|
|
362
|
+
attach_function :sfCircleShape_setTexture, [:circle_shape_t, :texture_t, :bool], :void
|
|
363
|
+
attach_function :sfCircleShape_getTexture, [:circle_shape_t], :texture_t
|
|
364
|
+
attach_function :sfCircleShape_setTextureRect, [:circle_shape_t, IntRect.by_value], :void
|
|
365
|
+
attach_function :sfCircleShape_getTextureRect, [:circle_shape_t], IntRect.by_value
|
|
321
366
|
|
|
322
367
|
# ---- RectangleShape ----
|
|
323
368
|
attach_function :sfRectangleShape_create, [], :rectangle_shape_t
|
|
@@ -341,6 +386,18 @@ module SFML
|
|
|
341
386
|
attach_function :sfRectangleShape_move, [:rectangle_shape_t, System::Vector2f.by_value], :void
|
|
342
387
|
attach_function :sfRectangleShape_rotate, [:rectangle_shape_t, :float], :void
|
|
343
388
|
attach_function :sfRectangleShape_scale, [:rectangle_shape_t, System::Vector2f.by_value], :void
|
|
389
|
+
attach_function :sfRectangleShape_copy, [:rectangle_shape_t], :rectangle_shape_t
|
|
390
|
+
attach_function :sfRectangleShape_getPointCount, [:rectangle_shape_t], :size_t
|
|
391
|
+
attach_function :sfRectangleShape_getPoint, [:rectangle_shape_t, :size_t], System::Vector2f.by_value
|
|
392
|
+
attach_function :sfRectangleShape_getGeometricCenter, [:rectangle_shape_t], System::Vector2f.by_value
|
|
393
|
+
attach_function :sfRectangleShape_getLocalBounds, [:rectangle_shape_t], FloatRect.by_value
|
|
394
|
+
attach_function :sfRectangleShape_getGlobalBounds, [:rectangle_shape_t], FloatRect.by_value
|
|
395
|
+
attach_function :sfRectangleShape_getTransform, [:rectangle_shape_t], Transform.by_value
|
|
396
|
+
attach_function :sfRectangleShape_getInverseTransform,[:rectangle_shape_t], Transform.by_value
|
|
397
|
+
attach_function :sfRectangleShape_setTexture, [:rectangle_shape_t, :texture_t, :bool], :void
|
|
398
|
+
attach_function :sfRectangleShape_getTexture, [:rectangle_shape_t], :texture_t
|
|
399
|
+
attach_function :sfRectangleShape_setTextureRect, [:rectangle_shape_t, IntRect.by_value], :void
|
|
400
|
+
attach_function :sfRectangleShape_getTextureRect, [:rectangle_shape_t], IntRect.by_value
|
|
344
401
|
|
|
345
402
|
# ---- ConvexShape ----
|
|
346
403
|
attach_function :sfConvexShape_create, [], :convex_shape_t
|
|
@@ -366,6 +423,16 @@ module SFML
|
|
|
366
423
|
attach_function :sfConvexShape_move, [:convex_shape_t, System::Vector2f.by_value], :void
|
|
367
424
|
attach_function :sfConvexShape_rotate, [:convex_shape_t, :float], :void
|
|
368
425
|
attach_function :sfConvexShape_scale, [:convex_shape_t, System::Vector2f.by_value], :void
|
|
426
|
+
attach_function :sfConvexShape_copy, [:convex_shape_t], :convex_shape_t
|
|
427
|
+
attach_function :sfConvexShape_getGeometricCenter, [:convex_shape_t], System::Vector2f.by_value
|
|
428
|
+
attach_function :sfConvexShape_getLocalBounds, [:convex_shape_t], FloatRect.by_value
|
|
429
|
+
attach_function :sfConvexShape_getGlobalBounds, [:convex_shape_t], FloatRect.by_value
|
|
430
|
+
attach_function :sfConvexShape_getTransform, [:convex_shape_t], Transform.by_value
|
|
431
|
+
attach_function :sfConvexShape_getInverseTransform, [:convex_shape_t], Transform.by_value
|
|
432
|
+
attach_function :sfConvexShape_setTexture, [:convex_shape_t, :texture_t, :bool], :void
|
|
433
|
+
attach_function :sfConvexShape_getTexture, [:convex_shape_t], :texture_t
|
|
434
|
+
attach_function :sfConvexShape_setTextureRect, [:convex_shape_t, IntRect.by_value], :void
|
|
435
|
+
attach_function :sfConvexShape_getTextureRect, [:convex_shape_t], IntRect.by_value
|
|
369
436
|
|
|
370
437
|
# ---- VertexArray ----
|
|
371
438
|
attach_function :sfVertexArray_create, [], :vertex_array_t
|
|
@@ -378,6 +445,7 @@ module SFML
|
|
|
378
445
|
attach_function :sfVertexArray_setPrimitiveType, [:vertex_array_t, :int], :void
|
|
379
446
|
attach_function :sfVertexArray_getPrimitiveType, [:vertex_array_t], :int
|
|
380
447
|
attach_function :sfVertexArray_getBounds, [:vertex_array_t], FloatRect.by_value
|
|
448
|
+
attach_function :sfVertexArray_copy, [:vertex_array_t], :vertex_array_t
|
|
381
449
|
|
|
382
450
|
# ---- RenderTexture ----
|
|
383
451
|
attach_function :sfRenderTexture_create, [System::Vector2u.by_value, :pointer], :render_texture_t
|
|
@@ -433,6 +501,7 @@ module SFML
|
|
|
433
501
|
# ---- Shader ----
|
|
434
502
|
attach_function :sfShader_createFromFile, [:string, :string, :string], :shader_t
|
|
435
503
|
attach_function :sfShader_createFromMemory, [:string, :string, :string], :shader_t
|
|
504
|
+
attach_function :sfShader_createFromStream, [:pointer, :pointer, :pointer], :shader_t
|
|
436
505
|
attach_function :sfShader_destroy, [:shader_t], :void
|
|
437
506
|
attach_function :sfShader_isAvailable, [], :bool
|
|
438
507
|
attach_function :sfShader_bind, [:shader_t], :void
|
|
@@ -471,6 +540,7 @@ module SFML
|
|
|
471
540
|
attach_function :sfVertexBuffer_setUsage, [:vertex_buffer_t, :int], :void
|
|
472
541
|
attach_function :sfVertexBuffer_getUsage, [:vertex_buffer_t], :int
|
|
473
542
|
attach_function :sfVertexBuffer_isAvailable, [], :bool
|
|
543
|
+
attach_function :sfVertexBuffer_bind, [:vertex_buffer_t], :void
|
|
474
544
|
|
|
475
545
|
# Bulk array uniform setters. The array argument is a packed
|
|
476
546
|
# buffer of N elements (N×{1,2,3,4} floats); the length argument
|
|
@@ -480,6 +550,14 @@ module SFML
|
|
|
480
550
|
attach_function :sfShader_setVec3UniformArray, [:shader_t, :string, :pointer, :size_t], :void
|
|
481
551
|
attach_function :sfShader_setVec4UniformArray, [:shader_t, :string, :pointer, :size_t], :void
|
|
482
552
|
|
|
553
|
+
attach_function :sfShader_setBvec2Uniform, [:shader_t, :string, GlslBvec2.by_value], :void
|
|
554
|
+
attach_function :sfShader_setBvec3Uniform, [:shader_t, :string, GlslBvec3.by_value], :void
|
|
555
|
+
attach_function :sfShader_setBvec4Uniform, [:shader_t, :string, GlslBvec4.by_value], :void
|
|
556
|
+
attach_function :sfShader_setMat3Uniform, [:shader_t, :string, :pointer], :void
|
|
557
|
+
attach_function :sfShader_setMat4Uniform, [:shader_t, :string, :pointer], :void
|
|
558
|
+
attach_function :sfShader_setMat3UniformArray, [:shader_t, :string, :pointer, :size_t], :void
|
|
559
|
+
attach_function :sfShader_setMat4UniformArray, [:shader_t, :string, :pointer, :size_t], :void
|
|
560
|
+
|
|
483
561
|
# ---- Font ----
|
|
484
562
|
# `sfFontInfo` carries one field — the human-readable font
|
|
485
563
|
# family. CSFML 3 expanded this struct's surface area only
|
|
@@ -491,6 +569,7 @@ module SFML
|
|
|
491
569
|
|
|
492
570
|
attach_function :sfFont_createFromFile, [:string], :font_t
|
|
493
571
|
attach_function :sfFont_createFromMemory, [:pointer, :size_t], :font_t
|
|
572
|
+
attach_function :sfFont_createFromStream, [:pointer], :font_t
|
|
494
573
|
attach_function :sfFont_copy, [:font_t], :font_t
|
|
495
574
|
attach_function :sfFont_destroy, [:font_t], :void
|
|
496
575
|
attach_function :sfFont_setSmooth, [:font_t, :bool], :void
|
|
@@ -552,6 +631,69 @@ module SFML
|
|
|
552
631
|
attach_function :sfSprite_getTextureRect, [:sprite_t], IntRect.by_value
|
|
553
632
|
attach_function :sfSprite_getLocalBounds, [:sprite_t], FloatRect.by_value
|
|
554
633
|
attach_function :sfSprite_getGlobalBounds, [:sprite_t], FloatRect.by_value
|
|
634
|
+
|
|
635
|
+
# ---- Abstract Shape (callback-based custom polygon) ----
|
|
636
|
+
typedef :pointer, :shape_t
|
|
637
|
+
callback :shape_get_point_count, [:pointer], :size_t
|
|
638
|
+
callback :shape_get_point, [:size_t, :pointer], System::Vector2f.by_value
|
|
639
|
+
|
|
640
|
+
attach_function :sfShape_create, [:shape_get_point_count, :shape_get_point, :pointer], :shape_t
|
|
641
|
+
attach_function :sfShape_destroy, [:shape_t], :void
|
|
642
|
+
attach_function :sfShape_setPosition, [:shape_t, System::Vector2f.by_value], :void
|
|
643
|
+
attach_function :sfShape_getPosition, [:shape_t], System::Vector2f.by_value
|
|
644
|
+
attach_function :sfShape_setRotation, [:shape_t, :float], :void
|
|
645
|
+
attach_function :sfShape_getRotation, [:shape_t], :float
|
|
646
|
+
attach_function :sfShape_setScale, [:shape_t, System::Vector2f.by_value], :void
|
|
647
|
+
attach_function :sfShape_getScale, [:shape_t], System::Vector2f.by_value
|
|
648
|
+
attach_function :sfShape_setOrigin, [:shape_t, System::Vector2f.by_value], :void
|
|
649
|
+
attach_function :sfShape_getOrigin, [:shape_t], System::Vector2f.by_value
|
|
650
|
+
attach_function :sfShape_move, [:shape_t, System::Vector2f.by_value], :void
|
|
651
|
+
attach_function :sfShape_rotate, [:shape_t, :float], :void
|
|
652
|
+
attach_function :sfShape_scale, [:shape_t, System::Vector2f.by_value], :void
|
|
653
|
+
attach_function :sfShape_getTransform, [:shape_t], Transform.by_value
|
|
654
|
+
attach_function :sfShape_getInverseTransform, [:shape_t], Transform.by_value
|
|
655
|
+
attach_function :sfShape_setTexture, [:shape_t, :texture_t, :bool], :void
|
|
656
|
+
attach_function :sfShape_getTexture, [:shape_t], :texture_t
|
|
657
|
+
attach_function :sfShape_setTextureRect, [:shape_t, IntRect.by_value], :void
|
|
658
|
+
attach_function :sfShape_getTextureRect, [:shape_t], IntRect.by_value
|
|
659
|
+
attach_function :sfShape_setFillColor, [:shape_t, Color.by_value], :void
|
|
660
|
+
attach_function :sfShape_getFillColor, [:shape_t], Color.by_value
|
|
661
|
+
attach_function :sfShape_setOutlineColor, [:shape_t, Color.by_value], :void
|
|
662
|
+
attach_function :sfShape_getOutlineColor, [:shape_t], Color.by_value
|
|
663
|
+
attach_function :sfShape_setOutlineThickness, [:shape_t, :float], :void
|
|
664
|
+
attach_function :sfShape_getOutlineThickness, [:shape_t], :float
|
|
665
|
+
attach_function :sfShape_getPointCount, [:shape_t], :size_t
|
|
666
|
+
attach_function :sfShape_getPoint, [:shape_t, :size_t], System::Vector2f.by_value
|
|
667
|
+
attach_function :sfShape_getGeometricCenter, [:shape_t], System::Vector2f.by_value
|
|
668
|
+
attach_function :sfShape_getLocalBounds, [:shape_t], FloatRect.by_value
|
|
669
|
+
attach_function :sfShape_getGlobalBounds, [:shape_t], FloatRect.by_value
|
|
670
|
+
attach_function :sfShape_update, [:shape_t], :void
|
|
671
|
+
|
|
672
|
+
# CSFML draw entry-point for the abstract shape (same shape as
|
|
673
|
+
# the concrete CircleShape/RectangleShape/ConvexShape variants).
|
|
674
|
+
attach_function :sfRenderWindow_drawShape,
|
|
675
|
+
[:render_window_t, :shape_t, :render_states_t], :void
|
|
676
|
+
attach_function :sfRenderTexture_drawShape,
|
|
677
|
+
[:render_texture_t, :shape_t, :render_states_t], :void
|
|
678
|
+
|
|
679
|
+
# ---- Standalone Transformable ----
|
|
680
|
+
typedef :pointer, :transformable_t
|
|
681
|
+
attach_function :sfTransformable_create, [], :transformable_t
|
|
682
|
+
attach_function :sfTransformable_copy, [:transformable_t], :transformable_t
|
|
683
|
+
attach_function :sfTransformable_destroy, [:transformable_t], :void
|
|
684
|
+
attach_function :sfTransformable_setPosition, [:transformable_t, System::Vector2f.by_value], :void
|
|
685
|
+
attach_function :sfTransformable_getPosition, [:transformable_t], System::Vector2f.by_value
|
|
686
|
+
attach_function :sfTransformable_setRotation, [:transformable_t, :float], :void
|
|
687
|
+
attach_function :sfTransformable_getRotation, [:transformable_t], :float
|
|
688
|
+
attach_function :sfTransformable_setScale, [:transformable_t, System::Vector2f.by_value], :void
|
|
689
|
+
attach_function :sfTransformable_getScale, [:transformable_t], System::Vector2f.by_value
|
|
690
|
+
attach_function :sfTransformable_setOrigin, [:transformable_t, System::Vector2f.by_value], :void
|
|
691
|
+
attach_function :sfTransformable_getOrigin, [:transformable_t], System::Vector2f.by_value
|
|
692
|
+
attach_function :sfTransformable_move, [:transformable_t, System::Vector2f.by_value], :void
|
|
693
|
+
attach_function :sfTransformable_rotate, [:transformable_t, :float], :void
|
|
694
|
+
attach_function :sfTransformable_scale, [:transformable_t, System::Vector2f.by_value], :void
|
|
695
|
+
attach_function :sfTransformable_getTransform, [:transformable_t], Transform.by_value
|
|
696
|
+
attach_function :sfTransformable_getInverseTransform, [:transformable_t], Transform.by_value
|
|
555
697
|
end
|
|
556
698
|
end
|
|
557
699
|
end
|
data/lib/sfml/c/network.rb
CHANGED
|
@@ -69,11 +69,51 @@ module SFML
|
|
|
69
69
|
attach_function :sfUdpSocket_maxDatagramSize, [], :uint32
|
|
70
70
|
|
|
71
71
|
# ---- Packet (typed serializer) ----
|
|
72
|
-
attach_function :sfPacket_create,
|
|
73
|
-
attach_function :
|
|
74
|
-
attach_function :
|
|
75
|
-
attach_function :
|
|
76
|
-
attach_function :
|
|
72
|
+
attach_function :sfPacket_create, [], :packet_t
|
|
73
|
+
attach_function :sfPacket_copy, [:packet_t], :packet_t
|
|
74
|
+
attach_function :sfPacket_destroy, [:packet_t], :void
|
|
75
|
+
attach_function :sfPacket_append, [:packet_t, :pointer, :size_t], :void
|
|
76
|
+
attach_function :sfPacket_clear, [:packet_t], :void
|
|
77
|
+
attach_function :sfPacket_getData, [:packet_t], :pointer
|
|
78
|
+
attach_function :sfPacket_getDataSize, [:packet_t], :size_t
|
|
79
|
+
attach_function :sfPacket_getReadPosition, [:packet_t], :size_t
|
|
80
|
+
attach_function :sfPacket_endOfPacket, [:packet_t], :bool
|
|
81
|
+
attach_function :sfPacket_canRead, [:packet_t], :bool
|
|
82
|
+
|
|
83
|
+
attach_function :sfPacket_readBool, [:packet_t], :bool
|
|
84
|
+
attach_function :sfPacket_readInt8, [:packet_t], :int8
|
|
85
|
+
attach_function :sfPacket_readUint8, [:packet_t], :uint8
|
|
86
|
+
attach_function :sfPacket_readInt16, [:packet_t], :int16
|
|
87
|
+
attach_function :sfPacket_readUint16, [:packet_t], :uint16
|
|
88
|
+
attach_function :sfPacket_readInt32, [:packet_t], :int32
|
|
89
|
+
attach_function :sfPacket_readUint32, [:packet_t], :uint32
|
|
90
|
+
attach_function :sfPacket_readInt64, [:packet_t], :int64
|
|
91
|
+
attach_function :sfPacket_readUint64, [:packet_t], :uint64
|
|
92
|
+
attach_function :sfPacket_readFloat, [:packet_t], :float
|
|
93
|
+
attach_function :sfPacket_readDouble, [:packet_t], :double
|
|
94
|
+
# CSFML's `readString` writes a NUL-terminated C string into a
|
|
95
|
+
# caller-allocated buffer. We size the buffer from the packet's
|
|
96
|
+
# remaining bytes — the encoded length precedes the chars, so
|
|
97
|
+
# `getDataSize - getReadPosition` is a safe upper bound.
|
|
98
|
+
attach_function :sfPacket_readString, [:packet_t, :pointer], :void
|
|
99
|
+
|
|
100
|
+
attach_function :sfPacket_writeBool, [:packet_t, :bool], :void
|
|
101
|
+
attach_function :sfPacket_writeInt8, [:packet_t, :int8], :void
|
|
102
|
+
attach_function :sfPacket_writeUint8, [:packet_t, :uint8], :void
|
|
103
|
+
attach_function :sfPacket_writeInt16, [:packet_t, :int16], :void
|
|
104
|
+
attach_function :sfPacket_writeUint16, [:packet_t, :uint16], :void
|
|
105
|
+
attach_function :sfPacket_writeInt32, [:packet_t, :int32], :void
|
|
106
|
+
attach_function :sfPacket_writeUint32, [:packet_t, :uint32], :void
|
|
107
|
+
attach_function :sfPacket_writeInt64, [:packet_t, :int64], :void
|
|
108
|
+
attach_function :sfPacket_writeUint64, [:packet_t, :uint64], :void
|
|
109
|
+
attach_function :sfPacket_writeFloat, [:packet_t, :float], :void
|
|
110
|
+
attach_function :sfPacket_writeDouble, [:packet_t, :double], :void
|
|
111
|
+
attach_function :sfPacket_writeString, [:packet_t, :string], :void
|
|
112
|
+
|
|
113
|
+
attach_function :sfTcpSocket_sendPacket, [:tcp_socket_t, :packet_t], :int
|
|
114
|
+
attach_function :sfTcpSocket_receivePacket, [:tcp_socket_t, :packet_t], :int, blocking: true
|
|
115
|
+
attach_function :sfUdpSocket_sendPacket, [:udp_socket_t, :packet_t, IpAddress.by_value, :uint16], :int
|
|
116
|
+
attach_function :sfUdpSocket_receivePacket, [:udp_socket_t, :packet_t, :pointer, :pointer], :int, blocking: true
|
|
77
117
|
|
|
78
118
|
# ---- HTTP ----
|
|
79
119
|
typedef :pointer, :http_t
|
data/lib/sfml/c/system.rb
CHANGED
|
@@ -48,6 +48,18 @@ module SFML
|
|
|
48
48
|
attach_function :sfBuffer_destroy, [:buffer_t], :void
|
|
49
49
|
attach_function :sfBuffer_getSize, [:buffer_t], :size_t
|
|
50
50
|
attach_function :sfBuffer_getData, [:buffer_t], :pointer
|
|
51
|
+
|
|
52
|
+
# sfInputStream — a struct of 4 function pointers Ruby fills in
|
|
53
|
+
# to expose a Ruby IO-like object to CSFML's loader functions.
|
|
54
|
+
# User-data is ignored; we close over the Ruby object in each
|
|
55
|
+
# callback closure directly.
|
|
56
|
+
class InputStream < FFI::Struct
|
|
57
|
+
layout :read, :pointer,
|
|
58
|
+
:seek, :pointer,
|
|
59
|
+
:tell, :pointer,
|
|
60
|
+
:get_size, :pointer,
|
|
61
|
+
:user_data, :pointer
|
|
62
|
+
end
|
|
51
63
|
end
|
|
52
64
|
end
|
|
53
65
|
end
|
data/lib/sfml/c/window.rb
CHANGED
|
@@ -159,9 +159,16 @@ module SFML
|
|
|
159
159
|
end
|
|
160
160
|
end
|
|
161
161
|
|
|
162
|
-
attach_function :sfVideoMode_getDesktopMode,
|
|
162
|
+
attach_function :sfVideoMode_getDesktopMode, [], VideoMode.by_value
|
|
163
|
+
attach_function :sfVideoMode_getFullscreenModes, [:pointer], :pointer
|
|
164
|
+
attach_function :sfVideoMode_isValid, [VideoMode.by_value], :bool
|
|
163
165
|
|
|
164
|
-
attach_function :sfKeyboard_isKeyPressed,
|
|
166
|
+
attach_function :sfKeyboard_isKeyPressed, [:int], :bool
|
|
167
|
+
attach_function :sfKeyboard_isScancodePressed, [:int], :bool
|
|
168
|
+
attach_function :sfKeyboard_localize, [:int], :int
|
|
169
|
+
attach_function :sfKeyboard_delocalize, [:int], :int
|
|
170
|
+
attach_function :sfKeyboard_getDescription, [:int], :string
|
|
171
|
+
attach_function :sfKeyboard_setVirtualKeyboardVisible, [:bool], :void
|
|
165
172
|
|
|
166
173
|
# Mouse: position queries here use a sfWindow*. Pass NULL to get
|
|
167
174
|
# desktop-relative coordinates. The render-window variants live in
|
|
@@ -260,6 +267,17 @@ module SFML
|
|
|
260
267
|
# to use defaults.
|
|
261
268
|
attach_function :sfWindow_createFromHandle, [:pointer, :pointer], :raw_window_t
|
|
262
269
|
attach_function :sfWindow_getNativeHandle, [:raw_window_t], :pointer
|
|
270
|
+
|
|
271
|
+
# ---- Context (headless GL context — for off-screen shader
|
|
272
|
+
# compilation or raw GL work without a window) ----
|
|
273
|
+
typedef :pointer, :context_t
|
|
274
|
+
attach_function :sfContext_create, [], :context_t
|
|
275
|
+
attach_function :sfContext_destroy, [:context_t], :void
|
|
276
|
+
attach_function :sfContext_isExtensionAvailable, [:string], :bool
|
|
277
|
+
attach_function :sfContext_setActive, [:context_t, :bool], :bool
|
|
278
|
+
attach_function :sfContext_getFunction, [:string], :pointer
|
|
279
|
+
attach_function :sfContext_getSettings, [:context_t], ContextSettings.by_value
|
|
280
|
+
attach_function :sfContext_getActiveContextId, [], :uint64
|
|
263
281
|
end
|
|
264
282
|
end
|
|
265
283
|
end
|
|
@@ -10,6 +10,7 @@ module SFML
|
|
|
10
10
|
# window.draw(ball)
|
|
11
11
|
class CircleShape
|
|
12
12
|
include Graphics::Transformable
|
|
13
|
+
include Graphics::ShapeInspectable
|
|
13
14
|
CSFML_PREFIX = :sfCircleShape
|
|
14
15
|
|
|
15
16
|
def initialize(radius: 10.0, **opts)
|
|
@@ -22,6 +23,8 @@ module SFML
|
|
|
22
23
|
self.fill_color = opts[:fill_color] if opts.key?(:fill_color)
|
|
23
24
|
self.outline_color = opts[:outline_color] if opts.key?(:outline_color)
|
|
24
25
|
self.outline_thickness = opts[:outline_thickness] if opts.key?(:outline_thickness)
|
|
26
|
+
self.texture = opts[:texture] if opts.key?(:texture)
|
|
27
|
+
self.texture_rect = opts[:texture_rect] if opts.key?(:texture_rect)
|
|
25
28
|
self.position = opts[:position] if opts.key?(:position)
|
|
26
29
|
self.origin = opts[:origin] if opts.key?(:origin)
|
|
27
30
|
self.rotation = opts[:rotation] if opts.key?(:rotation)
|
data/lib/sfml/graphics/color.rb
CHANGED
|
@@ -59,6 +59,36 @@ module SFML
|
|
|
59
59
|
new(struct[:r], struct[:g], struct[:b], struct[:a])
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
# Build from a packed 0xRRGGBBAA integer.
|
|
63
|
+
def self.from_integer(value)
|
|
64
|
+
from_native(C::Graphics.sfColor_fromInteger(Integer(value)))
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Pack this color into a single 0xRRGGBBAA integer.
|
|
68
|
+
def to_integer = C::Graphics.sfColor_toInteger(to_native)
|
|
69
|
+
|
|
70
|
+
# Component-wise channel arithmetic (saturating in CSFML — values
|
|
71
|
+
# clamp to [0, 255]).
|
|
72
|
+
|
|
73
|
+
def +(other)
|
|
74
|
+
raise ArgumentError, "Color +: expected SFML::Color" unless other.is_a?(Color)
|
|
75
|
+
self.class.from_native(C::Graphics.sfColor_add(to_native, other.to_native))
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def -(other)
|
|
79
|
+
raise ArgumentError, "Color -: expected SFML::Color" unless other.is_a?(Color)
|
|
80
|
+
self.class.from_native(C::Graphics.sfColor_subtract(to_native, other.to_native))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Channel-wise multiply, e.g. for tinting (white modulates to
|
|
84
|
+
# input; black modulates to black). Uses CSFML's normalised
|
|
85
|
+
# formula `(a * b) / 255`.
|
|
86
|
+
def *(other)
|
|
87
|
+
raise ArgumentError, "Color *: expected SFML::Color" unless other.is_a?(Color)
|
|
88
|
+
self.class.from_native(C::Graphics.sfColor_modulate(to_native, other.to_native))
|
|
89
|
+
end
|
|
90
|
+
alias modulate *
|
|
91
|
+
|
|
62
92
|
# Standard SFML colors.
|
|
63
93
|
BLACK = new(0, 0, 0)
|
|
64
94
|
WHITE = new(255, 255, 255)
|
|
@@ -13,6 +13,7 @@ module SFML
|
|
|
13
13
|
# window.draw(star)
|
|
14
14
|
class ConvexShape
|
|
15
15
|
include Graphics::Transformable
|
|
16
|
+
include Graphics::ShapeInspectable
|
|
16
17
|
CSFML_PREFIX = :sfConvexShape
|
|
17
18
|
|
|
18
19
|
def initialize(points: nil, **opts)
|
|
@@ -24,6 +25,8 @@ module SFML
|
|
|
24
25
|
self.fill_color = opts[:fill_color] if opts.key?(:fill_color)
|
|
25
26
|
self.outline_color = opts[:outline_color] if opts.key?(:outline_color)
|
|
26
27
|
self.outline_thickness = opts[:outline_thickness] if opts.key?(:outline_thickness)
|
|
28
|
+
self.texture = opts[:texture] if opts.key?(:texture)
|
|
29
|
+
self.texture_rect = opts[:texture_rect] if opts.key?(:texture_rect)
|
|
27
30
|
self.position = opts[:position] if opts.key?(:position)
|
|
28
31
|
self.origin = opts[:origin] if opts.key?(:origin)
|
|
29
32
|
self.rotation = opts[:rotation] if opts.key?(:rotation)
|
data/lib/sfml/graphics/font.rb
CHANGED
|
@@ -41,6 +41,25 @@ module SFML
|
|
|
41
41
|
|
|
42
42
|
font = allocate
|
|
43
43
|
font.send(:_take_ownership, ptr)
|
|
44
|
+
# CSFML doesn't copy the font bytes — keep them pinned so the
|
|
45
|
+
# GC doesn't free them while CSFML still references the buffer.
|
|
46
|
+
font.instance_variable_set(:@_memory_pin, buf)
|
|
47
|
+
font
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Load a TTF/OTF from any Ruby IO-like object — file, in-memory,
|
|
51
|
+
# network-backed reader. Keep the IO open until the Font is no
|
|
52
|
+
# longer in use; CSFML reads glyphs lazily.
|
|
53
|
+
def self.from_stream(io)
|
|
54
|
+
stream = SFML::InputStream.new(io)
|
|
55
|
+
ptr = C::Graphics.sfFont_createFromStream(stream.to_ptr)
|
|
56
|
+
raise Error, "sfFont_createFromStream returned NULL" if ptr.null?
|
|
57
|
+
|
|
58
|
+
font = allocate
|
|
59
|
+
font.send(:_take_ownership, ptr)
|
|
60
|
+
# CSFML reads the font lazily from this stream — keep it pinned.
|
|
61
|
+
font.instance_variable_set(:@_stream_pin, stream)
|
|
62
|
+
font.instance_variable_set(:@_io_pin, io)
|
|
44
63
|
font
|
|
45
64
|
end
|
|
46
65
|
|
data/lib/sfml/graphics/image.rb
CHANGED
|
@@ -58,6 +58,18 @@ module SFML
|
|
|
58
58
|
img
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
# Decode an image from any Ruby IO-like object (File, StringIO,
|
|
62
|
+
# network-backed reader). The stream must support read/seek/pos/size.
|
|
63
|
+
def self.from_stream(io)
|
|
64
|
+
stream = SFML::InputStream.new(io)
|
|
65
|
+
ptr = C::Graphics.sfImage_createFromStream(stream.to_ptr)
|
|
66
|
+
raise Error, "sfImage_createFromStream returned NULL — unsupported format?" if ptr.null?
|
|
67
|
+
|
|
68
|
+
img = allocate
|
|
69
|
+
img.send(:_take_ownership, ptr)
|
|
70
|
+
img
|
|
71
|
+
end
|
|
72
|
+
|
|
61
73
|
# Build an image from a raw RGBA byte string. `pixels` must be
|
|
62
74
|
# exactly width*height*4 bytes, row-major from the top-left.
|
|
63
75
|
def self.from_pixels(width, height, pixels)
|
|
@@ -9,6 +9,7 @@ module SFML
|
|
|
9
9
|
# window.draw(wall)
|
|
10
10
|
class RectangleShape
|
|
11
11
|
include Graphics::Transformable
|
|
12
|
+
include Graphics::ShapeInspectable
|
|
12
13
|
CSFML_PREFIX = :sfRectangleShape
|
|
13
14
|
|
|
14
15
|
def initialize(size:, **opts)
|
|
@@ -20,12 +21,16 @@ module SFML
|
|
|
20
21
|
self.fill_color = opts[:fill_color] if opts.key?(:fill_color)
|
|
21
22
|
self.outline_color = opts[:outline_color] if opts.key?(:outline_color)
|
|
22
23
|
self.outline_thickness = opts[:outline_thickness] if opts.key?(:outline_thickness)
|
|
24
|
+
self.texture = opts[:texture] if opts.key?(:texture)
|
|
25
|
+
self.texture_rect = opts[:texture_rect] if opts.key?(:texture_rect)
|
|
23
26
|
self.position = opts[:position] if opts.key?(:position)
|
|
24
27
|
self.origin = opts[:origin] if opts.key?(:origin)
|
|
25
28
|
self.rotation = opts[:rotation] if opts.key?(:rotation)
|
|
26
29
|
self.scale = opts[:scale] if opts.key?(:scale)
|
|
27
30
|
end
|
|
28
31
|
|
|
32
|
+
def point_count = C::Graphics.sfRectangleShape_getPointCount(@handle)
|
|
33
|
+
|
|
29
34
|
def size
|
|
30
35
|
Vector2.from_native(C::Graphics.sfRectangleShape_getSize(@handle))
|
|
31
36
|
end
|
data/lib/sfml/graphics/shader.rb
CHANGED
|
@@ -68,6 +68,18 @@ module SFML
|
|
|
68
68
|
_wrap(ptr)
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
+
# Build a shader from one or more IO-like streams (any object
|
|
72
|
+
# answering read/seek/pos/size). Useful when shader source lives
|
|
73
|
+
# inside an archive or a network resource.
|
|
74
|
+
def self.from_stream(vertex: nil, geometry: nil, fragment: nil)
|
|
75
|
+
_check_at_least_one(vertex, geometry, fragment)
|
|
76
|
+
streams = [vertex, geometry, fragment].map { |io| io && SFML::InputStream.new(io) }
|
|
77
|
+
ptrs = streams.map { |s| s ? s.to_ptr : nil }
|
|
78
|
+
ptr = C::Graphics.sfShader_createFromStream(*ptrs)
|
|
79
|
+
raise Error, "sfShader_createFromStream failed (GLSL compile error?)" if ptr.null?
|
|
80
|
+
_wrap(ptr)
|
|
81
|
+
end
|
|
82
|
+
|
|
71
83
|
# Set a uniform by name. Dispatches to the right CSFML setter based
|
|
72
84
|
# on the Ruby value's type — see the class-level docs for the table.
|
|
73
85
|
def []=(name, value)
|
|
@@ -139,6 +151,56 @@ module SFML
|
|
|
139
151
|
C::Graphics.sfShader_setFloatUniformArray(@handle, name.to_s, buf, values.length)
|
|
140
152
|
end
|
|
141
153
|
|
|
154
|
+
# Set a `uniform bvec2/3/4` from a Ruby Array of booleans. Length
|
|
155
|
+
# picks the dimensionality.
|
|
156
|
+
def set_bvec(name, *components)
|
|
157
|
+
flat = components.flatten
|
|
158
|
+
case flat.length
|
|
159
|
+
when 2
|
|
160
|
+
s = C::Graphics::GlslBvec2.new
|
|
161
|
+
s[:x] = !!flat[0]; s[:y] = !!flat[1]
|
|
162
|
+
C::Graphics.sfShader_setBvec2Uniform(@handle, name.to_s, s)
|
|
163
|
+
when 3
|
|
164
|
+
s = C::Graphics::GlslBvec3.new
|
|
165
|
+
s[:x] = !!flat[0]; s[:y] = !!flat[1]; s[:z] = !!flat[2]
|
|
166
|
+
C::Graphics.sfShader_setBvec3Uniform(@handle, name.to_s, s)
|
|
167
|
+
when 4
|
|
168
|
+
s = C::Graphics::GlslBvec4.new
|
|
169
|
+
s[:x] = !!flat[0]; s[:y] = !!flat[1]; s[:z] = !!flat[2]; s[:w] = !!flat[3]
|
|
170
|
+
C::Graphics.sfShader_setBvec4Uniform(@handle, name.to_s, s)
|
|
171
|
+
else
|
|
172
|
+
raise ArgumentError, "bvec uniform must have 2, 3, or 4 components (got #{flat.length})"
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Set a `uniform mat3` from a 9-element row-major float array (or
|
|
177
|
+
# an SFML::Transform — its 3×3 matrix is read directly).
|
|
178
|
+
def set_mat3(name, matrix)
|
|
179
|
+
values = _coerce_matrix(matrix, 9, "mat3")
|
|
180
|
+
mat = C::Graphics::GlslMat3.new
|
|
181
|
+
values.each_with_index { |v, i| mat[:array][i] = v }
|
|
182
|
+
C::Graphics.sfShader_setMat3Uniform(@handle, name.to_s, mat.pointer)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Set a `uniform mat4` from a 16-element row-major float array.
|
|
186
|
+
def set_mat4(name, matrix)
|
|
187
|
+
values = _coerce_matrix(matrix, 16, "mat4")
|
|
188
|
+
mat = C::Graphics::GlslMat4.new
|
|
189
|
+
values.each_with_index { |v, i| mat[:array][i] = v }
|
|
190
|
+
C::Graphics.sfShader_setMat4Uniform(@handle, name.to_s, mat.pointer)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
# Set a `uniform mat3 arr[N];` / `uniform mat4 arr[N];` from a
|
|
194
|
+
# list of matrices (each a 9- or 16-element flat array, or an
|
|
195
|
+
# SFML::Transform for mat3).
|
|
196
|
+
def set_mat3_array(name, matrices)
|
|
197
|
+
_set_mat_array(name, matrices, 9, :sfShader_setMat3UniformArray)
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def set_mat4_array(name, matrices)
|
|
201
|
+
_set_mat_array(name, matrices, 16, :sfShader_setMat4UniformArray)
|
|
202
|
+
end
|
|
203
|
+
|
|
142
204
|
# Bind this shader as the active GL program. Useful when you
|
|
143
205
|
# want to issue raw GL draw calls under SFML's context. Pair
|
|
144
206
|
# with `Shader.unbind` to restore SFML's default. Most users
|
|
@@ -165,6 +227,30 @@ module SFML
|
|
|
165
227
|
|
|
166
228
|
private
|
|
167
229
|
|
|
230
|
+
def _coerce_matrix(matrix, expected_length, label)
|
|
231
|
+
values =
|
|
232
|
+
case matrix
|
|
233
|
+
when Transform then matrix.matrix
|
|
234
|
+
when Array then matrix.flatten
|
|
235
|
+
else
|
|
236
|
+
raise ArgumentError, "#{label} uniform requires an Array or SFML::Transform (got #{matrix.class})"
|
|
237
|
+
end
|
|
238
|
+
unless values.length == expected_length
|
|
239
|
+
raise ArgumentError, "#{label} uniform needs #{expected_length} elements (got #{values.length})"
|
|
240
|
+
end
|
|
241
|
+
values.map(&:to_f)
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
def _set_mat_array(name, matrices, stride, setter)
|
|
245
|
+
raise ArgumentError, "matrix array must not be empty" if matrices.empty?
|
|
246
|
+
|
|
247
|
+
label = stride == 9 ? "mat3" : "mat4"
|
|
248
|
+
flat = matrices.flat_map { |m| _coerce_matrix(m, stride, label) }
|
|
249
|
+
buf = FFI::MemoryPointer.new(:float, flat.length)
|
|
250
|
+
buf.write_array_of_float(flat)
|
|
251
|
+
C::Graphics.public_send(setter, @handle, name.to_s, buf, matrices.length)
|
|
252
|
+
end
|
|
253
|
+
|
|
168
254
|
# Detect the inner length (2/3/4), pack a contiguous float buffer,
|
|
169
255
|
# and dispatch to the matching CSFML setVec*UniformArray.
|
|
170
256
|
def _set_vec_array_uniform(name, elements)
|