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
#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
#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 |
#camera ⇒ Object
Returns the value of attribute camera.
6 7 8 |
# File 'lib/window.rb', line 6 def camera @camera end |
#cursor ⇒ Object
Returns the value of attribute cursor.
6 7 8 |
# File 'lib/window.rb', line 6 def cursor @cursor end |
#images ⇒ Object (readonly)
Returns the value of attribute images.
7 8 9 |
# File 'lib/window.rb', line 7 def images @images end |
#mapimages ⇒ Object (readonly)
Returns the value of attribute mapimages.
7 8 9 |
# File 'lib/window.rb', line 7 def mapimages @mapimages end |
#state ⇒ Object
Returns the value of attribute state.
6 7 8 |
# File 'lib/window.rb', line 6 def state @state end |
Instance Method Details
#button_down(id) ⇒ Object
46 47 48 49 50 |
# File 'lib/window.rb', line 46 def (id) @state.(id) checkFocus (id) end |
#button_up(id) ⇒ Object
52 53 54 55 56 |
# File 'lib/window.rb', line 52 def (id) @state.(id) checkFocus (id) end |
#createWidgets ⇒ Object
140 141 142 143 144 |
# File 'lib/window.rb', line 140 def createWidgets self.text_input=nil @focused=nil @stickfocused=nil end |
#deleteAllImages ⇒ Object
95 96 97 |
# File 'lib/window.rb', line 95 def deleteAllImages @images.clear end |
#deleteAllMapImages ⇒ Object
119 120 121 |
# File 'lib/window.rb', line 119 def deleteAllMapImages @mapimages.clear end |
#deleteAllWidgets ⇒ Object
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 |
#deleteImage(no) ⇒ Object
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 |
#deleteMapImage(no) ⇒ Object
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 |
#deleteWidget(widget) ⇒ Object
127 128 129 130 |
# File 'lib/window.rb', line 127 def deleteWidget() id=.id @guiWidgets.delete_at(id) end |
#draw ⇒ Object
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 |
#framedrawn ⇒ Object
42 43 44 |
# File 'lib/window.rb', line 42 def framedrawn return @framedrawn end |
#hasFocus ⇒ Object
171 172 173 |
# File 'lib/window.rb', line 171 def hasFocus return @focused end |
#hasStickyFocus ⇒ Object
175 176 177 |
# File 'lib/window.rb', line 175 def hasStickyFocus return @stickfocused end |
#newImage(x, y, z, src, hardBorders = true, tracer = "None") ⇒ Object
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 |
#newMapImage(x, y, z, src, hardBorders = true, tracer = "None") ⇒ Object
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 |
#newTexture(x1, y1, x2, y2, z, src, hardBorders = true, tracer = "None") ⇒ Object
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 |
#newWidget(widget) ⇒ Object
123 124 125 |
# File 'lib/window.rb', line 123 def newWidget() return @guiWidgets << end |
#setBackground(src) ⇒ Object
99 100 101 |
# File 'lib/window.rb', line 99 def setBackground(src) @background_image = Gosu::Image.new(self,src,true) end |
#setFocus(object) ⇒ Object
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 |
#setImage(index, x, y, z, src, hardBorders = true, tracer = "None") ⇒ Object
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 |
#setMapBackground(src) ⇒ Object
103 104 105 |
# File 'lib/window.rb', line 103 def setMapBackground(src) @map_image = Gosu::Image.new(self,src,true) end |
#setStickyFocus(object) ⇒ Object
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 |
#setTextInput(field) ⇒ Object
146 147 148 |
# File 'lib/window.rb', line 146 def setTextInput(field) self.text_input=field end |
#setTexture(index, x1, y1, x2, y2, z, src, hardBorders = true, tracer = "None") ⇒ Object
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 |
#timer ⇒ Object
58 59 60 |
# File 'lib/window.rb', line 58 def timer return @timer end |
#update ⇒ Object
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 |
#widgets ⇒ Object
38 39 40 |
# File 'lib/window.rb', line 38 def return @widgets end |