简单图像
简单图像(simple img)是图像(img)控件的一个简化版本,去掉了旋转、平移和缩放等几何变换操作。
用法
创建控件
使用gui_simple_img_create(void *parent, const char *name, void *addr, int16_t x, int16_t y, int16_t w, int16_t h, IMG_SOURCE_MODE_TYPE src_mode_type)创建一个简单图像(simple img)控件。 其中,如果src_mode_type
是IMG_SRC_MEMADDR
,图像将从内存地址加载;如果src_mode_type
是IMG_SRC_FILESYS
,图像将从文件系统加载,addr
的值应该是图片路径。加载方式请参考下列枚举:
typedef enum
{
IMG_SRC_MEMADDR = 0,
IMG_SRC_FILESYS,
IMG_SRC_FTL,
} IMG_SOURCE_MODE_TYPE;
设置位置
如果需要改变简单图像(simple img)控件的位置,使用 gui_simple_img_set_location(gui_img_t *img, uint16_t x, uint16_t y)重设起点坐标。其中,x, y
是新的起点坐标。
设置属性
使用void gui_simple_img_set_attribute(gui_simple_img_t *img, const char *name, void *addr,int16_t x,int16_t y)设置简单图像(simple img)控件的属性,改变图像来源并设置新的起点坐标。
获取高度/宽度
如果想获取简单图像(simple img)控件的高度或宽度,可以使用gui_simple_img_get_height(gui_simple_img_t *this)或gui_simple_img_get_width(gui_simple_img_t *this)。
示例
代码片段
#include "root_image_hongkong/ui_resource.h"
#include "gui_simple_img.h"
#include "gui_text.h"
#include "draw_font.h"
char *tb1_text = "gui_simple_img_create";
void page_tb1(void *parent)
{
static char array1[50];
static char array2[50];
gui_font_mem_init(ARIALBD_SIZE16_BITS4_FONT_BIN);
gui_simple_img_t *img_test = gui_simple_img_create(parent, "simg", SET_ON_BIN, 0, 0, 0, 0, 0);
gui_text_t *text1 = gui_text_create(parent, "text1", 10, 100, 300, 30);
gui_text_set(text1, tb1_text, GUI_FONT_SRC_BMP, APP_COLOR_WHITE, strlen(tb1_text), 16);
gui_text_mode_set(text1, LEFT);
gui_text_t *text2 = gui_text_create(parent, "text2", 10, 130, 330, 30);
gui_text_set(text2, tb1_text, GUI_FONT_SRC_BMP, APP_COLOR_WHITE, strlen(tb1_text), 16);
gui_text_mode_set(text2, LEFT);
sprintf(array1, "gui_img_get_height %d", gui_simple_img_get_height(img_test));
text2->content = array1;
text2->len = strlen(array1);
gui_text_t *text3 = gui_text_create(parent, "text3", 10, 160, 330, 30);
gui_text_set(text3, tb1_text, GUI_FONT_SRC_BMP, APP_COLOR_WHITE, strlen(tb1_text), 16);
gui_text_mode_set(text3, LEFT);
sprintf(array2, "gui_img_get_width %d", gui_simple_img_get_width(img_test));
text3->content = array2;
text3->len = strlen(array2);
}
void page_tb2(void *parent)
{
gui_simple_img_t *img_test = gui_simple_img_create(parent, "simg", SET_ON_BIN, 0, 0, 0, 0, 0);
gui_simple_img_set_location(img_test, 50, 50);
gui_text_t *text2 = gui_text_create(parent, "text2", 10, 150, 330, 24);
gui_text_set(text2, "gui_simple_img_set_location", GUI_FONT_SRC_BMP, APP_COLOR_WHITE, 27, 16);
gui_text_mode_set(text2, LEFT);
}
void page_tb3(void *parent)
{
gui_simple_img_t *img_test = gui_simple_img_create(parent, "simg", SET_ON_BIN, 0, 0, 0, 0, 0);
gui_simple_img_set_attribute(img_test, "test", SET_OFF_BIN, 20, 20);
gui_text_t *text3 = gui_text_create(parent, "text3", 10, 120, 330, 24);
gui_text_set(text3, "gui_simple_img_set_attribute", GUI_FONT_SRC_BMP, APP_COLOR_WHITE, 28, 16);
gui_text_mode_set(text3, LEFT);
}
API
Functions
-
uint16_t gui_simple_img_get_width(gui_simple_img_t *this)
load the image to read it’s width
- 参数:
img – the image widget pointer.
- 返回:
uint16_t image’s width
-
uint16_t gui_simple_img_get_height(gui_simple_img_t *this)
load the image to read it’s hight
- 参数:
img – the image widget pointer.
- 返回:
uint16_t image’s height
-
void gui_simple_img_set_location(gui_simple_img_t *this, uint16_t x, uint16_t y)
set the image’s location
- 参数:
img – the image widget pointer.
x – the x coordinate
y – the y coordinate
-
void gui_simple_img_set_mode(gui_simple_img_t *this, BLEND_MODE_TYPE mode)
set the image’s blend mode.
- 参数:
img – the image widget pointer.
mode – the enumeration value of the mode is BLEND_MODE_TYPE.
-
void gui_simple_img_set_attribute(gui_simple_img_t *this, const char *name, void *addr, int16_t x, int16_t y)
set x,y and file path
- 参数:
img – image widget
name – change widget name
addr – change picture address
x – X-axis coordinate
y – Y-axis coordinate
-
void gui_simple_img_set_opacity(gui_simple_img_t *this, unsigned char opacity_value)
Add opacity value to the image.
- 参数:
this – the image widget pointer.
opacity_value – The opacity value ranges from 0 to 255, default 255.
-
void gui_simple_img_set_quality(gui_simple_img_t *this, bool high_quality)
set the image’s quality.
- 参数:
img – the image widget pointer.
high_quality – image drawn in high quality or not.
-
gui_simple_img_t *gui_simple_img_create(void *parent, const char *name, void *addr, int16_t x, int16_t y, int16_t w, int16_t h, IMG_SOURCE_MODE_TYPE src_mode_type)
creat an simple image widget
备注
creat an simple image widget and set attribute
- 参数:
parent – the father widget it nested in.
name – widget name.
addr – bin file address in IMG_SRC_MEMADDR, or image file path in IMG_SRC_FILESYS mode.
x – the X-axis coordinate of the widget.
y – the Y-axis coordinate of the widget.
w – the width of the widget.
h – the hight of the widget.
src_mode_type – the type of image source.
- 返回:
return the widget object pointer.
-
struct gui_simple_img_t
- #include <gui_simple_img.h>
image widget structure
Public Members
-
draw_img_t *draw_img
-
void *data
-
void *filename
-
void *ftl
-
union gui_simple_img_t.[anonymous] [anonymous]
-
uint32_t opacity_value
-
uint32_t blend_mode
-
uint32_t src_mode
-
uint32_t high_quality
-
uint32_t press_flag
press to change picture to the highlighted
-
uint32_t release_flag
-
uint8_t checksum
-
draw_img_t *draw_img