mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-01 19:49:11 +08:00
improve assets build script to support any file extensions in data folder.
This commit is contained in:
parent
369c68dfb7
commit
db616f27fe
@ -118,6 +118,8 @@
|
||||
#include "assets/inc/ui/scroll_view_v.data"
|
||||
#include "assets/inc/xml/test.data"
|
||||
#include "assets/inc/data/test.data"
|
||||
#include "assets/inc/data/app.data"
|
||||
#include "assets/inc/data/abc.data"
|
||||
#ifdef WITH_STB_IMAGE
|
||||
#include "assets/inc/images/ani6.res"
|
||||
#include "assets/inc/images/checked.res"
|
||||
@ -627,6 +629,8 @@ ret_t assets_init(void) {
|
||||
assets_manager_add(rm, style_dialog_warn);
|
||||
assets_manager_add(rm, font_default);
|
||||
assets_manager_add(rm, data_test);
|
||||
assets_manager_add(rm, data_app);
|
||||
assets_manager_add(rm, data_abc);
|
||||
#ifdef WITH_VGCANVAS
|
||||
assets_manager_add(rm, image_pointer_4);
|
||||
assets_manager_add(rm, image_china);
|
||||
|
4
demos/assets/inc/data/abc.data
Normal file
4
demos/assets/inc/data/abc.data
Normal file
@ -0,0 +1,4 @@
|
||||
const unsigned char data_abc[] = {
|
||||
0x08,0x00,0x00,0x01,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x61,0x62,0x63,0x2e,0x61,0x6e,0x79,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x74,0x65,0x73,0x74,0x0a,0x00,0x00,0x00,0x00,};/*53*/
|
5
demos/assets/inc/data/app.data
Normal file
5
demos/assets/inc/data/app.data
Normal file
@ -0,0 +1,5 @@
|
||||
const unsigned char data_app[] = {
|
||||
0x08,0x00,0x03,0x01,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x61,0x70,0x70,0x2e,0x6a,0x73,0x6f,0x6e,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x7b,0x0a,0x20,0x20,0x22,0x6e,0x61,0x6d,0x65,0x22,0x3a,0x22,0x66,0x6f,0x72,0x20,
|
||||
0x74,0x65,0x73,0x74,0x22,0x0a,0x7d,0x0a,0x00,0x00,0x00,0x00,};/*72*/
|
@ -1,4 +1,4 @@
|
||||
const unsigned char data_test[] = {
|
||||
0x08,0x00,0x00,0x01,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x74,0x65,0x73,0x74,0x00,0x64,0x61,0x74,
|
||||
0x61,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x08,0x00,0x04,0x01,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x74,0x65,0x73,0x74,0x2e,0x64,0x61,0x74,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x61,0x62,0x63,0x64,0x0a,0x00,0x00,0x00,0x00,};/*53*/
|
||||
|
1
demos/assets/raw/data/abc.any
Normal file
1
demos/assets/raw/data/abc.any
Normal file
@ -0,0 +1 @@
|
||||
test
|
3
demos/assets/raw/data/app.json
Normal file
3
demos/assets/raw/data/app.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"name":"for test"
|
||||
}
|
@ -33,6 +33,7 @@
|
||||
* [如何设置字体的全局缩放比例](how_to_scale_font.md)
|
||||
* [如何实现"back"键和"home"键](how_to_impl_back_and_home_key.md)
|
||||
* [如何实现自定义的软键盘](how_to_impl_custom_soft_keyboard.md)
|
||||
* [如何编译Windows 32位版本](how_to_build_windows_32bit_version.md)
|
||||
|
||||
### 3.内部原理
|
||||
* [AWTK脚本绑定原理](script_binding.md)
|
||||
|
@ -112,6 +112,10 @@ widget_t* win = window_open(name);
|
||||
|
||||
资源名称一般就是资源的文件名,不带文件扩展名。比如图片名为test.png,那资源名称就是test,如果因为某种原因,把test.png换成了test.jpg,对代码并无影响。
|
||||
|
||||
> 对于DATA类型的资源,由于其扩展名不固定,所以需要带扩展名才能访问。
|
||||
>
|
||||
> 比如资源文件名为"app.json",不能用"app"访问,而是用"app.json"才能访问。
|
||||
|
||||
对于图片和UI资源名称,AWTK还支持一种高级用法。想想下面几种情况:
|
||||
|
||||
* 需要支持不同的分辨率。而在不同分辨率里,要使用不同的背景图片。
|
||||
@ -169,4 +173,4 @@ widget_t* win = window_open(name);
|
||||
|
||||
依次查找flag\_US和flag\_none两个图片。
|
||||
|
||||
> 变量名可以使用[system\_info中的成员变量](https://github.com/zlgopen/awtk/blob/master/docs/manual/system_info_t.md)
|
||||
> 变量名可以使用[system\_info中的成员变量](https://github.com/zlgopen/awtk/blob/master/docs/manual/system_info_t.md)
|
||||
|
@ -1,4 +1,8 @@
|
||||
# 最新动态
|
||||
* 2019/03/20
|
||||
* 支持编译Windows 32 位版本(感谢陈谭提供补丁)
|
||||
* 修改资源生成脚本,对于data数据,不限制文件名(DATA类型的资源需带扩展名才能访问)。
|
||||
|
||||
* 2019/03/19
|
||||
* 增加window\_close\_force函数。
|
||||
* 修改window\_manager\_close\_window多次关闭同一个窗口的问题。
|
||||
|
29
docs/how_to_build_windows_32bit_version.md
Normal file
29
docs/how_to_build_windows_32bit_version.md
Normal file
@ -0,0 +1,29 @@
|
||||
# 如何编译Windows 32位版本
|
||||
|
||||
* 1.在文件awtk\_config.py中设置TARGET\_ARCH为'x86':
|
||||
|
||||
将:
|
||||
|
||||
```
|
||||
#TARGET_ARCH='x86'
|
||||
```
|
||||
|
||||
修改为:
|
||||
|
||||
```
|
||||
TARGET_ARCH='x86'
|
||||
```
|
||||
|
||||
* 2.对于XP,如果OpenGL渲染不正常。可以使用AGGE(或BGFX)试试。
|
||||
|
||||
将:
|
||||
|
||||
```
|
||||
#NANOVG_BACKEND='AGGE'
|
||||
```
|
||||
|
||||
修改为:
|
||||
|
||||
```
|
||||
NANOVG_BACKEND='AGGE'
|
||||
```
|
@ -33,6 +33,7 @@
|
||||
* [如何设置字体的全局缩放比例](how_to_scale_font.md)
|
||||
* [如何实现"back"键和"home"键](how_to_impl_back_and_home_key.md)
|
||||
* [如何实现自定义的软键盘](how_to_impl_custom_soft_keyboard.md)
|
||||
* [如何编译Windows 32位版本](how_to_build_windows_32bit_version.md)
|
||||
|
||||
### 3.内部原理
|
||||
* [AWTK脚本绑定原理](script_binding.md)
|
||||
|
@ -260,11 +260,7 @@ asset_info_t* assets_manager_load(assets_manager_t* rm, asset_type_t type, const
|
||||
break;
|
||||
}
|
||||
case ASSET_TYPE_DATA: {
|
||||
if ((info = try_load_assets(res_root, name, ".bin", type, ASSET_TYPE_DATA)) != NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((info = try_load_assets(res_root, name, ".dat", type, ASSET_TYPE_DATA)) != NULL) {
|
||||
if ((info = try_load_assets(res_root, name, "", type, ASSET_TYPE_DATA)) != NULL) {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -98,6 +98,18 @@ typedef enum _asset_font_type_t {
|
||||
ASSET_TYPE_FONT_BMP
|
||||
} asset_font_type_t;
|
||||
|
||||
/**
|
||||
* @enum asset_data_type_t
|
||||
* 字体资源类型定义。
|
||||
*/
|
||||
typedef enum _asset_data_type_t {
|
||||
ASSET_TYPE_DATA_NONE,
|
||||
ASSET_TYPE_DATA_TEXT,
|
||||
ASSET_TYPE_DATA_BIN,
|
||||
ASSET_TYPE_DATA_JSON,
|
||||
ASSET_TYPE_DATA_DAT
|
||||
} asset_data_type_t;
|
||||
|
||||
/**
|
||||
* @enum asset_script_type_t
|
||||
* 脚本资源类型定义。
|
||||
@ -120,7 +132,7 @@ typedef enum _asset_image_type_t {
|
||||
ASSET_TYPE_IMAGE_PNG,
|
||||
ASSET_TYPE_IMAGE_JPG,
|
||||
ASSET_TYPE_IMAGE_BSVG,
|
||||
ASSET_TYPE_IMAGE_GIF /*not supported yet*/
|
||||
ASSET_TYPE_IMAGE_GIF
|
||||
} asset_image_type_t;
|
||||
|
||||
/**
|
||||
|
@ -458,7 +458,7 @@ int tk_sscanf(const char* str, const char* format, ...) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret_t filename_to_name(const char* filename, char* str, uint32_t size) {
|
||||
ret_t filename_to_name_ex(const char* filename, char* str, uint32_t size, bool_t remove_extname) {
|
||||
char* p = NULL;
|
||||
const char* name = filename;
|
||||
return_value_if_fail(filename != NULL && str != NULL, RET_BAD_PARAMS);
|
||||
@ -475,14 +475,21 @@ ret_t filename_to_name(const char* filename, char* str, uint32_t size) {
|
||||
}
|
||||
|
||||
tk_strncpy(str, name, size - 1);
|
||||
p = strchr(str, '.');
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
|
||||
if (remove_extname) {
|
||||
p = strchr(str, '.');
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t filename_to_name(const char* filename, char* str, uint32_t size) {
|
||||
return filename_to_name_ex(filename, str, size, TRUE);
|
||||
}
|
||||
|
||||
#define INCLUDE_XML "<?include"
|
||||
|
||||
ret_t xml_file_expand(const char* filename, str_t* s, const char* data) {
|
||||
|
@ -59,6 +59,7 @@ void* tk_pixel_copy(void* dst, const void* src, uint32_t size, uint8_t bpp);
|
||||
int tk_snprintf(char* str, size_t size, const char* format, ...);
|
||||
int tk_sscanf(const char* str, const char* format, ...);
|
||||
ret_t filename_to_name(const char* filename, char* str, uint32_t size);
|
||||
ret_t filename_to_name_ex(const char* filename, char* str, uint32_t size, bool_t remove_extname);
|
||||
|
||||
/*expand include process instruction to file content: <?include filename="view_me.inc" ?>*/
|
||||
ret_t xml_file_expand_read(const char* filename, str_t* s);
|
||||
|
@ -21,6 +21,7 @@ INCLUDE_PATH = [TK_ROOT,
|
||||
|
||||
env['CPPPATH'] = INCLUDE_PATH
|
||||
env['LIBS'] = ['assets', 'image_gen', 'theme_gen', 'font_gen', 'str_gen', 'common'] + env['LIBS']
|
||||
env['LINKFLAGS'] = env['OS_SUBSYSTEM_CONSOLE'] + env['LINKFLAGS'];
|
||||
|
||||
SOURCES = [
|
||||
os.path.join(GTEST_ROOT, 'src/gtest-all.cc'),
|
||||
|
@ -73,20 +73,6 @@ TEST(AssetsManager, clearCache) {
|
||||
assets_manager_destroy(rm);
|
||||
}
|
||||
|
||||
TEST(AssetsManager, data) {
|
||||
const asset_info_t* r = NULL;
|
||||
assets_manager_t* rm = assets_manager();
|
||||
|
||||
#ifdef WITH_FS_RES
|
||||
r = assets_manager_ref(rm, ASSET_TYPE_DATA, "test");
|
||||
ASSERT_EQ(r != NULL, true);
|
||||
assets_manager_unref(rm, r);
|
||||
#else
|
||||
r = assets_manager_find_in_cache(rm, ASSET_TYPE_DATA, "test");
|
||||
ASSERT_EQ(r != NULL, true);
|
||||
#endif /*WITH_FS_RES*/
|
||||
}
|
||||
|
||||
TEST(AssetsManager, xml) {
|
||||
const asset_info_t* r = NULL;
|
||||
assets_manager_t* rm = assets_manager();
|
||||
@ -99,3 +85,43 @@ TEST(AssetsManager, xml) {
|
||||
ASSERT_EQ(r != NULL, true);
|
||||
#endif /*WITH_FS_RES*/
|
||||
}
|
||||
|
||||
TEST(AssetsManager, data) {
|
||||
const asset_info_t* r = NULL;
|
||||
assets_manager_t* rm = assets_manager();
|
||||
|
||||
#ifdef WITH_FS_RES
|
||||
r = assets_manager_ref(rm, ASSET_TYPE_DATA, "test.dat");
|
||||
ASSERT_EQ(r != NULL, true);
|
||||
assets_manager_unref(rm, r);
|
||||
#else
|
||||
r = assets_manager_find_in_cache(rm, ASSET_TYPE_DATA, "test.dat");
|
||||
ASSERT_EQ(r != NULL, true);
|
||||
#endif /*WITH_FS_RES*/
|
||||
}
|
||||
|
||||
TEST(AssetsManager, json) {
|
||||
const asset_info_t* r = NULL;
|
||||
assets_manager_t* rm = assets_manager();
|
||||
#ifdef WITH_FS_RES
|
||||
r = assets_manager_ref(rm, ASSET_TYPE_DATA, "app.json");
|
||||
ASSERT_EQ(r != NULL, true);
|
||||
assets_manager_unref(rm, r);
|
||||
#else
|
||||
r = assets_manager_find_in_cache(rm, ASSET_TYPE_DATA, "app.json");
|
||||
ASSERT_EQ(r != NULL, true);
|
||||
#endif /*WITH_FS_RES*/
|
||||
}
|
||||
|
||||
TEST(AssetsManager, any) {
|
||||
const asset_info_t* r = NULL;
|
||||
assets_manager_t* rm = assets_manager();
|
||||
#ifdef WITH_FS_RES
|
||||
r = assets_manager_ref(rm, ASSET_TYPE_DATA, "abc.any");
|
||||
ASSERT_EQ(r != NULL, true);
|
||||
assets_manager_unref(rm, r);
|
||||
#else
|
||||
r = assets_manager_find_in_cache(rm, ASSET_TYPE_DATA, "abc.any");
|
||||
ASSERT_EQ(r != NULL, true);
|
||||
#endif /*WITH_FS_RES*/
|
||||
}
|
||||
|
@ -174,6 +174,16 @@ TEST(Utils, filename_to_name) {
|
||||
ASSERT_EQ(string(name), string("test"));
|
||||
}
|
||||
|
||||
TEST(Utils, filename_to_name_ex) {
|
||||
char name[TK_NAME_LEN + 1];
|
||||
|
||||
filename_to_name_ex("test.png", name, TK_NAME_LEN, FALSE);
|
||||
ASSERT_EQ(string(name), string("test.png"));
|
||||
|
||||
filename_to_name_ex("/a/test.png", name, TK_NAME_LEN, TRUE);
|
||||
ASSERT_EQ(string(name), string("test"));
|
||||
}
|
||||
|
||||
TEST(Utils, tk_skip_to_num) {
|
||||
ASSERT_EQ(tk_atoi(tk_skip_to_num("123")), 123);
|
||||
ASSERT_EQ(tk_atoi(tk_skip_to_num("abc123")), 123);
|
||||
|
@ -82,11 +82,24 @@ int unique(wchar_t* str, int size) {
|
||||
return d - str;
|
||||
}
|
||||
|
||||
static const char* to_var_name(char var_name[2 * TK_NAME_LEN + 1], const char* prefix,
|
||||
const char* name) {
|
||||
tk_snprintf(var_name, 2 * TK_NAME_LEN, "%s_%s", prefix ? prefix : "", name);
|
||||
|
||||
char* p = strrchr(var_name, '.');
|
||||
if (p != NULL) {
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
return var_name;
|
||||
}
|
||||
|
||||
ret_t output_c_source(const char* filename, const char* prefix, const char* name, uint8_t* buff,
|
||||
uint32_t size) {
|
||||
uint32_t i = 0;
|
||||
FILE* fp = NULL;
|
||||
char str[TK_NAME_LEN + 1];
|
||||
char var_name[2 * TK_NAME_LEN + 1];
|
||||
return_value_if_fail(filename != NULL && buff != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (name == NULL) {
|
||||
@ -94,9 +107,11 @@ ret_t output_c_source(const char* filename, const char* prefix, const char* name
|
||||
name = str;
|
||||
}
|
||||
|
||||
log_debug("filename=%s prefix=%s name=%s size=%u\n", filename, prefix, name, size);
|
||||
|
||||
fp = fopen(filename, "wb+");
|
||||
if (fp != NULL) {
|
||||
fprintf(fp, "const unsigned char %s_%s[] = {", prefix ? prefix : "", name);
|
||||
fprintf(fp, "const unsigned char %s[] = {", to_var_name(var_name, prefix, name));
|
||||
for (i = 0; i < size; i++) {
|
||||
if ((i % 20) == 0) {
|
||||
fprintf(fp, "\n");
|
||||
@ -113,8 +128,8 @@ ret_t output_c_source(const char* filename, const char* prefix, const char* name
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
ret_t output_res_c_source(const char* filename, uint16_t type, uint16_t subtype, uint8_t* buff,
|
||||
uint32_t size) {
|
||||
ret_t output_res_c_source_ex(const char* filename, uint16_t type, uint16_t subtype, uint8_t* buff,
|
||||
uint32_t size, const char* name) {
|
||||
asset_info_t* res = NULL;
|
||||
uint32_t total_size = sizeof(asset_info_t) + size;
|
||||
const key_type_value_t* kv = asset_type_find_by_value(type);
|
||||
@ -129,13 +144,26 @@ ret_t output_res_c_source(const char* filename, uint16_t type, uint16_t subtype,
|
||||
res->refcount = 0;
|
||||
res->subtype = subtype;
|
||||
memcpy(res->data, buff, size);
|
||||
filename_to_name(filename, res->name, sizeof(res->name));
|
||||
if (name != NULL) {
|
||||
tk_strncpy(res->name, name, sizeof(res->name) - 1);
|
||||
} else {
|
||||
if (type == ASSET_TYPE_DATA) {
|
||||
filename_to_name_ex(filename, res->name, sizeof(res->name), FALSE);
|
||||
} else {
|
||||
filename_to_name(filename, res->name, sizeof(res->name));
|
||||
}
|
||||
}
|
||||
output_c_source(filename, kv->name, res->name, (uint8_t*)res, total_size);
|
||||
free(res);
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t output_res_c_source(const char* filename, uint16_t type, uint16_t subtype, uint8_t* buff,
|
||||
uint32_t size) {
|
||||
return output_res_c_source_ex(filename, type, subtype, buff, size, NULL);
|
||||
}
|
||||
|
||||
const char* skip_to(const char* p, char c) {
|
||||
while (*p && *p != c) p++;
|
||||
|
||||
|
@ -37,6 +37,8 @@ ret_t output_c_source(const char* filename, const char* prefix, const char* name
|
||||
|
||||
ret_t output_res_c_source(const char* filename, uint16_t type, uint16_t subtype, uint8_t* buff,
|
||||
uint32_t size);
|
||||
ret_t output_res_c_source_ex(const char* filename, uint16_t type, uint16_t subtype, uint8_t* buff,
|
||||
uint32_t size, const char* name);
|
||||
|
||||
const char* to_lower(char* str);
|
||||
const char* skip_to(const char* p, char c);
|
||||
|
@ -61,7 +61,30 @@ int main(int argc, char** argv) {
|
||||
} else if (end_with(in_filename, ".xml")) {
|
||||
output_res_c_source(out_filename, ASSET_TYPE_XML, 0, input_buff, size);
|
||||
} else {
|
||||
output_res_c_source(out_filename, ASSET_TYPE_DATA, 0, input_buff, size);
|
||||
const char* name = strrchr(in_filename, '/');
|
||||
if (name == NULL) {
|
||||
name = strrchr(in_filename, '\\');
|
||||
}
|
||||
if (name != NULL) {
|
||||
name++;
|
||||
}
|
||||
|
||||
if (end_with(in_filename, ".txt")) {
|
||||
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_TEXT, input_buff, size,
|
||||
name);
|
||||
} else if (end_with(in_filename, ".json")) {
|
||||
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_JSON, input_buff, size,
|
||||
name);
|
||||
} else if (end_with(in_filename, ".bin")) {
|
||||
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_BIN, input_buff, size,
|
||||
name);
|
||||
} else if (end_with(in_filename, ".dat")) {
|
||||
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_DAT, input_buff, size,
|
||||
name);
|
||||
} else {
|
||||
output_res_c_source_ex(out_filename, ASSET_TYPE_DATA, ASSET_TYPE_DATA_NONE, input_buff, size,
|
||||
name);
|
||||
}
|
||||
}
|
||||
|
||||
TKMEM_FREE(input_buff);
|
||||
|
Loading…
Reference in New Issue
Block a user