Class: BaseObject

Inherits:
Object
  • Object
show all
Defined in:
lib/rutui/objects.rb

Overview

Base Object Class Dynamic Objects that get drawn on the Screen This class is used as basic class for other objects

Direct Known Subclasses

Axx, Box, Circle, Figlet, Line, Sprite, Table, Text, Textfield

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ BaseObject

Ex.: BaseObject.new({ :x => 1, :y => 20, :obj => [[Pixel.new(1),Pixel.new(2,4,"#")]] })



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rutui/objects.rb', line 10

def initialize options
	@obj = options[:obj]
	@obj = Array.new(height){ Array.new(width) } if @obj.nil?

	@x = options[:x]
	@y = options[:y]
	@x = 1 if @x.nil?
	@y = 1 if @y.nil?

	@height = @obj.size
	@width  = @obj[0].size
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



8
9
10
# File 'lib/rutui/objects.rb', line 8

def height
  @height
end

#objObject

Returns the value of attribute obj.



8
9
10
# File 'lib/rutui/objects.rb', line 8

def obj
  @obj
end

#widthObject

Returns the value of attribute width.



8
9
10
# File 'lib/rutui/objects.rb', line 8

def width
  @width
end

#xObject

Returns the value of attribute x.



8
9
10
# File 'lib/rutui/objects.rb', line 8

def x
  @x
end

#yObject

Returns the value of attribute y.



8
9
10
# File 'lib/rutui/objects.rb', line 8

def y
  @y
end

Instance Method Details

#eachObject

"special" each methods for objects



37
38
39
40
41
42
43
# File 'lib/rutui/objects.rb', line 37

def each 
	@obj.each_with_index do |row,row_count|
		row.each_with_index do |pixel,col_count|
			yield row_count, col_count, pixel
		end
	end
end

#get_pixel(x, y) ⇒ Object

Get pixel by position



32
33
34
# File 'lib/rutui/objects.rb', line 32

def get_pixel x, y
	@obj[x][y] if !@obj[x].nil? and !@obj[x][y].nil?
end

#move(x, y) ⇒ Object

Move object X and Y (modifiers like: -2, 2)



24
# File 'lib/rutui/objects.rb', line 24

def move x, y; @x += x; @y += y; end

#set_pixel(x, y, pixel) ⇒ Object

Set pixel on position on object



28
29
30
# File 'lib/rutui/objects.rb', line 28

def set_pixel x, y, pixel
	@obj[x][y] = pixel if !@obj[x].nil? and !@obj[x][y].nil?
end

#set_position(x, y) ⇒ Object

Set object position X Y



26
# File 'lib/rutui/objects.rb', line 26

def set_position x, y; @x = x; @y = y; end