no message

This commit is contained in:
gem
2025-02-18 15:21:31 +08:00
commit 2d133e56d7
1980 changed files with 465595 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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.
****************************************************************************/
#pragma once
#include "platform/interfaces/modules/IAccelerometer.h"
namespace cc {
class Accelerometer : public IAccelerometer {
public:
/**
* To enable or disable accelerometer.
*/
void setAccelerometerEnabled(bool isEnabled) override;
/**
* Sets the interval of accelerometer.
*/
void setAccelerometerInterval(float interval) override;
/**
* Gets the motion value of current device.
*/
const MotionValue &getDeviceMotionValue() override;
};
} // namespace cc

View File

@@ -0,0 +1,40 @@
/****************************************************************************
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/mac/modules/Accelerometer.h"
namespace cc {
void Accelerometer::setAccelerometerEnabled(bool isEnabled) {
}
void Accelerometer::setAccelerometerInterval(float interval) {
}
const Accelerometer::MotionValue& Accelerometer::getDeviceMotionValue() {
static MotionValue motionValue;
return motionValue;
}
} // namespace cc

View File

@@ -0,0 +1,37 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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.
****************************************************************************/
#pragma once
#include "platform/interfaces/modules/IBattery.h"
namespace cc {
class Battery : public IBattery {
public:
Battery() = default;
float getBatteryLevel() const override;
};
} // namespace cc

View File

@@ -0,0 +1,34 @@
/****************************************************************************
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/mac/modules/Battery.h"
namespace cc {
float Battery::getBatteryLevel() const {
return 1.0F;
}
} // namespace cc

View File

@@ -0,0 +1,36 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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.
****************************************************************************/
#pragma once
#include "platform/interfaces/modules/INetwork.h"
namespace cc {
class Network : public INetwork {
public:
NetworkType getNetworkType() const override;
};
} // namespace cc

View File

@@ -0,0 +1,58 @@
/****************************************************************************
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/mac/modules/Network.h"
#import <AppKit/AppKit.h>
#include <Cocoa/Cocoa.h>
#include <Foundation/Foundation.h>
#include "platform/apple/Reachability.h"
namespace cc {
INetwork::NetworkType Network::getNetworkType() const {
static Reachability *__reachability = nullptr;
if (__reachability == nullptr) {
__reachability = Reachability::createForInternetConnection();
__reachability->addRef();
}
NetworkType ret = NetworkType::NONE;
Reachability::NetworkStatus status = __reachability->getCurrentReachabilityStatus();
switch (status) {
case Reachability::NetworkStatus::REACHABLE_VIA_WIFI:
ret = NetworkType::LAN;
break;
case Reachability::NetworkStatus::REACHABLE_VIA_WWAN:
ret = NetworkType::WWAN;
break;
default:
ret = NetworkType::NONE;
break;
}
return ret;
}
} // namespace cc

View File

@@ -0,0 +1,50 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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.
****************************************************************************/
#pragma once
#include "platform/interfaces/modules/IScreen.h"
namespace cc {
class Screen : public IScreen {
public:
int getDPI() const override;
float getDevicePixelRatio() const override;
void setKeepScreenOn(bool value) override;
Orientation getDeviceOrientation() const override;
Vec4 getSafeAreaEdge() const override;
/**
@brief Get current display stats.
@return bool, is displaying stats or not.
*/
bool isDisplayStats() override;
/**
@brief set display stats information.
*/
void setDisplayStats(bool isShow) override;
};
} // namespace cc

View File

@@ -0,0 +1,88 @@
/****************************************************************************
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/mac/modules/Screen.h"
#import <AppKit/AppKit.h>
#include <Cocoa/Cocoa.h>
#include <Foundation/Foundation.h>
#include "base/Macros.h"
#include "cocos/bindings/jswrapper/SeApi.h"
#include "platform/interfaces/modules/ISystemWindowManager.h"
#include "platform/mac/modules/SystemWindow.h"
#include "application/ApplicationManager.h"
namespace cc {
int Screen::getDPI() const {
NSScreen *screen = [NSScreen mainScreen];
NSDictionary *description = [screen deviceDescription];
NSSize displayPixelSize = [[description objectForKey:NSDeviceSize] sizeValue];
CGSize displayPhysicalSize = CGDisplayScreenSize([[description objectForKey:@"NSScreenNumber"] unsignedIntValue]);
return ((displayPixelSize.width / displayPhysicalSize.width) * 25.4f);
}
float Screen::getDevicePixelRatio() const {
#if CC_EDITOR
auto* global = se::ScriptEngine::getInstance()->getGlobalObject();
se::Value devicePixelRatioVal;
global->getProperty("devicePixelRatio", &devicePixelRatioVal);
return devicePixelRatioVal.isNumber() ? devicePixelRatioVal.toFloat() : 1.F;
#else
auto* systemWindow = static_cast<SystemWindow*>(CC_GET_MAIN_SYSTEM_WINDOW());
auto* nsWindow = systemWindow->getNSWindow();
return [nsWindow backingScaleFactor];
#endif
}
void Screen::setKeepScreenOn(bool value) {
CC_UNUSED_PARAM(value);
}
Screen::Orientation Screen::getDeviceOrientation() const {
return Orientation::PORTRAIT;
}
Vec4 Screen::getSafeAreaEdge() const {
return cc::Vec4();
}
bool Screen::isDisplayStats() {
se::AutoHandleScope hs;
se::Value ret;
char commandBuf[100] = "cc.debug.isDisplayStats();";
se::ScriptEngine::getInstance()->evalString(commandBuf, 100, &ret);
return ret.toBoolean();
}
void Screen::setDisplayStats(bool isShow) {
se::AutoHandleScope hs;
char commandBuf[100] = {0};
sprintf(commandBuf, "cc.debug.setDisplayStats(%s);", isShow ? "true" : "false");
se::ScriptEngine::getInstance()->evalString(commandBuf);
}
} // namespace cc

View File

@@ -0,0 +1,66 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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.
****************************************************************************/
#pragma once
#include "platform/interfaces/modules/ISystem.h"
namespace cc {
class System : public ISystem {
public:
/**
@brief Get target system type.
*/
OSType getOSType() const override;
/**
@brief Get target device model.
*/
ccstd::string getDeviceModel() const override;
/**
@brief Get current language config.
@return Current language config.
*/
LanguageType getCurrentLanguage() const override;
/**
@brief Get current language iso 639-1 code.
@return Current language iso 639-1 code.
*/
ccstd::string getCurrentLanguageCode() const override;
/**
@brief Get system version.
@return system version.
*/
ccstd::string getSystemVersion() const override;
/**
@brief Open url in default browser.
@param String with url to open.
@return True if the resource located by the URL was successfully opened; otherwise false.
*/
bool openURL(const ccstd::string& url) override;
void copyTextToClipboard(const std::string& text) override;
};
} // namespace cc

View File

