mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-19 04:28:58 +00:00
Harmony port: main project
This commit is contained in:
parent
791e9b2101
commit
ed283adcaf
46 changed files with 822 additions and 0 deletions
12
ohos-project/.gitignore
vendored
Normal file
12
ohos-project/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
/node_modules
|
||||
/oh_modules
|
||||
/local.properties
|
||||
/.idea
|
||||
**/build
|
||||
/.hvigor
|
||||
.cxx
|
||||
/.clangd
|
||||
/.clang-format
|
||||
/.clang-tidy
|
||||
**/.test
|
||||
/.appanalyzer
|
||||
10
ohos-project/AppScope/app.json5
Normal file
10
ohos-project/AppScope/app.json5
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"app": {
|
||||
"bundleName": "com.cpp.app",
|
||||
"vendor": "example",
|
||||
"versionCode": 1000000,
|
||||
"versionName": "1.0.0",
|
||||
"icon": "$media:layered_image",
|
||||
"label": "$string:app_name"
|
||||
}
|
||||
}
|
||||
8
ohos-project/AppScope/resources/base/element/string.json
Normal file
8
ohos-project/AppScope/resources/base/element/string.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "MyApplication"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
ohos-project/AppScope/resources/base/media/background.png
Normal file
BIN
ohos-project/AppScope/resources/base/media/background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
BIN
ohos-project/AppScope/resources/base/media/foreground.png
Normal file
BIN
ohos-project/AppScope/resources/base/media/foreground.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"layered-image":
|
||||
{
|
||||
"background" : "$media:background",
|
||||
"foreground" : "$media:foreground"
|
||||
}
|
||||
}
|
||||
BIN
ohos-project/AppScope/resources/base/media/oforeground.png
Normal file
BIN
ohos-project/AppScope/resources/base/media/oforeground.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
42
ohos-project/build-profile.json5
Normal file
42
ohos-project/build-profile.json5
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"app": {
|
||||
"signingConfigs": [],
|
||||
"products": [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
"targetSdkVersion": "5.0.1(13)",
|
||||
"compatibleSdkVersion": "5.0.1(13)",
|
||||
"runtimeOS": "HarmonyOS",
|
||||
"buildOption": {
|
||||
"strictMode": {
|
||||
"caseSensitiveCheck": true,
|
||||
"useNormalizedOHMUrl": true
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildModeSet": [
|
||||
{
|
||||
"name": "debug",
|
||||
},
|
||||
{
|
||||
"name": "release"
|
||||
}
|
||||
]
|
||||
},
|
||||
"modules": [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
32
ohos-project/code-linter.json5
Normal file
32
ohos-project/code-linter.json5
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"files": [
|
||||
"**/*.ets"
|
||||
],
|
||||
"ignore": [
|
||||
"**/src/ohosTest/**/*",
|
||||
"**/src/test/**/*",
|
||||
"**/src/mock/**/*",
|
||||
"**/node_modules/**/*",
|
||||
"**/oh_modules/**/*",
|
||||
"**/build/**/*",
|
||||
"**/.preview/**/*"
|
||||
],
|
||||
"ruleSet": [
|
||||
"plugin:@performance/recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"rules": {
|
||||
"@security/no-unsafe-aes": "error",
|
||||
"@security/no-unsafe-hash": "error",
|
||||
"@security/no-unsafe-mac": "warn",
|
||||
"@security/no-unsafe-dh": "error",
|
||||
"@security/no-unsafe-dsa": "error",
|
||||
"@security/no-unsafe-ecdsa": "error",
|
||||
"@security/no-unsafe-rsa-encrypt": "error",
|
||||
"@security/no-unsafe-rsa-sign": "error",
|
||||
"@security/no-unsafe-rsa-key": "error",
|
||||
"@security/no-unsafe-dsa-key": "error",
|
||||
"@security/no-unsafe-dh-key": "error",
|
||||
"@security/no-unsafe-3des": "error"
|
||||
}
|
||||
}
|
||||
6
ohos-project/entry/.gitignore
vendored
Normal file
6
ohos-project/entry/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
/node_modules
|
||||
/oh_modules
|
||||
/.preview
|
||||
/build
|
||||
/.cxx
|
||||
/.test
|
||||
44
ohos-project/entry/build-profile.json5
Normal file
44
ohos-project/entry/build-profile.json5
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
{
|
||||
"apiType": "stageMode",
|
||||
"buildOption": {
|
||||
"externalNativeOptions": {
|
||||
"path": "./src/main/cpp/CMakeLists.txt",
|
||||
"arguments": "-DCMAKE_PLATFORM_NO_VERSIONED_SONAME=1",
|
||||
"cppFlags": "",
|
||||
"abiFilters": [
|
||||
"arm64-v8a",
|
||||
"x86_64"
|
||||
]
|
||||
},
|
||||
|
||||
},
|
||||
"buildOptionSet": [
|
||||
{
|
||||
"name": "release",
|
||||
"arkOptions": {
|
||||
"obfuscation": {
|
||||
"ruleOptions": {
|
||||
"enable": false,
|
||||
"files": [
|
||||
"./obfuscation-rules.txt"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"nativeLib": {
|
||||
"debugSymbol": {
|
||||
"strip": true,
|
||||
"exclude": []
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
"targets": [
|
||||
{
|
||||
"name": "default"
|
||||
},
|
||||
{
|
||||
"name": "ohosTest",
|
||||
}
|
||||
]
|
||||
}
|
||||
6
ohos-project/entry/hvigorfile.ts
Normal file
6
ohos-project/entry/hvigorfile.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
||||
23
ohos-project/entry/obfuscation-rules.txt
Normal file
23
ohos-project/entry/obfuscation-rules.txt
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# Define project specific obfuscation rules here.
|
||||
# You can include the obfuscation configuration files in the current module's build-profile.json5.
|
||||
#
|
||||
# For more details, see
|
||||
# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5
|
||||
|
||||
# Obfuscation options:
|
||||
# -disable-obfuscation: disable all obfuscations
|
||||
# -enable-property-obfuscation: obfuscate the property names
|
||||
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
|
||||
# -compact: remove unnecessary blank spaces and all line feeds
|
||||
# -remove-log: remove all console.* statements
|
||||
# -print-namecache: print the name cache that contains the mapping from the old names to new names
|
||||
# -apply-namecache: reuse the given cache file
|
||||
|
||||
# Keep options:
|
||||
# -keep-property-name: specifies property names that you want to keep
|
||||
# -keep-global-name: specifies names that you want to keep in the global scope
|
||||
|
||||
-enable-property-obfuscation
|
||||
-enable-toplevel-obfuscation
|
||||
-enable-filename-obfuscation
|
||||
-enable-export-obfuscation
|
||||
25
ohos-project/entry/oh-package-lock.json5
Normal file
25
ohos-project/entry/oh-package-lock.json5
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"meta": {
|
||||
"stableOrder": true
|
||||
},
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"libSDL3.so@src/main/cpp/sdl": "libSDL3.so@src/main/cpp/sdl",
|
||||
"libentry.so@src/main/cpp/types/libentry": "libentry.so@src/main/cpp/types/libentry"
|
||||
},
|
||||
"packages": {
|
||||
"libSDL3.so@src/main/cpp/sdl": {
|
||||
"name": "libSDL3.so",
|
||||
"version": "1.0.0",
|
||||
"resolved": "src/main/cpp/sdl",
|
||||
"registryType": "local"
|
||||
},
|
||||
"libentry.so@src/main/cpp/types/libentry": {
|
||||
"name": "libentry.so",
|
||||
"version": "1.0.0",
|
||||
"resolved": "src/main/cpp/types/libentry",
|
||||
"registryType": "local"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
ohos-project/entry/oh-package.json5
Normal file
12
ohos-project/entry/oh-package.json5
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "entry",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"author": "",
|
||||
"license": "",
|
||||
"dependencies": {
|
||||
"libentry.so": "file:./src/main/cpp/types/libentry",
|
||||
"libSDL3.so": "file:./src/main/cpp/sdl"
|
||||
}
|
||||
}
|
||||
21
ohos-project/entry/src/main/cpp/CMakeLists.txt
Normal file
21
ohos-project/entry/src/main/cpp/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# the minimum version of CMake.
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(MyApplication10)
|
||||
|
||||
set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if(DEFINED PACKAGE_FIND_FILE)
|
||||
include(${PACKAGE_FIND_FILE})
|
||||
endif()
|
||||
|
||||
add_subdirectory(../../../../.. external/sdlbin)
|
||||
|
||||
link_directories(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
||||
add_definitions(-DVK_USE_PLATFORM_OHOS=1)
|
||||
include_directories(${NATIVERENDER_ROOT_PATH}
|
||||
${NATIVERENDER_ROOT_PATH}/include
|
||||
${SDL3_SOURCE_DIR}/include)
|
||||
|
||||
add_library(entry SHARED napi_init.cpp)
|
||||
add_dependencies(entry SDL3::SDL3-shared)
|
||||
target_link_libraries(entry PUBLIC libace_napi.z.so libSDL3.so libvulkan.so libGLESv2.so)
|
||||
167
ohos-project/entry/src/main/cpp/napi_init.cpp
Normal file
167
ohos-project/entry/src/main/cpp/napi_init.cpp
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
#include "SDL3/SDL_assert.h"
|
||||
#include "SDL3/SDL_init.h"
|
||||
#include "SDL3/SDL_messagebox.h"
|
||||
#include "SDL3/SDL_render.h"
|
||||
#include "SDL3/SDL_timer.h"
|
||||
#include "SDL3/SDL_video.h"
|
||||
#include "SDL3/SDL_vulkan.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "SDL3/SDL_log.h"
|
||||
#include "SDL3/SDL_hints.h"
|
||||
#include <GLES2/gl2.h>
|
||||
#include <stdlib.h>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
static napi_value Add(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 2;
|
||||
napi_value args[2] = {nullptr};
|
||||
|
||||
napi_get_cb_info(env, info, &argc, args , nullptr, nullptr);
|
||||
|
||||
napi_valuetype valuetype0;
|
||||
napi_typeof(env, args[0], &valuetype0);
|
||||
|
||||
napi_valuetype valuetype1;
|
||||
napi_typeof(env, args[1], &valuetype1);
|
||||
|
||||
double value0;
|
||||
napi_get_value_double(env, args[0], &value0);
|
||||
|
||||
double value1;
|
||||
napi_get_value_double(env, args[1], &value1);
|
||||
|
||||
napi_value sum;
|
||||
napi_create_double(env, value0 + value1, &sum);
|
||||
|
||||
SDL_Log("Add invoke!");
|
||||
|
||||
return sum;
|
||||
|
||||
}
|
||||
|
||||
EXTERN_C_START
|
||||
static napi_value Init(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor desc[] = {
|
||||
{ "add", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr }
|
||||
};
|
||||
napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
|
||||
return exports;
|
||||
}
|
||||
|
||||
float vtxdata[] = {
|
||||
-0.5f, -0.5f, 0.f,
|
||||
0.5f, -0.5f, 0.0f,
|
||||
0.0f, 0.5f, 0.0f
|
||||
};
|
||||
|
||||
float vtxdata2[] = {
|
||||
0.f, 0.f, 1.f,
|
||||
0.f, 1.f, 0.f,
|
||||
1.f, 0.f, 0.f
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
SDL_SetHint(SDL_HINT_EGL_LIBRARY, "libEGL.so");
|
||||
SDL_SetHint(SDL_HINT_OPENGL_LIBRARY, "libGLESv2.so");
|
||||
SDL_SetHint(SDL_HINT_OPENGL_ES_DRIVER, "libGLESv2.so");
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
SDL_Log("Main func invoke !!!");
|
||||
// SDL_GL_LoadLibrary("libGLESv2.so");
|
||||
SDL_Log("sdl error: %s", SDL_GetError());
|
||||
SDL_Window* win = SDL_CreateWindow("test", 1024, 1024, SDL_WINDOW_OPENGL);
|
||||
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "SDL Application", "test!", win);
|
||||
|
||||
auto context = SDL_GL_CreateContext(win);
|
||||
SDL_GL_MakeCurrent(win, context);
|
||||
|
||||
int frgshader = ((PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader"))(GL_FRAGMENT_SHADER);
|
||||
int vexshader = ((PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader"))(GL_VERTEX_SHADER);
|
||||
|
||||
auto frag = "varying vec4 v_color;void main() {gl_FragColor = v_color;}";
|
||||
((PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource"))(frgshader, 1, &frag, nullptr);
|
||||
((PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader"))(frgshader);
|
||||
int status = 1;
|
||||
((PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv"))(frgshader, GL_COMPILE_STATUS, &status);
|
||||
int status2 = 1;
|
||||
((PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv"))(frgshader, GL_INFO_LOG_LENGTH, &status2);
|
||||
std::string log(status2, '\0');
|
||||
((PFNGLGETSHADERINFOLOGPROC)SDL_GL_GetProcAddress("glGetShaderInfoLog"))(frgshader, status2, nullptr, (char*)log.c_str());
|
||||
|
||||
SDL_Log("test: %d %d %s", status, status2, log.c_str());
|
||||
|
||||
auto vert = "attribute vec3 pos;attribute vec3 color;varying vec4 v_color;void main() {gl_Position=vec4(pos,1.0);v_color=vec4(color, 1.0);}";
|
||||
((PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource"))(vexshader, 1, &vert, nullptr);
|
||||
((PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader"))(vexshader);
|
||||
((PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv"))(vexshader, GL_COMPILE_STATUS, &status);
|
||||
((PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv"))(vexshader, GL_INFO_LOG_LENGTH, &status2);
|
||||
std::string log2(status2, '\0');
|
||||
((PFNGLGETSHADERINFOLOGPROC)SDL_GL_GetProcAddress("glGetShaderInfoLog"))(vexshader, status2, nullptr, (char*)log2.c_str());
|
||||
|
||||
SDL_Log("test: %d %d %s", status, status2, log2.c_str());
|
||||
|
||||
auto prog = ((PFNGLCREATEPROGRAMPROC)SDL_GL_GetProcAddress("glCreateProgram"))();
|
||||
((PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader"))(prog, vexshader);
|
||||
((PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader"))(prog, frgshader);
|
||||
((PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram"))(prog);
|
||||
((PFNGLGETPROGRAMIVPROC)SDL_GL_GetProcAddress("glGetProgramiv"))(prog, GL_LINK_STATUS, &status);
|
||||
SDL_Log("link: %d", status);
|
||||
|
||||
((PFNGLDELETESHADERPROC)SDL_GL_GetProcAddress("glDeleteShader"))(vexshader);
|
||||
((PFNGLDELETESHADERPROC)SDL_GL_GetProcAddress("glDeleteShader"))(frgshader);
|
||||
|
||||
while (true) {
|
||||
int w, h;
|
||||
SDL_GetWindowSize(win, &w, &h);
|
||||
|
||||
((PFNGLVIEWPORTPROC)SDL_GL_GetProcAddress("glViewport"))(0, 0, w, h);
|
||||
((PFNGLCLEARPROC)SDL_GL_GetProcAddress("glClear"))(GL_COLOR_BUFFER_BIT);
|
||||
((PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram"))(prog);
|
||||
for (int i = 0; i < 9; i++) {
|
||||
vtxdata2[i] += 0.01f;
|
||||
if (vtxdata2[i] >= 1.f) {
|
||||
vtxdata2[i] = 0.f;
|
||||
}
|
||||
}
|
||||
((PFNGLVERTEXATTRIBPOINTERPROC)SDL_GL_GetProcAddress("glVertexAttribPointer"))(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)vtxdata);
|
||||
((PFNGLENABLEVERTEXATTRIBARRAYPROC)SDL_GL_GetProcAddress("glEnableVertexAttribArray"))(0);
|
||||
((PFNGLVERTEXATTRIBPOINTERPROC)SDL_GL_GetProcAddress("glVertexAttribPointer"))(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)vtxdata2);
|
||||
((PFNGLENABLEVERTEXATTRIBARRAYPROC)SDL_GL_GetProcAddress("glEnableVertexAttribArray"))(1);
|
||||
|
||||
((PFNGLDRAWARRAYSPROC)SDL_GL_GetProcAddress("glDrawArrays"))(GL_TRIANGLES, 0, 3);
|
||||
|
||||
SDL_GL_SwapWindow(win);
|
||||
}
|
||||
|
||||
SDL_Log("glversion: %s", ((PFNGLGETSTRINGPROC)SDL_GL_GetProcAddress("glGetString"))(GL_VERSION));
|
||||
|
||||
SDL_GL_DestroyContext(context);
|
||||
|
||||
SDL_DestroyWindow(win);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXTERN_C_END
|
||||
|
||||
static napi_module demoModule = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = Init,
|
||||
.nm_modname = "entry",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = { 0 },
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void RegisterEntryModule(void)
|
||||
{
|
||||
napi_module_register(&demoModule);
|
||||
}
|
||||
2
ohos-project/entry/src/main/cpp/sdl/Index.d.ts
vendored
Normal file
2
ohos-project/entry/src/main/cpp/sdl/Index.d.ts
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export const sdlCallbackInit: (d) => void;
|
||||
export const sdlLaunchMain: (lib: string, func: string) => number;
|
||||
6
ohos-project/entry/src/main/cpp/sdl/oh-package.json5
Normal file
6
ohos-project/entry/src/main/cpp/sdl/oh-package.json5
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "libSDL3.so",
|
||||
"types": "./Index.d.ts",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information."
|
||||
}
|
||||
1
ohos-project/entry/src/main/cpp/types/libentry/Index.d.ts
vendored
Normal file
1
ohos-project/entry/src/main/cpp/types/libentry/Index.d.ts
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export const add: (a: number, b: number) => number;
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "libentry.so",
|
||||
"types": "./Index.d.ts",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information."
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
import { AbilityConstant, ConfigurationConstant, UIAbility, Want } from '@kit.AbilityKit';
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { window } from '@kit.ArkUI';
|
||||
import { KeyboardAvoidMode } from '@ohos.arkui.UIContext';
|
||||
|
||||
const DOMAIN = 0x0000;
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
|
||||
this.context.getApplicationContext().setColorMode(ConfigurationConstant.ColorMode.COLOR_MODE_NOT_SET);
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onCreate');
|
||||
}
|
||||
|
||||
onDestroy(): void {
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onDestroy');
|
||||
}
|
||||
|
||||
onWindowStageCreate(windowStage: window.WindowStage): void {
|
||||
// Main window is created, set main page for this ability
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
|
||||
|
||||
windowStage.loadContent('pages/Index', (err) => {
|
||||
if (err.code) {
|
||||
hilog.error(DOMAIN, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
hilog.info(DOMAIN, 'testTag', 'Succeeded in loading the content.');
|
||||
windowStage.getMainWindowSync().getUIContext().setKeyboardAvoidMode(KeyboardAvoidMode.OFFSET);
|
||||
windowStage.getMainWindowSync().setWindowLayoutFullScreen(true)
|
||||
});
|
||||
}
|
||||
|
||||
onWindowStageDestroy(): void {
|
||||
// Main window is destroyed, release UI related resources
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
|
||||
}
|
||||
|
||||
onForeground(): void {
|
||||
// Ability has brought to foreground
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onForeground');
|
||||
}
|
||||
|
||||
onBackground(): void {
|
||||
// Ability has back to background
|
||||
hilog.info(DOMAIN, 'testTag', '%{public}s', 'Ability onBackground');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
|
||||
|
||||
const DOMAIN = 0x0000;
|
||||
|
||||
export default class EntryBackupAbility extends BackupExtensionAbility {
|
||||
async onBackup() {
|
||||
hilog.info(DOMAIN, 'testTag', 'onBackup ok');
|
||||
await Promise.resolve();
|
||||
}
|
||||
|
||||
async onRestore(bundleVersion: BundleVersion) {
|
||||
hilog.info(DOMAIN, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion));
|
||||
await Promise.resolve();
|
||||
}
|
||||
}
|
||||
51
ohos-project/entry/src/main/ets/pages/Index.ets
Normal file
51
ohos-project/entry/src/main/ets/pages/Index.ets
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import sdltest from 'libSDL3.so';
|
||||
import { intl } from '@kit.LocalizationKit';
|
||||
import { promptAction } from '@kit.ArkUI';
|
||||
|
||||
const DOMAIN = 0x0000;
|
||||
|
||||
export class ArkNapiCallback {
|
||||
onMainLaunch() {
|
||||
sdltest.sdlLaunchMain("libentry.so", "main")
|
||||
}
|
||||
showDialog(title: string, message: string) {
|
||||
promptAction.showDialog({title: title, message: message, buttons: [{text: 'Ok', color: '#999999'}]});
|
||||
}
|
||||
fetchLocale(): string {
|
||||
let locale = new intl.Locale();
|
||||
return locale.toString();
|
||||
}
|
||||
test(): number {
|
||||
hilog.info(DOMAIN, 'testTag', 'Call from native !!!');
|
||||
focusControl.requestFocus("inputHandler")
|
||||
let locale = new intl.Locale();
|
||||
hilog.info(DOMAIN, 'testTag', locale.toString());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
let callbackRef: ArkNapiCallback = new ArkNapiCallback()
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
aboutToAppear(): void {
|
||||
sdltest.sdlCallbackInit(callbackRef)
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
XComponent({ id: 'mainView', type: 'surface', libraryname: 'SDL3' })
|
||||
.id('mainView')
|
||||
TextInput().id('inputHandler').onChange((value: string) => {
|
||||
hilog.info(DOMAIN, 'testTag', value)
|
||||
}).onSubmit(() => {
|
||||
hilog.info(DOMAIN, 'testTag', "submit")
|
||||
})
|
||||
|
||||
}
|
||||
.alignItems(HorizontalAlign.End)
|
||||
.justifyContent(FlexAlign.End)
|
||||
}
|
||||
}
|
||||
55
ohos-project/entry/src/main/module.json5
Normal file
55
ohos-project/entry/src/main/module.json5
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
"type": "entry",
|
||||
"description": "$string:module_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"requestPermissions": [
|
||||
],
|
||||
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:layered_image",
|
||||
"label": "$string:EntryAbility_label",
|
||||
"startWindowIcon": "$media:startIcon",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"extensionAbilities": [
|
||||
{
|
||||
"name": "EntryBackupAbility",
|
||||
"srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets",
|
||||
"type": "backup",
|
||||
"exported": false,
|
||||
"metadata": [
|
||||
{
|
||||
"name": "ohos.extension.backup",
|
||||
"resource": "$profile:backup_config"
|
||||
}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"float": [
|
||||
{
|
||||
"name": "page_text_font_size",
|
||||
"value": "50fp"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "SDL Demo"
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
ohos-project/entry/src/main/resources/base/media/background.png
Normal file
BIN
ohos-project/entry/src/main/resources/base/media/background.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 90 KiB |
BIN
ohos-project/entry/src/main/resources/base/media/foreground.png
Normal file
BIN
ohos-project/entry/src/main/resources/base/media/foreground.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"layered-image":
|
||||
{
|
||||
"background" : "$media:background",
|
||||
"foreground" : "$media:foreground"
|
||||
}
|
||||
}
|
||||
BIN
ohos-project/entry/src/main/resources/base/media/startIcon.png
Normal file
BIN
ohos-project/entry/src/main/resources/base/media/startIcon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"allowToBackupRestore": true
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#000000"
|
||||
}
|
||||
]
|
||||
}
|
||||
7
ohos-project/entry/src/mock/Libentry.mock.ets
Normal file
7
ohos-project/entry/src/mock/Libentry.mock.ets
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
const NativeMock: Record<string, Object> = {
|
||||
'add': (a: number, b: number) => {
|
||||
return a + b;
|
||||
},
|
||||
};
|
||||
|
||||
export default NativeMock;
|
||||
5
ohos-project/entry/src/mock/mock-config.json5
Normal file
5
ohos-project/entry/src/mock/mock-config.json5
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"libentry.so": {
|
||||
"source": "src/mock/Libentry.mock.ets"
|
||||
}
|
||||
}
|
||||
35
ohos-project/entry/src/ohosTest/ets/test/Ability.test.ets
Normal file
35
ohos-project/entry/src/ohosTest/ets/test/Ability.test.ets
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
||||
|
||||
export default function abilityTest() {
|
||||
describe('ActsAbilityTest', () => {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
beforeAll(() => {
|
||||
// Presets an action, which is performed only once before all test cases of the test suite start.
|
||||
// This API supports only one parameter: preset action function.
|
||||
})
|
||||
beforeEach(() => {
|
||||
// Presets an action, which is performed before each unit test case starts.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: preset action function.
|
||||
})
|
||||
afterEach(() => {
|
||||
// Presets a clear action, which is performed after each unit test case ends.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: clear action function.
|
||||
})
|
||||
afterAll(() => {
|
||||
// Presets a clear action, which is performed after all test cases of the test suite end.
|
||||
// This API supports only one parameter: clear action function.
|
||||
})
|
||||
it('assertContain', 0, () => {
|
||||
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
|
||||
let a = 'abc';
|
||||
let b = 'b';
|
||||
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
|
||||
expect(a).assertContain(b);
|
||||
expect(a).assertEqual(a);
|
||||
})
|
||||
})
|
||||
}
|
||||
5
ohos-project/entry/src/ohosTest/ets/test/List.test.ets
Normal file
5
ohos-project/entry/src/ohosTest/ets/test/List.test.ets
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import abilityTest from './Ability.test';
|
||||
|
||||
export default function testsuite() {
|
||||
abilityTest();
|
||||
}
|
||||
13
ohos-project/entry/src/ohosTest/module.json5
Normal file
13
ohos-project/entry/src/ohosTest/module.json5
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"module": {
|
||||
"name": "entry_test",
|
||||
"type": "feature",
|
||||
"deviceTypes": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false
|
||||
}
|
||||
}
|
||||
5
ohos-project/entry/src/test/List.test.ets
Normal file
5
ohos-project/entry/src/test/List.test.ets
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import localUnitTest from './LocalUnit.test';
|
||||
|
||||
export default function testsuite() {
|
||||
localUnitTest();
|
||||
}
|
||||
33
ohos-project/entry/src/test/LocalUnit.test.ets
Normal file
33
ohos-project/entry/src/test/LocalUnit.test.ets
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
||||
|
||||
export default function localUnitTest() {
|
||||
describe('localUnitTest', () => {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
beforeAll(() => {
|
||||
// Presets an action, which is performed only once before all test cases of the test suite start.
|
||||
// This API supports only one parameter: preset action function.
|
||||
});
|
||||
beforeEach(() => {
|
||||
// Presets an action, which is performed before each unit test case starts.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: preset action function.
|
||||
});
|
||||
afterEach(() => {
|
||||
// Presets a clear action, which is performed after each unit test case ends.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: clear action function.
|
||||
});
|
||||
afterAll(() => {
|
||||
// Presets a clear action, which is performed after all test cases of the test suite end.
|
||||
// This API supports only one parameter: clear action function.
|
||||
});
|
||||
it('assertContain', 0, () => {
|
||||
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
||||
let a = 'abc';
|
||||
let b = 'b';
|
||||
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
|
||||
expect(a).assertContain(b);
|
||||
expect(a).assertEqual(a);
|
||||
});
|
||||
});
|
||||
}
|
||||
22
ohos-project/hvigor/hvigor-config.json5
Normal file
22
ohos-project/hvigor/hvigor-config.json5
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"modelVersion": "5.0.5",
|
||||
"dependencies": {
|
||||
},
|
||||
"execution": {
|
||||
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */
|
||||
// "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
|
||||
// "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
|
||||
// "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */
|
||||
// "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */
|
||||
},
|
||||
"logging": {
|
||||
// "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
|
||||
},
|
||||
"debugging": {
|
||||
// "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */
|
||||
},
|
||||
"nodeOptions": {
|
||||
// "maxOldSpaceSize": 8192 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process. Default: 8192*/
|
||||
// "exposeGC": true /* Enable to trigger garbage collection explicitly. Default: true*/
|
||||
}
|
||||
}
|
||||
6
ohos-project/hvigorfile.ts
Normal file
6
ohos-project/hvigorfile.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import { appTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
||||
27
ohos-project/oh-package-lock.json5
Normal file
27
ohos-project/oh-package-lock.json5
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"meta": {
|
||||
"stableOrder": true
|
||||
},
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0",
|
||||
"@ohos/hypium@1.0.21": "@ohos/hypium@1.0.21"
|
||||
},
|
||||
"packages": {
|
||||
"@ohos/hamock@1.0.0": {
|
||||
"name": "@ohos/hamock",
|
||||
"version": "1.0.0",
|
||||
"integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==",
|
||||
"resolved": "https://repo.harmonyos.com/ohpm/@ohos/hamock/-/hamock-1.0.0.har",
|
||||
"registryType": "ohpm"
|
||||
},
|
||||
"@ohos/hypium@1.0.21": {
|
||||
"name": "@ohos/hypium",
|
||||
"version": "1.0.21",
|
||||
"integrity": "sha512-iyKGMXxE+9PpCkqEwu0VykN/7hNpb+QOeIuHwkmZnxOpI+dFZt6yhPB7k89EgV1MiSK/ieV/hMjr5Z2mWwRfMQ==",
|
||||
"resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.21.har",
|
||||
"registryType": "ohpm"
|
||||
}
|
||||
}
|
||||
}
|
||||
10
ohos-project/oh-package.json5
Normal file
10
ohos-project/oh-package.json5
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"modelVersion": "5.0.5",
|
||||
"description": "Please describe the basic information.",
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ohos/hypium": "1.0.21",
|
||||
"@ohos/hamock": "1.0.0"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue