Class: SFML::TransformableObject

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

Overview

Standalone transformable — a pure CSFML transform container (no geometry attached). Useful as a base for custom drawables that combine a transform with their own rendering: parent the child’s vertices to this object’s ‘#transform` and you get position / rotation / scale / origin for free.

Most users want the ‘Graphics::Transformable` mixin instead — this standalone class exists for symmetry with the C++ API.

t = SFML::TransformableObject.new(position: [400, 300], rotation: 45)
t.transform   #=> SFML::C::Graphics::Transform (use via RenderStates)

Constant Summary collapse

CSFML_PREFIX =
:sfTransformable

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(**opts) ⇒ TransformableObject

Returns a new instance of TransformableObject.

Raises:



17
18
19
20
21
22
23
24
25
26
# File 'lib/sfml/graphics/transformable_object.rb', line 17

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

  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:



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

def handle
  @handle
end

Instance Method Details

#dupObject Also known as: clone

Raises:



36
37
38
39
40
41
42
43
# File 'lib/sfml/graphics/transformable_object.rb', line 36

def dup
  ptr = C::Graphics.sfTransformable_copy(@handle)
  raise Error, "sfTransformable_copy returned NULL" if ptr.null?
  copy = self.class.allocate
  copy.instance_variable_set(:@handle,
    FFI::AutoPointer.new(ptr, C::Graphics.method(:sfTransformable_destroy)))
  copy
end

#inverse_transformObject



32
33
34
# File 'lib/sfml/graphics/transformable_object.rb', line 32

def inverse_transform
  C::Graphics.sfTransformable_getInverseTransform(@handle)
end

#transformObject



28
29
30
# File 'lib/sfml/graphics/transformable_object.rb', line 28

def transform
  C::Graphics.sfTransformable_getTransform(@handle)
end