立方体

立方体是一个3D显示控件,它可以展示六个面的旋转立方体,每个面都能够显示不同的图像。

用法

创建控件

gui_cube_t *gui_cube_create(void *parent, const char *name, gui_cube_imgfile_t *img_file, int16_t x, int16_t y)创建一个cube控件。其中,img_file是一个包含了每个面图像源的结构体,支持内存地址或者文件系统路径。通过将IMG_SOURCE_MODE_TYPE src_mode[6]设置成IMG_SRC_MEMADDRIMG_SRC_FILESYS来选择内存地址还是文件系统路径访问图像。

设置大小

立方体控件的默认大小是dc->fb_height / 8.0,可以通过void gui_cube_set_size(cube, size)改变大小。注意size是立方体的1/2边长。

设置中心

立方体控件的默认中心是((dc->fb_width - size) / 2.0f,dc->fb_width - size) / 2.0f)。使用void gui_cube_set_center(cube, c_x, c_y)改变立方体的中心坐标。

设置图像模式

立方体控件默认图像混合模式是IMG_FILTER_BLACK滤黑,即图像中像素值为0的像素不写入屏幕刷新帧缓冲区),可以通过void gui_cube_set_mode(gui_cube_t *cube, T_CUBE_SIDE_TYPE cube_side, BLEND_MODE_TYPE mode)来改变图像混合模式。

设置立方体图像

可以通过void gui_cube_set_img(gui_cube_t *cube, gui_cube_imgfile_t *img_file)来设置立方体展示的图像。

设置旋转角度

立方体的旋转角度可以通过以下API设置,void gui_cube_auto_rotation_by_x(gui_cube_t *this, uint32_t internal_ms, float degree)void gui_cube_auto_rotation_by_y(gui_cube_t *this, uint32_t internal_ms, float degree)以及void gui_cube_auto_rotation_by_z(gui_cube_t *this, uint32_t internal_ms, float degree)

示例

#include <gui_obj.h>
#include "gui_cube.h"
#include "root_image_hongkong/ui_resource.h"

void page_tb_cube(void *parent)
{
    gui_cube_imgfile_t imgfile =
    {
        .src_mode[0] = IMG_SRC_MEMADDR, .src_mode[1] = IMG_SRC_MEMADDR, .src_mode[2] = IMG_SRC_MEMADDR,
        .src_mode[3] = IMG_SRC_MEMADDR, .src_mode[4] = IMG_SRC_MEMADDR, .src_mode[5] = IMG_SRC_MEMADDR,
        .data_addr.data_addr_front = ACTIVITY_BIN,
        .data_addr.data_addr_back = WEATHER_BIN,
        .data_addr.data_addr_up =  HEARTRATE_BIN,
        .data_addr.data_addr_down = CLOCKN_BIN,
        .data_addr.data_addr_left = MUSIC_BIN,
        .data_addr.data_addr_right = QUICKCARD_BIN
    };
    // gui_cube_imgfile_t imgfile =
    // {
    //     .src_mode[0] = IMG_SRC_FILESYS, .src_mode[1] = IMG_SRC_FILESYS, .src_mode[2] = IMG_SRC_FILESYS,
    //     .src_mode[3] = IMG_SRC_FILESYS, .src_mode[4] = IMG_SRC_FILESYS, .src_mode[5] = IMG_SRC_FILESYS,
    //     .img_path.img_path_front = "Activity.bin",
    //     .img_path.img_path_back = "Weather.bin",
    //     .img_path.img_path_up = "HeartRate.bin",
    //     .img_path.img_path_down = "Clockn.bin",
    //     .img_path.img_path_left = "Music.bin",
    //     .img_path.img_path_right = "QuickCard.bin"
    // };
    gui_cube_t *cube4 = gui_cube_create(parent, "cube", &imgfile, 0, 0);
    gui_cube_auto_rotation_by_y(cube4, 100, 5.5f);
    gui_cube_set_mode(cube4, CUBE_SIDE_DOWN, IMG_SRC_OVER_MODE);
    gui_cube_set_size(cube4, 100);
    gui_cube_set_center(cube4, 200, 200);
}


API

Defines

RAD(d)

angle to rad

Enums

enum T_CUBE_SIDE_TYPE

Values:

enumerator CUBE_SIDE_FRONT
enumerator CUBE_SIDE_BACK
enumerator CUBE_SIDE_UP
enumerator CUBE_SIDE_DOWN
enumerator CUBE_SIDE_LEFT
enumerator CUBE_SIDE_RIGHT
enumerator CUBE_SIDE_ALL
enum T_CUBE_NZ_TYPE

Values:

enumerator CUBE_NZ_0321
enumerator CUBE_NZ_4567
enumerator CUBE_NZ_5126
enumerator CUBE_NZ_0473
enumerator CUBE_NZ_7623
enumerator CUBE_NZ_0154

Functions

BLEND_MODE_TYPE gui_cube_get_mode(gui_cube_t *cube, T_CUBE_SIDE_TYPE side)

get the cube image’s blend mode

