add cocos2dx-win32 framework, can't work yet.

This commit is contained in:
yangws 2010-10-08 09:53:04 +00:00
parent 8088513c3d
commit cf0a2c5665
31 changed files with 3019 additions and 21 deletions

20
cocos2dx-win32.sln Normal file
View File

@ -0,0 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cocos2dx-win32", "cocos2dx\cocos2dx-win32.vcproj", "{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.ActiveCfg = Debug|Win32
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Debug|Win32.Build.0 = Debug|Win32
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.ActiveCfg = Release|Win32
{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -24,9 +24,14 @@ THE SOFTWARE.
#include "CCDrawingPrimitives.h"
#include <math.h>
#include <string.h>
#include <GLES/gl.h>
#include <cmath>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
namespace cocos2d {
void ccDrawPoint(CGPoint point)
@ -122,7 +127,7 @@ void ccDrawCircle(CGPoint center, float r, float a, int segs, bool drawLineToCen
++additionalSegment;
}
const float coef = 2.0f * (float)M_PI/segs;
const float coef = 2.0f * (float) (M_PI) /segs;
float *vertices = new float[2*(segs+2)]; // float *vertices = (float *)malloc( sizeof(float)*2*(segs+2));
if( ! vertices )

View File

@ -0,0 +1,917 @@
<?xml version="1.0" encoding="UTF-8"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="cocos2dx-win32"
ProjectGUID="{98A51BA8-FC3A-415B-AC8F-8C7BD464E93E}"
Keyword="Win32Proj"
TargetFrameworkVersion="0"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="2"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="d:\Work7\PRJ_TG3\Include\ThirdParty\iconv;d:\Work7\PRJ_TG3\Include\ThirdParty\zlib;d:\Work7\PRJ_TG3\Include\ThirdParty\libpng;d:\Work7\PRJ_TG3\Include\ThirdParty\libjpeg;d:\Work7\PRJ_TG3\Include\ThirdParty\libxml2;&quot;C:\Imagination Technologies\POWERVR SDK\OGLES-1.1_WINDOWS_PCEMULATION_2.06.26.0649\Builds\OGLES\Include&quot;;.\include;.\"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;GL_GLEXT_PROTOTYPES"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="4"
DisableSpecificWarnings="4996;4267"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="libEGL.lib libgles_cm.lib libxml2.lib zlib.lib libpng14-imp.lib libjpeg.lib"
LinkIncremental="2"
AdditionalLibraryDirectories="&quot;C:\Imagination Technologies\POWERVR SDK\OGLES-1.1_WINDOWS_PCEMULATION_2.06.26.0649\Builds\OGLES\WindowsPC\Lib&quot;;d:/Work7/PRJ_TG3/LIB/Win32Lib;D:\Work7\PRJ_TG3\Common\SoftSupport"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;COCOS2DXWIN32_EXPORTS;"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
LinkIncremental="2"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\support\base64.h"
>
</File>
<File
RelativePath=".\include\CCAction.h"
>
</File>
<File
RelativePath=".\include\CCActionManager.h"
>
</File>
<File
RelativePath=".\include\CCAtlasNode.h"
>
</File>
<File
RelativePath=".\include\CCBitmapFontAtlas.h"
>
</File>
<File
RelativePath=".\include\CCCamera.h"
>
</File>
<File
RelativePath=".\include\CCCameraAction.h"
>
</File>
<File
RelativePath=".\support\data_support\ccCArray.h"
>
</File>
<File
RelativePath=".\include\ccConfig.h"
>
</File>
<File
RelativePath=".\CCConfiguration.h"
>
</File>
<File
RelativePath=".\include\CCDirector.h"
>
</File>
<File
RelativePath=".\include\CCDrawingPrimitives.h"
>
</File>
<File
RelativePath=".\include\CCEaseAction.h"
>
</File>
<File
RelativePath=".\platform\CCFileUtils_platform.h"
>
</File>
<File
RelativePath=".\effects\CCGrabber.h"
>
</File>
<File
RelativePath=".\effects\CCGrid.h"
>
</File>
<File
RelativePath=".\include\CCGrid3DAction.h"
>
</File>
<File
RelativePath=".\include\CCGridAction.h"
>
</File>
<File
RelativePath=".\include\CCInstantAction.h"
>
</File>
<File
RelativePath=".\include\CCIntervalAction.h"
>
</File>
<File
RelativePath=".\include\CCLabel.h"
>
</File>
<File
RelativePath=".\include\CCLabelAtlas.h"
>
</File>
<File
RelativePath=".\include\CCLayer.h"
>
</File>
<File
RelativePath=".\include\ccMacros.h"
>
</File>
<File
RelativePath=".\include\CCMenu.h"
>
</File>
<File
RelativePath=".\include\CCMenuItem.h"
>
</File>
<File
RelativePath=".\include\CCMotionStreak.h"
>
</File>
<File
RelativePath=".\include\CCNode.h"
>
</File>
<File
RelativePath=".\include\CCPageTurn3DAction.h"
>
</File>
<File
RelativePath=".\include\CCPageTurnTransition.h"
>
</File>
<File
RelativePath=".\include\CCParallaxNode.h"
>
</File>
<File
RelativePath=".\include\CCParticleExamples.h"
>
</File>
<File
RelativePath=".\include\CCParticleSystem.h"
>
</File>
<File
RelativePath=".\include\CCPointParticleSystem.h"
>
</File>
<File
RelativePath=".\support\CCProfiling.h"
>
</File>
<File
RelativePath=".\include\CCProgressTimer.h"
>
</File>
<File
RelativePath=".\include\CCProgressTimerActions.h"
>
</File>
<File
RelativePath=".\include\CCProtocols.h"
>
</File>
<File
RelativePath=".\include\CCPVRTexture.h"
>
</File>
<File
RelativePath=".\include\CCQuadParticleSystem.h"
>
</File>
<File
RelativePath=".\include\CCRadialTransition.h"
>
</File>
<File
RelativePath=".\include\CCRenderTexture.h"
>
</File>
<File
RelativePath=".\include\CCRibbon.h"
>
</File>
<File
RelativePath=".\include\CCScene.h"
>
</File>
<File
RelativePath=".\include\CCScheduler.h"
>
</File>
<File
RelativePath=".\include\CCSprite.h"
>
</File>
<File
RelativePath=".\include\CCSpriteFrame.h"
>
</File>
<File
RelativePath=".\include\CCSpriteFrameCache.h"
>
</File>
<File
RelativePath=".\include\CCSpriteSheet.h"
>
</File>
<File
RelativePath=".\include\CCTexture2D.h"
>
</File>
<File
RelativePath=".\include\CCTextureAtlas.h"
>
</File>
<File
RelativePath=".\include\CCTextureCache.h"
>
</File>
<File
RelativePath=".\include\CCTiledGridAction.h"
>
</File>
<File
RelativePath=".\include\CCTileMapAtlas.h"
>
</File>
<File
RelativePath=".\platform\win32\CCTime.h"
>
</File>
<File
RelativePath=".\include\CCTMXLayer.h"
>
</File>
<File
RelativePath=".\include\CCTMXObjectGroup.h"
>
</File>
<File
RelativePath=".\include\CCTMXTiledMap.h"
>
</File>
<File
RelativePath=".\include\CCTMXXMLParser.h"
>
</File>
<File
RelativePath=".\include\CCTouch.h"
>
</File>
<File
RelativePath=".\include\CCTouchDelegateProtocol.h"
>
</File>
<File
RelativePath=".\include\CCTouchDispatcher.h"
>
</File>
<File
RelativePath=".\touch_dispatcher\CCTouchHandler.h"
>
</File>
<File
RelativePath=".\include\CCTransition.h"
>
</File>
<File
RelativePath=".\include\ccTypes.h"
>
</File>
<File
RelativePath=".\include\CCXApplication.h"
>
</File>
<File
RelativePath=".\platform\CCXApplication_platform.h"
>
</File>
<File
RelativePath=".\platform\win32\CCXApplication_win32.h"
>
</File>
<File
RelativePath=".\platform\win32\CCXBitmapDC.h"
>
</File>
<File
RelativePath=".\include\ccxCommon.h"
>
</File>
<File
RelativePath=".\platform\ccxCommon_platform.h"
>
</File>
<File
RelativePath=".\platform\win32\ccxCommon_win32.h"
>
</File>
<File
RelativePath=".\include\CCXEGLView.h"
>
</File>
<File
RelativePath=".\platform\CCXEGLView_platform.h"
>
</File>
<File
RelativePath=".\platform\win32\CCXEGLView_win32.h"
>
</File>
<File
RelativePath=".\include\CCXFileUtils.h"
>
</File>
<File
RelativePath=".\platform\win32\CCXFileUtils_win32.h"
>
</File>
<File
RelativePath=".\platform\CCXMath.h"
>
</File>
<File
RelativePath=".\include\CCXUIImage.h"
>
</File>
<File
RelativePath=".\platform\CCXUIImage_platform.h"
>
</File>
<File
RelativePath=".\platform\win32\CCXUIImage_win32.h"
>
</File>
<File
RelativePath=".\include\CGAffineTransform.h"
>
</File>
<File
RelativePath=".\include\CGGeometry.h"
>
</File>
<File
RelativePath=".\include\CGPointExtension.h"
>
</File>
<File
RelativePath=".\include\cocos2d.h"
>
</File>
<File
RelativePath=".\include\Cocos2dDefine.h"
>
</File>
<File
RelativePath=".\platform\win32\Cocos2dTypes.h"
>
</File>
<File
RelativePath=".\platform\config_platform.h"
>
</File>
<File
RelativePath=".\support\opengl_support\glu.h"
>
</File>
<File
RelativePath=".\include\NSAutoreleasePool.h"
>
</File>
<File
RelativePath=".\include\NSData.h"
>
</File>
<File
RelativePath=".\platform\win32\NSLock.h"
>
</File>
<File
RelativePath=".\include\NSMutableArray.h"
>
</File>
<File
RelativePath=".\include\NSMutableDictionary.h"
>
</File>
<File
RelativePath=".\include\NSObject.h"
>
</File>
<File
RelativePath=".\include\NSSet.h"
>
</File>
<File
RelativePath=".\include\NSString.h"
>
</File>
<File
RelativePath=".\include\NSZone.h"
>
</File>
<File
RelativePath=".\support\opengl_support\OpenGL_Internal.h"
>
</File>
<File
RelativePath=".\platform\platform.h"
>
</File>
<File
RelativePath=".\include\selector_protocol.h"
>
</File>
<File
RelativePath=".\support\image_support\TGAlib.h"
>
</File>
<File
RelativePath=".\support\TransformUtils.h"
>
</File>
<File
RelativePath=".\support\data_support\uthash.h"
>
</File>
<File
RelativePath=".\support\data_support\utlist.h"
>
</File>
<File
RelativePath=".\platform\win32\ZipUtils.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\support\base64.cpp"
>
</File>
<File
RelativePath=".\actions\CCAction.cpp"
>
</File>
<File
RelativePath=".\actions\CCActionManager.cpp"
>
</File>
<File
RelativePath=".\CCamera.cpp"
>
</File>
<File
RelativePath=".\base_nodes\CCAtlasNode.cpp"
>
</File>
<File
RelativePath=".\label_nodes\CCBitmapFontAtlas.cpp"
>
</File>
<File
RelativePath=".\actions\CCCameraAction.cpp"
>
</File>
<File
RelativePath=".\CCConfiguration.cpp"
>
</File>
<File
RelativePath=".\CCDirector.cpp"
>
</File>
<File
RelativePath=".\CCDrawingPrimitives.cpp"
>
</File>
<File
RelativePath=".\actions\CCEaseAction.cpp"
>
</File>
<File
RelativePath=".\effects\CCGrabber.cpp"
>
</File>
<File
RelativePath=".\effects\CCGrid.cpp"
>
</File>
<File
RelativePath=".\actions\CCGrid3DAction.cpp"
>
</File>
<File
RelativePath=".\actions\CCGridAction.cpp"
>
</File>
<File
RelativePath=".\actions\CCInstantAction.cpp"
>
</File>
<File
RelativePath=".\actions\CCIntervalAction.cpp"
>
</File>
<File
RelativePath=".\label_nodes\CCLabel.cpp"
>
</File>
<File
RelativePath=".\label_nodes\CCLabelAtlas.cpp"
>
</File>
<File
RelativePath=".\layers_scenes_transitions_nodes\CCLayer.cpp"
>
</File>
<File
RelativePath=".\menu_nodes\CCMenu.cpp"
>
</File>
<File
RelativePath=".\menu_nodes\CCMenuItem.cpp"
>
</File>
<File
RelativePath=".\misc_nodes\CCMotionStreak.cpp"
>
</File>
<File
RelativePath=".\base_nodes\CCNode.cpp"
>
</File>
<File
RelativePath=".\actions\CCPageTurn3DAction.cpp"
>
</File>
<File
RelativePath=".\layers_scenes_transitions_nodes\CCPageTurnTransition.cpp"
>
</File>
<File
RelativePath=".\tilemap_parallax_nodes\CCParallaxNode.cpp"
>
</File>
<File
RelativePath=".\particle_nodes\CCParticleExamples.cpp"
>
</File>
<File
RelativePath=".\particle_nodes\CCParticleSystem.cpp"
>
</File>
<File
RelativePath=".\particle_nodes\CCPointParticleSystem.cpp"
>
</File>
<File
RelativePath=".\support\CCProfiling.cpp"
>
</File>
<File
RelativePath=".\misc_nodes\CCProgressTimer.cpp"
>
</File>
<File
RelativePath=".\actions\CCProgressTimerActions.cpp"
>
</File>
<File
RelativePath=".\textures\CCPVRTexture.cpp"
>
</File>
<File
RelativePath=".\particle_nodes\CCQuadParticleSystem.cpp"
>
</File>
<File
RelativePath=".\layers_scenes_transitions_nodes\CCRadialTransition.cpp"
>
</File>
<File
RelativePath=".\misc_nodes\CCRenderTexture.cpp"
>
</File>
<File
RelativePath=".\misc_nodes\CCRibbon.cpp"
>
</File>
<File
RelativePath=".\layers_scenes_transitions_nodes\CCScene.cpp"
>
</File>
<File
RelativePath=".\CCScheduler.cpp"
>
</File>
<File
RelativePath=".\sprite_nodes\CCSprite.cpp"
>
</File>
<File
RelativePath=".\sprite_nodes\CCSpriteFrame.cpp"
>
</File>
<File
RelativePath=".\sprite_nodes\CCSpriteFrameCache.cpp"
>
</File>
<File
RelativePath=".\sprite_nodes\CCSpriteSheet.cpp"
>
</File>
<File
RelativePath=".\textures\CCTexture2D.cpp"
>
</File>
<File
RelativePath=".\textures\CCTextureAtlas.cpp"
>
</File>
<File
RelativePath=".\textures\CCTextureCache.cpp"
>
</File>
<File
RelativePath=".\actions\CCTiledGridAction.cpp"
>
</File>
<File
RelativePath=".\tilemap_parallax_nodes\CCTileMapAtlas.cpp"
>
</File>
<File
RelativePath=".\platform\win32\CCTime.cpp"
>
</File>
<File
RelativePath=".\tilemap_parallax_nodes\CCTMXLayer.cpp"
>
</File>
<File
RelativePath=".\tilemap_parallax_nodes\CCTMXObjectGroup.cpp"
>
</File>
<File
RelativePath=".\tilemap_parallax_nodes\CCTMXTiledMap.cpp"
>
</File>
<File
RelativePath=".\tilemap_parallax_nodes\CCTMXXMLParser.cpp"
>
</File>
<File
RelativePath=".\touch_dispatcher\CCTouchDispatcher.cpp"
>
</File>
<File
RelativePath=".\touch_dispatcher\CCTouchHandler.cpp"
>
</File>
<File
RelativePath=".\layers_scenes_transitions_nodes\CCTransition.cpp"
>
</File>
<File
RelativePath=".\platform\win32\CCXApplication_win32.cpp"
>
</File>
<File
RelativePath=".\platform\win32\CCXBitmapDC.cpp"
>
</File>
<File
RelativePath=".\platform\win32\CCXEGLView_win32.cpp"
>
</File>
<File
RelativePath=".\platform\win32\CCXFileUtils_win32.cpp"
>
</File>
<File
RelativePath=".\platform\win32\CCXUIImage_win32.cpp"
>
</File>
<File
RelativePath=".\cocoa\CGAffineTransform.cpp"
>
</File>
<File
RelativePath=".\cocoa\CGGeometry.cpp"
>
</File>
<File
RelativePath=".\support\CGPointExtension.cpp"
>
</File>
<File
RelativePath=".\cocos2d.cpp"
>
</File>
<File
RelativePath=".\support\opengl_support\glu.cpp"
>
</File>
<File
RelativePath=".\cocoa\NSAutoreleasePool.cpp"
>
</File>
<File
RelativePath=".\cocoa\NSData.cpp"
>
</File>
<File
RelativePath=".\platform\win32\NSLock.cpp"
>
</File>
<File
RelativePath=".\cocoa\NSObject.cpp"
>
</File>
<File
RelativePath=".\cocoa\NSSet.cpp"
>
</File>
<File
RelativePath=".\cocoa\NSZone.cpp"
>
</File>
<File
RelativePath=".\support\image_support\TGAlib.cpp"
>
</File>
<File
RelativePath=".\support\TransformUtils.cpp"
>
</File>
<File
RelativePath=".\platform\win32\ZipUtils.cpp"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -22,14 +22,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCBitmapFontAtlas.h"
#include "platform/platform.h"
#include "NSMutableDictionary.h"
#include "CCConfiguration.h"
#include "CCDrawingPrimitives.h"
#include "CCSprite.h"
#include "CGPointExtension.h"
//#include "platform/platform.h"
#include "CCXFileUtils.h"
#include "support/data_support/uthash.h"
namespace cocos2d{
//

View File

@ -26,10 +26,12 @@ THE SOFTWARE.
#include "config_platform.h"
#ifdef CCX_PLATFORM_UPHONE
#include "uphone/CCXFileUtils_uphone.h"
#if defined(CCX_PLATFORM_UPHONE)
#include "uphone/CCXFileUtils_uphone.h"
#elif defined(CCX_PLATFORM_WIN32)
#include "win32/CCXFileUtils_win32.h"
#else
#error
#error
#endif // __CCX_FILEUTILS_PLATFORM_H__
#endif // end of __CCX_EGLVIEW_PLATFORM_H__

View File

@ -27,8 +27,10 @@ THE SOFTWARE.
#include "config_platform.h"
#ifdef CCX_PLATFORM_UPHONE
#if defined(CCX_PLATFORM_UPHONE)
#include "uphone/CCXApplication_uphone.h"
#elif defined(CCX_PLATFORM_WIN32)
#include "win32/CCXApplication_win32.h"
#else
#error
#endif

View File

@ -27,8 +27,10 @@ THE SOFTWARE.
#include "config_platform.h"
#ifdef CCX_PLATFORM_UPHONE
#if defined(CCX_PLATFORM_UPHONE)
#include "uphone/CCXEGLView_uphone.h"
#elif defined(CCX_PLATFORM_WIN32)
#include "win32/CCXEGLView_win32.h"
#else
#error
#endif

View File

@ -26,8 +26,10 @@ THE SOFTWARE.
#include "config_platform.h"
#ifdef CCX_PLATFORM_UPHONE
#include "uphone/CCXUIImage_uphone.h"
#if defined(CCX_PLATFORM_UPHONE)
#include "uphone/CCXUIImage_uphone.h"
#elif defined(CCX_PLATFORM_WIN32)
#include "win32/CCXUIImage_win32.h"
#else
#error
#endif // __CCX_UIIMAGE_PLATFORM_H__

View File

@ -27,8 +27,10 @@ THE SOFTWARE.
#include "config_platform.h"
#ifdef CCX_PLATFORM_UPHONE
#if defined(CCX_PLATFORM_UPHONE)
#include "uphone/ccxCommon_uphone.h"
#elif defined(CCX_PLATFORM_WIN32)
#include "win32/ccxCommon_win32.h"
#else
#error
#endif

View File

@ -25,19 +25,33 @@ THE SOFTWARE.
// pre configure
#ifdef _TRANZDA_VM_ // under uphone emulator
#define CCX_PLATFORM_UPHONE
#else
// #error "no platform macro defined!"
#elif defined (WIN32) && defined (_WINDOWS) // under win32pc
#define CCX_PLATFORM_WIN32
#endif
// user configure
#if ! defined(CCX_PLATFORM_UPHONE) && defined(CCX_UNDER_UPHONE)
#define CCX_PLATFORM_UPHONE // under uphone
#endif
// use these macros to set compiling environment if needed
// #define CCX_PLATFORM_UPHONE
// #define CCX_PLATFORM_WIN32
// post configure
#if ! defined(CCX_PLATFORM_UPHONE)
#error "no platform macro defined!"
// check user set platform
#if defined(CCX_UNDER_UPHONE) || defined(CCX_UNDER_WIN32)
#undef CCX_PLATFORM_UPHONE
#undef CCX_PLATFORM_WIN32
#if defined(CCX_UNDER_UPHONE)
#define CCX_PLATFORM_UPHONE // under uphone
#elif defined(CCX_UNDER_WIN32)
#define CCX_PLATFORM_WIN32
#endif
#endif
// check compiling platform
#if ! defined(CCX_PLATFORM_UPHONE) && ! defined(CCX_PLATFORM_WIN32)
#error "no platform macro defined!"
#endif

View File

@ -27,13 +27,19 @@ THE SOFTWARE.
#include "config_platform.h"
#ifdef CCX_PLATFORM_UPHONE
#if defined(CCX_PLATFORM_UPHONE)
#include "uphone/CCTime.h"
#include "uphone/NSLock.h"
#include "uphone/Cocos2dTypes.h"
// #include "uphone/CCXGLExtFunc.h"
#include "uphone/CCXBitmapDC.h"
#include "uphone/ZipUtils.h"
#elif defined(CCX_PLATFORM_WIN32)
#include "win32/CCTime.h"
#include "win32/NSLock.h"
#include "win32/Cocos2dTypes.h"
#include "win32/CCXBitmapDC.h"
#include "win32/ZipUtils.h"
#else
#error
#endif

View File

@ -0,0 +1,47 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCTime.h"
#include <Windows.h>
namespace cocos2d {
// although it is not the same as gettimeofday as unix
// but we only use the diffrences of tow values
int CCTime::gettimeofdayCocos2d(struct cc_timeval *tp, void *tzp)
{
unsigned int ms = GetTickCount();
tp->tv_sec = ms / 1000;
tp->tv_usec = (ms % 1000) * 1000;
return 0;
}
void CCTime::timersubCocos2d(struct cc_timeval *out, struct cc_timeval *start, struct cc_timeval *end)
{
out->tv_sec = end->tv_sec - start->tv_sec;
out->tv_usec = end->tv_usec - start->tv_usec;
}
}//namespace cocos2d

View File

@ -0,0 +1,43 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __PLATFORM_UPHONE_CCTIME_H__
#define __PLATFORM_UPHONE_CCTIME_H__
namespace cocos2d {
struct cc_timeval
{
long tv_sec; // seconds
long tv_usec; // microSeconds
};
class CCTime
{
public:
static int gettimeofdayCocos2d(struct cc_timeval *tp, void *tzp);
static void timersubCocos2d(struct cc_timeval *out, struct cc_timeval *start, struct cc_timeval *end);
};
}//namespace cocos2d
#endif // __PLATFORM_UPHONE_NSTIME_H__

View File

@ -0,0 +1,62 @@
#include "CCXApplication_win32.h"
#include "CCDirector.h"
namespace cocos2d {
static CCXApplication * s_pApplication;
CCXApplication::CCXApplication()
{
s_pApplication = this;
}
CCXApplication::~CCXApplication()
{
s_pApplication = NULL;
}
void CCXApplication::setDeviceOrientation(int nOritation)
{
// TWindow * pWnd = TApplication::GetCurrentWindow();
// if (! pWnd)
// {
// return;
// }
// switch (nOritation)
// {
// /// Device oriented vertically, home button on the bottom
// case kCCDeviceOrientationPortrait:
// pWnd->RotateWindow(WM_WINDOW_ROTATE_MODE_NORMAL);
// break;
// /// Device oriented vertically, home button on the top
// case kCCDeviceOrientationPortraitUpsideDown:
// pWnd->RotateWindow(WM_WINDOW_ROTATE_MODE_UD);
// break;
//
// /// Device oriented horizontally, home button on the right
// case kCCDeviceOrientationLandscapeLeft:
// pWnd->RotateWindow(WM_WINDOW_ROTATE_MODE_CW);
// break;
// /// Device oriented horizontally, home button on the left
// case kCCDeviceOrientationLandscapeRight:
// pWnd->RotateWindow(WM_WINDOW_ROTATE_MODE_CCW);
// break;
// }
}
CGRect CCXApplication::statusBarFrame()
{
CGRect rc;
return rc;
}
//////////////////////////////////////////////////////////////////////////
/// Implement static class member
//////////////////////////////////////////////////////////////////////////
CCXApplication * CCXApplication::getSharedApplication()
{
return s_pApplication;
}
}

View File

@ -0,0 +1,86 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_APPLICATION_WIN32_H__
#define __CCX_APPLICATION_WIN32_H__
#include "CGGeometry.h"
#include <Windows.h>
namespace cocos2d {
class CCX_DLL CCXApplication
{
public:
CCXApplication();
virtual ~CCXApplication();
/**
@brief Implement CCDirector and sense init code here.
@return true Initialize success, app continue.
@return false Initialize failed, app terminate.
*/
virtual bool initCocos2d() = 0;
/**
@brief rotate main window by device orientation.
@param nOritation device orientation enum value.
@see ccDeviceOrientation
*/
void setDeviceOrientation(int nOritation);
/**
@brief Get status bar rectangle in EGLView window.
*/
CGRect statusBarFrame();
/**
@brief The function be called when the application enter background
@param the pointer of the application
*/
virtual void applicationDidEnterBackground() {}
/**
@brief The function be called when the application enter foreground
@param the pointer of the application
*/
virtual void applicationWillEnterForeground() {}
/**
@brief Get current applicaiton instance.
@return Current application instance pointer.
*/
static CCXApplication * getSharedApplication();
virtual BOOL InitInstance();
virtual int ExitInstance(); // return app exit code
virtual int Run();
private:
HINSTANCE m_hInstance;
};
} // end of namespace cocos2d
#endif // end of __CCX_APPLICATION_WIN32_H__

View File

@ -0,0 +1,82 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCXBitmapDC.h"
#include "CCDirector.h"
namespace cocos2d {
CCXBitmapDC::CCXBitmapDC(int width, int height)
{
m_hMemDC = CreateDC(NULL, NULL, NULL, NULL);
m_hBmp = CreateBitmap(width, height, 1, 32, NULL);
m_hOld = SelectObject(m_hMemDC, m_hBmp);
}
// CCXBitmapDC::CCXBitmapDC(const char *text, CGSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
// {
// // create font
// HFONT hFont = NULL;
// // font.Create(0, (Int32)fontSize);
//
// // text
// int len = strlen(text);
// WCHAR *pText = new WCHAR[len + 1];
// MultiByteToWideChar(CP_ACP, 0, text, len, pText, len + 1);
//
// DWORD dwStyle = 0;
//
// switch (alignment)
// {
// case UITextAlignmentLeft:
// dwStyle |= GUI_API_STYLE_ALIGNMENT_LEFT;
// break;
// case UITextAlignmentCenter:
// dwStyle |= GUI_API_STYLE_ALIGNMENT_CENTER;
// break;
// case UITextAlignmentRight:
// dwStyle |= GUI_API_STYLE_ALIGNMENT_RIGHT;
// break;
// default:
// dwStyle |= GUI_API_STYLE_ALIGNMENT_CENTER;
// break;
// }
//
// FillRect(m_hMemDC, NULL, )
//
// dc.DrawTextInRectangleEx(pText, 0, RGBA(255,255,255,255), RGBA(0,0,0,255), font, &rect, styles);
//
// delete [] pText;
// }
CCXBitmapDC::~CCXBitmapDC(void)
{
SelectObject(m_hMemDC, m_hOld);
DeleteObject(m_hBmp);
DeleteDC(m_hMemDC);
}
HBITMAP CCXBitmapDC::getBitmap()
{
return m_hBmp;
}
}

View File

@ -0,0 +1,53 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCXBITMAP_DC_H__
#define __CCXBITMAP_DC_H__
#include <Windows.h>
#include "ccTypes.h"
#include "Cocos2dDefine.h"
#include "CCXUIImage.h"
namespace cocos2d{
class CCX_DLL CCXBitmapDC
{
public:
CCXBitmapDC(int width, int height);
CCXBitmapDC(const char *text,
CGSize dimensions = CGSizeZero,
UITextAlignment alignment = UITextAlignmentCenter,
const char *fontName = NULL,
float fontSize = 0);
~CCXBitmapDC(void);
HBITMAP getBitmap(void);
void * getBuffer(){ return NULL; }
protected:
HDC m_hMemDC;
HBITMAP m_hBmp;
HGDIOBJ m_hOld;
};
}
#endif //__CCXBITMAP_DC_H__

View File

@ -0,0 +1,366 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCXEGLView.h"
#include "EGL/egl.h"
#include "gles/gl.h"
#include "Cocos2dDefine.h"
#include "NSSet.h"
#include "CCDirector.h"
#include "CCTouch.h"
#include "CCTouchDispatcher.h"
namespace cocos2d {
//////////////////////////////////////////////////////////////////////////
// impliment CCXEGL
//////////////////////////////////////////////////////////////////////////
class CCXEGL
{
public:
~CCXEGL()
{
if (EGL_NO_SURFACE != m_eglSurface)
{
eglDestroySurface(m_eglDisplay, m_eglSurface);
}
if (EGL_NO_CONTEXT != m_eglContext)
{
eglDestroyContext(m_eglDisplay, m_eglContext);
}
eglMakeCurrent(m_eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglTerminate(m_eglDisplay);
if (m_eglNativeDisplay)
{
ReleaseDC(m_eglNativeWindow, m_eglNativeDisplay);
}
}
static CCXEGL * create(CCXEGLView * pWindow)
{
CCXEGL * pEGL = new CCXEGL;
BOOL bSuccess = FALSE;
do
{
CCX_BREAK_IF(! pEGL);
pEGL->m_eglNativeWindow = pWindow->getHWnd();
pEGL->m_eglNativeDisplay = GetDC(pEGL->m_eglNativeWindow);
EGLDisplay eglDisplay;
CCX_BREAK_IF(EGL_NO_DISPLAY == (eglDisplay = eglGetDisplay(pEGL->m_eglNativeDisplay)));
EGLint nMajor, nMinor;
CCX_BREAK_IF(EGL_FALSE == eglInitialize(eglDisplay, &nMajor, &nMinor) || 1 != nMajor);
const EGLint aConfigAttribs[] =
{
EGL_LEVEL, 0,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NATIVE_RENDERABLE, EGL_FALSE,
EGL_DEPTH_SIZE, 16,
EGL_NONE,
};
EGLint iConfigs;
EGLConfig eglConfig;
CCX_BREAK_IF(EGL_FALSE == eglChooseConfig(eglDisplay, aConfigAttribs, &eglConfig, 1, &iConfigs)
|| (iConfigs != 1));
EGLContext eglContext;
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
CCX_BREAK_IF(EGL_NO_CONTEXT == eglContext);
EGLSurface eglSurface;
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, pEGL->m_eglNativeWindow, NULL);
CCX_BREAK_IF(EGL_NO_SURFACE == eglSurface);
CCX_BREAK_IF(EGL_FALSE == eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext));
pEGL->m_eglDisplay = eglDisplay;
pEGL->m_eglConfig = eglConfig;
pEGL->m_eglContext = eglContext;
pEGL->m_eglSurface = eglSurface;
bSuccess = TRUE;
} while (0);
if (! bSuccess)
{
CCX_SAFE_DELETE(pEGL);
}
return pEGL;
}
void resizeSurface()
{
// if (! m_eglWnd || EGL_NO_DISPLAY == m_eglDisplay)
// {
// return;
// }
//
// // release old surface
// if (EGL_NO_SURFACE != m_eglSurface)
// {
// eglDestroySurface(m_eglDisplay, m_eglSurface);
// m_eglSurface = EGL_NO_SURFACE;
// }
//
// // create new surface and make current
// m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_eglWnd, NULL);
// eglMakeCurrent(m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext);
}
void swapBuffers()
{
if (EGL_NO_DISPLAY != m_eglDisplay)
{
eglSwapBuffers(m_eglDisplay, m_eglSurface);
}
}
private:
CCXEGL()
: m_eglNativeWindow(NULL)
, m_eglNativeDisplay(EGL_DEFAULT_DISPLAY)
, m_eglDisplay(EGL_NO_DISPLAY)
, m_eglConfig(0)
, m_eglSurface(EGL_NO_SURFACE)
, m_eglContext(EGL_NO_CONTEXT)
{}
EGLNativeWindowType m_eglNativeWindow;
EGLNativeDisplayType m_eglNativeDisplay;
EGLDisplay m_eglDisplay;
EGLConfig m_eglConfig;
EGLSurface m_eglSurface;
EGLContext m_eglContext;
};
//////////////////////////////////////////////////////////////////////////
// impliment CCXEGLView
//////////////////////////////////////////////////////////////////////////
static CCXEGLView * pMainWindow;
static const WCHAR * kWindowClassName = L"Cocos2dxWin32";
static LRESULT CALLBACK _WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (pMainWindow && pMainWindow->getHWnd() == hWnd)
{
return pMainWindow->WindowProc(uMsg, wParam, lParam);
}
else
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
CCXEGLView::CCXEGLView()
: m_bCaptured(false)
, m_pDelegate(NULL)
, m_pEGL(NULL)
, m_hWnd(NULL)
{
m_pTouch = new CCTouch;
m_pSet = new NSSet;
}
CCXEGLView::~CCXEGLView()
{
release();
delete m_pSet;
delete m_pTouch;
CCX_SAFE_DELETE(m_pDelegate);
}
bool CCXEGLView::Create(LPCTSTR pTitle, int w, int h)
{
bool bRet = false;
do
{
CCX_BREAK_IF(m_hWnd);
HINSTANCE hInstance = GetModuleHandle( NULL );
WNDCLASS wc; // Windows Class Structure
// Redraw On Size, And Own DC For Window.
wc.style = CS_NOCLOSE | CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = _WindowProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon
wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = kWindowClassName; // Set The Class Name
CCX_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError());
// center window position
RECT rcDesktop;
GetWindowRect(GetDesktopWindow(), &rcDesktop);
RECT rect = {(rcDesktop.right + rcDesktop.left - w) / 2, (rcDesktop.bottom + rcDesktop.top - h) / 2, 0, 0};
rect.right = rect.left + w;
rect.bottom = rect.top + h;
AdjustWindowRectEx(&rect, WS_POPUPWINDOW, false, WS_EX_TOPMOST | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE);
// create window
m_hWnd = CreateWindowEx(
WS_EX_TOPMOST | WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window
kWindowClassName, // Class Name
pTitle, // Window Title
WS_POPUPWINDOW/*WS_OVERLAPPEDWINDOW*/ // Defined Window Style
| WS_CLIPSIBLINGS // Required Window Style
| WS_CLIPCHILDREN, // Required Window Style
rect.left, rect.top, // Window Position
rect.right - rect.left, // Window Width
rect.bottom - rect.top, // Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL );
CCX_BREAK_IF(! m_hWnd);
// init egl
m_pEGL = CCXEGL::create(this);
if (! m_pEGL)
{
DestroyWindow(m_hWnd);
m_hWnd = NULL;
break;
}
ShowWindow(m_hWnd, SW_SHOW);
pMainWindow = this;
bRet = true;
} while (0);
return bRet;
}
LRESULT CCXEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_MBUTTONDOWN:
if (m_pDelegate && m_pTouch && MK_LBUTTON == wParam)
{
m_bCaptured = true;
m_pTouch->SetTouchInfo(0, (float)LOWORD(lParam), (float)HIWORD(lParam));
m_pSet->addObject(m_pTouch);
m_pDelegate->touchesBegan(m_pSet, NULL);
}
break;
case WM_MOUSEMOVE:
if (MK_LBUTTON == wParam && m_bCaptured)
{
m_pTouch->SetTouchInfo(0, (float)LOWORD(lParam), (float)HIWORD(lParam));
m_pDelegate->touchesMoved(m_pSet, NULL);
}
break;
case WM_MBUTTONUP:
if (MK_LBUTTON == wParam && m_bCaptured)
{
m_pTouch->SetTouchInfo(0, (float)LOWORD(lParam), (float)HIWORD(lParam));
m_pDelegate->touchesEnded(m_pSet, NULL);
m_pSet->removeObject(m_pTouch);
m_bCaptured = false;
}
break;
case WM_PAINT:
if (m_pEGL)
{
m_pEGL->swapBuffers();
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(m_hWnd, message, wParam, lParam);
}
return 0;
}
CGSize CCXEGLView::getSize()
{
RECT rc;
GetClientRect(m_hWnd, &rc);
return CGSize((float)(rc.right - rc.left), (float)(rc.bottom - rc.top));
}
CGRect CCXEGLView::getFrame()
{
RECT rc;
GetClientRect(m_hWnd, &rc);
return (CGRect((float)rc.left, (float)rc.top, (float)(rc.right - rc.left), (float)(rc.bottom - rc.top)));
}
bool CCXEGLView::isOpenGLReady()
{
return (NULL != m_pEGL);
}
void CCXEGLView::release()
{
CCX_SAFE_DELETE(m_pEGL);
if (m_hWnd)
{
DestroyWindow(m_hWnd);
m_hWnd = NULL;
}
pMainWindow = NULL;
UnregisterClass(kWindowClassName, GetModuleHandle(NULL));
}
void CCXEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
{
m_pDelegate = pDelegate;
}
void CCXEGLView::swapBuffers()
{
if (m_pEGL)
{
m_pEGL->swapBuffers();
}
}
HWND CCXEGLView::getHWnd()
{
return m_hWnd;
}
} // end of namespace cocos2d

View File

@ -0,0 +1,74 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_EGLVIEW_WIN32_H__
#define __CCX_EGLVIEW_WIN32_H__
#include <Windows.h>
#include "Cocos2dDefine.h"
#include "CGGeometry.h"
namespace cocos2d {
class NSSet;
class CCTouch;
class EGLTouchDelegate;
class CCXEGL;
class CCX_DLL CCXEGLView
{
public:
CCXEGLView();
virtual ~CCXEGLView();
CGRect getFrame();
CGSize getSize();
bool isOpenGLReady();
void release();
void setTouchDelegate(EGLTouchDelegate * pDelegate);
void swapBuffers();
virtual bool Create(LPCTSTR pTitle, int w, int h);
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
HWND getHWnd();
private:
bool m_bCaptured;
NSSet * m_pSet;
CCTouch * m_pTouch;
EGLTouchDelegate * m_pDelegate;
CCXEGL * m_pEGL;
HWND m_hWnd;
};
} // end of namespace cocos2d
#endif // end of __CCX_EGLVIEW_WIN32_H__

View File

@ -0,0 +1,262 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCXFileUtils_win32.h"
#include <windows.h>
#include <stack>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlmemory.h>
#include "NSString.h"
#include "Cocos2dDefine.h"
namespace cocos2d {
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts);
void plist_endElement(void *ctx, const xmlChar *name);
void plist_characters(void *ctx, const xmlChar *ch, int len);
typedef enum
{
SAX_NONE = 0,
SAX_KEY,
SAX_DICT,
SAX_INT,
SAX_REAL,
SAX_STRING
}CCSAXState;
class CCDictMaker
{
public:
NSDictionary<std::string, NSObject*> *m_pRootDict;
NSDictionary<std::string, NSObject*> *m_pCurDict;
std::stack<NSDictionary<std::string, NSObject*>*> m_tDictStack;
std::string m_sCurKey;///< parsed key
CCSAXState m_tState;
public:
CCDictMaker()
{
m_pRootDict = NULL;
m_pCurDict = NULL;
m_tState = SAX_NONE;
}
~CCDictMaker()
{
}
NSDictionary<std::string, NSObject*> *dictionaryWithContentsOfFile(const char *pFileName)
{
FILE *fp = NULL;
if( !(fp = fopen(pFileName, "r")) )
{
return NULL;
}
fseek(fp,0,SEEK_END);
int size = ftell(fp);
fseek(fp,0,SEEK_SET);
char *buffer = new char[size+1];
fread(buffer,sizeof(char),size,fp);
fclose(fp);
/*
* this initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
xmlSAXHandler saxHandler;
memset( &saxHandler, 0, sizeof(saxHandler) );
// Using xmlSAXVersion( &saxHandler, 2 ) generate crash as it sets plenty of other pointers...
saxHandler.initialized = XML_SAX2_MAGIC; // so we do this to force parsing as SAX2.
saxHandler.startElement = &plist_startElement;
saxHandler.endElement = &plist_endElement;
saxHandler.characters = &plist_characters;
int result = xmlSAXUserParseMemory( &saxHandler, this, buffer, size );
if ( result != 0 )
{
return NULL;
}
/*
* Cleanup function for the XML library.
*/
xmlCleanupParser();
/*
* this is to debug memory for regression tests
*/
xmlMemoryDump();
delete []buffer;
return m_pRootDict;
}
};
void plist_startElement(void *ctx, const xmlChar *name, const xmlChar **atts)
{
CCDictMaker *pMaker = (CCDictMaker*)(ctx);
std::string sName((char*)name);
if( sName == "dict" )
{
NSDictionary<std::string, NSObject*> *pNewDict = new NSDictionary<std::string, NSObject*>();
if(! pMaker->m_pRootDict)
{
pMaker->m_pRootDict = pNewDict;
pNewDict->autorelease();
}
else
{
NSAssert(pMaker->m_pCurDict && !pMaker->m_sCurKey.empty(), "");
pMaker->m_pCurDict->setObject(pNewDict, pMaker->m_sCurKey);
pNewDict->release();
pMaker->m_sCurKey.clear();
}
pMaker->m_pCurDict = pNewDict;
pMaker->m_tDictStack.push(pMaker->m_pCurDict);
pMaker->m_tState = SAX_DICT;
}
else if(sName == "key")
{
pMaker->m_tState = SAX_KEY;
}
else if(sName == "integer")
{
pMaker->m_tState = SAX_INT;
}
else if(sName == "real")
{
pMaker->m_tState = SAX_REAL;
}
else if(sName == "string")
{
pMaker->m_tState = SAX_STRING;
}
else
{
pMaker->m_tState = SAX_NONE;
}
}
void plist_endElement(void *ctx, const xmlChar *name)
{
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
std::string sName((char*)name);
if( sName == "dict" )
{
pMaker->m_tDictStack.pop();
if ( !pMaker->m_tDictStack.empty() )
{
pMaker->m_pCurDict = (NSDictionary<std::string, NSObject*>*)(pMaker->m_tDictStack.top());
}
}
pMaker->m_tState = SAX_NONE;
}
void plist_characters(void *ctx, const xmlChar *ch, int len)
{
CCDictMaker * pMaker = (CCDictMaker*)(ctx);
if (pMaker->m_tState == SAX_NONE)
{
return;
}
NSString *pText = new NSString();
pText->m_sString = std::string((char*)ch,0,len);
switch(pMaker->m_tState)
{
case SAX_KEY:
pMaker->m_sCurKey = pText->m_sString;
break;
case SAX_INT:
case SAX_REAL:
case SAX_STRING:
{
NSAssert(!pMaker->m_sCurKey.empty(), "not found key : <integet/real>");
pMaker->m_pCurDict->setObject(pText, pMaker->m_sCurKey);
break;
}
}
pText->release();
}
// record the resource path
static char s_pszResourcePath[MAX_PATH] = {0};
void _CheckPath()
{
if (! s_pszResourcePath[0])
{
WCHAR wszPath[MAX_PATH];
WideCharToMultiByte(CP_ACP, 0, wszPath,
GetModuleFileName(NULL, wszPath, MAX_PATH),
s_pszResourcePath, MAX_PATH, NULL, NULL);
}
}
void CCFileUtils::setResourcePath(const char *pszResourcePath)
{
NSAssert(pszResourcePath != NULL, "[FileUtils setResourcePath] -- wrong resource path");
NSAssert(strlen(pszResourcePath) <= MAX_PATH, "[FileUtils setResourcePath] -- resource path too long");
strcpy(s_pszResourcePath, pszResourcePath);
}
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
_CheckPath();
NSString * pRet = new NSString();
pRet->autorelease();
if ((strlen(pszRelativePath) > 1 && pszRelativePath[1] == ':'))
{
pRet->m_sString = pszRelativePath;
}
else if (strlen(pszRelativePath) > 0 && pszRelativePath[0] == '/')
{
char szDriver[3] = {s_pszResourcePath[0], s_pszResourcePath[1], 0};
pRet->m_sString = szDriver;
pRet->m_sString += pszRelativePath;
}
else
{
pRet->m_sString = s_pszResourcePath;
pRet->m_sString += pszRelativePath;
}
return pRet->m_sString.c_str();
}
const char *CCFileUtils::fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile)
{
_CheckPath();
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
NSString *pRet = new NSString();
pRet->autorelease();
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
pRet->m_sString += pszFilename;
return pRet->m_sString.c_str();
}
NSDictionary<std::string, NSObject*> *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
{
CCDictMaker tMaker;
return tMaker.dictionaryWithContentsOfFile(pFileName);
}
}//namespace cocos2d

