Class: PSD::Node::Base
Constant Summary
collapse
- PROPERTIES =
Default properties that all nodes contain
[:name, :left, :right, :top, :bottom, :height, :width]
Instance Attribute Summary collapse
Instance Method Summary
collapse
#renderer, #save_as_png, #to_png
Methods included from Search
#children_at_path, #filter_by_comp
Constructor Details
#initialize(layer, parent = nil) ⇒ Base
Returns a new instance of Base.
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/psd/node.rb', line 26
def initialize(layer, parent = nil)
@layer = layer
@layer.node = self
@parent = parent
@children = []
@force_visible = nil
@top = @layer.top.to_i
@bottom = @layer.bottom.to_i
@left = @layer.left.to_i
@right = @layer.right.to_i
@top_offset = 0
@left_offset = 0
end
|
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
19
20
21
|
# File 'lib/psd/node.rb', line 19
def children
@children
end
|
#force_visible ⇒ Object
Returns the value of attribute force_visible.
19
20
21
|
# File 'lib/psd/node.rb', line 19
def force_visible
@force_visible
end
|
#layer ⇒ Object
Returns the value of attribute layer.
19
20
21
|
# File 'lib/psd/node.rb', line 19
def layer
@layer
end
|
#left_offset ⇒ Object
Returns the value of attribute left_offset.
19
20
21
|
# File 'lib/psd/node.rb', line 19
def left_offset
@left_offset
end
|
#name ⇒ Object
Returns the value of attribute name.
18
19
20
|
# File 'lib/psd/node.rb', line 18
def name
@name
end
|
#parent ⇒ Object
Returns the value of attribute parent.
18
19
20
|
# File 'lib/psd/node.rb', line 18
def parent
@parent
end
|
#top_offset ⇒ Object
Returns the value of attribute top_offset.
19
20
21
|
# File 'lib/psd/node.rb', line 19
def top_offset
@top_offset
end
|
Instance Method Details
#bottom ⇒ Object
47
48
49
|
# File 'lib/psd/node.rb', line 47
def bottom
@bottom + @top_offset
end
|
#clipping_mask ⇒ Object
Also known as:
clipped_by
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/psd/node.rb', line 76
def clipping_mask
return nil unless @layer.clipped?
@clipping_mask ||= (
mask_node = next_sibling
while mask_node.clipped?
mask_node = mask_node.next_sibling
end
mask_node
)
end
|
#debug_name ⇒ Object
98
99
100
|
# File 'lib/psd/node.rb', line 98
def debug_name
root? ? ":root:" : name
end
|
#group?(include_root = true) ⇒ Boolean
94
95
96
|
# File 'lib/psd/node.rb', line 94
def group?(include_root = true)
is_a?(PSD::Node::Group) || (include_root && is_a?(PSD::Node::Root))
end
|
#height ⇒ Object
63
64
65
|
# File 'lib/psd/node.rb', line 63
def height
bottom - top
end
|
#hidden? ⇒ Boolean
67
68
69
|
# File 'lib/psd/node.rb', line 67
def hidden?
!visible?
end
|
#layer? ⇒ Boolean
90
91
92
|
# File 'lib/psd/node.rb', line 90
def layer?
is_a?(PSD::Node::Layer)
end
|
#left ⇒ Object
51
52
53
|
# File 'lib/psd/node.rb', line 51
def left
@left + @left_offset
end
|
#right ⇒ Object
55
56
57
|
# File 'lib/psd/node.rb', line 55
def right
@right + @left_offset
end
|
#to_hash ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/psd/node.rb', line 102
def to_hash
hash = {
type: nil,
visible: visible?,
opacity: @layer.opacity / 255.0,
blending_mode: @layer.blending_mode
}
PROPERTIES.each do |p|
hash[p] = self.send(p)
end
hash
end
|
#top ⇒ Object
43
44
45
|
# File 'lib/psd/node.rb', line 43
def top
@top + @top_offset
end
|
#visible? ⇒ Boolean
71
72
73
74
|
# File 'lib/psd/node.rb', line 71
def visible?
return false if @layer.clipped? && !clipping_mask.visible?
@force_visible.nil? ? @layer.visible? : @force_visible
end
|
#width ⇒ Object
59
60
61
|
# File 'lib/psd/node.rb', line 59
def width
right - left
end
|