├── .gitignore ├── LICENSE.txt ├── README.md ├── cocos2d_swf ├── Classes │ ├── AppDelegate.cpp │ ├── AppDelegate.h │ ├── AppMacros.h │ ├── CCFlash.cpp │ ├── CCFlash.h │ ├── FontCache.cpp │ ├── FontCache.h │ ├── FontCache.mm │ ├── FontCache_win32.cpp │ ├── HelloWorldScene.cpp │ ├── HelloWorldScene.h │ ├── lru_cache.h │ └── stb_truetype.h ├── Resources │ ├── CloseNormal.png │ ├── CloseSelected.png │ ├── HelloWorld.png │ ├── fonts │ │ └── Marker Felt.ttf │ ├── ipad │ │ ├── CloseNormal.png │ │ ├── CloseSelected.png │ │ └── HelloWorld.png │ ├── ipadhd │ │ ├── CloseNormal.png │ │ ├── CloseSelected.png │ │ └── HelloWorld.png │ ├── iphone │ │ ├── CloseNormal.png │ │ ├── CloseSelected.png │ │ └── HelloWorld.png │ ├── orangerec.png │ ├── test.fla │ ├── test.swf │ ├── test.wav │ ├── test2.fla │ └── test2.swf ├── proj.ios │ ├── AppController.h │ ├── AppController.mm │ ├── Default-568h@2x.png │ ├── Default.png │ ├── Default@2x.png │ ├── HelloCpp.xcodeproj │ │ └── project.pbxproj │ ├── HelloCpp_Prefix.pch │ ├── Icon-114.png │ ├── Icon-144.png │ ├── Icon-57.png │ ├── Icon-72.png │ ├── Info.plist │ ├── Prefix.pch │ ├── RootViewController.h │ ├── RootViewController.mm │ └── main.m └── proj.win32 │ ├── HelloCpp.sln │ ├── HelloCpp.vcxproj │ ├── HelloCpp.vcxproj.filters │ ├── PropertySheet.props │ ├── main.cpp │ └── main.h ├── include ├── tinyswf.h ├── tsHeader.h ├── tsMovieClip.h ├── tsReader.h ├── tsSWF.h ├── tsTag.h └── tsTypes.h ├── libtess2 ├── LICENSE.txt ├── bucketalloc.c ├── bucketalloc.h ├── dict.c ├── dict.h ├── geom.c ├── geom.h ├── mesh.c ├── mesh.h ├── priorityq.c ├── priorityq.h ├── readme.txt ├── stdafx.h ├── sweep.c ├── sweep.h ├── tess.c ├── tess.h └── tesselator.h ├── misc ├── tinyswf-bitmap.docx ├── tinyswf-bitmap.pdf ├── tinyswf.ai ├── tinyswf.fla └── tinyswf.png ├── projects ├── proj.android │ ├── AndroidManifest.xml │ ├── jni │ │ ├── Android.mk │ │ └── Application.mk │ ├── project.properties │ └── res │ │ └── values │ │ └── strings.xml ├── proj.ios │ ├── libtinyswf-Prefix.pch │ └── libtinyswf.xcodeproj │ │ └── project.pbxproj └── proj.vc11 │ ├── libtinyswf.sln │ ├── libtinyswf.vcxproj │ ├── libtinyswf.vcxproj.filters │ ├── stdafx.cpp │ └── stdafx.h ├── rapidxml ├── license.txt ├── manual.html ├── rapidxml.hpp ├── rapidxml_iterators.hpp ├── rapidxml_print.hpp └── rapidxml_utils.hpp ├── src ├── tags │ ├── DefineButton.cpp │ ├── DefineButton.h │ ├── DefineFont.cpp │ ├── DefineFont.h │ ├── DefineScalingGrid.h │ ├── DefineShape.cpp │ ├── DefineShape.h │ ├── DefineSound.h │ ├── DefineSprite.cpp │ ├── DefineSprite.h │ ├── DefineText.cpp │ ├── DefineText.h │ ├── DoAction.cpp │ ├── DoAction.h │ ├── ExportAssets.h │ ├── FrameLabel.h │ ├── ImportAssets2.h │ ├── PlaceObject.cpp │ ├── PlaceObject.h │ ├── RemoveObject.h │ ├── SetBackgroundColor.h │ ├── ShowFrame.h │ ├── VectorEngine.cpp │ └── VectorEngine.h ├── tsHeader.cpp ├── tsMovieClip.cpp ├── tsReader.cpp ├── tsSWF.cpp └── tsTag.cpp ├── swf-file-format-spec.pdf ├── test ├── beer.swf ├── clown.swf ├── cupid.swf ├── daisies.swf ├── dog.swf ├── giraffe.swf ├── hole.swf ├── intersect3.swf ├── monkey.swf ├── monster │ ├── foot_0.png │ ├── foot_a.png │ ├── forearm_0.png │ ├── forearm_a.png │ ├── hand_0_0.png │ ├── hand_0_1.png │ ├── hand_0_2.png │ ├── hand_0_3.png │ ├── hand_a_0.png │ ├── hand_a_1.png │ ├── hand_a_2.png │ ├── hand_a_3.png │ ├── head_0.png │ ├── head_1.png │ ├── head_2.png │ ├── head_3.png │ ├── monster.fla │ ├── monster.swf │ ├── pelvis_0.png │ ├── shoulder_0.png │ ├── shoulder_a.png │ ├── test.wav │ ├── thigh_0.png │ ├── thigh_a.png │ └── torso_0.png ├── puppy.swf ├── splashscreen.swf ├── squares.swf ├── tatoo.swf ├── test.swf ├── transportation.swf ├── venus_fly_trap.swf └── whitebird1.swf ├── tsviewer └── proj.vc11 │ ├── FontCache.cpp │ ├── FontCache.h │ ├── FontCache_win32.cpp │ ├── ReadMe.txt │ ├── lru_cache.h │ ├── stb_truetype.h │ ├── stdafx.cpp │ ├── stdafx.h │ ├── targetver.h │ ├── tsviewer.cpp │ ├── tsviewer.sln │ ├── tsviewer.vcxproj │ └── tsviewer.vcxproj.filters └── zlib ├── include ├── zconf.h └── zlib.h └── lib ├── zdll.lib └── zlib.def /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore thumbnails created by windows 2 | Thumbs.db 3 | 4 | # Ignore files build by Visual Studio 5 | *.obj 6 | *.exe 7 | *.pdb 8 | *.aps 9 | *.user 10 | *.vspscc 11 | *_i.c 12 | *.i 13 | *.icf 14 | *_p.c 15 | *.ncb 16 | *.suo 17 | *.tlb 18 | *.tlh 19 | *.bak 20 | *.cache 21 | *.ilk 22 | *.log 23 | [Bb]in 24 | [Dd]ebug*/ 25 | *.sbr 26 | *.sdf 27 | [Rr]elease*/ 28 | _ReSharper*/ 29 | [Tt]est[Rr]esult* 30 | ipch/ 31 | *.opensdf 32 | 33 | # Ignore files build by ndk and eclipse 34 | libs/ 35 | bin/ 36 | obj/ 37 | gen/ 38 | assets/ 39 | local.properties 40 | 41 | # Ignore files build by xcode 42 | *.mode*v* 43 | *.pbxuser 44 | *.xcbkptlist 45 | *.xcscheme 46 | *.xcworkspacedata 47 | *.xcuserstate 48 | xcschememanagement.plist 49 | build/ 50 | .DS_Store 51 | ._.* 52 | xcuserdata/ 53 | DerivedData/ 54 | 55 | # Compiled Object files 56 | *.slo 57 | *.lo 58 | *.o 59 | 60 | # Compiled Dynamic libraries 61 | *.so 62 | *.dylib 63 | 64 | # Compiled Static libraries 65 | *.lai 66 | *.la 67 | *.a 68 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 jbyu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #TinySWF - Tiny SWF Player 2 | ![TinySWF - Tiny SWF Player](https://dl.dropboxusercontent.com/u/2907407/tinyswf.png) 3 | 4 | **TinySWF is a simple SWF (Adobe Flash) player which can play FLASH contents in cocos2d-x and OpenGL environment.** 5 | 6 | Creating 2D user interfaces requires a good graphics editor which needed lot of time and resource to develop. 7 | Adobe Flash editor already provides developers a good editing environment to create user interfaces and animations. 8 | TinySWF directly parse and play FLASH contents to speed up development processes. 9 | 10 | ![sample](https://dl.dropboxusercontent.com/u/2907407/tinyswf-sample.png) 11 | 12 | 13 | Features 14 | ---------- 15 | 16 | * Bitmap 17 | * Motion Tween 18 | * Text 19 | * Shape 20 | * Button 21 | * MovieClip 22 | * Mask 23 | * Sound 24 | * SWF3 action model 25 | - play 26 | - stop 27 | - gotoAndPlay 28 | - nextFrame 29 | - fscommand 30 | 31 | 32 | First step 33 | ---------- 34 | 35 | 1. Download source code from [Github][1] 36 | 2. Enter tsviewer/porj.vc11 37 | 3. Open tsviewer.sln by vs2012 38 | 39 | TSViewer is a simple FLASH viewer which also provides command line tool to trim unsupported tags in FLASH contents to save space of SWF files. 40 | 41 | Project Dpendence: 42 | 43 | * [FreeGLUT][2] 44 | * [SOIL][3] 45 | * [FMOD][4] (Optional) 46 | 47 | 48 | How to use TinySWF in cocos2d-x 49 | ---------- 50 | 51 | 1. Download source code from [Github][1] 52 | 2. Enter cocos2d_swf/porj.win32 53 | 3. Open HelloCpp.sln by vs2012 54 | 55 | HelloCpp is a simple FLASH viewer by coco2d-x. 56 | 57 | Project Dpendence: 58 | 59 | * [cocos2d-x 3.0 alpha][5] 60 | 61 | 62 | Test data 63 | ---------- 64 | test folder contains some FLASH data for testing. 65 | 66 | 67 | Bitmap Usage 68 | ---------- 69 | For optimization reason, TinySWF loads outside texture files instead of using embbed bitmap in SWF files. 70 | 71 | Please read [bitmap guide][6]. 72 | 73 | 74 | ---------- 75 | 76 | [1]: https://github.com/jbyu/tinyswf.git 77 | [2]: http://freeglut.sourceforge.net 78 | [3]: http://www.lonesock.net/soil.html 79 | [4]: http://www.fmod.org/ 80 | [5]: http://www.cocos2d-x.org 81 | [6]: https://dl.dropboxusercontent.com/u/2907407/tinyswf-bitmap.pdf 82 | -------------------------------------------------------------------------------- /cocos2d_swf/Classes/AppDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "AppDelegate.h" 2 | 3 | #include 4 | #include 5 | 6 | #include "HelloWorldScene.h" 7 | #include "AppMacros.h" 8 | 9 | USING_NS_CC; 10 | using namespace std; 11 | 12 | AppDelegate::AppDelegate() { 13 | 14 | } 15 | 16 | AppDelegate::~AppDelegate() 17 | { 18 | } 19 | 20 | bool AppDelegate::applicationDidFinishLaunching() { 21 | // initialize director 22 | Director* director = Director::getInstance(); 23 | EGLView* glView = EGLView::getInstance(); 24 | 25 | director->setOpenGLView(glView); 26 | 27 | Size size = director->getWinSize(); 28 | 29 | // Set the design resolution 30 | //glView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, kResolutionNoBorder); 31 | 32 | Size frameSize = glView->getFrameSize(); 33 | 34 | vector searchPath; 35 | #if 0 36 | // In this demo, we select resource according to the frame's height. 37 | // If the resource size is different from design resolution size, you need to set contentScaleFactor. 38 | // We use the ratio of resource's height to the height of design resolution, 39 | // this can make sure that the resource's height could fit for the height of design resolution. 40 | // if the frame's height is larger than the height of medium resource size, select large resource. 41 | if (frameSize.height > mediumResource.size.height) 42 | { 43 | searchPath.push_back(largeResource.directory); 44 | 45 | director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width)); 46 | } 47 | // if the frame's height is larger than the height of small resource size, select medium resource. 48 | else if (frameSize.height > smallResource.size.height) 49 | { 50 | searchPath.push_back(mediumResource.directory); 51 | 52 | director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width)); 53 | } 54 | // if the frame's height is smaller than the height of medium resource size, select small resource. 55 | else 56 | #endif 57 | { 58 | searchPath.push_back(smallResource.directory); 59 | 60 | director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width)); 61 | } 62 | 63 | // set searching path 64 | FileUtils::getInstance()->setSearchPaths(searchPath); 65 | 66 | // turn on display FPS 67 | director->setDisplayStats(true); 68 | 69 | // set FPS. the default value is 1.0/60 if you don't call this 70 | director->setAnimationInterval(1.0 / 60); 71 | 72 | // create a scene. it's an autorelease object 73 | Scene *scene = HelloWorld::scene(); 74 | 75 | // run 76 | director->runWithScene(scene); 77 | 78 | return true; 79 | } 80 | 81 | // This function will be called when the app is inactive. When comes a phone call,it's be invoked too 82 | void AppDelegate::applicationDidEnterBackground() { 83 | Director::getInstance()->stopAnimation(); 84 | 85 | // if you use SimpleAudioEngine, it must be pause 86 | // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); 87 | } 88 | 89 | // this function will be called when the app is active again 90 | void AppDelegate::applicationWillEnterForeground() { 91 | Director::getInstance()->startAnimation(); 92 | 93 | // if you use SimpleAudioEngine, it must resume here 94 | // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); 95 | } 96 | -------------------------------------------------------------------------------- /cocos2d_swf/Classes/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef _APP_DELEGATE_H_ 2 | #define _APP_DELEGATE_H_ 3 | 4 | #include "cocos2d.h" 5 | 6 | /** 7 | @brief The cocos2d Application. 8 | 9 | The reason for implement as private inheritance is to hide some interface call by CCDirector. 10 | */ 11 | class AppDelegate : private cocos2d::Application 12 | { 13 | public: 14 | AppDelegate(); 15 | virtual ~AppDelegate(); 16 | 17 | /** 18 | @brief Implement CCDirector and CCScene init code here. 19 | @return true Initialize success, app continue. 20 | @return false Initialize failed, app terminate. 21 | */ 22 | virtual bool applicationDidFinishLaunching(); 23 | 24 | /** 25 | @brief The function be called when the application enter background 26 | @param the pointer of the application 27 | */ 28 | virtual void applicationDidEnterBackground(); 29 | 30 | /** 31 | @brief The function be called when the application enter foreground 32 | @param the pointer of the application 33 | */ 34 | virtual void applicationWillEnterForeground(); 35 | }; 36 | 37 | #endif // _APP_DELEGATE_H_ 38 | 39 | -------------------------------------------------------------------------------- /cocos2d_swf/Classes/AppMacros.h: -------------------------------------------------------------------------------- 1 | #ifndef __APPMACROS_H__ 2 | #define __APPMACROS_H__ 3 | 4 | #include "cocos2d.h" 5 | 6 | /* For demonstrating using one design resolution to match different resources, 7 | or one resource to match different design resolutions. 8 | 9 | [Situation 1] Using one design resolution to match different resources. 10 | Please look into Appdelegate::applicationDidFinishLaunching. 11 | We check current device frame size to decide which resource need to be selected. 12 | So if you want to test this situation which said in title '[Situation 1]', 13 | you should change ios simulator to different device(e.g. iphone, iphone-retina3.5, iphone-retina4.0, ipad, ipad-retina), 14 | or change the window size in "proj.XXX/main.cpp" by "CCEGLView::setFrameSize" if you are using win32 or linux plaform 15 | and modify "proj.mac/AppController.mm" by changing the window rectangle. 16 | 17 | [Situation 2] Using one resource to match different design resolutions. 18 | The coordinates in your codes is based on your current design resolution rather than resource size. 19 | Therefore, your design resolution could be very large and your resource size could be small. 20 | To test this, just define the marco 'TARGET_DESIGN_RESOLUTION_SIZE' to 'DESIGN_RESOLUTION_2048X1536' 21 | and open iphone simulator or create a window of 480x320 size. 22 | 23 | [Note] Normally, developer just need to define one design resolution(e.g. 960x640) with one or more resources. 24 | */ 25 | 26 | #define DESIGN_RESOLUTION 0 27 | #define DESIGN_RESOLUTION_1024X768 1 28 | #define DESIGN_RESOLUTION_2048X1536 2 29 | 30 | /* If you want to switch design resolution, change next line */ 31 | #define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION 32 | 33 | typedef struct tagResource 34 | { 35 | cocos2d::Size size; 36 | char directory[100]; 37 | }Resource; 38 | 39 | static Resource smallResource = { cocos2d::Size(640, 960), "iphone" }; 40 | static Resource mediumResource = { cocos2d::Size(768, 1024), "ipad" }; 41 | static Resource largeResource = { cocos2d::Size(1536, 2048), "ipadhd" }; 42 | 43 | #if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION) 44 | static cocos2d::Size designResolutionSize = smallResource.size; 45 | #elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768) 46 | static cocos2d::Size designResolutionSize = mediumResource.size; 47 | #elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536) 48 | static cocos2d::Size designResolutionSize = largeResource.size; 49 | #else 50 | #error unknown target design resolution! 51 | #endif 52 | 53 | // The font size 24 is designed for small resolution, so we should change it to fit for current design resolution 54 | #define TITLE_FONT_SIZE (cocos2d::EGLView::getInstance()->getDesignResolutionSize().width / smallResource.size.width * 24) 55 | 56 | #endif /* __APPMACROS_H__ */ 57 | -------------------------------------------------------------------------------- /cocos2d_swf/Classes/CCFlash.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | #ifndef __CCFLASH_H__ 5 | #define __CCFLASH_H__ 6 | 7 | #include "tinyswf.h" 8 | #include "cocos2d.h" 9 | 10 | tinyswf::Asset CCFlashLoadAsset( const char *name, const char *url ); 11 | 12 | typedef std::function swfImportCallback; 13 | 14 | void CCFlashSetButtonText(tinyswf::Button& btn, const char* variable, const char* text); 15 | 16 | class CCFlash : public cocos2d::LayerRGBA { 17 | typedef std::map FlashTextureCache; 18 | FlashTextureCache _textureCache; 19 | bool _useTextureAtlas; 20 | tinyswf::SWF *_swf; 21 | std::string _directory; 22 | 23 | void updateColor(); 24 | 25 | public: 26 | CCFlash(bool useAtlas) 27 | :_useTextureAtlas(useAtlas) 28 | {} 29 | 30 | virtual ~CCFlash(); 31 | 32 | virtual void draw(); 33 | 34 | virtual void update(float delta); 35 | 36 | virtual bool initWithFile(const char* filename, tinyswf::SWF::GetURLCallback fscommand); 37 | 38 | tinyswf::SWF* getSWF(void) { return _swf; } 39 | 40 | virtual bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event) override; 41 | virtual void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event) override; 42 | virtual void onTouchCancelled(cocos2d::Touch *touch, cocos2d::Event* event) override; 43 | virtual void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event) override; 44 | 45 | virtual void setColor(const cocos2d::Color3B &color) override; 46 | virtual void setOpacity(GLubyte opacity) override; 47 | 48 | static CCFlash* create(const char* filename, bool useAtlas = false, tinyswf::SWF::GetURLCallback fscommand = NULL); 49 | 50 | cocos2d::Texture2D* getTexture(const char *filename, tinyswf::MATRIX &texture); 51 | }; 52 | 53 | class CCFlashRenderer : public tinyswf::Renderer { 54 | typedef std::map ImoprtSWFCache; 55 | ImoprtSWFCache _swfCache; 56 | 57 | cocos2d::GLProgram *_defaultShader; 58 | cocos2d::GLProgram *_textureShader; 59 | int _defaultColorLocation; 60 | int _addColorLocation; 61 | int _multColorLocation; 62 | int _textureMatrixLocation; 63 | int _maskLevel; 64 | kmMat4 _matrixMV; 65 | 66 | swfImportCallback _importCallback; 67 | 68 | public: 69 | CCFlashRenderer(); 70 | virtual ~CCFlashRenderer(); 71 | 72 | void maskBegin(void); 73 | void maskEnd(void); 74 | void maskOffBegin(void); 75 | void maskOffEnd(void); 76 | 77 | void applyTransform(const tinyswf::MATRIX3f& mtx ); 78 | 79 | void drawLineStrip(const tinyswf::VertexArray& vertices, const tinyswf::CXFORM& cxform, const tinyswf::LineStyle& style); 80 | 81 | void drawTriangles(const tinyswf::VertexArray& vertices, const tinyswf::CXFORM& cxform, const tinyswf::FillStyle& style, const tinyswf::Asset& asset ); 82 | 83 | void drawImportAsset( const tinyswf::RECT& rect, const tinyswf::CXFORM& cxform, const tinyswf::Asset& asset ); 84 | 85 | void drawBegin(void); 86 | void drawEnd(void); 87 | 88 | tinyswf::SWF* importSWF(const char* filename); 89 | 90 | static float kDesignScreenHeight; 91 | 92 | void setImportCallback(swfImportCallback func) { _importCallback = func; } 93 | swfImportCallback& getImportCallback(void) { return _importCallback; } 94 | }; 95 | 96 | 97 | #endif//__CCFLASH_H__ -------------------------------------------------------------------------------- /cocos2d_swf/Classes/FontCache.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | #ifndef __FONT_CACHE_H__ 5 | #define __FONT_CACHE_H__ 6 | 7 | #include "tinyswf.h" 8 | #include "lru_cache.h" 9 | 10 | const int kGLYPH_WIDTH = 36; 11 | 12 | namespace cocos2d { 13 | class Texture2D; 14 | class GLProgram; 15 | } 16 | 17 | struct GlyphInfo { 18 | float advance; 19 | float offsetX; 20 | float offsetY; 21 | char width; 22 | char height; 23 | unsigned short index; 24 | }; 25 | 26 | class OSFont { 27 | friend class CCFlashFontHandler; 28 | 29 | typedef const void* Handle; 30 | typedef LRUCache GlyphCache; 31 | 32 | GlyphCache *_cache; 33 | cocos2d::Texture2D *_bitmap; 34 | Handle _font; 35 | float _size; 36 | 37 | public: 38 | OSFont(const char *font_name, float fontsize, int style); 39 | ~OSFont(); 40 | 41 | GlyphInfo* getGlyph(wchar_t code); 42 | float getLineHeight(void) { return getLineHeight(_font); } 43 | float getSize(void) const { return _size;} 44 | 45 | protected: 46 | // platform-dependent 47 | static bool initialize(void); 48 | static void terminate(void); 49 | static Handle create(const char *font_name, float fontsize, int style); 50 | static void destroy(const Handle& font); 51 | static bool makeGlyph(const Handle& font, wchar_t codepoint, GlyphInfo& entry); 52 | static float getLineHeight(const Handle& font); 53 | static void* getGlyphBitmap(); 54 | }; 55 | 56 | //----------------------------------------------------------------------------- 57 | 58 | class CCFlashFontHandler : public tinyswf::FontHandler { 59 | typedef std::map CacheData; 60 | 61 | CacheData _font_cache; 62 | OSFont* _selectedFont; 63 | float _scale; 64 | float _areaHeight; 65 | 66 | cocos2d::GLProgram *_fontShader; 67 | int _uvScaleLocation; 68 | int _colorLocation; 69 | 70 | cocos2d::GLProgram *_fontShader_Shadow; 71 | int _uvScale_Shadow; 72 | int _uvOffset_Shadow; 73 | int _fonstColor_Shadow; 74 | int _shadowColor_Shadow; 75 | 76 | OSFont* selectFont(const char *font_name, float fontsize, int style); 77 | 78 | public: 79 | CCFlashFontHandler(); 80 | 81 | virtual ~CCFlashFontHandler(); 82 | 83 | float getAreaHeight(void) { return _areaHeight; } 84 | 85 | void drawText(const tinyswf::VertexArray& vertices, uint32_t glyphs, const tinyswf::CXFORM& cxform, const tinyswf::TextStyle& style); 86 | 87 | uint32_t formatText(tinyswf::VertexArray& vertices, float &lastX, float &lastY, 88 | const tinyswf::RECT& rect, const tinyswf::TextStyle& style, const std::wstring& text); 89 | 90 | GlyphInfo* getGlyph(wchar_t codepoint) { 91 | return _selectedFont->getGlyph(codepoint); 92 | } 93 | 94 | float getLineHeight(void) { 95 | return _selectedFont->getLineHeight(); 96 | } 97 | }; 98 | 99 | 100 | #endif//__FONT_CACHE_H__ -------------------------------------------------------------------------------- /cocos2d_swf/Classes/FontCache.mm: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #import 6 | #import 7 | #import 8 | #import 9 | #import "FontCache.h" 10 | 11 | bool isValidFontName(const char *fontName) { 12 | bool ret = false; 13 | 14 | NSString *fontNameNS = [NSString stringWithUTF8String:fontName]; 15 | for (NSString *familiName in [UIFont familyNames]) { 16 | //NSLog(@"font-family:%@", familiName); 17 | if ([familiName isEqualToString:fontNameNS]) { 18 | ret = true; 19 | goto out; 20 | } 21 | 22 | for (NSString *font in [UIFont fontNamesForFamilyName: familiName]) { 23 | //NSLog(@"font:%@", font); 24 | if ([font isEqualToString: fontNameNS]) { 25 | ret = true; 26 | goto out; 27 | } 28 | } 29 | } 30 | out: 31 | return ret; 32 | } 33 | 34 | static CGContextRef spContext; 35 | 36 | static char *spBitmapBuffer = NULL; 37 | 38 | struct SYSFONT { 39 | CTFontRef hFont; 40 | float ascent; 41 | float descent; 42 | float line_height; 43 | }; 44 | 45 | bool OSFont::initialize(void) { 46 | spBitmapBuffer = new char[kGLYPH_WIDTH * kGLYPH_WIDTH]; 47 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); 48 | spContext = CGBitmapContextCreate(spBitmapBuffer, kGLYPH_WIDTH, kGLYPH_WIDTH, 8, kGLYPH_WIDTH, colorSpace, kCGBitmapByteOrderDefault); 49 | CGColorSpaceRelease(colorSpace); 50 | if (spContext) { 51 | CGContextSetRGBFillColor(spContext, 1, 1, 1, 1); 52 | return true; 53 | } 54 | return false; 55 | } 56 | 57 | OSFont::Handle OSFont::create(const char *font_name, float fontsize, int style) { 58 | //CCLOG("create OS Font: %s", font_name); 59 | if (! isValidFontName(font_name)) { 60 | font_name = "HiraKakuProN-W6"; 61 | } 62 | //CGFontRef cgfont = CGFontCreateWithFontName (CFSTR("Helvetica")); 63 | //CTFontRef ctFont = CTFontCreateWithGraphicsFont(cgfont, 24,NULL); 64 | CFStringRef name = CFStringCreateWithCString (NULL, font_name, kCFStringEncodingUTF8); 65 | CTFontRef hFont = CTFontCreateWithName(name, fontsize, NULL); 66 | CFRelease(name); 67 | 68 | if (hFont) { 69 | SYSFONT *font = new SYSFONT; 70 | font->hFont = hFont; 71 | font->ascent = CTFontGetAscent(hFont); 72 | font->descent = CTFontGetDescent(hFont); 73 | font->line_height = font->ascent + font->descent + CTFontGetLeading(hFont); 74 | font->ascent += CTFontGetLeading(hFont) * 0.5f; 75 | return font; 76 | } 77 | return NULL; 78 | } 79 | 80 | void OSFont::destroy(const Handle& handle) { 81 | SYSFONT *font = (SYSFONT*)handle; 82 | //CGFontRelease( (CGFontRef) font ); 83 | CFRelease(font->hFont); 84 | delete font; 85 | } 86 | 87 | void OSFont::terminate(void) { 88 | CGContextRelease(spContext); 89 | delete [] spBitmapBuffer; 90 | spContext = NULL; 91 | spBitmapBuffer = NULL; 92 | } 93 | 94 | bool OSFont::makeGlyph(const Handle& handle, wchar_t codepoint, GlyphInfo& entry) { 95 | SYSFONT *font = (SYSFONT*)handle; 96 | UniChar characters[] = { (UniChar)codepoint }; 97 | CGGlyph glyphs[] = {0}; 98 | CGPoint positions[] = { CGPointMake(0, 0) }; 99 | CGRect rects[1]; 100 | 101 | // convert unicode to glyphs 102 | CTFontGetGlyphsForCharacters(font->hFont, characters, glyphs, 1); 103 | if (0 == glyphs[0]) 104 | return false; 105 | 106 | CTFontGetBoundingRectsForGlyphs(font->hFont, kCTFontOrientationHorizontal, glyphs, rects, 1); 107 | double adv = CTFontGetAdvancesForGlyphs(font->hFont, kCTFontOrientationHorizontal, glyphs, NULL, 1); 108 | 109 | // offset glyph from bottom left to top left 110 | positions[0].x = - rects->origin.x; 111 | positions[0].y = (kGLYPH_WIDTH - rects->size.height) - rects->origin.y; 112 | 113 | entry.advance = (adv); 114 | entry.offsetX = (rects->origin.x); 115 | entry.offsetY = (font->ascent - rects->size.height) - rects->origin.y; 116 | 117 | entry.width = (char)ceilf(rects->size.width)+4; 118 | entry.height = (char)ceilf(rects->size.height)+4; 119 | //entry.height = kGLYPH_WIDTH; 120 | 121 | //CGContextTranslateCTM(spContext, 0.0f, kCHAR_GRID_MAX); 122 | //CGContextScaleCTM(spContext, 1.0f, -1.0f); 123 | //NOTE: NSString draws in UIKit referential i.e. renders upside-down compared to CGBitmapContext referential 124 | UIGraphicsPushContext(spContext); 125 | CGContextClearRect (spContext, CGRectMake(0,0, kGLYPH_WIDTH, kGLYPH_WIDTH) ); 126 | CTFontDrawGlyphs( font->hFont, glyphs, positions, 1, spContext ); 127 | #if 0 128 | const int i = kGLYPH_WIDTH -1; 129 | CGContextFillRect(spContext, CGRectMake(0,i,i,1)); 130 | CGContextFillRect(spContext, CGRectMake(0,0,i,1)); 131 | #endif 132 | CGContextFlush(spContext); 133 | UIGraphicsPopContext(); 134 | return true; 135 | } 136 | 137 | float OSFont::getLineHeight(const Handle& handle) { 138 | SYSFONT *sysfont = (SYSFONT*)handle; 139 | return sysfont->line_height; 140 | } 141 | 142 | void* OSFont::getGlyphBitmap() { 143 | return spBitmapBuffer; 144 | } 145 | 146 | -------------------------------------------------------------------------------- /cocos2d_swf/Classes/FontCache_win32.cpp: -------------------------------------------------------------------------------- 1 | #ifdef WIN32 2 | 3 | #include "FontCache.h" 4 | #include "cocos2d.h" 5 | 6 | //#define USE_STB_TRUETYPE 1 7 | 8 | #ifdef USE_STB_TRUETYPE 9 | #define STBTT_malloc(x,u) malloc(x) 10 | #define STBTT_free(x,u) free(x) 11 | #define STB_TRUETYPE_IMPLEMENTATION 12 | #include "stb_truetype.h" 13 | #endif 14 | 15 | using namespace cocos2d; 16 | using namespace tinyswf; 17 | 18 | static HDC ghDC; 19 | 20 | static unsigned char *spSTBTT_BITMAP = NULL; 21 | const int kSize = kGLYPH_WIDTH * kGLYPH_WIDTH; 22 | 23 | struct SYSFONT { 24 | #ifdef USE_STB_TRUETYPE 25 | stbtt_fontinfo info; 26 | float scale; 27 | #endif 28 | float ascent; 29 | float descent; 30 | float line_height; 31 | float extra; 32 | HFONT hFont; 33 | }; 34 | 35 | bool OSFont::initialize(void) { 36 | spSTBTT_BITMAP = new unsigned char[kSize*2]; 37 | HDC hdc = GetDC(NULL); 38 | ghDC = CreateCompatibleDC(hdc); 39 | ReleaseDC(NULL, hdc); 40 | return true; 41 | } 42 | 43 | enum FONT_STYLE { 44 | FLAG_ITALIC = 0x02, 45 | FLAG_BOLD = 0x01 46 | }; 47 | 48 | inline FIXED FixedFromFloat(float d) { 49 | long l = (long) (d * 65536L); 50 | return *(FIXED *)&l; 51 | } 52 | inline void SetMat(LPMAT2 lpMat) { 53 | lpMat->eM11 = FixedFromFloat(1); 54 | lpMat->eM12 = FixedFromFloat(0); 55 | lpMat->eM21 = FixedFromFloat(0); 56 | lpMat->eM22 = FixedFromFloat(1); 57 | } 58 | 59 | OSFont::Handle OSFont::create(const char *fontname, float fontsize, int style) { 60 | SYSFONT *font = new SYSFONT; 61 | float height = fontsize * GetDeviceCaps(ghDC, LOGPIXELSY) / 72.f; 62 | 63 | bool bItalic = (FLAG_ITALIC & style) > 0; 64 | int weight = FW_NORMAL; 65 | if (FLAG_BOLD & style) { 66 | weight = FW_BOLD; 67 | } 68 | 69 | font->hFont = CreateFont((int)height, 0, 0, 0, 70 | weight, bItalic, FALSE, FALSE, 71 | DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, 72 | fontname); 73 | SelectObject(ghDC, font->hFont); 74 | TEXTMETRIC metric; 75 | GetTextMetrics(ghDC, &metric); 76 | 77 | font->ascent = (float)metric.tmAscent; 78 | font->descent = (float)metric.tmDescent; 79 | font->line_height = float(metric.tmHeight + metric.tmExternalLeading); 80 | font->extra = float(metric.tmExternalLeading/2); 81 | return font; 82 | 83 | #ifdef USE_STB_TRUETYPE 84 | DWORD tag = 0x66637474;//ttcf 85 | int size = GetFontData(ghDC, tag, 0, NULL, 0); 86 | if (-1 == size) { 87 | tag = 0; 88 | size = GetFontData(ghDC, tag, 0, NULL, 0); 89 | } 90 | void *pData = new char[size]; 91 | GetFontData(ghDC, tag, 0, pData, size); 92 | DeleteObject(hFont); 93 | 94 | int start = stbtt_GetFontOffsetForIndex( (const unsigned char *)pData, 0); 95 | if (0 != tag) { 96 | start = stbtt_FindMatchingFont((const unsigned char *)pData, fontname, STBTT_MACSTYLE_DONTCARE); 97 | } 98 | CCASSERT(0 <= start, "no such font!"); 99 | if (stbtt_InitFont(&font->info, (const unsigned char *)pData, start)) { 100 | // Store normalized line height. The real line height is got by multiplying the lineh by font size. 101 | int ascent, descent, lineGap; 102 | stbtt_GetFontVMetrics(&font->info, &ascent, &descent, &lineGap); 103 | //fh = ascent - descent; 104 | //fnt->ascender = (float)ascent / (float)fh; 105 | //fnt->descender = (float)descent / (float)fh; 106 | //fnt->lineh = (float)(fh + lineGap) / (float)fh; 107 | float scale = stbtt_ScaleForPixelHeight(&font->info, height); 108 | font->ascent = ascent * scale; 109 | font->descent = descent * scale; 110 | font->line_height = (ascent - descent + lineGap) * scale; 111 | font->scale = scale; 112 | return font; 113 | } 114 | delete font; 115 | #endif 116 | return NULL; 117 | } 118 | 119 | void OSFont::destroy(const Handle& handle) { 120 | SYSFONT *font = (SYSFONT*)handle; 121 | #ifdef USE_STB_TRUETYPE 122 | //delete [] font->info.data; 123 | #else 124 | DeleteObject(font->hFont); 125 | #endif 126 | delete font; 127 | font = NULL; 128 | } 129 | 130 | void OSFont::terminate(void) { 131 | delete [] spSTBTT_BITMAP; 132 | spSTBTT_BITMAP = NULL; 133 | DeleteDC(ghDC); 134 | } 135 | 136 | void* OSFont::getGlyphBitmap() { return spSTBTT_BITMAP; } 137 | 138 | float OSFont::getLineHeight(const Handle& handle) { 139 | SYSFONT *sysfont = (SYSFONT*)handle; 140 | return sysfont->line_height; 141 | } 142 | 143 | bool OSFont::makeGlyph(const Handle& handle, wchar_t codepoint, GlyphInfo& entry) { 144 | #ifdef USE_STB_TRUETYPE 145 | SYSFONT *sysfont = (SYSFONT*)handle; 146 | stbtt_fontinfo *font = &sysfont->info; 147 | int advance, lsb, x0, y0, x1, y1; 148 | int glyph = stbtt_FindGlyphIndex(font, codepoint); 149 | if (0 >= glyph) 150 | return false; 151 | 152 | float scale = sysfont->scale; 153 | 154 | stbtt_GetGlyphHMetrics(font, glyph, &advance, &lsb); 155 | stbtt_GetGlyphBitmapBox(font, glyph, scale, scale, &x0,&y0,&x1,&y1); 156 | 157 | int width = x1 - x0 +1; 158 | int height = y1 - y0+1; 159 | entry.advance = advance * scale; 160 | entry.offsetX = float(x0); 161 | entry.offsetY = sysfont->ascent + y0; 162 | entry.width = width; 163 | entry.height = height; 164 | 165 | memset(spSTBTT_BITMAP, 0, kGLYPH_WIDTH * kGLYPH_WIDTH); 166 | stbtt_MakeGlyphBitmap(font, spSTBTT_BITMAP, kGLYPH_WIDTH, kGLYPH_WIDTH, kGLYPH_WIDTH, scale, scale, glyph); 167 | 168 | #else 169 | memset(spSTBTT_BITMAP, 0, kSize); 170 | 171 | SYSFONT *sysfont = (SYSFONT*)handle; 172 | SelectObject(ghDC, sysfont->hFont); 173 | 174 | MAT2 mat2; 175 | SetMat(&mat2); 176 | GLYPHMETRICS gm; 177 | DWORD dwNeedSize = GetGlyphOutlineW(ghDC, codepoint, GGO_GRAY8_BITMAP, &gm, 0, NULL, &mat2); 178 | 179 | CCASSERT(dwNeedSize <= kSize, "exceed buffer"); 180 | BYTE *dst = spSTBTT_BITMAP+1; 181 | BYTE *src = spSTBTT_BITMAP + kSize; 182 | GetGlyphOutlineW(ghDC, codepoint, GGO_GRAY8_BITMAP, &gm, dwNeedSize, src, &mat2); 183 | 184 | int bytesPerRow = dwNeedSize / gm.gmBlackBoxY; 185 | for (UINT y = 0; y < gm.gmBlackBoxY; ++y) { 186 | for (int x = 0; x < bytesPerRow; ++x) { 187 | int value = src[x] * 4; 188 | dst[x] = (0xff < value) ? 0xff : value; 189 | } 190 | src += bytesPerRow; 191 | dst += kGLYPH_WIDTH; 192 | } 193 | 194 | entry.advance = (float)gm.gmCellIncX; 195 | entry.offsetX = (float)gm.gmptGlyphOrigin.x; 196 | entry.offsetY = sysfont->ascent - gm.gmptGlyphOrigin.y + sysfont->extra; 197 | entry.width = gm.gmBlackBoxX+4; 198 | entry.height = gm.gmBlackBoxY+4; 199 | //entry.width = kGLYPH_WIDTH; 200 | //entry.height = kGLYPH_WIDTH; 201 | 202 | #endif 203 | #if 0 204 | const int offset = kSize - kGLYPH_WIDTH; 205 | for(int i = 0; i < kGLYPH_WIDTH; ++i) { 206 | spSTBTT_BITMAP[i]=255; 207 | spSTBTT_BITMAP[i+offset]=255; 208 | } 209 | #endif 210 | return true; 211 | } 212 | 213 | #endif//WIN32 -------------------------------------------------------------------------------- /cocos2d_swf/Classes/HelloWorldScene.h: -------------------------------------------------------------------------------- 1 | #ifndef __HELLOWORLD_SCENE_H__ 2 | #define __HELLOWORLD_SCENE_H__ 3 | 4 | #include "cocos2d.h" 5 | 6 | #ifdef USE_HTTP 7 | #include "network/HttpResponse.h" 8 | #include "network/HttpClient.h" 9 | #endif 10 | 11 | class HelloWorld : public cocos2d::Layer 12 | { 13 | public: 14 | virtual ~HelloWorld(); 15 | 16 | // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone 17 | virtual bool init(); 18 | 19 | // there's no 'id' in cpp, so we recommend returning the class instance pointer 20 | static cocos2d::Scene* scene(); 21 | 22 | // a selector callback 23 | void menuCloseCallback(cocos2d::Object* pSender); 24 | 25 | #ifdef USE_HTTP 26 | //Http Response Callback 27 | void onHttpRequestCompleted(cocos2d::extension::HttpClient *sender, cocos2d::extension::HttpResponse *response); 28 | #endif 29 | 30 | // implement the "static node()" method manually 31 | CREATE_FUNC(HelloWorld); 32 | }; 33 | 34 | #endif // __HELLOWORLD_SCENE_H__ 35 | -------------------------------------------------------------------------------- /cocos2d_swf/Classes/lru_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef __LRU__CACHE_H__ 2 | #define __LRU__CACHE_H__ 3 | 4 | #include 5 | #include 6 | 7 | template 8 | struct LRUCacheEntry { 9 | K key; 10 | T data; 11 | LRUCacheEntry* prev; 12 | LRUCacheEntry* next; 13 | }; 14 | 15 | template 16 | class LRUCache { 17 | private: 18 | std::map< K, LRUCacheEntry* > _mapping; 19 | std::vector< LRUCacheEntry* > _freeEntries; 20 | LRUCacheEntry * head; 21 | LRUCacheEntry * tail; 22 | LRUCacheEntry * entries; 23 | 24 | public: 25 | LRUCache(int size) { 26 | _freeEntries.reserve(size); 27 | entries = new LRUCacheEntry[size]; 28 | for (int i=0; i; 31 | tail = new LRUCacheEntry; 32 | head->prev = NULL; 33 | head->next = tail; 34 | tail->next = NULL; 35 | tail->prev = head; 36 | } 37 | 38 | ~LRUCache() { 39 | delete head; 40 | delete tail; 41 | delete [] entries; 42 | } 43 | 44 | T& insert(K key, T data) { 45 | LRUCacheEntry* node = _mapping[key]; 46 | if (node) { 47 | // refresh the link list 48 | detach(node); 49 | node->data = data; 50 | attach(node); 51 | } else { 52 | if ( _freeEntries.empty() ) { 53 | node = tail->prev; 54 | detach(node); 55 | _mapping.erase(node->key); 56 | node->key = key; 57 | node->data = data; 58 | _mapping[key] = node; 59 | attach(node); 60 | } else { 61 | node = _freeEntries.back(); 62 | _freeEntries.pop_back(); 63 | node->key = key; 64 | node->data = data; 65 | _mapping[key] = node; 66 | attach(node); 67 | } 68 | } 69 | return node->data; 70 | } 71 | 72 | T* fetch_ptr(K key) { 73 | LRUCacheEntry* node = _mapping[key]; 74 | if (node) { 75 | detach(node); 76 | attach(node); 77 | return &node->data; 78 | } 79 | return NULL; 80 | } 81 | 82 | int size(void) const { 83 | return _freeEntries.capacity() - _freeEntries.size(); 84 | } 85 | 86 | bool full(void) const { 87 | return _freeEntries.empty(); 88 | } 89 | 90 | T& getLRU(void) { 91 | return tail->prev->data; 92 | } 93 | 94 | std::map< K, LRUCacheEntry* > getMaptable() { 95 | return _mapping; 96 | } 97 | 98 | private: 99 | void detach(LRUCacheEntry* node) { 100 | node->prev->next = node->next; 101 | node->next->prev = node->prev; 102 | } 103 | 104 | void attach(LRUCacheEntry* node) { 105 | node->next = head->next; 106 | node->prev = head; 107 | head->next = node; 108 | node->next->prev = node; 109 | } 110 | }; 111 | 112 | #endif//lru_cache -------------------------------------------------------------------------------- /cocos2d_swf/Resources/CloseNormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/CloseNormal.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/CloseSelected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/CloseSelected.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/HelloWorld.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/fonts/Marker Felt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/fonts/Marker Felt.ttf -------------------------------------------------------------------------------- /cocos2d_swf/Resources/ipad/CloseNormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/ipad/CloseNormal.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/ipad/CloseSelected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/ipad/CloseSelected.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/ipad/HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/ipad/HelloWorld.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/ipadhd/CloseNormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/ipadhd/CloseNormal.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/ipadhd/CloseSelected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/ipadhd/CloseSelected.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/ipadhd/HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/ipadhd/HelloWorld.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/iphone/CloseNormal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/iphone/CloseNormal.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/iphone/CloseSelected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/iphone/CloseSelected.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/iphone/HelloWorld.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/iphone/HelloWorld.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/orangerec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/orangerec.png -------------------------------------------------------------------------------- /cocos2d_swf/Resources/test.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/test.fla -------------------------------------------------------------------------------- /cocos2d_swf/Resources/test.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/test.swf -------------------------------------------------------------------------------- /cocos2d_swf/Resources/test.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/test.wav -------------------------------------------------------------------------------- /cocos2d_swf/Resources/test2.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/test2.fla -------------------------------------------------------------------------------- /cocos2d_swf/Resources/test2.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/Resources/test2.swf -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/AppController.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2010 cocos2d-x.org 3 | 4 | http://www.cocos2d-x.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | ****************************************************************************/ 24 | 25 | @class RootViewController; 26 | 27 | @interface AppController : NSObject { 28 | UIWindow *window; 29 | RootViewController *viewController; 30 | } 31 | 32 | @end 33 | 34 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/AppController.mm: -------------------------------------------------------------------------------- 1 | #import "AppController.h" 2 | #import "EAGLView.h" 3 | #import "cocos2d.h" 4 | #import "AppDelegate.h" 5 | #import "RootViewController.h" 6 | 7 | @implementation AppController 8 | 9 | #pragma mark - 10 | #pragma mark Application lifecycle 11 | 12 | // cocos2d application instance 13 | static AppDelegate s_sharedApplication; 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 16 | 17 | // Override point for customization after application launch. 18 | 19 | // Add the view controller's view to the window and display. 20 | window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 21 | 22 | // Init the EAGLView 23 | CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds] 24 | pixelFormat: kEAGLColorFormatRGB565 25 | depthFormat: GL_DEPTH24_STENCIL8_OES 26 | preserveBackbuffer: NO 27 | sharegroup: nil 28 | multiSampling: NO 29 | numberOfSamples: 0]; 30 | 31 | // Use RootViewController manage EAGLView 32 | viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; 33 | viewController.wantsFullScreenLayout = YES; 34 | viewController.view = __glView; 35 | 36 | // Set RootViewController to window 37 | if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) 38 | { 39 | // warning: addSubView doesn't work on iOS6 40 | [window addSubview: viewController.view]; 41 | } 42 | else 43 | { 44 | // use this method on ios6 45 | [window setRootViewController:viewController]; 46 | } 47 | 48 | [window makeKeyAndVisible]; 49 | 50 | [[UIApplication sharedApplication] setStatusBarHidden:true]; 51 | 52 | cocos2d::Application::getInstance()->run(); 53 | 54 | return YES; 55 | } 56 | 57 | 58 | - (void)applicationWillResignActive:(UIApplication *)application { 59 | /* 60 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 61 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 62 | */ 63 | cocos2d::Director::getInstance()->pause(); 64 | } 65 | 66 | - (void)applicationDidBecomeActive:(UIApplication *)application { 67 | /* 68 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 69 | */ 70 | cocos2d::Director::getInstance()->resume(); 71 | } 72 | 73 | - (void)applicationDidEnterBackground:(UIApplication *)application { 74 | /* 75 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 76 | If your application supports background execution, called instead of applicationWillTerminate: when the user quits. 77 | */ 78 | cocos2d::Application::getInstance()->applicationDidEnterBackground(); 79 | } 80 | 81 | - (void)applicationWillEnterForeground:(UIApplication *)application { 82 | /* 83 | Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. 84 | */ 85 | cocos2d::Application::getInstance()->applicationWillEnterForeground(); 86 | } 87 | 88 | - (void)applicationWillTerminate:(UIApplication *)application { 89 | /* 90 | Called when the application is about to terminate. 91 | See also applicationDidEnterBackground:. 92 | */ 93 | } 94 | 95 | 96 | #pragma mark - 97 | #pragma mark Memory management 98 | 99 | - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { 100 | /* 101 | Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. 102 | */ 103 | } 104 | 105 | 106 | - (void)dealloc { 107 | [window release]; 108 | [super dealloc]; 109 | } 110 | 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/proj.ios/Default-568h@2x.png -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/proj.ios/Default.png -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/proj.ios/Default@2x.png -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/HelloCpp_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'HelloWorld' target in the 'HelloWorld' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/Icon-114.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/proj.ios/Icon-114.png -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/Icon-144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/proj.ios/Icon-144.png -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/Icon-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/proj.ios/Icon-57.png -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/Icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/cocos2d_swf/proj.ios/Icon-72.png -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | Icon-57.png 13 | CFBundleIconFiles 14 | 15 | Icon.png 16 | Icon@2x.png 17 | Icon-57.png 18 | Icon-114.png 19 | Icon-72.png 20 | Icon-144.png 21 | 22 | CFBundleIdentifier 23 | com.jbyu.cocos2d-swf 24 | CFBundleInfoDictionaryVersion 25 | 6.0 26 | CFBundleName 27 | ${PRODUCT_NAME} 28 | CFBundlePackageType 29 | APPL 30 | CFBundleShortVersionString 31 | 1.0.0 32 | CFBundleSignature 33 | ???? 34 | CFBundleVersion 35 | 1.0 36 | LSRequiresIPhoneOS 37 | 38 | UIAppFonts 39 | 40 | UIStatusBarHidden 41 | 42 | UISupportedInterfaceOrientations 43 | 44 | UIInterfaceOrientationPortrait 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'iphone' target in the 'iphone' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/RootViewController.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2010-2011 cocos2d-x.org 3 | Copyright (c) 2010 Ricardo Quesada 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | #import 27 | 28 | 29 | @interface RootViewController : UIViewController { 30 | 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/RootViewController.mm: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2010-2011 cocos2d-x.org 3 | Copyright (c) 2010 Ricardo Quesada 4 | 5 | http://www.cocos2d-x.org 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | ****************************************************************************/ 25 | 26 | #import "RootViewController.h" 27 | 28 | 29 | @implementation RootViewController 30 | 31 | /* 32 | // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 33 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 34 | if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { 35 | // Custom initialization 36 | } 37 | return self; 38 | } 39 | */ 40 | 41 | /* 42 | // Implement loadView to create a view hierarchy programmatically, without using a nib. 43 | - (void)loadView { 44 | } 45 | */ 46 | 47 | /* 48 | // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 49 | - (void)viewDidLoad { 50 | [super viewDidLoad]; 51 | } 52 | 53 | */ 54 | // Override to allow orientations other than the default portrait orientation. 55 | // This method is deprecated on ios6 56 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 57 | return UIInterfaceOrientationIsLandscape( interfaceOrientation ); 58 | } 59 | 60 | // For ios6.0 and higher, use supportedInterfaceOrientations & shouldAutorotate instead 61 | - (NSUInteger) supportedInterfaceOrientations 62 | { 63 | #ifdef __IPHONE_6_0 64 | return UIInterfaceOrientationMaskAllButUpsideDown; 65 | #endif 66 | } 67 | 68 | - (BOOL) shouldAutorotate { 69 | return YES; 70 | } 71 | 72 | 73 | 74 | 75 | - (void)didReceiveMemoryWarning { 76 | // Releases the view if it doesn't have a superview. 77 | [super didReceiveMemoryWarning]; 78 | 79 | // Release any cached data, images, etc that aren't in use. 80 | } 81 | 82 | - (void)viewDidUnload { 83 | [super viewDidUnload]; 84 | // Release any retained subviews of the main view. 85 | // e.g. self.myOutlet = nil; 86 | } 87 | 88 | 89 | - (void)dealloc { 90 | [super dealloc]; 91 | } 92 | 93 | 94 | @end 95 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.ios/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // iphone 4 | // 5 | // Created by Walzer on 10-11-16. 6 | // Copyright 2010 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.win32/HelloCpp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HelloCpp", "HelloCpp.vcxproj", "{76A39BB2-9B84-4C65-98A5-654D86B86F2A}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {2EF32000-30A4-49E5-84E1-C1ED38931E36} = {2EF32000-30A4-49E5-84E1-C1ED38931E36} 7 | EndProjectSection 8 | EndProject 9 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtinyswf", "..\..\projects\proj.vc11\libtinyswf.vcxproj", "{2EF32000-30A4-49E5-84E1-C1ED38931E36}" 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Win32 = Debug|Win32 14 | Release|Win32 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Win32.ActiveCfg = Debug|Win32 18 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Debug|Win32.Build.0 = Debug|Win32 19 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Win32.ActiveCfg = Release|Win32 20 | {76A39BB2-9B84-4C65-98A5-654D86B86F2A}.Release|Win32.Build.0 = Release|Win32 21 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Debug|Win32.ActiveCfg = Debug|Win32 22 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Debug|Win32.Build.0 = Debug|Win32 23 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Release|Win32.ActiveCfg = Release|Win32 24 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Release|Win32.Build.0 = Release|Win32 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.win32/HelloCpp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {84a8ebd7-7cf0-47f6-b75e-d441df67da40} 6 | 7 | 8 | {bb6c862e-70e9-49d9-81b7-3829a6f50471} 9 | 10 | 11 | 12 | 13 | win32 14 | 15 | 16 | Classes 17 | 18 | 19 | Classes 20 | 21 | 22 | Classes 23 | 24 | 25 | Classes 26 | 27 | 28 | Classes 29 | 30 | 31 | 32 | 33 | win32 34 | 35 | 36 | Classes 37 | 38 | 39 | Classes 40 | 41 | 42 | Classes 43 | 44 | 45 | Classes 46 | 47 | 48 | Classes 49 | 50 | 51 | Classes 52 | 53 | 54 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.win32/PropertySheet.props: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | G:\projects\cocos2d-x 6 | 7 | 8 | <_PropertySheetDisplayName>cocos2d 9 | 10 | 11 | 12 | 13 | $(cocos2d) 14 | true 15 | 16 | 17 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.win32/main.cpp: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include "../Classes/AppDelegate.h" 3 | #include "CCEGLView.h" 4 | 5 | #if _DEBUG 6 | #define _CRTDBG_MAP_ALLOC 7 | #include 8 | #include 9 | //#include 10 | #endif//_DEBUG 11 | 12 | USING_NS_CC; 13 | 14 | int APIENTRY _tWinMain(HINSTANCE hInstance, 15 | HINSTANCE hPrevInstance, 16 | LPTSTR lpCmdLine, 17 | int nCmdShow) 18 | { 19 | UNREFERENCED_PARAMETER(hPrevInstance); 20 | UNREFERENCED_PARAMETER(lpCmdLine); 21 | 22 | // create the application instance 23 | AppDelegate app; 24 | EGLView eglView; 25 | eglView.init("HelloCpp", 640, 960); 26 | //glfwSetWindowPos(eglView.getWindow(), 128, 24); 27 | // The resolution of ipad3 is very large. In general, PC's resolution is smaller than it. 28 | // So we need to invoke 'setFrameZoomFactor'(only valid on desktop(win32, mac, linux)) to make the window smaller. 29 | //eglView->setFrameZoomFactor(0.4f); 30 | return Application::getInstance()->run(); 31 | } 32 | -------------------------------------------------------------------------------- /cocos2d_swf/proj.win32/main.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAIN_H__ 2 | #define __MAIN_H__ 3 | 4 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 5 | 6 | // Windows Header Files: 7 | #include 8 | #include 9 | 10 | // C RunTime Header Files 11 | #include "CCStdC.h" 12 | 13 | #endif // __MAIN_H__ 14 | -------------------------------------------------------------------------------- /include/tinyswf.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #include "tsReader.h" 6 | #include "tsHeader.h" 7 | #include "tsSWF.h" 8 | -------------------------------------------------------------------------------- /include/tsHeader.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __TS_HEADER_H__ 6 | #define __TS_HEADER_H__ 7 | 8 | #include "tsTypes.h" 9 | 10 | namespace tinyswf { 11 | 12 | class Reader; 13 | class Header { 14 | public: 15 | Header() : _outputBuffer(NULL) 16 | {} 17 | 18 | virtual ~Header() { 19 | if ( _outputBuffer ) { 20 | delete [] _outputBuffer; 21 | } 22 | } 23 | 24 | bool read( Reader& reader ); 25 | void print(); 26 | 27 | //The FrameSize RECTalways has Xmin and Ymin value of 0; 28 | /* 29 | float getFrameWidth() const {return (_frame_size.xmax - _frame_size.xmin);} 30 | float getFrameHeight() const {return (_frame_size.ymax - _frame_size.ymin); } 31 | */ 32 | float getFrameWidth() const { return _frame_size.xmax; } 33 | float getFrameHeight()const { return _frame_size.ymax; } 34 | float getFrameRate() const { return _frame_rate; } 35 | uint16_t getFrameCount() const { return _frame_count; } 36 | 37 | private: 38 | uint8_t _signature[3]; 39 | uint8_t _version; 40 | uint32_t _file_length; 41 | RECT _frame_size; 42 | float _frame_rate; 43 | uint16_t _frame_count; 44 | char* _outputBuffer; // used for compressed swf files 45 | }; 46 | 47 | }//namespace 48 | 49 | #endif // __TS_HEADER_H__ 50 | -------------------------------------------------------------------------------- /include/tsReader.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __TS_READER_H__ 6 | #define __TS_READER_H__ 7 | 8 | #include "tsTypes.h" 9 | #include 10 | 11 | namespace tinyswf { 12 | 13 | struct Filter; 14 | 15 | class Reader { 16 | public: 17 | Reader( char* data, int32_t sz ) 18 | : _data( data ) 19 | , _sz( sz ) 20 | , _cur( 0 ) 21 | , _bitpos( 0 ) 22 | {} 23 | 24 | template< class T> T get() { 25 | if( _bitpos > 0 && _bitpos < 8) 26 | _cur++; 27 | _bitpos = 0; 28 | T *ret = (T*)(_data + _cur); 29 | _cur += sizeof( T ); 30 | return *ret; 31 | } 32 | 33 | inline void skip( int32_t bytes ) { 34 | _cur += bytes; 35 | _bitpos = 0; 36 | } 37 | 38 | inline void align() { 39 | if( _bitpos > 0 && _bitpos < 8) 40 | _cur++; 41 | _bitpos = 0; 42 | } 43 | 44 | inline uint32_t getbit() { 45 | uint32_t v = (_data[_cur] >> (7 - _bitpos++)) & 1; 46 | if( _bitpos == 8 ) 47 | get(); 48 | return v; 49 | } 50 | 51 | inline uint32_t getbits( uint32_t nbits ) { 52 | uint32_t val = 0; 53 | for( uint32_t t = 0; t < nbits; t++ ) 54 | { 55 | val <<= 1; 56 | val |= getbit(); 57 | } 58 | return val; 59 | } 60 | 61 | inline int32_t getsignedbits( uint32_t nbits ) { 62 | uint32_t res = getbits( nbits ); 63 | if ( res & ( 1 << ( nbits - 1 ) ) ) 64 | res |= (0xffffffff << nbits); 65 | 66 | return (int32_t)res; 67 | } 68 | 69 | inline void getRectangle( RECT& rect ) { 70 | const uint32_t nbits = getbits( 5 ); 71 | rect.xmin = getsignedbits( nbits ) * SWF_INV_TWIPS; 72 | rect.xmax = getsignedbits( nbits ) * SWF_INV_TWIPS; 73 | rect.ymin = getsignedbits( nbits ) * SWF_INV_TWIPS; 74 | rect.ymax = getsignedbits( nbits ) * SWF_INV_TWIPS; 75 | } 76 | 77 | inline void getMatrix( MATRIX& m ) { 78 | int32_t nbits; 79 | if ( getbits( 1 ) ) { // has scale 80 | nbits = getbits( 5 ); 81 | m.sx = (float)getsignedbits( nbits )*SWF_INV_MATRIX; 82 | m.sy = (float)getsignedbits( nbits )*SWF_INV_MATRIX; 83 | } else { 84 | m.sx = m.sy = 1.0f; 85 | } 86 | 87 | if ( getbits( 1 ) ) { // has rotation 88 | nbits = getbits( 5 ); 89 | m.r0 = (float)getsignedbits( nbits )*SWF_INV_MATRIX; 90 | m.r1 = (float)getsignedbits( nbits )*SWF_INV_MATRIX; 91 | } else { 92 | m.r0 = m.r1 = 0.0f; 93 | } 94 | 95 | nbits = getbits( 5 ); 96 | m.tx = getsignedbits( nbits ) * SWF_INV_TWIPS; 97 | m.ty = getsignedbits( nbits ) * SWF_INV_TWIPS; 98 | } 99 | 100 | inline void getColor( COLOR4f& color, uint32_t nbits ) { 101 | color.r = getsignedbits( nbits ) * SWF_INV_CXFORM; 102 | color.g = getsignedbits( nbits ) * SWF_INV_CXFORM; 103 | color.b = getsignedbits( nbits ) * SWF_INV_CXFORM; 104 | color.a = getsignedbits( nbits ) * SWF_INV_CXFORM; 105 | } 106 | 107 | inline void getRGBA( RGBA& color ) { 108 | color.r = get(); 109 | color.g = get(); 110 | color.b = get(); 111 | color.a = get(); 112 | } 113 | 114 | inline void getCXForm( CXFORM& cx ) { 115 | const uint32_t has_add_terms = getbits( 1 ); 116 | const uint32_t has_mult_terms = getbits( 1 ); 117 | const uint32_t nbits = getbits( 4 ); 118 | if( has_mult_terms ) { 119 | getColor( cx.mult, nbits); 120 | } else { 121 | COLOR4f color = {1.f,1.f,1.f,1.f}; 122 | cx.mult = color; 123 | } 124 | if( has_add_terms ) { 125 | getColor( cx.add, nbits); 126 | } else { 127 | COLOR4f color = {0.f,0.f,0.f,0.f}; 128 | cx.add = color; 129 | } 130 | } 131 | 132 | inline int32_t getCurrentPos() const { 133 | return _cur; 134 | } 135 | 136 | inline uint8_t getBitPos() const { 137 | return _bitpos; 138 | } 139 | 140 | int32_t getBytes( int32_t s, uint8_t* b ) { 141 | if ( _cur + s > _sz ) { 142 | s = _sz - _cur; 143 | if ( s == 0 ) { 144 | return 0; 145 | } 146 | } 147 | memcpy( b, &_data[_cur], s ); 148 | _cur += s; 149 | return s; 150 | } 151 | 152 | void setNewData( char* data, int32_t sz ) { 153 | _data = data; 154 | _sz = sz; 155 | _cur = 0; 156 | _bitpos = 0; 157 | } 158 | 159 | inline const char* getString() { 160 | const char *src = (const char *)&_data[_cur]; 161 | size_t len = strlen(src) + 1; 162 | _cur += len; 163 | return src; 164 | /* 165 | char *dst = new char[len]; 166 | strcpy(dst, src); 167 | return( dst ); 168 | */ 169 | } 170 | 171 | void getFilterList(Filter& dropShadow); 172 | 173 | float getFIXED(); 174 | 175 | float getFIXED8(); 176 | 177 | const char *getData() const { return _data + _cur; } 178 | 179 | private: 180 | char* _data; 181 | int32_t _sz; // total size of the buffer 182 | int32_t _cur; // current ptr/idx into buffer 183 | uint8_t _bitpos; // for reading bits 184 | }; 185 | 186 | // template<> char Reader::get(); 187 | }//namespace 188 | 189 | #endif // __TS_READER_H__ -------------------------------------------------------------------------------- /libtess2/LICENSE.txt: -------------------------------------------------------------------------------- 1 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 2 | ** Copyright (C) [dates of first publication] Silicon Graphics, Inc. 3 | ** All Rights Reserved. 4 | ** 5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ** of this software and associated documentation files (the "Software"), to deal 7 | ** in the Software without restriction, including without limitation the rights 8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | ** of the Software, and to permit persons to whom the Software is furnished to do so, 10 | ** subject to the following conditions: 11 | ** 12 | ** The above copyright notice including the dates of first publication and either this 13 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be 14 | ** included in all copies or substantial portions of the Software. 15 | ** 16 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 17 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 18 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. 19 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 20 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 21 | ** OR OTHER DEALINGS IN THE SOFTWARE. 22 | ** 23 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not 24 | ** be used in advertising or otherwise to promote the sale, use or other dealings in 25 | ** this Software without prior written authorization from Silicon Graphics, Inc. 26 | -------------------------------------------------------------------------------- /libtess2/bucketalloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 | ** Copyright (C) [dates of first publication] Silicon Graphics, Inc. 4 | ** All Rights Reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 7 | ** of this software and associated documentation files (the "Software"), to deal 8 | ** in the Software without restriction, including without limitation the rights 9 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | ** of the Software, and to permit persons to whom the Software is furnished to do so, 11 | ** subject to the following conditions: 12 | ** 13 | ** The above copyright notice including the dates of first publication and either this 14 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. 20 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 22 | ** OR OTHER DEALINGS IN THE SOFTWARE. 23 | ** 24 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not 25 | ** be used in advertising or otherwise to promote the sale, use or other dealings in 26 | ** this Software without prior written authorization from Silicon Graphics, Inc. 27 | */ 28 | /* 29 | ** Author: Mikko Mononen, July 2009. 30 | */ 31 | 32 | #include 33 | #include 34 | #include "tesselator.h" 35 | 36 | //#define CHECK_BOUNDS 37 | 38 | typedef struct BucketAlloc BucketAlloc; 39 | typedef struct Bucket Bucket; 40 | 41 | struct Bucket 42 | { 43 | Bucket *next; 44 | }; 45 | 46 | struct BucketAlloc 47 | { 48 | void *freelist; 49 | Bucket *buckets; 50 | unsigned int itemSize; 51 | unsigned int bucketSize; 52 | const char *name; 53 | TESSalloc* alloc; 54 | }; 55 | 56 | static int CreateBucket( struct BucketAlloc* ba ) 57 | { 58 | size_t size; 59 | Bucket* bucket; 60 | void* freelist; 61 | unsigned char* head; 62 | unsigned char* it; 63 | 64 | // Allocate memory for the bucket 65 | size = sizeof(Bucket) + ba->itemSize * ba->bucketSize; 66 | bucket = (Bucket*)ba->alloc->memalloc( ba->alloc->userData, size ); 67 | if ( !bucket ) 68 | return 0; 69 | bucket->next = 0; 70 | 71 | // Add the bucket into the list of buckets. 72 | bucket->next = ba->buckets; 73 | ba->buckets = bucket; 74 | 75 | // Add new items to the free list. 76 | freelist = ba->freelist; 77 | head = (unsigned char*)bucket + sizeof(Bucket); 78 | it = head + ba->itemSize * ba->bucketSize; 79 | do 80 | { 81 | it -= ba->itemSize; 82 | // Store pointer to next free item. 83 | *((void**)it) = freelist; 84 | // Pointer to next location containing a free item. 85 | freelist = (void*)it; 86 | } 87 | while ( it != head ); 88 | // Update pointer to next location containing a free item. 89 | ba->freelist = (void*)it; 90 | 91 | return 1; 92 | } 93 | 94 | static void *NextFreeItem( struct BucketAlloc *ba ) 95 | { 96 | return *(void**)ba->freelist; 97 | } 98 | 99 | struct BucketAlloc* createBucketAlloc( TESSalloc* alloc, const char* name, 100 | unsigned int itemSize, unsigned int bucketSize ) 101 | { 102 | BucketAlloc* ba = (BucketAlloc*)alloc->memalloc( alloc->userData, sizeof(BucketAlloc) ); 103 | 104 | ba->alloc = alloc; 105 | ba->name = name; 106 | ba->itemSize = itemSize; 107 | if ( ba->itemSize < sizeof(void*) ) 108 | ba->itemSize = sizeof(void*); 109 | ba->bucketSize = bucketSize; 110 | ba->freelist = 0; 111 | ba->buckets = 0; 112 | 113 | if ( !CreateBucket( ba ) ) 114 | { 115 | alloc->memfree( alloc->userData, ba ); 116 | return 0; 117 | } 118 | 119 | return ba; 120 | } 121 | 122 | void* bucketAlloc( struct BucketAlloc *ba ) 123 | { 124 | void *it; 125 | 126 | // If running out of memory, allocate new bucket and update the freelist. 127 | if ( !ba->freelist || !NextFreeItem( ba ) ) 128 | { 129 | if ( !CreateBucket( ba ) ) 130 | return 0; 131 | } 132 | 133 | // Pop item from in front of the free list. 134 | it = ba->freelist; 135 | ba->freelist = NextFreeItem( ba ); 136 | 137 | return it; 138 | } 139 | 140 | void bucketFree( struct BucketAlloc *ba, void *ptr ) 141 | { 142 | #ifdef CHECK_BOUNDS 143 | int inBounds = 0; 144 | Bucket *bucket; 145 | 146 | // Check that the pointer is allocated with this allocator. 147 | bucket = ba->buckets; 148 | while ( bucket ) 149 | { 150 | void *bucketMin = (void*)((unsigned char*)bucket + sizeof(Bucket)); 151 | void *bucketMax = (void*)((unsigned char*)bucket + sizeof(Bucket) + ba->itemSize * ba->bucketSize); 152 | if ( ptr >= bucketMin && ptr < bucketMax ) 153 | { 154 | inBounds = 1; 155 | break; 156 | } 157 | bucket = bucket->next; 158 | } 159 | 160 | if ( inBounds ) 161 | { 162 | // Add the node in front of the free list. 163 | *(void**)ptr = ba->freelist; 164 | ba->freelist = ptr; 165 | } 166 | else 167 | { 168 | printf("ERROR! pointer 0x%p does not belong to allocator '%s'\n", ba->name); 169 | } 170 | #else 171 | // Add the node in front of the free list. 172 | *(void**)ptr = ba->freelist; 173 | ba->freelist = ptr; 174 | #endif 175 | } 176 | 177 | void deleteBucketAlloc( struct BucketAlloc *ba ) 178 | { 179 | TESSalloc* alloc = ba->alloc; 180 | Bucket *bucket = ba->buckets; 181 | Bucket *next; 182 | while ( bucket ) 183 | { 184 | next = bucket->next; 185 | alloc->memfree( alloc->userData, bucket ); 186 | bucket = next; 187 | } 188 | ba->freelist = 0; 189 | ba->buckets = 0; 190 | alloc->memfree( alloc->userData, ba ); 191 | } 192 | -------------------------------------------------------------------------------- /libtess2/bucketalloc.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 | ** Copyright (C) [dates of first publication] Silicon Graphics, Inc. 4 | ** All Rights Reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 7 | ** of this software and associated documentation files (the "Software"), to deal 8 | ** in the Software without restriction, including without limitation the rights 9 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | ** of the Software, and to permit persons to whom the Software is furnished to do so, 11 | ** subject to the following conditions: 12 | ** 13 | ** The above copyright notice including the dates of first publication and either this 14 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. 20 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 22 | ** OR OTHER DEALINGS IN THE SOFTWARE. 23 | ** 24 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not 25 | ** be used in advertising or otherwise to promote the sale, use or other dealings in 26 | ** this Software without prior written authorization from Silicon Graphics, Inc. 27 | */ 28 | /* 29 | ** Author: Mikko Mononen, July 2009. 30 | */ 31 | 32 | #ifndef MEMALLOC_H 33 | #define MEMALLOC_H 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #include "tesselator.h" 40 | 41 | struct BucketAlloc *createBucketAlloc( TESSalloc* alloc, const char *name, 42 | unsigned int itemSize, unsigned int bucketSize ); 43 | void *bucketAlloc( struct BucketAlloc *ba); 44 | void bucketFree( struct BucketAlloc *ba, void *ptr ); 45 | void deleteBucketAlloc( struct BucketAlloc *ba ); 46 | 47 | #ifdef __cplusplus 48 | }; 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /libtess2/dict.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 | ** Copyright (C) [dates of first publication] Silicon Graphics, Inc. 4 | ** All Rights Reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 7 | ** of this software and associated documentation files (the "Software"), to deal 8 | ** in the Software without restriction, including without limitation the rights 9 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | ** of the Software, and to permit persons to whom the Software is furnished to do so, 11 | ** subject to the following conditions: 12 | ** 13 | ** The above copyright notice including the dates of first publication and either this 14 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. 20 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 22 | ** OR OTHER DEALINGS IN THE SOFTWARE. 23 | ** 24 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not 25 | ** be used in advertising or otherwise to promote the sale, use or other dealings in 26 | ** this Software without prior written authorization from Silicon Graphics, Inc. 27 | */ 28 | /* 29 | ** Author: Eric Veach, July 1994. 30 | */ 31 | 32 | #include 33 | #include "tesselator.h" 34 | #include "bucketalloc.h" 35 | #include "dict.h" 36 | 37 | /* really tessDictListNewDict */ 38 | Dict *dictNewDict( TESSalloc* alloc, void *frame, int (*leq)(void *frame, DictKey key1, DictKey key2) ) 39 | { 40 | Dict *dict = (Dict *)alloc->memalloc( alloc->userData, sizeof( Dict )); 41 | DictNode *head; 42 | 43 | if (dict == NULL) return NULL; 44 | 45 | head = &dict->head; 46 | 47 | head->key = NULL; 48 | head->next = head; 49 | head->prev = head; 50 | 51 | dict->frame = frame; 52 | dict->leq = leq; 53 | 54 | if (alloc->dictNodeBucketSize < 16) 55 | alloc->dictNodeBucketSize = 16; 56 | if (alloc->dictNodeBucketSize > 4096) 57 | alloc->dictNodeBucketSize = 4096; 58 | dict->nodePool = createBucketAlloc( alloc, "Dict", sizeof(DictNode), alloc->dictNodeBucketSize ); 59 | 60 | return dict; 61 | } 62 | 63 | /* really tessDictListDeleteDict */ 64 | void dictDeleteDict( TESSalloc* alloc, Dict *dict ) 65 | { 66 | deleteBucketAlloc( dict->nodePool ); 67 | alloc->memfree( alloc->userData, dict ); 68 | } 69 | 70 | /* really tessDictListInsertBefore */ 71 | DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key ) 72 | { 73 | DictNode *newNode; 74 | 75 | do { 76 | node = node->prev; 77 | } while( node->key != NULL && ! (*dict->leq)(dict->frame, node->key, key)); 78 | 79 | newNode = (DictNode *)bucketAlloc( dict->nodePool ); 80 | if (newNode == NULL) return NULL; 81 | 82 | newNode->key = key; 83 | newNode->next = node->next; 84 | node->next->prev = newNode; 85 | newNode->prev = node; 86 | node->next = newNode; 87 | 88 | return newNode; 89 | } 90 | 91 | /* really tessDictListDelete */ 92 | void dictDelete( Dict *dict, DictNode *node ) /*ARGSUSED*/ 93 | { 94 | node->next->prev = node->prev; 95 | node->prev->next = node->next; 96 | bucketFree( dict->nodePool, node ); 97 | } 98 | 99 | /* really tessDictListSearch */ 100 | DictNode *dictSearch( Dict *dict, DictKey key ) 101 | { 102 | DictNode *node = &dict->head; 103 | 104 | do { 105 | node = node->next; 106 | } while( node->key != NULL && ! (*dict->leq)(dict->frame, key, node->key)); 107 | 108 | return node; 109 | } 110 | -------------------------------------------------------------------------------- /libtess2/dict.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 | ** Copyright (C) [dates of first publication] Silicon Graphics, Inc. 4 | ** All Rights Reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 7 | ** of this software and associated documentation files (the "Software"), to deal 8 | ** in the Software without restriction, including without limitation the rights 9 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | ** of the Software, and to permit persons to whom the Software is furnished to do so, 11 | ** subject to the following conditions: 12 | ** 13 | ** The above copyright notice including the dates of first publication and either this 14 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. 20 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 22 | ** OR OTHER DEALINGS IN THE SOFTWARE. 23 | ** 24 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not 25 | ** be used in advertising or otherwise to promote the sale, use or other dealings in 26 | ** this Software without prior written authorization from Silicon Graphics, Inc. 27 | */ 28 | /* 29 | ** Author: Eric Veach, July 1994. 30 | */ 31 | 32 | #ifndef DICT_LIST_H 33 | #define DICT_LIST_H 34 | 35 | typedef void *DictKey; 36 | typedef struct Dict Dict; 37 | typedef struct DictNode DictNode; 38 | 39 | Dict *dictNewDict( TESSalloc* alloc, void *frame, int (*leq)(void *frame, DictKey key1, DictKey key2) ); 40 | 41 | void dictDeleteDict( TESSalloc* alloc, Dict *dict ); 42 | 43 | /* Search returns the node with the smallest key greater than or equal 44 | * to the given key. If there is no such key, returns a node whose 45 | * key is NULL. Similarly, Succ(Max(d)) has a NULL key, etc. 46 | */ 47 | DictNode *dictSearch( Dict *dict, DictKey key ); 48 | DictNode *dictInsertBefore( Dict *dict, DictNode *node, DictKey key ); 49 | void dictDelete( Dict *dict, DictNode *node ); 50 | 51 | #define dictKey(n) ((n)->key) 52 | #define dictSucc(n) ((n)->next) 53 | #define dictPred(n) ((n)->prev) 54 | #define dictMin(d) ((d)->head.next) 55 | #define dictMax(d) ((d)->head.prev) 56 | #define dictInsert(d,k) (dictInsertBefore((d),&(d)->head,(k))) 57 | 58 | 59 | /*** Private data structures ***/ 60 | 61 | struct DictNode { 62 | DictKey key; 63 | DictNode *next; 64 | DictNode *prev; 65 | }; 66 | 67 | struct Dict { 68 | DictNode head; 69 | void *frame; 70 | struct BucketAlloc *nodePool; 71 | int (*leq)(void *frame, DictKey key1, DictKey key2); 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /libtess2/geom.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 | ** Copyright (C) [dates of first publication] Silicon Graphics, Inc. 4 | ** All Rights Reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 7 | ** of this software and associated documentation files (the "Software"), to deal 8 | ** in the Software without restriction, including without limitation the rights 9 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | ** of the Software, and to permit persons to whom the Software is furnished to do so, 11 | ** subject to the following conditions: 12 | ** 13 | ** The above copyright notice including the dates of first publication and either this 14 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. 20 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 22 | ** OR OTHER DEALINGS IN THE SOFTWARE. 23 | ** 24 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not 25 | ** be used in advertising or otherwise to promote the sale, use or other dealings in 26 | ** this Software without prior written authorization from Silicon Graphics, Inc. 27 | */ 28 | /* 29 | ** Author: Eric Veach, July 1994. 30 | */ 31 | 32 | #ifndef GEOM_H 33 | #define GEOM_H 34 | 35 | #include "mesh.h" 36 | 37 | #ifdef NO_BRANCH_CONDITIONS 38 | /* MIPS architecture has special instructions to evaluate boolean 39 | * conditions -- more efficient than branching, IF you can get the 40 | * compiler to generate the right instructions (SGI compiler doesn't) 41 | */ 42 | #define VertEq(u,v) (((u)->s == (v)->s) & ((u)->t == (v)->t)) 43 | #define VertLeq(u,v) (((u)->s < (v)->s) | \ 44 | ((u)->s == (v)->s & (u)->t <= (v)->t)) 45 | #else 46 | #define VertEq(u,v) ((u)->s == (v)->s && (u)->t == (v)->t) 47 | #define VertLeq(u,v) (((u)->s < (v)->s) || ((u)->s == (v)->s && (u)->t <= (v)->t)) 48 | #endif 49 | 50 | #define EdgeEval(u,v,w) tesedgeEval(u,v,w) 51 | #define EdgeSign(u,v,w) tesedgeSign(u,v,w) 52 | 53 | /* Versions of VertLeq, EdgeSign, EdgeEval with s and t transposed. */ 54 | 55 | #define TransLeq(u,v) (((u)->t < (v)->t) || ((u)->t == (v)->t && (u)->s <= (v)->s)) 56 | #define TransEval(u,v,w) testransEval(u,v,w) 57 | #define TransSign(u,v,w) testransSign(u,v,w) 58 | 59 | 60 | #define EdgeGoesLeft(e) VertLeq( (e)->Dst, (e)->Org ) 61 | #define EdgeGoesRight(e) VertLeq( (e)->Org, (e)->Dst ) 62 | 63 | #define ABS(x) ((x) < 0 ? -(x) : (x)) 64 | #define VertL1dist(u,v) (ABS(u->s - v->s) + ABS(u->t - v->t)) 65 | 66 | #define VertCCW(u,v,w) tesvertCCW(u,v,w) 67 | 68 | int tesvertLeq( TESSvertex *u, TESSvertex *v ); 69 | TESSreal tesedgeEval( TESSvertex *u, TESSvertex *v, TESSvertex *w ); 70 | TESSreal tesedgeSign( TESSvertex *u, TESSvertex *v, TESSvertex *w ); 71 | TESSreal testransEval( TESSvertex *u, TESSvertex *v, TESSvertex *w ); 72 | TESSreal testransSign( TESSvertex *u, TESSvertex *v, TESSvertex *w ); 73 | int tesvertCCW( TESSvertex *u, TESSvertex *v, TESSvertex *w ); 74 | void tesedgeIntersect( TESSvertex *o1, TESSvertex *d1, TESSvertex *o2, TESSvertex *d2, TESSvertex *v ); 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /libtess2/priorityq.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 | ** Copyright (C) [dates of first publication] Silicon Graphics, Inc. 4 | ** All Rights Reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 7 | ** of this software and associated documentation files (the "Software"), to deal 8 | ** in the Software without restriction, including without limitation the rights 9 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | ** of the Software, and to permit persons to whom the Software is furnished to do so, 11 | ** subject to the following conditions: 12 | ** 13 | ** The above copyright notice including the dates of first publication and either this 14 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. 20 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 22 | ** OR OTHER DEALINGS IN THE SOFTWARE. 23 | ** 24 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not 25 | ** be used in advertising or otherwise to promote the sale, use or other dealings in 26 | ** this Software without prior written authorization from Silicon Graphics, Inc. 27 | */ 28 | /* 29 | ** Author: Eric Veach, July 1994. 30 | */ 31 | 32 | #ifndef PRIORITYQ_H 33 | #define PRIORITYQ_H 34 | 35 | /* The basic operations are insertion of a new key (pqInsert), 36 | * and examination/extraction of a key whose value is minimum 37 | * (pqMinimum/pqExtractMin). Deletion is also allowed (pqDelete); 38 | * for this purpose pqInsert returns a "handle" which is supplied 39 | * as the argument. 40 | * 41 | * An initial heap may be created efficiently by calling pqInsert 42 | * repeatedly, then calling pqInit. In any case pqInit must be called 43 | * before any operations other than pqInsert are used. 44 | * 45 | * If the heap is empty, pqMinimum/pqExtractMin will return a NULL key. 46 | * This may also be tested with pqIsEmpty. 47 | */ 48 | 49 | /* Since we support deletion the data structure is a little more 50 | * complicated than an ordinary heap. "nodes" is the heap itself; 51 | * active nodes are stored in the range 1..pq->size. When the 52 | * heap exceeds its allocated size (pq->max), its size doubles. 53 | * The children of node i are nodes 2i and 2i+1. 54 | * 55 | * Each node stores an index into an array "handles". Each handle 56 | * stores a key, plus a pointer back to the node which currently 57 | * represents that key (ie. nodes[handles[i].node].handle == i). 58 | */ 59 | 60 | typedef void *PQkey; 61 | typedef int PQhandle; 62 | typedef struct PriorityQHeap PriorityQHeap; 63 | 64 | #define INV_HANDLE 0x0fffffff 65 | 66 | typedef struct { PQhandle handle; } PQnode; 67 | typedef struct { PQkey key; PQhandle node; } PQhandleElem; 68 | 69 | struct PriorityQHeap { 70 | 71 | PQnode *nodes; 72 | PQhandleElem *handles; 73 | int size, max; 74 | PQhandle freeList; 75 | int initialized; 76 | 77 | int (*leq)(PQkey key1, PQkey key2); 78 | }; 79 | 80 | typedef struct PriorityQ PriorityQ; 81 | 82 | struct PriorityQ { 83 | PriorityQHeap *heap; 84 | 85 | PQkey *keys; 86 | PQkey **order; 87 | PQhandle size, max; 88 | int initialized; 89 | 90 | int (*leq)(PQkey key1, PQkey key2); 91 | }; 92 | 93 | PriorityQ *pqNewPriorityQ( TESSalloc* alloc, int size, int (*leq)(PQkey key1, PQkey key2) ); 94 | void pqDeletePriorityQ( TESSalloc* alloc, PriorityQ *pq ); 95 | 96 | int pqInit( TESSalloc* alloc, PriorityQ *pq ); 97 | PQhandle pqInsert( TESSalloc* alloc, PriorityQ *pq, PQkey key ); 98 | PQkey pqExtractMin( PriorityQ *pq ); 99 | void pqDelete( PriorityQ *pq, PQhandle handle ); 100 | 101 | PQkey pqMinimum( PriorityQ *pq ); 102 | int pqIsEmpty( PriorityQ *pq ); 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /libtess2/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | Libtess2 version 1.0 3 | 4 | 5 | This is refactored version of the original libtess which comes with the GLU reference implementation. The code is good quality polygon tesselator and triangulator. The original code comes with rather horrible interface and its' performance suffers from lots of small memory allocations. The main point of the refactoring has been the interface and memory allocation scheme. 6 | 7 | Simple bucketed memory allocator (see Graphics Gems III for reference) was added which speeds up the code by order of magnitude (tests showed 15 to 50 times improvement depending on data). The API allows the user to pass his own allocator to the library. It is possible to configure the library so that the library runs on predefined chunk of memory. 8 | 9 | The API was changed to loosely resemble the OpenGL vertex array API. The processed data can be accessed via getter functions. The code is able to output contours, polygons and connected polygons. The output of the tesselator can be also used as input for new run. I.e. the user may first want to calculate an union all the input contours and the triangulate them. 10 | 11 | The code is released under SGI FREE SOFTWARE LICENSE B Version 2.0. 12 | 13 | 14 | 15 | Mikko Mononen 16 | memon@inside.org -------------------------------------------------------------------------------- /libtess2/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | -------------------------------------------------------------------------------- /libtess2/sweep.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 | ** Copyright (C) [dates of first publication] Silicon Graphics, Inc. 4 | ** All Rights Reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 7 | ** of this software and associated documentation files (the "Software"), to deal 8 | ** in the Software without restriction, including without limitation the rights 9 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | ** of the Software, and to permit persons to whom the Software is furnished to do so, 11 | ** subject to the following conditions: 12 | ** 13 | ** The above copyright notice including the dates of first publication and either this 14 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. 20 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 22 | ** OR OTHER DEALINGS IN THE SOFTWARE. 23 | ** 24 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not 25 | ** be used in advertising or otherwise to promote the sale, use or other dealings in 26 | ** this Software without prior written authorization from Silicon Graphics, Inc. 27 | */ 28 | /* 29 | ** Author: Eric Veach, July 1994. 30 | */ 31 | 32 | #ifndef SWEEP_H 33 | #define SWEEP_H 34 | 35 | #include "mesh.h" 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* tessComputeInterior( tess ) computes the planar arrangement specified 42 | * by the given contours, and further subdivides this arrangement 43 | * into regions. Each region is marked "inside" if it belongs 44 | * to the polygon, according to the rule given by tess->windingRule. 45 | * Each interior region is guaranteed be monotone. 46 | */ 47 | int tessComputeInterior( TESStesselator *tess ); 48 | 49 | #ifdef __cplusplus 50 | }; 51 | #endif 52 | 53 | 54 | /* The following is here *only* for access by debugging routines */ 55 | 56 | #include "dict.h" 57 | 58 | /* For each pair of adjacent edges crossing the sweep line, there is 59 | * an ActiveRegion to represent the region between them. The active 60 | * regions are kept in sorted order in a dynamic dictionary. As the 61 | * sweep line crosses each vertex, we update the affected regions. 62 | */ 63 | 64 | struct ActiveRegion { 65 | TESShalfEdge *eUp; /* upper edge, directed right to left */ 66 | DictNode *nodeUp; /* dictionary node corresponding to eUp */ 67 | int windingNumber; /* used to determine which regions are 68 | * inside the polygon */ 69 | int inside; /* is this region inside the polygon? */ 70 | int sentinel; /* marks fake edges at t = +/-infinity */ 71 | int dirty; /* marks regions where the upper or lower 72 | * edge has changed, but we haven't checked 73 | * whether they intersect yet */ 74 | int fixUpperEdge; /* marks temporary edges introduced when 75 | * we process a "right vertex" (one without 76 | * any edges leaving to the right) */ 77 | }; 78 | 79 | #define RegionBelow(r) ((ActiveRegion *) dictKey(dictPred((r)->nodeUp))) 80 | #define RegionAbove(r) ((ActiveRegion *) dictKey(dictSucc((r)->nodeUp))) 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /libtess2/tess.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 | ** Copyright (C) [dates of first publication] Silicon Graphics, Inc. 4 | ** All Rights Reserved. 5 | ** 6 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 7 | ** of this software and associated documentation files (the "Software"), to deal 8 | ** in the Software without restriction, including without limitation the rights 9 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | ** of the Software, and to permit persons to whom the Software is furnished to do so, 11 | ** subject to the following conditions: 12 | ** 13 | ** The above copyright notice including the dates of first publication and either this 14 | ** permission notice or a reference to http://oss.sgi.com/projects/FreeB/ shall be 15 | ** included in all copies or substantial portions of the Software. 16 | ** 17 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 18 | ** INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 19 | ** PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL SILICON GRAPHICS, INC. 20 | ** BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 22 | ** OR OTHER DEALINGS IN THE SOFTWARE. 23 | ** 24 | ** Except as contained in this notice, the name of Silicon Graphics, Inc. shall not 25 | ** be used in advertising or otherwise to promote the sale, use or other dealings in 26 | ** this Software without prior written authorization from Silicon Graphics, Inc. 27 | */ 28 | /* 29 | ** Author: Eric Veach, July 1994. 30 | */ 31 | 32 | #ifndef TESS_H 33 | #define TESS_H 34 | 35 | #include 36 | #include "bucketalloc.h" 37 | #include "mesh.h" 38 | #include "dict.h" 39 | #include "priorityq.h" 40 | #include "tesselator.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | //typedef struct TESStesselator TESStesselator; 47 | 48 | struct TESStesselator { 49 | 50 | /*** state needed for collecting the input data ***/ 51 | TESSmesh *mesh; /* stores the input contours, and eventually 52 | the tessellation itself */ 53 | int outOfMemory; 54 | 55 | /*** state needed for projecting onto the sweep plane ***/ 56 | 57 | TESSreal normal[3]; /* user-specified normal (if provided) */ 58 | TESSreal sUnit[3]; /* unit vector in s-direction (debugging) */ 59 | TESSreal tUnit[3]; /* unit vector in t-direction (debugging) */ 60 | 61 | TESSreal bmin[2]; 62 | TESSreal bmax[2]; 63 | 64 | /*** state needed for the line sweep ***/ 65 | int windingRule; /* rule for determining polygon interior */ 66 | 67 | Dict *dict; /* edge dictionary for sweep line */ 68 | PriorityQ *pq; /* priority queue of vertex events */ 69 | TESSvertex *event; /* current sweep event being processed */ 70 | 71 | struct BucketAlloc* regionPool; 72 | 73 | TESSindex vertexIndexCounter; 74 | 75 | TESSreal *vertices; 76 | TESSindex *vertexIndices; 77 | int vertexCount; 78 | TESSindex *elements; 79 | int elementCount; 80 | 81 | TESSalloc alloc; 82 | 83 | jmp_buf env; /* place to jump to when memAllocs fail */ 84 | }; 85 | 86 | #ifdef __cplusplus 87 | }; 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /misc/tinyswf-bitmap.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/misc/tinyswf-bitmap.docx -------------------------------------------------------------------------------- /misc/tinyswf-bitmap.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/misc/tinyswf-bitmap.pdf -------------------------------------------------------------------------------- /misc/tinyswf.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/misc/tinyswf.ai -------------------------------------------------------------------------------- /misc/tinyswf.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/misc/tinyswf.fla -------------------------------------------------------------------------------- /misc/tinyswf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/misc/tinyswf.png -------------------------------------------------------------------------------- /projects/proj.android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /projects/proj.android/jni/Android.mk: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2009 The Android Open Source Project 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | 16 | # the purpose of this sample is to demonstrate how one can 17 | # generate two distinct shared libraries and have them both 18 | # uploaded in 19 | # 20 | 21 | LOCAL_PATH:= $(call my-dir) 22 | 23 | include $(CLEAR_VARS) 24 | 25 | LOCAL_MODULE := libtinyswf 26 | 27 | MY_PREFIX := $(LOCAL_PATH)/../../../ 28 | 29 | MY_SOURCES = $(wildcard $(MY_PREFIX)/src/*.cpp) \ 30 | $(wildcard $(MY_PREFIX)/src/tags/*.cpp) \ 31 | $(wildcard $(MY_PREFIX)/libtess2/*.c) 32 | 33 | LOCAL_SRC_FILES := $(subst jni/, , $(MY_SOURCES)) 34 | 35 | LOCAL_C_INCLUDES := $(MY_PREFIX)/include \ 36 | $(MY_PREFIX)/libtess2 \ 37 | $(MY_PREFIX)/rapidxml \ 38 | $(MY_PREFIX)/src/tags 39 | 40 | LOCAL_CFLAGS := -std=c++11 -fexceptions -frtti -Wno-literal-suffix 41 | 42 | include $(BUILD_STATIC_LIBRARY) 43 | -------------------------------------------------------------------------------- /projects/proj.android/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_STL := gnustl_static 2 | -------------------------------------------------------------------------------- /projects/proj.android/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-15 15 | -------------------------------------------------------------------------------- /projects/proj.android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | tinyswf 4 | 5 | -------------------------------------------------------------------------------- /projects/proj.ios/libtinyswf-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'tinyswf' target in the 'tinyswf' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | 9 | #ifdef __cplusplus 10 | #include "tinyswf.h" 11 | #endif -------------------------------------------------------------------------------- /projects/proj.vc11/libtinyswf.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtinyswf", "libtinyswf.vcxproj", "{2EF32000-30A4-49E5-84E1-C1ED38931E36}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Debug|Win32.Build.0 = Debug|Win32 14 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Release|Win32.ActiveCfg = Release|Win32 15 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /projects/proj.vc11/libtinyswf.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {e5b3dc34-182f-4a25-a172-dae705b01da0} 6 | 7 | 8 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 9 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 10 | 11 | 12 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 13 | h;hpp;hxx;hm;inl;inc;xsd 14 | 15 | 16 | {5682f1c0-ebd6-4b6f-b309-920de2309944} 17 | 18 | 19 | 20 | 21 | header 22 | 23 | 24 | header 25 | 26 | 27 | header 28 | 29 | 30 | header 31 | 32 | 33 | header 34 | 35 | 36 | header 37 | 38 | 39 | header 40 | 41 | 42 | header 43 | 44 | 45 | libtess2 46 | 47 | 48 | libtess2 49 | 50 | 51 | libtess2 52 | 53 | 54 | libtess2 55 | 56 | 57 | libtess2 58 | 59 | 60 | libtess2 61 | 62 | 63 | libtess2 64 | 65 | 66 | libtess2 67 | 68 | 69 | header\tags 70 | 71 | 72 | header\tags 73 | 74 | 75 | header\tags 76 | 77 | 78 | header\tags 79 | 80 | 81 | header\tags 82 | 83 | 84 | header\tags 85 | 86 | 87 | header\tags 88 | 89 | 90 | header\tags 91 | 92 | 93 | header\tags 94 | 95 | 96 | header\tags 97 | 98 | 99 | header\tags 100 | 101 | 102 | header\tags 103 | 104 | 105 | header\tags 106 | 107 | 108 | header\tags 109 | 110 | 111 | header\tags 112 | 113 | 114 | 115 | 116 | 117 | source 118 | 119 | 120 | source 121 | 122 | 123 | source 124 | 125 | 126 | source 127 | 128 | 129 | source 130 | 131 | 132 | source 133 | 134 | 135 | source 136 | 137 | 138 | source 139 | 140 | 141 | source 142 | 143 | 144 | source 145 | 146 | 147 | source 148 | 149 | 150 | libtess2 151 | 152 | 153 | libtess2 154 | 155 | 156 | libtess2 157 | 158 | 159 | libtess2 160 | 161 | 162 | libtess2 163 | 164 | 165 | libtess2 166 | 167 | 168 | libtess2 169 | 170 | 171 | source 172 | 173 | 174 | source 175 | 176 | 177 | 178 | -------------------------------------------------------------------------------- /projects/proj.vc11/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // tsviewer.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /projects/proj.vc11/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | // TODO: reference additional headers your program requires here 13 | #include "tinyswf.h" 14 | #include "tsTag.h" 15 | -------------------------------------------------------------------------------- /rapidxml/license.txt: -------------------------------------------------------------------------------- 1 | Use of this software is granted under one of the following two licenses, 2 | to be chosen freely by the user. 3 | 4 | 1. Boost Software License - Version 1.0 - August 17th, 2003 5 | =============================================================================== 6 | 7 | Copyright (c) 2006, 2007 Marcin Kalicinski 8 | 9 | Permission is hereby granted, free of charge, to any person or organization 10 | obtaining a copy of the software and accompanying documentation covered by 11 | this license (the "Software") to use, reproduce, display, distribute, 12 | execute, and transmit the Software, and to prepare derivative works of the 13 | Software, and to permit third-parties to whom the Software is furnished to 14 | do so, all subject to the following: 15 | 16 | The copyright notices in the Software and this entire statement, including 17 | the above license grant, this restriction and the following disclaimer, 18 | must be included in all copies of the Software, in whole or in part, and 19 | all derivative works of the Software, unless such copies or derivative 20 | works are solely in the form of machine-executable object code generated by 21 | a source language processor. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 25 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 26 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 27 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 28 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 29 | DEALINGS IN THE SOFTWARE. 30 | 31 | 2. The MIT License 32 | =============================================================================== 33 | 34 | Copyright (c) 2006, 2007 Marcin Kalicinski 35 | 36 | Permission is hereby granted, free of charge, to any person obtaining a copy 37 | of this software and associated documentation files (the "Software"), to deal 38 | in the Software without restriction, including without limitation the rights 39 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 40 | of the Software, and to permit persons to whom the Software is furnished to do so, 41 | subject to the following conditions: 42 | 43 | The above copyright notice and this permission notice shall be included in all 44 | copies or substantial portions of the Software. 45 | 46 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 47 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 48 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 49 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 50 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 51 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 52 | IN THE SOFTWARE. 53 | -------------------------------------------------------------------------------- /rapidxml/rapidxml_iterators.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDXML_ITERATORS_HPP_INCLUDED 2 | #define RAPIDXML_ITERATORS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! \file rapidxml_iterators.hpp This file contains rapidxml iterators 8 | 9 | #include "rapidxml.hpp" 10 | 11 | namespace rapidxml 12 | { 13 | 14 | //! Iterator of child nodes of xml_node 15 | template 16 | class node_iterator 17 | { 18 | 19 | public: 20 | 21 | typedef typename xml_node value_type; 22 | typedef typename xml_node &reference; 23 | typedef typename xml_node *pointer; 24 | typedef std::ptrdiff_t difference_type; 25 | typedef std::bidirectional_iterator_tag iterator_category; 26 | 27 | node_iterator() 28 | : m_node(0) 29 | { 30 | } 31 | 32 | node_iterator(xml_node *node) 33 | : m_node(node->first_node()) 34 | { 35 | } 36 | 37 | reference operator *() const 38 | { 39 | assert(m_node); 40 | return *m_node; 41 | } 42 | 43 | pointer operator->() const 44 | { 45 | assert(m_node); 46 | return m_node; 47 | } 48 | 49 | node_iterator& operator++() 50 | { 51 | assert(m_node); 52 | m_node = m_node->next_sibling(); 53 | return *this; 54 | } 55 | 56 | node_iterator operator++(int) 57 | { 58 | node_iterator tmp = *this; 59 | ++this; 60 | return tmp; 61 | } 62 | 63 | node_iterator& operator--() 64 | { 65 | assert(m_node && m_node->previous_sibling()); 66 | m_node = m_node->previous_sibling(); 67 | return *this; 68 | } 69 | 70 | node_iterator operator--(int) 71 | { 72 | node_iterator tmp = *this; 73 | ++this; 74 | return tmp; 75 | } 76 | 77 | bool operator ==(const node_iterator &rhs) 78 | { 79 | return m_node == rhs.m_node; 80 | } 81 | 82 | bool operator !=(const node_iterator &rhs) 83 | { 84 | return m_node != rhs.m_node; 85 | } 86 | 87 | private: 88 | 89 | xml_node *m_node; 90 | 91 | }; 92 | 93 | //! Iterator of child attributes of xml_node 94 | template 95 | class attribute_iterator 96 | { 97 | 98 | public: 99 | 100 | typedef typename xml_attribute value_type; 101 | typedef typename xml_attribute &reference; 102 | typedef typename xml_attribute *pointer; 103 | typedef std::ptrdiff_t difference_type; 104 | typedef std::bidirectional_iterator_tag iterator_category; 105 | 106 | attribute_iterator() 107 | : m_attribute(0) 108 | { 109 | } 110 | 111 | attribute_iterator(xml_node *node) 112 | : m_attribute(node->first_attribute()) 113 | { 114 | } 115 | 116 | reference operator *() const 117 | { 118 | assert(m_attribute); 119 | return *m_attribute; 120 | } 121 | 122 | pointer operator->() const 123 | { 124 | assert(m_attribute); 125 | return m_attribute; 126 | } 127 | 128 | attribute_iterator& operator++() 129 | { 130 | assert(m_attribute); 131 | m_attribute = m_attribute->next_attribute(); 132 | return *this; 133 | } 134 | 135 | attribute_iterator operator++(int) 136 | { 137 | attribute_iterator tmp = *this; 138 | ++this; 139 | return tmp; 140 | } 141 | 142 | attribute_iterator& operator--() 143 | { 144 | assert(m_attribute && m_attribute->previous_attribute()); 145 | m_attribute = m_attribute->previous_attribute(); 146 | return *this; 147 | } 148 | 149 | attribute_iterator operator--(int) 150 | { 151 | attribute_iterator tmp = *this; 152 | ++this; 153 | return tmp; 154 | } 155 | 156 | bool operator ==(const attribute_iterator &rhs) 157 | { 158 | return m_attribute == rhs.m_attribute; 159 | } 160 | 161 | bool operator !=(const attribute_iterator &rhs) 162 | { 163 | return m_attribute != rhs.m_attribute; 164 | } 165 | 166 | private: 167 | 168 | xml_attribute *m_attribute; 169 | 170 | }; 171 | 172 | } 173 | 174 | #endif 175 | -------------------------------------------------------------------------------- /rapidxml/rapidxml_utils.hpp: -------------------------------------------------------------------------------- 1 | #ifndef RAPIDXML_UTILS_HPP_INCLUDED 2 | #define RAPIDXML_UTILS_HPP_INCLUDED 3 | 4 | // Copyright (C) 2006, 2009 Marcin Kalicinski 5 | // Version 1.13 6 | // Revision $DateTime: 2009/05/13 01:46:17 $ 7 | //! \file rapidxml_utils.hpp This file contains high-level rapidxml utilities that can be useful 8 | //! in certain simple scenarios. They should probably not be used if maximizing performance is the main objective. 9 | 10 | #include "rapidxml.hpp" 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace rapidxml 17 | { 18 | 19 | //! Represents data loaded from a file 20 | template 21 | class file 22 | { 23 | 24 | public: 25 | 26 | //! Loads file into the memory. Data will be automatically destroyed by the destructor. 27 | //! \param filename Filename to load. 28 | file(const char *filename) 29 | { 30 | using namespace std; 31 | 32 | // Open stream 33 | basic_ifstream stream(filename, ios::binary); 34 | if (!stream) 35 | throw runtime_error(string("cannot open file ") + filename); 36 | stream.unsetf(ios::skipws); 37 | 38 | // Determine stream size 39 | stream.seekg(0, ios::end); 40 | size_t size = stream.tellg(); 41 | stream.seekg(0); 42 | 43 | // Load data and add terminating 0 44 | m_data.resize(size + 1); 45 | stream.read(&m_data.front(), static_cast(size)); 46 | m_data[size] = 0; 47 | } 48 | 49 | //! Loads file into the memory. Data will be automatically destroyed by the destructor 50 | //! \param stream Stream to load from 51 | file(std::basic_istream &stream) 52 | { 53 | using namespace std; 54 | 55 | // Load data and add terminating 0 56 | stream.unsetf(ios::skipws); 57 | m_data.assign(istreambuf_iterator(stream), istreambuf_iterator()); 58 | if (stream.fail() || stream.bad()) 59 | throw runtime_error("error reading stream"); 60 | m_data.push_back(0); 61 | } 62 | 63 | //! Gets file data. 64 | //! \return Pointer to data of file. 65 | Ch *data() 66 | { 67 | return &m_data.front(); 68 | } 69 | 70 | //! Gets file data. 71 | //! \return Pointer to data of file. 72 | const Ch *data() const 73 | { 74 | return &m_data.front(); 75 | } 76 | 77 | //! Gets file data size. 78 | //! \return Size of file data, in characters. 79 | std::size_t size() const 80 | { 81 | return m_data.size(); 82 | } 83 | 84 | private: 85 | 86 | std::vector m_data; // File data 87 | 88 | }; 89 | 90 | //! Counts children of node. Time complexity is O(n). 91 | //! \return Number of children of node 92 | template 93 | inline std::size_t count_children(xml_node *node) 94 | { 95 | xml_node *child = node->first_node(); 96 | std::size_t count = 0; 97 | while (child) 98 | { 99 | ++count; 100 | child = child->next_sibling(); 101 | } 102 | return count; 103 | } 104 | 105 | //! Counts attributes of node. Time complexity is O(n). 106 | //! \return Number of attributes of node 107 | template 108 | inline std::size_t count_attributes(xml_node *node) 109 | { 110 | xml_attribute *attr = node->first_attribute(); 111 | std::size_t count = 0; 112 | while (attr) 113 | { 114 | ++count; 115 | attr = attr->next_attribute(); 116 | } 117 | return count; 118 | } 119 | 120 | } 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /src/tags/DefineButton.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __DEFINE_BUTTON_H__ 6 | #define __DEFINE_BUTTON_H__ 7 | 8 | #include "tsTag.h" 9 | #include "tsReader.h" 10 | #include "tsMovieClip.h" 11 | #include "DoAction.h" 12 | 13 | namespace tinyswf { 14 | class MovieClip; 15 | class Button; 16 | class PlaceObjectTag; 17 | 18 | //----------------------------------------------------------------------------- 19 | 20 | const int kButtonStateHitTest = 0x08; 21 | 22 | struct ButtonRecord { 23 | /* 24 | ButtonReserved UB[2] Reserved bits; always 0 25 | ButtonHasBlendMode UB[1] 0 = No blend mode, 1 = Has blend mode (SWF 8 and later only) 26 | ButtonHasFilterList UB[1] 0 = No filter list, 1 = Has filter list (SWF 8 and later only) 27 | ButtonStateHitTest UB[1] Present in hit test state 28 | ButtonStateDown UB[1] Present in down state 29 | ButtonStateOver UB[1] Present in over state 30 | ButtonStateUp UB[1] Present in up state 31 | */ 32 | int _state; 33 | uint16_t _character_id; 34 | uint16_t _depth; 35 | MATRIX _matrix; 36 | CXFORM _cxform; 37 | int _blend_mode; 38 | 39 | bool read( Reader& read, SWF& swf, int tag_type ); 40 | void print(); 41 | }; 42 | 43 | //----------------------------------------------------------------------------- 44 | 45 | struct ButtonAction { 46 | public: 47 | enum Condition { 48 | IDLE_TO_OVER_UP = 1 << 0, 49 | OVER_UP_TO_IDLE = 1 << 1, 50 | OVER_UP_TO_OVER_DOWN = 1 << 2, 51 | OVER_DOWN_TO_OVER_UP = 1 << 3, 52 | OVER_DOWN_TO_OUT_DOWN = 1 << 4, 53 | OUT_DOWN_TO_OVER_DOWN = 1 << 5, 54 | OUT_DOWN_TO_IDLE = 1 << 6, 55 | IDLE_TO_OVER_DOWN = 1 << 7, 56 | OVER_DOWN_TO_IDLE = 1 << 8, 57 | }; 58 | int _conditions; 59 | DoActionTag _actions; 60 | 61 | bool read( Reader& reader, SWF& swf, MovieFrames& frames, int tag_type ); 62 | void print() { SWF_TRACE("Condition[0x%x]\n",_conditions); _actions.print(); } 63 | }; 64 | 65 | //----------------------------------------------------------------------------- 66 | 67 | //TAG_DEFINE_BUTTON 68 | class DefineButtonTag : public ITag 69 | { 70 | uint16_t _buttonId; 71 | 72 | public: 73 | DefineButtonTag( TagHeader& h ) 74 | : ITag( h ) 75 | {} 76 | 77 | virtual ~DefineButtonTag() 78 | {} 79 | 80 | virtual bool read( Reader& reader, SWF& , MovieFrames& ) { 81 | _buttonId = reader.get(); 82 | reader.skip( length()-2 ); 83 | return false;//delete tag 84 | } 85 | 86 | virtual void print() { 87 | _header.print(); 88 | SWF_TRACE("id=%d\n", _buttonId); 89 | } 90 | 91 | static ITag* create( TagHeader& header ) { 92 | return new DefineButtonTag( header ); 93 | } 94 | }; 95 | 96 | //----------------------------------------------------------------------------- 97 | 98 | typedef std::vector ButtonRecordArray; 99 | typedef std::vector ButtonActionArray; 100 | 101 | class DefineButton2Tag : public ITag 102 | { 103 | friend class Button; 104 | private: 105 | uint16_t _buttonId; 106 | bool _asMenu; 107 | RECT _bound; 108 | ButtonRecordArray _buttonRecords; 109 | ButtonActionArray _buttonActions; 110 | 111 | public: 112 | DefineButton2Tag( TagHeader& h ) 113 | : ITag( h ) 114 | ,_buttonId(0) 115 | ,_asMenu(0) 116 | {} 117 | 118 | virtual ~DefineButton2Tag(); 119 | 120 | virtual bool read( Reader& reader, SWF& swf, MovieFrames& frames); 121 | virtual void print(); 122 | 123 | const RECT& getRectangle(void) const { return _bound; } 124 | 125 | static ITag* create( TagHeader& header ) { 126 | return new DefineButton2Tag( header ); 127 | } 128 | }; 129 | 130 | //----------------------------------------------------------------------------- 131 | 132 | }// namespace 133 | 134 | #endif // __DEFINE_BUTTON_H__ 135 | -------------------------------------------------------------------------------- /src/tags/DefineFont.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #include "DefineFont.h" 6 | #include "tsSWF.h" 7 | 8 | using namespace tinyswf; 9 | 10 | enum FONT_FLAG { 11 | FLAG_HAS_LAYOUT = 0x80, 12 | FLAG_SHIFT_JIS = 0x40, 13 | FLAG_SMALL_TEXT = 0x20, 14 | FLAG_ANSI = 0x10, 15 | FLAG_WIDE_OFFSETS = 0x08, 16 | FLAG_WIDE_CODES = 0x04, 17 | FLAG_ITALIC = 0x02, 18 | FLAG_BOLD = 0x01 19 | }; 20 | 21 | bool DefineFontTag::read( Reader& reader, SWF& swf, MovieFrames& ) { 22 | _character_id = reader.get(); 23 | int flag = reader.get(); 24 | int langcode = reader.get(); 25 | SWF_UNUSED_PARAM(langcode); 26 | 27 | int name_length = reader.get(); 28 | _font_name.assign(reader.getData(), name_length); 29 | reader.skip(name_length); 30 | 31 | uint32_t code_table_offset; 32 | int glyph_count = reader.get(); 33 | 34 | _font_style = flag & (FLAG_ITALIC | FLAG_BOLD); 35 | 36 | if (0 == glyph_count) { 37 | swf.addCharacter( this, _character_id ); 38 | return true; 39 | } 40 | 41 | if (flag & FLAG_WIDE_OFFSETS) { 42 | int skip = glyph_count * 4; 43 | reader.skip(skip); // skip offset table 44 | code_table_offset = reader.get() - skip - 4; 45 | } else { 46 | int skip = glyph_count * 2; 47 | reader.skip(skip); // skip offset table 48 | code_table_offset = reader.get() - skip - 2; 49 | } 50 | 51 | // GlyphShapeTable 52 | reader.skip(code_table_offset); // skip offset table 53 | 54 | // CodeTable 55 | _code_table.resize(glyph_count); 56 | if (flag & FLAG_WIDE_CODES) { 57 | for (int i = 0; i < glyph_count; ++i) { 58 | _code_table[i] = reader.get(); 59 | } 60 | } else { 61 | for (int i = 0; i < glyph_count; ++i) { 62 | _code_table[i] = reader.get(); 63 | } 64 | } 65 | 66 | if (flag & FLAG_HAS_LAYOUT) { 67 | float ascent = reader.get() * SWF_INV_TWIPS; 68 | float descent = reader.get() * SWF_INV_TWIPS; 69 | float leading = reader.get() * SWF_INV_TWIPS; 70 | 71 | SWF_UNUSED_PARAM(ascent); 72 | SWF_UNUSED_PARAM(descent); 73 | SWF_UNUSED_PARAM(leading); 74 | 75 | // advance table 76 | for (int i = 0; i < glyph_count; ++i) { 77 | float advance = reader.get() * SWF_INV_TWIPS; 78 | SWF_UNUSED_PARAM(advance); 79 | } 80 | // bound table 81 | RECT bound; 82 | for (int i = 0; i < glyph_count; ++i) { 83 | reader.align(); 84 | reader.getRectangle(bound); 85 | } 86 | // kerning 87 | uint16_t kerning_count = reader.get(); 88 | if (flag & FLAG_WIDE_CODES) { 89 | for (int i = 0; i < kerning_count; ++i) { 90 | uint16_t code1 = reader.get(); 91 | uint16_t code2 = reader.get(); 92 | int16_t adjust = reader.get(); 93 | SWF_UNUSED_PARAM(code1); 94 | SWF_UNUSED_PARAM(code2); 95 | SWF_UNUSED_PARAM(adjust); 96 | } 97 | } else { 98 | for (int i = 0; i < kerning_count; ++i) { 99 | uint16_t code1 = reader.get(); 100 | uint16_t code2 = reader.get(); 101 | int16_t adjust = reader.get(); 102 | SWF_UNUSED_PARAM(code1); 103 | SWF_UNUSED_PARAM(code2); 104 | SWF_UNUSED_PARAM(adjust); 105 | } 106 | } 107 | } 108 | 109 | swf.addCharacter( this, _character_id ); 110 | return true; // keep tag 111 | } 112 | 113 | void DefineFontTag::print() { 114 | _header.print(); 115 | SWF_TRACE("id=%d, name:'%s', glyph:%d\n", _character_id, _font_name.c_str(), _code_table.size()); 116 | } 117 | 118 | //----------------------------------------------------------------------------- 119 | 120 | bool DefineFontNameTag::read( Reader& reader, SWF&, MovieFrames& data ) 121 | { 122 | _font_id = reader.get(); 123 | _name.assign( reader.getString() ); 124 | _copyright.assign( reader.getString() ); 125 | return false;//delete tag 126 | } 127 | 128 | void DefineFontNameTag::print() { 129 | _header.print(); 130 | SWF_TRACE("id=%d, name:'%s', copyright='%s'\n", _font_id, _name.c_str(), _copyright.c_str()); 131 | } 132 | -------------------------------------------------------------------------------- /src/tags/DefineFont.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | #ifndef __DEFINE_FONT_H__ 5 | #define __DEFINE_FONT_H__ 6 | 7 | #include "tsTag.h" 8 | 9 | namespace tinyswf { 10 | 11 | class DefineFontTag : public ITag { 12 | uint16_t _character_id; 13 | int _font_style; 14 | std::string _font_name; 15 | std::vector _code_table; 16 | 17 | public: 18 | DefineFontTag( TagHeader& h ) 19 | :ITag( h ) 20 | {} 21 | 22 | virtual ~DefineFontTag() 23 | {} 24 | 25 | virtual bool read( Reader& reader, SWF&, MovieFrames& data ); 26 | 27 | virtual void print(); 28 | 29 | int getFontStyle(void) { return _font_style; } 30 | const std::string& getFontName(void) { return _font_name; } 31 | 32 | static ITag* create( TagHeader& header ) { 33 | return new DefineFontTag( header ); 34 | } 35 | }; 36 | 37 | //----------------------------------------------------------------------------- 38 | 39 | class DefineFontNameTag : public ITag { 40 | uint16_t _font_id; 41 | std::string _name; 42 | std::string _copyright; 43 | 44 | public: 45 | DefineFontNameTag( TagHeader& h ) 46 | :ITag( h ) 47 | {} 48 | 49 | virtual ~DefineFontNameTag() 50 | {} 51 | 52 | virtual bool read( Reader& reader, SWF&, MovieFrames& data ); 53 | 54 | virtual void print(); 55 | 56 | static ITag* create( TagHeader& header ) { 57 | return new DefineFontNameTag( header ); 58 | } 59 | }; 60 | 61 | 62 | }//namespace 63 | #endif//__DEFINE_FONT_H__ -------------------------------------------------------------------------------- /src/tags/DefineScalingGrid.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | #ifndef __DEFINE_SCALING_GRID_H__ 5 | #define __DEFINE_SCALING_GRID_H__ 6 | 7 | #include "tsTag.h" 8 | #include "tsReader.h" 9 | 10 | namespace tinyswf 11 | { 12 | class DefineScalingGridTag : public ITag { 13 | uint16_t _character_id; 14 | RECT _center; 15 | 16 | public: 17 | DefineScalingGridTag( TagHeader& h ) 18 | :ITag( h ) 19 | {} 20 | 21 | virtual ~DefineScalingGridTag() 22 | {} 23 | 24 | virtual bool read( Reader& reader, SWF&, MovieFrames& ) 25 | { 26 | _character_id = reader.get(); 27 | reader.getRectangle(_center); 28 | reader.align(); 29 | return false;//delete tag 30 | } 31 | 32 | virtual void print() { 33 | _header.print(); 34 | SWF_TRACE("id=%d, ", _character_id); 35 | SWF_TRACE("RECT:{%.2f,%.2f,%.2f,%.2f}\n", 36 | _center.xmin, _center.ymin, 37 | _center.xmax, _center.ymax); 38 | } 39 | 40 | static ITag* create( TagHeader& header ) { 41 | return new DefineScalingGridTag( header ); 42 | } 43 | }; 44 | } 45 | #endif//__DEFINE_SCALING_GRID_H__ -------------------------------------------------------------------------------- /src/tags/DefineShape.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __DEFINE_SHAPE_H__ 6 | #define __DEFINE_SHAPE_H__ 7 | 8 | #include "tsTag.h" 9 | #include "VectorEngine.h" 10 | 11 | namespace tinyswf { 12 | 13 | class DefineShapeTag; 14 | 15 | //----------------------------------------------------------------------------- 16 | 17 | class Gradient { 18 | public: 19 | bool read( Reader* reader, bool support_32bit_color ); 20 | //void configPaint( VGPaint paint, uint8_t type, MATRIX& m, bool support_32bit_color); 21 | 22 | private: 23 | uint32_t _spread_mode; // 0 = Pad mode 1 = Reflect mode 2 = Repeat mode 24 | uint32_t _interpolation_mode; // 0 = Normal RGB mode interpolation 1 = Linear RGB mode interpolation 25 | uint32_t _num_gradients; 26 | 27 | struct Record { 28 | uint8_t _ratio; 29 | RGBA _color; 30 | }; 31 | 32 | typedef std::vector< Gradient::Record > GradientRecordArray; 33 | typedef GradientRecordArray::iterator GradientRecordArrayIter; 34 | 35 | GradientRecordArray _gradient_records; 36 | }; 37 | 38 | //----------------------------------------------------------------------------- 39 | 40 | class Edge { 41 | public: 42 | Edge( const POINT& anchor ) 43 | :_anchor(anchor) 44 | ,_control(anchor) 45 | {} 46 | 47 | Edge( const POINT& anchor, const POINT& ctrl ) 48 | :_anchor(anchor) 49 | ,_control(ctrl) 50 | {} 51 | 52 | const POINT& getAnchor() const { 53 | return _anchor; 54 | } 55 | 56 | const POINT& getControl() const { 57 | return _control; 58 | } 59 | 60 | void print() const { 61 | if (_anchor == _control) { 62 | SWF_TRACE("[line] anchor:%.2f, %.2f\n", _anchor.x, _anchor.y); 63 | } else { 64 | SWF_TRACE("[curve] anchor:%.2f, %.2f;\tctrl:%.2f, %.2f\n", _anchor.x, _anchor.y, _control.x, _control.y); 65 | } 66 | } 67 | 68 | protected: 69 | POINT _anchor; 70 | POINT _control; 71 | }; 72 | 73 | //----------------------------------------------------------------------------- 74 | 75 | class Path { 76 | public: 77 | typedef std::vector EdgeArray; 78 | 79 | const static int kINVALID = -1; 80 | 81 | Path() 82 | :_fill0( kINVALID ) 83 | ,_fill1( kINVALID ) 84 | ,_line( kINVALID ) 85 | ,_new_shape(false) 86 | { 87 | _start.x = 0.f; 88 | _start.y = 0.f; 89 | } 90 | 91 | void addEdge( const Edge& e ) { 92 | SWF_TRACE("add "); 93 | e.print(); 94 | _edges.push_back( e ); 95 | } 96 | 97 | bool isEmpty() const { 98 | return _edges.size() == 0; 99 | } 100 | 101 | POINT& getStart() { return _start; } 102 | 103 | EdgeArray& getEdges() { return _edges; } 104 | 105 | bool isClockWise(void) const; 106 | 107 | // style indices 108 | int _fill0; 109 | int _fill1; 110 | int _line; 111 | bool _new_shape; 112 | 113 | private: 114 | POINT _start; 115 | EdgeArray _edges; 116 | }; 117 | 118 | //----------------------------------------------------------------------------- 119 | 120 | class ShapeWithStyle { 121 | public: 122 | typedef std::vector FillStyleArray; 123 | typedef std::vector LineStyleArray; 124 | 125 | bool read( Reader& reader, SWF&, DefineShapeTag* define_shape_tag ); 126 | 127 | void draw(SWF *owner); 128 | 129 | void addMesh(size_t fill_idx) { 130 | SWF_ASSERT(0 <= fill_idx && _fill_styles.size() > fill_idx); 131 | Mesh mesh = { &_fill_styles[fill_idx], kNULL_ASSET }; 132 | _shapes.back()._meshes.push_back(mesh); 133 | } 134 | 135 | void addMeshVertex( const POINT& pt) { 136 | _shapes.back()._meshes.back()._vertices.push_back(pt); 137 | } 138 | 139 | void addLine(size_t line_idx) { 140 | SWF_ASSERT(0 <= line_idx && _line_styles.size() > line_idx); 141 | Line l = { &_line_styles[line_idx] }; 142 | _shapes.back()._lines.push_back(l); 143 | } 144 | 145 | void addLineVertex( const POINT& pt) { 146 | _shapes.back()._lines.back()._vertices.push_back(pt); 147 | } 148 | 149 | bool isInside(float x, float y) const; 150 | 151 | const FillStyleArray& getFillStyles(void) const { return _fill_styles; } 152 | 153 | private: 154 | struct Line { 155 | LineStyle *_style; 156 | VertexArray _vertices; 157 | }; 158 | struct Mesh { 159 | FillStyle *_style; 160 | Asset _asset; 161 | RECT _bound; 162 | VertexArray _vertices; 163 | 164 | bool isInsideMesh(const POINT& pt) const; 165 | }; 166 | typedef std::vector MeshArray; 167 | typedef std::vector LineArray; 168 | 169 | struct Shape { 170 | MeshArray _meshes; 171 | LineArray _lines; 172 | }; 173 | typedef std::vector ShapeArray; 174 | typedef std::vector PathArray; 175 | 176 | FillStyleArray _fill_styles; 177 | LineStyleArray _line_styles; 178 | PathArray _paths; 179 | ShapeArray _shapes; 180 | 181 | bool readStyles(Reader* reader, bool lineStyle2, bool support_32bit_color); 182 | 183 | bool readShapeRecords(Reader* reader, bool lineStyle2, bool support_32bit_color); 184 | 185 | bool triangluate(); 186 | }; 187 | 188 | //----------------------------------------------------------------------------- 189 | 190 | class DefineShapeTag : public ITag, public ICharacter { 191 | public: 192 | DefineShapeTag( TagHeader& h ) 193 | :ITag( h ) 194 | ,_shape_id(0) 195 | { 196 | } 197 | 198 | virtual ~DefineShapeTag() 199 | { 200 | } 201 | 202 | virtual bool read( Reader& reader, SWF&, MovieFrames& data ); 203 | virtual void print(); 204 | 205 | // override ICharacter function 206 | virtual const RECT& getRectangle(void) const { return _bound; } 207 | virtual void draw(SWF *owner); 208 | virtual void update(void) {} 209 | virtual ICharacter* getTopMost(float localX, float localY, bool polygonTest); 210 | virtual void onEvent(Event::Code) {} 211 | 212 | virtual TYPE type() const { return TYPE_SHAPE; } 213 | 214 | static ITag* create( TagHeader& header ); 215 | 216 | protected: 217 | uint16_t _shape_id; 218 | RECT _bound; 219 | ShapeWithStyle _shape_with_style; 220 | }; 221 | 222 | //----------------------------------------------------------------------------- 223 | 224 | } //namespace 225 | 226 | #endif // __DEFINE_SHAPE_H__ 227 | -------------------------------------------------------------------------------- /src/tags/DefineSound.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __DEFINE_SOUND_H__ 6 | #define __DEFINE_SOUND_H__ 7 | 8 | #include "tsTag.h" 9 | 10 | namespace tinyswf { 11 | 12 | class DefineSoundTag : public ITag 13 | { 14 | uint16_t _soundId; 15 | 16 | public: 17 | DefineSoundTag( TagHeader& h ) 18 | : ITag( h ) 19 | {} 20 | 21 | virtual ~DefineSoundTag() 22 | {} 23 | 24 | virtual bool read( Reader& reader, SWF& , MovieFrames& ) { 25 | _soundId = reader.get(); 26 | reader.skip( length()-2 ); 27 | return false;//delete tag 28 | } 29 | 30 | virtual void print() { 31 | _header.print(); 32 | SWF_TRACE("id=%d\n", _soundId); 33 | } 34 | 35 | static ITag* create( TagHeader& header ) { 36 | return new DefineSoundTag( header ); 37 | } 38 | }; 39 | 40 | //----------------------------------------------------------------------------- 41 | class StartSoundTag : public ITag 42 | { 43 | uint16_t _soundId; 44 | Asset _asset; 45 | bool _syncStop; 46 | bool _noMultiple; 47 | bool _loop; 48 | 49 | public: 50 | StartSoundTag( TagHeader& h ) 51 | : ITag( h ) 52 | {} 53 | 54 | virtual ~StartSoundTag() 55 | {} 56 | 57 | virtual bool read( Reader& reader, SWF& swf, MovieFrames&) { 58 | _soundId = reader.get(); 59 | // read SOUNDINFO 60 | reader.getbits(2);//reserved 61 | _syncStop = reader.getbits(1)!=0; 62 | _noMultiple = reader.getbits(1)!=0; 63 | uint32_t hasEnvelope= reader.getbits(1); 64 | _loop = reader.getbits(1)!=0; 65 | uint32_t hasOutPoint= reader.getbits(1); 66 | uint32_t hasInPoint = reader.getbits(1); 67 | SWF_UNUSED_PARAM(hasEnvelope); 68 | SWF_UNUSED_PARAM(hasOutPoint); 69 | SWF_UNUSED_PARAM(hasInPoint); 70 | 71 | reader.skip( length()-3 ); 72 | 73 | _asset = swf.getAsset(_soundId); 74 | return true; // keep tag 75 | } 76 | 77 | virtual void print() { 78 | _header.print(); 79 | SWF_TRACE("id=%d, stop:%d, noMultiple:%d, loop:%d\n", _soundId, _syncStop, _noMultiple, _loop); 80 | } 81 | 82 | virtual void setup(MovieClip&, bool skipAction) 83 | { 84 | SWF_UNUSED_PARAM(skipAction); 85 | Speaker *speaker = tinyswf::Speaker::getInstance(); 86 | if (NULL==speaker) return; 87 | speaker->playSound(_asset.handle, _syncStop, _noMultiple, _loop); 88 | } 89 | 90 | static ITag* create( TagHeader& header ) { 91 | return new StartSoundTag( header ); 92 | } 93 | }; 94 | 95 | }//namespace 96 | #endif // __DEFINE_SOUND_H__ -------------------------------------------------------------------------------- /src/tags/DefineSprite.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #include "DefineSprite.h" 6 | #include "tsSWF.h" 7 | 8 | using namespace tinyswf; 9 | 10 | DefineSpriteTag::~DefineSpriteTag() 11 | { 12 | MovieClip::destroyFrames(_data); 13 | } 14 | 15 | bool DefineSpriteTag::read( Reader& reader, SWF& swf, MovieFrames& ) { 16 | SWF_TRACE("=== DEFINE_SPRITE BEGIN ===\n"); 17 | _sprite_id = reader.get(); 18 | _frame_count = reader.get(); 19 | 20 | MovieClip::createFrames(reader, swf, _data); 21 | 22 | SWF_ASSERT(_data._frames.size() == _frame_count); 23 | SWF_TRACE("RECT:{%.2f,%.2f,%.2f,%.2f}\n", 24 | _data._rectangle.xmin, _data._rectangle.ymin, 25 | _data._rectangle.xmax, _data._rectangle.ymax); 26 | SWF_TRACE("=== DEFINE_SPRITE END ===\n"); 27 | swf.addCharacter( this, _sprite_id ); 28 | return true; // keep tag 29 | } 30 | 31 | void DefineSpriteTag::print() { 32 | _header.print(); 33 | SWF_TRACE("id=%d, frame_count=%d\n", _sprite_id, _frame_count); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/tags/DefineSprite.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __DEFINE_SPRITE_H__ 6 | #define __DEFINE_SPRITE_H__ 7 | 8 | #include "tsTag.h" 9 | 10 | namespace tinyswf { 11 | 12 | class DefineSpriteTag : public ITag { 13 | public: 14 | DefineSpriteTag( TagHeader& h ) 15 | : ITag( h ) 16 | { 17 | } 18 | 19 | virtual ~DefineSpriteTag(); 20 | 21 | virtual bool read( Reader& reader, SWF&, MovieFrames& ); 22 | virtual void print(); 23 | 24 | const MovieFrames& getMovieFrames(void) const { return _data; } 25 | 26 | static ITag* create( TagHeader& header ) { 27 | return new DefineSpriteTag( header ); 28 | } 29 | 30 | private: 31 | uint16_t _sprite_id; 32 | uint16_t _frame_count; 33 | MovieFrames _data; 34 | }; 35 | 36 | }//namespace 37 | #endif // __DEFINE_SPRITE_H__ 38 | -------------------------------------------------------------------------------- /src/tags/DefineText.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | #ifndef __DEFINE_TEXT_H__ 5 | #define __DEFINE_TEXT_H__ 6 | 7 | #include "tsTag.h" 8 | 9 | namespace tinyswf { 10 | 11 | struct TextRecord { 12 | struct Glyph { 13 | int _index; 14 | float _advance; 15 | }; 16 | 17 | struct Style { 18 | uint16_t _font_id; 19 | float _font_height; 20 | float _XOffset; 21 | float _YOffset; 22 | COLOR4f _color; 23 | bool read(Reader& reader, int tag_type, int flag); 24 | }; 25 | 26 | typedef std::vector GlyphArray; 27 | 28 | Style _style; 29 | GlyphArray _glyphs; 30 | 31 | bool read(Reader& reader, int tag_type, int flag, int glyph_bits, int advance_bits, Style& prev); 32 | }; 33 | 34 | //----------------------------------------------------------------------------- 35 | 36 | class DefineTextTag : public ITag { 37 | typedef std::vector TextArray; 38 | 39 | uint16_t _character_id; 40 | RECT _bound; 41 | MATRIX _transform; 42 | TextArray _texts; 43 | 44 | public: 45 | DefineTextTag( TagHeader& h ) 46 | :ITag( h ) 47 | {} 48 | 49 | virtual ~DefineTextTag() 50 | {} 51 | 52 | virtual bool read( Reader& reader, SWF&, MovieFrames& data ); 53 | 54 | virtual void print(); 55 | 56 | static ITag* create( TagHeader& header ) { 57 | return new DefineTextTag( header ); 58 | } 59 | }; 60 | 61 | //----------------------------------------------------------------------------- 62 | 63 | class DefineEditTextTag : public ITag { 64 | friend class Text; 65 | uint16_t _character_id; 66 | uint16_t _font_id; 67 | uint16_t _max_length; 68 | bool _html; 69 | RECT _bound; 70 | TextStyle _style; 71 | std::string _font_class; 72 | std::string _variable_name; 73 | std::string _initial_text; 74 | 75 | public: 76 | DefineEditTextTag( TagHeader& h ) 77 | :ITag( h ) 78 | ,_character_id(0) 79 | ,_font_id(0) 80 | ,_max_length(0) 81 | ,_html(false) 82 | {} 83 | 84 | virtual ~DefineEditTextTag() 85 | {} 86 | 87 | virtual bool read( Reader& reader, SWF&, MovieFrames& data ); 88 | 89 | virtual void print(); 90 | 91 | const RECT& getRectangle(void) const { return _bound; } 92 | 93 | std::string& getName(void) { return _variable_name; } 94 | 95 | static ITag* create( TagHeader& header ) { 96 | return new DefineEditTextTag( header ); 97 | } 98 | }; 99 | 100 | }//namespace 101 | #endif//__DEFINE_TEXT_H__ -------------------------------------------------------------------------------- /src/tags/DoAction.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #include "DoAction.h" 6 | #include "tsSWF.h" 7 | 8 | using namespace tinyswf; 9 | 10 | enum ACTION_CODE 11 | { 12 | //SWF 3 action model 13 | ACTION_NEXT_FRAME = 0x04, 14 | ACTION_PREV_FRAME = 0x05, 15 | ACTION_PLAY = 0x06, 16 | ACTION_STOP = 0x07, 17 | ACTION_TOGGLE_QUALITY = 0x08, 18 | ACTION_STOP_SOUNDS = 0x09, 19 | ACTION_GOTO_FRAME = 0x81, 20 | ACTION_GET_URL = 0x83, 21 | ACTION_WAIT_FOR_FRAME = 0x8A, 22 | ACTION_SET_TARGET = 0x8B, 23 | ACTION_GOTO_LABEL = 0x8C, 24 | }; 25 | 26 | TagHeader DoActionTag::scButtonHeader; 27 | 28 | DoActionTag::~DoActionTag() { 29 | ActionArray::iterator it = moActions.begin(); 30 | while(moActions.end() != it) { 31 | delete [] it->buffer; 32 | it->buffer = NULL; 33 | ++it; 34 | } 35 | } 36 | 37 | bool DoActionTag::read( Reader& reader, SWF& , MovieFrames& ) 38 | { 39 | uint8_t code; 40 | do { 41 | code = reader.get(); 42 | ACTION action = {code, 0, 0, NULL}; 43 | if (code & 0x80) { 44 | // Action contains extra data. 45 | uint16_t length = reader.get(); 46 | int read = 0; 47 | switch(code) { 48 | case ACTION_GOTO_FRAME: 49 | action.data = reader.get(); 50 | read = 2; 51 | break; 52 | case ACTION_GOTO_LABEL: 53 | { 54 | int pos = reader.getCurrentPos(); 55 | const char *label = reader.getString(); 56 | action.data = strlen(label) + 1; 57 | action.buffer = new char[action.data]; 58 | memcpy(action.buffer, label, action.data); 59 | read = reader.getCurrentPos() - pos; 60 | } 61 | break; 62 | case ACTION_GET_URL: 63 | { 64 | // extract parameters 65 | int pos = reader.getCurrentPos(); 66 | const char* url = reader.getString(); 67 | const char *target = reader.getString(); 68 | if (strncmp("FSCommand:", url, 10) == 0) { 69 | action.padding = 1; 70 | url += 10; 71 | } 72 | action.data = strlen(url) + 1; 73 | const int paramSize = strlen(target) + 1; 74 | action.buffer = new char[action.data + paramSize]; 75 | memcpy(action.buffer, url, action.data); 76 | memcpy(action.buffer + action.data, target, paramSize); 77 | read = reader.getCurrentPos() - pos; 78 | } 79 | break; 80 | default: 81 | break; 82 | } 83 | reader.skip(length - read); 84 | } 85 | moActions.push_back(action); 86 | } while(0 != code); 87 | return true; // keep tag 88 | } 89 | 90 | void DoActionTag::setup(MovieClip& movie, bool skipAction) 91 | { 92 | if (skipAction) 93 | return; 94 | ActionArray::iterator it = moActions.begin(); 95 | while(moActions.end() != it) { 96 | const ACTION& action = (*it); 97 | switch(action.code) { 98 | case ACTION_PLAY: 99 | movie.play(true); 100 | break; 101 | case ACTION_STOP: 102 | movie.play(false); 103 | break; 104 | case ACTION_GOTO_FRAME: 105 | movie.gotoAndPlay(action.data); 106 | break; 107 | case ACTION_GOTO_LABEL: 108 | movie.gotoLabel(action.buffer); 109 | break; 110 | case ACTION_GET_URL: 111 | { 112 | SWF* swf = movie.getSWF(); 113 | if (! swf) break; 114 | const char *url = action.buffer; 115 | const char *target = action.buffer + action.data; 116 | swf->callGetURL(movie, 0 < action.padding, url, target); 117 | } 118 | break; 119 | case ACTION_NEXT_FRAME: 120 | movie.step(1, skipAction); 121 | break; 122 | case ACTION_PREV_FRAME: 123 | // TODO: reverse frame playback 124 | //movie.step(-1, skipAction); 125 | break; 126 | 127 | default: 128 | break; 129 | } 130 | ++it; 131 | } 132 | } 133 | 134 | -------------------------------------------------------------------------------- /src/tags/DoAction.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __DO_ACTION_H__ 6 | #define __DO_ACTION_H__ 7 | 8 | #include "tsTag.h" 9 | 10 | namespace tinyswf { 11 | 12 | //----------------------------------------------------------------------------- 13 | class DoActionTag : public ITag 14 | { 15 | struct ACTION { 16 | uint8_t code; 17 | uint8_t padding; 18 | uint16_t data; 19 | char *buffer; 20 | }; 21 | typedef std::vector ActionArray; 22 | ActionArray moActions; 23 | 24 | public: 25 | static TagHeader scButtonHeader; 26 | 27 | DoActionTag( TagHeader& h ) 28 | :ITag( h ) 29 | {} 30 | 31 | DoActionTag( ) 32 | :ITag( scButtonHeader ) 33 | {} 34 | 35 | virtual ~DoActionTag(); 36 | 37 | //restricted copy constructor 38 | DoActionTag( DoActionTag& action ); 39 | 40 | virtual bool read( Reader& reader, SWF& swf, MovieFrames& data); 41 | 42 | virtual void print() 43 | { 44 | _header.print(); 45 | ActionArray::iterator it = moActions.begin(); 46 | while(moActions.end()!=it) 47 | { 48 | SWF_TRACE("0x%x,", (*it).code); 49 | ++it; 50 | } 51 | SWF_TRACE("\n"); 52 | } 53 | 54 | virtual void setup(MovieClip&, bool skipAction); 55 | 56 | static ITag* create( TagHeader& header ) { 57 | return new DoActionTag( header ); 58 | } 59 | }; 60 | 61 | }//namespace 62 | #endif // __DO_ACTION_H__ -------------------------------------------------------------------------------- /src/tags/ExportAssets.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __EXPORT_ASSETS_H__ 6 | #define __EXPORT_ASSETS_H__ 7 | 8 | #include "tsTag.h" 9 | 10 | namespace tinyswf 11 | { 12 | class ExportAssetsTag : public ITag 13 | { 14 | uint16_t count; 15 | 16 | public: 17 | ExportAssetsTag( TagHeader& h ) 18 | : ITag( h ) 19 | {} 20 | 21 | virtual ~ExportAssetsTag() 22 | {} 23 | 24 | virtual bool read( Reader& reader, SWF& swf, MovieFrames&) { 25 | count = reader.get(); 26 | for (uint16_t i = 0; i < count; ++i) 27 | { 28 | uint16_t tag = reader.get(); 29 | const char *name = reader.getString(); 30 | swf.addAsset(tag, name, NULL ); 31 | SWF_TRACE("id=%d, symbol=%s\n", tag, name); 32 | } 33 | return false; // delete tag 34 | } 35 | 36 | virtual void print() { 37 | _header.print(); 38 | //SWF_TRACE("EXPORT_ASSETS:%d\n", count); 39 | } 40 | 41 | static ITag* create( TagHeader& header ) { 42 | return new ExportAssetsTag( header ); 43 | } 44 | }; 45 | 46 | }//namespace 47 | #endif // __EXPORT_ASSETS_H__ -------------------------------------------------------------------------------- /src/tags/FrameLabel.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | #ifndef __FRAME_LABEL_H__ 5 | #define __FRAME_LABEL_H__ 6 | 7 | #include "tsTag.h" 8 | 9 | namespace tinyswf 10 | { 11 | class FrameLabelTag : public ITag { 12 | std::string _label; 13 | 14 | public: 15 | FrameLabelTag( TagHeader& h ) 16 | : ITag( h ) 17 | {} 18 | 19 | virtual ~FrameLabelTag() 20 | {} 21 | 22 | virtual bool read( Reader& reader, SWF&, MovieFrames& data ) 23 | { 24 | const char* label = reader.getString(); 25 | //reader.skip( length() - _label.size() ); 26 | _label.assign( label ); 27 | data._labels[label] = data._frames.size(); 28 | return false;//delete tag 29 | } 30 | 31 | virtual void print() { 32 | _header.print(); 33 | SWF_TRACE("label:%s\n", _label.c_str()); 34 | } 35 | 36 | static ITag* create( TagHeader& header ) { 37 | return new FrameLabelTag( header ); 38 | } 39 | }; 40 | } 41 | #endif //__FRAME_LABEL_H__ -------------------------------------------------------------------------------- /src/tags/ImportAssets2.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __IMPORT_ASSETS2_H__ 6 | #define __IMPORT_ASSETS2_H__ 7 | 8 | #include "tsTag.h" 9 | 10 | namespace tinyswf 11 | { 12 | class ImportAssets2Tag : public ITag 13 | { 14 | ICharacter *_character; 15 | 16 | public: 17 | ImportAssets2Tag( TagHeader& h ) 18 | :ITag( h ) 19 | ,_character(NULL) 20 | {} 21 | 22 | virtual ~ImportAssets2Tag() 23 | {} 24 | 25 | ICharacter *getCharacter() { return _character; } 26 | 27 | virtual bool read( Reader& reader, SWF& swf, MovieFrames&) { 28 | const char *url = reader.getString(); 29 | reader.get();//reserved 30 | reader.get();//reserved 31 | uint16_t count = reader.get(); 32 | for (uint16_t i = 0; i < count; ++i) { 33 | uint16_t id = reader.get(); 34 | const char *name = reader.getString(); 35 | _character = swf.addAsset(id, name, url); 36 | SWF_TRACE("id=%d, symbol=%s from %s\n", id, name, url); 37 | if (_character) { 38 | swf.addCharacter( this, id ); 39 | return true; // keep tag 40 | } 41 | } 42 | return false; // delete tag 43 | } 44 | 45 | virtual void print() { 46 | _header.print(); 47 | } 48 | 49 | static ITag* create( TagHeader& header ) { 50 | return new ImportAssets2Tag( header ); 51 | } 52 | }; 53 | 54 | }//namespace 55 | #endif//__IMPORT_ASSETS2_H__ -------------------------------------------------------------------------------- /src/tags/PlaceObject.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __PLACE_OBJECT_H__ 6 | #define __PLACE_OBJECT_H__ 7 | 8 | #include "tsTag.h" 9 | #include "DoAction.h" 10 | 11 | namespace tinyswf { 12 | 13 | struct ButtonRecord; 14 | class MovieClip; 15 | class MovieObject; 16 | 17 | //----------------------------------------------------------------------------- 18 | 19 | struct ClipAction { 20 | public: 21 | enum EVENT { 22 | EVENT_KEY_UP = 1 << 7, 23 | EVENT_KEY_DOWN = 1 << 6, 24 | EVENT_MOUSE_UP = 1 << 5, 25 | EVENT_MOUSE_DOWN = 1 << 4, 26 | EVENT_MOUSE_MOVE = 1 << 3, 27 | EVENT_UNLOAD = 1 << 2, 28 | EVENT_ENTER_FRAME = 1 << 1, 29 | EVENT_LOAD = 1 << 0, 30 | EVENT_DRAG_OVER = 1 << 15, 31 | EVENT_ROLL_OUT = 1 << 14, 32 | EVENT_ROLL_OVER = 1 << 13, 33 | EVENT_RELEASE_OUTSIDE = 1 << 12, 34 | EVENT_RELEASE = 1 << 11, 35 | EVENT_PRESS = 1 << 10, 36 | EVENT_INITIALIZE = 1 << 9, 37 | EVENT_DATA = 1 << 8, 38 | //RESERVED_5BITS, 39 | EVENT_CONSTRUCT = 1 << 18, 40 | EVENT_KEY_PRESS = 1 << 17, 41 | EVENT_DRAG_OUT = 1 << 16, 42 | //RESERVED_8BITS, 43 | }; 44 | uint32_t _conditions; 45 | DoActionTag _actions; 46 | 47 | bool read( Reader& reader, SWF& swf, MovieFrames& frames, uint32_t flag ); 48 | void print() { SWF_TRACE("EventFlags[0x%x]\n",_conditions); _actions.print(); } 49 | }; 50 | 51 | //----------------------------------------------------------------------------- 52 | 53 | class PlaceObjectTag : public ITag 54 | { 55 | enum Mode { 56 | INVALID, 57 | PLACE, 58 | MOVE, 59 | REPLACE 60 | }; 61 | 62 | bool readPlaceObject3( Reader& reader, SWF&, MovieFrames& ); 63 | 64 | public: 65 | PlaceObjectTag( TagHeader& h ); 66 | PlaceObjectTag( const ButtonRecord& h, const char*name = "btn" ); 67 | 68 | virtual ~PlaceObjectTag(); 69 | 70 | virtual bool read( Reader& reader, SWF&, MovieFrames& ); 71 | 72 | virtual void print(); 73 | 74 | virtual void setup(MovieClip&, bool skipAction); 75 | 76 | uint16_t depth() const { return _depth; } 77 | uint16_t clipDepth() const { return _clip_depth; } 78 | uint16_t characterID() const { return _character_id; } 79 | 80 | MATRIX& transform() { return _transform; } 81 | 82 | const std::string& name() const { return _name; } 83 | 84 | void copyAttributes(MovieObject&); 85 | 86 | static ITag* create( TagHeader& header ) { 87 | return new PlaceObjectTag( header ); 88 | } 89 | 90 | void trigger(MovieClip&target, int e) const; 91 | 92 | const Filter* getFilter() const { return _dropShadow; } 93 | 94 | private: 95 | uint16_t _character_id; 96 | uint16_t _depth; 97 | uint16_t _clip_depth; 98 | 99 | uint8_t _has_matrix; 100 | uint8_t _has_clip_depth; 101 | uint32_t _has_color_transform; 102 | uint32_t _all_event_flags; 103 | 104 | Mode _placeMode; 105 | 106 | MATRIX _transform; 107 | CXFORM _cxform; 108 | std::string _name; 109 | 110 | Filter *_dropShadow; 111 | 112 | typedef std::vector ClipActionArray; 113 | ClipActionArray _actions; 114 | }; 115 | 116 | }//namespace 117 | #endif // __PLACE_OBJECT_H__ -------------------------------------------------------------------------------- /src/tags/RemoveObject.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __REMOVE_OBJECT_H__ 6 | #define __REMOVE_OBJECT_H__ 7 | 8 | #include "tsTag.h" 9 | #include "tsMovieClip.h" 10 | //#include "PlaceObject.h" 11 | 12 | namespace tinyswf { 13 | 14 | class RemoveObjectTag : public ITag { 15 | uint16_t _character_id; 16 | uint16_t _depth; 17 | 18 | public: 19 | RemoveObjectTag( TagHeader& h ) 20 | :ITag( h ) 21 | ,_character_id( 0 ) 22 | {} 23 | 24 | virtual ~RemoveObjectTag() 25 | {} 26 | 27 | uint16_t characterId() const { 28 | return _character_id; 29 | } 30 | uint16_t depth() const { 31 | return _depth; 32 | } 33 | 34 | virtual void setup(MovieClip &movie, bool skipAction ) 35 | { 36 | SWF_UNUSED_PARAM(skipAction); 37 | MovieClip::DisplayList& _display_list = movie.getDisplayList(); 38 | const uint16_t depth = this->depth(); 39 | MovieClip::DisplayList::iterator it = _display_list.find(depth); 40 | if (it == _display_list.end()) 41 | return; 42 | 43 | //PlaceObjectTag* current_obj = it->second;; 44 | //if (current_obj) current_obj->gotoFrame(ICharacter::kFRAME_MAXIMUM, skipAction); 45 | _display_list.erase(it); 46 | } 47 | 48 | virtual bool read( Reader& reader, SWF&, MovieFrames& ) { 49 | if ( code() == TAG_REMOVE_OBJECT ) 50 | { 51 | _character_id = reader.get(); 52 | } 53 | _depth = reader.get(); 54 | 55 | return true; // keep tag 56 | } 57 | 58 | virtual void print() { 59 | if( code() == TAG_REMOVE_OBJECT ) 60 | SWF_TRACE("REMOVEOBJECT id=%d, depth=%d\n", _character_id, _depth); 61 | else 62 | SWF_TRACE("REMOVEOBJECT2 depth=%d\n", _depth); 63 | } 64 | 65 | static ITag* create( TagHeader& header ) { 66 | return new RemoveObjectTag( header ); 67 | } 68 | }; 69 | 70 | }//namespace 71 | #endif // __REMOVE_OBJECT_H__ -------------------------------------------------------------------------------- /src/tags/SetBackgroundColor.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __BACKGROUND_H__ 6 | #define __BACKGROUND_H__ 7 | 8 | #include "tsTag.h" 9 | 10 | namespace tinyswf 11 | { 12 | class SetBackgroundColorTag : public ITag { 13 | public: 14 | uint8_t r,g,b; 15 | 16 | SetBackgroundColorTag( TagHeader& h ) 17 | : ITag( h ) 18 | {} 19 | 20 | virtual ~SetBackgroundColorTag() 21 | {} 22 | 23 | virtual bool read( Reader& reader, SWF& swf, MovieFrames& ) { 24 | r = reader.get(); 25 | g = reader.get(); 26 | b = reader.get(); 27 | 28 | COLOR4f &color = swf.getBackgroundColor(); 29 | color.r = r * SWF_INV_COLOR; 30 | color.g = g * SWF_INV_COLOR; 31 | color.b = b * SWF_INV_COLOR; 32 | color.a = 1.f; 33 | return false; // delete tag 34 | } 35 | 36 | virtual void print() { 37 | _header.print(); 38 | SWF_TRACE("color:%d,%d,%d\n", r,g,b); 39 | } 40 | 41 | static ITag* create( TagHeader& header ) { 42 | return new SetBackgroundColorTag( header ); 43 | } 44 | }; 45 | 46 | }//namespace 47 | #endif // __BACKGROUND_H__ -------------------------------------------------------------------------------- /src/tags/ShowFrame.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __SHOW_FRAME_H__ 6 | #define __SHOW_FRAME_H__ 7 | 8 | #include "tsTag.h" 9 | 10 | namespace tinyswf { 11 | 12 | class ShowFrameTag : public ITag { 13 | public: 14 | ShowFrameTag( TagHeader& h ) 15 | : ITag( h ) 16 | {} 17 | 18 | virtual ~ShowFrameTag() 19 | {} 20 | 21 | virtual bool read( Reader& , SWF&, MovieFrames& ) { return false; } //delete tag 22 | 23 | virtual void print() { SWF_TRACE("SHOW_FRAME"); } 24 | 25 | static ITag* create( TagHeader& header ) { 26 | return new ShowFrameTag( header ); 27 | } 28 | }; 29 | 30 | }//namespace 31 | #endif // __SHOW_FRAME_H__ -------------------------------------------------------------------------------- /src/tags/VectorEngine.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #ifndef __VECTOR_ENGINE__ 6 | #define __VECTOR_ENGINE__ 7 | 8 | //----------------------------------------------------------------------------- 9 | 10 | namespace tinyswf { 11 | class ShapeWithStyle; 12 | class Path; 13 | } 14 | 15 | //----------------------------------------------------------------------------- 16 | 17 | namespace triangulation { 18 | void create_memory_pool(int size); 19 | void destroy_memory_pool(void); 20 | void begin_shape(void); 21 | void add_collector(tinyswf::ShapeWithStyle& shape, tinyswf::Path&); 22 | void end_shape(tinyswf::ShapeWithStyle&); 23 | } 24 | 25 | //----------------------------------------------------------------------------- 26 | 27 | #endif//__VECTOR_ENGINE__ -------------------------------------------------------------------------------- /src/tsHeader.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #include "tsHeader.h" 6 | #include "tsReader.h" 7 | 8 | #ifdef WIN32 9 | #include 10 | //#define USE_ZLIB 11 | #endif 12 | 13 | #ifdef USE_ZLIB 14 | #include "..\zlib\include\zlib.h" 15 | #pragma comment(lib, "../../zlib/lib/zdll.lib") 16 | #endif 17 | 18 | using namespace std; 19 | 20 | short int endianSwap16(short int val) 21 | { 22 | long int i = 1; 23 | const char *p = (const char *) &i; 24 | if (p[0] == 1) // Lowest address contains the least significant byte 25 | { 26 | return (((val & 0xff00) >> 8) | ((val & 0x00ff) << 8)); 27 | } 28 | return val; 29 | } 30 | 31 | namespace tinyswf { 32 | 33 | bool Header::read( Reader& reader ) { 34 | // little endian 35 | long int i = 0x12345678; 36 | const char *p = (const char*) &i; 37 | assert(0x78 == *p); 38 | 39 | _signature[0] = reader.get(); 40 | _signature[1] = reader.get(); 41 | _signature[2] = reader.get(); 42 | 43 | _version = reader.get(); 44 | assert(5 < _version); 45 | 46 | _file_length = reader.get(); 47 | 48 | if ( _signature[0] == 'C' ) { 49 | #ifdef USE_ZLIB 50 | SWF_TRACE("** inflate: %d bytes ***\n", _file_length); 51 | // uncompressed file 52 | _outputBuffer = new char[_file_length]; 53 | 54 | z_stream stream; 55 | const int MAX_BUFFER = 128 * 1024; 56 | unsigned char * inputBuffer = new unsigned char[ MAX_BUFFER ]; 57 | int status; 58 | 59 | stream.avail_in = 0; 60 | stream.next_in = inputBuffer; 61 | stream.next_out = (Bytef*) _outputBuffer; 62 | stream.zalloc = (alloc_func) NULL; 63 | stream.zfree = (free_func) NULL; 64 | stream.opaque = (voidpf) 0; 65 | stream.avail_out = _file_length; 66 | 67 | status = inflateInit( &stream ); 68 | 69 | if( status != Z_OK ) { 70 | fprintf( stderr, "Error decompressing SWF: %s\n", stream.msg ); 71 | delete [] inputBuffer; 72 | return false; 73 | } 74 | 75 | do { 76 | if ( stream.avail_in == 0 ) { 77 | stream.next_in = inputBuffer; 78 | stream.avail_in = reader.getBytes( MAX_BUFFER, inputBuffer ); 79 | } 80 | if ( stream.avail_in == 0 ) 81 | break; 82 | status = inflate( &stream, Z_SYNC_FLUSH ); 83 | } while( status == Z_OK ); 84 | 85 | (void)inflateEnd(&stream); 86 | delete [] inputBuffer; 87 | 88 | if( status != Z_STREAM_END && status != Z_OK ) { 89 | fprintf( stderr, "Error decompressing SWF: %s\n", stream.msg ); 90 | return false; 91 | } 92 | reader.setNewData( _outputBuffer, _file_length ); 93 | #else 94 | return false; 95 | #endif 96 | } 97 | 98 | 99 | // get the bound rectangle 100 | reader.getRectangle(_frame_size); 101 | reader.align(); 102 | uint16_t fr = reader.get(); 103 | _frame_rate = 1.f/(fr>>8); 104 | _frame_count = reader.get(); 105 | 106 | return true; 107 | } 108 | 109 | void Header::print() { 110 | SWF_TRACE("signature:\t%c%c%c\n",_signature[0], _signature[1], _signature[2]); 111 | SWF_TRACE("version:\t\t%d\n", _version); 112 | SWF_TRACE("file length:\t%d\n", _file_length); 113 | SWF_TRACE("frame width:\t%f\n", getFrameWidth()); 114 | SWF_TRACE("frame height:\t%f\n", getFrameHeight()); 115 | SWF_TRACE("frame rate:\t%f\n", _frame_rate); 116 | SWF_TRACE("frame count:\t%d\n", _frame_count); 117 | } 118 | 119 | #ifdef WIN32 120 | void Log(const char* szmsg, ...) { 121 | const int kMAXIMUM = 1024; 122 | static char buffer[kMAXIMUM]; 123 | va_list arglist; 124 | va_start(arglist, szmsg); 125 | { 126 | vsprintf_s(buffer,kMAXIMUM,szmsg,arglist); 127 | OutputDebugString(buffer); 128 | } 129 | va_end(arglist); 130 | } 131 | #endif 132 | 133 | }//namespace -------------------------------------------------------------------------------- /src/tsTag.cpp: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | 5 | #include "tsTag.h" 6 | #include "tsReader.h" 7 | 8 | using namespace std; 9 | 10 | namespace tinyswf { 11 | 12 | #ifdef SWF_DEBUG 13 | std::map TagHeader::_tagNames; 14 | 15 | int TagHeader::initialize() { 16 | _tagNames[TAG_END]="END"; 17 | _tagNames[TAG_SHOW_FRAME]="SHOW_FRAME"; 18 | _tagNames[TAG_DEFINE_SHAPE]="DEFINE_SHAPE"; 19 | _tagNames[TAG_PLACE_OBJECT]="PLACE_OBJECT"; 20 | _tagNames[TAG_REMOVE_OBJECT]="REMOVE_OBJECT"; 21 | _tagNames[TAG_DEFINE_BITS]="DEFINE_BITS"; 22 | _tagNames[TAG_DEFINE_BUTTON]="DEFINE_BUTTON"; 23 | _tagNames[TAG_JPEG_TABLES]="JPEG_TABLES"; 24 | _tagNames[TAG_SET_BACKGROUND_COLOR]="SET_BACKGROUND_COLOR"; 25 | _tagNames[TAG_DEFINE_FONT]="DEFINE_FONT"; 26 | _tagNames[TAG_DEFINE_TEXT]="DEFINE_TEXT"; 27 | _tagNames[TAG_DO_ACTION]="DO_ACTION"; 28 | _tagNames[TAG_DEFINE_FONT_INFO]="DEFINE_FONT_INFO"; 29 | _tagNames[TAG_DEFINE_SOUND]="DEFINE_SOUND"; 30 | _tagNames[TAG_START_SOUND]="START_SOUND"; 31 | _tagNames[TAG_DEFINE_BUTTON_SOUND]="DEFINE_BUTTON_SOUND"; 32 | _tagNames[TAG_SOUND_STREAM_HEAD]="SOUND_STREAM_HEAD"; 33 | _tagNames[TAG_SOUND_STREAM_BLOCK]="SOUND_STREAM_BLOCK"; 34 | _tagNames[TAG_DEFINE_BITS_LOSSLESS]="DEFINE_BITS_LOSSLESS"; 35 | _tagNames[TAG_DEFINE_BITS_JPEG2]="DEFINE_BITS_JPEG2"; 36 | _tagNames[TAG_DEFINE_SHAPE2]="DEFINE_SHAPE2"; 37 | _tagNames[TAG_DEFINE_BUTTON_CXFORM]="DEFINE_BUTTON_CXFORM"; 38 | _tagNames[TAG_PROTECT]="PROTECT"; 39 | _tagNames[TAG_PLACE_OBJECT2]="PLACE_OBJECT2"; 40 | _tagNames[TAG_REMOVE_OBJECT2]="REMOVE_OBJECT2"; 41 | _tagNames[TAG_DEFINE_SHAPE3]="DEFINE_SHAPE3"; 42 | _tagNames[TAG_DEFINE_TEXT2]="DEFINE_TEXT2"; 43 | _tagNames[TAG_DEFINE_BUTTON2]="DEFINE_BUTTON2"; 44 | _tagNames[TAG_DEFINE_BITS_JPEG3]="DEFINE_BITS_JPEG3"; 45 | _tagNames[TAG_DEFINE_BITS_LOSSLESS2]="DEFINE_BITS_LOSSLESS2"; 46 | _tagNames[TAG_DEFINE_EDIT_TEXT]="DEFINE_EDIT_TEXT"; 47 | _tagNames[TAG_DEFINE_SPRITE]="DEFINE_SPRITE"; 48 | _tagNames[TAG_FRAME_LABEL]="FRAME_LABEL"; 49 | _tagNames[TAG_SOUND_STREAM_HEAD2]="SOUND_STREAM_HEAD2"; 50 | _tagNames[TAG_DEFINE_MORPH_SHAPE]="DEFINE_MORPH_SHAPE"; 51 | _tagNames[TAG_DEFINE_FONT2]="DEFINE_FONT2"; 52 | _tagNames[TAG_EXPORT_ASSETS]="EXPORT_ASSETS"; 53 | _tagNames[TAG_IMPORT_ASSETS]="IMPORT_ASSETS"; 54 | _tagNames[TAG_ENABLE_DEBUGGER]="ENABLE_DEBUGGER"; 55 | _tagNames[TAG_DO_INIT_ACTION]="DO_INIT_ACTION"; 56 | _tagNames[TAG_DEFINE_VIDEO_STREAM]="DEFINE_VIDEO_STREAM"; 57 | _tagNames[TAG_VIDEO_FRAME]="VIDEO_FRAME"; 58 | _tagNames[TAG_DEFINE_FONT_INFO2]="DEFINE_FONT_INFO2"; 59 | _tagNames[TAG_ENABLE_DEBUGGER2]="ENABLE_DEBUGGER2"; 60 | _tagNames[TAG_SCRIPT_LIMITS]="SCRIPT_LIMITS"; 61 | _tagNames[TAG_SET_TAB_INDEX]="SET_TAB_INDEX"; 62 | _tagNames[TAG_FILE_ATTRIBUTES]="FILE_ATTRIBUTES"; 63 | _tagNames[TAG_PLACE_OBJECT3]="PLACE_OBJECT3"; 64 | _tagNames[TAG_IMPORT_ASSETS2]="IMPORT_ASSETS2"; 65 | _tagNames[TAG_DEFINE_FONT_ALIGN_ZONES]="DEFINE_FONT_ALIGN_ZONES"; 66 | _tagNames[TAG_DEFINE_CSM_TEXT_SETTINGS]="DEFINE_CSM_TEXT_SETTINGS"; 67 | _tagNames[TAG_DEFINE_FONT3]="DEFINE_FONT3"; 68 | _tagNames[TAG_SYMBOL_CLASS]="SYMBOL_CLASS"; 69 | _tagNames[TAG_METADATA]="METADATA"; 70 | _tagNames[TAG_DEFINE_SCALING_GRID]="DEFINE_SCALING_GRID"; 71 | _tagNames[TAG_DO_ABC]="DO_ABC"; 72 | _tagNames[TAG_DEFINE_SHAPE4]="DEFINE_SHAPE4"; 73 | _tagNames[TAG_DEFINE_MORPH_SHAPE2]="DEFINE_MORPH_SHAPE2"; 74 | _tagNames[TAG_DEFINE_SCENE_AND_FRAME_LABEL_DATA]="DEFINE_SCENE_AND_FRAME_LABEL_DATA"; 75 | _tagNames[TAG_DEFINE_BINARY_DATA]="DEFINE_BINARY_DATA"; 76 | _tagNames[TAG_DEFINE_FONT_NAME]="DEFINE_FONT_NAME"; 77 | _tagNames[TAG_DEFINE_START_SOUND2]="DEFINE_START_SOUND2"; 78 | _tagNames[TAG_DEFINE_BITS_JPEG4]="DEFINE_BITS_JPEG4"; 79 | _tagNames[TAG_DEFINE_FONT4]="DEFINE_FONT4"; 80 | return 0; 81 | } 82 | const int kTagInitialize = TagHeader::initialize(); 83 | #endif 84 | 85 | bool TagHeader::read( Reader& reader ) { 86 | uint16_t tagcode_and_length = reader.get(); 87 | 88 | _code = (tagcode_and_length >> 6 ); 89 | _length = (tagcode_and_length & 0x3F ); 90 | if( _length == 0x3f ) // if long tag read an additional 32 bit length value 91 | _length = reader.get(); 92 | 93 | return true; 94 | } 95 | 96 | void TagHeader::print() { 97 | SWF_TRACE("%s\tcode:%2d, length:%d\n", name(), _code , _length); 98 | } 99 | 100 | 101 | void MATRIX::transform(RECT& result, const RECT& p) const { 102 | POINT in[4] = { 103 | {p.xmin, p.ymin}, 104 | {p.xmin, p.ymax}, 105 | {p.xmax, p.ymin}, 106 | {p.xmax, p.ymax} 107 | }; 108 | RECT rect = {FLT_MAX,FLT_MAX,-FLT_MAX,-FLT_MAX}; 109 | for (int i = 0; i < 4; ++i) { 110 | POINT other; 111 | transform(other, in[i]); 112 | if (other.x < rect.xmin) 113 | rect.xmin = other.x; 114 | else if (other.x > rect.xmax) 115 | rect.xmax = other.x; 116 | if (other.y < rect.ymin) 117 | rect.ymin = other.y; 118 | else if (other.y > rect.ymax) 119 | rect.ymax = other.y; 120 | } 121 | result = rect; 122 | } 123 | 124 | }//namespace -------------------------------------------------------------------------------- /swf-file-format-spec.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/swf-file-format-spec.pdf -------------------------------------------------------------------------------- /test/beer.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/beer.swf -------------------------------------------------------------------------------- /test/clown.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/clown.swf -------------------------------------------------------------------------------- /test/cupid.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/cupid.swf -------------------------------------------------------------------------------- /test/daisies.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/daisies.swf -------------------------------------------------------------------------------- /test/dog.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/dog.swf -------------------------------------------------------------------------------- /test/giraffe.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/giraffe.swf -------------------------------------------------------------------------------- /test/hole.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/hole.swf -------------------------------------------------------------------------------- /test/intersect3.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/intersect3.swf -------------------------------------------------------------------------------- /test/monkey.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monkey.swf -------------------------------------------------------------------------------- /test/monster/foot_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/foot_0.png -------------------------------------------------------------------------------- /test/monster/foot_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/foot_a.png -------------------------------------------------------------------------------- /test/monster/forearm_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/forearm_0.png -------------------------------------------------------------------------------- /test/monster/forearm_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/forearm_a.png -------------------------------------------------------------------------------- /test/monster/hand_0_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/hand_0_0.png -------------------------------------------------------------------------------- /test/monster/hand_0_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/hand_0_1.png -------------------------------------------------------------------------------- /test/monster/hand_0_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/hand_0_2.png -------------------------------------------------------------------------------- /test/monster/hand_0_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/hand_0_3.png -------------------------------------------------------------------------------- /test/monster/hand_a_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/hand_a_0.png -------------------------------------------------------------------------------- /test/monster/hand_a_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/hand_a_1.png -------------------------------------------------------------------------------- /test/monster/hand_a_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/hand_a_2.png -------------------------------------------------------------------------------- /test/monster/hand_a_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/hand_a_3.png -------------------------------------------------------------------------------- /test/monster/head_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/head_0.png -------------------------------------------------------------------------------- /test/monster/head_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/head_1.png -------------------------------------------------------------------------------- /test/monster/head_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/head_2.png -------------------------------------------------------------------------------- /test/monster/head_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/head_3.png -------------------------------------------------------------------------------- /test/monster/monster.fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/monster.fla -------------------------------------------------------------------------------- /test/monster/monster.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/monster.swf -------------------------------------------------------------------------------- /test/monster/pelvis_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/pelvis_0.png -------------------------------------------------------------------------------- /test/monster/shoulder_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/shoulder_0.png -------------------------------------------------------------------------------- /test/monster/shoulder_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/shoulder_a.png -------------------------------------------------------------------------------- /test/monster/test.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/test.wav -------------------------------------------------------------------------------- /test/monster/thigh_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/thigh_0.png -------------------------------------------------------------------------------- /test/monster/thigh_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/thigh_a.png -------------------------------------------------------------------------------- /test/monster/torso_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/monster/torso_0.png -------------------------------------------------------------------------------- /test/puppy.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/puppy.swf -------------------------------------------------------------------------------- /test/splashscreen.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/splashscreen.swf -------------------------------------------------------------------------------- /test/squares.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/squares.swf -------------------------------------------------------------------------------- /test/tatoo.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/tatoo.swf -------------------------------------------------------------------------------- /test/test.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/test.swf -------------------------------------------------------------------------------- /test/transportation.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/transportation.swf -------------------------------------------------------------------------------- /test/venus_fly_trap.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/venus_fly_trap.swf -------------------------------------------------------------------------------- /test/whitebird1.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/test/whitebird1.swf -------------------------------------------------------------------------------- /tsviewer/proj.vc11/FontCache.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | Copyright (c) 2013 jbyu. All rights reserved. 3 | ******************************************************************************/ 4 | #ifndef __FONT_CACHE_H__ 5 | #define __FONT_CACHE_H__ 6 | 7 | #include "tinyswf.h" 8 | #include "lru_cache.h" 9 | 10 | const int kGLYPH_WIDTH = 32; 11 | 12 | struct GlyphInfo { 13 | float advance; 14 | float offsetX; 15 | float offsetY; 16 | char width; 17 | char height; 18 | unsigned short index; 19 | }; 20 | 21 | class OSFont { 22 | friend class GLFontHandler; 23 | 24 | typedef const void* Handle; 25 | typedef LRUCache GlyphCache; 26 | 27 | GlyphCache *_cache; 28 | unsigned int _bitmap; 29 | Handle _font; 30 | 31 | public: 32 | OSFont(const char *font_name, float fontsize, int style); 33 | ~OSFont(); 34 | 35 | GlyphInfo* getGlyph(wchar_t code); 36 | float getLineHeight(void) { return getLineHeight(_font); } 37 | 38 | protected: 39 | // platform-dependent 40 | static bool initialize(void); 41 | static void terminate(void); 42 | static Handle create(const char *font_name, float fontsize, int style); 43 | static void destroy(const Handle& font); 44 | static bool makeGlyph(const Handle& font, wchar_t codepoint, GlyphInfo& entry); 45 | static float getLineHeight(const Handle& font); 46 | static void* getGlyphBitmap(); 47 | }; 48 | 49 | //----------------------------------------------------------------------------- 50 | 51 | class GLFontHandler : public tinyswf::FontHandler { 52 | typedef std::map CacheData; 53 | 54 | CacheData _font_cache; 55 | OSFont* _selectedFont; 56 | 57 | OSFont* selectFont(const char *font_name, float fontsize, int style); 58 | 59 | public: 60 | GLFontHandler(); 61 | 62 | virtual ~GLFontHandler(); 63 | 64 | void drawText(const tinyswf::VertexArray& vertices, uint32_t glyphs, const tinyswf::CXFORM& cxform, const tinyswf::TextStyle& style); 65 | 66 | uint32_t formatText(tinyswf::VertexArray& vertices, float &lastX, float &lastY, 67 | const tinyswf::RECT& rect, const tinyswf::TextStyle& style, const std::wstring& text); 68 | 69 | GlyphInfo* getGlyph(wchar_t codepoint) { 70 | return _selectedFont->getGlyph(codepoint); 71 | } 72 | 73 | float getLineHeight(void) { 74 | return _selectedFont->getLineHeight(); 75 | } 76 | }; 77 | 78 | #endif//__FONT_CACHE_H__ -------------------------------------------------------------------------------- /tsviewer/proj.vc11/FontCache_win32.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | 4 | #ifdef WIN32 5 | #include "FontCache.h" 6 | 7 | #define STBTT_malloc(x,u) malloc(x) 8 | #define STBTT_free(x,u) free(x) 9 | #define STB_TRUETYPE_IMPLEMENTATION 10 | #include "stb_truetype.h" 11 | 12 | using namespace tinyswf; 13 | 14 | static HDC ghDC; 15 | 16 | static unsigned char *spSTBTT_BITMAP = NULL; 17 | 18 | struct SYSFONT { 19 | stbtt_fontinfo info; 20 | float ascent; 21 | float descent; 22 | float line_height; 23 | float scale; 24 | //TEXTMETRIC metric; 25 | //HFONT hFont; 26 | }; 27 | 28 | 29 | bool OSFont::initialize(void) { 30 | spSTBTT_BITMAP = new unsigned char[kGLYPH_WIDTH * kGLYPH_WIDTH]; 31 | HDC hdc = GetDC(NULL); 32 | ghDC = CreateCompatibleDC(hdc); 33 | ReleaseDC(NULL, hdc); 34 | return true; 35 | } 36 | 37 | enum FONT_STYLE { 38 | FLAG_ITALIC = 0x02, 39 | FLAG_BOLD = 0x01 40 | }; 41 | 42 | OSFont::Handle OSFont::create(const char *fontname, float fontsize, int style) { 43 | SYSFONT *font = new SYSFONT; 44 | float height = fontsize * GetDeviceCaps(ghDC, LOGPIXELSY) / 72.f; 45 | 46 | bool bItalic = (FLAG_ITALIC & style) > 0; 47 | int weight = FW_NORMAL; 48 | if (FLAG_BOLD & style) { 49 | weight = FW_BOLD; 50 | } 51 | 52 | HFONT hFont = CreateFont((int)height, 0, 0, 0, 53 | weight, bItalic, FALSE, FALSE, 54 | DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, 55 | fontname); 56 | SelectObject(ghDC, hFont); 57 | //GetTextMetrics(ghDC, &font->metric); 58 | 59 | DWORD tag = 0x66637474;//ttcf 60 | int size = GetFontData(ghDC, tag, 0, NULL, 0); 61 | if (-1 == size) { 62 | tag = 0; 63 | size = GetFontData(ghDC, tag, 0, NULL, 0); 64 | } 65 | void *pData = new char[size]; 66 | GetFontData(ghDC, tag, 0, pData, size); 67 | DeleteObject(hFont); 68 | 69 | int start = stbtt_GetFontOffsetForIndex( (const unsigned char *)pData, 0); 70 | if (0 != tag) { 71 | //start = stbtt_FindMatchingFont((const unsigned char *)pData, fontname, STBTT_MACSTYLE_DONTCARE); 72 | } 73 | //CCASSERT(0 <= start, "no such font!"); 74 | if (stbtt_InitFont(&font->info, (const unsigned char *)pData, start)) { 75 | // Store normalized line height. The real line height is got by multiplying the lineh by font size. 76 | int ascent, descent, lineGap; 77 | stbtt_GetFontVMetrics(&font->info, &ascent, &descent, &lineGap); 78 | //fh = ascent - descent; 79 | //fnt->ascender = (float)ascent / (float)fh; 80 | //fnt->descender = (float)descent / (float)fh; 81 | //fnt->lineh = (float)(fh + lineGap) / (float)fh; 82 | float scale = stbtt_ScaleForPixelHeight(&font->info, height); 83 | font->ascent = ascent * scale; 84 | font->descent = descent * scale; 85 | font->line_height = (ascent - descent + lineGap) * scale; 86 | font->scale = scale; 87 | return font; 88 | } 89 | delete font; 90 | return NULL; 91 | } 92 | 93 | void OSFont::destroy(const Handle& handle) { 94 | SYSFONT *font = (SYSFONT*)handle; 95 | delete [] font->info.data; 96 | delete font; 97 | font = NULL; 98 | } 99 | 100 | void OSFont::terminate(void) { 101 | delete [] spSTBTT_BITMAP; 102 | spSTBTT_BITMAP = NULL; 103 | //DeleteObject(ghBitmap); 104 | DeleteDC(ghDC); 105 | } 106 | 107 | void* OSFont::getGlyphBitmap() { return spSTBTT_BITMAP; } 108 | 109 | float OSFont::getLineHeight(const Handle& handle) { 110 | SYSFONT *sysfont = (SYSFONT*)handle; 111 | return sysfont->line_height; 112 | } 113 | 114 | bool OSFont::makeGlyph(const Handle& handle, wchar_t codepoint, GlyphInfo& entry) { 115 | SYSFONT *sysfont = (SYSFONT*)handle; 116 | stbtt_fontinfo *font = &sysfont->info; 117 | int advance, lsb, x0, y0, x1, y1; 118 | int glyph = stbtt_FindGlyphIndex(font, codepoint); 119 | if (0 >= glyph) 120 | return false; 121 | 122 | float scale = sysfont->scale; 123 | 124 | stbtt_GetGlyphHMetrics(font, glyph, &advance, &lsb); 125 | stbtt_GetGlyphBitmapBox(font, glyph, scale, scale, &x0,&y0,&x1,&y1); 126 | 127 | int width = x1 - x0 +1; 128 | int height = y1 - y0+1; 129 | entry.advance = advance * scale; 130 | entry.offsetX = float(x0); 131 | entry.offsetY = sysfont->ascent + y0; 132 | entry.width = width; 133 | entry.height = height; 134 | 135 | memset(spSTBTT_BITMAP, 0, kGLYPH_WIDTH * kGLYPH_WIDTH); 136 | stbtt_MakeGlyphBitmap(font, spSTBTT_BITMAP, kGLYPH_WIDTH, kGLYPH_WIDTH, kGLYPH_WIDTH, scale, scale, glyph); 137 | 138 | #if 0 139 | const int offset = kGLYPH_WIDTH * (kGLYPH_WIDTH - 1); 140 | for(int i = 0; i < kGLYPH_WIDTH; ++i) { 141 | spSTBTT_BITMAP[i]=255; 142 | spSTBTT_BITMAP[i+offset]=255; 143 | } 144 | #endif 145 | return true; 146 | } 147 | 148 | #endif//WIN32 -------------------------------------------------------------------------------- /tsviewer/proj.vc11/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | CONSOLE APPLICATION : tsviewer Project Overview 3 | ======================================================================== 4 | 5 | AppWizard has created this tsviewer application for you. 6 | 7 | This file contains a summary of what you will find in each of the files that 8 | make up your tsviewer application. 9 | 10 | 11 | tsviewer.vcxproj 12 | This is the main project file for VC++ projects generated using an Application Wizard. 13 | It contains information about the version of Visual C++ that generated the file, and 14 | information about the platforms, configurations, and project features selected with the 15 | Application Wizard. 16 | 17 | tsviewer.vcxproj.filters 18 | This is the filters file for VC++ projects generated using an Application Wizard. 19 | It contains information about the association between the files in your project 20 | and the filters. This association is used in the IDE to show grouping of files with 21 | similar extensions under a specific node (for e.g. ".cpp" files are associated with the 22 | "Source Files" filter). 23 | 24 | tsviewer.cpp 25 | This is the main application source file. 26 | 27 | ///////////////////////////////////////////////////////////////////////////// 28 | Other standard files: 29 | 30 | StdAfx.h, StdAfx.cpp 31 | These files are used to build a precompiled header (PCH) file 32 | named tsviewer.pch and a precompiled types file named StdAfx.obj. 33 | 34 | ///////////////////////////////////////////////////////////////////////////// 35 | Other notes: 36 | library dependence: 37 | freeglut http://freeglut.sourceforge.net/ 38 | SOIL http://www.lonesock.net/soil.html 39 | FMOD http://www.fmod.org/ 40 | 41 | AppWizard uses "TODO:" comments to indicate parts of the source code you 42 | should add to or customize. 43 | 44 | ///////////////////////////////////////////////////////////////////////////// 45 | -------------------------------------------------------------------------------- /tsviewer/proj.vc11/lru_cache.h: -------------------------------------------------------------------------------- 1 | #ifndef __LRU__CACHE_H__ 2 | #define __LRU__CACHE_H__ 3 | 4 | #include 5 | #include 6 | 7 | template 8 | struct LRUCacheEntry { 9 | K key; 10 | T data; 11 | LRUCacheEntry* prev; 12 | LRUCacheEntry* next; 13 | }; 14 | 15 | template 16 | class LRUCache { 17 | private: 18 | std::map< K, LRUCacheEntry* > _mapping; 19 | std::vector< LRUCacheEntry* > _freeEntries; 20 | LRUCacheEntry * head; 21 | LRUCacheEntry * tail; 22 | LRUCacheEntry * entries; 23 | 24 | public: 25 | LRUCache(int size) { 26 | _freeEntries.reserve(size); 27 | entries = new LRUCacheEntry[size]; 28 | for (int i=0; i; 31 | tail = new LRUCacheEntry; 32 | head->prev = NULL; 33 | head->next = tail; 34 | tail->next = NULL; 35 | tail->prev = head; 36 | } 37 | 38 | ~LRUCache() { 39 | delete head; 40 | delete tail; 41 | delete [] entries; 42 | } 43 | 44 | T& insert(K key, T data) { 45 | LRUCacheEntry* node = _mapping[key]; 46 | if (node) { 47 | // refresh the link list 48 | detach(node); 49 | node->data = data; 50 | attach(node); 51 | } else { 52 | if ( _freeEntries.empty() ) { 53 | node = tail->prev; 54 | detach(node); 55 | _mapping.erase(node->key); 56 | node->key = key; 57 | node->data = data; 58 | _mapping[key] = node; 59 | attach(node); 60 | } else { 61 | node = _freeEntries.back(); 62 | _freeEntries.pop_back(); 63 | node->key = key; 64 | node->data = data; 65 | _mapping[key] = node; 66 | attach(node); 67 | } 68 | } 69 | return node->data; 70 | } 71 | 72 | T* fetch_ptr(K key) { 73 | LRUCacheEntry* node = _mapping[key]; 74 | if (node) { 75 | detach(node); 76 | attach(node); 77 | return &node->data; 78 | } 79 | return NULL; 80 | } 81 | 82 | int size(void) const { 83 | return _freeEntries.capacity() - _freeEntries.size(); 84 | } 85 | 86 | bool full(void) const { 87 | return _freeEntries.empty(); 88 | } 89 | 90 | T& getLRU(void) { 91 | return tail->prev->data; 92 | } 93 | 94 | std::map< K, LRUCacheEntry* > getMaptable() { 95 | return _mapping; 96 | } 97 | 98 | private: 99 | void detach(LRUCacheEntry* node) { 100 | node->prev->next = node->next; 101 | node->next->prev = node->prev; 102 | } 103 | 104 | void attach(LRUCacheEntry* node) { 105 | node->next = head->next; 106 | node->prev = head; 107 | head->next = node; 108 | node->next->prev = node; 109 | } 110 | }; 111 | 112 | #endif//lru_cache -------------------------------------------------------------------------------- /tsviewer/proj.vc11/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // tsviewer.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /tsviewer/proj.vc11/stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include "targetver.h" 9 | 10 | #include 11 | #include 12 | 13 | 14 | 15 | // TODO: reference additional headers your program requires here 16 | -------------------------------------------------------------------------------- /tsviewer/proj.vc11/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Including SDKDDKVer.h defines the highest available Windows platform. 4 | 5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and 6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /tsviewer/proj.vc11/tsviewer.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tsviewer", "tsviewer.vcxproj", "{51E00A1E-C3A8-434C-B775-6A70B8896F9F}" 5 | ProjectSection(ProjectDependencies) = postProject 6 | {2EF32000-30A4-49E5-84E1-C1ED38931E36} = {2EF32000-30A4-49E5-84E1-C1ED38931E36} 7 | EndProjectSection 8 | EndProject 9 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtinyswf", "..\..\projects\proj.vc11\libtinyswf.vcxproj", "{2EF32000-30A4-49E5-84E1-C1ED38931E36}" 10 | EndProject 11 | Global 12 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 13 | Debug|Win32 = Debug|Win32 14 | Release|Win32 = Release|Win32 15 | EndGlobalSection 16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 17 | {51E00A1E-C3A8-434C-B775-6A70B8896F9F}.Debug|Win32.ActiveCfg = Debug|Win32 18 | {51E00A1E-C3A8-434C-B775-6A70B8896F9F}.Debug|Win32.Build.0 = Debug|Win32 19 | {51E00A1E-C3A8-434C-B775-6A70B8896F9F}.Release|Win32.ActiveCfg = Release|Win32 20 | {51E00A1E-C3A8-434C-B775-6A70B8896F9F}.Release|Win32.Build.0 = Release|Win32 21 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Debug|Win32.ActiveCfg = Debug|Win32 22 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Debug|Win32.Build.0 = Debug|Win32 23 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Release|Win32.ActiveCfg = Release|Win32 24 | {2EF32000-30A4-49E5-84E1-C1ED38931E36}.Release|Win32.Build.0 = Release|Win32 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | EndGlobal 30 | -------------------------------------------------------------------------------- /tsviewer/proj.vc11/tsviewer.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {51E00A1E-C3A8-434C-B775-6A70B8896F9F} 15 | Win32Proj 16 | tsviewer 17 | 18 | 19 | 20 | Application 21 | true 22 | v110 23 | MultiByte 24 | 25 | 26 | Application 27 | false 28 | v110 29 | true 30 | MultiByte 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | true 44 | $(SolutionDir)..\..\bin\ 45 | $(ProjectName)D 46 | 47 | 48 | false 49 | $(SolutionDir)..\..\bin\ 50 | 51 | 52 | 53 | Use 54 | Level3 55 | Disabled 56 | FREEGLUT_STATIC;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 57 | C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\lowlevel\inc;D:\project\freeglut-2.8.1\include;D:\project\SOIL\src;..\..\include;%(AdditionalIncludeDirectories) 58 | 59 | 60 | Console 61 | true 62 | C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\lowlevel\lib;D:\project\freeglut-2.8.1\lib\x86\Debug;D:\project\SOIL\lib\Debug;..\..\lib\Debug;%(AdditionalLibraryDirectories) 63 | fmod_vc.lib 64 | 65 | 66 | 67 | 68 | Level3 69 | Use 70 | MaxSpeed 71 | true 72 | true 73 | FREEGLUT_STATIC;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 74 | C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\lowlevel\inc;D:\project\freeglut-2.8.1\include;D:\project\SOIL\src;..\..\include;%(AdditionalIncludeDirectories) 75 | 76 | 77 | Console 78 | true 79 | true 80 | true 81 | C:\Program Files %28x86%29\FMOD SoundSystem\FMOD Studio API Windows\api\lowlevel\lib;D:\project\freeglut-2.8.1\lib\x86;D:\project\SOIL\lib;..\..\lib;%(AdditionalLibraryDirectories) 82 | fmod_vc.lib;%(AdditionalDependencies) 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | Create 100 | Create 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /tsviewer/proj.vc11/tsviewer.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | 38 | 39 | Source Files 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | -------------------------------------------------------------------------------- /zlib/lib/zdll.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jbyu/tinyswf/00e9fe707bca2a7c6bf2e2d3d76e9831e96f8171/zlib/lib/zdll.lib -------------------------------------------------------------------------------- /zlib/lib/zlib.def: -------------------------------------------------------------------------------- 1 | ; zlib data compression library 2 | EXPORTS 3 | ; basic functions 4 | zlibVersion 5 | deflate 6 | deflateEnd 7 | inflate 8 | inflateEnd 9 | ; advanced functions 10 | deflateSetDictionary 11 | deflateCopy 12 | deflateReset 13 | deflateParams 14 | deflateTune 15 | deflateBound 16 | deflatePending 17 | deflatePrime 18 | deflateSetHeader 19 | inflateSetDictionary 20 | inflateGetDictionary 21 | inflateSync 22 | inflateCopy 23 | inflateReset 24 | inflateReset2 25 | inflatePrime 26 | inflateMark 27 | inflateGetHeader 28 | inflateBack 29 | inflateBackEnd 30 | zlibCompileFlags 31 | ; utility functions 32 | compress 33 | compress2 34 | compressBound 35 | uncompress 36 | gzopen 37 | gzdopen 38 | gzbuffer 39 | gzsetparams 40 | gzread 41 | gzwrite 42 | gzprintf 43 | gzvprintf 44 | gzputs 45 | gzgets 46 | gzputc 47 | gzgetc 48 | gzungetc 49 | gzflush 50 | gzseek 51 | gzrewind 52 | gztell 53 | gzoffset 54 | gzeof 55 | gzdirect 56 | gzclose 57 | gzclose_r 58 | gzclose_w 59 | gzerror 60 | gzclearerr 61 | ; large file functions 62 | gzopen64 63 | gzseek64 64 | gztell64 65 | gzoffset64 66 | adler32_combine64 67 | crc32_combine64 68 | ; checksum functions 69 | adler32 70 | crc32 71 | adler32_combine 72 | crc32_combine 73 | ; various hacks, don't look :) 74 | deflateInit_ 75 | deflateInit2_ 76 | inflateInit_ 77 | inflateInit2_ 78 | inflateBackInit_ 79 | gzgetc_ 80 | zError 81 | inflateSyncPoint 82 | get_crc_table 83 | inflateUndermine 84 | inflateResetKeep 85 | deflateResetKeep 86 | gzopen_w 87 | --------------------------------------------------------------------------------