Module: PSD::Node::LayerComps

Included in:
Base
Defined in:
lib/psd/nodes/layer_comps.rb

Instance Method Summary collapse

Instance Method Details

#filter_by_comp(id) ⇒ Object

Given a layer comp ID or name, create a new tree with layer/group visibility altered based on the layer comp.


6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/psd/nodes/layer_comps.rb', line 6

def filter_by_comp(id)
  comp = find_comp(id)
  root = PSD::Node::Root.new(psd)
  
  # Force layers to be visible if they are enabled for the comp
  root.descendants.each do |c|
    set_visibility(comp, c) if Resource::Section::LayerComps.visibility_captured?(comp)
    set_position(comp, c) if Resource::Section::LayerComps.position_captured?(comp)

    PSD.logger.debug "#{c.path}: visible = #{c.visible?}, position = #{c.left}, #{c.top}"
  end

  return root
end

#position_in_comp(id) ⇒ Object


25
26
27
28
29
30
31
32
33
34
# File 'lib/psd/nodes/layer_comps.rb', line 25

def position_in_comp(id)
  offset = determine_position_offset(find_comp(id), self)
  
  {
    top: top + offset[:y],
    right: right + offset[:x],
    bottom: bottom + offset[:y],
    left: left + offset[:x]
  }
end

#visible_in_comp?(id) ⇒ Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/psd/nodes/layer_comps.rb', line 21

def visible_in_comp?(id)
  determine_visibility(find_comp(id), self)
end