no message
This commit is contained in:
65
cocos/platform/openharmony/modules/Accelerometer.cpp
Normal file
65
cocos/platform/openharmony/modules/Accelerometer.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-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 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/openharmony/modules/Accelerometer.h"
|
||||
#include "platform/openharmony/napi/NapiHelper.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
void Accelerometer::setAccelerometerEnabled(bool isEnabled) {
|
||||
//setAccelerometerEnabledJNI(isEnabled);
|
||||
}
|
||||
|
||||
void Accelerometer::setAccelerometerInterval(float interval) {
|
||||
//setAccelerometerIntervalJNI(interval);
|
||||
}
|
||||
|
||||
const Accelerometer::MotionValue &Accelerometer::getDeviceMotionValue() {
|
||||
static MotionValue motionValue;
|
||||
Napi::Value ret = NapiHelper::napiCallFunction("getDeviceMotionValue");
|
||||
if (!ret.IsArray()) {
|
||||
return motionValue;
|
||||
}
|
||||
|
||||
auto v = ret.As<Napi::Array>();
|
||||
if (v.Length() == 9) {
|
||||
motionValue.accelerationIncludingGravityX = static_cast<Napi::Value>(v[(uint32_t)0]).As<Napi::Number>().FloatValue();
|
||||
motionValue.accelerationIncludingGravityY = static_cast<Napi::Value>(v[(uint32_t)1]).As<Napi::Number>().FloatValue();
|
||||
motionValue.accelerationIncludingGravityZ = static_cast<Napi::Value>(v[(uint32_t)2]).As<Napi::Number>().FloatValue();
|
||||
|
||||
motionValue.accelerationX = static_cast<Napi::Value>(v[(uint32_t)3]).As<Napi::Number>().FloatValue();
|
||||
motionValue.accelerationY = static_cast<Napi::Value>(v[(uint32_t)4]).As<Napi::Number>().FloatValue();
|
||||
motionValue.accelerationZ = static_cast<Napi::Value>(v[(uint32_t)5]).As<Napi::Number>().FloatValue();
|
||||
|
||||
motionValue.rotationRateAlpha = static_cast<Napi::Value>(v[(uint32_t)6]).As<Napi::Number>().FloatValue();
|
||||
motionValue.rotationRateBeta = static_cast<Napi::Value>(v[(uint32_t)7]).As<Napi::Number>().FloatValue();
|
||||
motionValue.rotationRateGamma = static_cast<Napi::Value>(v[(uint32_t)8]).As<Napi::Number>().FloatValue();
|
||||
} else {
|
||||
memset(&motionValue, 0, sizeof(motionValue));
|
||||
}
|
||||
return motionValue;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
50
cocos/platform/openharmony/modules/Accelerometer.h
Normal file
50
cocos/platform/openharmony/modules/Accelerometer.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-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 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.
|
||||
****************************************************************************/
|
||||
|
||||
#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
|
||||
39
cocos/platform/openharmony/modules/Battery.cpp
Normal file
39
cocos/platform/openharmony/modules/Battery.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
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 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/openharmony/modules/Battery.h"
|
||||
#include "platform/openharmony/napi/NapiHelper.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
float Battery::getBatteryLevel() const {
|
||||
auto value = NapiHelper::napiCallFunction("getBatteryLevel");
|
||||
if (value.IsNumber()) {
|
||||
return value.As<Napi::Number>().FloatValue();
|
||||
}
|
||||
return 0.F;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
37
cocos/platform/openharmony/modules/Battery.h
Normal file
37
cocos/platform/openharmony/modules/Battery.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-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 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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/interfaces/modules/IBattery.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class Battery : public IBattery {
|
||||
public:
|
||||
float getBatteryLevel() const override;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
@@ -0,0 +1,338 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-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 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/openharmony/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#include "platform/openharmony/OpenHarmonyPlatform.h"
|
||||
#include <native_drawing/drawing_text_typography.h>
|
||||
#include <native_drawing/drawing_canvas.h>
|
||||
#include <native_drawing/drawing_font_collection.h>
|
||||
#include <native_drawing/drawing_types.h>
|
||||
#include <native_drawing/drawing_path.h>
|
||||
#include <native_drawing/drawing_brush.h>
|
||||
|
||||
namespace cc {
|
||||
class CanvasRenderingContext2DDelegate::ScopedTypography {
|
||||
public:
|
||||
ScopedTypography(OH_Drawing_Typography* typography) :_typegraphy(typography) {}
|
||||
~ScopedTypography() {
|
||||
if(_typegraphy) {
|
||||
OH_Drawing_DestroyTypography(_typegraphy);
|
||||
}
|
||||
}
|
||||
OH_Drawing_Typography* get() {
|
||||
return _typegraphy;
|
||||
}
|
||||
private:
|
||||
OH_Drawing_Typography* _typegraphy{nullptr};
|
||||
};
|
||||
|
||||
CanvasRenderingContext2DDelegate::CanvasRenderingContext2DDelegate() {
|
||||
_typographyStyle = OH_Drawing_CreateTypographyStyle();
|
||||
OH_Drawing_SetTypographyTextDirection(_typographyStyle, TEXT_DIRECTION_LTR);
|
||||
OH_Drawing_SetTypographyTextAlign(_typographyStyle, TEXT_ALIGN_LEFT);
|
||||
|
||||
_fontCollection = OH_Drawing_CreateFontCollection();
|
||||
_typographyCreate = OH_Drawing_CreateTypographyHandler(_typographyStyle, _fontCollection);
|
||||
_textStyle = OH_Drawing_CreateTextStyle();
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DDelegate::~CanvasRenderingContext2DDelegate() {
|
||||
if(_typographyStyle) {
|
||||
OH_Drawing_DestroyTypographyStyle(_typographyStyle);
|
||||
_typographyStyle = nullptr;
|
||||
}
|
||||
|
||||
if(_fontCollection) {
|
||||
OH_Drawing_DestroyFontCollection(_fontCollection);
|
||||
}
|
||||
|
||||
if(_typographyCreate) {
|
||||
OH_Drawing_DestroyTypographyHandler(_typographyCreate);
|
||||
_typographyCreate = nullptr;
|
||||
}
|
||||
|
||||
if(_textStyle) {
|
||||
OH_Drawing_DestroyTextStyle(_textStyle);
|
||||
_textStyle = nullptr;
|
||||
}
|
||||
|
||||
if(_canvas) {
|
||||
OH_Drawing_CanvasDestroy(_canvas);
|
||||
_canvas = nullptr;
|
||||
}
|
||||
|
||||
if(_bitmap) {
|
||||
OH_Drawing_BitmapDestroy(_bitmap);
|
||||
_bitmap = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::recreateBuffer(float w, float h) {
|
||||
_bufferWidth = w;
|
||||
_bufferHeight = h;
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(_canvas) {
|
||||
OH_Drawing_CanvasDestroy(_canvas);
|
||||
_canvas = nullptr;
|
||||
}
|
||||
if(_bitmap) {
|
||||
OH_Drawing_BitmapDestroy(_bitmap);
|
||||
_bitmap = nullptr;
|
||||
}
|
||||
|
||||
_bufferSize = static_cast<int>(_bufferWidth * _bufferHeight * 4);
|
||||
auto *data = static_cast<uint8_t *>(malloc(sizeof(uint8_t) * _bufferSize));
|
||||
memset(data, 0x00, _bufferSize);
|
||||
_imageData.fastSet(data, _bufferSize);
|
||||
|
||||
_bitmap = OH_Drawing_BitmapCreate();
|
||||
OH_Drawing_BitmapBuild(_bitmap, _bufferWidth, _bufferHeight, &_format);
|
||||
_canvas = OH_Drawing_CanvasCreate();
|
||||
OH_Drawing_CanvasBind(_canvas, _bitmap);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::beginPath() {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::closePath() {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::moveTo(float x, float y) {
|
||||
//MoveToEx(_DC, static_cast<int>(x), static_cast<int>(-(y - _bufferHeight - _fontSize)), nullptr);
|
||||
_x = x;
|
||||
_y = y;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::lineTo(float x, float y) {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::stroke() {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::saveContext() {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::restoreContext() {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::clearRect(float x, float y, float w, float h) {
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_imageData.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
recreateBuffer(w, h);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fillRect(float x, float y, float w, float h) {
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
uint8_t r = static_cast<uint8_t>(_fillStyle[0]);
|
||||
uint8_t g = static_cast<uint8_t>(_fillStyle[1]);
|
||||
uint8_t b = static_cast<uint8_t>(_fillStyle[2]);
|
||||
uint8_t a = static_cast<uint8_t>(_fillStyle[3]);
|
||||
|
||||
OH_Drawing_Path* path = OH_Drawing_PathCreate();
|
||||
OH_Drawing_PathMoveTo(path, x, y);
|
||||
OH_Drawing_PathLineTo(path, x + w, y);
|
||||
OH_Drawing_PathLineTo(path, x + w, y + h);
|
||||
OH_Drawing_PathLineTo(path, x, y + h);
|
||||
OH_Drawing_PathLineTo(path, x, y);
|
||||
OH_Drawing_PathClose(path);
|
||||
OH_Drawing_Brush* brush = OH_Drawing_BrushCreate();
|
||||
OH_Drawing_BrushSetColor(brush, OH_Drawing_ColorSetArgb(a, r, g, b));
|
||||
OH_Drawing_CanvasAttachBrush(_canvas, brush);
|
||||
OH_Drawing_CanvasDrawPath(_canvas, path);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fillText(const ccstd::string &text, float x, float y, float /*maxWidth*/) {
|
||||
if (text.empty() || _bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
Size textSize = {0, 0};
|
||||
Point offsetPoint = convertDrawPoint(Point{x, y}, text);
|
||||
drawText(text, (int)offsetPoint[0], (int)offsetPoint[1]);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::strokeText(const ccstd::string &text, float /*x*/, float /*y*/, float /*maxWidth*/) const {
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DDelegate::Size CanvasRenderingContext2DDelegate::measureText(const ccstd::string &text) {
|
||||
auto typography = createTypography(text);
|
||||
return ccstd::array<float, 2>{static_cast<float>(OH_Drawing_TypographyGetMaxIntrinsicWidth(typography->get())),
|
||||
static_cast<float>(OH_Drawing_TypographyGetHeight(typography->get()))};
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::updateFont(const ccstd::string &fontName,
|
||||
float fontSize,
|
||||
bool bold,
|
||||
bool italic,
|
||||
bool oblique,
|
||||
bool /* smallCaps */) {
|
||||
_fontName = fontName;
|
||||
_fontSize = static_cast<int>(fontSize);
|
||||
ccstd::string fontPath;
|
||||
if (!_fontName.empty()) {
|
||||
const char* fontFamilies[1];
|
||||
fontFamilies[0] = fontName.c_str();
|
||||
OH_Drawing_SetTextStyleFontFamilies(_textStyle, 1, fontFamilies);
|
||||
OH_Drawing_SetTextStyleLocale(_textStyle, "en");
|
||||
}
|
||||
if (_fontSize)
|
||||
OH_Drawing_SetTextStyleFontSize(_textStyle, _fontSize);
|
||||
if (bold)
|
||||
OH_Drawing_SetTextStyleFontWeight(_textStyle, FONT_WEIGHT_700);
|
||||
else
|
||||
OH_Drawing_SetTextStyleFontWeight(_textStyle, FONT_WEIGHT_400);
|
||||
if(italic)
|
||||
OH_Drawing_SetTextStyleFontStyle(_textStyle, FONT_STYLE_ITALIC);
|
||||
else
|
||||
OH_Drawing_SetTextStyleFontStyle(_textStyle, FONT_STYLE_NORMAL);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setTextAlign(TextAlign align) {
|
||||
_textAlign = align;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setTextBaseline(TextBaseline baseline) {
|
||||
_textBaseLine = baseline;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setFillStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
_fillStyle = {static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a)};
|
||||
OH_Drawing_SetTextStyleColor(_textStyle, OH_Drawing_ColorSetArgb(a, r, g, b));
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setStrokeStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
_strokeStyle = {static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a)};
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setLineWidth(float lineWidth) {
|
||||
_lineWidth = lineWidth;
|
||||
}
|
||||
|
||||
const cc::Data &CanvasRenderingContext2DDelegate::getDataRef() const {
|
||||
void* bitmapAddr = OH_Drawing_BitmapGetPixels(_bitmap);
|
||||
memcpy(_imageData.getBytes(), bitmapAddr, _bufferSize);
|
||||
return _imageData;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::removeCustomFont() {
|
||||
}
|
||||
|
||||
// x, y offset value
|
||||
int CanvasRenderingContext2DDelegate::drawText(const ccstd::string &text, int x, int y) {
|
||||
auto typography = createTypography(text);
|
||||
OH_Drawing_TypographyPaint(typography->get(), _canvas, x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DDelegate::Size CanvasRenderingContext2DDelegate::sizeWithText(const wchar_t *pszText, int nLen) {
|
||||
return ccstd::array<float, 2>{0.0F, 0.0F};
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::prepareBitmap(int nWidth, int nHeight) {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::deleteBitmap() {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fillTextureData() {
|
||||
}
|
||||
|
||||
ccstd::array<float, 2> CanvasRenderingContext2DDelegate::convertDrawPoint(Point point, const ccstd::string &text) {
|
||||
auto typography = createTypography(text);
|
||||
Size textSize {static_cast<float>(OH_Drawing_TypographyGetMaxIntrinsicWidth(typography->get())),
|
||||
static_cast<float>(OH_Drawing_TypographyGetHeight(typography->get()))};
|
||||
if (_textAlign == TextAlign::CENTER) {
|
||||
point[0] -= textSize[0] / 2.0f;
|
||||
} else if (_textAlign == TextAlign::RIGHT) {
|
||||
point[0] -= textSize[0];
|
||||
}
|
||||
double alphabeticBaseLine = OH_Drawing_TypographyGetAlphabeticBaseline(typography->get());
|
||||
if (_textBaseLine == TextBaseline::TOP) {
|
||||
//point[1] += -alphabeticBaseLine;
|
||||
} else if (_textBaseLine == TextBaseline::MIDDLE) {
|
||||
point[1] += -textSize[1] / 2.0f;
|
||||
} else if (_textBaseLine == TextBaseline::BOTTOM) {
|
||||
point[1] += -textSize[1];
|
||||
} else if (_textBaseLine == TextBaseline::ALPHABETIC) {
|
||||
//GetTextMetrics(_DC, &_tm);
|
||||
//point[1] -= _tm.tmAscent;
|
||||
point[1] -= alphabeticBaseLine;
|
||||
}
|
||||
return point;
|
||||
}
|
||||
|
||||
std::unique_ptr<CanvasRenderingContext2DDelegate::ScopedTypography> CanvasRenderingContext2DDelegate::createTypography(const ccstd::string &text) {
|
||||
OH_Drawing_TypographyHandlerPushTextStyle(_typographyCreate, _textStyle);
|
||||
OH_Drawing_TypographyHandlerAddText(_typographyCreate, text.c_str());
|
||||
OH_Drawing_TypographyHandlerPopTextStyle(_typographyCreate);
|
||||
OH_Drawing_Typography* typography = OH_Drawing_CreateTypography(_typographyCreate);
|
||||
OH_Drawing_TypographyLayout(typography, _bufferWidth);
|
||||
return std::make_unique<ScopedTypography>(typography);
|
||||
}
|
||||
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fill() {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setLineCap(const ccstd::string &lineCap) {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setLineJoin(const ccstd::string &lineJoin) {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fillImageData(const Data & /* imageData */,
|
||||
float /* imageWidth */,
|
||||
float /* imageHeight */,
|
||||
float /* offsetX */,
|
||||
float /* offsetY */) {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::strokeText(const ccstd::string & /* text */,
|
||||
float /* x */,
|
||||
float /* y */,
|
||||
float /* maxWidth */) {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::rect(float /* x */,
|
||||
float /* y */,
|
||||
float /* w */,
|
||||
float /* h */) {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::updateData() {
|
||||
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
@@ -0,0 +1,136 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-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 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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/interfaces/modules/canvas/ICanvasRenderingContext2D.h"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <regex>
|
||||
#include <memory>
|
||||
|
||||
#include <native_drawing/drawing_types.h>
|
||||
#include <native_drawing/drawing_bitmap.h>
|
||||
#include <native_drawing/drawing_text_declaration.h>
|
||||
|
||||
#include "base/csscolorparser.h"
|
||||
#include "cocos/bindings/manual/jsb_platform.h"
|
||||
#include "math/Math.h"
|
||||
#include "platform/FileUtils.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CanvasRenderingContext2DDelegate : public ICanvasRenderingContext2D::Delegate {
|
||||
public:
|
||||
using Point = ccstd::array<float, 2>;
|
||||
using Vec2 = ccstd::array<float, 2>;
|
||||
using Size = ccstd::array<float, 2>;
|
||||
using Color4F = ccstd::array<float, 4>;
|
||||
using TextAlign = ICanvasRenderingContext2D::TextAlign;
|
||||
using TextBaseline = ICanvasRenderingContext2D::TextBaseline;
|
||||
|
||||
CanvasRenderingContext2DDelegate();
|
||||
~CanvasRenderingContext2DDelegate() override;
|
||||
|
||||
void recreateBuffer(float w, float h) override;
|
||||
void beginPath() override;
|
||||
void closePath() override;
|
||||
void moveTo(float x, float y) override;
|
||||
void lineTo(float x, float y) override;
|
||||
void stroke() override;
|
||||
void saveContext() override;
|
||||
void restoreContext() override;
|
||||
void clearRect(float /*x*/, float /*y*/, float w, float h) override;
|
||||
void fillRect(float x, float y, float w, float h) override;
|
||||
void fillText(const ccstd::string &text, float x, float y, float /*maxWidth*/) override;
|
||||
void strokeText(const ccstd::string &text, float /*x*/, float /*y*/, float /*maxWidth*/) const;
|
||||
Size measureText(const ccstd::string &text) override;
|
||||
void updateFont(const ccstd::string &fontName, float fontSize, bool bold, bool italic, bool oblique, bool smallCaps) override;
|
||||
void setTextAlign(TextAlign align) override;
|
||||
void setTextBaseline(TextBaseline baseline) override;
|
||||
void setFillStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) override;
|
||||
void setStrokeStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) override;
|
||||
void setLineWidth(float lineWidth) override;
|
||||
const cc::Data &getDataRef() const override;
|
||||
void fill() override;
|
||||
void setLineCap(const ccstd::string &lineCap) override;
|
||||
void setLineJoin(const ccstd::string &lineCap) override;
|
||||
void fillImageData(const Data &imageData, float imageWidth, float imageHeight, float offsetX, float offsetY) override;
|
||||
void strokeText(const ccstd::string &text, float /*x*/, float /*y*/, float /*maxWidth*/) override;
|
||||
void rect(float x, float y, float w, float h) override;
|
||||
void setShadowBlur(float blur)override{}
|
||||
void setShadowColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) override{}
|
||||
void setShadowOffsetX(float offsetX) override{}
|
||||
void setShadowOffsetY(float offsetY) override{}
|
||||
void updateData() override;
|
||||
private:
|
||||
static wchar_t * utf8ToUtf16(const ccstd::string &str, int *pRetLen = nullptr);
|
||||
void removeCustomFont();
|
||||
int drawText(const ccstd::string &text, int x, int y);
|
||||
Size sizeWithText(const wchar_t *pszText, int nLen);
|
||||
void prepareBitmap(int nWidth, int nHeight);
|
||||
void deleteBitmap();
|
||||
void fillTextureData();
|
||||
ccstd::array<float, 2> convertDrawPoint(Point point, const ccstd::string &text);
|
||||
|
||||
class ScopedTypography;
|
||||
std::unique_ptr<ScopedTypography> createTypography(const ccstd::string &text);
|
||||
public:
|
||||
int _screen{0};
|
||||
|
||||
private:
|
||||
|
||||
int32_t _x{0};
|
||||
int32_t _y{0};
|
||||
int32_t _lineCap{0};
|
||||
int32_t _lineJoin{0};
|
||||
|
||||
private:
|
||||
OH_Drawing_Bitmap* _bitmap{nullptr};
|
||||
OH_Drawing_BitmapFormat _format {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
|
||||
OH_Drawing_Canvas* _canvas{nullptr};
|
||||
OH_Drawing_TypographyStyle* _typographyStyle{nullptr};
|
||||
OH_Drawing_TypographyCreate* _typographyCreate{nullptr};
|
||||
OH_Drawing_FontCollection* _fontCollection{nullptr};
|
||||
OH_Drawing_TextStyle* _textStyle{nullptr};
|
||||
cc::Data _imageData;
|
||||
ccstd::string _curFontPath;
|
||||
int _savedDC{0};
|
||||
float _lineWidth{0.0F};
|
||||
float _bufferWidth{0.0F};
|
||||
float _bufferHeight{0.0F};
|
||||
int32_t _bufferSize{0};
|
||||
|
||||
ccstd::string _fontName;
|
||||
int _fontSize{0};
|
||||
Size _textSize;
|
||||
TextAlign _textAlign{TextAlign::CENTER};
|
||||
TextBaseline _textBaseLine{TextBaseline::TOP};
|
||||
Color4F _fillStyle{0};
|
||||
Color4F _strokeStyle{0};
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
93
cocos/platform/openharmony/modules/Screen.cpp
Normal file
93
cocos/platform/openharmony/modules/Screen.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-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 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/openharmony/modules/Screen.h"
|
||||
#include "platform/openharmony/napi/NapiHelper.h"
|
||||
|
||||
#include "bindings/jswrapper/SeApi.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
int Screen::getDPI() const {
|
||||
auto dpi = NapiHelper::napiCallFunction("getDPI");
|
||||
if (dpi.IsNumber()) {
|
||||
return dpi.As<Napi::Number>().Int32Value();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
float Screen::getDevicePixelRatio() const {
|
||||
// float value;
|
||||
// NapiHelper::napiCallFunction("getPixelRation", &value);
|
||||
// return value;
|
||||
// TODO(qgh):openharmony does support this interface, but returning a value of 1.5 will cause the entire page to zoom in.
|
||||
return 1;
|
||||
}
|
||||
|
||||
Screen::Orientation Screen::getDeviceOrientation() const {
|
||||
auto dpi = NapiHelper::napiCallFunction("getDeviceOrientation");
|
||||
int32_t value = 0;
|
||||
if (dpi.IsNumber()) {
|
||||
value = dpi.As<Napi::Number>().Int32Value();
|
||||
}
|
||||
|
||||
if(value == 0) {
|
||||
return Orientation::PORTRAIT;
|
||||
} else if(value == 1) {
|
||||
return Orientation::LANDSCAPE_LEFT;
|
||||
} else if(value == 2) {
|
||||
return Orientation::PORTRAIT_UPSIDE_DOWN;
|
||||
} else if(value == 3) {
|
||||
return Orientation::LANDSCAPE_RIGHT;
|
||||
}
|
||||
CC_ASSERT(false);
|
||||
return Orientation::PORTRAIT;
|
||||
}
|
||||
|
||||
void Screen::setKeepScreenOn(bool value) {
|
||||
CC_UNUSED_PARAM(value);
|
||||
}
|
||||
|
||||
Vec4 Screen::getSafeAreaEdge() const {
|
||||
return cc::Vec4();
|
||||
}
|
||||
|
||||
bool Screen::isDisplayStats() {
|
||||
se::AutoHandleScope hs;
|
||||
se::Value ret;
|
||||
const char commandBuf[100] = "cc.profiler.isShowingStats();";
|
||||
se::ScriptEngine::getInstance()->evalString(commandBuf, 100, &ret);
|
||||
return ret.toBoolean();
|
||||
}
|
||||
|
||||
void Screen::setDisplayStats(bool isShow) {
|
||||
se::AutoHandleScope hs;
|
||||
char commandBuf[100] = {0};
|
||||
sprintf(commandBuf, isShow ? "cc.profiler.showStats();" : "cc.profiler.hideStats();");
|
||||
se::ScriptEngine::getInstance()->evalString(commandBuf);
|
||||
}
|
||||
|
||||
|
||||
} // namespace cc
|
||||
51
cocos/platform/openharmony/modules/Screen.h
Normal file
51
cocos/platform/openharmony/modules/Screen.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-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 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.
|
||||
****************************************************************************/
|
||||
|
||||
#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
|
||||
115
cocos/platform/openharmony/modules/System.cpp
Normal file
115
cocos/platform/openharmony/modules/System.cpp
Normal file
@@ -0,0 +1,115 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-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 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/openharmony/modules/System.h"
|
||||
#include <string>
|
||||
#include "platform/openharmony/napi/NapiHelper.h"
|
||||
|
||||
namespace cc {
|
||||
System::System() = default;
|
||||
System::~System() = default;
|
||||
|
||||
System::OSType System::getOSType() const {
|
||||
return OSType::OPENHARMONY;
|
||||
}
|
||||
|
||||
std::string System::getDeviceModel() const {
|
||||
return "";
|
||||
}
|
||||
|
||||
System::LanguageType System::getCurrentLanguage() const {
|
||||
ccstd::string languageStr = getCurrentLanguageCode(); // NOLINT
|
||||
if (languageStr == "en") {
|
||||
return ISystem::LanguageType::ENGLISH;
|
||||
} else if (languageStr == "zh") {
|
||||
return ISystem::LanguageType::CHINESE;
|
||||
} else if (languageStr == "fr") {
|
||||
return ISystem::LanguageType::FRENCH;
|
||||
} else if (languageStr == "it") {
|
||||
return ISystem::LanguageType::ITALIAN;
|
||||
} else if (languageStr == "de") {
|
||||
return ISystem::LanguageType::GERMAN;
|
||||
} else if (languageStr == "es") {
|
||||
return ISystem::LanguageType::SPANISH;
|
||||
} else if (languageStr == "du") {
|
||||
return ISystem::LanguageType::DUTCH;
|
||||
} else if (languageStr == "ru") {
|
||||
return ISystem::LanguageType::RUSSIAN;
|
||||
} else if (languageStr == "ko") {
|
||||
return ISystem::LanguageType::KOREAN;
|
||||
} else if (languageStr == "ja") {
|
||||
return ISystem::LanguageType::JAPANESE;
|
||||
} else if (languageStr == "hu") {
|
||||
return ISystem::LanguageType::HUNGARIAN;
|
||||
} else if (languageStr == "pt") {
|
||||
return ISystem::LanguageType::PORTUGUESE;
|
||||
} else if (languageStr == "ar") {
|
||||
return ISystem::LanguageType::ARABIC;
|
||||
} else if (languageStr == "no") {
|
||||
return ISystem::LanguageType::NORWEGIAN;
|
||||
} else if (languageStr == "pl") {
|
||||
return ISystem::LanguageType::POLISH;
|
||||
} else if (languageStr == "tr") {
|
||||
return ISystem::LanguageType::TURKISH;
|
||||
} else if (languageStr == "uk") {
|
||||
return ISystem::LanguageType::UKRAINIAN;
|
||||
} else if (languageStr == "ro") {
|
||||
return ISystem::LanguageType::ROMANIAN;
|
||||
} else if (languageStr == "bg") {
|
||||
return ISystem::LanguageType::BULGARIAN;
|
||||
}
|
||||
return ISystem::LanguageType::ENGLISH;
|
||||
}
|
||||
|
||||
std::string System::getCurrentLanguageCode() const {
|
||||
auto ret = NapiHelper::napiCallFunction("getSystemLanguage");
|
||||
if (!ret.IsString()) {
|
||||
return {};
|
||||
}
|
||||
auto str = ret.As<Napi::String>().Utf8Value();
|
||||
std::string::size_type pos = str.find('-');
|
||||
if(pos != std::string::npos) {
|
||||
str = str.substr(0, pos);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string System::getSystemVersion() const {
|
||||
auto ret = NapiHelper::napiCallFunction("getOSFullName");
|
||||
if (!ret.IsString()) {
|
||||
return {};
|
||||
}
|
||||
return ret.As<Napi::String>().Utf8Value();
|
||||
}
|
||||
|
||||
bool System::openURL(const std::string& url) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void System::copyTextToClipboard(const std::string& text) {
|
||||
//copyTextToClipboardJNI(text);
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
68
cocos/platform/openharmony/modules/System.h
Normal file
68
cocos/platform/openharmony/modules/System.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-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 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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "platform/interfaces/modules/ISystem.h"
|
||||
|
||||
class ANativeWindow;
|
||||
|
||||
namespace cc {
|
||||
|
||||
class System : public ISystem {
|
||||
public:
|
||||
System();
|
||||
~System() override;
|
||||
|
||||
OSType getOSType() const override;
|
||||
/**
|
||||
@brief Get target device model.
|
||||
*/
|
||||
std::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.
|
||||
*/
|
||||
std::string getCurrentLanguageCode() const override;
|
||||
/**
|
||||
@brief Get system version.
|
||||
@return system version.
|
||||
*/
|
||||
std::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 std::string& url) override;
|
||||
void copyTextToClipboard(const std::string& text) override;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
85
cocos/platform/openharmony/modules/SystemWindow.cpp
Normal file
85
cocos/platform/openharmony/modules/SystemWindow.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/****************************************************************************
|
||||
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/openharmony/modules/SystemWindow.h"
|
||||
#include "base/Log.h"
|
||||
#include "base/Macros.h"
|
||||
#include "platform/openharmony/OpenHarmonyPlatform.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
SystemWindow::SystemWindow(uint32_t windowId, void *externalHandle)
|
||||
: _windowId(windowId) {
|
||||
if (externalHandle) {
|
||||
_windowHandle = reinterpret_cast<void*>(externalHandle);
|
||||
}
|
||||
}
|
||||
|
||||
SystemWindow::~SystemWindow() {
|
||||
_windowHandle = 0;
|
||||
_windowId = 0;
|
||||
}
|
||||
|
||||
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(flags);
|
||||
|
||||
_width = w;
|
||||
_height = h;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
}
|
||||
|
||||
uint32_t SystemWindow::getWindowId() const {
|
||||
return _windowId;
|
||||
}
|
||||
|
||||
uintptr_t SystemWindow::getWindowHandle() const {
|
||||
return reinterpret_cast<uintptr_t>(_windowHandle);
|
||||
}
|
||||
|
||||
void SystemWindow::setWindowHandle(void* window) {
|
||||
_windowHandle = window;
|
||||
}
|
||||
|
||||
void SystemWindow::setViewSize(uint32_t width, uint32_t height) {
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
|
||||
SystemWindow::Size SystemWindow::getViewSize() const {
|
||||
return Size{static_cast<float>(_width),
|
||||
static_cast<float>(_height)};
|
||||
}
|
||||
|
||||
|
||||
} // namespace cc
|
||||
63
cocos/platform/openharmony/modules/SystemWindow.h
Normal file
63
cocos/platform/openharmony/modules/SystemWindow.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
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 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.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "platform/interfaces/modules/ISystemWindow.h"
|
||||
#include <ace/xcomponent/native_interface_xcomponent.h>
|
||||
|
||||
namespace cc {
|
||||
|
||||
class SystemWindow : public ISystemWindow {
|
||||
public:
|
||||
explicit SystemWindow(uint32_t windowId, void* externalHandle);
|
||||
~SystemWindow() override;
|
||||
|
||||
bool createWindow(const char* title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) override;
|
||||
|
||||
uint32_t getWindowId() const override;
|
||||
uintptr_t getWindowHandle() const override;
|
||||
void setWindowHandle(void* window);
|
||||
Size getViewSize() const override;
|
||||
void setViewSize(uint32_t width, uint32_t height) override;
|
||||
|
||||
/**
|
||||
@brief enable/disable(lock) the cursor, default is enabled
|
||||
*/
|
||||
void setCursorEnabled(bool value) override;
|
||||
|
||||
private:
|
||||
void* _windowHandle{nullptr};
|
||||
uint32_t _windowId{0};
|
||||
std::string _id{""};
|
||||
uint64_t _width{0};
|
||||
uint64_t _height{0};
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
93
cocos/platform/openharmony/modules/SystemWindowManager.cpp
Normal file
93
cocos/platform/openharmony/modules/SystemWindowManager.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 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 "platform/BasePlatform.h"
|
||||
#include "platform/SDLHelper.h"
|
||||
#include "platform/interfaces/modules/ISystemWindowManager.h"
|
||||
#include "platform/openharmony/modules/SystemWindow.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
int SystemWindowManager::init() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SystemWindowManager::processEvent() {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
ISystemWindow *SystemWindowManager::getWindowFromHandle(void *window) const {
|
||||
if (!window) {
|
||||
return nullptr;
|
||||
}
|
||||
for (const auto &pair : _windows) {
|
||||
ISystemWindow *sysWindow = pair.second.get();
|
||||
auto *nativeWindow = reinterpret_cast<void *>(sysWindow->getWindowHandle());
|
||||
if (nativeWindow == window) {
|
||||
return sysWindow;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void SystemWindowManager::removeWindow(void* window) {
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
for (auto it = _windows.begin(); it != _windows.end(); ++it) {
|
||||
ISystemWindow *sysWindow = it->second.get();
|
||||
auto *nativeWindow = reinterpret_cast<void *>(sysWindow->getWindowHandle());
|
||||
if (nativeWindow == window) {
|
||||
_windows.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
51
cocos/platform/openharmony/modules/SystemWindowManager.h
Normal file
51
cocos/platform/openharmony/modules/SystemWindowManager.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 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 "base/std/container/unordered_map.h"
|
||||
#include "platform/interfaces/modules/ISystemWindowManager.h"
|
||||
|
||||
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 *getWindowFromHandle(void* handle) const;
|
||||
void removeWindow(void* window);
|
||||
private:
|
||||
uint32_t _nextWindowId{1}; // start from 1, 0 means an invalid ID
|
||||
|
||||
SystemWindowMap _windows;
|
||||
};
|
||||
} // namespace cc
|
||||
Reference in New Issue
Block a user