2013-04-30 00:14:11 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
Copyright (c) 2013 Lee, Jae-Hong
|
|
|
|
|
|
|
|
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 "CCOspApplication.h"
|
|
|
|
#include "CCOspForm.h"
|
|
|
|
#include "cocos2d.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace Tizen::App;
|
|
|
|
using namespace Tizen::System;
|
2013-05-06 20:25:42 +08:00
|
|
|
using namespace Tizen::Ui;
|
2013-04-30 00:14:11 +08:00
|
|
|
using namespace Tizen::Ui::Controls;
|
|
|
|
using namespace Tizen::Base::Runtime;
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication * OspApplication::sm_pSharedOspApplication = 0;
|
|
|
|
OspApplicationInitialized OspApplication::sm_pApplicationInitialized = 0;
|
|
|
|
Orientation OspApplication::sm_eScreenOrientation = ORIENTATION_NONE;
|
2013-04-30 00:14:11 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OspApplication()
|
2013-04-30 00:14:11 +08:00
|
|
|
: __pForm(null)
|
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
CCAssert(! sm_pSharedOspApplication, "");
|
|
|
|
sm_pSharedOspApplication = this;
|
2013-04-30 00:14:11 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::~OspApplication()
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
CCAssert(this == sm_pSharedOspApplication, "");
|
|
|
|
sm_pSharedOspApplication = NULL;
|
2013-04-30 00:14:11 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 18:20:27 +08:00
|
|
|
Tizen::App::Application*
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::CreateInstance(void)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
|
|
|
// Create the instance through the constructor.
|
2013-06-20 14:13:12 +08:00
|
|
|
return new (std::nothrow) OspApplication();
|
2013-04-30 00:14:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::SetApplicationInitializedCallback(OspApplicationInitialized p)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
|
|
|
sm_pApplicationInitialized = p;
|
|
|
|
}
|
|
|
|
|
2013-05-06 20:25:42 +08:00
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::SetScreenOrientation(Orientation orientation)
|
2013-05-06 20:25:42 +08:00
|
|
|
{
|
2013-05-17 21:04:39 +08:00
|
|
|
sm_eScreenOrientation = orientation;
|
2013-05-06 20:25:42 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication*
|
|
|
|
OspApplication::GetInstance(void)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
CCAssert(sm_pSharedOspApplication, "");
|
|
|
|
return sm_pSharedOspApplication;
|
2013-04-30 00:14:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Tizen::Ui::Controls::Form*
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::getOspForm()
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
|
|
|
return __pForm;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OnAppInitializing(AppRegistry& appRegistry)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
|
|
|
CCLOG("OnAppInitializing");
|
|
|
|
|
|
|
|
result r = E_SUCCESS;
|
|
|
|
|
2013-05-06 20:25:42 +08:00
|
|
|
__pFrame = new (std::nothrow) Frame();
|
2013-06-20 14:13:12 +08:00
|
|
|
TryReturn(__pFrame != null, E_FAILURE, "[OspApplication] Generating a frame failed.");
|
2013-04-30 00:14:11 +08:00
|
|
|
|
2013-05-06 20:25:42 +08:00
|
|
|
r = __pFrame->Construct();
|
2013-06-20 14:13:12 +08:00
|
|
|
TryReturn(!IsFailed(r), E_FAILURE, "[OspApplication] pAppFrame->Construct() failed.");
|
2013-04-30 00:14:11 +08:00
|
|
|
|
2013-05-06 20:25:42 +08:00
|
|
|
this->AddFrame(*__pFrame);
|
2013-04-30 00:14:11 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
__pForm = new (std::nothrow) OspForm;
|
|
|
|
TryCatch(__pForm != null, , "[OspApplication] Allocation of OspForm failed.");
|
2013-04-30 00:14:11 +08:00
|
|
|
|
|
|
|
r = __pForm->Construct(FORM_STYLE_NORMAL);
|
2013-06-20 14:13:12 +08:00
|
|
|
TryCatch(!IsFailed(r), , "[OspApplication] __pForm->Construct(FORM_STYLE_NORMAL) failed.");
|
2013-04-30 00:14:11 +08:00
|
|
|
|
|
|
|
r = GetAppFrame()->GetFrame()->AddControl(*__pForm);
|
2013-06-20 14:13:12 +08:00
|
|
|
TryCatch(!IsFailed(r), , "[OspApplication] GetAppFrame()->GetFrame()->AddControl(*__pForm) failed.");
|
2013-04-30 00:14:11 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
CATCH:
|
|
|
|
delete __pForm;
|
|
|
|
__pForm = null;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OnAppInitialized(void)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
|
|
|
sm_pApplicationInitialized();
|
2013-05-06 20:25:42 +08:00
|
|
|
__pFrame->SetOrientation(sm_eScreenOrientation);
|
2013-05-05 12:25:23 +08:00
|
|
|
return true;
|
2013-04-30 00:14:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OnAppTerminating(AppRegistry& appRegistry, bool forcedTermination)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
2013-07-12 13:11:21 +08:00
|
|
|
EGLView::getInstance()->cleanup();
|
2013-04-30 00:14:11 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OnForeground(void)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
2013-07-12 13:11:21 +08:00
|
|
|
Tizen::Base::Runtime::Timer* timer = EGLView::getInstance()->getTimer();
|
2013-04-30 00:14:11 +08:00
|
|
|
|
|
|
|
if (timer != null)
|
|
|
|
{
|
2013-06-20 18:20:27 +08:00
|
|
|
timer->Start(cocos2d::Application::sharedApplication()->getAnimationInterval());
|
2013-04-30 00:14:11 +08:00
|
|
|
}
|
2013-05-21 21:48:51 +08:00
|
|
|
|
2013-07-12 11:50:36 +08:00
|
|
|
if (Director::getInstance()->getOpenGLView())
|
2013-05-21 21:48:51 +08:00
|
|
|
{
|
2013-06-20 18:20:27 +08:00
|
|
|
cocos2d::Application::sharedApplication()->applicationWillEnterForeground();
|
2013-05-21 21:48:51 +08:00
|
|
|
}
|
2013-04-30 00:14:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OnBackground(void)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
2013-07-12 13:11:21 +08:00
|
|
|
Tizen::Base::Runtime::Timer* timer = EGLView::getInstance()->getTimer();
|
2013-04-30 00:14:11 +08:00
|
|
|
|
|
|
|
if (timer != null)
|
|
|
|
{
|
|
|
|
timer->Cancel();
|
|
|
|
}
|
2013-05-21 21:48:51 +08:00
|
|
|
|
2013-06-20 18:20:27 +08:00
|
|
|
cocos2d::Application::sharedApplication()->applicationDidEnterBackground();
|
2013-04-30 00:14:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OnLowMemory(void)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OnBatteryLevelChanged(BatteryLevel batteryLevel)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OnScreenOn(void)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-20 14:13:12 +08:00
|
|
|
OspApplication::OnScreenOff(void)
|
2013-04-30 00:14:11 +08:00
|
|
|
{
|
|
|
|
}
|