diff --git a/HelloWorld/Classes/AppDelegate.cpp b/HelloWorld/Classes/AppDelegate.cpp
index 5cf758ebfd..30503e2932 100644
--- a/HelloWorld/Classes/AppDelegate.cpp
+++ b/HelloWorld/Classes/AppDelegate.cpp
@@ -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
diff --git a/HelloWorld/bada/sdk1.2/.cproject b/HelloWorld/bada/sdk1.2/.cproject
index bb895199bb..6fd4909049 100644
--- a/HelloWorld/bada/sdk1.2/.cproject
+++ b/HelloWorld/bada/sdk1.2/.cproject
@@ -72,7 +72,7 @@
-
+
@@ -568,7 +568,8 @@
-
+
+
@@ -1064,7 +1065,8 @@
-
+
+
diff --git a/HelloWorld/bada/sdk1.2/.project b/HelloWorld/bada/sdk1.2/.project
index e9870b23eb..6f13d2415b 100644
--- a/HelloWorld/bada/sdk1.2/.project
+++ b/HelloWorld/bada/sdk1.2/.project
@@ -82,14 +82,9 @@
- AppDelegate.cpp
- 1
- cocos2dx_root/HelloWorld/AppDelegate.cpp
-
-
- HelloWorldScene.cpp
- 1
- cocos2dx_root/HelloWorld/HelloWorldScene.cpp
+ Classes
+ 2
+ cocos2dx_root/HelloWorld/Classes
src
diff --git a/HelloWorld/bada/src/HelloWorldEntry.cpp b/HelloWorld/bada/src/HelloWorldEntry.cpp
index a4e63fae32..2808e54099 100644
--- a/HelloWorld/bada/src/HelloWorldEntry.cpp
+++ b/HelloWorld/bada/src/HelloWorldEntry.cpp
@@ -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;
diff --git a/cocos2dx/platform/bada/CCAccelerometer_bada.cpp b/cocos2dx/platform/bada/CCAccelerometer_bada.cpp
index 96dbe8366d..17b3b2f740 100644
--- a/cocos2dx/platform/bada/CCAccelerometer_bada.cpp
+++ b/cocos2dx/platform/bada/CCAccelerometer_bada.cpp
@@ -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;
diff --git a/cocos2dx/platform/bada/CCAccelerometer_bada.h b/cocos2dx/platform/bada/CCAccelerometer_bada.h
index b0bf0f5aeb..1d78349c2a 100644
--- a/cocos2dx/platform/bada/CCAccelerometer_bada.h
+++ b/cocos2dx/platform/bada/CCAccelerometer_bada.h
@@ -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
diff --git a/cocos2dx/platform/bada/CCEGLView_bada.cpp b/cocos2dx/platform/bada/CCEGLView_bada.cpp
index acb706d7cd..7f2c658747 100644
--- a/cocos2dx/platform/bada/CCEGLView_bada.cpp
+++ b/cocos2dx/platform/bada/CCEGLView_bada.cpp
@@ -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);
+ float x, y;
+ if (!m_bNotHVGA)
+ {
+ x = currentPosition.x * 2 / 3;
+ y = currentPosition.y * 2 / 3;
+ }
+ else
+ {
+ x = currentPosition.x;
+ y = currentPosition.y;
+ }
+ AppLog("OnTouchPressed... x = %f, y = %f", x, y);
if (m_pDelegate && m_pTouch)
{
m_bCaptured = true;
- if (m_bNotHVGA)
- {
- m_pTouch->SetTouchInfo(0, (float)currentPosition.x, (float)currentPosition.y);
- }
- else
- {
- m_pTouch->SetTouchInfo(0, (float)currentPosition.x*2/3, (float)currentPosition.y*2/3);
- }
-
+ 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);
+ float x, y;
+ if (!m_bNotHVGA)
+ {
+ x = currentPosition.x * 2 / 3;
+ y = currentPosition.y * 2 / 3;
+ }
+ else
+ {
+ x = currentPosition.x;
+ y = currentPosition.y;
+ }
+
+ AppLog("OnTouchReleased... x = %f, y = %f", x, y);
if (m_bCaptured)
{
- if (m_bNotHVGA)
- {
- m_pTouch->SetTouchInfo(0, (float)currentPosition.x, (float)currentPosition.y);
- }
- else
- {
- m_pTouch->SetTouchInfo(0, (float)currentPosition.x*2/3, (float)currentPosition.y*2/3);
- }
-
+ 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);
+ float x, y;
+ if (!m_bNotHVGA)
+ {
+ x = currentPosition.x * 2 / 3;
+ y = currentPosition.y * 2 / 3;
+ }
+ else
+ {
+ x = currentPosition.x;
+ y = currentPosition.y;
+ }
+ AppLog("OnTouchMoved... x = %f, y = %f", x, y);
if (m_bCaptured)
{
- if (m_bNotHVGA)
- {
- m_pTouch->SetTouchInfo(0, (float)currentPosition.x, (float)currentPosition.y);
- }
- else
- {
- m_pTouch->SetTouchInfo(0, (float)currentPosition.x*2/3, (float)currentPosition.y*2/3);
- }
+ m_pTouch->SetTouchInfo(0, (x - m_rcViewPort.origin.x) / m_fScreenScaleFactor, (y - m_rcViewPort.origin.y) / m_fScreenScaleFactor);
m_pDelegate->touchesMoved(m_pSet, NULL);
}
}
diff --git a/cocos2dx/platform/bada/CCEGLView_bada.h b/cocos2dx/platform/bada/CCEGLView_bada.h
index 28474963d7..7f0e8b2ce4 100644
--- a/cocos2dx/platform/bada/CCEGLView_bada.h
+++ b/cocos2dx/platform/bada/CCEGLView_bada.h
@@ -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);
diff --git a/tests/AppDelegate.cpp b/tests/AppDelegate.cpp
index e7a1848b15..098bcfd233 100644
--- a/tests/AppDelegate.cpp
+++ b/tests/AppDelegate.cpp
@@ -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