fixed button syntax.
[swftools.git] / doc / swfc.xml
index b751bd8..00b6916 100644 (file)
@@ -89,7 +89,7 @@ Boxes:
 
  <note>
   Though swfc is a command-line utility, there also exists a nice graphical
-  frontend for it, called <uri link="http://www.ucolick.de/~de/Snarf/quiss">Swifty</uri>.
+  frontend for it, called Swifty.
  </note>
 
  </section>
@@ -118,13 +118,143 @@ Boxes:
 
  </section>
  
- <section><title>Text generation</title>
-  
+ <section><title>Color transforms</title>
+
+  <code lang="swfc">
+.flash name="cxform.swf" version=5
+    
+    .jpeg s1 "photo.jpeg" quality=80%
+
+    .put s1 x=50 y=50 scalex=110 scaley=110
+    .frame 100
+    .change s1 x=0 y=0 scalex=210 scaley=210 red=-1+255 green=-1+255 blue=-1+255 #invert
+    .frame 200
+    .change s1 x=100 y=50 scalex=110 scaley=110 red=0 green=+0 blue=+0 #remove red
+    .frame 300
+    .change s1 x=0 y=0 scalex=210 scaley=210 red=+0 green=2 blue=-1+255 #amplify green, invert blue
+    .frame 400
+    .change s1 x=50 y=100 scalex=110 scaley=110 red=2-128 green=-2+255 blue=+0.7+40 #alien glow
+    .frame 500
+    .change s1 x=0 y=0 scalex=210 scaley=210 red=8-1024 green=8-1024 blue=8-1024 #palette reduce
+    .frame 600
+    .change s1 x=0 y=0 scalex=210 scaley=210 red=+0 green=+0 blue=+0 #back to normal
+    .frame 700
+    .change s1 x=105 y=105 scalex=0 scaley=0 luminance=0 #fadeout
+.end
+  </code>
+ </section>
+
+</chapter>
+
+<chapter><title>Fonts</title>
+
+<section>
+
+swfc has font support. That means you can also insert texts into
+your animations.
+The easiest way to load a font is to do something like
+<c>
+    .font Arial filename="Arial.ttf"
+</c>
+.
+You now have a font named <c>Arial</c> to play with.
+For example, for the obligatory hello world program:
+
+  <code lang="swfc">
+.flash name="helloworld.swf"
+    
+    .font Arial filename="Arial.ttf"
+    .text helloworld font=Arial text="Hello World!"
+    .put helloworld
+.end
+  </code>
+
+Besides TrueType fonts, swfc also supports native SWF fonts.
+If you have a SWF with a font you would like to use, do a 
+<shell>
+    swfextract file.swf
+</shell>
+Then write down the font ID of the font, and do a
+<shell>
+    swfextract -f &lt;fontid&gt; file.swf -o myfont.swf
+</shell>
+.
+<p>
+This will give you a file named myfont.swf which you can
+also use in the <c>filename</c> parameter of <c>.font</c>.
+</p>
+
+<p>
+Furthermore, you can convert TTF and Type1
+fonts into SWF using <c>font2swf</c>:
+<shell>
+    font2swf Arial.ttf -o Arial.swf
+</shell>
+The nice advantage of this is that you can play
+Arial.swf in the flash player and see what the
+font looks like.
+(Also, loading a font in SWF format is slighly
+faster than from a TTF file, as with TTFs spline
+conversion has to take place).
+</p>
+
+</section>
+<section>
+<p>
+So much for the basics. Now let's go to the more advanced
+functionality.
+</p>
+
+<p>
+Apart from being able to define text in your swfc files,
+you can also define text <c>outlines</c>. 
+Those are not real characters but rather abstract vector 
+objects which you can use in other commands.
+</p>
+
+<code lang="swfc">
+.flash name="fontoutline.swf"
+    .font Arial "Arial.swf"
+    .textshape helloworld font=Arial text="Hello World"
+    .filled filled_helloworld outline=helloworld fill=blue line=5 color=green
+    .put filled_helloworld
+.end
+</code>
+
+Here, <c>.textshape helloworld</c> defines an outline named "helloworld",
+which is then used to construct a filled outline named filled_helloworld.
+
+To make this a little more interesting, let's fill with a gradient instead
+of a plain color:
+
+<code lang="swfc">
+.flash name="fontgradient.swf"
+    .font Arial "Arial.swf"
+    .textshape helloworld font=Arial text="SHADE"
+    
+    .gradient whitefade:
+       0% black
+       50% #505050
+       100% yellow
+    .end
+
+    .filled filled_helloworld outline=helloworld fill=whitefade line=1 color=#2c2c2c
+    .put filled_helloworld scale=200%
+.end
+</code>
+
+But let's get back to normal <c>.text</c> characters.
+The following demonstrates that you can treat objects defined
+with <c>.text</c> like normal shapes, i.e., scale them, move them, and use
+them for clipping:
+
   <code lang="swfc">
 .flash name="text5.swf"
 .font courier "Courier.swf"
 .font helvetica "Helvetica.swf"
-.text hithere text="HELLO" font=courier size=50% color=blue
+.text hithere text="HELLO" font=courier size=50%
 .swf scene Scenery50.swf
 
 .frame 0
@@ -136,7 +266,12 @@ Boxes:
 
 .end
   </code>