参数:
  • cube – the cube widget pointer

  • cube_side – the cube image’s side, CUBE_SIDE_ALL is not supported

返回:

the cube image’s blend mode

void gui_cube_set_mode(gui_cube_t *cube, T_CUBE_SIDE_TYPE cube_side, BLEND_MODE_TYPE mode)

set the cube image’s blend mode

参数:
  • cube – the cube widget pointer

  • cube_side – the cube image’s side

  • mode – the enumeration value of the mode is BLEND_MODE_TYPE

uint8_t gui_cube_get_opacity(gui_cube_t *cube, T_CUBE_SIDE_TYPE side)

get the cube image’s opacity

参数:
  • cube – the cube widget pointer

  • cube_side – the cube image’s side, CUBE_SIDE_ALL is not supported

返回:

the cube image’s opacity

void gui_cube_set_opacity(gui_cube_t *cube, T_CUBE_SIDE_TYPE side, uint8_t opacity)

set the cube image’s opacity

参数:
  • cube – the cube widget pointer

  • cube_side – the cube image’s side

  • opacity – the cube image’s opacity

void gui_cube_set_img(gui_cube_t *cube, gui_cube_imgfile_t *img_file)

set cube image

参数:
  • cube – the cube widget pointer

  • img_file – the image file data, set flg_fs true when using filesystem

gui_cube_t *gui_cube_create(void *parent, const char *name, gui_cube_imgfile_t *img_file, int16_t x, int16_t y)

cube create, images can be loaded from filesystem or memory address

参数:
  • parent – parent widget

  • name – widget name

  • img_file – the image file data, set flg_fs true when using filesystem

  • x – left

  • y – top

返回:

gui_cube_t* widget pointer Example usage

{
    gui_cube_imgfile_t imgfile =
    {
        .flg_fs = true,
        .img_path.img_path_front = "Activity.bin",
        .img_path.img_path_back = "Weather.bin",
        .img_path.img_path_up = "HeartRate.bin",
        .img_path.img_path_down = "Clockn.bin",
        .img_path.img_path_left = "Music.bin",
        .img_path.img_path_right = "QuickCard.bin"
    };

    gui_cube_t *cube4 = gui_cube_create(parent, "cube", &imgfile, 0, 0);
    gui_cube_set_size(cube4, 100);
    gui_cube_set_center(cube4, 200, 200);
}

void gui_cube_set_center(gui_cube_t *this, float c_x, float c_y)

set center

参数:
  • this – widget pointer

  • c_x – center x

  • c_y – center y

void gui_cube_set_size(gui_cube_t *this, float size)

set size

参数:
  • this – widget pointer

  • size – scale size

void gui_cube_add_click_cb(gui_cube_t *this, gui_cube_cb_t cb_list)

set click cb

参数:
  • this – widget pointer

  • cb_list – click cb list

void gui_cube_auto_rotation_by_x(gui_cube_t *this, uint32_t internal_ms, float degree)
参数:
  • this

  • interval

void gui_cube_auto_rotation_by_y(gui_cube_t *this, uint32_t internal_ms, float degree)
参数:
  • this

  • interval

void gui_cube_auto_rotation_by_z(gui_cube_t *this, uint32_t internal_ms, float degree)
参数:
  • this

  • interval

struct cube_img_path_t
#include <gui_cube.h>

Public Members

char *img_path_front

images file path

char *img_path_back

images file path

char *img_path_up

images file path

char *img_path_down

images file path

char *img_path_left

images file path

char *img_path_right

images file path

struct cube_data_addr_t
#include <gui_cube.h>

Public Members

void *data_addr_front

images memory address

void *data_addr_back

images memory address

void *data_addr_up

images memory address

void *data_addr_down

images memory address

void *data_addr_left

images memory address

void *data_addr_right

images memory address

struct gui_cube_imgfile_t
#include <gui_cube.h>

Public Members

IMG_SOURCE_MODE_TYPE src_mode[6]

flag: indicate file source

cube_img_path_t img_path
cube_data_addr_t data_addr
union gui_cube_imgfile_t.[anonymous] [anonymous]
struct gui_cube_img_event_t
#include <gui_cube.h>

Public Members

float size
gui_event_t event
struct gui_cube_cb_t
#include <gui_cube.h>

Public Members

gui_event_cb_t click_cb_front
gui_event_cb_t click_cb_back
gui_event_cb_t click_cb_up
gui_event_cb_t click_cb_down
gui_event_cb_t click_cb_left
gui_event_cb_t click_cb_right
struct gui_cube_t
#include <gui_cube.h>

CUBE widget structure.

Public Members

gui_obj_t base

base structure

draw_img_t draw_img[6]
float c_x
float c_y
float cbsize
float nz[6]
int16_t release_x
int16_t release_y
bool auto_flag
uint32_t interval_ms_y
float step_degree_y
float xrot
float yrot
float zrot
void *filename[6]
void *ftl[6]
union gui_cube_t.[anonymous] [anonymous]
void *data[6]
uint8_t src_mode[6]