Class: GGLib::TextBox
Constant Summary
collapse
- CaretColor =
0xff646464
- TextColor =
0xff646464
- SelColor =
0xff33FFFF
- TextPadding =
5
Instance Attribute Summary
Attributes inherited from Widget
#buttonId, #defimage, #id, #name, #sleeping, #theme, #window, #zfocus
Attributes inherited from Containable
#align, #container, #maxSize, #minSize, #offset, #padding, #valign
Attributes inherited from Tile
#id, #inclusive, #x1, #x2, #y1, #y2
Instance Method Summary
collapse
Methods inherited from Widget
#acceptText?, #blur, #button, #clicked?, #del, #downevent, #event, #feedText, #focus, #hasFocus?, #hasStickyFocus?, #intDraw, #onClick, #onDelete, #onDrag, #onInitialize, #onKeyDown, #onKeyUp, #onMouseDown, #onRightClick, #onRightDrag, #onRightMouseDown, #over?, #sleep, #sleeping?, #stickFocus, #unstickFocus, #wakeUp
Methods inherited from Tile
#centerOn, #del, deleteAllInstances, deleteById, #each, #eachBorder, getAllInstances, getById, #height, #iTile, #intersect?, intersect?, #isInTile?, #move, #resize, setAllInstances, #setCoordinates, #setTile, #xTile
Constructor Details
#initialize(name, x, y, len = 12, theme = Themes::blank, w = nil, height = nil) ⇒ TextBox
Returns a new instance of TextBox.
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
# File 'lib/ext/widgets.rb', line 239
def initialize(name, x, y, len=12, theme=Themes::blank, w=nil,height=nil)
if width!=nil and height!=nil
super(name, x, y, x+w, y+h, theme)
else
@theme = theme.newInstance(self) @theme.setCoords(1,1,1,1)
super(name, x, y, x+@theme.width, y+@theme.height, theme)
@theme.setCoords(@x1, @y1, @x2, @y2)
end
@textinput=Gosu::TextInput.new
@offsety=((@theme.height-@theme.font.editable.height)/2).floor
@maxlength=len
@x=x
@y=y
@drawcursor=0
@realwidth=@x + TextPadding
end
|
Instance Method Details
#acceptStickyFocus? ⇒ Boolean
256
257
258
|
# File 'lib/ext/widgets.rb', line 256
def acceptStickyFocus?
return true
end
|
#draw ⇒ Object
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
# File 'lib/ext/widgets.rb', line 286
def draw
text=@textinput.text.slice(0,12)
if self.hasStickyFocus?
pos_x = @x + @theme.font.editable.text_width(@textinput.text[0...@textinput.caret_pos]) + TextPadding
sel_x = @x + @theme.font.editable.text_width(@textinput.text[0...@textinput.selection_start]) + TextPadding
@realwidth+=@theme.font.editable.text_width(text)
if pos_x > @realwidth
pos_x=@realwidth+1
sel_x=@realwidth+1
@textinput.text=text
end
@realwidth-=@theme.font.editable.text_width(text)
if @drawcursor < 18
$window.draw_line(pos_x, @y+@offsety, CaretColor, pos_x, @y+@theme.font.editable.height+@offsety, CaretColor, ZOrder::Text)
elsif @drawcursor > 36
@drawcursor=0
end
@drawcursor+=1
$window.draw_quad(sel_x, @y+@offsety, @theme.font.selcolor, pos_x, @y+@offsety, @theme.font.selcolor, sel_x, @y+@theme.font.editable.height+@offsety, @theme.font.selcolor, pos_x, @y+@theme.font.editable.height+@offsety, @theme.font.selcolor, ZOrder::Text-0.5)
end
@theme.font.editable.draw(text, @x+TextPadding, @y+@offsety, ZOrder::Text, 1, 1, @theme.font.color)
end
|
#onMouseClick ⇒ Object
265
266
267
|
# File 'lib/ext/widgets.rb', line 265
def onMouseClick
stickFocus
end
|
#onMouseOut ⇒ Object
262
263
264
|
# File 'lib/ext/widgets.rb', line 262
def onMouseOut
@theme.setDefaultState unless self.hasStickyFocus?
end
|
#onMouseOver ⇒ Object
259
260
261
|
# File 'lib/ext/widgets.rb', line 259
def onMouseOver
@theme.setOverState unless self.hasStickyFocus?
end
|
#onStickyBlur ⇒ Object
272
273
274
275
|
# File 'lib/ext/widgets.rb', line 272
def onStickyBlur
@theme.setDefaultState
$window.setTextInput(nil)
end
|
#onStickyFocus ⇒ Object
268
269
270
271
|
# File 'lib/ext/widgets.rb', line 268
def onStickyFocus
@theme.setOverState
$window.setTextInput(@textinput)
end
|
#text ⇒ Object
279
280
281
|
# File 'lib/ext/widgets.rb', line 279
def text
return @textinput.text
end
|
#text=(val) ⇒ Object
282
283
284
285
|
# File 'lib/ext/widgets.rb', line 282
def text=(val)
val=val.slice(0,12) if val.size>12
@textinput.text = val
end
|
#width ⇒ Object
276
277
278
|
# File 'lib/ext/widgets.rb', line 276
def width
return @maxlength
end
|