Cube

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

Usage

Create Cube

gui_cube_create() 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 gui_cube_set_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 gui_cube_set_center() 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 gui_cube_set_mode().

Set Cube Image

The images of cube can be configured by calling gui_cube_set_img().

Set Rotation Direction

The rotation direction of this cube can be achieved by calling gui_cube_auto_rotation_by_x(), gui_cube_auto_rotation_by_y() and gui_cube_auto_rotation_by_z().

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_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) (d*3.1415926f/180.0f)

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:

Return 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:

Return 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)

Create a cube widget, 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:

Return the cube widget pointer.

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

Set the center of the cube.

Parameters:
  • _this – Widget pointer.

  • c_x – Center X.

  • c_y – Center Y.

void gui_cube_set_size(gui_cube_t *_this, float size)

Set the size of the cube.

Parameters:
  • _this – Widget pointer.

  • size – Scale size.

void gui_cube_add_click_cb(gui_cube_t *_this, gui_cube_cb_t cb_list)

Add click callback for the cube.

Parameters:
  • _this – Widget pointer.

  • cb_list – Click callback list.

void gui_cube_auto_rotation_by_x(gui_cube_t *_this, uint32_t internal_ms, float degree)

Enable automatic rotation of the cube along the X-axis.

Parameters:
  • _this – Widget pointer.

  • internal_ms – Rotation interval.

  • degree – Angle per rotation.

void gui_cube_auto_rotation_by_y(gui_cube_t *_this, uint32_t internal_ms, float degree)

Enable automatic rotation of the cube along the Y-axis.

Parameters:
  • _this – Widget pointer.

  • internal_ms – Rotation interval.

  • degree – Angle per rotation.

void gui_cube_auto_rotation_by_z(gui_cube_t *_this, uint32_t internal_ms, float degree)

Enable automatic rotation of the cube along the Z-axis.

Parameters:
  • _this – Widget pointer.

  • internal_ms – Rotation interval.

  • degree – Angle per rotation.

struct cube_img_path_t

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

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

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
struct gui_cube_img_event_t

Public Members

float size
gui_event_t event
struct gui_cube_cb_t

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

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
void *data[6]
uint8_t src_mode[6]