Class: GGLib::GUIWindow
- Inherits:
-
Gosu::Window
- Object
- Gosu::Window
- GGLib::GUIWindow
- Defined in:
- lib/window.rb
Overview
The GUIWindow class is the central hub of the program. It is utimately responsible for all input and output (exept for logging output). The main game loops can be found in this class.
Constant Summary collapse
- BlankState =
StateObject.new
Instance Attribute Summary collapse
-
#background_image ⇒ Object
Returns the value of attribute background_image.
-
#camera ⇒ Object
Returns the value of attribute camera.
-
#cursor ⇒ Object
Returns the value of attribute cursor.
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#mapimages ⇒ Object
readonly
Returns the value of attribute mapimages.
-
#state ⇒ Object
Returns the value of attribute state.
Instance Method Summary collapse
- #button_down(id) ⇒ Object
- #button_up(id) ⇒ Object
- #createWidgets ⇒ Object
- #deleteAllImages ⇒ Object
- #deleteAllMapImages ⇒ Object
- #deleteAllWidgets ⇒ Object
- #deleteImage(no) ⇒ Object
- #deleteMapImage(no) ⇒ Object
- #deleteWidget(widget) ⇒ Object
- #draw ⇒ Object
- #framedrawn ⇒ Object
- #hasFocus ⇒ Object
- #hasStickyFocus ⇒ Object
-
#initialize(w = 640, h = 480, fullscreen = true, u = 20, stateObj = BlankState) ⇒ GUIWindow
constructor
A new instance of GUIWindow.
- #newImage(x, y, z, src, hardBorders = true, tracer = "None") ⇒ Object
- #newMapImage(x, y, z, src, hardBorders = true, tracer = "None") ⇒ Object
- #newTexture(x1, y1, x2, y2, z, src, hardBorders = true, tracer = "None") ⇒ Object
- #newWidget(widget) ⇒ Object
- #setBackground(src) ⇒ Object
- #setFocus(object) ⇒ Object
- #setImage(index, x, y, z, src, hardBorders = true, tracer = "None") ⇒ Object
- #setMapBackground(src) ⇒ Object
- #setStickyFocus(object) ⇒ Object
- #setTextInput(field) ⇒ Object
- #setTexture(index, x1, y1, x2, y2, z, src, hardBorders = true, tracer = "None") ⇒ Object
- #timer ⇒ Object
- #update ⇒ Object
- #widgets ⇒ Object
Constructor Details
permalink #initialize(w = 640, h = 480, fullscreen = true, u = 20, stateObj = BlankState) ⇒ GUIWindow
Returns a new instance of GUIWindow.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/window.rb', line 11 def initialize(w=640, h=480, fullscreen=true, u=20, stateObj=BlankState) super(w, h, fullscreen, u) $window=self #pre initialize global var to allow win initialization @background_image = Gosu::Image.new(self, File.(File.dirname(__FILE__))+"/null.png", true) @cursor = Cursor.new(File.(File.dirname(__FILE__))+"/media/cursor.bmp", false) @framedrawn=false @timer=0 @camera=Camera.new @images = CArray.new @mapimages = CArray.new @guiWidgets = CArray.new @state=stateObj @focused=nil @stickfocused=nil @leftdrag = MouseDragEvent.new @rightdrag = MouseDragEvent.new @state.start $window=self $theme_init_hook.call end |
Instance Attribute Details
permalink #background_image ⇒ Object
Returns the value of attribute background_image.
6 7 8 |
# File 'lib/window.rb', line 6 def background_image @background_image end |
permalink #camera ⇒ Object
Returns the value of attribute camera.
6 7 8 |
# File 'lib/window.rb', line 6 def camera @camera end |
permalink #cursor ⇒ Object
Returns the value of attribute cursor.
6 7 8 |
# File 'lib/window.rb', line 6 def cursor @cursor end |
permalink #images ⇒ Object (readonly)
Returns the value of attribute images.
7 8 9 |
# File 'lib/window.rb', line 7 def images @images end |
permalink #mapimages ⇒ Object (readonly)
Returns the value of attribute mapimages.
7 8 9 |
# File 'lib/window.rb', line 7 def mapimages @mapimages end |
permalink #state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'lib/window.rb', line 6 def state @state end |
Instance Method Details
permalink #button_down(id) ⇒ Object
[View source]
46 47 48 49 50 |
# File 'lib/window.rb', line 46 def (id) @state.(id) checkFocus (id) end |
permalink #button_up(id) ⇒ Object
[View source]
52 53 54 55 56 |
# File 'lib/window.rb', line 52 def (id) @state.(id) checkFocus (id) end |
permalink #createWidgets ⇒ Object
[View source]
140 141 142 143 144 |
# File 'lib/window.rb', line 140 def createWidgets self.text_input=nil @focused=nil @stickfocused=nil end |
permalink #deleteAllImages ⇒ Object
[View source]
95 96 97 |
# File 'lib/window.rb', line 95 def deleteAllImages @images.clear end |
permalink #deleteAllMapImages ⇒ Object
[View source]
119 120 121 |
# File 'lib/window.rb', line 119 def deleteAllMapImages @mapimages.clear end |
permalink #deleteAllWidgets ⇒ Object
[View source]
132 133 134 135 136 137 138 |
# File 'lib/window.rb', line 132 def deleteAllWidgets @guiWidgets.each {|| .del} @guiWidgets.clear @focused=nil @stickfocused=nil self.text_input=nil end |
permalink #deleteImage(no) ⇒ Object
[View source]
88 89 90 91 92 93 |
# File 'lib/window.rb', line 88 def deleteImage(no) if @images[no]!=nil @images[no].del end @images.delete_at(no) end |
permalink #deleteMapImage(no) ⇒ Object
[View source]
112 113 114 115 116 117 |
# File 'lib/window.rb', line 112 def deleteMapImage(no) if @mapimages[no]!=nil @mapimages[no].del end @mapimages.delete_at(no) end |
permalink #deleteWidget(widget) ⇒ Object
[View source]
127 128 129 130 |
# File 'lib/window.rb', line 127 def deleteWidget() id=.id @guiWidgets.delete_at(id) end |
permalink #draw ⇒ Object
[View source]
202 203 204 205 206 207 208 209 |
# File 'lib/window.rb', line 202 def draw @cursor.draw @images.each {|img| img.draw} @guiWidgets.each {|| .intDraw} @background_image.draw(0, 0, ZOrder::Background) @state.draw @framedrawn=true end |
permalink #framedrawn ⇒ Object
[View source]
42 43 44 |
# File 'lib/window.rb', line 42 def framedrawn return @framedrawn end |
permalink #hasFocus ⇒ Object
[View source]
171 172 173 |
# File 'lib/window.rb', line 171 def hasFocus return @focused end |
permalink #hasStickyFocus ⇒ Object
[View source]
175 176 177 |
# File 'lib/window.rb', line 175 def hasStickyFocus return @stickfocused end |
permalink #newImage(x, y, z, src, hardBorders = true, tracer = "None") ⇒ Object
[View source]
66 67 68 69 |
# File 'lib/window.rb', line 66 def newImage(x,y,z,src,hardBorders=true,tracer="None") img=Image.new(x,y,z,src,hardBorders,tracer,@images.size) return @images << img end |
permalink #newMapImage(x, y, z, src, hardBorders = true, tracer = "None") ⇒ Object
[View source]
107 108 109 110 |
# File 'lib/window.rb', line 107 def newMapImage(x,y,z,src,hardBorders=true,tracer="None") img=Image.new(x,y,z,src,hardBorders,tracer,@mapimages.size) return @mapimages << img end |
permalink #newTexture(x1, y1, x2, y2, z, src, hardBorders = true, tracer = "None") ⇒ Object
[View source]
71 72 73 74 |
# File 'lib/window.rb', line 71 def newTexture(x1,y1,x2,y2,z,src,hardBorders=true,tracer="None") img=Texture.new(x1,y1,x2,y2,z,src,hardBorders,tracer,@images.size) return @images << img end |
permalink #newWidget(widget) ⇒ Object
[View source]
123 124 125 |
# File 'lib/window.rb', line 123 def newWidget() return @guiWidgets << end |
permalink #setBackground(src) ⇒ Object
[View source]
99 100 101 |
# File 'lib/window.rb', line 99 def setBackground(src) @background_image = Gosu::Image.new(self,src,true) end |
permalink #setFocus(object) ⇒ Object
[View source]
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/window.rb', line 150 def setFocus(object) if @focused!=nil and not @focused.sleeping? #dont blur the object if it is the window or if it is sleeping @focused.blur end if object==nil @focused=nil else @focused=@guiWidgets[object] end end |
permalink #setImage(index, x, y, z, src, hardBorders = true, tracer = "None") ⇒ Object
[View source]
76 77 78 79 80 |
# File 'lib/window.rb', line 76 def setImage(index,x,y,z,src,hardBorders=true,tracer="None") img=Image.new(x,y,z,src,@images.size,hardBorders,tracer) @images[index]=img return index end |
permalink #setMapBackground(src) ⇒ Object
[View source]
103 104 105 |
# File 'lib/window.rb', line 103 def setMapBackground(src) @map_image = Gosu::Image.new(self,src,true) end |
permalink #setStickyFocus(object) ⇒ Object
[View source]
161 162 163 164 165 166 167 168 169 |
# File 'lib/window.rb', line 161 def setStickyFocus(object) if @stickfocused!=nil @stickfocused.onStickyBlur end @stickfocused=object if @stickfocused!=nil @stickfocused.onStickyFocus end end |
permalink #setTextInput(field) ⇒ Object
[View source]
146 147 148 |
# File 'lib/window.rb', line 146 def setTextInput(field) self.text_input=field end |
permalink #setTexture(index, x1, y1, x2, y2, z, src, hardBorders = true, tracer = "None") ⇒ Object
[View source]
82 83 84 85 86 |
# File 'lib/window.rb', line 82 def setTexture(index, x1,y1,x2,y2,z,src,hardBorders=true,tracer="None") img=Texture.new(x1,y1,x2,y2,z,src,hardBorders,tracer,@images.size) @images[index]=img return index end |
permalink #timer ⇒ Object
[View source]
58 59 60 |
# File 'lib/window.rb', line 58 def timer return @timer end |
permalink #update ⇒ Object
[View source]
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/window.rb', line 179 def update checkFocus if @leftdrag.starting if(Gosu::distance(@leftdrag.start_x, @leftdrag.start_y, mouse_x, mouse_y) > 5) @leftdrag.confirmStart end elsif @rightdrag.starting if(Gosu::distance(@rightdrag.start_x, @rightdrag.start_y, mouse_x, mouse_y) > 5) @rightdrag.confirmStart end end if @timer>100 @timer=0 else @timer+=1 end @state.update @framedrawn = false end |
permalink #widgets ⇒ Object
[View source]
38 39 40 |
# File 'lib/window.rb', line 38 def return @widgets end |