mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
V3.5.0 create window (#10481)
* 1. Modify the parameters of the creation window 2. Modify the relationship between platform and interface 3. Rename vibrate to vibrator in linux and QNX * Fix empty platform implementation * Fix empty platform implementation * Modify mac and ios createwindow interface * Create a centered window by default * Mobile platforms do not require window creation
This commit is contained in:
+7
-13
@@ -382,7 +382,7 @@ elseif(IOS)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WINDOWS OR LINUX)
|
||||
if(NOT USE_SERVER_MODE AND (WINDOWS OR LINUX))
|
||||
cocos_source_files(
|
||||
cocos/platform/SDLHelper.h
|
||||
cocos/platform/SDLHelper.cpp
|
||||
@@ -461,19 +461,13 @@ cocos_source_files(
|
||||
cocos_source_files(
|
||||
cocos/platform/interfaces/modules/Device.cpp
|
||||
cocos/platform/interfaces/modules/Device.h
|
||||
cocos/platform/interfaces/modules/IAccelerometer.cpp
|
||||
cocos/platform/interfaces/modules/IAccelerometer.h
|
||||
cocos/platform/interfaces/modules/IBattery.cpp
|
||||
cocos/platform/interfaces/modules/IBattery.h
|
||||
cocos/platform/interfaces/modules/IScreen.cpp
|
||||
cocos/platform/interfaces/modules/IScreen.h
|
||||
cocos/platform/interfaces/modules/INetwork.cpp
|
||||
cocos/platform/interfaces/modules/INetwork.h
|
||||
cocos/platform/interfaces/modules/ISystem.cpp
|
||||
cocos/platform/interfaces/modules/ISystem.h
|
||||
cocos/platform/interfaces/modules/ISystemWindow.cpp
|
||||
cocos/platform/interfaces/modules/ISystemWindow.h
|
||||
cocos/platform/interfaces/modules/IVibrator.cpp
|
||||
cocos/platform/interfaces/modules/IVibrator.h
|
||||
)
|
||||
|
||||
@@ -527,8 +521,8 @@ if(USE_SERVER_MODE)
|
||||
cocos/platform/empty/modules/Screen.h
|
||||
cocos/platform/empty/modules/Network.cpp
|
||||
cocos/platform/empty/modules/Network.h
|
||||
cocos/platform/empty/modules/Vibrate.cpp
|
||||
cocos/platform/empty/modules/Vibrate.h
|
||||
cocos/platform/empty/modules/Vibrator.cpp
|
||||
cocos/platform/empty/modules/Vibrator.h
|
||||
cocos/platform/empty/modules/System.cpp
|
||||
cocos/platform/empty/modules/System.h
|
||||
cocos/platform/empty/modules/SystemWindow.cpp
|
||||
@@ -629,8 +623,8 @@ elseif(LINUX)
|
||||
cocos/platform/linux/modules/Screen.h
|
||||
cocos/platform/linux/modules/Network.cpp
|
||||
cocos/platform/linux/modules/Network.h
|
||||
cocos/platform/linux/modules/Vibrate.cpp
|
||||
cocos/platform/linux/modules/Vibrate.h
|
||||
cocos/platform/linux/modules/Vibrator.cpp
|
||||
cocos/platform/linux/modules/Vibrator.h
|
||||
cocos/platform/linux/modules/System.cpp
|
||||
cocos/platform/linux/modules/System.h
|
||||
cocos/platform/linux/modules/SystemWindow.cpp
|
||||
@@ -646,8 +640,8 @@ elseif(QNX)
|
||||
cocos/platform/qnx/modules/Screen.h
|
||||
cocos/platform/qnx/modules/Network.cpp
|
||||
cocos/platform/qnx/modules/Network.h
|
||||
cocos/platform/qnx/modules/Vibrate.cpp
|
||||
cocos/platform/qnx/modules/Vibrate.h
|
||||
cocos/platform/qnx/modules/Vibrator.cpp
|
||||
cocos/platform/qnx/modules/Vibrator.h
|
||||
cocos/platform/qnx/modules/System.cpp
|
||||
cocos/platform/qnx/modules/System.h
|
||||
cocos/platform/qnx/modules/SystemWindow.cpp
|
||||
|
||||
@@ -36,7 +36,6 @@ public:
|
||||
std::string address{"0.0.0.0"};
|
||||
bool pauseOnStart{false};
|
||||
};
|
||||
|
||||
struct WindowInfo {
|
||||
std::string title;
|
||||
int32_t x{-1};
|
||||
@@ -45,20 +44,26 @@ public:
|
||||
int32_t height{-1};
|
||||
int32_t flags{-1};
|
||||
};
|
||||
|
||||
BaseGame() = default;
|
||||
int init() override {
|
||||
#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MAC_OSX
|
||||
// override default value
|
||||
_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x;
|
||||
_windowInfo.y = _windowInfo.y == -1 ? 0 : _windowInfo.y;
|
||||
//_windowInfo.x = _windowInfo.x == -1 ? 0 : _windowInfo.x;
|
||||
//_windowInfo.y = _windowInfo.y == -1 ? 0 : _windowInfo.y;
|
||||
_windowInfo.width = _windowInfo.width == -1 ? 800 : _windowInfo.width;
|
||||
_windowInfo.height = _windowInfo.height == -1 ? 600 : _windowInfo.height;
|
||||
_windowInfo.flags = _windowInfo.flags == -1 ? cc::ISystemWindow::CC_WINDOW_SHOWN |
|
||||
cc::ISystemWindow::CC_WINDOW_RESIZABLE |
|
||||
cc::ISystemWindow::CC_WINDOW_INPUT_FOCUS
|
||||
: _windowInfo.flags;
|
||||
|
||||
createWindow(_windowInfo.title.c_str(),
|
||||
_windowInfo.x, _windowInfo.y, _windowInfo.width, _windowInfo.height, _windowInfo.flags);
|
||||
: _windowInfo.flags;
|
||||
if (_windowInfo.x == -1 || _windowInfo.y == -1) {
|
||||
createWindow(_windowInfo.title.c_str(), _windowInfo.width, _windowInfo.height, _windowInfo.flags);
|
||||
} else {
|
||||
createWindow(_windowInfo.title.c_str(),
|
||||
_windowInfo.x, _windowInfo.y, _windowInfo.width, _windowInfo.height, _windowInfo.flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (_debuggerInfo.enabled) {
|
||||
setJsDebugIpAndPort(_debuggerInfo.address, _debuggerInfo.port, _debuggerInfo.pauseOnStart);
|
||||
@@ -81,4 +86,4 @@ protected:
|
||||
DebuggerInfo _debuggerInfo;
|
||||
WindowInfo _windowInfo;
|
||||
};
|
||||
} // namespace cc
|
||||
} // namespace cc
|
||||
|
||||
@@ -133,12 +133,18 @@ void CocosApplication::handleException(const char *location, const char *message
|
||||
void CocosApplication::setXXTeaKey(const std::string &key) {
|
||||
jsb_set_xxtea_key(key);
|
||||
}
|
||||
#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MAC_OSX
|
||||
void CocosApplication::createWindow(const char* title, int32_t w,
|
||||
int32_t h, int32_t flags) {
|
||||
_systemWidow->createWindow(title, w, h, flags);
|
||||
}
|
||||
|
||||
void CocosApplication::createWindow(const char *title,
|
||||
int32_t x, int32_t y, int32_t w,
|
||||
int32_t h, int32_t flags) {
|
||||
_systemWidow->createWindow(title, x, y, w, h, flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
void CocosApplication::handleAppEvent(const OSEvent &ev) {
|
||||
const AppEvent &appEv = OSEvent::castEvent<AppEvent>(ev);
|
||||
|
||||
@@ -78,6 +78,7 @@ public:
|
||||
* @brief Processing close events.
|
||||
*/
|
||||
virtual void onClose();
|
||||
#if CC_PLATFORM == CC_PLATFORM_WINDOWS || CC_PLATFORM == CC_PLATFORM_LINUX || CC_PLATFORM == CC_PLATFORM_QNX || CC_PLATFORM == CC_PLATFORM_MAC_OSX
|
||||
/**
|
||||
* @brief Create window.
|
||||
* @param title: Window title
|
||||
@@ -90,6 +91,16 @@ public:
|
||||
virtual void createWindow(const char* title,
|
||||
int32_t x, int32_t y, int32_t w,
|
||||
int32_t h, int32_t flags);
|
||||
/**
|
||||
* @brief Create a centered window.
|
||||
* @param title: Window title
|
||||
* @param w: Window width
|
||||
* @param h: Window height
|
||||
* @param flags: Window flag
|
||||
*/
|
||||
virtual void createWindow(const char* title, int32_t w,
|
||||
int32_t h, int32_t flags);
|
||||
#endif
|
||||
/**
|
||||
* @brief Set the js debugging server Addr and port
|
||||
* @param serverAddr:Server address.
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "SDL2/SDL_main.h"
|
||||
#include "platform/BasePlatform.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "SDL2/SDL_main.h"
|
||||
#include "platform/BasePlatform.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
@@ -158,13 +158,13 @@ SDLHelper::~SDLHelper() {
|
||||
}
|
||||
}
|
||||
|
||||
bool SDLHelper::init() {
|
||||
int SDLHelper::init() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
// Display error message
|
||||
CC_LOG_ERROR("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
return true;
|
||||
return 0;
|
||||
}
|
||||
void SDLHelper::dispatchWindowEvent(const SDL_WindowEvent &wevent) {
|
||||
WindowEvent ev;
|
||||
@@ -332,12 +332,17 @@ void SDLHelper::pollEvent(bool *quit) {
|
||||
}
|
||||
}
|
||||
|
||||
bool SDLHelper::createWindow(const char *title,
|
||||
int w, int h, int flags) {
|
||||
return createWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags);
|
||||
}
|
||||
|
||||
bool SDLHelper::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
// Create window
|
||||
int sdlFlags = windowFlagsToSDLWindowFlag(flags);
|
||||
_handle = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, sdlFlags);
|
||||
_handle = SDL_CreateWindow(title, x, y, w, h, sdlFlags);
|
||||
if (_handle == nullptr) {
|
||||
// Display error message
|
||||
CC_LOG_ERROR("Window could not be created! SDL_Error: %s\n", SDL_GetError());
|
||||
@@ -347,6 +352,10 @@ bool SDLHelper::createWindow(const char *title,
|
||||
return true;
|
||||
}
|
||||
|
||||
void SDLHelper::setCursorEnabled(bool value) {
|
||||
SDL_SetRelativeMouseMode(value ? SDL_FALSE : SDL_TRUE);
|
||||
}
|
||||
|
||||
void SDLHelper::swapWindow() {
|
||||
SDL_GL_SwapWindow(_handle);
|
||||
}
|
||||
|
||||
@@ -39,20 +39,20 @@ public:
|
||||
SDLHelper(IEventDispatch* delegate);
|
||||
~SDLHelper();
|
||||
|
||||
bool init();
|
||||
int init();
|
||||
void swapWindow();
|
||||
void createWindow();
|
||||
int getEvent(OSEvent* ev);
|
||||
bool createWindow(const char* title,
|
||||
int w, int h, int flags);
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags);
|
||||
|
||||
void pollEvent(bool* quit);
|
||||
|
||||
uintptr_t getWindowHandler() const;
|
||||
#if (CC_PLATFORM == CC_PLATFORM_LINUX)
|
||||
uintptr_t getDisplay() const;
|
||||
#endif
|
||||
void setCursorEnabled(bool value);
|
||||
|
||||
private:
|
||||
void dispatchSDLEvent(const SDL_Event& sdlEvent, bool* quit);
|
||||
|
||||
@@ -27,14 +27,6 @@
|
||||
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
|
||||
#include "platform/interfaces/modules/IAccelerometer.h"
|
||||
#include "platform/interfaces/modules/IBattery.h"
|
||||
#include "platform/interfaces/modules/INetwork.h"
|
||||
#include "platform/interfaces/modules/IScreen.h"
|
||||
#include "platform/interfaces/modules/ISystem.h"
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
#include "platform/interfaces/modules/IVibrator.h"
|
||||
|
||||
extern int cocos_main(int argc, const char** argv); // NOLINT(readability-identifier-naming)
|
||||
extern void cocos_destory(); // NOLINT(readability-identifier-naming)
|
||||
|
||||
@@ -74,17 +66,6 @@ void UniversalPlatform::setHandleDefaultEventCallback(HandleEventCallback cb) {
|
||||
_handleDefaultEventCallback = cb;
|
||||
}
|
||||
|
||||
int32_t UniversalPlatform::init() {
|
||||
registerInterface(ISystemWindow::createSystemWindowInterface());
|
||||
registerInterface(ISystem::createSystemInterface());
|
||||
registerInterface(INetwork::createNetworkInterface());
|
||||
registerInterface(IScreen::createScreenInterface());
|
||||
registerInterface(IBattery::createBatteryInterface());
|
||||
registerInterface(IVibrator::createVibratorInterface());
|
||||
registerInterface(IAccelerometer::createAccelerometerInterface());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t UniversalPlatform::run(int argc, const char** argv) {
|
||||
if (cocos_main(argc, argv) != 0) {
|
||||
return -1;
|
||||
|
||||
@@ -31,10 +31,6 @@
|
||||
namespace cc {
|
||||
class CC_DLL UniversalPlatform : public BasePlatform, public IEventDispatch {
|
||||
public:
|
||||
/**
|
||||
* @brief Implement basic platform initialization.
|
||||
*/
|
||||
int32_t init() override;
|
||||
/**
|
||||
* @brief Start base platform initialization.
|
||||
*/
|
||||
|
||||
@@ -27,12 +27,30 @@
|
||||
|
||||
#include "platform/android/AndroidPlatform.h"
|
||||
#include "platform/java/jni/glue/JniNativeGlue.h"
|
||||
#include "platform/java/modules/Accelerometer.h"
|
||||
#include "platform/java/modules/Battery.h"
|
||||
#include "platform/java/modules/Network.h"
|
||||
#include "platform/java/modules/SystemWindow.h"
|
||||
#include "platform/java/modules/Vibrator.h"
|
||||
#include "modules/Screen.h"
|
||||
#include "modules/System.h"
|
||||
|
||||
namespace cc {
|
||||
AndroidPlatform::AndroidPlatform() {
|
||||
_jniNativeGlue = JNI_NATIVE_GLUE();
|
||||
}
|
||||
|
||||
int AndroidPlatform::init() {
|
||||
registerInterface(std::make_shared<Accelerometer>());
|
||||
registerInterface(std::make_shared<Battery>());
|
||||
registerInterface(std::make_shared<Network>());
|
||||
registerInterface(std::make_shared<Screen>());
|
||||
registerInterface(std::make_shared<System>());
|
||||
registerInterface(std::make_shared<SystemWindow>());
|
||||
registerInterface(std::make_shared<Vibrator>());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AndroidPlatform::getSdkVersion() const {
|
||||
return _jniNativeGlue->getSdkVersion();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class JniNativeGlue;
|
||||
class CC_DLL AndroidPlatform : public UniversalPlatform {
|
||||
public:
|
||||
AndroidPlatform();
|
||||
int init() override;
|
||||
void pollEvent() override;
|
||||
int32_t run(int argc, const char** argv) override;
|
||||
int getSdkVersion() const override;
|
||||
|
||||
@@ -24,12 +24,17 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "platform/empty/EmptyPlatform.h"
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
#include "modules/Accelerometer.h"
|
||||
#include "modules/Battery.h"
|
||||
#include "modules/Network.h"
|
||||
#include "modules/Screen.h"
|
||||
#include "modules/System.h"
|
||||
#include "modules/SystemWindow.h"
|
||||
#include "modules/Vibrator.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
namespace cc {
|
||||
EmptyPlatform::EmptyPlatform() = default;
|
||||
@@ -37,30 +42,21 @@ EmptyPlatform::~EmptyPlatform() {
|
||||
}
|
||||
|
||||
int32_t EmptyPlatform::init() {
|
||||
UniversalPlatform::init();
|
||||
|
||||
//init
|
||||
registerInterface(std::make_shared<Accelerometer>());
|
||||
registerInterface(std::make_shared<Battery>());
|
||||
registerInterface(std::make_shared<Network>());
|
||||
registerInterface(std::make_shared<Screen>());
|
||||
registerInterface(std::make_shared<System>());
|
||||
registerInterface(std::make_shared<SystemWindow>());
|
||||
registerInterface(std::make_shared<Vibrator>());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t EmptyPlatform::loop() {
|
||||
while (!_quit) {
|
||||
usleep(1000);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EmptyPlatform::pollEvent() {
|
||||
}
|
||||
|
||||
bool EmptyPlatform::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uintptr_t EmptyPlatform::getWindowHandler() const {
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -30,8 +30,7 @@
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL EmptyPlatform : public UniversalPlatform,
|
||||
public SystemWindow::Delegate {
|
||||
class CC_DLL EmptyPlatform : public UniversalPlatform {
|
||||
public:
|
||||
EmptyPlatform();
|
||||
/**
|
||||
@@ -45,15 +44,6 @@ public:
|
||||
|
||||
int32_t loop() override;
|
||||
|
||||
// override from SystemWindow::Delegate
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
uintptr_t getWindowHandler() const override;
|
||||
|
||||
private:
|
||||
void pollEvent() override;
|
||||
|
||||
private:
|
||||
bool _quit{false};
|
||||
};
|
||||
|
||||
@@ -81,6 +81,7 @@ void CanvasRenderingContext2DDelegate::strokeText(const std::string &text, float
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DDelegate::Size CanvasRenderingContext2DDelegate::measureText(const std::string &text) {
|
||||
return Size{0, 0};
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::updateFont(const std::string &fontName,
|
||||
@@ -144,4 +145,4 @@ void CanvasRenderingContext2DDelegate::rect(float /* x */,
|
||||
float /* h */) {
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
} // namespace cc
|
||||
|
||||
@@ -45,24 +45,8 @@ SystemWindow::SystemWindow() {
|
||||
SystemWindow::~SystemWindow() {
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
// Create window
|
||||
|
||||
EmptyPlatform *platform = dynamic_cast<EmptyPlatform *>(BasePlatform::getPlatform());
|
||||
CCASSERT(platform != nullptr, "Platform pointer can't be null");
|
||||
platform->createWindow(title, x, y, w, h, flags);
|
||||
_width = w;
|
||||
_height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
uintptr_t SystemWindow::getWindowHandler() const {
|
||||
//return _handle;
|
||||
EmptyPlatform *platform = dynamic_cast<EmptyPlatform *>(BasePlatform::getPlatform());
|
||||
CCASSERT(platform != nullptr, "Platform pointer can't be null");
|
||||
return platform->getWindowHandler();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
|
||||
@@ -29,9 +29,6 @@
|
||||
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
|
||||
struct SDL_Window;
|
||||
struct SDL_WindowEvent;
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL SystemWindow : public ISystemWindow {
|
||||
@@ -39,18 +36,6 @@ public:
|
||||
explicit SystemWindow();
|
||||
~SystemWindow() override;
|
||||
|
||||
class Delegate {
|
||||
public:
|
||||
virtual ~Delegate() = default;
|
||||
virtual bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) = 0;
|
||||
virtual uintptr_t getWindowHandler() const = 0;
|
||||
};
|
||||
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
uintptr_t getWindowHandler() const override;
|
||||
|
||||
Size getViewSize() const override;
|
||||
@@ -65,4 +50,4 @@ private:
|
||||
int _height{0};
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
} // namespace cc
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "platform/empty/modules/Vibrate.h"
|
||||
#include "platform/empty/modules/Vibrator.h"
|
||||
|
||||
#include "base/Macros.h"
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
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 "platform/interfaces/modules/IAccelerometer.h"
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
#include "platform/win32/modules/Accelerometer.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS)
|
||||
#include "platform/java/modules/Accelerometer.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
|
||||
#include "platform/mac/modules/Accelerometer.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
|
||||
#include "platform/ios/modules/Accelerometer.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_LINUX)
|
||||
#include "platform/linux/modules/Accelerometer.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_QNX)
|
||||
#include "platform/qnx/modules/Accelerometer.h"
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
|
||||
// static
|
||||
OSInterface::Ptr IAccelerometer::createAccelerometerInterface() {
|
||||
return std::make_shared<Accelerometer>();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
@@ -59,13 +59,7 @@ public:
|
||||
* Gets the motion value of current device.
|
||||
*/
|
||||
virtual const MotionValue &getDeviceMotionValue() = 0;
|
||||
/**
|
||||
@brief Create default accelerometer interface.
|
||||
@return accelerometer interface.
|
||||
*/
|
||||
static OSInterface::Ptr createAccelerometerInterface();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
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 "platform/interfaces/modules/IBattery.h"
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
#include "platform/win32/modules/Battery.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS)
|
||||
#include "platform/java/modules/Battery.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
|
||||
#include "platform/mac/modules/Battery.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
|
||||
#include "platform/ios/modules/Battery.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_LINUX)
|
||||
#include "platform/linux/modules/Battery.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_QNX)
|
||||
#include "platform/qnx/modules/Battery.h"
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
|
||||
// static
|
||||
OSInterface::Ptr IBattery::createBatteryInterface() {
|
||||
return std::make_shared<Battery>();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
@@ -36,13 +36,7 @@ public:
|
||||
* @return 0.0 ~ 1.0
|
||||
*/
|
||||
virtual float getBatteryLevel() const = 0;
|
||||
/**
|
||||
@brief Create default battery interface.
|
||||
@return battery interface.
|
||||
*/
|
||||
static OSInterface::Ptr createBatteryInterface();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
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 "platform/interfaces/modules/INetwork.h"
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
#include "platform/win32/modules/Network.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS)
|
||||
#include "platform/java/modules/Network.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
|
||||
#include "platform/mac/modules/Network.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
|
||||
#include "platform/ios/modules/Network.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_LINUX)
|
||||
#include "platform/linux/modules/Network.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_QNX)
|
||||
#include "platform/qnx/modules/Network.h"
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
|
||||
// static
|
||||
OSInterface::Ptr INetwork::createNetworkInterface() {
|
||||
return std::make_shared<Network>();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
@@ -37,13 +37,6 @@ public:
|
||||
WWAN
|
||||
};
|
||||
virtual NetworkType getNetworkType() const = 0;
|
||||
/**
|
||||
@brief Create default network interface.
|
||||
@return network interface.
|
||||
*/
|
||||
static OSInterface::Ptr createNetworkInterface();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
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 "platform/interfaces/modules/IScreen.h"
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
#include "platform/win32/modules/Screen.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#include "platform/android/modules/Screen.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_OHOS)
|
||||
#include "platform/ohos/modules/Screen.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
|
||||
#include "platform/mac/modules/Screen.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
|
||||
#include "platform/ios/modules/Screen.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_LINUX)
|
||||
#include "platform/linux/modules/Screen.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_QNX)
|
||||
#include "platform/qnx/modules/Screen.h"
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
|
||||
// static
|
||||
OSInterface::Ptr IScreen::createScreenInterface() {
|
||||
return std::make_shared<Screen>();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
@@ -62,12 +62,6 @@ public:
|
||||
virtual void setKeepScreenOn(bool keepScreenOn) = 0;
|
||||
|
||||
virtual Vec4 getSafeAreaEdge() const = 0;
|
||||
/**
|
||||
@brief Create default screen interface.
|
||||
@return screen interface.
|
||||
*/
|
||||
static OSInterface::Ptr createScreenInterface();
|
||||
|
||||
private:
|
||||
};
|
||||
} // namespace cc
|
||||
|
||||
@@ -25,29 +25,9 @@
|
||||
|
||||
#include "platform/interfaces/modules/ISystem.h"
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
#include "platform/win32/modules/System.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
#include "platform/android/modules/System.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_OHOS)
|
||||
#include "platform/ohos/modules/System.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
|
||||
#include "platform/mac/modules/System.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
|
||||
#include "platform/ios/modules/System.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_LINUX)
|
||||
#include "platform/linux/modules/System.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_QNX)
|
||||
#include "platform/qnx/modules/System.h"
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
ISystem::~ISystem() = default;
|
||||
|
||||
ISystem::Ptr ISystem::createSystemInterface() {
|
||||
return std::make_shared<System>();
|
||||
}
|
||||
|
||||
std::string ISystem::getCurrentLanguageToString() {
|
||||
LanguageType language = getCurrentLanguage();
|
||||
std::string languageStr = ""; // NOLINT
|
||||
@@ -116,4 +96,4 @@ std::string ISystem::getCurrentLanguageToString() {
|
||||
return languageStr;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
} // namespace cc
|
||||
|
||||
@@ -84,13 +84,7 @@ public:
|
||||
@return True if the resource located by the URL was successfully opened; otherwise false.
|
||||
*/
|
||||
virtual bool openURL(const std::string& url) = 0;
|
||||
/**
|
||||
@brief Create default sytem interface.
|
||||
@return sytem interface.
|
||||
*/
|
||||
static OSInterface::Ptr createSystemInterface();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
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 "platform/interfaces/modules/ISystemWindow.h"
|
||||
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
#include "platform/win32/modules/SystemWindow.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS)
|
||||
#include "platform/java/modules/SystemWindow.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
|
||||
#include "platform/mac/modules/SystemWindow.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
|
||||
#include "platform/ios/modules/SystemWindow.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_LINUX)
|
||||
#include "platform/linux/modules/SystemWindow.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_QNX)
|
||||
#include "platform/qnx/modules/SystemWindow.h"
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
|
||||
// static
|
||||
OSInterface::Ptr ISystemWindow::createSystemWindowInterface() {
|
||||
return std::make_shared<SystemWindow>();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
@@ -71,9 +71,22 @@ public:
|
||||
*@param h: Window height
|
||||
*@param flags: Window flag
|
||||
*/
|
||||
virtual bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* @brief Create a centered window.
|
||||
*@param title: Window title
|
||||
*@param w: Window width
|
||||
*@param h: Window height
|
||||
*@param flags: Window flag
|
||||
*/
|
||||
virtual bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) = 0;
|
||||
int w, int h, int flags) {
|
||||
return true;
|
||||
}
|
||||
virtual uintptr_t getWindowHandler() const = 0;
|
||||
virtual Size getViewSize() const = 0;
|
||||
/**
|
||||
@@ -82,13 +95,6 @@ public:
|
||||
virtual void setCursorEnabled(bool value) = 0;
|
||||
|
||||
virtual void copyTextToClipboard(const std::string& text) = 0;
|
||||
/**
|
||||
@brief Create default sytem window interface.
|
||||
@return sytem window interface.
|
||||
*/
|
||||
static OSInterface::Ptr createSystemWindowInterface();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
|
||||
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 "platform/interfaces/modules/IVibrator.h"
|
||||
|
||||
#if (CC_PLATFORM == CC_PLATFORM_WINDOWS)
|
||||
#include "platform/win32/modules/Vibrator.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_ANDROID || CC_PLATFORM == CC_PLATFORM_OHOS)
|
||||
#include "platform/java/modules/Vibrator.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_OSX)
|
||||
#include "platform/mac/modules/Vibrator.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_MAC_IOS)
|
||||
#include "platform/ios/modules/Vibrator.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_LINUX)
|
||||
#include "platform/linux/modules/Vibrate.h"
|
||||
#elif (CC_PLATFORM == CC_PLATFORM_QNX)
|
||||
#include "platform/qnx/modules/Vibrate.h"
|
||||
#endif
|
||||
|
||||
namespace cc {
|
||||
|
||||
// static
|
||||
OSInterface::Ptr IVibrator::createVibratorInterface() {
|
||||
return std::make_shared<Vibrator>();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
@@ -40,12 +40,6 @@ public:
|
||||
* @param duration The duration in seconds.
|
||||
*/
|
||||
virtual void vibrate(float duration) = 0;
|
||||
|
||||
/**
|
||||
* @brief Create default Vibrator interface.
|
||||
* @return Vibrator interface.
|
||||
*/
|
||||
static OSInterface::Ptr createVibratorInterface();
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -28,7 +28,15 @@
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import "platform/ios/AppDelegate.h"
|
||||
#include "modules/Accelerometer.h"
|
||||
#include "modules/Battery.h"
|
||||
#include "modules/Network.h"
|
||||
#include "modules/Screen.h"
|
||||
#include "modules/System.h"
|
||||
#include "modules/SystemWindow.h"
|
||||
#include "modules/Vibrator.h"
|
||||
|
||||
extern int cocos_main(int argc, const char** argv);
|
||||
|
||||
@@ -92,7 +100,14 @@ IOSPlatform::~IOSPlatform() = default;
|
||||
|
||||
int32_t IOSPlatform::init() {
|
||||
_timer = [[MyTimer alloc] initWithApp:this fps:60];
|
||||
return UniversalPlatform::init();
|
||||
registerInterface(std::make_shared<Accelerometer>());
|
||||
registerInterface(std::make_shared<Battery>());
|
||||
registerInterface(std::make_shared<Network>());
|
||||
registerInterface(std::make_shared<Screen>());
|
||||
registerInterface(std::make_shared<System>());
|
||||
registerInterface(std::make_shared<SystemWindow>());
|
||||
registerInterface(std::make_shared<Vibrator>());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t IOSPlatform::loop() {
|
||||
|
||||
@@ -36,9 +36,6 @@ public:
|
||||
SystemWindow() = default;
|
||||
~SystemWindow() override;
|
||||
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
uintptr_t getWindowHandler() const override;
|
||||
|
||||
Size getViewSize() const override;
|
||||
|
||||
@@ -35,12 +35,6 @@ namespace cc {
|
||||
|
||||
SystemWindow::~SystemWindow() = default;
|
||||
|
||||
bool SystemWindow::createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
_width = w;
|
||||
_height = h;
|
||||
}
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
}
|
||||
|
||||
@@ -41,18 +41,6 @@ namespace {
|
||||
|
||||
namespace cc {
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
CC_UNUSED_PARAM(title);
|
||||
CC_UNUSED_PARAM(x);
|
||||
CC_UNUSED_PARAM(y);
|
||||
CC_UNUSED_PARAM(w);
|
||||
CC_UNUSED_PARAM(h);
|
||||
CC_UNUSED_PARAM(flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
}
|
||||
|
||||
@@ -70,4 +58,4 @@ SystemWindow::Size SystemWindow::getViewSize() const {
|
||||
static_cast<float>(JNI_NATIVE_GLUE()->getHeight())};
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
} // namespace cc
|
||||
|
||||
@@ -33,9 +33,6 @@ namespace cc {
|
||||
|
||||
class SystemWindow : public ISystemWindow {
|
||||
public:
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
/**
|
||||
@brief enable/disable(lock) the cursor, default is enabled
|
||||
*/
|
||||
@@ -45,4 +42,4 @@ public:
|
||||
Size getViewSize() const override;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
} // namespace cc
|
||||
|
||||
@@ -28,24 +28,37 @@
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
#include "platform/SDLHelper.h"
|
||||
|
||||
#include "modules/Accelerometer.h"
|
||||
#include "modules/Battery.h"
|
||||
#include "modules/Network.h"
|
||||
#include "modules/Screen.h"
|
||||
#include "modules/System.h"
|
||||
#include "modules/SystemWindow.h"
|
||||
#include "modules/Vibrator.h"
|
||||
|
||||
namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace cc {
|
||||
LinuxPlatform::LinuxPlatform() {
|
||||
_sdl = std::make_unique<SDLHelper>(this);
|
||||
}
|
||||
|
||||
LinuxPlatform::~LinuxPlatform() {
|
||||
}
|
||||
|
||||
int32_t LinuxPlatform::init() {
|
||||
UniversalPlatform::init();
|
||||
return _sdl->init() ? 0 : -1;
|
||||
registerInterface(std::make_shared<Accelerometer>());
|
||||
registerInterface(std::make_shared<Battery>());
|
||||
registerInterface(std::make_shared<Network>());
|
||||
registerInterface(std::make_shared<Screen>());
|
||||
registerInterface(std::make_shared<System>());
|
||||
_window = std::make_shared<SystemWindow>(this);
|
||||
registerInterface(_window);
|
||||
registerInterface(std::make_shared<Vibrator>());
|
||||
return _window->init();
|
||||
}
|
||||
|
||||
static long getCurrentMillSecond() {
|
||||
@@ -66,12 +79,12 @@ int32_t LinuxPlatform::loop() {
|
||||
while (!_quit) {
|
||||
curTime = getCurrentMillSecond();
|
||||
desiredInterval = static_cast<long>(1000.0 / getFps());
|
||||
pollEvent();
|
||||
_window->pollEvent(&_quit);
|
||||
actualInterval = curTime - lastTime;
|
||||
if (actualInterval >= desiredInterval) {
|
||||
lastTime = getCurrentMillSecond();
|
||||
runTask();
|
||||
_sdl->swapWindow();
|
||||
_window->swapWindow();
|
||||
} else {
|
||||
usleep((desiredInterval - curTime + lastTime) * 1000);
|
||||
}
|
||||
@@ -81,22 +94,4 @@ int32_t LinuxPlatform::loop() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LinuxPlatform::pollEvent() {
|
||||
_sdl->pollEvent(&_quit);
|
||||
}
|
||||
|
||||
bool LinuxPlatform::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
return _sdl->createWindow(title, x, y, w, h, flags);
|
||||
}
|
||||
|
||||
uintptr_t LinuxPlatform::getWindowHandler() const {
|
||||
return _sdl->getWindowHandler();
|
||||
}
|
||||
|
||||
uintptr_t LinuxPlatform::getDisplay() const {
|
||||
return _sdl->getDisplay();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -26,12 +26,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "platform/UniversalPlatform.h"
|
||||
#include "platform/linux/modules/SystemWindow.h"
|
||||
|
||||
namespace cc {
|
||||
class SDLHelper;
|
||||
class CC_DLL LinuxPlatform : public UniversalPlatform,
|
||||
public SystemWindow::Delegate {
|
||||
class SystemWindow;
|
||||
class CC_DLL LinuxPlatform : public UniversalPlatform {
|
||||
public:
|
||||
LinuxPlatform();
|
||||
/**
|
||||
@@ -45,18 +43,9 @@ public:
|
||||
|
||||
int32_t loop() override;
|
||||
|
||||
// override from SystemWindow::Delegate
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
uintptr_t getWindowHandler() const override;
|
||||
uintptr_t getDisplay() const;
|
||||
|
||||
private:
|
||||
void pollEvent() override;
|
||||
bool _inited{false};
|
||||
bool _quit{false};
|
||||
std::unique_ptr<SDLHelper> _sdl;
|
||||
bool _quit{false};
|
||||
std::shared_ptr<SystemWindow> _window{nullptr};
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include "platform/linux/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#include "platform/linux/LinuxPlatform.h"
|
||||
#include "platform/linux/modules/SystemWindow.h"
|
||||
|
||||
namespace {
|
||||
#define RGB(r, g, b) (int)((int)r | (((int)g) << 8) | (((int)b) << 16))
|
||||
@@ -37,10 +38,10 @@ namespace cc {
|
||||
static const char gdefaultFontName[] = "lucidasans-24";
|
||||
|
||||
CanvasRenderingContext2DDelegate::CanvasRenderingContext2DDelegate() {
|
||||
LinuxPlatform *platform = dynamic_cast<LinuxPlatform *>(BasePlatform::getPlatform());
|
||||
CCASSERT(platform != nullptr, "Platform pointer can't be null");
|
||||
_dis = reinterpret_cast<Display*>(platform->getDisplay());
|
||||
_win = reinterpret_cast<Drawable>(platform->getWindowHandler());
|
||||
SystemWindow* window = BasePlatform::getPlatform()->getInterface<SystemWindow>();
|
||||
CCASSERT(window != nullptr, "System window is not registered");
|
||||
_dis = reinterpret_cast<Display*>(window->getDisplay());
|
||||
_win = reinterpret_cast<Drawable>(window->getWindowHandler());
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DDelegate::~CanvasRenderingContext2DDelegate() {
|
||||
|
||||
@@ -35,41 +35,57 @@
|
||||
#include "SDL2/SDL_syswm.h"
|
||||
#include "bindings/event/EventDispatcher.h"
|
||||
#include "platform/IEventDispatch.h"
|
||||
#include "platform/linux/LinuxPlatform.h"
|
||||
|
||||
namespace {
|
||||
|
||||
} // namespace
|
||||
#include "platform/SDLHelper.h"
|
||||
|
||||
namespace cc {
|
||||
SystemWindow::SystemWindow() {
|
||||
SystemWindow::SystemWindow(IEventDispatch *delegate)
|
||||
: _sdl(std::make_unique<SDLHelper>(delegate)) {
|
||||
|
||||
}
|
||||
|
||||
SystemWindow::~SystemWindow() {
|
||||
}
|
||||
|
||||
int SystemWindow::init() {
|
||||
return _sdl->init();
|
||||
}
|
||||
|
||||
void SystemWindow::pollEvent(bool *quit) {
|
||||
return _sdl->pollEvent(quit);
|
||||
}
|
||||
|
||||
void SystemWindow::swapWindow() {
|
||||
_sdl->swapWindow();
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int w, int h, int flags) {
|
||||
_sdl->createWindow(title, w, h, flags);
|
||||
_width = w;
|
||||
_height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
// Create window
|
||||
|
||||
LinuxPlatform *platform = dynamic_cast<LinuxPlatform *>(BasePlatform::getPlatform());
|
||||
CCASSERT(platform != nullptr, "Platform pointer can't be null");
|
||||
platform->createWindow(title, x, y, w, h, flags);
|
||||
_sdl->createWindow(title, x, y, w, h, flags);
|
||||
_width = w;
|
||||
_height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
uintptr_t SystemWindow::getWindowHandler() const {
|
||||
//return _handle;
|
||||
LinuxPlatform *platform = dynamic_cast<LinuxPlatform *>(BasePlatform::getPlatform());
|
||||
CCASSERT(platform != nullptr, "Platform pointer can't be null");
|
||||
return platform->getWindowHandler();
|
||||
return _sdl->getWindowHandler();
|
||||
}
|
||||
|
||||
uintptr_t SystemWindow::getDisplay() const {
|
||||
return _sdl->getDisplay();
|
||||
}
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
SDL_SetRelativeMouseMode(value ? SDL_FALSE : SDL_TRUE);
|
||||
_sdl->setCursorEnabled(value);
|
||||
}
|
||||
|
||||
void SystemWindow::copyTextToClipboard(const std::string &text) {
|
||||
|
||||
@@ -29,30 +29,24 @@
|
||||
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
|
||||
struct SDL_Window;
|
||||
struct SDL_WindowEvent;
|
||||
|
||||
namespace cc {
|
||||
|
||||
class SDLHelper;
|
||||
class CC_DLL SystemWindow : public ISystemWindow {
|
||||
public:
|
||||
explicit SystemWindow();
|
||||
explicit SystemWindow(IEventDispatch* delegate);
|
||||
~SystemWindow() override;
|
||||
|
||||
class Delegate {
|
||||
public:
|
||||
virtual ~Delegate() = default;
|
||||
virtual bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) = 0;
|
||||
virtual uintptr_t getWindowHandler() const = 0;
|
||||
};
|
||||
int init();
|
||||
void swapWindow();
|
||||
void pollEvent(bool* quit);
|
||||
|
||||
bool createWindow(const char* title,
|
||||
int w, int h, int flags) override;
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
uintptr_t getWindowHandler() const override;
|
||||
|
||||
uintptr_t getDisplay() const;
|
||||
Size getViewSize() const override;
|
||||
/*
|
||||
@brief enable/disable(lock) the cursor, default is enabled
|
||||
@@ -63,6 +57,7 @@ public:
|
||||
private:
|
||||
int _width{0};
|
||||
int _height{0};
|
||||
std::unique_ptr<SDLHelper> _sdl;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "platform/linux/modules/Vibrate.h"
|
||||
#include "platform/linux/modules/Vibrator.h"
|
||||
|
||||
#include "base/Macros.h"
|
||||
|
||||
@@ -40,6 +40,17 @@
|
||||
|
||||
@implementation AppDelegate
|
||||
|
||||
- (void)createWindowPosCentered:(NSString*)title width:(int)w height:(int)h {
|
||||
CGRect screenFrame = CGDisplayBounds(kCGDirectMainDisplay);
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if(w < screenFrame.size.width)
|
||||
x = screenFrame.origin.x + (screenFrame.size.width - w)/2;
|
||||
if(h < screenFrame.size.height)
|
||||
y = screenFrame.origin.y + (screenFrame.size.height - h)/2;
|
||||
[self createWindow :title xPos:x yPos:y width:w height:h];
|
||||
}
|
||||
|
||||
- (void)createWindow:(NSString*)title xPos:(int)x yPos:(int)y width:(int)w height:(int)h {
|
||||
_window.title = title;
|
||||
NSRect rect = NSMakeRect(x, y, w, h);
|
||||
|
||||
@@ -25,10 +25,18 @@
|
||||
|
||||
#include "platform/mac/MacPlatform.h"
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
#include "platform/mac/AppDelegate.h"
|
||||
|
||||
#include "modules/Accelerometer.h"
|
||||
#include "modules/Battery.h"
|
||||
#include "modules/Network.h"
|
||||
#include "modules/Screen.h"
|
||||
#include "modules/System.h"
|
||||
#include "modules/SystemWindow.h"
|
||||
#include "modules/Vibrator.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
extern int cocos_main(int argc, const char** argv);
|
||||
|
||||
@interface MyTimer : NSObject {
|
||||
@@ -99,7 +107,14 @@ MacPlatform::~MacPlatform() {
|
||||
|
||||
int32_t MacPlatform::init() {
|
||||
_timer = [[MyTimer alloc] initWithApp:this fps:60];
|
||||
return UniversalPlatform::init();
|
||||
registerInterface(std::make_shared<Accelerometer>());
|
||||
registerInterface(std::make_shared<Battery>());
|
||||
registerInterface(std::make_shared<Network>());
|
||||
registerInterface(std::make_shared<Screen>());
|
||||
registerInterface(std::make_shared<System>());
|
||||
registerInterface(std::make_shared<SystemWindow>());
|
||||
registerInterface(std::make_shared<Vibrator>());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t MacPlatform::loop(void) {
|
||||
|
||||
@@ -39,6 +39,9 @@ public:
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
bool createWindow(const char* title,
|
||||
int w,int h, int flags) override;
|
||||
|
||||
uintptr_t getWindowHandler() const override;
|
||||
|
||||
Size getViewSize() const override;
|
||||
|
||||
@@ -38,6 +38,16 @@ SystemWindow::SystemWindow() = default;
|
||||
|
||||
SystemWindow::~SystemWindow() = default;
|
||||
|
||||
bool SystemWindow::createWindow(const char* title,
|
||||
int w, int h, int flags) {
|
||||
_width = w;
|
||||
_height = h;
|
||||
AppDelegate *delegate = [[NSApplication sharedApplication] delegate];
|
||||
NSString * aString = [NSString stringWithUTF8String:title];
|
||||
[delegate createWindowPosCentered:aString width:w height:h];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
@@ -50,6 +60,7 @@ bool SystemWindow::createWindow(const char *title,
|
||||
AppDelegate *delegate = [[NSApplication sharedApplication] delegate];
|
||||
NSString * aString = [NSString stringWithUTF8String:title];
|
||||
[delegate createWindow:aString xPos:x yPos:y width:w height:h];
|
||||
return true;
|
||||
}
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
|
||||
@@ -25,16 +25,32 @@
|
||||
|
||||
#include <thread>
|
||||
|
||||
#include "platform/UniversalPlatform.h"
|
||||
#include "platform/java/jni/glue/JniNativeGlue.h"
|
||||
#include "platform/java/modules/SystemWindow.h"
|
||||
#include "platform/ohos/OhosPlatform.h"
|
||||
#include "platform/java/jni/glue/JniNativeGlue.h"
|
||||
#include "platform/java/modules/Accelerometer.h"
|
||||
#include "platform/java/modules/Battery.h"
|
||||
#include "platform/java/modules/Network.h"
|
||||
#include "platform/java/modules/SystemWindow.h"
|
||||
#include "platform/java/modules/Vibrator.h"
|
||||
#include "modules/Screen.h"
|
||||
#include "modules/System.h"
|
||||
|
||||
namespace cc {
|
||||
OhosPlatform::OhosPlatform() {
|
||||
_jniNativeGlue = JNI_NATIVE_GLUE();
|
||||
}
|
||||
|
||||
int OhosPlatform::init() {
|
||||
registerInterface(std::make_shared<Accelerometer>());
|
||||
registerInterface(std::make_shared<Battery>());
|
||||
registerInterface(std::make_shared<Network>());
|
||||
registerInterface(std::make_shared<Screen>());
|
||||
registerInterface(std::make_shared<System>());
|
||||
registerInterface(std::make_shared<SystemWindow>());
|
||||
registerInterface(std::make_shared<Vibrator>());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int OhosPlatform::getSdkVersion() const {
|
||||
return _jniNativeGlue->getSdkVersion();
|
||||
}
|
||||
@@ -78,4 +94,4 @@ void OhosPlatform::pollEvent() {
|
||||
_jniNativeGlue->flushTasksOnGameThread();
|
||||
}
|
||||
|
||||
}; // namespace cc
|
||||
}; // namespace cc
|
||||
|
||||
@@ -29,9 +29,10 @@
|
||||
|
||||
namespace cc {
|
||||
class JniNativeGlue;
|
||||
class OhosPlatform : public UniversalPlatform {
|
||||
class CC_DLL OhosPlatform : public UniversalPlatform {
|
||||
public:
|
||||
OhosPlatform();
|
||||
int init() override;
|
||||
void pollEvent() override;
|
||||
int32_t run(int argc, const char** argv) override;
|
||||
int getSdkVersion() const override;
|
||||
|
||||
@@ -29,7 +29,13 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
#include "modules/Accelerometer.h"
|
||||
#include "modules/Battery.h"
|
||||
#include "modules/Network.h"
|
||||
#include "modules/Screen.h"
|
||||
#include "modules/System.h"
|
||||
#include "modules/SystemWindow.h"
|
||||
#include "modules/Vibrator.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -39,18 +45,19 @@ namespace cc {
|
||||
QnxPlatform::QnxPlatform() {
|
||||
// _sdl = std::make_unique<SDLHelper>(this);
|
||||
}
|
||||
|
||||
QnxPlatform::~QnxPlatform() {
|
||||
if (_screenWin) {
|
||||
screen_destroy_window(_screenWin);
|
||||
}
|
||||
if (_screenCtx) {
|
||||
screen_destroy_context(_screenCtx);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t QnxPlatform::init() {
|
||||
UniversalPlatform::init();
|
||||
// return _sdl->init() ? 0 : -1;
|
||||
registerInterface(std::make_shared<Accelerometer>());
|
||||
registerInterface(std::make_shared<Battery>());
|
||||
registerInterface(std::make_shared<Network>());
|
||||
registerInterface(std::make_shared<Screen>());
|
||||
registerInterface(std::make_shared<System>());
|
||||
_window = std::make_shared<SystemWindow>();
|
||||
registerInterface(_window);
|
||||
registerInterface(std::make_shared<Vibrator>());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -71,7 +78,7 @@ int32_t QnxPlatform::loop() {
|
||||
onResume();
|
||||
while (!_quit) {
|
||||
curTime = getCurrentMillSecond();
|
||||
desiredInterval = static_cast<long>(1000.0 / getFps());
|
||||
desiredInterval = static_cast<long>(1000.0 / getFps());
|
||||
pollEvent();
|
||||
actualInterval = curTime - lastTime;
|
||||
if (actualInterval >= desiredInterval) {
|
||||
@@ -92,50 +99,4 @@ void QnxPlatform::pollEvent() {
|
||||
//_sdl->pollEvent(&_quit);
|
||||
}
|
||||
|
||||
bool QnxPlatform::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
if (_inited) {
|
||||
return true;
|
||||
}
|
||||
int rc;
|
||||
|
||||
//Create the screen context
|
||||
rc = screen_create_context(&_screenCtx, SCREEN_APPLICATION_CONTEXT);
|
||||
if (rc) {
|
||||
perror("screen_create_window");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Create the screen window that will be render onto
|
||||
rc = screen_create_window(&_screenWin, _screenCtx);
|
||||
if (rc) {
|
||||
perror("screen_create_window");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_FORMAT, (const int[]){SCREEN_FORMAT_RGBX8888});
|
||||
screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_USAGE, (const int[]){SCREEN_USAGE_OPENGL_ES2});
|
||||
|
||||
int size[2] = {w, h}; /* size of the window on screen */
|
||||
rc = screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_SIZE, size);
|
||||
|
||||
int dpi = 0;
|
||||
screen_get_window_property_iv(_screenWin, SCREEN_PROPERTY_DPI, &dpi);
|
||||
fprintf(stdout, "[glError] %d\n", dpi);
|
||||
|
||||
rc = screen_create_window_buffers(_screenWin, 2);
|
||||
if (rc) {
|
||||
perror("screen_create_window_buffers");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// return _sdl->createWindow(title, x, y, w, h, flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
uintptr_t QnxPlatform::getWindowHandler() const {
|
||||
// return _sdl->getWindowHandler();
|
||||
return reinterpret_cast<uintptr_t>(_screenWin);
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -25,14 +25,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <screen/screen.h>
|
||||
#include "platform/UniversalPlatform.h"
|
||||
#include "platform/qnx/modules/SystemWindow.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL QnxPlatform : public UniversalPlatform,
|
||||
public SystemWindow::Delegate {
|
||||
class SystemWindow;
|
||||
class CC_DLL QnxPlatform : public UniversalPlatform {
|
||||
public:
|
||||
QnxPlatform();
|
||||
/**
|
||||
@@ -46,22 +43,10 @@ public:
|
||||
|
||||
int32_t loop() override;
|
||||
|
||||
// override from SystemWindow::Delegate
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
uintptr_t getWindowHandler() const override;
|
||||
struct SDL_Window* getWindow() {
|
||||
return nullptr; //_handle;
|
||||
}
|
||||
|
||||
private:
|
||||
void pollEvent() override;
|
||||
bool _inited{false};
|
||||
bool _quit{false};
|
||||
// std::unique_ptr<SDLHelper> _sdl;
|
||||
screen_context_t _screenCtx;
|
||||
screen_window_t _screenWin;
|
||||
std::shared_ptr<SystemWindow> _window;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -37,39 +37,90 @@
|
||||
#include "platform/IEventDispatch.h"
|
||||
#include "platform/qnx/QnxPlatform.h"
|
||||
|
||||
namespace {
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace cc {
|
||||
SystemWindow::SystemWindow() {
|
||||
}
|
||||
|
||||
SystemWindow::~SystemWindow() {
|
||||
if (_screenWin) {
|
||||
screen_destroy_window(_screenWin);
|
||||
}
|
||||
if (_screenCtx) {
|
||||
screen_destroy_context(_screenCtx);
|
||||
}
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int w, int h, int flags) {
|
||||
_width = w;
|
||||
_height = h;
|
||||
createWindow(title, 0, 0, w, h, flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
// Create window
|
||||
|
||||
QnxPlatform *platform = dynamic_cast<QnxPlatform *>(BasePlatform::getPlatform());
|
||||
CCASSERT(platform != nullptr, "Platform pointer can't be null");
|
||||
platform->createWindow(title, x, y, w, h, flags);
|
||||
if (_screenWin) {
|
||||
return true;
|
||||
}
|
||||
_width = w;
|
||||
_height = h;
|
||||
|
||||
//Create the screen context
|
||||
int rc = screen_create_context(&_screenCtx, SCREEN_APPLICATION_CONTEXT);
|
||||
if (rc) {
|
||||
perror("screen_create_window");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Create the screen window that will be render onto
|
||||
rc = screen_create_window(&_screenWin, _screenCtx);
|
||||
if (rc) {
|
||||
perror("screen_create_window");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_FORMAT, (const int[]){SCREEN_FORMAT_RGBX8888});
|
||||
#ifdef CC_USE_GLES3
|
||||
screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_USAGE, (const int[]){SCREEN_USAGE_OPENGL_ES3});
|
||||
#elif CC_USE_GLES2
|
||||
screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_USAGE, (const int[]){SCREEN_USAGE_OPENGL_ES2});
|
||||
#endif
|
||||
|
||||
int pos[2] = {x, y}; /* size of the window on screen */
|
||||
rc = screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_POSITION, pos);
|
||||
if (rc) {
|
||||
perror("screen_set_window_property_iv(SCREEN_PROPERTY_SIZE)");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int size[2] = {w, h}; /* size of the window on screen */
|
||||
rc = screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_SIZE, size);
|
||||
if (rc) {
|
||||
perror("screen_set_window_property_iv(SCREEN_PROPERTY_POSITION)");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int dpi = 0;
|
||||
screen_get_window_property_iv(_screenWin, SCREEN_PROPERTY_DPI, &dpi);
|
||||
fprintf(stdout, "[glError] %d\n", dpi);
|
||||
|
||||
rc = screen_create_window_buffers(_screenWin, 2);
|
||||
if (rc) {
|
||||
perror("screen_create_window_buffers");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// return _sdl->createWindow(title, x, y, w, h, flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
uintptr_t SystemWindow::getWindowHandler() const {
|
||||
//return _handle;
|
||||
QnxPlatform *platform = dynamic_cast<QnxPlatform *>(BasePlatform::getPlatform());
|
||||
CCASSERT(platform != nullptr, "Platform pointer can't be null");
|
||||
return platform->getWindowHandler();
|
||||
return reinterpret_cast<uintptr_t>(_screenWin);
|
||||
}
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
SDL_SetRelativeMouseMode(value ? SDL_FALSE : SDL_TRUE);
|
||||
//TODO
|
||||
}
|
||||
|
||||
void SystemWindow::copyTextToClipboard(const std::string &text) {
|
||||
|
||||
@@ -28,9 +28,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
|
||||
struct SDL_Window;
|
||||
struct SDL_WindowEvent;
|
||||
#include <screen/screen.h>
|
||||
|
||||
namespace cc {
|
||||
|
||||
@@ -39,15 +37,8 @@ public:
|
||||
explicit SystemWindow();
|
||||
~SystemWindow() override;
|
||||
|
||||
class Delegate {
|
||||
public:
|
||||
virtual ~Delegate() = default;
|
||||
virtual bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) = 0;
|
||||
virtual uintptr_t getWindowHandler() const = 0;
|
||||
};
|
||||
|
||||
bool createWindow(const char* title,
|
||||
int w, int h, int flags) override;
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
@@ -63,6 +54,9 @@ public:
|
||||
private:
|
||||
int _width{0};
|
||||
int _height{0};
|
||||
// std::unique_ptr<SDLHelper> _sdl;
|
||||
screen_context_t _screenCtx{nullptr};
|
||||
screen_window_t _screenWin{nullptr};
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
+1
-1
@@ -23,7 +23,7 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "platform/qnx/modules/Vibrate.h"
|
||||
#include "platform/qnx/modules/Vibrator.h"
|
||||
|
||||
#include "base/Macros.h"
|
||||
|
||||
@@ -28,9 +28,14 @@
|
||||
#include <Windows.h>
|
||||
#include <shellapi.h>
|
||||
#include <sstream>
|
||||
#include "platform/interfaces/OSInterface.h"
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
#include "platform/SDLHelper.h"
|
||||
|
||||
#include "modules/Accelerometer.h"
|
||||
#include "modules/Battery.h"
|
||||
#include "modules/Network.h"
|
||||
#include "modules/Screen.h"
|
||||
#include "modules/System.h"
|
||||
#include "modules/SystemWindow.h"
|
||||
#include "modules/Vibrator.h"
|
||||
|
||||
namespace {
|
||||
/**
|
||||
@@ -73,7 +78,6 @@ void PVRFrameEnableControlWindow(bool bEnable) {
|
||||
|
||||
namespace cc {
|
||||
WindowsPlatform::WindowsPlatform() {
|
||||
_sdl = std::make_unique<SDLHelper>(this);
|
||||
}
|
||||
WindowsPlatform::~WindowsPlatform() {
|
||||
|
||||
@@ -83,7 +87,15 @@ WindowsPlatform::~WindowsPlatform() {
|
||||
}
|
||||
|
||||
int32_t WindowsPlatform::init() {
|
||||
UniversalPlatform::init();
|
||||
registerInterface(std::make_shared<Accelerometer>());
|
||||
registerInterface(std::make_shared<Battery>());
|
||||
registerInterface(std::make_shared<Network>());
|
||||
registerInterface(std::make_shared<Screen>());
|
||||
registerInterface(std::make_shared<System>());
|
||||
_window = std::make_shared<SystemWindow>(this);
|
||||
registerInterface(_window);
|
||||
registerInterface(std::make_shared<Vibrator>());
|
||||
|
||||
#ifdef USE_WIN32_CONSOLE
|
||||
AllocConsole();
|
||||
freopen("CONIN$", "r", stdin);
|
||||
@@ -93,7 +105,7 @@ int32_t WindowsPlatform::init() {
|
||||
|
||||
PVRFrameEnableControlWindow(false);
|
||||
|
||||
return _sdl->init() ? 0 : -1;
|
||||
return _window->init();
|
||||
}
|
||||
|
||||
int32_t WindowsPlatform::loop() {
|
||||
@@ -126,13 +138,13 @@ int32_t WindowsPlatform::loop() {
|
||||
onResume();
|
||||
while (!_quit) {
|
||||
desiredInterval = (LONGLONG)(1.0 / getFps() * nFreq.QuadPart);
|
||||
pollEvent();
|
||||
_window->pollEvent(&_quit);
|
||||
QueryPerformanceCounter(&nNow);
|
||||
actualInterval = nNow.QuadPart - nLast.QuadPart;
|
||||
if (actualInterval >= desiredInterval) {
|
||||
nLast.QuadPart = nNow.QuadPart;
|
||||
runTask();
|
||||
_sdl->swapWindow();
|
||||
_window->swapWindow();
|
||||
} else {
|
||||
// The precision of timer on Windows is set to highest (1ms) by 'timeBeginPeriod' from above code,
|
||||
// but it's still not precise enough. For example, if the precision of timer is 1ms,
|
||||
@@ -152,19 +164,4 @@ int32_t WindowsPlatform::loop() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void WindowsPlatform::pollEvent() {
|
||||
_sdl->pollEvent(&_quit);
|
||||
}
|
||||
|
||||
bool WindowsPlatform::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
return _sdl->createWindow(title, x, y, w, h, flags);
|
||||
}
|
||||
|
||||
uintptr_t WindowsPlatform::getWindowHandler() const {
|
||||
return _sdl->getWindowHandler();
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -25,13 +25,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "platform/UniversalPlatform.h"
|
||||
#include "platform/win32/modules/SystemWindow.h"
|
||||
|
||||
namespace cc {
|
||||
class SDLHelper;
|
||||
class CC_DLL WindowsPlatform : public UniversalPlatform,
|
||||
public SystemWindow::Delegate {
|
||||
class SystemWindow;
|
||||
class CC_DLL WindowsPlatform : public UniversalPlatform {
|
||||
public:
|
||||
WindowsPlatform();
|
||||
/**
|
||||
@@ -45,16 +44,9 @@ public:
|
||||
|
||||
int32_t loop() override;
|
||||
|
||||
// override from SystemWindow::Delegate
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
uintptr_t getWindowHandler() const override;
|
||||
|
||||
private:
|
||||
void pollEvent() override;
|
||||
bool _quit{false};
|
||||
std::unique_ptr<SDLHelper> _sdl;
|
||||
std::shared_ptr<SystemWindow> _window{nullptr};
|
||||
bool _quit{false};
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -501,4 +501,4 @@ void CanvasRenderingContext2DDelegate::rect(float /* x */,
|
||||
float /* h */) {
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
} // namespace cc
|
||||
|
||||
@@ -31,42 +31,52 @@
|
||||
#include "bindings/event/EventDispatcher.h"
|
||||
#include "platform/IEventDispatch.h"
|
||||
#include "platform/win32/WindowsPlatform.h"
|
||||
#include "sdl2/SDL.h"
|
||||
#include "sdl2/SDL_main.h"
|
||||
#include "sdl2/SDL_syswm.h"
|
||||
|
||||
namespace {
|
||||
|
||||
} // namespace
|
||||
#include "platform/SDLHelper.h"
|
||||
|
||||
namespace cc {
|
||||
SystemWindow::SystemWindow() {
|
||||
SystemWindow::SystemWindow(IEventDispatch *delegate)
|
||||
: _sdl(std::make_unique<SDLHelper>(delegate)) {
|
||||
|
||||
}
|
||||
|
||||
SystemWindow::~SystemWindow() {
|
||||
}
|
||||
|
||||
int SystemWindow::init() {
|
||||
return _sdl->init();
|
||||
}
|
||||
|
||||
void SystemWindow::pollEvent(bool *quit) {
|
||||
return _sdl->pollEvent(quit);
|
||||
}
|
||||
|
||||
void SystemWindow::swapWindow() {
|
||||
_sdl->swapWindow();
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int w, int h, int flags) {
|
||||
_sdl->createWindow(title, w, h, flags);
|
||||
_width = w;
|
||||
_height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
// Create window
|
||||
|
||||
WindowsPlatform *platform = dynamic_cast<WindowsPlatform *>(BasePlatform::getPlatform());
|
||||
CCASSERT(platform != nullptr, "Platform pointer can't be null");
|
||||
platform->createWindow(title, x, y, w, h, flags);
|
||||
_sdl->createWindow(title, x, y, w, h, flags);
|
||||
_width = w;
|
||||
_height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
uintptr_t SystemWindow::getWindowHandler() const {
|
||||
WindowsPlatform *platform = dynamic_cast<WindowsPlatform *>(BasePlatform::getPlatform());
|
||||
CCASSERT(platform != nullptr, "Platform pointer can't be null");
|
||||
return platform->getWindowHandler();
|
||||
return _sdl->getWindowHandler();
|
||||
}
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
SDL_SetRelativeMouseMode(value ? SDL_FALSE : SDL_TRUE);
|
||||
_sdl->setCursorEnabled(value);
|
||||
}
|
||||
|
||||
void SystemWindow::copyTextToClipboard(const std::string &text) {
|
||||
|
||||
@@ -29,30 +29,23 @@
|
||||
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
|
||||
struct SDL_Window;
|
||||
struct SDL_WindowEvent;
|
||||
|
||||
namespace cc {
|
||||
|
||||
class SDLHelper;
|
||||
class CC_DLL SystemWindow : public ISystemWindow {
|
||||
public:
|
||||
explicit SystemWindow();
|
||||
explicit SystemWindow(IEventDispatch* delegate);
|
||||
~SystemWindow() override;
|
||||
|
||||
class Delegate {
|
||||
public:
|
||||
virtual ~Delegate() = default;
|
||||
virtual bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) = 0;
|
||||
virtual uintptr_t getWindowHandler() const = 0;
|
||||
};
|
||||
|
||||
int init();
|
||||
void pollEvent(bool* quit);
|
||||
void swapWindow();
|
||||
|
||||
bool createWindow(const char* title,
|
||||
int w, int h, int flags) override;
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
uintptr_t getWindowHandler() const override;
|
||||
|
||||
Size getViewSize() const override;
|
||||
/*
|
||||
@brief enable/disable(lock) the cursor, default is enabled
|
||||
@@ -63,6 +56,7 @@ public:
|
||||
private:
|
||||
int _width{0};
|
||||
int _height{0};
|
||||
std::unique_ptr<SDLHelper> _sdl;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
|
||||
Reference in New Issue
Block a user