add scale support

This commit is contained in:
dumganhar 2011-09-30 17:19:16 +08:00
parent 1830b4e2e9
commit beaa489406
9 changed files with 153 additions and 135 deletions

View File

@ -69,6 +69,15 @@ bool AppDelegate::initInstance() {
CCFileUtils::setResourcePath("../Resource/");
#endif // CC_PLATFORM_LINUX
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320));
CCFileUtils::setResourcePath("/Res/");
#endif // CC_PLATFORM_BADA
bRet = true;
} while (0);
return bRet;
@ -85,7 +94,9 @@ bool AppDelegate::applicationDidFinishLaunching() {
// turn on display FPS
pDirector->setDisplayFPS(true);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
#endif
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// set FPS. the default value is 1.0/60 if you don't call this

View File

@ -72,7 +72,7 @@
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="src" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="Classes"/>
</sourceEntries>
</configuration>
</storageModule>
@ -568,7 +568,8 @@
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Classes"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
</sourceEntries>
</configuration>
</storageModule>
@ -1064,7 +1065,8 @@
</toolChain>
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="Classes"/>
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="src"/>
</sourceEntries>
</configuration>
</storageModule>

View File

@ -82,14 +82,9 @@
</natures>
<linkedResources>
<link>
<name>AppDelegate.cpp</name>
<type>1</type>
<locationURI>cocos2dx_root/HelloWorld/AppDelegate.cpp</locationURI>
</link>
<link>
<name>HelloWorldScene.cpp</name>
<type>1</type>
<locationURI>cocos2dx_root/HelloWorld/HelloWorldScene.cpp</locationURI>
<name>Classes</name>
<type>2</type>
<locationURI>cocos2dx_root/HelloWorld/Classes</locationURI>
</link>
<link>
<name>src</name>

View File

@ -1,7 +1,7 @@
/**
* This file contains the bada application entry point.
*/
#include "../../AppDelegate.h"
#include "../../Classes/AppDelegate.h"
using namespace Osp::Base;
using namespace Osp::Base::Collection;

View File

@ -31,8 +31,11 @@ NS_CC_BEGIN;
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
CCAccelerometer::CCAccelerometer() : m_pAccelDelegate(NULL)
CCAccelerometer::CCAccelerometer() :
m_pAccelDelegate(NULL)
, m_pSensor(NULL)
{
}
CCAccelerometer::~CCAccelerometer()
@ -52,6 +55,14 @@ CCAccelerometer* CCAccelerometer::sharedAccelerometer()
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
{
m_pAccelDelegate = pDelegate;
if (pDelegate)
{
setEnable(true);
}
else
{
setEnable(false);
}
}
void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorData, result r)
@ -64,14 +75,47 @@ void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorDa
sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Y, y);
sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Z, z);
// only consider land postion, to be continued.
CCAcceleration AccValue;
AccValue.x = -x;
AccValue.y = -y;
AccValue.z = -z;
AccValue.x = y;
AccValue.y = -x;
AccValue.z = z;
AccValue.timestamp = timeStamp;
m_pAccelDelegate->didAccelerate(&AccValue);
AppLog("####################TimeStamp:[%d], Accel.x,y,z:[%f,%f,%f]", timeStamp, x, y, z);
AppLog("##TimeStamp:[%d], Accel.x,y,z:[%f,%f,%f]", timeStamp, x, y, z);
}
void CCAccelerometer::setEnable(bool bEnable)
{
if (m_pSensor != NULL)
{
m_pSensor->RemoveSensorListener(*this);
}
CC_SAFE_DELETE(m_pSensor);
if (bEnable)
{
long interval = 10;
bool available = false;
result r = E_INVALID_STATE;
m_pSensor = new SensorManager();
m_pSensor->Construct();
available = m_pSensor->IsAvailable(SENSOR_TYPE_ACCELERATION);
if (available)
{
long intervalTemp = 0;
m_pSensor->GetMaxInterval(SENSOR_TYPE_ACCELERATION, intervalTemp);
if (interval > intervalTemp)
interval = intervalTemp;
m_pSensor->GetMinInterval(SENSOR_TYPE_ACCELERATION, intervalTemp);
if (interval < intervalTemp)
interval = intervalTemp;
r = m_pSensor->AddSensorListener(*this, SENSOR_TYPE_ACCELERATION, interval, false);
}
}
}
NS_CC_END;

View File

@ -45,8 +45,11 @@ public:
void setDelegate(CCAccelerometerDelegate* pDelegate);
virtual void OnDataReceived(Osp::Uix::SensorType sensorType, Osp::Uix::SensorData& sensorData , result r);
private:
void setEnable(bool bEnable);
static CCAccelerometer* m_spCCAccelerometer;
CCAccelerometerDelegate* m_pAccelDelegate;
Osp::Uix::SensorManager* m_pSensor;
};
}//namespace cocos2d

View File

