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.
Direct Known Subclasses
Button, CheckBox, CheckBox::CheckedHk, DebugConsole, FadeScreen::FadeIn, Label, RadioButton, RadioButton::CheckedHk, RadioGroup, TextBox, TracePanel
Defined Under Namespace
Modules: Event
Instance Attribute Summary collapse
Attributes inherited from Containable
#align, #container, #maxSize, #minSize, #offset, #padding, #valign
Attributes inherited from Tile
#inclusive, #x1, #x2, #y1, #y2
Instance Method Summary
collapse
-
#acceptStickyFocus? ⇒ Boolean
-
#acceptText? ⇒ Boolean
-
#blur ⇒ Object
-
#button ⇒ Object
-
#clicked?(x, y) ⇒ Boolean
-
#del ⇒ Object
-
#downevent(type) ⇒ Object
-
#draw ⇒ Object
-
#event(type, dat = nil) ⇒ Object
-
#feedText(char) ⇒ Object
-
#focus ⇒ Object
-
#hasFocus? ⇒ Boolean
-
#hasStickyFocus? ⇒ Boolean
-
#initialize(name = "unnamed", x1 = 0, y1 = 0, x2 = 1, y2 = 1, theme = Themes::blank, z = 0) ⇒ Widget
constructor
-
#intDraw ⇒ Object
-
#onClick ⇒ Object
-
#onDelete ⇒ Object
-
#onDrag(x1, y1, x2, y2) ⇒ Object
-
#onInitialize ⇒ Object
-
#onKeyDown(key) ⇒ Object
-
#onKeyUp(key) ⇒ Object
-
#onMouseDown ⇒ Object
-
#onMouseOut ⇒ Object
-
#onMouseOver ⇒ Object
-
#onRightClick ⇒ Object
-
#onRightDrag(x1, y1, x2, y2) ⇒ Object
-
#onRightMouseDown ⇒ 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, #resize, setAllInstances, #setCoordinates, #setTile, #width, #xTile
Constructor Details
#initialize(name = "unnamed", x1 = 0, y1 = 0, x2 = 1, y2 = 1, theme = Themes::blank, z = 0) ⇒ Widget
141
142
143
144
145
146
147
148
149
|
# File 'lib/widget.rb', line 141
def initialize(name="unnamed",x1=0,y1=0,x2=1,y2=1,theme=Themes::blank,z=0) super(x1,y1,x2,y2)
@id=$window.newWidget(self)
@theme=theme.newInstance(self)
@name=name
@sleeping=false
@zfocus=z
onInitialize
end
|
Instance Attribute Details
Returns the value of attribute buttonId.
139
140
141
|
# File 'lib/widget.rb', line 139
def buttonId
@buttonId
end
|
#defimage ⇒ Object
Returns the value of attribute defimage.
139
140
141
|
# File 'lib/widget.rb', line 139
def defimage
@defimage
end
|
#id ⇒ Object
Returns the value of attribute id.
139
140
141
|
# File 'lib/widget.rb', line 139
def id
@id
end
|
#name ⇒ Object
Returns the value of attribute name.
139
140
141
|
# File 'lib/widget.rb', line 139
def name
@name
end
|
#sleeping ⇒ Object
Returns the value of attribute sleeping.
139
140
141
|
# File 'lib/widget.rb', line 139
def sleeping
@sleeping
end
|
#theme ⇒ Object
Returns the value of attribute theme.
140
141
142
|
# File 'lib/widget.rb', line 140
def theme
@theme
end
|
#window ⇒ Object
Returns the value of attribute window.
139
140
141
|
# File 'lib/widget.rb', line 139
def window
@window
end
|
#zfocus ⇒ Object
Returns the value of attribute zfocus.
139
140
141
|
# File 'lib/widget.rb', line 139
def zfocus
@zfocus
end
|
Instance Method Details
#acceptStickyFocus? ⇒ Boolean
213
214
215
|
# File 'lib/widget.rb', line 213
def acceptStickyFocus?
return false
end
|
#acceptText? ⇒ Boolean
209
210
211
|
# File 'lib/widget.rb', line 209
def acceptText?
return false
end
|
#blur ⇒ Object
169
170
171
|
# File 'lib/widget.rb', line 169
def blur onMouseOut end
|
286
287
288
|
# File 'lib/widget.rb', line 286
def button
return Button.getButton(buttonId)
end
|
#clicked?(x, y) ⇒ Boolean
176
177
178
179
180
181
182
|
# File 'lib/widget.rb', line 176
def clicked?(x,y)
if $window.button_down?(Gosu::Button::MsLeft)
return xTile(x,y)
else
return false
end
end
|
#del ⇒ Object
290
291
292
293
294
295
296
297
298
|
# File 'lib/widget.rb', line 290
def del
onDelete
if $window.nil?
raise "Window assigned to nil" return
end
$window.deleteWidget(self)
super
end
|
#downevent(type) ⇒ Object
199
200
201
202
203
204
205
|
# File 'lib/widget.rb', line 199
def downevent(type)
if type==Widget::Event::MsLeft
onMouseDown
elsif type==Widget::Event::MsRight
onRightMouseDown
end
end
|
#draw ⇒ Object
264
265
|
# File 'lib/widget.rb', line 264
def draw
end
|
#event(type, dat = nil) ⇒ Object
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# File 'lib/widget.rb', line 184
def event(type, dat=nil) if type==Event::MsLeft
if acceptStickyFocus?
stickFocus
end
onClick
elsif type==Event::MsRight
onRightClick
elsif type==Event::KeyUp
onKeyUp(dat)
elsif type==Event::KeyDown
onKeyDown(dat)
end
end
|
#feedText(char) ⇒ Object
207
208
|
# File 'lib/widget.rb', line 207
def feedText(char)
end
|
#focus ⇒ Object
164
165
166
167
168
|
# File 'lib/widget.rb', line 164
def focus $window.setFocus(@id)
onMouseOver end
|
#hasFocus? ⇒ Boolean
150
151
152
153
154
155
156
|
# File 'lib/widget.rb', line 150
def hasFocus? if $window.hasFocus == self
return true
else
return false
end
end
|
#hasStickyFocus? ⇒ Boolean
157
158
159
160
161
162
163
|
# File 'lib/widget.rb', line 157
def hasStickyFocus? if $window.hasStickyFocus == self
return true
else
return false
end
end
|
#intDraw ⇒ Object
257
258
259
260
261
262
|
# File 'lib/widget.rb', line 257
def intDraw
if not @sleeping
@theme.draw
draw
end
end
|
#onClick ⇒ Object
221
222
|
# File 'lib/widget.rb', line 221
def onClick
end
|
#onDelete ⇒ Object
239
240
|
# File 'lib/widget.rb', line 239
def onDelete
end
|
#onDrag(x1, y1, x2, y2) ⇒ Object
225
226
|
# File 'lib/widget.rb', line 225
def onDrag(x1, y1, x2, y2)
end
|
#onInitialize ⇒ Object
237
238
|
# File 'lib/widget.rb', line 237
def onInitialize
end
|
#onKeyDown(key) ⇒ Object
243
244
|
# File 'lib/widget.rb', line 243
def onKeyDown(key)
end
|
#onKeyUp(key) ⇒ Object
241
242
|
# File 'lib/widget.rb', line 241
def onKeyUp(key)
end
|
#onMouseDown ⇒ Object
217
218
|
# File 'lib/widget.rb', line 217
def onMouseDown
end
|
#onMouseOut ⇒ Object
233
234
|
# File 'lib/widget.rb', line 233
def onMouseOut
end
|
#onMouseOver ⇒ Object
229
230
|
# File 'lib/widget.rb', line 229
def onMouseOver
end
|
#onRightClick ⇒ Object
223
224
|
# File 'lib/widget.rb', line 223
def onRightClick
end
|
#onRightDrag(x1, y1, x2, y2) ⇒ Object
227
228
|
# File 'lib/widget.rb', line 227
def onRightDrag(x1, y1, x2, y2)
end
|
#onRightMouseDown ⇒ Object
219
220
|
# File 'lib/widget.rb', line 219
def onRightMouseDown
end
|
#onStickyBlur ⇒ Object
235
236
|
# File 'lib/widget.rb', line 235
def onStickyBlur
end
|
#onStickyFocus ⇒ Object
231
232
|
# File 'lib/widget.rb', line 231
def onStickyFocus
end
|
#over?(x, y) ⇒ Boolean
173
174
175
|
# File 'lib/widget.rb', line 173
def over?(x,y)
return iTile(x,y)
end
|
#sleep ⇒ Object
267
268
269
270
271
272
273
274
275
|
# File 'lib/widget.rb', line 267
def sleep
if not @sleeping
if hasStickyFocus?
$window.setStickyFocus(nil)
end
@theme.setSleepState
@sleeping=true
end
end
|
#sleeping? ⇒ Boolean
276
277
278
|
# File 'lib/widget.rb', line 276
def sleeping?
return @sleeping
end
|
#stickFocus ⇒ Object
246
247
248
249
250
|
# File 'lib/widget.rb', line 246
def stickFocus
if acceptStickyFocus?
$window.setStickyFocus(self)
end
end
|
#unstickFocus ⇒ Object
251
252
253
254
255
|
# File 'lib/widget.rb', line 251
def unstickFocus
if hasStickyFocus?
$window.setStickyFocus(nil)
end
end
|
#wakeUp ⇒ Object
279
280
281
282
283
284
|
# File 'lib/widget.rb', line 279
def wakeUp
if @sleeping
@theme.setWakeState
@sleeping=false
end
end
|