📄 main.cpp
字号:
#include <fstream>
#include <sstream>
#include <vector>
#include "FButton.h"
#include "FBase.h"
#include "FShape.h"
#include "FDisplay.h"
#include "FControl.h"
#include "FSprite.h"
#include "FSound.h"
#include "FlashMP3Encoder.h"
#include "FFont.h"
#if defined(__WIN32__)
#include "FlashFontObj.h"
#endif
#include "FMorph.h"
#include "FTarga.h"
#include "FBitmap.h"
#include "FImport.h"
#include "magick++/Magick++.h"
using namespace Magick;
UWORD ReadImage(char *fname, std::ostringstream &f)
{
UWORD return_val = 0;
try
{
Image image(fname);
int width = image.baseColumns();
int height = image.baseRows();
//Encode Image with 24 bit color
int format = 5;
unsigned char *imagedata = (unsigned char *)malloc(height*width*3);
unsigned char *tgadata = (unsigned char *)malloc(height*width*4);
image.write(0,0,width,height,"RGB",CharPixel,imagedata);
{
for(UWORD y = 0; y < height; y++)
{
for(UWORD x = 0; x < width; x++)
{
UDWORD base = (y*width+x)*4;
UDWORD base2 = (y*width+x)*3;
unsigned char r = imagedata[base2];
unsigned char g = imagedata[base2+1];
unsigned char b = imagedata[base2+2];
((unsigned char*)tgadata)[base+0] = 0xff;
((unsigned char*)tgadata)[base+1] = r;
((unsigned char*)tgadata)[base+2] = g;
((unsigned char*)tgadata)[base+3] = b;
}
}
}
FlashZLibBitmapData d((unsigned char *)tgadata,(width*height*4));
FlashTagDefineBitsLossless2 db(format,width, height, d);
f << db;
free (imagedata);
free (tgadata);
FlashMatrix m;
m.SetScale(20,20);
FlashShapeWithStyle s;
FlashFillStyleArray ffa;
FlashFillStyleBitmap sf(db.GetID(),m);
ffa.AddFillStyle(&sf);
s.SetFillStyleArray(ffa);
FlashShapeRecordChange c(0,0);
c.ChangeFillStyle1(1);
s.AddRecord(c);
s.AddRecord(FlashShapeRecordStraight(width*20, 0));
s.AddRecord(FlashShapeRecordStraight(0, height*20));
s.AddRecord(FlashShapeRecordStraight(-width*20, 0));
s.AddRecord(FlashShapeRecordStraight(0, -height*20));
FlashTagDefineShape3 ftds(s);
f << ftds;
return_val = ftds.GetID();
}
catch(Exception &error_)
{
std::cout << "Caught exception: " << error_.what() << "\n";
}
return return_val;
}
void SetBackground(std::ostringstream &f)
{
f << FlashTagPlaceObject2 (1,ReadImage("c:\\windows\\desktop\\background.tga",f));
}
#if defined(__WIN32__)
void WriteText(std::ostringstream &f)
{
FlashFontFactory fff;
fff.WriteText(f,"Arial Black","Virtuascape", 530*20, 505*20, FlashRGB(0x34,0x34,0x34),18,100,220);
fff.WriteText(f,"Arial Black","Virtuascape", 650*20, 520*20, FlashRGB(0xff,0xff,0xff),10,101,100);
}
#endif
void Write3DBox(std::ostringstream &f, int x1, int y1, int x2, int y2, FlashRGB &c1, UWORD depth)
{
FlashShapeWithStyle shape;
FlashRGB c2((unsigned short)(1.50 * c1.GetR()), (unsigned short)(1.50 * c1.GetG()), (unsigned short)(1.50 * c1.GetB()));
FlashRGB c3((unsigned short)(0.50 * c1.GetR()), (unsigned short)(0.50 * c1.GetG()), (unsigned short)(0.50 * c1.GetB()));
FlashFillStyleArray fsa;
FlashFillStyleSolid s1(c1);
fsa.AddFillStyle(&s1);
FlashLineStyleArray fla;
FlashLineStyle ls1(20,c2);
FlashLineStyle ls2(20,c3);
fla.AddLineStyle(&ls1);
fla.AddLineStyle(&ls2);
shape.SetFillStyleArray(fsa);
shape.SetLineStyleArray(fla);
FlashShapeRecordChange line0(x1,y1);
line0.ChangeFillStyle1(1);
line0.ChangeLineStyle(1);
FlashShapeRecordChange line1;
line1.ChangeLineStyle(1);
FlashShapeRecordChange line2;
line2.ChangeLineStyle(2);
shape.AddRecord(line0);
shape.AddRecord(FlashShapeRecordStraight(x2-x1,0));
shape.AddRecord(line2);
shape.AddRecord(FlashShapeRecordStraight(0,y2-y1));
shape.AddRecord(FlashShapeRecordStraight(-(x2-x1),0));
shape.AddRecord(line1);
shape.AddRecord(FlashShapeRecordStraight(0,-(y2-y1)));
FlashTagDefineShape3 tshape(shape);
f << tshape;
f << FlashTagPlaceObject2(depth, tshape.GetID());
}
void WriteSprite(std::ostringstream &f)
{
UWORD id = ReadImage("c:\\windows\\desktop\\v.tga",f);
FlashTagSprite ftds;
FlashMatrix m;
m.SetTranslate(300*20,230*20);
FlashColorTransform cfx;
FlashTagPlaceObject2 f1(2,id,m);
int r;
r = 128+rand()%128;
cfx.SetAddRGB(FlashRGB(0,0,0,-r));
FlashTagPlaceObject2 f2(2,id,m,cfx);
f2.SetMove(true);
r = 128+rand()%128;
cfx.SetAddRGB(FlashRGB(0,0,0,-r));
FlashTagPlaceObject2 f3(2,id,m,cfx);
f3.SetMove(true);
r = 128+rand()%128;
cfx.SetAddRGB(FlashRGB(0,0,0,-r));
FlashTagPlaceObject2 f4(2,id,m,cfx);
f4.SetMove(true);
r = 128+rand()%128;
cfx.SetAddRGB(FlashRGB(0,0,0,-r));
FlashTagPlaceObject2 f5(2,id,m,cfx);
f5.SetMove(true);
r = 128+rand()%128;
cfx.SetAddRGB(FlashRGB(0,0,0,-r));
FlashTagPlaceObject2 f6(2,id,m,cfx);
f6.SetMove(true);
r = 128+rand()%128;
cfx.SetAddRGB(FlashRGB(0,0,0,-r));
FlashTagPlaceObject2 f7(2,id,m,cfx);
f7.SetMove(true);
r = 128+rand()%128;
cfx.SetAddRGB(FlashRGB(0,0,0,-r));
FlashTagPlaceObject2 f8(2,id,m,cfx);
f8.SetMove(true);
FlashTagShowFrame s;
ftds.Add(&f1);
ftds.Add(&s);
ftds.Add(&f2);
ftds.Add(&s);
ftds.Add(&f3);
ftds.Add(&s);
ftds.Add(&f4);
ftds.Add(&s);
ftds.Add(&f5);
ftds.Add(&s);
ftds.Add(&f6);
ftds.Add(&s);
ftds.Add(&f7);
ftds.Add(&s);
ftds.Add(&f8);
ftds.Add(&s);
f << ftds;
f << FlashTagPlaceObject2(2,ftds.GetID());
}
void TestRotatingText(void)
{
#if defined(__WIN32__)
std::ofstream fileout("testing2.swf",std::ios::binary);
std::ostringstream f(std::ios::binary);
f << FlashTagBackgroundColor(0xff,0xee,0xff);
FlashRect bounds;
UWORD depth = 0;
FlashFontFactory fff;
fff.WriteText(f,"Arial","Hello,SWFSource", 25*20, 10*20, FlashRGB(0xff,0x00,0x00),10,depth,bounds);
depth = 1;
fff.WriteText(f,"Arial","Support Double-byte Char Set", 25*20, 50*20, FlashRGB(0x00,0x00,0x50),10,depth,bounds);
depth = 1;
fff.WriteText(f,"Arial","CJK(China,Japan,Korea)", 25*20, 75*20, FlashRGB(0x00,0x50,0x00),10,depth,bounds);
depth = 2;
//Test DBCS
//WriteText(f,"Arial","耖闲茄惫
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -