Class: PSD::Node::Layer
- Includes:
- LockToOrigin
- Defined in:
- lib/psd/node_layer.rb
Constant Summary
Constants inherited from PSD::Node
Instance Attribute Summary collapse
-
#layer ⇒ Object
readonly
Returns the value of attribute layer.
Attributes inherited from PSD::Node
#children, #force_visible, #parent
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#hide! ⇒ Object
Tries to hide the layer by moving it way off canvas.
-
#initialize(layer) ⇒ Layer
constructor
Stores a reference to the PSD::Layer.
-
#method_missing(method, *args, &block) ⇒ Object
If the method is missing, we blindly send it to the layer.
-
#scale_path_components(xr, yr) ⇒ Object
Attempt to scale the path components of the layer.
-
#show! ⇒ Object
Tries to re-show the canvas by moving it back to it’s original position.
-
#to_hash ⇒ Object
Exports this layer to a Hash.
-
#translate(x = 0, y = 0) ⇒ Object
Attempt to translate the layer.
Methods included from LockToOrigin
Methods inherited from PSD::Node
#document_dimensions, #group?, #hidden?, #layer?, #psd, #visible?
Methods included from BuildPreview
#build_png, #orig_to_png, #to_png
Methods included from Image::Export::PNG
#mask_to_png, #save_as_png, #to_png, #to_png_with_mask
Methods included from Search
#children_at_path, #filter_by_comp
Methods included from Ancestry
#ancestors, #childless?, #depth, #descendants, #has_children?, #has_siblings?, #next_sibling, #only_child?, #path, #prev_sibling, #root, #root?, #siblings, #subtree
Constructor Details
#initialize(layer) ⇒ Layer
Stores a reference to the PSD::Layer
10 11 12 13 14 15 |
# File 'lib/psd/node_layer.rb', line 10 def initialize(layer) super([]) @layer = layer layer.node = self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
If the method is missing, we blindly send it to the layer. The layer handles the case in which the method doesn’t exist.
77 78 79 |
# File 'lib/psd/node_layer.rb', line 77 def method_missing(method, *args, &block) @layer.send(method, *args, &block) end |
Instance Attribute Details
#layer ⇒ Object (readonly)
Returns the value of attribute layer.
7 8 9 |
# File 'lib/psd/node_layer.rb', line 7 def layer @layer end |
Instance Method Details
#empty? ⇒ Boolean
55 56 57 |
# File 'lib/psd/node_layer.rb', line 55 def empty? width == 0 || height == 0 end |
#hide! ⇒ Object
Tries to hide the layer by moving it way off canvas.
39 40 41 42 43 44 45 |
# File 'lib/psd/node_layer.rb', line 39 def hide! # TODO actually mess with the blend modes instead of # just putting things way off canvas return if @hidden_by_kelly translate(100000, 10000) @hidden_by_kelly = true end |
#scale_path_components(xr, yr) ⇒ Object
Attempt to scale the path components of the layer.
34 35 36 |
# File 'lib/psd/node_layer.rb', line 34 def scale_path_components(xr, yr) @layer.scale_path_components(xr, yr) end |
#show! ⇒ Object
Tries to re-show the canvas by moving it back to it’s original position.
48 49 50 51 52 53 |
# File 'lib/psd/node_layer.rb', line 48 def show! if @hidden_by_kelly translate(-100000, -10000) @hidden_by_kelly = false end end |
#to_hash ⇒ Object
Exports this layer to a Hash.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/psd/node_layer.rb', line 60 def to_hash super.merge({ type: :layer, text: @layer.text, ref_x: @layer.reference_point.x, ref_y: @layer.reference_point.y, mask: @layer.mask.to_hash, image: { width: @layer.image.width, height: @layer.image.height, channels: @layer.channels_info } }) end |
#translate(x = 0, y = 0) ⇒ Object
Attempt to translate the layer.
29 30 31 |
# File 'lib/psd/node_layer.rb', line 29 def translate(x=0, y=0) @layer.translate x, y end |