Class: SFML::RectangleShape

Inherits:
Object
  • Object
show all
Includes:
Graphics::Transformable
Defined in:
lib/sfml/graphics/rectangle_shape.rb

Overview

An axis-aligned filled rectangle.

wall = SFML::RectangleShape.new(
  size: [200, 40],
  position: [100, 500],
  fill_color: SFML::Color["#444"],
)
window.draw(wall)

Constant Summary collapse

CSFML_PREFIX =
:sfRectangleShape

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Graphics::Transformable

#move, #origin, #origin=, #position, #position=, #rotate, #rotation, #rotation=, #scale, #scale=, #scale_by

Constructor Details

#initialize(size:, **opts) ⇒ RectangleShape

Returns a new instance of RectangleShape.

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sfml/graphics/rectangle_shape.rb', line 14

def initialize(size:, **opts)
  ptr = C::Graphics.sfRectangleShape_create
  raise Error, "sfRectangleShape_create returned NULL" if ptr.null?
  @handle = FFI::AutoPointer.new(ptr, C::Graphics.method(:sfRectangleShape_destroy))

  self.size = size
  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.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

#handleObject (readonly)

:nodoc:



60
61
62
# File 'lib/sfml/graphics/rectangle_shape.rb', line 60

def handle
  @handle
end

Instance Method Details

#draw_on(target, states_ptr = nil) ⇒ Object

:nodoc:



56
57
58
# File 'lib/sfml/graphics/rectangle_shape.rb', line 56

def draw_on(target, states_ptr = nil) # :nodoc:
  target._draw_native(:RectangleShape, @handle, states_ptr)
end

#fill_colorObject



38
# File 'lib/sfml/graphics/rectangle_shape.rb', line 38

def fill_color = Color.from_native(C::Graphics.sfRectangleShape_getFillColor(@handle))

#fill_color=(c) ⇒ Object



40
41
42
# File 'lib/sfml/graphics/rectangle_shape.rb', line 40

def fill_color=(c)
  C::Graphics.sfRectangleShape_setFillColor(@handle, c.to_native)
end

#outline_colorObject



44
# File 'lib/sfml/graphics/rectangle_shape.rb', line 44

def outline_color = Color.from_native(C::Graphics.sfRectangleShape_getOutlineColor(@handle))

#outline_color=(c) ⇒ Object



46
47
48
# File 'lib/sfml/graphics/rectangle_shape.rb', line 46

def outline_color=(c)
  C::Graphics.sfRectangleShape_setOutlineColor(@handle, c.to_native)
end

#outline_thicknessObject



50
# File 'lib/sfml/graphics/rectangle_shape.rb', line 50

def outline_thickness = C::Graphics.sfRectangleShape_getOutlineThickness(@handle)

#outline_thickness=(t) ⇒ Object



52
53
54
# File 'lib/sfml/graphics/rectangle_shape.rb', line 52

def outline_thickness=(t)
  C::Graphics.sfRectangleShape_setOutlineThickness(@handle, t.to_f)
end

#sizeObject



29
30
31
# File 'lib/sfml/graphics/rectangle_shape.rb', line 29

def size
  Vector2.from_native(C::Graphics.sfRectangleShape_getSize(@handle))
end

#size=(value) ⇒ Object



33
34
35
36
# File 'lib/sfml/graphics/rectangle_shape.rb', line 33

def size=(value)
  vec = value.is_a?(Vector2) ? value : Vector2.new(*value)
  C::Graphics.sfRectangleShape_setSize(@handle, vec.to_native_f)
end