Class: SFML::RectangleShape

Inherits:
Object
  • Object
show all
Includes:
Graphics::ShapeInspectable, 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::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(size:, **opts) ⇒ RectangleShape

Returns a new instance of RectangleShape.

Raises:



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

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.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

#handleObject (readonly)

:nodoc:



65
66
67
# File 'lib/sfml/graphics/rectangle_shape.rb', line 65

def handle
  @handle
end

Instance Method Details

#draw_on(target, states_ptr = nil) ⇒ Object

:nodoc:



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

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

#fill_colorObject



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

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

#fill_color=(c) ⇒ Object



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

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

#outline_colorObject



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

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

#outline_color=(c) ⇒ Object



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

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

#outline_thicknessObject



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

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

#outline_thickness=(t) ⇒ Object



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

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

#point_countObject



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

def point_count = C::Graphics.sfRectangleShape_getPointCount(@handle)

#sizeObject



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

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

#size=(value) ⇒ Object



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

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