mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
improve mutable image
This commit is contained in:
parent
b99eb1c3ce
commit
324dbc08cc
@ -1,5 +1,8 @@
|
||||
# 最新动态
|
||||
|
||||
* 2020/03/06
|
||||
* 完善mutable image,支持自定义的图片创建函数。
|
||||
|
||||
* 2020/03/05
|
||||
* 增加path\_replace\_extname函数。
|
||||
* 完善path\_replace\_basename函数。
|
||||
|
@ -26,20 +26,33 @@
|
||||
#include "base/widget_vtable.h"
|
||||
#include "mutable_image/mutable_image.h"
|
||||
|
||||
static bitmap_format_t mutable_image_get_disire_format(widget_t* widget, canvas_t* c) {
|
||||
mutable_image_t* mutable_image = MUTABLE_IMAGE(widget);
|
||||
bitmap_format_t format = BITMAP_FMT_NONE;
|
||||
|
||||
if (mutable_image->fb != NULL) {
|
||||
format = (bitmap_format_t)(mutable_image->fb->format);
|
||||
} else {
|
||||
format = lcd_get_desired_bitmap_format(c->lcd);
|
||||
}
|
||||
|
||||
return format;
|
||||
}
|
||||
|
||||
static bitmap_t* mutable_image_prepare_image(widget_t* widget, canvas_t* c) {
|
||||
mutable_image_t* mutable_image = MUTABLE_IMAGE(widget);
|
||||
bitmap_format_t format = mutable_image_get_disire_format(widget, c);
|
||||
return_value_if_fail(mutable_image != NULL && mutable_image->prepare_image != NULL, NULL);
|
||||
|
||||
if (mutable_image->create_image != NULL) {
|
||||
void* ctx = mutable_image->create_image_ctx;
|
||||
mutable_image->image = mutable_image->create_image(ctx, format, mutable_image->image);
|
||||
} else if (mutable_image->image == NULL) {
|
||||
mutable_image->image = bitmap_create_ex(widget->w, widget->h, 0, format);
|
||||
}
|
||||
|
||||
if (mutable_image->image == NULL) {
|
||||
bitmap_format_t format = BITMAP_FMT_NONE;
|
||||
|
||||
if (mutable_image->fb != NULL) {
|
||||
format = (bitmap_format_t)(mutable_image->fb->format);
|
||||
} else {
|
||||
format = lcd_get_desired_bitmap_format(c->lcd);
|
||||
}
|
||||
|
||||
mutable_image->image = bitmap_create_ex(widget->w, widget->h, widget->w * 2, format);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mutable_image->prepare_image != NULL) {
|
||||
@ -57,7 +70,9 @@ ret_t mutable_image_on_paint_self(widget_t* widget, canvas_t* canvas) {
|
||||
mutable_image_t* mutable_image = MUTABLE_IMAGE(widget);
|
||||
bitmap_t* bitmap = mutable_image_prepare_image(widget, canvas);
|
||||
|
||||
return_value_if_fail(bitmap != NULL, RET_BAD_PARAMS);
|
||||
if (bitmap == NULL) {
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
if (mutable_image->fb != NULL) {
|
||||
rect_t r = rect_init(0, 0, bitmap->w, bitmap->h);
|
||||
@ -76,9 +91,8 @@ ret_t mutable_image_on_paint_self(widget_t* widget, canvas_t* canvas) {
|
||||
}
|
||||
|
||||
if (bitmap->buffer != NULL) {
|
||||
rect_t src = rect_init(0, 0, bitmap->w, bitmap->h);
|
||||
rect_t dst = rect_init(0, 0, widget->w, widget->h);
|
||||
canvas_draw_image(canvas, bitmap, &src, &dst);
|
||||
canvas_draw_image_center(canvas, bitmap, &dst);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,6 +166,17 @@ ret_t mutable_image_set_prepare_image(widget_t* widget, mutable_image_prepare_im
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t mutable_image_set_create_image(widget_t* widget, mutable_image_create_image_t create_image,
|
||||
void* create_image_ctx) {
|
||||
mutable_image_t* mutable_image = MUTABLE_IMAGE(widget);
|
||||
return_value_if_fail(mutable_image != NULL && create_image != NULL, RET_BAD_PARAMS);
|
||||
|
||||
mutable_image->create_image = create_image;
|
||||
mutable_image->create_image_ctx = create_image_ctx;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t mutable_image_set_framebuffer(widget_t* widget, uint32_t w, uint32_t h,
|
||||
bitmap_format_t format, uint8_t* buff) {
|
||||
mutable_image_t* mutable_image = MUTABLE_IMAGE(widget);
|
||||
|
@ -28,6 +28,8 @@
|
||||
BEGIN_C_DECLS
|
||||
|
||||
typedef ret_t (*mutable_image_prepare_image_t)(void* ctx, bitmap_t* image);
|
||||
typedef bitmap_t* (*mutable_image_create_image_t)(void* ctx, bitmap_format_t format,
|
||||
bitmap_t* old_image);
|
||||
|
||||
/**
|
||||
* @class mutable_image_t
|
||||
@ -61,6 +63,7 @@ typedef ret_t (*mutable_image_prepare_image_t)(void* ctx, bitmap_t* image);
|
||||
*
|
||||
* > 创建之后:
|
||||
* >
|
||||
* > 需要用mutable\_image\_set\_create\_image设置创建图片的回调函数。
|
||||
* > 需要用mutable\_image\_set\_prepare\_image设置准备图片的回调函数。
|
||||
*
|
||||
* > 完整示例请参考:[mutable image demo](
|
||||
@ -76,6 +79,9 @@ typedef struct _mutable_image_t {
|
||||
void* prepare_image_ctx;
|
||||
mutable_image_prepare_image_t prepare_image;
|
||||
|
||||
void* create_image_ctx;
|
||||
mutable_image_create_image_t create_image;
|
||||
|
||||
bitmap_t* fb;
|
||||
bitmap_t* image;
|
||||
canvas_t* canvas;
|
||||
@ -113,6 +119,19 @@ widget_t* mutable_image_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h)
|
||||
ret_t mutable_image_set_prepare_image(widget_t* widget, mutable_image_prepare_image_t prepare_image,
|
||||
void* prepare_image_ctx);
|
||||
|
||||
/**
|
||||
* @method mutable_image_set_create_image
|
||||
* 设置create_image回调函数。
|
||||
*
|
||||
* @param {widget_t*} widget mutable_image对象。
|
||||
* @param {mutable_image_create_image_t} create_image 创建图片的回调函数。
|
||||
* @param {void*} create_image_ctx create_image回调函数的上下文。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t mutable_image_set_create_image(widget_t* widget, mutable_image_create_image_t create_image,
|
||||
void* create_image_ctx);
|
||||
|
||||
/**
|
||||
* @method mutable_image_set_framebuffer
|
||||
* 设置framebuffer(当硬件支持多层合成时才用)。
|
||||
|
Loading…
Reference in New Issue
Block a user