Cube

The cube is a 3D display widget that show a rotating cube with six faces, each capable of displaying distinct images.

Usage

Create a cube

gui_cube_t *gui_cube_create(void *parent, const char *name, gui_cube_imgfile_t *img_file, int16_t x, int16_t y) creates a cube widget. The img_file is an struct including image sources for the six faces of a cube. Both memory address and file path are supported, whether you choose to utilize memory or access the filesystem, simply set IMG_SOURCE_MODE_TYPE src_mode[6] to either IMG_SRC_MEMADDR or IMG_SRC_FILESYS.

Set size

By default, the cube’s size is dc->fb_height / 8.0. If you want to change the size set void gui_cube_set_size(cube, size). Note this size is the 1/2 length of cube edge.

Set center

By default, the center is ((dc->fb_width - size) / 2.0f,dc->fb_width - size) / 2.0f). You can use void gui_cube_set_center(cube, c_x, c_y) to set the center coordinates of the cube.

Set image mode

By default, the cube’s image blend mode is IMG_FILTER_BLACK, you can change the blend mode of image by calling void gui_cube_set_mode(gui_cube_t *cube, T_CUBE_SIDE_TYPE cube_side, BLEND_MODE_TYPE mode).

Set cube image

The images of cube can be configured by calling void gui_cube_set_img(gui_cube_t *cube, gui_cube_imgfile_t *img_file).

Set rotation direction

The rotation direction of this cube can be achieved by calling 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) and void gui_cube_auto_rotation_by_z(gui_cube_t *this, uint32_t internal_ms, float degree).

Example

#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

Parameters:
  • cube – the cube widget pointer

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

Returns:

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

Parameters:
  • 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

Parameters:
  • cube – the cube widget pointer

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

Returns:

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

Parameters:
  • 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

Parameters:
  • 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

Parameters:
  • parent – parent widget

  • name – widget name

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

  • x – left

  • y – top

Returns:

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

Parameters:
  • this – widget pointer

  • c_x – center x

  • c_y – center y

void gui_cube_set_size(gui_cube_t *this, float size)

set size

Parameters:
  • 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

Parameters:
  • 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)
Parameters:
  • this

  • interval

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

  • interval

void gui_cube_auto_rotation_by_z(gui_cube_t *this, uint32_t internal_ms, float degree)
Parameters:
  • 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]