mirror of https://github.com/axmolengine/axmol.git
Specific classes for Marmalade platform
This commit is contained in:
parent
d97e1b705f
commit
97967ffcb3
|
@ -0,0 +1,83 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2011 cocos2d-x.org http://cocos2d-x.org
|
||||||
|
Copyright (c) 2011 Максим Аксенов
|
||||||
|
|
||||||
|
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 "CCAccelerometer_airplay.h"
|
||||||
|
#include "ccMacros.h"
|
||||||
|
|
||||||
|
namespace cocos2d
|
||||||
|
{
|
||||||
|
|
||||||
|
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
|
||||||
|
|
||||||
|
CCAccelerometer::CCAccelerometer() : m_pAccelDelegate(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CCAccelerometer::~CCAccelerometer()
|
||||||
|
{
|
||||||
|
if( m_spCCAccelerometer ) {
|
||||||
|
delete m_spCCAccelerometer ;
|
||||||
|
m_spCCAccelerometer = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (m_spCCAccelerometer == NULL)
|
||||||
|
{
|
||||||
|
m_spCCAccelerometer = new CCAccelerometer();
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_spCCAccelerometer;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
||||||
|
{
|
||||||
|
m_pAccelDelegate = pDelegate;
|
||||||
|
|
||||||
|
if (pDelegate)
|
||||||
|
{
|
||||||
|
s3eAccelerometerStart();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s3eAccelerometerStop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCAccelerometer::update(float x, float y, float z, long sensorTimeStamp)
|
||||||
|
{
|
||||||
|
if (m_pAccelDelegate)
|
||||||
|
{
|
||||||
|
m_obAccelerationValue.x = ((double)x)/S3E_ACCELEROMETER_1G ;
|
||||||
|
m_obAccelerationValue.y = ((double)y)/S3E_ACCELEROMETER_1G ;
|
||||||
|
m_obAccelerationValue.z = ((double)z)/S3E_ACCELEROMETER_1G ;
|
||||||
|
m_obAccelerationValue.timestamp = (double)(sensorTimeStamp / 1000.0);
|
||||||
|
|
||||||
|
m_pAccelDelegate->didAccelerate(&m_obAccelerationValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of namespace cococs2d
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2011 cocos2d-x.org http://cocos2d-x.org
|
||||||
|
Copyright (c) 2011 Максим Аксенов
|
||||||
|
|
||||||
|
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_AIRPLAY_ACCELEROMETER_H__
|
||||||
|
#define __PLATFORM_AIRPLAY_ACCELEROMETER_H__
|
||||||
|
|
||||||
|
#include "CCAccelerometerDelegate.h"
|
||||||
|
#include "CCMutableArray.h"
|
||||||
|
#include "ccCommon.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace cocos2d {
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief
|
||||||
|
The CCAccelerometer class lets you register to receive
|
||||||
|
acceleration-related data from the onboard hardware.
|
||||||
|
*/
|
||||||
|
class CC_DLL CCAccelerometer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCAccelerometer();
|
||||||
|
~CCAccelerometer();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Returns the shared accelerometer object for the system.
|
||||||
|
*/
|
||||||
|
static CCAccelerometer* sharedAccelerometer();
|
||||||
|
|
||||||
|
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
||||||
|
void update(float x, float y, float z, long sensorTimeStamp);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static CCAccelerometer* m_spCCAccelerometer;
|
||||||
|
CCAccelerometerDelegate* m_pAccelDelegate;
|
||||||
|
CCAcceleration m_obAccelerationValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
}//namespace cocos2d
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,131 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2011 cocos2d-x.org http://cocos2d-x.org
|
||||||
|
Copyright (c) 2011 Максим Аксенов
|
||||||
|
|
||||||
|
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 "CCApplication.h"
|
||||||
|
#include "CCEGLView.h"
|
||||||
|
#include "CCDirector.h"
|
||||||
|
#include "CCAccelerometer.h"
|
||||||
|
#include "CCTouchDispatcher.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <s3e.h>
|
||||||
|
#include <IwMemBucketHelpers.h>
|
||||||
|
|
||||||
|
|
||||||
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
|
// sharedApplication pointer
|
||||||
|
CCApplication * CCApplication::sm_pSharedApplication = 0;
|
||||||
|
|
||||||
|
CCApplication::CCApplication()
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCApplication::CCApplication");
|
||||||
|
|
||||||
|
m_nAnimationInterval = 0;
|
||||||
|
CC_ASSERT(! sm_pSharedApplication);
|
||||||
|
sm_pSharedApplication = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCApplication::~CCApplication()
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCApplication::~CCApplication");
|
||||||
|
|
||||||
|
CC_ASSERT(this == sm_pSharedApplication);
|
||||||
|
sm_pSharedApplication = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int CCApplication::Run()
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCApplication::Run");
|
||||||
|
|
||||||
|
if ( ! initInstance() || !applicationDidFinishLaunching() )
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int64 updateTime = s3eTimerGetMs();
|
||||||
|
|
||||||
|
while (!s3eDeviceCheckQuitRequest())
|
||||||
|
{
|
||||||
|
int64 currentTime = s3eTimerGetMs();
|
||||||
|
if (currentTime - updateTime > m_nAnimationInterval)
|
||||||
|
{
|
||||||
|
updateTime = currentTime;
|
||||||
|
|
||||||
|
s3eDeviceYield(0);
|
||||||
|
s3eKeyboardUpdate();
|
||||||
|
s3ePointerUpdate();
|
||||||
|
|
||||||
|
ccAccelerationUpdate();
|
||||||
|
CCDirector::sharedDirector()->mainLoop();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
s3eDeviceYield(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCApplication::setAnimationInterval(double interval)
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCXApplication::setAnimationInterval");
|
||||||
|
m_nAnimationInterval = 1000 * interval;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CCApplication::Orientation CCApplication::setOrientation(Orientation orientation)
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCApplication::setOrientation");
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCApplication::statusBarFrame(CCRect * rect)
|
||||||
|
{
|
||||||
|
if (rect)
|
||||||
|
{
|
||||||
|
*rect = CCRectMake(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void CCApplication::ccAccelerationUpdate()
|
||||||
|
{
|
||||||
|
CCAccelerometer::sharedAccelerometer()->update(s3eAccelerometerGetX(),s3eAccelerometerGetY(),s3eAccelerometerGetZ(),s3eTimerGetMs());
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// static member function
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
CCApplication& CCApplication::sharedApplication()
|
||||||
|
{
|
||||||
|
CC_ASSERT(sm_pSharedApplication);
|
||||||
|
return *sm_pSharedApplication;
|
||||||
|
}
|
||||||
|
|
||||||
|
ccLanguageType CCApplication::getCurrentLanguage()
|
||||||
|
{
|
||||||
|
return kLanguageEnglish;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END;
|
|
@ -0,0 +1,121 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2011 cocos2d-x.org http://cocos2d-x.org
|
||||||
|
Copyright (c) 2011 Максим Аксенов
|
||||||
|
|
||||||
|
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 __CC_APPLICATION_AIRPLAY_H__
|
||||||
|
#define __CC_APPLICATION_AIRPLAY_H__
|
||||||
|
|
||||||
|
#include "CCCommon.h"
|
||||||
|
|
||||||
|
#include "CCGeometry.h"
|
||||||
|
#include "CCDirector.h"
|
||||||
|
#include "IwUtil.h"
|
||||||
|
#include "IwUtilInitTerm.h"
|
||||||
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
class CCRect;
|
||||||
|
|
||||||
|
class CC_DLL CCApplication
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
CCApplication();
|
||||||
|
virtual ~CCApplication();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Implement for initialize OpenGL instance, set source path, etc...
|
||||||
|
*/
|
||||||
|
virtual bool initInstance() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Implement CCDirector and sense init code here.
|
||||||
|
@return true Initialize success, app continue.
|
||||||
|
@return false Initialize failed, app terminate.
|
||||||
|
*/
|
||||||
|
virtual bool applicationDidFinishLaunching() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief The function be called when the application enter background
|
||||||
|
@param the pointer of the application
|
||||||
|
*/
|
||||||
|
virtual void applicationDidEnterBackground() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief The function be called when the application enter foreground
|
||||||
|
@param the pointer of the application
|
||||||
|
*/
|
||||||
|
virtual void applicationWillEnterForeground() = 0;
|
||||||
|
|
||||||
|
void setAnimationInterval(double interval);
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
/// Device oriented vertically, home button on the bottom
|
||||||
|
kOrientationPortrait = 0,
|
||||||
|
/// Device oriented vertically, home button on the top
|
||||||
|
kOrientationPortraitUpsideDown = 1,
|
||||||
|
/// Device oriented horizontally, home button on the right
|
||||||
|
kOrientationLandscapeLeft = 2,
|
||||||
|
/// Device oriented horizontally, home button on the left
|
||||||
|
kOrientationLandscapeRight = 3,
|
||||||
|
} Orientation;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Callback by CCDirector for change device orientation.
|
||||||
|
@orientation The defination of orientation which CCDirector want change to.
|
||||||
|
@return The actual orientation of the application.
|
||||||
|
*/
|
||||||
|
Orientation setOrientation(Orientation orientation);
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get status bar rectangle in EGLView window.
|
||||||
|
*/
|
||||||
|
void statusBarFrame(CCRect * rect);
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Run the message loop.
|
||||||
|
*/
|
||||||
|
virtual int Run();
|
||||||
|
|
||||||
|
void ccAccelerationUpdate();
|
||||||
|
/**
|
||||||
|
@brief Get current applicaiton instance.
|
||||||
|
@return Current application instance pointer.
|
||||||
|
*/
|
||||||
|
static CCApplication& sharedApplication();
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief Get current language config
|
||||||
|
@return Current language config
|
||||||
|
*/
|
||||||
|
static ccLanguageType getCurrentLanguage();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int64 m_nAnimationInterval;
|
||||||
|
static CCApplication * sm_pSharedApplication;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END;
|
||||||
|
#endif // end of __CC_APPLICATION_AIRPLAY_H__
|
|
@ -0,0 +1,279 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2011 cocos2d-x.org http://cocos2d-x.org
|
||||||
|
Copyright (c) 2011 Максим Аксенов
|
||||||
|
|
||||||
|
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 "CCEGLView.h"
|
||||||
|
|
||||||
|
#include "IwGL.h"
|
||||||
|
|
||||||
|
#include "CCDirector.h"
|
||||||
|
#include "CCSet.h"
|
||||||
|
#include "CCTouch.h"
|
||||||
|
#include "CCTouchDispatcher.h"
|
||||||
|
#include "CCKeypadDispatcher.h"
|
||||||
|
#include "ccMacros.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
|
CCEGLView::CCEGLView()
|
||||||
|
: m_pDelegate(NULL)
|
||||||
|
, m_fScreenScaleFactor(1.0)
|
||||||
|
, m_bNotHVGA(false)
|
||||||
|
|
||||||
|
, m_bCaptured(false)
|
||||||
|
, m_bAccelState(false)
|
||||||
|
, m_Key(s3eKeyFirst)
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCEGLView::CCEGLView");
|
||||||
|
|
||||||
|
// s3eSurfaceSetup( (s3eSurfacePixelType)-1, 0, 0, S3E_SURFACE_BLIT_DIR_NATIVE ) ;
|
||||||
|
|
||||||
|
IwGLInit();
|
||||||
|
|
||||||
|
m_sSizeInPixel.width = IwGLGetInt(IW_GL_WIDTH);
|
||||||
|
m_sSizeInPixel.height = IwGLGetInt(IW_GL_HEIGHT);
|
||||||
|
|
||||||
|
m_pSet = new CCSet;
|
||||||
|
m_pTouch = new CCTouch;
|
||||||
|
|
||||||
|
// Register pointer touch button event handler
|
||||||
|
s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, &TouchEventHandler, this);
|
||||||
|
|
||||||
|
// Register pointer motion button event handler
|
||||||
|
s3ePointerRegister(S3E_POINTER_MOTION_EVENT, &MotionEventHandler, this);
|
||||||
|
|
||||||
|
// Register keyboard event handler
|
||||||
|
s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT, &KeyEventHandler, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setFrameWidthAndHeight(int width, int height)
|
||||||
|
{
|
||||||
|
m_sSizeInPixel.width = width;
|
||||||
|
m_sSizeInPixel.height = height;
|
||||||
|
}
|
||||||
|
void CCEGLView::create(int width, int height)
|
||||||
|
{
|
||||||
|
if (width == 0 || height == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_sSizeInPoint.width = width;
|
||||||
|
m_sSizeInPoint.height = height;
|
||||||
|
|
||||||
|
// calculate the factor and the rect of viewport
|
||||||
|
m_fScreenScaleFactor = MIN((float)m_sSizeInPixel.width / m_sSizeInPoint.width,
|
||||||
|
(float)m_sSizeInPixel.height / m_sSizeInPoint.height);
|
||||||
|
int viewPortW = (int)(m_sSizeInPoint.width * m_fScreenScaleFactor);
|
||||||
|
int viewPortH = (int)(m_sSizeInPoint.height * m_fScreenScaleFactor);
|
||||||
|
m_rcViewPort.origin.x = (m_sSizeInPixel.width - viewPortW) / 2;
|
||||||
|
m_rcViewPort.origin.y = (m_sSizeInPixel.height - viewPortH) / 2;
|
||||||
|
m_rcViewPort.size.width = viewPortW;
|
||||||
|
m_rcViewPort.size.height = viewPortH;
|
||||||
|
|
||||||
|
m_bNotHVGA = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
CCEGLView::~CCEGLView()
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCEGLView::~CCEGLView");
|
||||||
|
|
||||||
|
release();
|
||||||
|
|
||||||
|
CC_SAFE_DELETE(m_pDelegate);
|
||||||
|
CC_SAFE_DELETE(m_pSet);
|
||||||
|
CC_SAFE_DELETE(m_pTouch);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CCSize CCEGLView::getSize()
|
||||||
|
{
|
||||||
|
if (m_bNotHVGA)
|
||||||
|
{
|
||||||
|
CCSize size(m_sSizeInPoint.width, m_sSizeInPoint.height);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCSize size(m_sSizeInPixel.width, m_sSizeInPixel.height);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void CCEGLView::setTouch(void* systemData)
|
||||||
|
{
|
||||||
|
s3ePointerEvent* event =(s3ePointerEvent*)systemData;
|
||||||
|
|
||||||
|
switch (event->m_Pressed)
|
||||||
|
{
|
||||||
|
case 1 :
|
||||||
|
m_bCaptured = true;
|
||||||
|
m_pTouch->SetTouchInfo(0, (float)event->m_x, (float)event->m_y);
|
||||||
|
m_pSet->addObject(m_pTouch);
|
||||||
|
m_pDelegate->touchesBegan(m_pSet, NULL);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0 :
|
||||||
|
if (m_bCaptured)
|
||||||
|
{
|
||||||
|
m_pTouch->SetTouchInfo(0, (float)event->m_x, (float)event->m_y);
|
||||||
|
m_pDelegate->touchesEnded(m_pSet, NULL);
|
||||||
|
m_pSet->removeObject(m_pTouch);
|
||||||
|
m_bCaptured = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void CCEGLView::setMotionTouch(void* systemData)
|
||||||
|
{
|
||||||
|
s3ePointerMotionEvent* event =(s3ePointerMotionEvent*)systemData;
|
||||||
|
if (m_bCaptured)
|
||||||
|
{
|
||||||
|
m_pTouch->SetTouchInfo(0, (float)event->m_x, (float)event->m_y);
|
||||||
|
m_pDelegate->touchesMoved(m_pSet, NULL);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void CCEGLView::setKeyTouch(void* systemData)
|
||||||
|
{
|
||||||
|
s3eKeyboardEvent* event = (s3eKeyboardEvent*)systemData;
|
||||||
|
if (event->m_Pressed)
|
||||||
|
{
|
||||||
|
if (event->m_Key!=m_Key)
|
||||||
|
{
|
||||||
|
CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeMenuClicked);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
|
||||||
|
|
||||||
|
}
|
||||||
|
m_Key =event->m_Key;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCEGLView::isOpenGLReady()
|
||||||
|
{
|
||||||
|
return (IwGLIsInitialised() && m_sSizeInPixel.width != 0 && m_sSizeInPixel.height !=0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCEGLView::release()
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCEGLView::release");
|
||||||
|
|
||||||
|
|
||||||
|
if (IwGLIsInitialised())
|
||||||
|
IwGLTerminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setTouchDelegate(EGLTouchDelegate * pDelegate)
|
||||||
|
{
|
||||||
|
m_pDelegate = pDelegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
EGLTouchDelegate* CCEGLView::getDelegate(void)
|
||||||
|
{
|
||||||
|
return m_pDelegate;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCEGLView::swapBuffers()
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCEGLView::swapBuffers(");
|
||||||
|
IwGLSwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCEGLView::canSetContentScaleFactor()
|
||||||
|
{
|
||||||
|
// can scale content?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
|
||||||
|
{
|
||||||
|
m_fScreenScaleFactor = contentScaleFactor;
|
||||||
|
}
|
||||||
|
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
|
||||||
|
{
|
||||||
|
if (m_bNotHVGA)
|
||||||
|
{
|
||||||
|
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
|
||||||
|
glViewport((GLint)(x * factor) + m_rcViewPort.origin.x,
|
||||||
|
(GLint)(y * factor) + m_rcViewPort.origin.y,
|
||||||
|
(GLint)(w * factor),
|
||||||
|
(GLint)(h * factor));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glViewport((GLint)x,
|
||||||
|
(GLint)y,
|
||||||
|
(GLint)w,
|
||||||
|
(GLint)h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CCEGLView::setScissorInPoints(float x, float y, float w, float h)
|
||||||
|
{
|
||||||
|
if (m_bNotHVGA)
|
||||||
|
{
|
||||||
|
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
|
||||||
|
glScissor((GLint)(x * factor) + m_rcViewPort.origin.x,
|
||||||
|
(GLint)(y * factor) + m_rcViewPort.origin.y,
|
||||||
|
(GLint)(w * factor),
|
||||||
|
(GLint)(h * factor));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glScissor((GLint)x,
|
||||||
|
(GLint)y,
|
||||||
|
(GLint)w,
|
||||||
|
(GLint)h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CCEGLView& CCEGLView::sharedOpenGLView()
|
||||||
|
{
|
||||||
|
static CCEGLView instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
float CCEGLView::getScreenScaleFactor()
|
||||||
|
{
|
||||||
|
return m_fScreenScaleFactor;
|
||||||
|
}
|
||||||
|
|
||||||
|
CCRect CCEGLView::getViewPort()
|
||||||
|
{
|
||||||
|
if (m_bNotHVGA)
|
||||||
|
{
|
||||||
|
return m_rcViewPort;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CCRect rect(0, 0, 0, 0);
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END;
|
|
@ -0,0 +1,114 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2011 cocos2d-x.org http://cocos2d-x.org
|
||||||
|
Copyright (c) 2011 Максим Аксенов
|
||||||
|
|
||||||
|
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 __CC_EGLVIEW_AIRPLAY_H__
|
||||||
|
#define __CC_EGLVIEW_AIRPLAY_H__
|
||||||
|
|
||||||
|
#include "CCGeometry.h"
|
||||||
|
#include "s3eKeyboard.h"
|
||||||
|
#include "IwUtil.h"
|
||||||
|
#include "IwUtilInitTerm.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN;
|
||||||
|
class CCSet;
|
||||||
|
class CCTouch;
|
||||||
|
class EGLTouchDelegate;
|
||||||
|
class CCKeypadDelegate;
|
||||||
|
|
||||||
|
|
||||||
|
class CC_DLL CCEGLView
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CCEGLView();
|
||||||
|
virtual ~CCEGLView();
|
||||||
|
|
||||||
|
CCSize getSize();
|
||||||
|
bool isOpenGLReady();
|
||||||
|
/**
|
||||||
|
* the width and height is the real size of phone
|
||||||
|
*/
|
||||||
|
void setFrameWidthAndHeight(int width, int height);
|
||||||
|
/**
|
||||||
|
* create a drawing rect,
|
||||||
|
* the width and heiht is the resource size match best
|
||||||
|
*/
|
||||||
|
void create(int width, int height);
|
||||||
|
EGLTouchDelegate* getDelegate(void);
|
||||||
|
|
||||||
|
// keep compatible
|
||||||
|
void release();
|
||||||
|
void setTouchDelegate(EGLTouchDelegate * pDelegate);
|
||||||
|
void swapBuffers();
|
||||||
|
bool canSetContentScaleFactor();
|
||||||
|
void setContentScaleFactor(float contentScaleFactor);
|
||||||
|
void setViewPortInPoints(float x, float y, float w, float h);
|
||||||
|
void setScissorInPoints(float x, float y, float w, float h);
|
||||||
|
CCRect getViewPort();
|
||||||
|
float getScreenScaleFactor();
|
||||||
|
|
||||||
|
// static function
|
||||||
|
/**
|
||||||
|
@brief get the shared main open gl window
|
||||||
|
*/
|
||||||
|
static CCEGLView& sharedOpenGLView();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
CCSize m_sSizeInPixel;
|
||||||
|
CCSize m_sSizeInPoint;
|
||||||
|
CCRect m_rcViewPort;
|
||||||
|
bool m_bNotHVGA;
|
||||||
|
|
||||||
|
EGLTouchDelegate *m_pDelegate;
|
||||||
|
float m_fScreenScaleFactor;
|
||||||
|
|
||||||
|
bool m_bAccelState;
|
||||||
|
bool m_bCaptured;
|
||||||
|
s3eKey m_Key;
|
||||||
|
CCSet * m_pSet;
|
||||||
|
CCTouch * m_pTouch;
|
||||||
|
|
||||||
|
void setTouch(void* systemData);
|
||||||
|
void setMotionTouch(void* systemData);
|
||||||
|
void setKeyTouch(void* systemData);
|
||||||
|
|
||||||
|
static int32 TouchEventHandler(void* systemData, void* userData)
|
||||||
|
{
|
||||||
|
((CCEGLView*)userData)->setTouch(systemData);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int32 MotionEventHandler(void* systemData, void* userData)
|
||||||
|
{
|
||||||
|
((CCEGLView*)userData)->setMotionTouch(systemData);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int32 KeyEventHandler(void* systemData, void* userData)
|
||||||
|
{
|
||||||
|
((CCEGLView*)userData)->setKeyTouch(systemData);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_CC_END;
|
||||||
|
|
||||||
|
#endif // end of __CC_EGLVIEW_AIRPLAY_H__
|
|
@ -0,0 +1,109 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2011 cocos2d-x.org http://cocos2d-x.org
|
||||||
|
Copyright (c) 2011 Максим Аксенов
|
||||||
|
|
||||||
|
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 "CCFileUtils.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "stack"
|
||||||
|
#include "CCString.h"
|
||||||
|
|
||||||
|
#include "CCApplication.h"
|
||||||
|
|
||||||
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
|
static char s_pszResourcePath[S3E_FILE_MAX_PATH] = {0};
|
||||||
|
|
||||||
|
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
|
||||||
|
{
|
||||||
|
|
||||||
|
IwAssert(GAME, pszRelativePath);
|
||||||
|
|
||||||
|
CCString * pRet = new CCString();
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::string relativeFile = fullPathFromRelativePath(pszRelativeFile);
|
||||||
|
|
||||||
|
CCString *pRet = new CCString();
|
||||||
|
pRet->autorelease();
|
||||||
|
pRet->m_sString = relativeFile.substr(0, relativeFile.rfind('/')+1);
|
||||||
|
pRet->m_sString += pszFilename;
|
||||||
|
return pRet->m_sString.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* pszMode, unsigned long * pSize)
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCFileUtils::getFileData");
|
||||||
|
|
||||||
|
s3eFile* pFile = s3eFileOpen(pszFileName, pszMode);
|
||||||
|
|
||||||
|
if (! pFile && getIsPopupNotify())
|
||||||
|
{
|
||||||
|
IwAssertMsg(GAME, pFile, ("Open file %s Failed. s3eFileError Code : %i", pszFileName, s3eFileGetError()));
|
||||||
|
}
|
||||||
|
if (! pFile)
|
||||||
|
{
|
||||||
|
*pSize = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int32 fileSize = s3eFileGetSize(pFile);
|
||||||
|
*pSize=fileSize;
|
||||||
|
|
||||||
|
static int32* pDataToBeReadBinary;
|
||||||
|
|
||||||
|
pDataToBeReadBinary = (int32*)s3eMallocBase(fileSize);
|
||||||
|
memset(pDataToBeReadBinary, 0, fileSize);
|
||||||
|
s3eFileRead(pDataToBeReadBinary, fileSize, 1, pFile);
|
||||||
|
s3eFileClose(pFile);
|
||||||
|
|
||||||
|
return (unsigned char*)pDataToBeReadBinary;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CCFileUtils::getWriteablePath()
|
||||||
|
{
|
||||||
|
// fixed me, what path can airplay can write
|
||||||
|
return string("");
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END;
|
||||||
|
|
|
@ -0,0 +1,281 @@
|
||||||
|
/****************************************************************************
|
||||||
|
Copyright (c) 2011 cocos2d-x.org http://cocos2d-x.org
|
||||||
|
Copyright (c) 2011 Максим Аксенов
|
||||||
|
|
||||||
|
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 "CCImage.h"
|
||||||
|
#include "CCCommon.h"
|
||||||
|
#include "CCStdC.h"
|
||||||
|
#include "CCFileUtils.h"
|
||||||
|
#include "s3eFile.h"
|
||||||
|
#include "IwRuntime.h"
|
||||||
|
#include "IwDebug.h"
|
||||||
|
#include "png.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned char* data;
|
||||||
|
int size;
|
||||||
|
int offset;
|
||||||
|
}tImageSource;
|
||||||
|
|
||||||
|
NS_CC_BEGIN;
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
// Implement CCImage
|
||||||
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
CCImage::CCImage()
|
||||||
|
: m_nWidth(0)
|
||||||
|
, m_nHeight(0)
|
||||||
|
, m_nBitsPerComponent(0)
|
||||||
|
, m_pData(0)
|
||||||
|
, m_bHasAlpha(false)
|
||||||
|
, m_bPreMulti(false)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CCImage::~CCImage()
|
||||||
|
{
|
||||||
|
CC_SAFE_DELETE_ARRAY(m_pData);
|
||||||
|
}
|
||||||
|
bool CCImage::initWithImageFile(const char * strPath, EImageFormat eImgFmt/* = eFmtPng*/)
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("UIImage::initWithImageFile");
|
||||||
|
CCFileData data(CCFileUtils::fullPathFromRelativePath(strPath), "rb");
|
||||||
|
return initWithImageData(data.getBuffer(), data.getSize(), eImgFmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCImage::initWithImageFileThreadSafe(const char *fullpath, EImageFormat imageType)
|
||||||
|
{
|
||||||
|
CC_UNUSED_PARAM(imageType);
|
||||||
|
CCFileData data(fullpath, "rb");
|
||||||
|
return initWithImageData(data.getBuffer(), data.getSize(), imageType);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCImage::initWithImageData(void * pData,
|
||||||
|
int nDataLen,
|
||||||
|
EImageFormat eFmt,
|
||||||
|
int nWidth,
|
||||||
|
int nHeight,
|
||||||
|
int nBitsPerComponent)
|
||||||
|
{
|
||||||
|
bool bRet = false;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
CC_BREAK_IF(! pData || nDataLen <= 0);
|
||||||
|
|
||||||
|
if (kFmtPng == eFmt)
|
||||||
|
{
|
||||||
|
bRet = _initWithPngData(pData, nDataLen);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (kFmtJpg == eFmt)
|
||||||
|
{
|
||||||
|
bRet = _initWithJpgData(pData, nDataLen);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (0);
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCImage::_initWithJpgData(void * data, int nSize)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void userReadData(png_structp pngPtr, png_bytep data, png_size_t length) {
|
||||||
|
png_voidp png_pointer = png_get_io_ptr(pngPtr);
|
||||||
|
s3eFileRead((char*)data, length, 1, (s3eFile*)png_pointer);
|
||||||
|
}
|
||||||
|
|
||||||
|
#define PNGSIGSIZE 8
|
||||||
|
bool CCImage::_initWithPngData(void * pData, int nDatalen)
|
||||||
|
{
|
||||||
|
IW_CALLSTACK("CCImage::_initWithPngData");
|
||||||
|
|
||||||
|
bool bRet = false;
|
||||||
|
|
||||||
|
s3eFile* pFile = s3eFileOpenFromMemory(pData, nDatalen);
|
||||||
|
|
||||||
|
IwAssert(GAME, pFile);
|
||||||
|
|
||||||
|
png_byte pngsig[PNGSIGSIZE];
|
||||||
|
|
||||||
|
bool is_png = false;
|
||||||
|
|
||||||
|
s3eFileRead((char*)pngsig, PNGSIGSIZE, 1, pFile);
|
||||||
|
|
||||||
|
is_png = png_sig_cmp(pngsig, 0, PNGSIGSIZE) == 0 ? true : false;
|
||||||
|
|
||||||
|
if (!is_png)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
png_structp pngPtr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
if (!pngPtr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
png_infop infoPtr = png_create_info_struct(pngPtr);
|
||||||
|
|
||||||
|
if (!infoPtr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
png_bytep* rowPtrs = NULL;
|
||||||
|
m_pData = NULL;
|
||||||
|
|
||||||
|
if (setjmp(png_jmpbuf(pngPtr))) {
|
||||||
|
png_destroy_read_struct(&pngPtr, &infoPtr,(png_infopp)0);
|
||||||
|
if (rowPtrs != NULL) delete [] rowPtrs;
|
||||||
|
if (m_pData != NULL) delete [] m_pData;
|
||||||
|
|
||||||
|
CCLog("ERROR: An error occured while reading the PNG file");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
png_set_read_fn(pngPtr, pFile, userReadData);
|
||||||
|
png_set_sig_bytes(pngPtr, PNGSIGSIZE);
|
||||||
|
png_read_info(pngPtr, infoPtr);
|
||||||
|
|
||||||
|
|
||||||
|
png_uint_32 bitdepth = png_get_bit_depth(pngPtr, infoPtr);
|
||||||
|
png_uint_32 channels = png_get_channels(pngPtr, infoPtr);
|
||||||
|
png_uint_32 color_type = png_get_color_type(pngPtr, infoPtr);
|
||||||
|
|
||||||
|
// Convert palette color to true color
|
||||||
|
if (color_type ==PNG_COLOR_TYPE_PALETTE)
|
||||||
|
png_set_palette_to_rgb(pngPtr);
|
||||||
|
|
||||||
|
// Convert low bit colors to 8 bit colors
|
||||||
|
if (png_get_bit_depth(pngPtr, infoPtr) < 8)
|
||||||
|
{
|
||||||
|
if (color_type==PNG_COLOR_TYPE_GRAY || color_type==PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
|
png_set_gray_1_2_4_to_8(pngPtr);
|
||||||
|
else
|
||||||
|
png_set_packing(pngPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (png_get_valid(pngPtr, infoPtr, PNG_INFO_tRNS))
|
||||||
|
png_set_tRNS_to_alpha(pngPtr);
|
||||||
|
|
||||||
|
// Convert high bit colors to 8 bit colors
|
||||||
|
if (bitdepth == 16)
|
||||||
|
png_set_strip_16(pngPtr);
|
||||||
|
|
||||||
|
// Convert gray color to true color
|
||||||
|
if (color_type==PNG_COLOR_TYPE_GRAY || color_type==PNG_COLOR_TYPE_GRAY_ALPHA)
|
||||||
|
png_set_gray_to_rgb(pngPtr);
|
||||||
|
|
||||||
|
// Update the changes
|
||||||
|
png_read_update_info(pngPtr, infoPtr);
|
||||||
|
|
||||||
|
// init image info
|
||||||
|
m_bPreMulti = true;
|
||||||
|
|
||||||
|
unsigned int bytesPerComponent = png_get_channels(pngPtr, infoPtr);
|
||||||
|
|
||||||
|
m_bHasAlpha = (bytesPerComponent == 4 ? true : false);
|
||||||
|
|
||||||
|
m_nHeight = (unsigned int)png_get_image_height(pngPtr, infoPtr);
|
||||||
|
m_nWidth = (unsigned int) png_get_image_width(pngPtr, infoPtr);
|
||||||
|
|
||||||
|
m_nBitsPerComponent = (unsigned int)png_get_bit_depth(pngPtr, infoPtr);
|
||||||
|
|
||||||
|
m_pData = new unsigned char[m_nHeight * m_nWidth * bytesPerComponent];
|
||||||
|
|
||||||
|
unsigned int bytesPerRow = m_nWidth * bytesPerComponent;
|
||||||
|
|
||||||
|
{
|
||||||
|
unsigned char *ptr = m_pData;
|
||||||
|
rowPtrs = new png_bytep[m_nHeight];
|
||||||
|
|
||||||
|
for (int i = 0; i < m_nHeight; i++) {
|
||||||
|
|
||||||
|
int q = (i) * bytesPerRow;
|
||||||
|
|
||||||
|
rowPtrs[i] = (png_bytep)m_pData + q;
|
||||||
|
}
|
||||||
|
|
||||||
|
png_read_image(pngPtr, rowPtrs);
|
||||||
|
|
||||||
|
delete[] (png_bytep)rowPtrs;
|
||||||
|
png_destroy_read_struct(&pngPtr, &infoPtr,(png_infopp)0);
|
||||||
|
|
||||||
|
s3eFileClose(pFile);
|
||||||
|
pFile = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// premultiplay if alpha
|
||||||
|
if(m_bHasAlpha)
|
||||||
|
for(unsigned int i = 0; i < m_nHeight*bytesPerRow; i += bytesPerComponent){
|
||||||
|
*(m_pData + i + 0) = (*(m_pData + i + 0) * *(m_pData + i + 3) + 1) >> 8;
|
||||||
|
*(m_pData + i + 1) = (*(m_pData + i + 1) * *(m_pData + i + 3) + 1) >> 8;
|
||||||
|
*(m_pData + i + 2) = (*(m_pData + i + 2) * *(m_pData + i + 3) + 1) >> 8;
|
||||||
|
*(m_pData + i + 3) = *(m_pData + i + 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bRet = true;
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCImage::initWithString(
|
||||||
|
const char * pText,
|
||||||
|
int nWidth/* = 0*/,
|
||||||
|
int nHeight/* = 0*/,
|
||||||
|
ETextAlign eAlignMask/* = kAlignCenter*/,
|
||||||
|
const char * pFontName/* = nil*/,
|
||||||
|
int nSize/* = 0*/)
|
||||||
|
{
|
||||||
|
bool bRet = false;
|
||||||
|
return bRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCImage::saveToFile(const char *pszFilePath, bool bIsToRGB)
|
||||||
|
{
|
||||||
|
// todo
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCImage::_initWithRawData(void * pData, int nDatalen, int nWidth, int nHeight, int nBitsPerComponent)
|
||||||
|
{
|
||||||
|
// todo
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCImage::_saveImageToPNG(const char * pszFilePath, bool bIsToRGB)
|
||||||
|
{
|
||||||
|
// todo
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCImage::_saveImageToJPG(const char * pszFilePath)
|
||||||
|
{
|
||||||
|
// todo
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_CC_END;
|
Loading…
Reference in New Issue