class Savio::InputBox

Attributes

height[R]
length[R]
selected[R]
shift[RW]
value[R]

Public Class Methods

inputBoxs() click to toggle source
# File lib/savio/InputBox.rb, line 9
def self.inputBoxs
  @@inputBoxs
end
new(args = {}) click to toggle source
Calls superclass method Savio::IORenderable::new
# File lib/savio/InputBox.rb, line 13
def initialize(args = {})
  @@inputBoxs.push(self)
  super(args)

  @selected = args[:selected] || false

  @size = args[:size] || 20

  @shift = false

  @value = args[:value] || @displayName
  @displayName = @value

  @length = args[:length] || @size * 10
  @height = args[:height] || @size * 1.2

  @color = args[:color] || Savio::Colors::White
  @activeColor = args[:activeColor] || Savio::Colors::Green

  @activeTextColor = args[:activeTextColor] || Savio::Colors::White
  @inactiveTextColor = args[:inactiveTextColor] || Savio::Colors::Gray

  build()
end

Public Instance Methods

activeColor=(color) click to toggle source
# File lib/savio/InputBox.rb, line 54
def activeColor=(color)
  @activeColor = color
  rebuild()
end
activeTextcolor=(color) click to toggle source
# File lib/savio/InputBox.rb, line 58
def activeTextcolor=(color)
  @activeTextcolor = color
  rebuild()
end
add() click to toggle source
Calls superclass method Savio::IORenderable#add
# File lib/savio/InputBox.rb, line 44
def add()
  super()
  @display.add
  @container.add
end
addKey(key) click to toggle source
# File lib/savio/InputBox.rb, line 87
def addKey(key)
  if key == "space"
    @value += + " "
    updateDisplay()
  elsif key == "return"
    deselect()
  elsif key == "backspace"
    @value = @value[0...-1]
    updateDisplay()
  elsif key.chars.count == 1
    if @shift == true
      key = key.upcase
    end
    @value += key
    updateDisplay()
  else
    puts "SAVIO : I am a work in progress, and the key you pressed couldnt be handled"
    puts "SAVIO : Unknown key : " + key.to_s
  end
end
build() click to toggle source
# File lib/savio/InputBox.rb, line 152
def build()
  @shown = true

  @display = Text.new(@value,x: @x + 0.02 * @length,y: @y,z: @z + 1, size: @size, color: @inactiveTextColor)
  @height = @display.height * 1.1

  @container = Rectangle.new(x: @x, y: @y, z: @z, height: @height, width: @length, color: @color)

  @display.y = @container.y + @container.height / 2 - @display.height / 2
end
color=(color) click to toggle source
# File lib/savio/InputBox.rb, line 50
def color=(color)
  @color = color
  rebuild()
end
deselect() click to toggle source
# File lib/savio/InputBox.rb, line 132
def deselect()
  @selected = false

  if @value == ""
    @value = @displayName
  end

  @display.text = @value
  @display.color = @inactiveTextColor
  @container.color = @color
end
height=(height) click to toggle source
# File lib/savio/InputBox.rb, line 70
def height=(height)
  @height = height
  rebuild()
end
inactiveTextColor=(color) click to toggle source
# File lib/savio/InputBox.rb, line 62
def inactiveTextColor=(color)
  @inactiveTextColor = color
  rebuild()
end
length=(length) click to toggle source
# File lib/savio/InputBox.rb, line 66
def length=(length)
  @length = length
  rebuild()
end
remove() click to toggle source
Calls superclass method Savio::IORenderable#remove
# File lib/savio/InputBox.rb, line 38
def remove()
  super()
  @display.remove
  @container.remove
end
select() click to toggle source
# File lib/savio/InputBox.rb, line 120
def select()
  @selected = true

  if @value == @displayName
    @value = ""
  end

  @display.text = @value + "|"
  @display.color = @activeTextColor
  @container.color = @activeColor
end
selected=(bool) click to toggle source
# File lib/savio/InputBox.rb, line 112
def selected=(bool)
  if bool == true
    select()
  elsif bool == false
    deselect()
  end
end
size=(size) click to toggle source
Calls superclass method Savio::IORenderable#size=
# File lib/savio/InputBox.rb, line 81
def size=(size)
  @length = size * 10
  @height = size * 1.2
  super(size)
end
toggle() click to toggle source
# File lib/savio/InputBox.rb, line 144
def toggle()
  if @selected
    deselect()
  else
    select()
  end
end
updateDisplay() click to toggle source
# File lib/savio/InputBox.rb, line 108
def updateDisplay()
  @display.text = @value + "|"
end
value=(value) click to toggle source
# File lib/savio/InputBox.rb, line 75
def value=(value)
  @value = value
  @displayName = @value
  @display.text = @value
end