@@ -0,0 +1,107 @@
/****************************************************************************
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/mac/modules/System.h"
#import <AppKit/AppKit.h>
#include <sys/utsname.h>
#include <algorithm>
#include <mutex>
#include <sstream>
namespace cc {
using OSType = System::OSType;
OSType System::getOSType() const {
return OSType::MAC;
}
ccstd::string System::getDeviceModel() const {
struct utsname systemInfo;
uname(&systemInfo);
return systemInfo.machine;
}
System::LanguageType System::getCurrentLanguage() const {
// get the current language and country config
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
NSString *currentLanguage = [languages objectAtIndex:0];
// get the current language code.(such as English is "en", Chinese is "zh" and so on)
NSDictionary *temp = [NSLocale componentsFromLocaleIdentifier:currentLanguage];
NSString *languageCode = [temp objectForKey:NSLocaleLanguageCode];
if ([languageCode isEqualToString:@"zh"]) return LanguageType::CHINESE;
if ([languageCode isEqualToString:@"en"]) return LanguageType::ENGLISH;
if ([languageCode isEqualToString:@"fr"]) return LanguageType::FRENCH;
if ([languageCode isEqualToString:@"it"]) return LanguageType::ITALIAN;
if ([languageCode isEqualToString:@"de"]) return LanguageType::GERMAN;
if ([languageCode isEqualToString:@"es"]) return LanguageType::SPANISH;
if ([languageCode isEqualToString:@"nl"]) return LanguageType::DUTCH;
if ([languageCode isEqualToString:@"ru"]) return LanguageType::RUSSIAN;
if ([languageCode isEqualToString:@"ko"]) return LanguageType::KOREAN;
if ([languageCode isEqualToString:@"ja"]) return LanguageType::JAPANESE;
if ([languageCode isEqualToString:@"hu"]) return LanguageType::HUNGARIAN;
if ([languageCode isEqualToString:@"pt"]) return LanguageType::PORTUGUESE;
if ([languageCode isEqualToString:@"ar"]) return LanguageType::ARABIC;
if ([languageCode isEqualToString:@"nb"]) return LanguageType::NORWEGIAN;
if ([languageCode isEqualToString:@"pl"]) return LanguageType::POLISH;
if ([languageCode isEqualToString:@"tr"]) return LanguageType::TURKISH;
if ([languageCode isEqualToString:@"uk"]) return LanguageType::UKRAINIAN;
if ([languageCode isEqualToString:@"ro"]) return LanguageType::ROMANIAN;
if ([languageCode isEqualToString:@"bg"]) return LanguageType::BULGARIAN;
if ([languageCode isEqualToString:@"hi"]) return LanguageType::HINDI;
return LanguageType::ENGLISH;
}
ccstd::string System::getCurrentLanguageCode() const {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
NSString *currentLanguage = [languages objectAtIndex:0];
return [currentLanguage UTF8String];
}
ccstd::string System::getSystemVersion() const {
NSOperatingSystemVersion v = NSProcessInfo.processInfo.operatingSystemVersion;
char version[50] = {0};
snprintf(version, sizeof(version), "%d.%d.%d", (int)v.majorVersion, (int)v.minorVersion, (int)v.patchVersion);
return version;
}
bool System::openURL(const ccstd::string &url) {
NSString *msg = [NSString stringWithCString:url.c_str() encoding:NSUTF8StringEncoding];
NSURL *nsUrl = [NSURL URLWithString:msg];
return [[NSWorkspace sharedWorkspace] openURL:nsUrl];
}
void System::copyTextToClipboard(const std::string &text) {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
NSString *tmp = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding];
[pasteboard setString:tmp forType:NSPasteboardTypeString];
}
} // namespace cc

View File

@@ -0,0 +1,72 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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.
****************************************************************************/
#pragma once
#include <iostream>
#include <AppKit/AppKit.h>
#include "platform/interfaces/modules/ISystemWindow.h"
struct SDL_Window;
namespace cc {
class SDLHelper;
class CC_DLL SystemWindow : public ISystemWindow {
friend class SystemWindowManager;
public:
explicit SystemWindow(uint32_t windowId, void* externalHandle);
~SystemWindow() override;
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;
void closeWindow() override;
virtual uint32_t getWindowId() const override { return _windowId; }
uintptr_t getWindowHandle() const override;
Size getViewSize() const override;
void setViewSize(uint32_t w, uint32_t h) override {
_width = w;
_height = h;
}
/*
@brief enable/disable(lock) the cursor, default is enabled
*/
void setCursorEnabled(bool value) override;
NSWindow* getNSWindow() const;
private:
SDL_Window* getSDLWindow() const { return _window; }
void initWindowProperty(SDL_Window* window, const char *title, int x, int y, int w, int h);
uint32_t _width{0};
uint32_t _height{0};
uint32_t _windowId{0};
uintptr_t _windowHandle{0};
SDL_Window* _window{nullptr};
};
} // namespace cc

View File

