1 /* once.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2009 */
2
3 /*
4
5 Copyright (c) 2002-2009 Made to Order Software Corp.
6
7 Permission is hereby granted, free of charge, to any
8 person obtaining a copy of this software and
9 associated documentation files (the "Software"), to
10 deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify,
12 merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom
14 the Software is furnished to do so, subject to the
15 following conditions:
16
17 The above copyright notice and this permission notice
18 shall be included in all copies or substantial
19 portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
22 ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
25 EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
27 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
28 ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 SOFTWARE.
31
32 */
33
34
35 #include <sswf/libsswf.h>
36
37 #define TWIPS(x) ((long) ((x) * 20.0))
38 #define TORAD(x) ((double) (x) * (M_PI / 180.0))
39
40
main(int argc,char * argv[])41 int main(int argc, char *argv[])
42 {
43 // Initialize the header
44 sswf::TagHeader my_header;
45
46 my_header.SetCompress();
47
48 sswf::SRectangle rect;
49 rect.Set(0, TWIPS(640), 0, TWIPS(480));
50 my_header.SetFrame(rect);
51
52 my_header.SetRate(15);
53
54 //my_header.SetVersion(3); -- SetCompress() requires version 6 anyway
55
56 sswf::TagProtect *protect = new sswf::TagProtect(&my_header);
57
58 // Add a box
59 sswf::TagShape *square = new sswf::TagShape(&my_header);
60 sswf::Style style(my_header);
61 style.SetType(sswf::Style::STYLE_TYPE_SOLID);
62 sswf::Color color;
63 color.Set(0, 0, 0); // solid black
64 style.SetColor(0, color);
65 square->AddStyle(style);
66 square->AddMove(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS(-0.5 * 60.0), TWIPS(-0.5 * 60.0)); // draw square
67 square->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS( 1.0 * 60.0), TWIPS( 0.0 * 60.0));
68 square->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS( 0.0 * 60.0), TWIPS( 1.0 * 60.0));
69 square->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS(-1.0 * 60.0), TWIPS( 0.0 * 60.0));
70 square->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS( 0.0 * 60.0), TWIPS(-1.0 * 60.0));
71 rect.Set(TWIPS(-0.6 * 60.0), TWIPS(0.6 * 60.0), TWIPS(-0.6 * 60.0), TWIPS(0.6 * 60.0)); // make bounds a bit bigger
72 square->SetBounds(0, rect);
73
74 // Add a circle
75 sswf::TagShape *circle = new sswf::TagShape(&my_header);
76 style.SetType(sswf::Style::STYLE_TYPE_SOLID);
77 color.Set(0, 255, 0, 128); // 50% transparent green
78 style.SetColor(0, color);
79 circle->AddStyle(style);
80 circle->AddMove(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS(0), TWIPS(-28.35)); // draw circle
81 circle->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS( 8.3), TWIPS( 8.3), TWIPS( 11.8), TWIPS( 0));
82 circle->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS( 0), TWIPS( 11.75), TWIPS( 8.35), TWIPS( 8.3));
83 circle->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS( -8.3), TWIPS( 8.35), TWIPS( 0.05), TWIPS( 11.75));
84 circle->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS(-11.8), TWIPS( 0.05), TWIPS( -8.3), TWIPS( 8.3));
85 circle->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS(-8.35), TWIPS( -8.3), TWIPS(-11.75), TWIPS( 0));
86 circle->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS(-0.05), TWIPS(-11.75), TWIPS( -8.3), TWIPS( -8.3));
87 circle->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS( 8.3), TWIPS( -8.35), TWIPS( 0), TWIPS(-11.75));
88 circle->AddEdge(sswf::TagShape::MORPH_MODE_SHAPE0, TWIPS(11.75), TWIPS( 0), TWIPS( 8.3), TWIPS( -8.35));
89 rect.Set(TWIPS(-1.0) * 60, TWIPS(1.0) * 60, TWIPS(-1.0) * 60, TWIPS(1.0) * 60); // make bounds a bit bigger
90 circle->SetBounds(0, rect);
91
92 // Place the two shapes
93 sswf::TagPlace *place = new sswf::TagPlace(&my_header);
94 place->SetDepth(1);
95 place->SetObjectID(square->Identification());
96 sswf::Matrix matrix;
97 matrix.SetScale(1.0);
98 matrix.SetRotate(0);
99 matrix.SetTranslate(TWIPS(640 / 2), TWIPS(480 / 2));
100 place->SetMatrix(matrix);
101 new sswf::TagShowFrame(&my_header);
102
103 place = new sswf::TagPlace(&my_header);
104 place->SetDepth(2);
105 place->SetObjectID(circle->Identification());
106 matrix.SetScale(1.0);
107 matrix.SetRotate(0);
108 matrix.SetTranslate(TWIPS(640 / 2), TWIPS(480 / 2 - 70));
109 place->SetMatrix(matrix);
110 new sswf::TagShowFrame(&my_header);
111
112 // Rotate and move the shape
113 for(int i = 0; i < 360; i += 5) {
114 sswf::TagPlace *place = new sswf::TagPlace(&my_header);
115 place->SetDepth(2);
116 sswf::Matrix matrix;
117 matrix.SetScale(1.0);
118 matrix.SetRotate(0);
119 double a = TORAD(i + 180.0);
120 matrix.SetTranslate(TWIPS(640.0 / 2.0 + sin(a) * 70.0), TWIPS(480.0 / 2.0 + cos(a) * 70.0));
121 place->SetMatrix(matrix);
122
123 new sswf::TagShowFrame(&my_header);
124 }
125
126 // Now we stop the animation
127 sswf::TagDoAction *do_action = new sswf::TagDoAction(&my_header);
128 sswf::Action *action = new sswf::Action(do_action, sswf::Action::ACTION_STOP);
129 do_action->SetAction(*action);
130 delete action;
131
132 new sswf::TagShowFrame(&my_header);
133
134 // end the movie
135 new sswf::TagEnd(&my_header);
136
137 // Save the result in a file
138 sswf::Data result;
139 size_t size;
140 void *buffer;
141
142 my_header.Save(result);
143 result.Read(buffer, size);
144
145 FILE *f = fopen("once.swf", "wb");
146 if(f != 0) {
147 fwrite(buffer, size, 1, f);
148 fclose(f);
149 }
150
151 return 0;
152 }
153
154