Class: Metro::UI::ModelLabeler

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

Overview

The model labeler will draw a bounding box and label around all the scene’s drawers.

The model labeler is used in the edit transition scene to generate the bounding boxes and labeles around all the actors within the scene being edited.

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_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 use for the border surrounding each actor and the background behind the model’s name.



17
# File 'lib/metro/models/ui/model_labeler.rb', line 17

property :color, default: "rgba(255,0,0,0.5)"

#fontObject

The font of the model name label.



29
# File 'lib/metro/models/ui/model_labeler.rb', line 29

property :font, default: { name: 'Arial', size: 16 }

#label_colorObject

The color of the model name text.



25
# File 'lib/metro/models/ui/model_labeler.rb', line 25

property :label_color, default: "rgba(255,255,255,1.0)"

#should_draw_bounding_boxesObject

Sets whether to draw the bounding boxes around the actors.



21
# File 'lib/metro/models/ui/model_labeler.rb', line 21

property :should_draw_bounding_boxes, type: :boolean, default: true

#should_draw_labelsObject

Sets whether to draw the model name labels



33
# File 'lib/metro/models/ui/model_labeler.rb', line 33

property :should_draw_labels, type: :boolean, default: true

#should_hide_boundless_actorsObject

TODO:

when enabled the boundless actors should be presented in a cleaner way to allow for easier viewing of them.

For actors that have no bounds, like sound or custom models without a position, they are normally hidden but can be shown. Currently they appear all overlapped in the upper-left corner of the screen.



42
# File 'lib/metro/models/ui/model_labeler.rb', line 42

property :should_hide_boundless_actors, type: :boolean, default: true

Instance Method Details

#drawObject



72
73
74
# File 'lib/metro/models/ui/model_labeler.rb', line 72

def draw
  labels.values.each { |label| label.draw }
end

#labelsObject

Store the labels that are being drawn in the scene. This hash of labels acts as a cache around the items that are being labeled based on the name of the objects that are being labeled.



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

def labels
  @labels ||= {}
end

#showObject



51
52
53
# File 'lib/metro/models/ui/model_labeler.rb', line 51

def show
  self.saveable_to_view = false
end

#updateObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/metro/models/ui/model_labeler.rb', line 55

def update
  scene.drawers.each do |drawer|
    next if (drawer.bounds == Bounds.none and should_hide_boundless_actors)
    label = labels[drawer.name]

    unless label
      label = create "metro::ui::model_label", target: drawer
      labels[drawer.name] = label
    end

    label.should_draw_label = should_draw_labels
    label.should_draw_bounding_box = should_draw_bounding_boxes
    label.bounds = drawer.bounds
  end

end