Class: GGLib::Button

Inherits:
Widget show all
Defined in:
lib/ext/widgets.rb

Constant Summary collapse

TextColor =
0xff000000

Instance Attribute Summary collapse

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

#acceptStickyFocus?, #acceptText?, #blur, #button, #clicked?, #del, #downevent, #event, #feedText, #focus, #hasFocus?, #hasStickyFocus?, #intDraw, #onDelete, #onDrag, #onInitialize, #onKeyDown, #onKeyUp, #onRightClick, #onRightDrag, #onRightMouseDown, #onStickyBlur, #onStickyFocus, #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, #width, #xTile

Constructor Details

#initialize(name, text, x, y, onClickPrc = Proc.new{}, theme = Themes::blank) ⇒ Button

Returns a new instance of Button.



313
314
315
316
317
318
319
# File 'lib/ext/widgets.rb', line 313

def initialize(name, text, x, y, onClickPrc=Proc.new{}, theme = Themes::blank)
  super(name, x, y, x+100, y+30, theme)
  @text=text
  @onClickPrc=onClickPrc
  @drawx=x+((100-@theme.font.default.text_width(@text))/2).floor
  @drawy=y+((30-@theme.font.default.height)/2).floor
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



312
313
314
# File 'lib/ext/widgets.rb', line 312

def text
  @text
end

Instance Method Details

#drawObject



345
346
347
# File 'lib/ext/widgets.rb', line 345

def draw
  @theme.font.default.draw(@text, @drawx, @drawy, ZOrder::Text, 1, 1, @theme.font.color)
end

#onClickObject



331
332
333
334
335
336
337
338
# File 'lib/ext/widgets.rb', line 331

def onClick
  @onClickPrc.call(self)
  if self.hasFocus?
    @theme.setOverState
  else
    @theme.setDefaultState
  end
end

#onMouseDownObject



328
329
330
# File 'lib/ext/widgets.rb', line 328

def onMouseDown
  @theme.setDownState
end

#onMouseOutObject



342
343
344
# File 'lib/ext/widgets.rb', line 342

def onMouseOut
  @theme.setDefaultState
end

#onMouseOverObject



339
340
341
# File 'lib/ext/widgets.rb', line 339

def onMouseOver
  @theme.setOverState
end

#x1=Object



320
321
322
323
# File 'lib/ext/widgets.rb', line 320

def x1=
  super
  @drawx=x+((100-@theme.font.default.text_width(@text))/2).floor
end

#y1=Object



324
325
326
327
# File 'lib/ext/widgets.rb', line 324

def y1=
  super
  @drawy=y+((30-@theme.font.default.height)/2).floor
end