Class: Metro::UI::FPS

Inherits:
Model
  • Object
show all
Defined in:
lib/metro/models/ui/fps.rb

Constant Summary

Constants included from Metro::Units

Metro::Units::Bounds

Instance Attribute Summary

Attributes inherited from Model

#scene, #window

Instance Method Summary collapse

Methods inherited from Model

#_load, #_save, #after_initialize, #bounds, #completed?, #create, hierarchy, inherited, #initialize, metro_name, #model, model_name, models, #name, #notification, #saveable_to_view, #to_hash

Methods included from HasEvents

included

Methods included from KeyValueCoding

#get, #set

Methods included from PropertyOwner

included, #properties

Constructor Details

This class inherits a constructor from Metro::Model

Instance Method Details

#drawObject



47
48
49
# File 'lib/metro/models/ui/fps.rb', line 47

def draw
  label.draw
end

#place_labelObject



35
36
37
38
39
40
41
# File 'lib/metro/models/ui/fps.rb', line 35

def place_label
  placement_hash = valid_placements[placement.to_sym]
  
  label.align = placement_hash[:align]
  label.vertical_align = placement_hash[:vertical_align]
  label.position = placement_hash[:position]
end

#showObject



31
32
33
# File 'lib/metro/models/ui/fps.rb', line 31

def show
  place_label
end

#updateObject



43
44
45
# File 'lib/metro/models/ui/fps.rb', line 43

def update
  label.text = "FPS: #{Gosu.fps}"
end

#valid_placementsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/metro/models/ui/fps.rb', line 13

def valid_placements
  @valid_placements ||= begin
    {
     top_left:     { position: Game.bounds.top_left, align: 'left', vertical_align: 'top' },
     top:          { position: Point.at(Game.center.x, Game.bounds.top), align: 'center', vertical_align: 'top' },
     top_right:    { position: Game.bounds.top_right, align: 'right', vertical_align: 'top' },
     right:        { position: Point.at(Game.bounds.right, Game.center.y), align: 'right', vertical_align: 'center' },
     bottom_right: { position: Game.bounds.bottom_right, align: 'right', vertical_align: 'bottom' },
     bottom:       { position: Point.at(Game.center.x, Game.bounds.bottom), align: 'right', vertical_align: 'bottom' },
     bottom_left:  { position: Game.bounds.bottom_right, align: 'left', vertical_align: 'bottom' },
     left:         { position: Point.at(Game.bounds.left, Game.center.y), align: 'left', vertical_align: 'center' }
    }
  end

  @valid_placements.default = :top
  @valid_placements
end