Class: Savio::InputBox

Inherits:
Object
  • Object
show all
Includes:
IORenderable
Defined in:
lib/savio/InputBox.rb

Constant Summary collapse

@@inputBoxs =
[]
@@tabIndex =
0

Instance Attribute Summary collapse

Attributes included from IORenderable

#allowDrag, #draggingEnabled, #duplicate, #enabled, #shown, #size, #x, #y, #z

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IORenderable

#context, #drag, #dragType=, #endDrag, #kill, #rebuild

Constructor Details

#initialize(args = {}) ⇒ InputBox

Returns a new instance of InputBox.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/savio/InputBox.rb', line 15

def initialize(args = {})
  super(args)

  @@inputBoxs.push(self)

  @selected = args[:selected] || false

  @size = args[:size] || 20

  @shift = false

  @value = args[: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()

  if @shown == false
    remove()
  end

end

Instance Attribute Details

#displayNameObject (readonly)

Returns the value of attribute displayName.



6
7
8
# File 'lib/savio/InputBox.rb', line 6

def displayName
  @displayName
end

#heightObject

Returns the value of attribute height.



6
7
8
# File 'lib/savio/InputBox.rb', line 6

def height
  @height
end

#lengthObject

Returns the value of attribute length.



6
7
8
# File 'lib/savio/InputBox.rb', line 6

def length
  @length
end

#selectedObject

Returns the value of attribute selected.



6
7
8
# File 'lib/savio/InputBox.rb', line 6

def selected
  @selected
end

#shiftObject

Returns the value of attribute shift.



5
6
7
# File 'lib/savio/InputBox.rb', line 5

def shift
  @shift
end

#valueObject

Returns the value of attribute value.



6
7
8
# File 'lib/savio/InputBox.rb', line 6

def value
  @value
end

Class Method Details

.inputBoxsObject



9
10
11
# File 'lib/savio/InputBox.rb', line 9

def self.inputBoxs
  @@inputBoxs
end

Instance Method Details

#activeColor=(color) ⇒ Object



61
62
63
64
# File 'lib/savio/InputBox.rb', line 61

def activeColor=(color)
  @activeColor = color
  rebuild()
end

#activeTextcolor=(color) ⇒ Object



65
66
67
68
# File 'lib/savio/InputBox.rb', line 65

def activeTextcolor=(color)
  @activeTextcolor = color
  rebuild()
end

#addObject



51
52
53
54
55
# File 'lib/savio/InputBox.rb', line 51

def add()
  super()
  @display.add
  @container.add
end

#addKey(key) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/savio/InputBox.rb', line 120

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()
  elsif key == "tab"
    tabMover()
  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

#buildObject



184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/savio/InputBox.rb', line 184

def build()
  if @value == ""
    @display = Text.new(@displayName,x: @x + 0.02 * @length,y: @y,z: @z + 1, size: @size, color: @inactiveTextColor)
  else
    @display = Text.new(@value,x: @x + 0.02 * @length,y: @y,z: @z + 1, size: @size, color: @inactiveTextColor)
  end
  @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

#clearObject



91
92
93
94
# File 'lib/savio/InputBox.rb', line 91

def clear()
  @value = ""
  @display.text = @displayName
end

#color=(color) ⇒ Object



57
58
59
60
# File 'lib/savio/InputBox.rb', line 57

def color=(color)
  @color = color
  rebuild()
end

#deselectObject



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/savio/InputBox.rb', line 163

def deselect()
  @selected = false

  if @value == ""
    @display.text = @displayName
  else
    @display.text = @value
  end

  @display.color = @inactiveTextColor
  @container.color = @color
end

#inactiveTextColor=(color) ⇒ Object



69
70
71
72
# File 'lib/savio/InputBox.rb', line 69

def inactiveTextColor=(color)
  @inactiveTextColor = color
  rebuild()
end

#removeObject



45
46
47
48
49
# File 'lib/savio/InputBox.rb', line 45

def remove()
  super()
  @display.remove
  @container.remove
end

#selectObject



155
156
157
158
159
160
161
# File 'lib/savio/InputBox.rb', line 155

def select()
  @selected = true

  @display.text = @value + "|"
  @display.color = @activeTextColor
  @container.color = @activeColor
end

#size=(size) ⇒ Object



96
97
98
99
100
# File 'lib/savio/InputBox.rb', line 96

def size=(size)
  @length = size * 10
  @height = size * 1.2
  super(size)
end

#tabMoverObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/savio/InputBox.rb', line 102

def tabMover()
  if @@tabIndex >= @@inputBoxs.count
    @@tabIndex = 0
  end

  for i in @@tabIndex..@@inputBoxs.count-1 do
    if @@inputBoxs[i].enabled && @@inputBoxs[i].shown
      @@tabIndex = i
      deselect()
      @@inputBoxs[i].select()
    end
    if @selected
      deselect()
      @@tabIndex = 0
    end
  end
end

#toggleObject



176
177
178
179
180
181
182
# File 'lib/savio/InputBox.rb', line 176

def toggle()
  if @selected
    deselect()
  else
    select()
  end
end

#updateDisplayObject



143
144
145
# File 'lib/savio/InputBox.rb', line 143

def updateDisplay()
  @display.text = @value + "|"
end