@@ -0,0 +1,138 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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 "platform/mac/modules/SystemWindow.h"
#include "platform/mac/View.h"
#include "base/Log.h"
#include "base/Macros.h"
// SDL headers
#include <functional>
#include "SDL2/SDL.h"
#include "SDL2/SDL_main.h"
#include "SDL2/SDL_syswm.h"
#include "engine/EngineEvents.h"
#include "platform/SDLHelper.h"
#import <AppKit/NSView.h>
#import <AppKit/NSWindow.h>
#import <Metal/Metal.h>
#import <QuartzCore/CAMetalLayer.h>
#include "platform/interfaces/modules/IScreen.h"
#include "platform/BasePlatform.h"
namespace cc {
SystemWindow::SystemWindow(uint32_t windowId, void *externalHandle)
: _windowId(windowId) {
if (externalHandle) {
_windowHandle = reinterpret_cast<uintptr_t>(externalHandle);
}
}
SystemWindow::~SystemWindow() {
_windowHandle = 0;
_windowId = 0;
}
void SystemWindow::initWindowProperty(SDL_Window* window, const char *title, int x, int y, int w, int h) {
CC_ASSERT(window != nullptr);
auto* nsWindow = reinterpret_cast<NSWindow*>(SDLHelper::getWindowHandle(window));
NSString *astring = [NSString stringWithUTF8String:title];
nsWindow.title = astring;
// contentView is created internally by sdl.
NSView *view = nsWindow.contentView;
auto* newView = [[View alloc] initWithFrame:view.frame];
[view addSubview:newView];
[nsWindow.contentView setWantsBestResolutionOpenGLSurface:YES];
[nsWindow makeKeyAndOrderFront:nil];
_windowHandle = reinterpret_cast<uintptr_t>(newView);
auto dpr = [nsWindow backingScaleFactor];
_width = w * dpr;
_height = h * dpr;
}
NSWindow* SystemWindow::getNSWindow() const {
CC_ASSERT(_window != nullptr);
return reinterpret_cast<NSWindow*>(SDLHelper::getWindowHandle(_window));
}
bool SystemWindow::createWindow(const char *title,
int w, int h, int flags) {
#if CC_EDITOR
return createWindow(title, 0, 0, w, h, flags);
#else
_window = SDLHelper::createWindow(title, w, h, flags);
if (!_window) {
return false;
}
Vec2 pos = SDLHelper::getWindowPosition(_window);
initWindowProperty(_window, title, pos.x, pos.y, w, h);
return true;
#endif
}
bool SystemWindow::createWindow(const char *title,
int x, int y, int w,
int h, int flags) {
#if CC_EDITOR
_width = w;
_height = h;
CAMetalLayer *layer = [[CAMetalLayer layer] retain];
layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
layer.frame = CGRectMake(x, y, w, h);
[layer setAnchorPoint:CGPointMake(0.f, 0.f)];
_windowHandle = reinterpret_cast<uintptr_t>(layer);
return true;
#else
_window = SDLHelper::createWindow(title, x, y, w, h, flags);
if (!_window) {
return false;
}
initWindowProperty(_window, title, x, y, w, h);
return true;
#endif
}
void SystemWindow::closeWindow() {
#ifndef CC_SERVER_MODE
SDL_Event et;
et.type = SDL_QUIT;
SDL_PushEvent(&et);
#endif
}
uintptr_t SystemWindow::getWindowHandle() const {
return _windowHandle;
}
void SystemWindow::setCursorEnabled(bool value) {
SDLHelper::setCursorEnabled(value);
}
SystemWindow::Size SystemWindow::getViewSize() const {
return Size{static_cast<float>(_width), static_cast<float>(_height)};
}
} // namespace cc

View File

