Class: CyberarmEngine::Window
  
  
  
  
  
    - Inherits:
- 
      Gosu::Window
      
        
          - Object
- Gosu::Window
- CyberarmEngine::Window
 show all
      - Includes:
- Common
    - Defined in:
- lib/cyberarm_engine/window.rb
 
  
    
      Constant Summary
      collapse
    
    
      
        - IMAGES =
          
        
- {}
- SAMPLES =
          
        
- {}
- SONGS =
          
        
- {}
Instance Attribute Summary collapse
  
  
    
      Class Method Summary
      collapse
    
    
  
    
      Instance Method Summary
      collapse
    
    
      
        - 
  
    
      #aspect_ratio  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #button_down(id)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #button_up(id)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #close  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #current_state  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #draw  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #draw_circle(cx, cy, r, z = 9999, color = Gosu::Color::GREEN, step = 10)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #drop(filename)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #dt  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #exit_on_opengl_error?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #gain_focus  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #gamepad_connected(index)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #gamepad_disconnected(index)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #has_focus?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)  ⇒ Window 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Window. 
 
- 
  
    
      #lose_focus  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #needs_cursor?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #needs_redraw?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #pop_state  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #push_state(klass, options = {})  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #shift_state  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
- 
  
    
      #update  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
  
Methods included from Common
  #alt_down?, #control_down?, #darken, #draw_rect, #fill, #find_element_by_tag, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #previous_state, #shift_down?, #window
  
  Constructor Details
  
    
  
  
    #initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)  ⇒ Window 
  
  
  
  
    
Returns a new instance of Window.
   
 
  
  
    | 
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 | # File 'lib/cyberarm_engine/window.rb', line 31
def initialize(width: 800, height: 600, fullscreen: false, update_interval: 1000.0 / 60, resizable: false, borderless: false)
  @show_cursor = false
  @has_focus = false
  super(width, height, fullscreen: fullscreen, update_interval: update_interval, resizable: resizable, borderless: borderless)
  Window.instance = self
  @last_frame_time = Gosu.milliseconds - 1
  @current_frame_time = Gosu.milliseconds
  self.caption = "CyberarmEngine #{CyberarmEngine::VERSION} #{Gosu.language}"
  @states = []
  @exit_on_opengl_error = false
  preload_default_shaders if respond_to?(:preload_default_shaders)
  setup if defined?(setup)
end | 
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #exit_on_opengl_error=(value)  ⇒ Object  
  
  
  
  
    
Sets the attribute exit_on_opengl_error
   
 
  
    | 
10
11
12 | # File 'lib/cyberarm_engine/window.rb', line 10
def exit_on_opengl_error=(value)
  @exit_on_opengl_error = value
end | 
 
    
      
      
      
  
  
    #last_frame_time  ⇒ Object  
  
  
  
  
    
Returns the value of attribute last_frame_time.
   
 
  
  
    | 
11
12
13 | # File 'lib/cyberarm_engine/window.rb', line 11
def last_frame_time
  @last_frame_time
end | 
 
    
      
      
      
  
  
    #show_cursor  ⇒ Object 
  
  
  
  
    
Returns the value of attribute show_cursor.
   
 
  
  
    | 
9
10
11 | # File 'lib/cyberarm_engine/window.rb', line 9
def show_cursor
  @show_cursor
end | 
 
    
      
      
      
  
  
    #states  ⇒ Object  
  
  
  
  
    
Returns the value of attribute states.
   
 
  
  
    | 
11
12
13 | # File 'lib/cyberarm_engine/window.rb', line 11
def states
  @states
end | 
 
    
   
  
    Class Method Details
    
      
  
  
    .dt  ⇒ Object 
  
  
  
  
    | 
17
18
19 | # File 'lib/cyberarm_engine/window.rb', line 17
def self.dt
  instance.last_frame_time / 1000.0
end | 
 
    
      
  
  
    .instance  ⇒ Object 
  
  
  
  
    | 
27
28
29 | # File 'lib/cyberarm_engine/window.rb', line 27
def self.instance
  @@instance
end | 
 
    
      
  
  
    .instance=(window)  ⇒ Object 
  
  
  
  
    | 
21
22
23
24
25 | # File 'lib/cyberarm_engine/window.rb', line 21
def self.instance=(window)
  raise ArgumentError, "Expected window to be a subclass of CyberarmEngine::Window, got: #{window.class}" unless window.is_a?(CyberarmEngine::Window)
  @@instance = window
end | 
 
    
      
  
  
    .now  ⇒ Object 
  
  
  
  
    | 
13
14
15 | # File 'lib/cyberarm_engine/window.rb', line 13
def self.now
  Gosu.milliseconds
end | 
 
    
   
  
    Instance Method Details
    
      
  
  
    #aspect_ratio  ⇒ Object 
  
  
  
  
    | 
112
113
114 | # File 'lib/cyberarm_engine/window.rb', line 112
def aspect_ratio
  width / height.to_f
end | 
 
    
      
  
  
    | 
94
95
96
97 | # File 'lib/cyberarm_engine/window.rb', line 94
def button_down(id)
  super
  current_state&.button_down(id)
end | 
 
    
      
  
  
    | 
99
100
101
102 | # File 'lib/cyberarm_engine/window.rb', line 99
def button_up(id)
  super
  current_state&.button_up(id)
end | 
 
    
      
  
  
    #close  ⇒ Object 
  
  
  
  
    | 
104
105
106 | # File 'lib/cyberarm_engine/window.rb', line 104
def close
  current_state ? current_state.close : super
