Class: GGLib::Widget
Overview
The Widget class is an interface between the button class and the window class which allows for user interaction with an area of the screen. This area is referred to as the widget. To make a Widget, simply create a class derived from Widget and override methods as needed:
class MyWidget < Widget #all widgets are subclasses of Widget
attr_reader :text,:font def initialize(window,text)
super(window,Button::Image,0,400,640,480,"img/gui/mywidget image.png",name="My Widget") @text=text; @font=Gosu::Font.new(window, "arial", 50) end
def draw font.draw(text,0,0) if clicked? setImage(Gosu::Image.new) end
end
def onDelete puts "deleted" end
end
See the ‘Widget Programmer’s Handbook` for more info.
Instance Attribute Summary collapse
Attributes inherited from Tile
#inclusive, #x1, #x2, #y1, #y2
Instance Method Summary
collapse
-
#blur ⇒ Object
-
#button ⇒ Object
-
#clicked?(x, y) ⇒ Boolean
-
#del ⇒ Object
-
#draw ⇒ Object
-
#event(type) ⇒ Object
-
#feedText(char) ⇒ Object
-
#focus ⇒ Object
-
#hasFocus? ⇒ Boolean
-
#hasStickyFocus? ⇒ Boolean
-
#initialize(name = "unnamed", x1 = 0, y1 = 0, x2 = 1, y2 = 1, theme = Theme::BlankTheme, acceptsticky = true, z = 0) ⇒ Widget
constructor
-
#intDraw ⇒ Object
-
#onClick ⇒ Object
-
#onDelete ⇒ Object
-
#onDrag(x1, y1, x2, y2) ⇒ Object
-
#onInitialize ⇒ Object
-
#onKeyPress(key) ⇒ Object
-
#onMouseOut ⇒ Object
-
#onMouseOver ⇒ Object
-
#onRightClick ⇒ Object
-
#onRightDrag(x1, y1, x2, y2) ⇒ Object
-
#onStickyBlur ⇒ Object
-
#onStickyFocus ⇒ Object
-
#over?(x, y) ⇒ Boolean
-
#sleep ⇒ Object
-
#sleeping? ⇒ Boolean
-
#stickFocus ⇒ Object
-
#unstickFocus ⇒ Object
-
#wakeUp ⇒ Object
Methods inherited from Tile
#centerOn, deleteAllInstances, deleteById, #each, #eachBorder, getAllInstances, getById, #height, #iTile, #intersect?, intersect?, #isInTile?, #move, setAllInstances, #setCoordinates, #setTile, #width, #xTile
Constructor Details
#initialize(name = "unnamed", x1 = 0, y1 = 0, x2 = 1, y2 = 1, theme = Theme::BlankTheme, acceptsticky = true, z = 0) ⇒ Widget
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/widget.rb', line 28
def initialize(name="unnamed",x1=0,y1=0,x2=1,y2=1,theme=Theme::BlankTheme,acceptsticky=true,z=0) super(x1,y1,x2,y2)
@id=$window.newWidget(self)
@theme=theme.newInstance(self)
@name=name
@sleeping=false
@zfocus=z
@acceptstickyfocus=acceptsticky
onInitialize
end
|
Instance Attribute Details
Returns the value of attribute buttonId.
26
27
28
|
# File 'lib/widget.rb', line 26
def buttonId
@buttonId
end
|
#defimage ⇒ Object
Returns the value of attribute defimage.
26
27
28
|
# File 'lib/widget.rb', line 26
def defimage
@defimage
end
|
#id ⇒ Object
Returns the value of attribute id.
26
27
28
|
# File 'lib/widget.rb', line 26
def id
@id
end
|
#name ⇒ Object
Returns the value of attribute name.
26
27
28
|
# File 'lib/widget.rb', line 26
def name
@name
end
|
#sleeping ⇒ Object
Returns the value of attribute sleeping.
26
27
28
|
# File 'lib/widget.rb', line 26
def sleeping
@sleeping
end
|
#theme ⇒ Object
Returns the value of attribute theme.
27
28
29
|
# File 'lib/widget.rb', line 27
def theme
@theme
end
|
#window ⇒ Object
Returns the value of attribute window.
26
27
28
|
# File 'lib/widget.rb', line 26
def window
@window
end
|
#zfocus ⇒ Object
Returns the value of attribute zfocus.
26
27
28
|
# File 'lib/widget.rb', line 26
def zfocus
@zfocus
end
|
Instance Method Details
#blur ⇒ Object
57
58
59
|
# File 'lib/widget.rb', line 57
def blur onMouseOut end
|
146
147
148
|
# File 'lib/widget.rb', line 146
def button
return Button.getButton(buttonId)
end
|
#clicked?(x, y) ⇒ Boolean
64
65
66
67
68
69
70
|
# File 'lib/widget.rb', line 64
def clicked?(x,y)
if $window.button_down?(Gosu::Button::MsLeft)
return xTile(x,y)
else
return false
end
end
|
#del ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/widget.rb', line 150
def del
onDelete
if $window.nil?
raise "Window assigned to nil" return
end
$window.deleteWidget(self)
super
end
|
#draw ⇒ Object
124
125
|
# File 'lib/widget.rb', line 124
def draw
end
|
#event(type) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/widget.rb', line 72
def event(type) if type==WidgetEvent::MsLeft
if @acceptstickyfocus
stickFocus
end
onClick
elsif type==WidgetEvent::MsRight
onRightClick
else
onKeyPress(type)
end
end
|
#feedText(char) ⇒ Object
85
86
|
# File 'lib/widget.rb', line 85
def feedText(char)
end
|
#focus ⇒ Object
52
53
54
55
56
|
# File 'lib/widget.rb', line 52
def focus $window.setFocus(@id)
onMouseOver end
|
#hasFocus? ⇒ Boolean
38
39
40
41
42
43
44
|
# File 'lib/widget.rb', line 38
def hasFocus? if $window.hasFocus == self
return true
else
return false
end
end
|
#hasStickyFocus? ⇒ Boolean
45
46
47
48
49
50
51
|
# File 'lib/widget.rb', line 45
def hasStickyFocus? if $window.hasStickyFocus == self
return true
else
return false
end
end
|
#intDraw ⇒ Object
117
118
119
120
121
122
|
# File 'lib/widget.rb', line 117
def intDraw
if not @sleeping
@theme.draw
draw
end
end
|
#onClick ⇒ Object
87
88
|
# File 'lib/widget.rb', line 87
def onClick
end
|
#onDelete ⇒ Object
105
106
|
# File 'lib/widget.rb', line 105
def onDelete
end
|
#onDrag(x1, y1, x2, y2) ⇒ Object
91
92
|
# File 'lib/widget.rb', line 91
def onDrag(x1, y1, x2, y2)
end
|
#onInitialize ⇒ Object
103
104
|
# File 'lib/widget.rb', line 103
def onInitialize
end
|
#onKeyPress(key) ⇒ Object
107
108
|
# File 'lib/widget.rb', line 107
def onKeyPress(key)
end
|
#onMouseOut ⇒ Object
99
100
|
# File 'lib/widget.rb', line 99
def onMouseOut
end
|
#onMouseOver ⇒ Object
95
96
|
# File 'lib/widget.rb', line 95
def onMouseOver
end
|
#onRightClick ⇒ Object
89
90
|
# File 'lib/widget.rb', line 89
def onRightClick
end
|
#onRightDrag(x1, y1, x2, y2) ⇒ Object
93
94
|
# File 'lib/widget.rb', line 93
def onRightDrag(x1, y1, x2, y2)
end
|
#onStickyBlur ⇒ Object
101
102
|
# File 'lib/widget.rb', line 101
def onStickyBlur
end
|
#onStickyFocus ⇒ Object
97
98
|
# File 'lib/widget.rb', line 97
def onStickyFocus
end
|
#over?(x, y) ⇒ Boolean
61
62
63
|
# File 'lib/widget.rb', line 61
def over?(x,y)
return iTile(x,y)
end
|
#sleep ⇒ Object
127
128
129
130
131
132
133
134
135
|
# File 'lib/widget.rb', line 127
def sleep
if not @sleeping
if hasStickyFocus?
$window.setStickyFocus(nil)
end
@theme.setSleepState
@sleeping=true
end
end
|
#sleeping? ⇒ Boolean
136
137
138
|
# File 'lib/widget.rb', line 136
def sleeping?
return @sleeping
end
|
#stickFocus ⇒ Object
110
111
112
|
# File 'lib/widget.rb', line 110
def stickFocus
$window.setStickyFocus(self)
end
|
#unstickFocus ⇒ Object
113
114
115
|
# File 'lib/widget.rb', line 113
def unstickFocus
$window.setStickyFocus(nil)
end
|
#wakeUp ⇒ Object
139
140
141
142
143
144
|
# File 'lib/widget.rb', line 139
def wakeUp
if @sleeping
@theme.setWakeState
@sleeping=false
end
end
|