View File

@ -0,0 +1,67 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __PLATFORM_WIN32_CCFILE_UTILS_H__
#define __PLATFORM_WIN32_CCFILE_UTILS_H__
#include <string>
#include "ccxCommon.h"
#include "NSMutableDictionary.h"
namespace cocos2d {
//! @brief Helper class to handle file operations
class CCX_DLL CCFileUtils
{
public:
/**
@brief Generate the absolute path of the file.
@param pszRelativePath The relative path of the file.
@return The absolute path of the file.
@warning We only add the ResourcePath before the relative path of the file.
If you have not set the ResourcePath,the function add "/NEWPLUS/TDA_DATA/UserData/" as default.
You can set ResourcePath by function void setResourcePath(const char *pszResourcePath);
*/
static const char* fullPathFromRelativePath(const char *pszRelativePath);
/// @cond
static const char* fullPathFromRelativeFile(const char *pszFilename, const char *pszRelativeFile);
/// @endcond
/**
@brief Generate a NSDictionary pointer by file
@param pFileName The file name of *.plist file
@return The NSDictionary pointer generated from the file
*/
static NSDictionary<std::string, NSObject*> *dictionaryWithContentsOfFile(const char *pFileName);
/**
@brief Set the ResourcePath,we will find resource in this path
@param pszResourcePath The absolute resource path
*/
static void setResourcePath(const char *pszResourcePath);
};
}//namespace cocos2d
#endif // __PLATFORM_WIN32_CCFILE_UTILS_H__

