Class: Rect

Inherits:
Object
  • Object
show all
Defined in:
lib/openrgss/rect.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#heightObject

The rectangle’s height.



13
14
15
# File 'lib/openrgss/rect.rb', line 13

def height
  @height
end

#widthObject

The rectangle’s width.



10
11
12
# File 'lib/openrgss/rect.rb', line 10

def width
  @width
end

#xObject

The x-coordinate of the rectangle’s upper left corner.



4
5
6
# File 'lib/openrgss/rect.rb', line 4

def x
  @x
end

#yObject

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

#emptyObject

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_sObject



50
51
52
# File 'lib/openrgss/rect.rb', line 50

def to_s
  "(#{x}, #{y}, #{width}, #{height})"
end