Module: FN::SWF::Node::PhotoBlock

Includes:
Node::Base
Defined in:
lib/fn/swf/node/photo_block.rb

Constant Summary

Constants included from Node::Base

Node::Base::CURRENT_PAGE_HEIGHT, Node::Base::CURRENT_PAGE_WIDTH

Instance Method Summary collapse

Methods included from Node::Base

#classify, #has_no_children, #mixin, #value, #visit_children, #with_attributes_like

Instance Method Details

#visit(struct, debug = false) ⇒ Object

<block type=“photo” src=“logo” width=“162” boxX=“30” boxY=“40” boxWidth=“185” boxHeight=“99” align=“middlecenter”/>



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fn/swf/node/photo_block.rb', line 19

def visit(struct, debug = false)
  has_no_children
  
  src   = self[:src]
  bx    = self[:boxX].to_i
  by    = self[:boxY].to_i
  bw    = self[:boxWidth].to_i
  bh    = self[:boxHeight].to_i
  w     = self[:width].to_i
  ow    = self[:orig_width].to_i
  oh    = self[:orig_height].to_i
  align = self[:align]
  
  scale   = w.to_f / ow
  percent = "#{scale * 100}%"
  h       = ow * scale
  
  x = case align
  when /center/
    bx + (bw - w) / 2.0;
  when /right/
    bx + (bw - w)
  else
    bx
  end
  
  y = case align
  when /middle/
    by + (bh - h) / 2.0;
  when /bottom/
    by + (bh - h)
  else
    by
  end
    
  struct << ".put #{src} x=#{x} y=#{y} scalex=#{percent} scaley=#{percent}"
end