@@ -0,0 +1,53 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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.
****************************************************************************/
#pragma once
#include <AppKit/AppKit.h>
#include "base/std/container/unordered_map.h"
#include "platform/interfaces/modules/ISystemWindowManager.h"
struct SDL_Window;
namespace cc {
class ISystemWindow;
class SystemWindowManager : public ISystemWindowManager {
public:
SystemWindowManager() = default;
int init() override;
void processEvent() override;
ISystemWindow *createWindow(const ISystemWindowInfo &info) override;
ISystemWindow *getWindow(uint32_t windowId) const override;
const SystemWindowMap &getWindows() const override { return _windows; }
ISystemWindow *getWindowFromSDLWindow(SDL_Window *window) const;
ISystemWindow *getWindowFromNSWindow(NSWindow *window) const;
private:
uint32_t _nextWindowId{1}; // start from 1, 0 means an invalid ID
SystemWindowMap _windows;
};
} // namespace cc

View File

@@ -0,0 +1,98 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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 "SystemWindowManager.h"
#include "SDL2/SDL_events.h"
#include "platform/BasePlatform.h"
#include "platform/SDLHelper.h"
#include "platform/interfaces/modules/ISystemWindowManager.h"
#include "platform/mac/modules/SystemWindow.h"
namespace cc {
int SystemWindowManager::init() {
return SDLHelper::init();
}
void SystemWindowManager::processEvent() {
SDL_Event sdlEvent;
while (SDL_PollEvent(&sdlEvent) != 0) {
SDL_Window *sdlWindow = SDL_GetWindowFromID(sdlEvent.window.windowID);
// SDL_Event like SDL_QUIT does not associate a window
if (!sdlWindow) {
SDLHelper::dispatchSDLEvent(0, sdlEvent);
} else {
ISystemWindow *window = getWindowFromSDLWindow(sdlWindow);
CC_ASSERT(window);
uint32_t windowId = window->getWindowId();
SDLHelper::dispatchSDLEvent(windowId, sdlEvent);
}
}
}
ISystemWindow *SystemWindowManager::createWindow(const ISystemWindowInfo &info) {
ISystemWindow *window = BasePlatform::getPlatform()->createNativeWindow(_nextWindowId, info.externalHandle);
if (window) {
if (!info.externalHandle) {
window->createWindow(info.title.c_str(), info.x, info.y, info.width, info.height, info.flags);
}
_windows[_nextWindowId] = std::shared_ptr<ISystemWindow>(window);
_nextWindowId++;
}
return window;
}
ISystemWindow *SystemWindowManager::getWindow(uint32_t windowId) const {
if (windowId == 0)
return nullptr;
auto iter = _windows.find(windowId);
if (iter != _windows.end())
return iter->second.get();
return nullptr;
}
cc::ISystemWindow *SystemWindowManager::getWindowFromSDLWindow(SDL_Window *window) const {
for (const auto &iter : _windows) {
SystemWindow *sysWindow = static_cast<SystemWindow *>(iter.second.get());
SDL_Window *sdlWindow = sysWindow->getSDLWindow();
if (sdlWindow == window) {
return sysWindow;
}
}
return nullptr;
}
ISystemWindow *SystemWindowManager::getWindowFromNSWindow(NSWindow *window) const {
for (const auto &iter : _windows) {
SystemWindow *sysWindow = static_cast<SystemWindow *>(iter.second.get());
NSWindow *nsWindow = sysWindow->getNSWindow();
if (nsWindow == window) {
return sysWindow;
}
}
return nullptr;
}
} // namespace cc

View File

@@ -0,0 +1,43 @@
/****************************************************************************
Copyright (c) 2021-2023 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 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.
****************************************************************************/
#pragma once
#include "platform/interfaces/modules/IVibrator.h"
namespace cc {
class Vibrator : public IVibrator {
public:
/**
* Vibrate for the specified amount of time.
* If vibrate is not supported, then invoking this method has no effect.
* Some platforms limit to a maximum duration of 5 seconds.
* Duration is ignored on iOS due to API limitations.
* @param duration The duration in seconds.
*/
void vibrate(float duration) override;
};
} // namespace cc

View File

@@ -0,0 +1,36 @@
/****************************************************************************
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/mac/modules/Vibrator.h"
#include "base/Macros.h"
namespace cc {
void Vibrator::vibrate(float duration) {
CC_UNUSED_PARAM(duration);
}
} // namespace cc