@ -172,8 +172,6 @@ private:
//////////////////////////////////////////////////////////////////////////
// impliment CCEGLView
//////////////////////////////////////////////////////////////////////////
CCEGLView::CCEGLView()
: m_bNotHVGA(true)
, m_pDelegate(NULL)
@ -198,55 +196,7 @@ CCEGLView::~CCEGLView()
CCSize CCEGLView::getSize()
{
CCSize s;
// if (m_nowOrientation == ORIENTATION_PORTRAIT || m_nowOrientation == ORIENTATION_PORTRAIT_REVERSE)
// {
// if (m_bNotHVGA)
// {
// s = CCSizeMake(480, 800);
// }
// else
// {
// s = CCSizeMake(320, 480);
// }
// }
// else
// {
// if (m_bNotHVGA)
// {
// s = CCSizeMake(800, 480);
// }
// else
// {
// s = CCSizeMake(480, 320);
// }
// }
//
if (m_nowOrientation == ORIENTATION_PORTRAIT || m_nowOrientation == ORIENTATION_PORTRAIT_REVERSE)
{
if (m_bNotHVGA)
{
s = CCSizeMake(MIN(m_sSizeInPoint.width, m_sSizeInPoint.height), MAX(m_sSizeInPoint.width, m_sSizeInPoint.height));
}
else
{
s = CCSizeMake(MIN(m_sSizeInPixel.width, m_sSizeInPixel.height), MAX(m_sSizeInPixel.width, m_sSizeInPixel.height));
}
}
else
{
if (m_bNotHVGA)
{
s = CCSizeMake(MAX(m_sSizeInPoint.width, m_sSizeInPoint.height), MIN(m_sSizeInPoint.width, m_sSizeInPoint.height));
}
else
{
s = CCSizeMake(MAX(m_sSizeInPixel.width, m_sSizeInPixel.height), MIN(m_sSizeInPixel.width, m_sSizeInPixel.height));
}
}
return s;
return CCSize((float)(m_sSizeInPoint.width), (float)(m_sSizeInPoint.height));
}
CCRect CCEGLView::getFrame()
@ -313,15 +263,11 @@ int CCEGLView::setDeviceOrientation(int eOritation)
{
if (m_bNotHVGA)
{
m_sSizeInPoint.width = 480;
m_sSizeInPoint.height = 800;
m_sSizeInPixel.width = 480;
m_sSizeInPixel.height = 800;
}
else
{
m_sSizeInPoint.width = 320;
m_sSizeInPoint.height = 480;
m_sSizeInPixel.width = 320;
m_sSizeInPixel.height = 480;
}
@ -330,25 +276,32 @@ int CCEGLView::setDeviceOrientation(int eOritation)
{
if (m_bNotHVGA)
{
m_sSizeInPoint.width = 800;
m_sSizeInPoint.height = 480;
m_sSizeInPixel.width = 800;
m_sSizeInPixel.height = 480;
}
else
{
m_sSizeInPoint.width = 480;
m_sSizeInPoint.height = 320;
m_sSizeInPixel.width = 480;
m_sSizeInPixel.height = 320;
}
}
// 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;
return m_eInitOrientation;
}
void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
{
if (m_bNotHVGA)
// if (m_bNotHVGA)
{
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glViewport((GLint)(x * factor) + m_rcViewPort.origin.x,
@ -356,18 +309,18 @@ void CCEGLView::setViewPortInPoints(float x, float y, float w, float h)
(GLint)(w * factor),
(GLint)(h * factor));
}
else
{
glViewport((GLint)x,
(GLint)y,
(GLint)w,
(GLint)h);
}
// else
// {
// glViewport((GLint)x,
// (GLint)y,
// (GLint)w,
// (GLint)h);
// }
}
void CCEGLView::setScissorInPoints(float x, float y, float w, float h)
{
if (m_bNotHVGA)
// if (m_bNotHVGA)
{
float factor = m_fScreenScaleFactor / CC_CONTENT_SCALE_FACTOR();
glScissor((GLint)(x * factor) + m_rcViewPort.origin.x,
@ -375,23 +328,23 @@ void CCEGLView::setScissorInPoints(float x, float y, float w, float h)
(GLint)(w * factor),
(GLint)(h * factor));
}
else
{
glScissor((GLint)x,
(GLint)y,
(GLint)w,
(GLint)h);
}
// else
// {
// glScissor((GLint)x,
// (GLint)y,
// (GLint)w,
// (GLint)h);
// }
}
void CCEGLView::setIMEKeyboardState(bool /*bOpen*/)
void CCEGLView::setIMEKeyboardState(bool bOpen)
{
}
//bada
bool
CCEGLView::Create(Osp::App::Application* pApp)
bool CCEGLView::Create(Osp::App::Application* pApp, int width, int height)
{
m_sSizeInPoint.width = width;
m_sSizeInPoint.height = height;
// Construct an XML form
Construct(FORM_STYLE_NORMAL);
Frame *pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
@ -423,16 +376,12 @@ CCEGLView::OnInitializing(void)
|| (rc.width == 720 && rc.height == 480))
{
m_bNotHVGA = false;
m_sSizeInPoint.width = 320;
m_sSizeInPoint.height = 480;
m_sSizeInPixel.width = 320;
m_sSizeInPixel.height = 480;
}
else
{
m_bNotHVGA = true;
m_sSizeInPoint.width = 480;
m_sSizeInPoint.height = 800;
m_sSizeInPixel.width = 480;
m_sSizeInPixel.height = 800;
}
@ -452,8 +401,7 @@ CCEGLView::OnInitializing(void)
return r;
}
result
CCEGLView::OnTerminating(void)
result CCEGLView::OnTerminating(void)
{
result r = E_SUCCESS;
@ -472,19 +420,22 @@ void CCEGLView::OnTouchIndicated(const Osp::Ui::Control& source,
void CCEGLView::OnTouchPressed(const Osp::Ui::Control& source,
const Osp::Graphics::Point& currentPosition, const Osp::Ui::TouchEventInfo & touchInfo)
{
AppLog("OnTouchPressed... x = %d, y = %d", currentPosition.x, currentPosition.y);
if (m_pDelegate && m_pTouch)
float x, y;
if (!m_bNotHVGA)
{
m_bCaptured = true;
if (m_bNotHVGA)
{
m_pTouch->SetTouchInfo(0, (float)currentPosition.x, (float)currentPosition.y);
x = currentPosition.x * 2 / 3;
y = currentPosition.y * 2 / 3;
}
else
{
m_pTouch->SetTouchInfo(0, (float)currentPosition.x*2/3, (float)currentPosition.y*2/3);
x = currentPosition.x;
y = currentPosition.y;
}
AppLog("OnTouchPressed... x = %f, y = %f", x, y);
if (m_pDelegate && m_pTouch)
{
m_bCaptured = true;
m_pTouch->SetTouchInfo(0, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
m_pSet->addObject(m_pTouch);
m_pDelegate->touchesBegan(m_pSet, NULL);
}
@ -503,18 +454,22 @@ void CCEGLView::OnTouchLongPressed(const Osp::Ui::Control& source,
void CCEGLView::OnTouchReleased(const Osp::Ui::Control& source,
const Osp::Graphics::Point& currentPosition, const Osp::Ui::TouchEventInfo & touchInfo)
{
AppLog("OnTouchReleased... x = %d, y = %d", currentPosition.x, currentPosition.y);
if (m_bCaptured)
float x, y;
if (!m_bNotHVGA)
{
if (m_bNotHVGA)
{
m_pTouch->SetTouchInfo(0, (float)currentPosition.x, (float)currentPosition.y);
x = currentPosition.x * 2 / 3;
y = currentPosition.y * 2 / 3;
}
else
{
m_pTouch->SetTouchInfo(0, (float)currentPosition.x*2/3, (float)currentPosition.y*2/3);
x = currentPosition.x;
y = currentPosition.y;
}
AppLog("OnTouchReleased... x = %f, y = %f", x, y);
if (m_bCaptured)
{
m_pTouch->SetTouchInfo(0, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
m_pDelegate->touchesEnded(m_pSet, NULL);
m_pSet->removeObject(m_pTouch);
m_bCaptured = false;
@ -525,17 +480,21 @@ void CCEGLView::OnTouchReleased(const Osp::Ui::Control& source,
void CCEGLView::OnTouchMoved(const Osp::Ui::Control& source,
const Osp::Graphics::Point& currentPosition, const Osp::Ui::TouchEventInfo & touchInfo)
{
AppLog("OnTouchMoved... x = %d, y = %d", currentPosition.x, currentPosition.y);
if (m_bCaptured)
float x, y;
if (!m_bNotHVGA)
{
if (m_bNotHVGA)
{
m_pTouch->SetTouchInfo(0, (float)currentPosition.x, (float)currentPosition.y);
x = currentPosition.x * 2 / 3;
y = currentPosition.y * 2 / 3;
}
else
{
m_pTouch->SetTouchInfo(0, (float)currentPosition.x*2/3, (float)currentPosition.y*2/3);
x = currentPosition.x;
y = currentPosition.y;
}
AppLog("OnTouchMoved... x = %f, y = %f", x, y);
if (m_bCaptured)
{
m_pTouch->SetTouchInfo(0, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
m_pDelegate->touchesMoved(m_pSet, NULL);
}
}

View File

@ -68,8 +68,12 @@ public:
*/
static CCEGLView& sharedOpenGLView();
//bada
bool Create(Osp::App::Application* pApp);
/*
* param
* width[in]: resource width
* height[in]: resource height
*/
bool Create(Osp::App::Application* pApp, int width, int height);
virtual result OnInitializing(void);
virtual result OnTerminating(void);

View File

@ -78,7 +78,7 @@ bool AppDelegate::initInstance()
#if (CC_TARGET_PLATFORM == CC_PLATFORM_BADA)
CCEGLView * pMainWnd = new CCEGLView();
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this));
CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(this, 480, 320));
CCFileUtils::setResourcePath("/Res/");
#endif // CC_PLATFORM_BADA