mirror of
https://github.com/zlgopen/awtk.git
synced 2025-05-08 19:44:45 +08:00
image support packed image
This commit is contained in:
parent
47748684e5
commit
aa2e89f9e0
@ -49,6 +49,11 @@
|
||||
<label/>
|
||||
<image style="border" image="green_btn_n" draw_type="patch3_y_scale_x"><label w="100%" h="100%" text="patch3_y_scale_x" /></image>
|
||||
</list_item>
|
||||
<list_item style="empty" children_layout="default(r=1,c=3,s=2,m=2)">
|
||||
<image style="border" image="image_packed_fg#xywh(0,0,106,54)" draw_type="center"><label w="100%" h="100%" text="packed center" /></image>
|
||||
<image style="border" image="image_packed_fg#grid(4,3,0,2)" draw_type="default"><label w="100%" h="100%" text="packed default" /></image>
|
||||
<image style="border" image="image_packed_fg#xywh(106,0,106,54)" draw_type="scale"><label w="100%" h="100%" text="packed scale" /></image>
|
||||
</list_item>
|
||||
</scroll_view>
|
||||
<scroll_bar_d name="bar" x="right" y="0" w="12" h="100%" value="0"/>
|
||||
</list_view>
|
||||
|
@ -1,5 +1,8 @@
|
||||
# 最新动态
|
||||
|
||||
2023/10/26
|
||||
* 图片控件支持[packed image](how_to_use_packed_image.md)
|
||||
|
||||
2023/10/25
|
||||
* 增加函数tk\_iostream\_serial\_create\_ex
|
||||
* 修复编译报错的问题(感谢智明提供补丁)
|
||||
|
@ -156,5 +156,9 @@
|
||||
|
||||
## 4. 限制
|
||||
|
||||
- 目前只能在 style 中使用。
|
||||
- 目前只能在 style 中 和 image 控件使用。
|
||||
- draw\_type 只支持 default|scale|center|icon 等几种。
|
||||
|
||||
## 5. 其它
|
||||
* [packed image demo](https://github.com/zlgopen/awtk-c-demos/blob/master/demos/packed_image.c)
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
TK_CONST_DATA_ALIGN(const unsigned char ui_images[]) = {
|
||||
0x04,0x00,0x01,0x01,0x03,0x19,0x00,0x00,0x00,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x73,0x00,0x00,
|
||||
0x04,0x00,0x01,0x01,0x06,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,0x73,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,0x00,0x12,0x12,0x22,0x11,0x77,0x69,0x6e,0x64,0x6f,0x77,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,0x00,
|
||||
@ -309,16 +309,55 @@ TK_CONST_DATA_ALIGN(const unsigned char ui_images[]) = {
|
||||
0x00,0x00,0x64,0x00,0x00,0x00,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,0x65,
|
||||
0x66,0x61,0x75,0x6c,0x74,0x28,0x77,0x3d,0x31,0x30,0x30,0x25,0x2c,0x68,0x3d,0x31,0x30,0x30,0x25,0x29,
|
||||
0x00,0x74,0x65,0x78,0x74,0x00,0x70,0x61,0x74,0x63,0x68,0x33,0x5f,0x79,0x5f,0x73,0x63,0x61,0x6c,0x65,
|
||||
0x5f,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x73,0x63,0x72,0x6f,0x6c,0x6c,0x5f,0x62,0x61,0x72,0x5f,0x64,
|
||||
0x5f,0x78,0x00,0x00,0x00,0x00,0x00,0x6c,0x69,0x73,0x74,0x5f,0x69,0x74,0x65,0x6d,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0c,0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x73,0x65,0x6c,0x66,
|
||||
0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,0x72,0x69,
|
||||
0x67,0x68,0x74,0x2c,0x79,0x3d,0x30,0x2c,0x77,0x3d,0x31,0x32,0x2c,0x68,0x3d,0x31,0x30,0x30,0x25,0x29,
|
||||
0x00,0x6e,0x61,0x6d,0x65,0x00,0x62,0x61,0x72,0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x30,0x00,0x00,0x00,
|
||||
0x00,0x62,0x75,0x74,0x74,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,0x00,0x00,0x00,0x00,0x73,0x74,0x79,0x6c,0x65,
|
||||
0x00,0x65,0x6d,0x70,0x74,0x79,0x00,0x63,0x68,0x69,0x6c,0x64,0x72,0x65,0x6e,0x5f,0x6c,0x61,0x79,0x6f,
|
||||
0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x72,0x3d,0x31,0x2c,0x63,0x3d,0x33,0x2c,0x73,
|
||||
0x3d,0x32,0x2c,0x6d,0x3d,0x32,0x29,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,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,0x00,
|
||||
0x00,0x19,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,
|
||||
0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,0x63,0x65,0x6e,0x74,0x65,0x72,0x2c,0x79,0x3d,
|
||||
0x62,0x6f,0x74,0x74,0x6f,0x6d,0x3a,0x31,0x30,0x2c,0x77,0x3d,0x32,0x35,0x25,0x2c,0x68,0x3d,0x33,0x30,
|
||||
0x29,0x00,0x6e,0x61,0x6d,0x65,0x00,0x63,0x6c,0x6f,0x73,0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,
|
||||
0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,};/*6451*/
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x73,0x74,0x79,
|
||||
0x6c,0x65,0x00,0x62,0x6f,0x72,0x64,0x65,0x72,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x69,0x6d,0x61,0x67,
|
||||
0x65,0x5f,0x70,0x61,0x63,0x6b,0x65,0x64,0x5f,0x66,0x67,0x23,0x78,0x79,0x77,0x68,0x28,0x30,0x2c,0x30,
|
||||
0x2c,0x31,0x30,0x36,0x2c,0x35,0x34,0x29,0x00,0x64,0x72,0x61,0x77,0x5f,0x74,0x79,0x70,0x65,0x00,0x63,
|
||||
0x65,0x6e,0x74,0x65,0x72,0x00,0x00,0x6c,0x61,0x62,0x65,0x6c,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,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x73,0x65,0x6c,0x66,0x5f,
|
||||
0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x77,0x3d,0x31,0x30,0x30,
|
||||
0x25,0x2c,0x68,0x3d,0x31,0x30,0x30,0x25,0x29,0x00,0x74,0x65,0x78,0x74,0x00,0x70,0x61,0x63,0x6b,0x65,
|
||||
0x64,0x20,0x63,0x65,0x6e,0x74,0x65,0x72,0x00,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x73,0x74,0x79,0x6c,0x65,0x00,0x62,0x6f,0x72,0x64,0x65,0x72,0x00,0x69,0x6d,0x61,0x67,0x65,0x00,0x69,
|
||||
0x6d,0x61,0x67,0x65,0x5f,0x70,0x61,0x63,0x6b,0x65,0x64,0x5f,0x66,0x67,0x23,0x67,0x72,0x69,0x64,0x28,
|
||||
0x34,0x2c,0x33,0x2c,0x30,0x2c,0x32,0x29,0x00,0x64,0x72,0x61,0x77,0x5f,0x74,0x79,0x70,0x65,0x00,0x64,
|
||||
0x65,0x66,0x61,0x75,0x6c,0x74,0x00,0x00,0x6c,0x61,0x62,0x65,0x6c,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,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x73,0x65,0x6c,0x66,
|
||||
0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x77,0x3d,0x31,0x30,
|
||||
0x30,0x25,0x2c,0x68,0x3d,0x31,0x30,0x30,0x25,0x29,0x00,0x74,0x65,0x78,0x74,0x00,0x70,0x61,0x63,0x6b,
|
||||
0x65,0x64,0x20,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x00,0x00,0x00,0x00,0x69,0x6d,0x61,0x67,0x65,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x73,0x74,0x79,0x6c,0x65,0x00,0x62,0x6f,0x72,0x64,0x65,0x72,0x00,0x69,0x6d,0x61,0x67,0x65,
|
||||
0x00,0x69,0x6d,0x61,0x67,0x65,0x5f,0x70,0x61,0x63,0x6b,0x65,0x64,0x5f,0x66,0x67,0x23,0x78,0x79,0x77,
|
||||
0x68,0x28,0x31,0x30,0x36,0x2c,0x30,0x2c,0x31,0x30,0x36,0x2c,0x35,0x34,0x29,0x00,0x64,0x72,0x61,0x77,
|
||||
0x5f,0x74,0x79,0x70,0x65,0x00,0x73,0x63,0x61,0x6c,0x65,0x00,0x00,0x6c,0x61,0x62,0x65,0x6c,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x64,0x00,0x00,
|
||||
0x00,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,
|
||||
0x28,0x77,0x3d,0x31,0x30,0x30,0x25,0x2c,0x68,0x3d,0x31,0x30,0x30,0x25,0x29,0x00,0x74,0x65,0x78,0x74,
|
||||
0x00,0x70,0x61,0x63,0x6b,0x65,0x64,0x20,0x73,0x63,0x61,0x6c,0x65,0x00,0x00,0x00,0x00,0x00,0x00,0x73,
|
||||
0x63,0x72,0x6f,0x6c,0x6c,0x5f,0x62,0x61,0x72,0x5f,0x64,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,0x00,0x00,0x00,0x0c,
|
||||
0x00,0x00,0x00,0x64,0x00,0x00,0x00,0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,
|
||||
0x65,0x66,0x61,0x75,0x6c,0x74,0x28,0x78,0x3d,0x72,0x69,0x67,0x68,0x74,0x2c,0x79,0x3d,0x30,0x2c,0x77,
|
||||
0x3d,0x31,0x32,0x2c,0x68,0x3d,0x31,0x30,0x30,0x25,0x29,0x00,0x6e,0x61,0x6d,0x65,0x00,0x62,0x61,0x72,
|
||||
0x00,0x76,0x61,0x6c,0x75,0x65,0x00,0x30,0x00,0x00,0x00,0x00,0x62,0x75,0x74,0x74,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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x19,0x00,0x00,0x00,0x1e,0x00,0x00,0x00,
|
||||
0x73,0x65,0x6c,0x66,0x5f,0x6c,0x61,0x79,0x6f,0x75,0x74,0x00,0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x28,
|
||||
0x78,0x3d,0x63,0x65,0x6e,0x74,0x65,0x72,0x2c,0x79,0x3d,0x62,0x6f,0x74,0x74,0x6f,0x6d,0x3a,0x31,0x30,
|
||||
0x2c,0x77,0x3d,0x32,0x35,0x25,0x2c,0x68,0x3d,0x33,0x30,0x29,0x00,0x6e,0x61,0x6d,0x65,0x00,0x63,0x6c,
|
||||
0x6f,0x73,0x65,0x00,0x74,0x65,0x78,0x74,0x00,0x43,0x6c,0x6f,0x73,0x65,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,};/*7222*/
|
||||
|
Binary file not shown.
@ -1605,6 +1605,25 @@ ret_t widget_draw_icon_text(widget_t* widget, canvas_t* c, const char* icon, wst
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t widget_draw_image_with_region(widget_t* widget, canvas_t* c, bitmap_t* img,
|
||||
const char* region, const rect_t* dst, image_draw_type_t draw_type) {
|
||||
rect_t src;
|
||||
return_value_if_fail(widget != NULL && img != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(c != NULL && region != NULL && dst != NULL, RET_BAD_PARAMS);
|
||||
|
||||
if (tk_str_eq(region, "#")) {
|
||||
src = rect_init(widget->x, widget->y, widget->w, widget->h);
|
||||
} else if (tk_str_eq(region, "#g")) {
|
||||
point_t p = {widget->x, widget->y};
|
||||
widget_to_global(widget, &p);
|
||||
src = rect_init(p.x, p.y, widget->w, widget->h);
|
||||
} else {
|
||||
image_region_parse(img->w, img->h, region, &src);
|
||||
}
|
||||
|
||||
return canvas_draw_image_ex2(c, img, draw_type, &src, dst);
|
||||
}
|
||||
|
||||
ret_t widget_fill_rect(widget_t* widget, canvas_t* c, const rect_t* r, bool_t bg,
|
||||
image_draw_type_t draw_type) {
|
||||
bitmap_t img;
|
||||
@ -1655,33 +1674,14 @@ ret_t widget_fill_rect(widget_t* widget, canvas_t* c, const rect_t* r, bool_t bg
|
||||
}
|
||||
|
||||
if (image_name != NULL && *image_name && r->w > 0 && r->h > 0) {
|
||||
char name[MAX_PATH + 1];
|
||||
const char* region = strrchr(image_name, '#');
|
||||
if (region != NULL) {
|
||||
memset(name, 0x00, sizeof(name));
|
||||
tk_strncpy(name, image_name, region - image_name);
|
||||
image_name = name;
|
||||
}
|
||||
|
||||
if (widget_load_image(widget, image_name, &img) == RET_OK) {
|
||||
const char* region = strrchr(image_name, '#');
|
||||
draw_type = (image_draw_type_t)style_get_int(style, draw_type_key, draw_type);
|
||||
|
||||
if (region == NULL) {
|
||||
canvas_draw_image_ex(c, &img, draw_type, r);
|
||||
} else {
|
||||
rect_t src;
|
||||
rect_t dst = *r;
|
||||
if (tk_str_eq(region, "#")) {
|
||||
src = rect_init(widget->x, widget->y, widget->w, widget->h);
|
||||
} else if (tk_str_eq(region, "#g")) {
|
||||
point_t p = {widget->x, widget->y};
|
||||
widget_to_global(widget, &p);
|
||||
src = rect_init(p.x, p.y, widget->w, widget->h);
|
||||
} else {
|
||||
image_region_parse(img.w, img.h, region, &src);
|
||||
}
|
||||
|
||||
canvas_draw_image_ex2(c, &img, draw_type, &src, &dst);
|
||||
widget_draw_image_with_region(widget, c, &img, region, r, draw_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4032,11 +4032,19 @@ float_t widget_measure_text(widget_t* widget, const wchar_t* text) {
|
||||
}
|
||||
|
||||
ret_t widget_load_image(widget_t* widget, const char* name, bitmap_t* bitmap) {
|
||||
char real_name[MAX_PATH+1];
|
||||
const char* region = NULL;
|
||||
image_manager_t* imm = widget_get_image_manager(widget);
|
||||
|
||||
return_value_if_fail(imm != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(widget != NULL && name != NULL && bitmap != NULL, RET_BAD_PARAMS);
|
||||
|
||||
region = strrchr(name, '#');
|
||||
if (region != NULL) {
|
||||
tk_strncpy(real_name, name, region-name);
|
||||
name = real_name;
|
||||
}
|
||||
|
||||
return image_manager_get_bitmap(imm, name, bitmap);
|
||||
}
|
||||
|
||||
|
@ -3386,6 +3386,8 @@ ret_t widget_stroke_border_rect_for_border_type(canvas_t* c, const rect_t* r, co
|
||||
|
||||
/* internal use */
|
||||
rect_t widget_get_content_area_ex(widget_t* widget, int32_t default_margin);
|
||||
ret_t widget_draw_image_with_region(widget_t* widget, canvas_t* c, bitmap_t* img,
|
||||
const char* region, const rect_t* dst, image_draw_type_t draw_type);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
|
@ -39,8 +39,10 @@ static ret_t image_on_paint_self(widget_t* widget, canvas_t* c) {
|
||||
}
|
||||
|
||||
do {
|
||||
if (image_base->image != NULL &&
|
||||
widget_load_image(widget, image_base->image, &bitmap) == RET_OK) {
|
||||
break_if_fail(image_base->image != NULL);
|
||||
if (widget_load_image(widget, image_base->image, &bitmap) == RET_OK) {
|
||||
const char* region = strrchr(image_base->image, '#');
|
||||
|
||||
if (vg != NULL) {
|
||||
if (image_need_transform(widget)) {
|
||||
if (image->draw_type == IMAGE_DRAW_ICON || image->draw_type == IMAGE_DRAW_CENTER) {
|
||||
@ -62,7 +64,11 @@ static ret_t image_on_paint_self(widget_t* widget, canvas_t* c) {
|
||||
}
|
||||
|
||||
dst = rect_init(0, 0, widget->w, widget->h);
|
||||
canvas_draw_image_ex(c, &bitmap, image->draw_type, &dst);
|
||||
if (region == NULL) {
|
||||
canvas_draw_image_ex(c, &bitmap, image->draw_type, &dst);
|
||||
} else {
|
||||
widget_draw_image_with_region(widget, c, &bitmap, region, &dst, image->draw_type);
|
||||
}
|
||||
}
|
||||
} while (FALSE);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user