Class: Metro::UI::GridDrawer

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

Overview

The grid drawer will draw a grid from the specified position out to the specified dimensions at the spacing interval provided. This is currently used when the edit mode is enabled.

Examples:

Drawing a white, translucent, 100 by 100 grid starting at (20,20).


class BuildScene < GameScene
  draw :grid, model: "metro::ui::grid_drawer", position: "20,20",
    color: "rgba(255,255,255,0.5)", spacing: 20, dimensions: "100,100"
end

Constant Summary

Constants included from Metro::Units

Metro::Units::Bounds

Instance Attribute Summary collapse

Attributes inherited from Model

#scene, #window

Instance Method Summary collapse

Methods inherited from Model

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

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 Attribute Details

#colorObject

The color of the grid lines



24
# File 'lib/metro/models/ui/grid_drawer.rb', line 24

property :color, default: "rgba(255,255,255,0.1)"

#dimensionsObject

The dimension of the grid



32
33
34
# File 'lib/metro/models/ui/grid_drawer.rb', line 32

property :dimensions do
  Dimensions.of Game.width, Game.height
end

#enabledObject

This controls whether the grid should be drawn. By default the grid will be drawn.



39
# File 'lib/metro/models/ui/grid_drawer.rb', line 39

property :enabled, type: :boolean, default: true

#positionObject

The position to start drawing the grid



20
# File 'lib/metro/models/ui/grid_drawer.rb', line 20

property :position, default: Point.at(0,0,100)

#spacingObject

The interval which to draw the lines



28
# File 'lib/metro/models/ui/grid_drawer.rb', line 28

property :spacing, type: :numeric, default: 10

Instance Method Details

#drawObject



45
46
47
48
49
# File 'lib/metro/models/ui/grid_drawer.rb', line 45

def draw
  return unless enabled
  draw_horizontal_lines
  draw_vertical_lines
end

#showObject



41
42
43
# File 'lib/metro/models/ui/grid_drawer.rb', line 41

def show
  self.saveable_to_view = false
end