View File

@ -0,0 +1,413 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "CCXUIImage_win32.h"
#include "png.h"
// in order to compile correct in andLinux, because ssTypes(uphone)
// and jmorecfg.h all typedef xxx INT32
#define QGLOBAL_H
#include "jpeglib.h"
#undef QGLOBAL_H
//using namespace ImageToolKit;
using namespace std;
namespace cocos2d {
#define CCX_RGB_PREMULTIPLY_APLHA(vr, vg, vb, va) \
(UINT)(((UINT32)((UINT8)(vr) * ((UINT8)(va) + 1)) >> 8) | \
((UINT32)((UINT8)(vg) * ((UINT8)(va) + 1) >> 8) << 8) | \
((UINT32)((UINT8)(vb) * ((UINT8)(va) + 1) >> 8) << 16) | \
((UINT32)(UINT8)(va) << 24))
typedef struct
{
unsigned char* data;
int size;
int offset;
}tImageSource;
// because we do not want to include "png.h" in CCXUIImage_uphone.h, so we implement
// the function as a static function
static void pngReadCallback(png_structp png_ptr, png_bytep data, png_size_t length)
{
tImageSource* isource = (tImageSource*)png_get_io_ptr(png_ptr);
if((int)(isource->offset + length) <= isource->size)
{
memcpy(data, isource->data+isource->offset, length);
isource->offset += length;
}
else
{
png_error(png_ptr, "pngReaderCallback failed");
}
}
UIImage::UIImage(void)
{
m_pBitmap = NULL;
m_imageInfo.hasAlpha = false;
m_imageInfo.isPremultipliedAlpha = false;
m_imageInfo.height = 0;
m_imageInfo.width = 0;
m_imageInfo.data = NULL;
m_imageInfo.bitsPerComponent = 0;
}
UIImage::UIImage(HBITMAP hBitmap)
{
// if (bitmap)
// {
// m_pBitmap = bitmap->DupBitmapTo32();
//
// // init imageinfo
// m_imageInfo.data = m_pBitmap->GetDataPtr();
// m_imageInfo.height = m_pBitmap->GetHeight();
// m_imageInfo.width = m_pBitmap->GetWidth();
// m_imageInfo.hasAlpha = true;//m_pBitmap->HasAlphaData();
// // uphone only support predefined
// m_imageInfo.isPremultipliedAlpha = true;
// m_imageInfo.bitsPerComponent = m_pBitmap->GetDepth() / 4;
// }
}
UIImage::~UIImage(void)
{
// if (m_pBitmap)
// {
// // the m_imageInfo's data points to m_pBitmap,
// // so we don't release m_imageInfo's data
// m_pBitmap->Destroy();
// }
// else
{
if (m_imageInfo.data)
{
delete []m_imageInfo.data;
}
}
}
bool UIImage::initWithContentsOfFile(const string &strPath, tImageFormat imageType)
{
bool bRet = false;
switch (imageType)
{
case kImageFormatPNG:
// use libpng load image
bRet = loadPng(strPath.c_str());
break;
case kImageFormatJPG:
bRet = loadJpg(strPath.c_str());
break;
default:
// unsupported image type
bRet = false;
break;
}
return bRet;
}
unsigned int UIImage::width(void)
{
return m_imageInfo.width;
}
unsigned int UIImage::height(void)
{
return m_imageInfo.height;
}
bool UIImage::isAlphaPixelFormat(void)
{
return m_imageInfo.hasAlpha;
}
// now, uphone only support premultiplied data
// so, we only return true
bool UIImage::isPremultipliedAlpha(void)
{
return m_imageInfo.isPremultipliedAlpha;
}
// compute how many bits every color component
int UIImage::CGImageGetBitsPerComponent(void)
{
return m_imageInfo.bitsPerComponent;
}
// now we only support RGBA8888 or RGB888
// so it has color space
int UIImage::CGImageGetColorSpace(void)
{
return 1;
}
unsigned char* UIImage::getData(void)
{
return m_imageInfo.data;
}
bool UIImage::loadPng(const char* strFileName)
{
FILE *fp;
unsigned char *buffer = NULL;
bool bRet = true;
fp = NULL;
do
{
// open file
fp = fopen(strFileName, "rb");
if (!fp)
{
bRet = false;
break;
}
// compute the length of file
fseek(fp,0,SEEK_END);
int size = ftell(fp);
fseek(fp,0,SEEK_SET);
// allocate enough memory to save the data of file
buffer = new unsigned char[size];
if (! buffer)
{
bRet = false;
break;
}
// read data
fread(buffer, sizeof(unsigned char), size, fp);
bRet = loadPngFromStream(buffer, size);
delete[] buffer;
} while (0);
if (fp)
{
fclose(fp);
}
return bRet;
}
bool UIImage::loadPngFromStream(unsigned char *data, int nLength)
{
char header[8];
png_structp png_ptr;
png_infop info_ptr;
png_bytep * rowPointers;
tImageSource imageSource;
int color_type;
// read 8 bytes from the beginning of stream
unsigned char *tmp = data;
memcpy(header, tmp, 8);
// close the file if it's not a png
if (png_sig_cmp((png_bytep)header, 0, 8))
{
return false;
}
// init png_struct
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr)
{
return false;
}
// init png_info
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
png_destroy_read_struct(&png_ptr, NULL, NULL);
return false;
}
// if something wrong,close file and return
if (setjmp(png_jmpbuf(png_ptr)))
{
png_destroy_read_struct(&png_ptr, NULL, NULL);
png_destroy_info_struct(png_ptr, &info_ptr);
return false;
}
// set the read call back function
imageSource.data = data;
imageSource.size = nLength;
imageSource.offset = 0;
png_set_read_fn(png_ptr, &imageSource, pngReadCallback);
// read png
// PNG_TRANSFORM_EXPAND: perform set_expand()
// PNG_TRANSFORM_PACKING: expand 1, 2 and 4-bit samples to bytes
// PNG_TRANSFORM_STRIP_16: strip 16-bit samples to 8 bits
// PNG_TRANSFORM_GRAY_TO_RGB: expand grayscale samples to RGB (or GA to RGBA)
png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_GRAY_TO_RGB, NULL);
png_get_IHDR(png_ptr, info_ptr, &m_imageInfo.width, &m_imageInfo.height, &m_imageInfo.bitsPerComponent, &color_type,
NULL, NULL, NULL);
// init image info
m_imageInfo.isPremultipliedAlpha = true;
m_imageInfo.hasAlpha = ( info_ptr->color_type & PNG_COLOR_MASK_ALPHA ) ? true : false;
// allocate memory and read data
int bytesPerComponent = 3;
if (m_imageInfo.hasAlpha)
{
bytesPerComponent = 4;
}
m_imageInfo.data = new unsigned char[m_imageInfo.height * m_imageInfo.width * bytesPerComponent];
rowPointers = png_get_rows(png_ptr, info_ptr);
// copy data to image info
int bytesPerRow = m_imageInfo.width * bytesPerComponent;
if(m_imageInfo.hasAlpha)
{
unsigned int *tmp = (unsigned int *)m_imageInfo.data;
for(unsigned int i = 0; i < m_imageInfo.height; i++)
{
for(int j = 0; j < bytesPerRow; j += 4)
{
*tmp++ = CCX_RGB_PREMULTIPLY_APLHA( rowPointers[i][j], rowPointers[i][j + 1],
rowPointers[i][j + 2], rowPointers[i][j + 3] );
}
}
}
else
{
for (unsigned int j = 0; j < m_imageInfo.height; ++j)
{
memcpy(m_imageInfo.data + j * bytesPerRow, rowPointers[j], bytesPerRow);
}
}
// release
png_destroy_read_struct(&png_ptr, NULL, NULL);
png_destroy_info_struct(png_ptr, &info_ptr);
return true;
}
bool UIImage::loadJpg(const char *strFileName)
{
/* these are standard libjpeg structures for reading(decompression) */
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
/* libjpeg data structure for storing one row, that is, scanline of an image */
JSAMPROW row_pointer[1];
FILE *infile = fopen( strFileName, "rb" );
unsigned long location = 0;
unsigned int i = 0;
if ( !infile )
{
return false;
}
/* here we set up the standard libjpeg error handler */
cinfo.err = jpeg_std_error( &jerr );
/* setup decompression process and source, then read JPEG header */
jpeg_create_decompress( &cinfo );
/* this makes the library read from infile */
jpeg_stdio_src( &cinfo, infile );
/* reading the image header which contains image information */
jpeg_read_header( &cinfo, true );
// we only support RGB or grayscale
if (cinfo.jpeg_color_space != JCS_RGB)
{
if (cinfo.jpeg_color_space == JCS_GRAYSCALE || cinfo.jpeg_color_space == JCS_YCbCr)
{
cinfo.out_color_space = JCS_RGB;
}
}
else
{
return false;
}
/* Start decompression jpeg here */
jpeg_start_decompress( &cinfo );
/* init image info */
m_imageInfo.width = cinfo.image_width;
m_imageInfo.height = cinfo.image_height;
m_imageInfo.hasAlpha = false;
m_imageInfo.isPremultipliedAlpha = false;
m_imageInfo.bitsPerComponent = 8;
m_imageInfo.data = new unsigned char[cinfo.output_width*cinfo.output_height*cinfo.output_components];
/* now actually read the jpeg into the raw buffer */
row_pointer[0] = new unsigned char[cinfo.output_width*cinfo.output_components];
/* read one scan line at a time */
while( cinfo.output_scanline < cinfo.image_height )
{
jpeg_read_scanlines( &cinfo, row_pointer, 1 );
for( i=0; i<cinfo.image_width*cinfo.num_components;i++)
m_imageInfo.data[location++] = row_pointer[0][i];
}
/* wrap up decompression, destroy objects, free pointers and close open files */
jpeg_finish_decompress( &cinfo );
jpeg_destroy_decompress( &cinfo );
delete row_pointer[0];
fclose( infile );
return true;
}
bool UIImage::save(const std::string &strFileName, int nFormat)
{
/// @todo uiimage::save
return false;
}
bool UIImage::initWithData(unsigned char *pBuffer, int nLength)
{
return loadPngFromStream(pBuffer, nLength);
}
bool UIImage::initWithBuffer(int tx, int ty, unsigned char *pBuffer)
{
/// @todo
return false;
}
}//namespace cocos2d

