Class: GGLib::GUIWindow

Inherits:
Gosu::Window
  • Object
show all
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

Instance Method Summary collapse

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.expand_path(File.dirname(__FILE__))+"/null.png", true)
  @cursor = Cursor.new(File.expand_path(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_imageObject

Returns the value of attribute background_image.



6
7
8
# File 'lib/window.rb', line 6

def background_image
  @background_image
end

#cameraObject

Returns the value of attribute camera.



6
7
8
# File 'lib/window.rb', line 6

def camera
  @camera
end

#cursorObject

Returns the value of attribute cursor.



6
7
8
# File 'lib/window.rb', line 6

def cursor
  @cursor
end

#imagesObject (readonly)

Returns the value of attribute images.



7
8
9
# File 'lib/window.rb', line 7

def images
  @images
end

#mapimagesObject (readonly)

Returns the value of attribute mapimages.



7
8
9
# File 'lib/window.rb', line 7

def mapimages
  @mapimages
end

#stateObject

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 button_down(id)
  @state.button_down(id)
  checkFocus
  widgetDownProc(id)
end

#button_up(id) ⇒ Object



52
53
54
55
56
# File 'lib/window.rb', line 52

def button_up(id)
  @state.button_up(id)
  checkFocus                       
  widgetUpProc(id)
end

#createWidgetsObject



140
141
142
143
144
# File 'lib/window.rb', line 140

def createWidgets
  self.text_input=nil
  @focused=nil
  @stickfocused=nil
end

#deleteAllImagesObject



95
96
97
# File 'lib/window.rb', line 95

def deleteAllImages
  @images.clear
end

#deleteAllMapImagesObject



119
120
121
# File 'lib/window.rb', line 119

def deleteAllMapImages
  @mapimages.clear
end

#deleteAllWidgetsObject



132
133
134
135
136
137
138
# File 'lib/window.rb', line 132

def deleteAllWidgets
  @guiWidgets.each {|widget| widget.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(widget)
  id=widget.id
  @guiWidgets.delete_at(id)
end

#drawObject



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 {|widget| widget.intDraw}
  @background_image.draw(0, 0, ZOrder::Background)
  @state.draw
  @framedrawn=true
end

#framedrawnObject



42
43
44
# File 'lib/window.rb', line 42

def framedrawn
  return @framedrawn
end

#hasFocusObject



171
172
173
# File 'lib/window.rb', line 171

def hasFocus
  return @focused
end

#hasStickyFocusObject



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(widget)
  return @guiWidgets << widget
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

#timerObject



58
59
60
# File 'lib/window.rb', line 58

def timer
  return @timer
end

#updateObject



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

#widgetsObject



38
39
40
# File 'lib/window.rb', line 38

def widgets
  return @widgets
end