Class: Rect
- Inherits:
-
Object
- Object
- Rect
- Defined in:
- lib/openrgss/rect.rb
Instance Attribute Summary collapse
-
#height ⇒ Object
The rectangle’s height.
-
#width ⇒ Object
The rectangle’s width.
-
#x ⇒ Object
The x-coordinate of the rectangle’s upper left corner.
-
#y ⇒ Object
The y-coordinate of the rectangle’s upper left corner.
Class Method Summary collapse
-
._load(str) ⇒ Object
Deserialisiert das Objekt.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Vergleichsmethode.
-
#_dump(limit) ⇒ Object
Serialisiert das Objekt.
-
#empty ⇒ Object
Sets all components to 0.
-
#initialize(x = 0, y = 0, width = 0, height = 0) ⇒ Rect
constructor
:call-seq: Rect.new(x, y, width, height) Rect.new.
-
#set(x, y = 0, width = 0, height = 0) ⇒ Object
:call-seq: set(x, y, width, height) set(rect).
- #to_s ⇒ Object
Constructor Details
#initialize(x = 0, y = 0, width = 0, height = 0) ⇒ Rect
:call-seq: Rect.new(x, y, width, height) Rect.new
Creates a new Rect object.
The default values when no arguments are specified are (0, 0, 0, 0).
23 24 25 |
# File 'lib/openrgss/rect.rb', line 23 def initialize(x=0, y=0, width=0, height=0) set(x, y, width, height) end |
Instance Attribute Details
#height ⇒ Object
The rectangle’s height.
13 14 15 |
# File 'lib/openrgss/rect.rb', line 13 def height @height end |
#width ⇒ Object
The rectangle’s width.
10 11 12 |
# File 'lib/openrgss/rect.rb', line 10 def width @width end |
#x ⇒ Object
The x-coordinate of the rectangle’s upper left corner.
4 5 6 |
# File 'lib/openrgss/rect.rb', line 4 def x @x end |
#y ⇒ Object
The y-coordinate of the rectangle’s upper left corner.
7 8 9 |
# File 'lib/openrgss/rect.rb', line 7 def y @y end |
Class Method Details
._load(str) ⇒ Object
Deserialisiert das Objekt
74 75 76 |
# File 'lib/openrgss/rect.rb', line 74 def self._load str new(*str.unpack("iiii")) end |
Instance Method Details
#==(other) ⇒ Object
Vergleichsmethode
60 61 62 63 64 65 66 |
# File 'lib/openrgss/rect.rb', line 60 def == other if other.kind_of?(Rect) then x == other.x && y == other.y && width == other.width && height == other.height else raise TypeError.new("Can't convert #{other.class} to Rect") end end |
#_dump(limit) ⇒ Object
Serialisiert das Objekt
69 70 71 |
# File 'lib/openrgss/rect.rb', line 69 def _dump limit [x, y, width, height].pack("iiii") end |
#empty ⇒ Object
Sets all components to 0.
55 56 57 |
# File 'lib/openrgss/rect.rb', line 55 def empty set(0, 0, 0, 0) end |
#set(x, y = 0, width = 0, height = 0) ⇒ Object
:call-seq: set(x, y, width, height) set(rect)
Sets all parameters at once.
The second format copies all the components from a separate Rect object.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/openrgss/rect.rb', line 35 def set(x, y=0, width=0, height=0) if x.is_a? Rect rect = x @x = rect.x @y = rect.y @width = rect.width @height = rect.height else @x = x @y = y @width = width @height = height end end |
#to_s ⇒ Object
50 51 52 |
# File 'lib/openrgss/rect.rb', line 50 def to_s "(#{x}, #{y}, #{width}, #{height})" end |