View File

@ -0,0 +1,110 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __PLATFORM_WIN32_UIIMAGE_H__
#define __PLATFORM_WIN32_UIIMAGE_H__
#include <Windows.h>
#include <string>
#include "ccxCommon.h"
#include "CCRenderTexture.h"
namespace cocos2d {
/// @cond
typedef struct
{
unsigned int height;
unsigned int width;
int bitsPerComponent;
bool hasAlpha;
bool isPremultipliedAlpha;
unsigned char *data;
} tImageInfo;
/// @endcond
/**
@brief image toolkits
*/
class CCX_DLL UIImage
{
public:
UIImage(void);
UIImage(HBITMAP hBitmap);
~UIImage(void);
/**
Load the image from the specified path.
@param strPath the absolute file path
@param imageType the type of image, now only support tow types:
- kImageFormatPNG -> png
- kImageFormatJPG -> jpeg
@return true if load correctly
*/
bool initWithContentsOfFile(const std::string &strPath, tImageFormat imageType = kImageFormatPNG);
/**
Load image from stream buffer.
@param pBuffer stream buffer that hold the image data
@param nLength the length of data(managed in byte)
@return true if load correctly
*/
bool initWithData(unsigned char *pBuffer, int nLength);
/// @cond
bool initWithBuffer(int tx, int ty, unsigned char *pBuffer);
bool save(const std::string &strFileName, int nFormat);
/// @endcond
/** get the image width */
unsigned int width(void);
/** get the image height */
unsigned int height(void);
/** whether or not the image has alpha channel */
bool isAlphaPixelFormat(void);
/** whether or not the r, g, b channels are premultiplied by alpha channel */
bool isPremultipliedAlpha(void);
/** get the bit depth of each color channel */
int CGImageGetBitsPerComponent(void);
/** the source color space for the image, or 0 if the image is an image mask */
int CGImageGetColorSpace(void);
/** get the image data */
unsigned char* getData(void);
private:
bool loadPng(const char* strFileName);
bool loadPngFromStream(unsigned char *data, int nLength);
bool loadJpg(const char *strFileName);
private:
HBITMAP *m_pBitmap;
tImageInfo m_imageInfo;
};
}//namespace cocos2d
#endif // __PLATFORM_WIN32_UIIMAGE_H__