end | 
 
    
      
  
  
    #current_state  ⇒ Object 
  
  
  
  
    | 
139
140
141 | # File 'lib/cyberarm_engine/window.rb', line 139
def current_state
  @states.last
end | 
 
    
      
  
  
    #draw  ⇒ Object 
  
  
  
  
    | 
49
50
51 | # File 'lib/cyberarm_engine/window.rb', line 49
def draw
  current_state&.draw
end | 
 
    
      
  
  
    #draw_circle(cx, cy, r, z = 9999, color = Gosu::Color::GREEN, step = 10)  ⇒ Object 
  
  
  
  
  
    | 
160
161
162
163
164
165
166 | # File 'lib/cyberarm_engine/window.rb', line 160
def draw_circle(cx, cy, r, z = 9999, color = Gosu::Color::GREEN, step = 10)
  0.step(360, step) do |a1|
    a2 = a1 + step
    draw_line(cx + Gosu.offset_x(a1, r), cy + Gosu.offset_y(a1, r), color, cx + Gosu.offset_x(a2, r),
              cy + Gosu.offset_y(a2, r), color, z)
  end
end | 
 
    
      
  
  
    #drop(filename)  ⇒ Object 
  
  
  
  
    | 
70
71
72 | # File 'lib/cyberarm_engine/window.rb', line 70
def drop(filename)
  current_state&.drop(filename)
end | 
 
    
      
  
  
    #dt  ⇒ Object 
  
  
  
  
    | 
108
109
110 | # File 'lib/cyberarm_engine/window.rb', line 108
def dt
  @last_frame_time / 1000.0
end | 
 
    
      
  
  
    #exit_on_opengl_error?  ⇒ Boolean 
  
  
  
  
    | 
116
117
118 | # File 'lib/cyberarm_engine/window.rb', line 116
def exit_on_opengl_error?
  @exit_on_opengl_error
end | 
 
    
      
  
  
    #gain_focus  ⇒ Object 
  
  
  
  
    | 
82
83
84
85
86 | # File 'lib/cyberarm_engine/window.rb', line 82
def gain_focus
  @has_focus = true
  current_state&.gain_focus
end | 
 
    
      
  
  
    #gamepad_connected(index)  ⇒ Object 
  
  
  
  
    | 
74
75
76 | # File 'lib/cyberarm_engine/window.rb', line 74
def gamepad_connected(index)
  current_state&.gamepad_connected(index)
end | 
 
    
      
  
  
    #gamepad_disconnected(index)  ⇒ Object 
  
  
  
  
    | 
78
79
80 | # File 'lib/cyberarm_engine/window.rb', line 78
def gamepad_disconnected(index)
  current_state&.gamepad_disconnected(index)
end | 
 
    
      
  
  
    #has_focus?  ⇒ Boolean 
  
  
  
  
    | 
155
156
157 | # File 'lib/cyberarm_engine/window.rb', line 155
def has_focus?
  @has_focus
end | 
 
    
      
  
  
    #lose_focus  ⇒ Object 
  
  
  
  
    | 
88
89
90
91
92 | # File 'lib/cyberarm_engine/window.rb', line 88
def lose_focus
  @has_focus = false
  current_state&.lose_focus
end | 
 
    
      
  
  
    #needs_cursor?  ⇒ Boolean 
  
  
  
  
    | 
62
63
64 | # File 'lib/cyberarm_engine/window.rb', line 62
def needs_cursor?
  @show_cursor
end | 
 
    
      
  
  
    #needs_redraw?  ⇒ Boolean 
  
  
  
  
    | 
66
67
68 | # File 'lib/cyberarm_engine/window.rb', line 66
def needs_redraw?
  current_state ? current_state.needs_redraw? : true
end | 
 
    
      
  
  
    #pop_state  ⇒ Object 
  
  
  
  
    | 
143
144
145
146
147 | # File 'lib/cyberarm_engine/window.rb', line 143
def pop_state
  @states.pop
  current_state.request_repaint if current_state&.is_a?(GuiState)
end | 
 
    
      
  
  
    #push_state(klass, options = {})  ⇒ Object 
  
  
  
  
    | 
120
121
122
123
124
125
126
127
128
129
130
131
132
133 | # File 'lib/cyberarm_engine/window.rb', line 120
def push_state(klass, options = {})
  options = { setup: true }.merge(options)
  if klass.instance_of?(klass.class) && defined?(klass.options)
    @states << klass
    klass.setup if options[:setup]
    klass.post_setup if options[:setup]
  else
    @states << klass.new(options) if child_of?(klass, GameState)
    @states << klass.new if child_of?(klass, Element::Container)
    current_state.setup if current_state.instance_of?(klass) && options[:setup]
    current_state.post_setup if current_state.instance_of?(klass) && options[:setup]
  end
end | 
 
    
      
  
  
    #shift_state  ⇒ Object 
  
  
  
  
    | 
149
150
151
152
153 | # File 'lib/cyberarm_engine/window.rb', line 149
def shift_state
  @states.shift
  current_state.request_repaint if current_state&.is_a?(GuiState)
end | 
 
    
      
  
  
    #update  ⇒ Object 
  
  
  
  
    | 
53
54
55
56
57
58
59
60 | # File 'lib/cyberarm_engine/window.rb', line 53
def update
  Stats.clear
  current_state&.update
  @last_frame_time = Gosu.milliseconds - @current_frame_time
  @current_frame_time = Gosu.milliseconds
end |