-  
+
+Also, <c>.text</c> takes a color attribute (that's actually
+the poor man's version of the more advanced filling options
+that <c>.textshape</c> in conjunction with <c>.filled</c> offers),
+which is used here together with the alpha parameter of <c>.change</c>:
+
   <code lang="swfc">
 .flash name="text6.swf"
 .font courier "Courier.swf"
@@ -155,33 +290,124 @@ Boxes:
  
  </section>
 
- <section><title>Color transforms</title>
+</chapter>
 
-  <code lang="swfc">
-.flash name="cxform.swf" version=5
-    
-    .jpeg s1 "photo.jpeg" quality=80%
+<chapter><title>ActionScript</title>
 
-    .put s1 x=50 y=50 scalex=110 scaley=110
-    .frame 100
-    .change s1 x=0 y=0 scalex=210 scaley=210 red=-1+255 green=-1+255 blue=-1+255 #invert
-    .frame 200
-    .change s1 x=100 y=50 scalex=110 scaley=110 red=0 green=+0 blue=+0 #remove red
-    .frame 300
-    .change s1 x=0 y=0 scalex=210 scaley=210 red=+0 green=2 blue=-1+255 #amplify green, invert blue
-    .frame 400
-    .change s1 x=50 y=100 scalex=110 scaley=110 red=2-128 green=-2+255 blue=+0.7+40 #alien glow
-    .frame 500
-    .change s1 x=0 y=0 scalex=210 scaley=210 red=8-1024 green=8-1024 blue=8-1024 #palette reduce
-    .frame 600
-    .change s1 x=0 y=0 scalex=210 scaley=210 red=+0 green=+0 blue=+0 #back to normal
-    .frame 700
-    .change s1 x=105 y=105 scalex=0 scaley=0 luminance=0 #fadeout
+<section>
+    <c>swfc</c> has Actionscript support.
+    For normal actionscript, which is executed once a given frame
+    is reached, just open an <c>.action</c> block, and write
+    the ActionScript into the block:
+  
+<code lang="swfc">
+.flash name="action.swf" bbox=300x300 fps=50
+
+.box mybox color=blue fill=green width=100 height=100
+.put mybox
+
+.frame 0
+    .action:
+       _root.angle += 0.3;
+       mybox._x = 100*Math.cos(_root.angle)+100;
+       mybox._y = 100*Math.sin(_root.angle)+100;
+    .end
+.frame 1
+    .action:
+       gotoFrame(0);
+       Play();
+    .end
+.frame 2
 .end
-  </code>
- </section>
+</code>
+
+</section>
+
 
 </chapter>
+
+<chapter><title>Buttons</title>
+<p>
+Actionscript comes in handy when dealing with SWF Buttons.
+</p>
+<p>
+A button defines, in SWF context, an object sensitive to mouse movement,
+mouse buttons, and key presses.
+</p>
+<p>
+The following is a trivial example: Four objects which change their shape
+once the cursor is over it.
+<code lang="swfc">
+.flash name="button1.swf" fps=50
+
+.box box1 color=white fill=#336633 width=100 height=100 .box box2 color=white fill=#99cc99 width=150 height=150
+.button mybutton1
+    .show box1 as=shape x=50 y=50
+    .show box2 as=hover x=25 y=25
+.end
+
+.frame 0
+    .put b1=mybutton1
+    .put b2=mybutton1 x=200 red=+255
+    .put b3=mybutton1 y=200 green=+255
+    .put b4=mybutton1 x=200 y=200 blue=+255
+.end
+</code>
+</p>
+
+<p>
+The <c>.show</c> command (which can only be used inside <c>.button</c>) has a syntax
+very similar to <c>.put</c>. 
+For every shape a button uses, you can specify the position, color transform, scaling,
+rotation etc. just like with <c>.put</c>.
+</p>
+<p>
+The only <i>real</i> difference between those two commands is the <c>as</c> parameter:
+with that you tell the button when to display that specific shape.
+There are four allowed parameters to <c>as</c>:
+<ul>
+    <li><b>idle</b> The shape to display when the button is idle, that is, the
+                    mouse is somewhere else, and not over the button.
+    </li><li><b>hover</b> The shape to display if the mouse cursor is <i>inside</i> the button.
+                     What exactly is <i>"inside"</i> is defined by <b>area</b>:
+    </li><li><b>area</b> This shape is not displayed. It serves as bounding box (actually,
+                     bounding polygon) for the button. A button considers itself
+                    active (that is, the <c>hover</c> shape is active, not the <c>idle</c>
+                    shape) if the mouse is inside this area. Also, mouse button clicks
+                    have to be in this area for this button.
+    </li><li><b>pressed</b> The shape to display if the user clicks on the button. This shape
+                       is displayed as long as the mouse button is down.
+    </li>
+</ul>
+</p>
+
+<section><title>Another button example: tooltips</title>
+
+<code lang="swfc">
+.flash name="button2.swf" fps=50
+
+.sprite red_tooltip
+    .font arial Arial.swf
+    .text text font=arial text="A red shape" color=white
+    .box box fill=blue color=turquoise width=90 height=20
+    .put box
+    .put text x=10 y=15
+.end
+
+.box box1 fill=red width=50 height=50 
+.button mybutton1
+    .show box1 as=area x=0 y=0
+    .show red_tooltip as=hover x=25 y=25 alpha=50%
+.end
+
+.frame 0
+    .put mybutton1
+.end
+</code>
+    
+
+</section>
+
+</chapter>
+
 </guide>