View File

@ -0,0 +1,39 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __SUPPORT_COCOS2D_TYPES_H__
#define __SUPPORT_COCOS2D_TYPES_H__
namespace cocos2d {
typedef signed char INT8;
typedef unsigned char UINT8;
typedef signed short INT16;
typedef unsigned short UINT16;
typedef signed int INT32;
typedef unsigned int UINT32;
typedef long long INT64;
typedef unsigned long long UINT64;
}//namespace cocos2d
#endif // __SUPPORT_COCOS2D_TYPES_H__

View File

@ -0,0 +1,46 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "NSLock.h"
namespace cocos2d {
NSLock::NSLock(void)
{
InitializeCriticalSection(&m_cs);
}
NSLock::~NSLock(void)
{
DeleteCriticalSection(&m_cs);
}
void NSLock::lock(void)
{
EnterCriticalSection(&m_cs);
}
void NSLock::unlock(void)
{
LeaveCriticalSection(&m_cs);
}
}//namespace cocos2d

View File

@ -0,0 +1,45 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __PLATFORM_WIN32_PLATFORM_NSLOCK_H__
#define __PLATFORM_WIN32_PLATFORM_NSLOCK_H__
#include <windows.h>
namespace cocos2d {
class NSLock
{
public:
NSLock(void);
~NSLock(void);
void lock(void);
void unlock(void);
private:
CRITICAL_SECTION m_cs;
};
}//namespace cocos2d
#endif // __PLATFORM_WIN32_PLATFORM_NSLOCK_H__

