no message
This commit is contained in:
39
cocos/platform/qnx/modules/Accelerometer.cpp
Normal file
39
cocos/platform/qnx/modules/Accelerometer.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 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/qnx/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
|
||||
301
cocos/platform/qnx/modules/CanvasRenderingContext2DDelegate.cpp
Normal file
301
cocos/platform/qnx/modules/CanvasRenderingContext2DDelegate.cpp
Normal file
@@ -0,0 +1,301 @@
|
||||
/****************************************************************************
|
||||
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/qnx/modules/CanvasRenderingContext2DDelegate.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace {
|
||||
#define RGB(r, g, b) (int)((int)r | (((int)g) << 8) | (((int)b) << 16))
|
||||
#define RGBA(r, g, b, a) (int)((int)r | (((int)g) << 8) | (((int)b) << 16) | (((int)a) << 24))
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
void fillRectWithColor(uint8_t *buf, uint32_t totalWidth, uint32_t totalHeight, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
assert(x + width <= totalWidth);
|
||||
assert(y + height <= totalHeight);
|
||||
|
||||
uint32_t y0 = y;
|
||||
uint32_t y1 = y + height;
|
||||
uint8_t *p;
|
||||
for (uint32_t offsetY = y0; offsetY < y1; ++offsetY) {
|
||||
for (uint32_t offsetX = x; offsetX < (x + width); ++offsetX) {
|
||||
p = buf + (totalWidth * offsetY + offsetX) * 4;
|
||||
*p++ = r;
|
||||
*p++ = g;
|
||||
*p++ = b;
|
||||
*p++ = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace cc {
|
||||
//static const char gdefaultFontName[] = "-*-helvetica-medium-o-*-*-24-*-*-*-*-*-iso8859-*";
|
||||
//static const char gdefaultFontName[] = "lucidasanstypewriter-bold-24";
|
||||
static const char gdefaultFontName[] = "lucidasans-24";
|
||||
static const char gdefaultFontName1[] = "lucidasans";
|
||||
|
||||
CanvasRenderingContext2DDelegate::CanvasRenderingContext2DDelegate() {
|
||||
//_surface = cairo_image_surface_create_for_data(pointer , CAIRO_FORMAT_ARGB32,size[0], size[1], stride);
|
||||
//_cr = cairo_create (_surface);
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DDelegate::~CanvasRenderingContext2DDelegate() {
|
||||
if (_cr != nullptr) {
|
||||
cairo_destroy(_cr);
|
||||
}
|
||||
if (_surface) {
|
||||
cairo_surface_destroy(_surface);
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::recreateBuffer(float w, float h) {
|
||||
_bufferWidth = w;
|
||||
_bufferHeight = h;
|
||||
if (_bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
auto textureSize = static_cast<int>(_bufferWidth * _bufferHeight * 4);
|
||||
auto *data = static_cast<int8_t *>(malloc(sizeof(int8_t) * textureSize));
|
||||
memset(data, 0x00, textureSize);
|
||||
_imageData.fastSet((unsigned char *)data, textureSize);
|
||||
|
||||
if (_cr) {
|
||||
cairo_destroy(_cr);
|
||||
}
|
||||
if (_surface) {
|
||||
cairo_surface_destroy(_surface);
|
||||
}
|
||||
_surface = cairo_image_surface_create_for_data((unsigned char *)data, CAIRO_FORMAT_ARGB32, _bufferWidth, _bufferHeight, _bufferWidth * 4);
|
||||
_cr = cairo_create(_surface);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::beginPath() {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::closePath() {
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::moveTo(float x, float y) {
|
||||
CC_ASSERT_NOT_NULL(_cr);
|
||||
cairo_move_to(_cr, x, y);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::lineTo(float x, float y) {
|
||||
CC_ASSERT_NOT_NULL(_cr);
|
||||
cairo_line_to(_cr, x, 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;
|
||||
}
|
||||
CC_ASSERT_NOT_NULL(_cr);
|
||||
cairo_set_source_rgba(_cr, _fillStyle[0], _fillStyle[1], _fillStyle[2], _fillStyle[3]);
|
||||
cairo_rectangle(_cr, x, y, w, h);
|
||||
cairo_fill(_cr);
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::fillText(const ccstd::string &text, float x, float y, float /*maxWidth*/) {
|
||||
if (text.empty() || _bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
// cairo_font_weight_t fontWeight = CAIRO_FONT_WEIGHT_NORMAL; // bold ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL;
|
||||
// cairo_font_slant_t fontSlant = CAIRO_FONT_SLANT_NORMAL;
|
||||
// cairo_select_font_face (_cr, "Arial", fontSlant, fontWeight);
|
||||
cairo_set_font_size(_cr, _fontSize);
|
||||
Point offsetPoint = convertDrawPoint(Point{x, y}, text);
|
||||
cairo_set_source_rgba(_cr, _fillStyle[0], _fillStyle[1], _fillStyle[2], _fillStyle[3]);
|
||||
cairo_move_to(_cr, offsetPoint[0], offsetPoint[1]);
|
||||
cairo_show_text(_cr, text.c_str());
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::strokeText(const ccstd::string &text, float /*x*/, float /*y*/, float /*maxWidth*/) const {
|
||||
if (text.empty() || _bufferWidth < 1.0F || _bufferHeight < 1.0F) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CanvasRenderingContext2DDelegate::Size CanvasRenderingContext2DDelegate::measureText(const ccstd::string &text) {
|
||||
if (text.empty())
|
||||
return ccstd::array<float, 2>{0.0f, 0.0f};
|
||||
cairo_text_extents_t extents;
|
||||
cairo_text_extents(_cr, text.c_str(), &extents);
|
||||
return ccstd::array<float, 2>{static_cast<float>(extents.x_advance),
|
||||
static_cast<float>(extents.height)};
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::updateFont(const ccstd::string &fontName,
|
||||
float fontSize,
|
||||
bool bold,
|
||||
bool italic,
|
||||
bool oblique,
|
||||
bool /* smallCaps */) {
|
||||
do {
|
||||
_fontName = fontName;
|
||||
_fontSize = static_cast<int>(fontSize);
|
||||
cairo_font_weight_t fontWeight = bold ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL;
|
||||
cairo_font_slant_t fontSlant = CAIRO_FONT_SLANT_NORMAL;
|
||||
if (italic) {
|
||||
fontSlant = CAIRO_FONT_SLANT_ITALIC;
|
||||
} else if (oblique) {
|
||||
fontSlant = CAIRO_FONT_SLANT_OBLIQUE;
|
||||
}
|
||||
std::cout << _fontName << std::endl;
|
||||
cairo_select_font_face(_cr, _fontName.c_str(), fontSlant, fontWeight);
|
||||
cairo_set_font_size(_cr, _fontSize);
|
||||
} while (false);
|
||||
}
|
||||
|
||||
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 = {r / 255.0F, g / 255.0F, b / 255.0F, a / 255.0F};
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setStrokeStyle(uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
|
||||
_strokeStyle = {r / 255.0F, g / 255.0F, b / 255.0F, a / 255.0F};
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::setLineWidth(float lineWidth) {
|
||||
_lineWidth = lineWidth;
|
||||
}
|
||||
|
||||
const cc::Data &CanvasRenderingContext2DDelegate::getDataRef() const {
|
||||
return _imageData;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2DDelegate::removeCustomFont() {
|
||||
}
|
||||
|
||||
// x, y offset value
|
||||
int CanvasRenderingContext2DDelegate::drawText(const ccstd::string &text, int x, int y) {
|
||||
cairo_move_to(_cr, x, y);
|
||||
cairo_show_text(_cr, text.c_str());
|
||||
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) {
|
||||
int font_ascent = 0;
|
||||
int font_descent = 0;
|
||||
int direction = 0;
|
||||
cairo_text_extents_t extents;
|
||||
cairo_text_extents(_cr, text.c_str(), &extents);
|
||||
|
||||
int width = extents.width;
|
||||
if (_textAlign == TextAlign::CENTER) {
|
||||
point[0] -= width / 2.0f;
|
||||
} else if (_textAlign == TextAlign::RIGHT) {
|
||||
point[0] -= width;
|
||||
}
|
||||
|
||||
if (_textBaseLine == TextBaseline::TOP) {
|
||||
point[1] += -extents.y_bearing;
|
||||
} else if (_textBaseLine == TextBaseline::MIDDLE) {
|
||||
point[1] += extents.height / 2;
|
||||
} else if (_textBaseLine == TextBaseline::BOTTOM) {
|
||||
point[1] += extents.height;
|
||||
}
|
||||
if (text == ".") {
|
||||
// The calculation of points is not the same as the calculation of numbers,
|
||||
// which will cause the drawing of points and numbers to be different from the same horizontal line.
|
||||
// Therefore, here is manually adjusted to calculate the drawing coordinates of
|
||||
// the point according to the numerical calculation method
|
||||
cairo_text_extents_t extentNumber;
|
||||
cairo_text_extents(_cr, "1", &extentNumber);
|
||||
point[1] += extents.y_bearing - extentNumber.y_bearing;
|
||||
}
|
||||
|
||||
return point;
|
||||
}
|
||||
|
||||
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 */) {
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
114
cocos/platform/qnx/modules/CanvasRenderingContext2DDelegate.h
Normal file
114
cocos/platform/qnx/modules/CanvasRenderingContext2DDelegate.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/****************************************************************************
|
||||
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/canvas/ICanvasRenderingContext2D.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <regex>
|
||||
#include "base/csscolorparser.h"
|
||||
#include "base/std/container/array.h"
|
||||
#include "cocos/bindings/manual/jsb_platform.h"
|
||||
#include "math/Math.h"
|
||||
#include "platform/FileUtils.h"
|
||||
|
||||
#include "cairo.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
class CC_DLL 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>;
|
||||
|
||||
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 updateData() 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 {}
|
||||
|
||||
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);
|
||||
|
||||
public:
|
||||
cairo_surface_t *_surface{nullptr};
|
||||
cairo_t *_cr{nullptr};
|
||||
|
||||
private:
|
||||
cc::Data _imageData;
|
||||
ccstd::string _curFontPath;
|
||||
int _savedDC{0};
|
||||
float _lineWidth{0.0F};
|
||||
float _bufferWidth{0.0F};
|
||||
float _bufferHeight{0.0F};
|
||||
|
||||
ccstd::string _fontName;
|
||||
int _fontSize{0};
|
||||
Size _textSize;
|
||||
TextAlign _textAlign{TextAlign::CENTER};
|
||||
TextBaseline _textBaseLine{TextBaseline::TOP};
|
||||
Color4F _fillStyle;
|
||||
Color4F _strokeStyle;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
127
cocos/platform/qnx/modules/System.cpp
Normal file
127
cocos/platform/qnx/modules/System.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/****************************************************************************
|
||||
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/qnx/modules/System.h"
|
||||
#include <string.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
namespace cc {
|
||||
|
||||
using OSType = System::OSType;
|
||||
|
||||
OSType System::getOSType() const {
|
||||
return OSType::QNX;
|
||||
}
|
||||
|
||||
ccstd::string System::getDeviceModel() const {
|
||||
return "QNX";
|
||||
}
|
||||
|
||||
System::LanguageType System::getCurrentLanguage() const {
|
||||
char *pLanguageName = getenv("LANG");
|
||||
if (!pLanguageName) {
|
||||
return LanguageType::ENGLISH;
|
||||
}
|
||||
strtok(pLanguageName, "_");
|
||||
if (!pLanguageName) {
|
||||
return LanguageType::ENGLISH;
|
||||
}
|
||||
|
||||
return getLanguageTypeByISO2(pLanguageName);
|
||||
}
|
||||
|
||||
ccstd::string System::getCurrentLanguageCode() const {
|
||||
static char code[3] = {0};
|
||||
char *pLanguageName = getenv("LANG");
|
||||
if (!pLanguageName) {
|
||||
return "en";
|
||||
}
|
||||
strtok(pLanguageName, "_");
|
||||
if (!pLanguageName) {
|
||||
return "en";
|
||||
}
|
||||
strncpy(code, pLanguageName, 2);
|
||||
code[2] = '\0';
|
||||
return code;
|
||||
}
|
||||
|
||||
ccstd::string System::getSystemVersion() const {
|
||||
struct utsname u;
|
||||
uname(&u);
|
||||
return u.version;
|
||||
}
|
||||
|
||||
bool System::openURL(const ccstd::string &url) {
|
||||
//ccstd::string op = ccstd::string("xdg-open '").append(url).append("'");
|
||||
//return system(op.c_str()) == 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
System::LanguageType System::getLanguageTypeByISO2(const char *code) const {
|
||||
// this function is used by all platforms to get system language
|
||||
// except windows: cocos/platform/win32/CCApplication-win32.cpp
|
||||
LanguageType ret = LanguageType::ENGLISH;
|
||||
|
||||
if (strncmp(code, "zh", 2) == 0) {
|
||||
ret = LanguageType::CHINESE;
|
||||
} else if (strncmp(code, "ja", 2) == 0) {
|
||||
ret = LanguageType::JAPANESE;
|
||||
} else if (strncmp(code, "fr", 2) == 0) {
|
||||
ret = LanguageType::FRENCH;
|
||||
} else if (strncmp(code, "it", 2) == 0) {
|
||||
ret = LanguageType::ITALIAN;
|
||||
} else if (strncmp(code, "de", 2) == 0) {
|
||||
ret = LanguageType::GERMAN;
|
||||
} else if (strncmp(code, "es", 2) == 0) {
|
||||
ret = LanguageType::SPANISH;
|
||||
} else if (strncmp(code, "nl", 2) == 0) {
|
||||
ret = LanguageType::DUTCH;
|
||||
} else if (strncmp(code, "ru", 2) == 0) {
|
||||
ret = LanguageType::RUSSIAN;
|
||||
} else if (strncmp(code, "hu", 2) == 0) {
|
||||
ret = LanguageType::HUNGARIAN;
|
||||
} else if (strncmp(code, "pt", 2) == 0) {
|
||||
ret = LanguageType::PORTUGUESE;
|
||||
} else if (strncmp(code, "ko", 2) == 0) {
|
||||
ret = LanguageType::KOREAN;
|
||||
} else if (strncmp(code, "ar", 2) == 0) {
|
||||
ret = LanguageType::ARABIC;
|
||||
} else if (strncmp(code, "nb", 2) == 0) {
|
||||
ret = LanguageType::NORWEGIAN;
|
||||
} else if (strncmp(code, "pl", 2) == 0) {
|
||||
ret = LanguageType::POLISH;
|
||||
} else if (strncmp(code, "tr", 2) == 0) {
|
||||
ret = LanguageType::TURKISH;
|
||||
} else if (strncmp(code, "uk", 2) == 0) {
|
||||
ret = LanguageType::UKRAINIAN;
|
||||
} else if (strncmp(code, "ro", 2) == 0) {
|
||||
ret = LanguageType::ROMANIAN;
|
||||
} else if (strncmp(code, "bg", 2) == 0) {
|
||||
ret = LanguageType::BULGARIAN;
|
||||
} else if (strncmp(code, "hi", 2) == 0) {
|
||||
ret = LanguageType::HINDI;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace cc
|
||||
67
cocos/platform/qnx/modules/System.h
Normal file
67
cocos/platform/qnx/modules/System.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
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 CC_DLL 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;
|
||||
|
||||
private:
|
||||
LanguageType getLanguageTypeByISO2(const char *code) const;
|
||||
};
|
||||
|
||||
} // namespace cc
|
||||
133
cocos/platform/qnx/modules/SystemWindow.cpp
Normal file
133
cocos/platform/qnx/modules/SystemWindow.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/****************************************************************************
|
||||
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/qnx/modules/SystemWindow.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 "bindings/event/EventDispatcher.h"
|
||||
#include "platform/IEventDispatch.h"
|
||||
#include "platform/qnx/QnxPlatform.h"
|
||||
|
||||
namespace cc {
|
||||
SystemWindow::SystemWindow() {
|
||||
}
|
||||
|
||||
SystemWindow::~SystemWindow() {
|
||||
if (_screenWin) {
|
||||
screen_destroy_window(_screenWin);
|
||||
}
|
||||
if (_screenCtx) {
|
||||
screen_destroy_context(_screenCtx);
|
||||
}
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int w, int h, int flags) {
|
||||
_width = w;
|
||||
_height = h;
|
||||
createWindow(title, 0, 0, w, h, flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SystemWindow::createWindow(const char *title,
|
||||
int x, int y, int w,
|
||||
int h, int flags) {
|
||||
if (_screenWin) {
|
||||
return true;
|
||||
}
|
||||
_width = w;
|
||||
_height = h;
|
||||
|
||||
//Create the screen context
|
||||
int rc = screen_create_context(&_screenCtx, SCREEN_APPLICATION_CONTEXT);
|
||||
if (rc) {
|
||||
perror("screen_create_window");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
//Create the screen window that will be render onto
|
||||
rc = screen_create_window(&_screenWin, _screenCtx);
|
||||
if (rc) {
|
||||
perror("screen_create_window");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_FORMAT, (const int[]){SCREEN_FORMAT_RGBX8888});
|
||||
#ifdef CC_USE_GLES3
|
||||
screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_USAGE, (const int[]){SCREEN_USAGE_OPENGL_ES3});
|
||||
#elif CC_USE_GLES2
|
||||
screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_USAGE, (const int[]){SCREEN_USAGE_OPENGL_ES2});
|
||||
#endif
|
||||
|
||||
int pos[2] = {x, y}; /* size of the window on screen */
|
||||
rc = screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_POSITION, pos);
|
||||
if (rc) {
|
||||
perror("screen_set_window_property_iv(SCREEN_PROPERTY_SIZE)");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int size[2] = {w, h}; /* size of the window on screen */
|
||||
rc = screen_set_window_property_iv(_screenWin, SCREEN_PROPERTY_SIZE, size);
|
||||
if (rc) {
|
||||
perror("screen_set_window_property_iv(SCREEN_PROPERTY_POSITION)");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
int dpi = 0;
|
||||
screen_get_window_property_iv(_screenWin, SCREEN_PROPERTY_DPI, &dpi);
|
||||
fprintf(stdout, "[glError] %d\n", dpi);
|
||||
|
||||
rc = screen_create_window_buffers(_screenWin, 2);
|
||||
if (rc) {
|
||||
perror("screen_create_window_buffers");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// return _sdl->createWindow(title, x, y, w, h, flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
uintptr_t SystemWindow::getWindowHandle() const {
|
||||
return reinterpret_cast<uintptr_t>(_screenWin);
|
||||
}
|
||||
|
||||
void SystemWindow::setCursorEnabled(bool value) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
void SystemWindow::copyTextToClipboard(const ccstd::string &text) {
|
||||
//TODO
|
||||
}
|
||||
|
||||
SystemWindow::Size SystemWindow::getViewSize() const {
|
||||
return Size{static_cast<float>(_width), static_cast<float>(_height)};
|
||||
}
|
||||
|
||||
} // namespace cc
|
||||
Reference in New Issue
Block a user