Module: SFML::Graphics::Transformable

Included in:
CircleShape, ConvexShape, RectangleShape, Sprite, Text
Defined in:
lib/sfml/graphics/transformable.rb

Overview

Shared transform interface for Sprite, CircleShape, RectangleShape (and Text once added). Including class must:

1. Define a constant CSFML_PREFIX (Symbol), e.g. :sfCircleShape
2. Hold the FFI handle in @handle

All wrappers go through C::Graphics.public_send so the same Ruby code picks up sfSprite_*, sfCircleShape_*, sfRectangleShape_* etc. without repetition. The cost (~1µs of method dispatch on a typical call) is negligible against any GPU work, but the wins on maintainability are large — adding a new shape becomes ~5 lines.

Instance Method Summary collapse

Instance Method Details

#move(offset) ⇒ Object



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

def move(offset)
  _csfml(:move, @handle, _coerce_vec2(offset).to_native_f)
  self
end

#originObject



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

def origin
  Vector2.from_native(_csfml(:getOrigin, @handle))
end

#origin=(value) ⇒ Object



42
43
44
# File 'lib/sfml/graphics/transformable.rb', line 42

def origin=(value)
  _csfml(:setOrigin, @handle, _coerce_vec2(value).to_native_f)
end

#positionObject



14
15
16
# File 'lib/sfml/graphics/transformable.rb', line 14

def position
  Vector2.from_native(_csfml(:getPosition, @handle))
end

#position=(value) ⇒ Object



18
19
20
# File 'lib/sfml/graphics/transformable.rb', line 18

def position=(value)
  _csfml(:setPosition, @handle, _coerce_vec2(value).to_native_f)
end

#rotate(degrees) ⇒ Object



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

def rotate(degrees)
  _csfml(:rotate, @handle, degrees.to_f)
  self
end

#rotationObject



22
23
24
# File 'lib/sfml/graphics/transformable.rb', line 22

def rotation
  _csfml(:getRotation, @handle)
end

#rotation=(degrees) ⇒ Object



26
27
28
# File 'lib/sfml/graphics/transformable.rb', line 26

def rotation=(degrees)
  _csfml(:setRotation, @handle, degrees.to_f)
end

#scaleObject



30
31
32
# File 'lib/sfml/graphics/transformable.rb', line 30

def scale
  Vector2.from_native(_csfml(:getScale, @handle))
end

#scale=(value) ⇒ Object



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

def scale=(value)
  _csfml(:setScale, @handle, _coerce_vec2(value).to_native_f)
end

#scale_by(factors) ⇒ Object



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

def scale_by(factors)
  _csfml(:scale, @handle, _coerce_vec2(factors).to_native_f)
  self
end