Class: SFML::ConvexShape
- Inherits:
-
Object
- Object
- SFML::ConvexShape
- Defined in:
- lib/sfml/graphics/convex_shape.rb
Overview
An arbitrary convex polygon. Define its outline by listing points in order (clockwise or counter-clockwise — just stay consistent). The shape must remain convex — drawing a non-convex point set produces visual artifacts (CSFML doesn’t validate).
star = SFML::ConvexShape.new(
points: [[60, 0], [80, 40], [120, 50], [90, 80],
[100, 120], [60, 95], [20, 120], [30, 80],
[0, 50], [40, 40]],
fill_color: SFML::Color.yellow,
)
window.draw(star)
Constant Summary collapse
- CSFML_PREFIX =
:sfConvexShape
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#draw_on(target, states_ptr = nil) ⇒ Object
:nodoc:.
- #fill_color ⇒ Object
- #fill_color=(c) ⇒ Object
-
#initialize(points: nil, **opts) ⇒ ConvexShape
constructor
A new instance of ConvexShape.
- #outline_color ⇒ Object
- #outline_color=(c) ⇒ Object
- #outline_thickness ⇒ Object
- #outline_thickness=(t) ⇒ Object
- #point_count ⇒ Object
-
#points ⇒ Object
Returns the polygon vertices as an Array of Vector2.
-
#points=(list) ⇒ Object
Replace every point.
-
#set_point(index, point) ⇒ Object
Mutate a single vertex by index.
Methods included from Graphics::ShapeInspectable
#dup, #geometric_center, #global_bounds, #inverse_transform, #local_bounds, #point, #set_texture, #texture, #texture=, #texture_rect, #texture_rect=, #transform
Methods included from Graphics::Transformable
#move, #origin, #origin=, #position, #position=, #rotate, #rotation, #rotation=, #scale, #scale=, #scale_by
Constructor Details
#initialize(points: nil, **opts) ⇒ ConvexShape
Returns a new instance of ConvexShape.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sfml/graphics/convex_shape.rb', line 19 def initialize(points: nil, **opts) ptr = C::Graphics.sfConvexShape_create raise Error, "sfConvexShape_create returned NULL" if ptr.null? @handle = FFI::AutoPointer.new(ptr, C::Graphics.method(:sfConvexShape_destroy)) self.points = points if points self.fill_color = opts[:fill_color] if opts.key?(:fill_color) self.outline_color = opts[:outline_color] if opts.key?(:outline_color) self.outline_thickness = opts[:outline_thickness] if opts.key?(:outline_thickness) self.texture = opts[:texture] if opts.key?(:texture) self.texture_rect = opts[:texture_rect] if opts.key?(:texture_rect) self.position = opts[:position] if opts.key?(:position) self.origin = opts[:origin] if opts.key?(:origin) self.rotation = opts[:rotation] if opts.key?(:rotation) self.scale = opts[:scale] if opts.key?(:scale) end |
Instance Attribute Details
#handle ⇒ Object (readonly)
:nodoc:
83 84 85 |
# File 'lib/sfml/graphics/convex_shape.rb', line 83 def handle @handle end |
Instance Method Details
#draw_on(target, states_ptr = nil) ⇒ Object
:nodoc:
79 80 81 |
# File 'lib/sfml/graphics/convex_shape.rb', line 79 def draw_on(target, states_ptr = nil) # :nodoc: target._draw_native(:ConvexShape, @handle, states_ptr) end |
#fill_color ⇒ Object
61 |
# File 'lib/sfml/graphics/convex_shape.rb', line 61 def fill_color = Color.from_native(C::Graphics.sfConvexShape_getFillColor(@handle)) |
#fill_color=(c) ⇒ Object
63 64 65 |
# File 'lib/sfml/graphics/convex_shape.rb', line 63 def fill_color=(c) C::Graphics.sfConvexShape_setFillColor(@handle, c.to_native) end |
#outline_color ⇒ Object
67 |
# File 'lib/sfml/graphics/convex_shape.rb', line 67 def outline_color = Color.from_native(C::Graphics.sfConvexShape_getOutlineColor(@handle)) |
#outline_color=(c) ⇒ Object
69 70 71 |
# File 'lib/sfml/graphics/convex_shape.rb', line 69 def outline_color=(c) C::Graphics.sfConvexShape_setOutlineColor(@handle, c.to_native) end |
#outline_thickness ⇒ Object
73 |
# File 'lib/sfml/graphics/convex_shape.rb', line 73 def outline_thickness = C::Graphics.sfConvexShape_getOutlineThickness(@handle) |
#outline_thickness=(t) ⇒ Object
75 76 77 |
# File 'lib/sfml/graphics/convex_shape.rb', line 75 def outline_thickness=(t) C::Graphics.sfConvexShape_setOutlineThickness(@handle, t.to_f) end |
#point_count ⇒ Object
36 |
# File 'lib/sfml/graphics/convex_shape.rb', line 36 def point_count = C::Graphics.sfConvexShape_getPointCount(@handle) |
#points ⇒ Object
Returns the polygon vertices as an Array of Vector2.
39 40 41 42 43 44 |
# File 'lib/sfml/graphics/convex_shape.rb', line 39 def points n = point_count (0...n).map do |i| Vector2.from_native(C::Graphics.sfConvexShape_getPoint(@handle, i)) end end |
#points=(list) ⇒ Object
Replace every point. Accepts a list of [x, y] arrays or Vector2s.
47 48 49 50 51 52 53 |
# File 'lib/sfml/graphics/convex_shape.rb', line 47 def points=(list) C::Graphics.sfConvexShape_setPointCount(@handle, list.length) list.each_with_index do |pt, i| vec = pt.is_a?(Vector2) ? pt : Vector2.new(*pt) C::Graphics.sfConvexShape_setPoint(@handle, i, vec.to_native_f) end end |