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
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
-
#downevent(type) ⇒ 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 = Themes::blank, acceptsticky = true, z = 0) ⇒ Widget
constructor
-
#intDraw ⇒ Object
-
#onClick ⇒ Object
-
#onDelete ⇒ Object
-
#onDrag(x1, y1, x2, y2) ⇒ Object
-
#onInitialize ⇒ Object
-
#onKeyPress(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, setAllInstances, #setCoordinates, #setTile, #width, #xTile
Constructor Details
#initialize(name = "unnamed", x1 = 0, y1 = 0, x2 = 1, y2 = 1, theme = Themes::blank, 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=Themes::blank,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
|
158
159
160
|
# File 'lib/widget.rb', line 158
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
162
163
164
165
166
167
168
169
170
|
# File 'lib/widget.rb', line 162
def del
onDelete
if $window.nil?
raise "Window assigned to nil" return
end
$window.deleteWidget(self)
super
end
|
#downevent(type) ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/widget.rb', line 85
def downevent(type)
if type==WidgetEvent::MsLeft
onMouseDown
elsif type==WidgetEvent::MsRight
onRightMouseDown
end
end
|
#draw ⇒ Object
136
137
|
# File 'lib/widget.rb', line 136
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
93
94
|
# File 'lib/widget.rb', line 93
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
129
130
131
132
133
134
|
# File 'lib/widget.rb', line 129
def intDraw
if not @sleeping
@theme.draw
draw
end
end
|
#onClick ⇒ Object
99
100
|
# File 'lib/widget.rb', line 99
def onClick
end
|
#onDelete ⇒ Object
117
118
|
# File 'lib/widget.rb', line 117
def onDelete
end
|
#onDrag(x1, y1, x2, y2) ⇒ Object
103
104
|
# File 'lib/widget.rb', line 103
def onDrag(x1, y1, x2, y2)
end
|
#onInitialize ⇒ Object
115
116
|
# File 'lib/widget.rb', line 115
def onInitialize
end
|
#onKeyPress(key) ⇒ Object
119
120
|
# File 'lib/widget.rb', line 119
def onKeyPress(key)
end
|
#onMouseDown ⇒ Object
95
96
|
# File 'lib/widget.rb', line 95
def onMouseDown
end
|
#onMouseOut ⇒ Object
111
112
|
# File 'lib/widget.rb', line 111
def onMouseOut
end
|
#onMouseOver ⇒ Object
107
108
|
# File 'lib/widget.rb', line 107
def onMouseOver
end
|
#onRightClick ⇒ Object
101
102
|
# File 'lib/widget.rb', line 101
def onRightClick
end
|
#onRightDrag(x1, y1, x2, y2) ⇒ Object
105
106
|
# File 'lib/widget.rb', line 105
def onRightDrag(x1, y1, x2, y2)
end
|
#onRightMouseDown ⇒ Object
97
98
|
# File 'lib/widget.rb', line 97
def onRightMouseDown
end
|
#onStickyBlur ⇒ Object
113
114
|
# File 'lib/widget.rb', line 113
def onStickyBlur
end
|
#onStickyFocus ⇒ Object
109
110
|
# File 'lib/widget.rb', line 109
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
139
140
141
142
143
144
145
146
147
|
# File 'lib/widget.rb', line 139
def sleep
if not @sleeping
if hasStickyFocus?
$window.setStickyFocus(nil)
end
@theme.setSleepState
@sleeping=true
end
end
|
#sleeping? ⇒ Boolean
148
149
150
|
# File 'lib/widget.rb', line 148
def sleeping?
return @sleeping
end
|
#stickFocus ⇒ Object
122
123
124
|
# File 'lib/widget.rb', line 122
def stickFocus
$window.setStickyFocus(self)
end
|
#unstickFocus ⇒ Object
125
126
127
|
# File 'lib/widget.rb', line 125
def unstickFocus
$window.setStickyFocus(nil)
end
|
#wakeUp ⇒ Object
151
152
153
154
155
156
|
# File 'lib/widget.rb', line 151
def wakeUp
if @sleeping
@theme.setWakeState
@sleeping=false
end
end
|