View File

@ -0,0 +1,141 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include <zlib.h>
#include "ZipUtils.h"
#include "ccMacros.h"
namespace cocos2d
{
int ZipUtils::inflateMemory_(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLength)
{
#if 1
/* ret value */
int err = Z_OK;
/* 256k initial decompress buffer */
int bufferSize = 256 * 1024;
*out = new unsigned char[bufferSize];
z_stream d_stream; /* decompression stream */
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = in;
d_stream.avail_in = inLength;
d_stream.next_out = *out;
d_stream.avail_out = bufferSize;
/* window size to hold 256k */
if( (err = inflateInit2(&d_stream, 15 + 32)) != Z_OK )
{
return err;
}
for (;;) {
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END)
{
break;
}
switch (err) {
case Z_NEED_DICT:
err = Z_DATA_ERROR;
case Z_DATA_ERROR:
case Z_MEM_ERROR:
inflateEnd(&d_stream);
return err;
}
// not enough memory ?
if (err != Z_STREAM_END)
{
// memory in iPhone is precious
// Should buffer factor be 1.5 instead of 2 ?
#define BUFFER_INC_FACTOR (2)
delete [] *out;
*out = new unsigned char[bufferSize * BUFFER_INC_FACTOR];
/* not enough memory, ouch */
if (! *out )
{
CCLOG("cocos2d: ZipUtils: realloc failed");
inflateEnd(&d_stream);
return Z_MEM_ERROR;
}
d_stream.next_out = *out + bufferSize;
d_stream.avail_out = bufferSize;
bufferSize *= BUFFER_INC_FACTOR;
}
}
*outLength = bufferSize - d_stream.avail_out;
err = inflateEnd(&d_stream);
return err;
#else
return 0;
#endif
}
int ZipUtils::inflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out)
{
#if 1
unsigned int outLength = 0;
int err = inflateMemory_(in, inLength, out, &outLength);
if (err != Z_OK || *out == NULL) {
if (err == Z_MEM_ERROR)
{
CCLOG("cocos2d: ZipUtils: Out of memory while decompressing map data!");
} else
if (err == Z_VERSION_ERROR)
{
CCLOG("cocos2d: ZipUtils: Incompatible zlib version!");
} else
if (err == Z_DATA_ERROR)
{
CCLOG("cocos2d: ZipUtils: Incorrect zlib compressed data!");
}
else
{
CCLOG("cocos2d: ZipUtils: Unknown error while decompressing map data!");
}
delete[] *out;
*out = NULL;
outLength = 0;
}
return outLength;
#else
return 0;
#endif
}
} // end of namespace cocos2d

View File

@ -0,0 +1,48 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __PLATFORM_WIN32_ZIPUTILS_H__
#define __PLATFORM_WIN32_ZIPUTILS_H__
namespace cocos2d
{
class ZipUtils
{
public:
/**
* Inflates either zlib or gzip deflated memory. The inflated memory is
* expected to be freed by the caller.
*
* @returns the length of the deflated buffer
*
@since v0.8.1
*/
static int inflateMemory(unsigned char *in, unsigned int inLength, unsigned char **out);
private:
static int inflateMemory_(unsigned char *in, unsigned int inLength, unsigned char **out, unsigned int *outLengh);
};
} // end of namespace cocos2d
#endif // __PLATFORM_WIN32_ZIPUTILS_H__

View File

@ -0,0 +1,34 @@
/****************************************************************************
Copyright (c) 2010 cocos2d-x.org
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCX_COMMON_WIN32__
#define __CCX_COMMON_WIN32__
#if defined(_USRDLL)
#define CCX_DLL __declspec(dllexport)
#else /* use a DLL library */
#define CCX_DLL __declspec(dllimport)
#endif
#endif // end of __CCX_COMMON_WIN32__

View File

@ -33,7 +33,7 @@ THE SOFTWARE.
#include "CGGeometry.h"
#include "CCTexture2D.h"
#include "CGAffineTransform.h"
#include "ssTsd.h"
#include <string.h>
using namespace std;
@ -922,7 +922,7 @@ void CCSprite::setDisplayFrame(CCSpriteFrame *pNewFrame)
setTextureRect(pNewFrame->getRect(), pNewFrame->getOriginalSize());
}
void CCSprite::setDisplayFrame(const char *pszAnimationName, Int32 nFrameIndex)
void CCSprite::setDisplayFrame(const char *pszAnimationName, int nFrameIndex)
{
if (! m_pAnimations)
{

View File

@ -28,6 +28,11 @@ THE SOFTWARE.
#include <GLES/gl.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
namespace cocos2d {
void gluPerspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)