mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
feat(obj): merge draw clallback to events
This commit is contained in:
parent
6b7fe23fb8
commit
03f74ce186
@ -39,6 +39,7 @@ void lv_example_scroll_2(void)
|
||||
}
|
||||
lv_obj_update_snap(panel, LV_ANIM_ON);
|
||||
|
||||
#if LV_USE_SWITCH
|
||||
/*Switch between "One scroll" and "Normal scroll" mode*/
|
||||
lv_obj_t * sw = lv_switch_create(lv_scr_act(), NULL);
|
||||
lv_obj_align(sw, NULL, LV_ALIGN_IN_TOP_RIGHT, -20, 10);
|
||||
@ -46,6 +47,7 @@ void lv_example_scroll_2(void)
|
||||
lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);
|
||||
lv_label_set_text(label, "One scroll");
|
||||
lv_obj_align(label, sw, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_IMG && LV_BUILD_EXAMPLES
|
||||
#if LV_USE_IMG && LV_USE_SLIDER && LV_BUILD_EXAMPLES
|
||||
|
||||
static lv_obj_t * create_slider(lv_color_t color);
|
||||
static void slider_event_cb(lv_obj_t * slider, lv_event_t event);
|
||||
|
@ -61,7 +61,7 @@ typedef struct {
|
||||
**********************/
|
||||
static void lv_obj_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_obj_destructor(lv_obj_t * obj);
|
||||
static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_obj_draw(lv_obj_t * obj, lv_event_t e);
|
||||
static void lv_obj_event_cb(lv_obj_t * obj, lv_event_t e);
|
||||
static void draw_scrollbar(lv_obj_t * obj, const lv_area_t * clip_area);
|
||||
static lv_res_t scrollbar_init_draw_dsc(lv_obj_t * obj, lv_draw_rect_dsc_t * dsc);
|
||||
@ -80,7 +80,6 @@ const lv_obj_class_t lv_obj_class = {
|
||||
.constructor_cb = lv_obj_constructor,
|
||||
.destructor_cb = lv_obj_destructor,
|
||||
.event_cb = lv_obj_event_cb,
|
||||
.draw_cb = lv_obj_draw,
|
||||
.instance_size = (sizeof(lv_obj_t)),
|
||||
.base_class = NULL,
|
||||
};
|
||||
@ -225,12 +224,12 @@ lv_res_t lv_event_send(lv_obj_t * obj, lv_event_t event, void * param)
|
||||
if(indev_act->driver->feedback_cb) indev_act->driver->feedback_cb(indev_act->driver, event);
|
||||
}
|
||||
|
||||
lv_obj_event_base(NULL, obj, event);
|
||||
lv_event_dsc_t * event_dsc = lv_obj_get_event_dsc(obj, 0);
|
||||
lv_res_t res = LV_RES_OK;
|
||||
res = lv_obj_event_base(NULL, obj, event);
|
||||
|
||||
uint32_t i = 0;
|
||||
lv_res_t res = LV_RES_OK;
|
||||
lv_event_dsc_t * event_dsc = lv_obj_get_event_dsc(obj, 0);
|
||||
while(event_dsc) {
|
||||
while(event_dsc && res == LV_RES_OK) {
|
||||
if(event_dsc->cb) {
|
||||
void * event_act_user_data_cb_save = event_act_user_data_cb;
|
||||
event_act_user_data_cb = event_dsc->user_data;
|
||||
@ -735,10 +734,15 @@ static void lv_obj_destructor(lv_obj_t * p)
|
||||
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
static void lv_obj_draw(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
if(lv_obj_get_style_clip_corner(obj, LV_PART_MAIN)) return LV_DRAW_RES_MASKED;
|
||||
if(e == LV_EVENT_COVER_CHECK) {
|
||||
lv_cover_check_info_t * info = lv_event_get_param();
|
||||
if(info->res == LV_DRAW_RES_MASKED) return;
|
||||
if(lv_obj_get_style_clip_corner(obj, LV_PART_MAIN)) {
|
||||
info->res = LV_DRAW_RES_MASKED;
|
||||
return;
|
||||
}
|
||||
|
||||
/*Most trivial test. Is the mask fully IN the object? If no it surely doesn't cover it*/
|
||||
lv_coord_t r = lv_obj_get_style_radius(obj, LV_PART_MAIN);
|
||||
@ -751,19 +755,32 @@ static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
|
||||
coords.y1 -= h;
|
||||
coords.y2 += h;
|
||||
|
||||
if(_lv_area_is_in(clip_area, &coords, r) == false) return LV_DRAW_RES_NOT_COVER;
|
||||
if(_lv_area_is_in(info->clip_area, &coords, r) == false) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
|
||||
if(lv_obj_get_style_bg_opa(obj, LV_PART_MAIN) < LV_OPA_MAX) return LV_DRAW_RES_NOT_COVER;
|
||||
if(lv_obj_get_style_bg_opa(obj, LV_PART_MAIN) < LV_OPA_MAX) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
|
||||
#if LV_DRAW_COMPLEX
|
||||
if(lv_obj_get_style_blend_mode(obj, LV_PART_MAIN) != LV_BLEND_MODE_NORMAL) return LV_DRAW_RES_NOT_COVER;
|
||||
if(lv_obj_get_style_blend_mode(obj, LV_PART_MAIN) != LV_BLEND_MODE_NORMAL) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if(lv_obj_get_style_opa(obj, LV_PART_MAIN) < LV_OPA_MAX) return LV_DRAW_RES_NOT_COVER;
|
||||
if(lv_obj_get_style_opa(obj, LV_PART_MAIN) < LV_OPA_MAX) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_COVER;
|
||||
info->res = LV_DRAW_RES_COVER;
|
||||
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_draw_rect_dsc_t draw_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_dsc);
|
||||
/*If the border is drawn later disable loading its properties*/
|
||||
@ -794,7 +811,8 @@ static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
else if(e == LV_EVENT_DRAW_POST) {
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
draw_scrollbar(obj, clip_area);
|
||||
|
||||
#if LV_DRAW_COMPLEX
|
||||
@ -825,8 +843,6 @@ static lv_draw_res_t lv_obj_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
|
||||
lv_draw_rect(&coords, clip_area, &draw_dsc);
|
||||
}
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void draw_scrollbar(lv_obj_t * obj, const lv_area_t * clip_area)
|
||||
@ -1052,6 +1068,9 @@ static void lv_obj_event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
}
|
||||
lv_obj_refresh_ext_draw_size(obj);
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN || e == LV_EVENT_DRAW_POST || e == LV_EVENT_COVER_CHECK) {
|
||||
lv_obj_draw(obj, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -38,8 +38,6 @@ struct _lv_obj_t;
|
||||
* EVENTS
|
||||
*---------------------*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Type of event being sent to the object.
|
||||
*/
|
||||
@ -70,8 +68,10 @@ typedef enum {
|
||||
LV_EVENT_REFR_EXT_DRAW_SIZE, /**< Draw extras on the object */
|
||||
|
||||
LV_EVENT_DRAW_MAIN_BEGIN,
|
||||
LV_EVENT_DRAW_MAIN,
|
||||
LV_EVENT_DRAW_MAIN_END,
|
||||
LV_EVENT_DRAW_POST_BEGIN,
|
||||
LV_EVENT_DRAW_POST,
|
||||
LV_EVENT_DRAW_POST_END,
|
||||
LV_EVENT_DRAW_PART_BEGIN,
|
||||
LV_EVENT_DRAW_PART_END,
|
||||
@ -259,6 +259,11 @@ typedef struct {
|
||||
bool result;
|
||||
} lv_hit_test_info_t;
|
||||
|
||||
typedef struct {
|
||||
lv_draw_res_t res;
|
||||
const lv_area_t * clip_area;
|
||||
} lv_cover_check_info_t;
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
@ -83,20 +83,6 @@ void _lv_obj_destruct(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
lv_draw_res_t lv_obj_draw_base(const lv_obj_class_t * class_p, struct _lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
if(class_p == NULL) return LV_DRAW_RES_OK;
|
||||
|
||||
/*Find a base in which draw_cb is set*/
|
||||
const lv_obj_class_t * base = class_p->base_class;
|
||||
while(base && base->draw_cb == NULL) base = base->base_class;
|
||||
|
||||
if(base == NULL) return LV_DRAW_RES_OK;
|
||||
if(base->draw_cb == NULL) return LV_DRAW_RES_OK;
|
||||
|
||||
return base->draw_cb(obj, clip_area, mode);
|
||||
}
|
||||
|
||||
bool lv_obj_is_editable(struct _lv_obj_t * obj)
|
||||
{
|
||||
const lv_obj_class_t * class_p = obj->class_p;
|
||||
|
@ -42,7 +42,6 @@ typedef struct _lv_obj_class_t{
|
||||
void (*constructor_cb)(struct _lv_obj_t * obj, const struct _lv_obj_t * copy);
|
||||
void (*destructor_cb)(struct _lv_obj_t * obj);
|
||||
lv_event_cb_t event_cb; /**< Object type specific event function*/
|
||||
lv_draw_cb_t draw_cb; /**< Object type specific draw function*/
|
||||
uint32_t editable :2; /**< Value from ::lv_obj_class_editable_t */
|
||||
uint32_t instance_size :20;
|
||||
}lv_obj_class_t;
|
||||
@ -62,8 +61,6 @@ struct _lv_obj_t * lv_obj_create_from_class(const struct _lv_obj_class_t * class
|
||||
|
||||
void _lv_obj_destruct(struct _lv_obj_t * obj);
|
||||
|
||||
lv_draw_res_t lv_obj_draw_base(const lv_obj_class_t * class_p, struct _lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
|
||||
bool lv_obj_is_editable(struct _lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
|
@ -53,20 +53,6 @@ typedef struct
|
||||
const void * sub_part_ptr;
|
||||
}lv_obj_draw_dsc_t;
|
||||
|
||||
/** Design modes */
|
||||
enum {
|
||||
LV_DRAW_MODE_COVER_CHECK, /**< Check if the object fully covers the 'mask_p' area */
|
||||
LV_DRAW_MODE_MAIN_DRAW, /**< Draw the main portion of the object */
|
||||
LV_DRAW_MODE_POST_DRAW, /**< Draw extras on the object */
|
||||
};
|
||||
typedef uint8_t lv_draw_mode_t;
|
||||
|
||||
/**
|
||||
* The draw callback is used to draw the object on the screen.
|
||||
* It accepts the object, a mask area, and the mode in which to draw the object.
|
||||
*/
|
||||
typedef lv_draw_res_t (*lv_draw_cb_t)(struct _lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
@ -43,7 +43,6 @@ static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj);
|
||||
static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p);
|
||||
static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p);
|
||||
static void draw_buf_flush(void);
|
||||
static lv_draw_res_t call_draw_cb(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void call_flush_cb(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p);
|
||||
|
||||
/**********************
|
||||
@ -580,18 +579,11 @@ static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj)
|
||||
|
||||
/*If this object is fully cover the draw area check the children too */
|
||||
if(_lv_area_is_in(area_p, &obj->coords, 0) && lv_obj_has_flag(obj, LV_OBJ_FLAG_HIDDEN) == false) {
|
||||
lv_draw_res_t draw_res = call_draw_cb(obj, area_p, LV_DRAW_MODE_COVER_CHECK);
|
||||
if(draw_res == LV_DRAW_RES_MASKED) return NULL;
|
||||
|
||||
lv_draw_res_t event_draw_res = LV_DRAW_RES_OK;
|
||||
lv_event_send(obj, LV_EVENT_COVER_CHECK, &event_draw_res);
|
||||
if(event_draw_res == LV_DRAW_RES_MASKED) return NULL;
|
||||
if(event_draw_res == LV_DRAW_RES_NOT_COVER) draw_res = LV_DRAW_RES_NOT_COVER;
|
||||
|
||||
|
||||
if(draw_res == LV_DRAW_RES_COVER && lv_obj_get_style_opa(obj, LV_PART_MAIN) != LV_OPA_COVER) {
|
||||
draw_res = LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
lv_cover_check_info_t info;
|
||||
info.res = LV_DRAW_RES_COVER;
|
||||
info.clip_area = area_p;
|
||||
lv_event_send(obj, LV_EVENT_COVER_CHECK, &info);
|
||||
if(info.res == LV_DRAW_RES_MASKED) return NULL;
|
||||
|
||||
uint32_t i;
|
||||
for(i = 0; i < lv_obj_get_child_cnt(obj); i++) {
|
||||
@ -606,7 +598,7 @@ static lv_obj_t * lv_refr_get_top_obj(const lv_area_t * area_p, lv_obj_t * obj)
|
||||
|
||||
/*If no better children use this object*/
|
||||
if(found_p == NULL) {
|
||||
if(draw_res == LV_DRAW_RES_COVER) {
|
||||
if(info.res == LV_DRAW_RES_COVER) {
|
||||
found_p = obj;
|
||||
}
|
||||
}
|
||||
@ -653,7 +645,7 @@ static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p)
|
||||
|
||||
/*Call the post draw draw function of the parents of the to object*/
|
||||
lv_event_send(par, LV_EVENT_DRAW_POST_BEGIN, (void*)mask_p);
|
||||
call_draw_cb(par, mask_p, LV_DRAW_MODE_POST_DRAW);
|
||||
lv_event_send(par, LV_EVENT_DRAW_POST, (void*)mask_p);
|
||||
lv_event_send(par, LV_EVENT_DRAW_POST_END, (void*)mask_p);
|
||||
|
||||
/*The new border will be the last parents,
|
||||
@ -692,7 +684,7 @@ static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p)
|
||||
if(union_ok != false) {
|
||||
/* Redraw the object */
|
||||
lv_event_send(obj, LV_EVENT_DRAW_MAIN_BEGIN, &obj_ext_mask);
|
||||
call_draw_cb(obj, &obj_ext_mask, LV_DRAW_MODE_MAIN_DRAW);
|
||||
lv_event_send(obj, LV_EVENT_DRAW_MAIN, &obj_ext_mask);
|
||||
lv_event_send(obj, LV_EVENT_DRAW_MAIN_END, &obj_ext_mask);
|
||||
|
||||
#if MASK_AREA_DEBUG
|
||||
@ -735,7 +727,7 @@ static void lv_refr_obj(lv_obj_t * obj, const lv_area_t * mask_ori_p)
|
||||
|
||||
/* If all the children are redrawn make 'post draw' draw */
|
||||
lv_event_send(obj, LV_EVENT_DRAW_POST_BEGIN, &obj_ext_mask);
|
||||
call_draw_cb(obj, &obj_ext_mask, LV_DRAW_MODE_POST_DRAW);
|
||||
lv_event_send(obj, LV_EVENT_DRAW_POST, &obj_ext_mask);
|
||||
lv_event_send(obj, LV_EVENT_DRAW_POST_END, &obj_ext_mask);
|
||||
}
|
||||
}
|
||||
@ -932,23 +924,6 @@ static void draw_buf_flush(void)
|
||||
}
|
||||
}
|
||||
|
||||
static lv_draw_res_t call_draw_cb(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
if(obj == NULL) return LV_DRAW_RES_OK;
|
||||
|
||||
const lv_obj_class_t * class_p = obj->class_p;
|
||||
while(class_p && class_p->draw_cb == NULL) class_p = class_p->base_class;
|
||||
|
||||
if(class_p == NULL) return LV_DRAW_RES_OK;
|
||||
|
||||
|
||||
lv_draw_res_t res = LV_DRAW_RES_OK;
|
||||
|
||||
if(class_p->draw_cb) res = class_p->draw_cb(obj, clip_area, mode);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static void call_flush_cb(lv_disp_drv_t * drv, const lv_area_t * area, lv_color_t * color_p)
|
||||
{
|
||||
TRACE_REFR("Calling flush_cb on (%d;%d)(%d;%d) area with 0x%p image pointer", area->x1, area->y1, area->x2, area->y2, color_p);
|
||||
|
@ -32,11 +32,10 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_colorwheel_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static lv_draw_res_t lv_colorwheel_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_colorwheel_event(lv_obj_t * obj, lv_event_t e);
|
||||
|
||||
static void draw_disc_grad(lv_obj_t * obj, const lv_area_t * mask);
|
||||
static void draw_knob(lv_obj_t * obj, const lv_area_t * mask);
|
||||
static void draw_disc_grad(lv_obj_t * obj);
|
||||
static void draw_knob(lv_obj_t * obj);
|
||||
static void invalidate_knob(lv_obj_t * obj);
|
||||
static lv_area_t get_knob_area(lv_obj_t * obj);
|
||||
|
||||
@ -51,7 +50,6 @@ static uint16_t get_angle(lv_obj_t * obj);
|
||||
**********************/
|
||||
const lv_obj_class_t lv_colorwheel_class = {.instance_size = sizeof(lv_colorwheel_t), .base_class = &lv_obj_class,
|
||||
.constructor_cb = lv_colorwheel_constructor,
|
||||
.draw_cb = lv_colorwheel_draw,
|
||||
.event_cb = lv_colorwheel_event,
|
||||
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
|
||||
};
|
||||
@ -227,26 +225,9 @@ static void lv_colorwheel_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
refr_knob_pos(obj);
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_colorwheel_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
draw_disc_grad(obj, clip_area);
|
||||
draw_knob(obj, clip_area);
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void draw_disc_grad(lv_obj_t * obj, const lv_area_t * mask)
|
||||
static void draw_disc_grad(lv_obj_t * obj)
|
||||
{
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_coord_t w = lv_obj_get_width(obj);
|
||||
lv_coord_t h = lv_obj_get_height(obj);
|
||||
lv_coord_t cx = obj->coords.x1 + w / 2;
|
||||
@ -296,7 +277,7 @@ static void draw_disc_grad(lv_obj_t * obj, const lv_area_t * mask)
|
||||
p[1].x = cx + ((r - cir_w - cir_w_extra) * lv_trigo_sin(angle_trigo) >> LV_TRIGO_SHIFT);
|
||||
p[1].y = cy + ((r - cir_w - cir_w_extra) * lv_trigo_cos(angle_trigo) >> LV_TRIGO_SHIFT);
|
||||
|
||||
lv_draw_line(&p[0], &p[1], mask, &line_dsc);
|
||||
lv_draw_line(&p[0], &p[1], clip_area, &line_dsc);
|
||||
}
|
||||
|
||||
#if LV_DRAW_COMPLEX
|
||||
@ -305,8 +286,9 @@ static void draw_disc_grad(lv_obj_t * obj, const lv_area_t * mask)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void draw_knob(lv_obj_t * obj, const lv_area_t * mask)
|
||||
static void draw_knob(lv_obj_t * obj)
|
||||
{
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_colorwheel_t * colorwheel = (lv_colorwheel_t *)obj;
|
||||
|
||||
lv_draw_rect_dsc_t cir_dsc;
|
||||
@ -321,7 +303,7 @@ static void draw_knob(lv_obj_t * obj, const lv_area_t * mask)
|
||||
|
||||
lv_area_t knob_area = get_knob_area(obj);
|
||||
|
||||
lv_draw_rect(&knob_area, mask, &cir_dsc);
|
||||
lv_draw_rect(&knob_area, clip_area, &cir_dsc);
|
||||
}
|
||||
|
||||
static void invalidate_knob(lv_obj_t * obj)
|
||||
@ -522,6 +504,14 @@ static void lv_colorwheel_event(lv_obj_t * obj, lv_event_t e)
|
||||
/*Valid clicks can be only in the circle*/
|
||||
info->result = _lv_area_is_point_on(&obj->coords, info->point, LV_RADIUS_CIRCLE);
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_disc_grad(obj);
|
||||
draw_knob(obj);
|
||||
}
|
||||
else if(e == LV_EVENT_COVER_CHECK) {
|
||||
lv_cover_check_info_t * info = lv_event_get_param();
|
||||
if(info->res != LV_DRAW_RES_MASKED) info->res = LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_imgbtn_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static lv_draw_res_t lv_imgbtn_draw(lv_obj_t * imgbtn, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void draw_main(lv_obj_t * obj);
|
||||
static void lv_imgbtn_event(lv_obj_t * imgbtn, lv_event_t e);
|
||||
static void refr_img(lv_obj_t * imgbtn);
|
||||
static lv_imgbtn_state_t suggest_state(lv_obj_t * imgbtn, lv_imgbtn_state_t state);
|
||||
@ -38,7 +38,6 @@ const lv_obj_class_t lv_imgbtn_class = {
|
||||
.instance_size = sizeof(lv_imgbtn_t),
|
||||
.constructor_cb = lv_imgbtn_constructor,
|
||||
.event_cb = lv_imgbtn_event,
|
||||
.draw_cb = lv_imgbtn_draw,
|
||||
};
|
||||
|
||||
/**********************
|
||||
@ -164,114 +163,6 @@ static void lv_imgbtn_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
}
|
||||
|
||||
|
||||
static lv_draw_res_t lv_imgbtn_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
lv_imgbtn_t * imgbtn = (lv_imgbtn_t *)obj;
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return LV_DRAW_RES_NOT_COVER;
|
||||
|
||||
lv_draw_res_t cover = lv_obj_draw_base(&lv_imgbtn_class, obj, clip_area, mode);
|
||||
if(cover != LV_DRAW_RES_COVER) return cover;
|
||||
|
||||
if(imgbtn->act_cf == LV_IMG_CF_TRUE_COLOR || imgbtn->act_cf == LV_IMG_CF_RAW) {
|
||||
cover = _lv_area_is_in(clip_area, &obj->coords, 0) ? LV_DRAW_RES_COVER : LV_DRAW_RES_NOT_COVER;
|
||||
} else {
|
||||
cover = LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
|
||||
return cover;
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
|
||||
lv_obj_draw_base(&lv_imgbtn_class, obj, clip_area, mode);
|
||||
|
||||
/*Just draw an image*/
|
||||
lv_imgbtn_state_t state = suggest_state(obj, get_state(obj));
|
||||
|
||||
/*Simply draw the middle src if no tiled*/
|
||||
const void * src = imgbtn->img_src_left[state];
|
||||
if(lv_img_src_get_type(src) == LV_IMG_SRC_SYMBOL) {
|
||||
LV_LOG_WARN("lv_imgbtn_draw: SYMBOLS are not supported in tiled mode")
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
lv_coord_t tw = lv_obj_get_style_transform_width(obj, LV_PART_MAIN);
|
||||
lv_coord_t th = lv_obj_get_style_transform_height(obj, LV_PART_MAIN);
|
||||
lv_area_t coords;
|
||||
lv_area_copy(&coords, &obj->coords);
|
||||
coords.x1 -= tw;
|
||||
coords.x2 += tw;
|
||||
coords.y1 -= th;
|
||||
coords.y2 += th;
|
||||
|
||||
lv_draw_img_dsc_t img_dsc;
|
||||
lv_draw_img_dsc_init(&img_dsc);
|
||||
lv_obj_init_draw_img_dsc(obj, LV_PART_MAIN, &img_dsc);
|
||||
|
||||
lv_img_header_t header;
|
||||
lv_area_t coords_part;
|
||||
lv_coord_t left_w = 0;
|
||||
lv_coord_t right_w = 0;
|
||||
|
||||
if(src) {
|
||||
lv_img_decoder_get_info(src, &header);
|
||||
left_w = header.w;
|
||||
coords_part.x1 = coords.x1;
|
||||
coords_part.y1 = coords.y1;
|
||||
coords_part.x2 = coords.x1 + header.w - 1;
|
||||
coords_part.y2 = coords.y1 + header.h - 1;
|
||||
lv_draw_img(&coords_part, clip_area, src, &img_dsc);
|
||||
}
|
||||
|
||||
src = imgbtn->img_src_right[state];
|
||||
if(src) {
|
||||
lv_img_decoder_get_info(src, &header);
|
||||
right_w = header.w;
|
||||
coords_part.x1 = coords.x2 - header.w + 1;
|
||||
coords_part.y1 = coords.y1;
|
||||
coords_part.x2 = coords.x2;
|
||||
coords_part.y2 = coords.y1 + header.h - 1;
|
||||
lv_draw_img(&coords_part, clip_area, src, &img_dsc);
|
||||
}
|
||||
|
||||
src = imgbtn->img_src_mid[state];
|
||||
if(src) {
|
||||
lv_area_t clip_center_area;
|
||||
clip_center_area.x1 = coords.x1 + left_w;
|
||||
clip_center_area.x2 = coords.x2 - right_w;
|
||||
clip_center_area.y1 = coords.y1;
|
||||
clip_center_area.y2 = coords.y2;
|
||||
|
||||
bool comm_res;
|
||||
comm_res = _lv_area_intersect(&clip_center_area, &clip_center_area, clip_area);
|
||||
if(comm_res) {
|
||||
lv_coord_t i;
|
||||
lv_img_decoder_get_info(src, &header);
|
||||
|
||||
coords_part.x1 = coords.x1 + left_w;
|
||||
coords_part.y1 = coords.y1;
|
||||
coords_part.x2 = coords_part.x1 + header.w - 1;
|
||||
coords_part.y2 = coords_part.y1 + header.h - 1;
|
||||
|
||||
for(i = 0; i < clip_center_area.x2 + header.w - 1; i += header.w) {
|
||||
|
||||
lv_draw_img(&coords_part, &clip_center_area, src, &img_dsc);
|
||||
coords_part.x1 = coords_part.x2 + 1;
|
||||
coords_part.x2 += header.w;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(&lv_imgbtn_class, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_imgbtn_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res = lv_obj_event_base(&lv_imgbtn_class, obj, e);
|
||||
@ -280,6 +171,96 @@ static void lv_imgbtn_event(lv_obj_t * obj, lv_event_t e)
|
||||
if(e == LV_EVENT_PRESSED || e == LV_EVENT_RELEASED || e == LV_EVENT_PRESS_LOST) {
|
||||
refr_img(obj);
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_main(obj);
|
||||
}
|
||||
else if(e == LV_EVENT_COVER_CHECK) {
|
||||
lv_cover_check_info_t * info = lv_event_get_param();
|
||||
if(info->res != LV_DRAW_RES_MASKED) info->res = LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_main(lv_obj_t * obj)
|
||||
{
|
||||
lv_imgbtn_t * imgbtn = (lv_imgbtn_t *)obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
/*Just draw_main an image*/
|
||||
lv_imgbtn_state_t state = suggest_state(obj, get_state(obj));
|
||||
|
||||
/*Simply draw the middle src if no tiled*/
|
||||
const void * src = imgbtn->img_src_left[state];
|
||||
if(lv_img_src_get_type(src) == LV_IMG_SRC_SYMBOL) {
|
||||
LV_LOG_WARN("lv_imgbtn_draw: SYMBOLS are not supported in tiled mode")
|
||||
return;
|
||||
}
|
||||
|
||||
lv_coord_t tw = lv_obj_get_style_transform_width(obj, LV_PART_MAIN);
|
||||
lv_coord_t th = lv_obj_get_style_transform_height(obj, LV_PART_MAIN);
|
||||
lv_area_t coords;
|
||||
lv_area_copy(&coords, &obj->coords);
|
||||
coords.x1 -= tw;
|
||||
coords.x2 += tw;
|
||||
coords.y1 -= th;
|
||||
coords.y2 += th;
|
||||
|
||||
lv_draw_img_dsc_t img_dsc;
|
||||
lv_draw_img_dsc_init(&img_dsc);
|
||||
lv_obj_init_draw_img_dsc(obj, LV_PART_MAIN, &img_dsc);
|
||||
|
||||
lv_img_header_t header;
|
||||
lv_area_t coords_part;
|
||||
lv_coord_t left_w = 0;
|
||||
lv_coord_t right_w = 0;
|
||||
|
||||
if(src) {
|
||||
lv_img_decoder_get_info(src, &header);
|
||||
left_w = header.w;
|
||||
coords_part.x1 = coords.x1;
|
||||
coords_part.y1 = coords.y1;
|
||||
coords_part.x2 = coords.x1 + header.w - 1;
|
||||
coords_part.y2 = coords.y1 + header.h - 1;
|
||||
lv_draw_img(&coords_part, clip_area, src, &img_dsc);
|
||||
}
|
||||
|
||||
src = imgbtn->img_src_right[state];
|
||||
if(src) {
|
||||
lv_img_decoder_get_info(src, &header);
|
||||
right_w = header.w;
|
||||
coords_part.x1 = coords.x2 - header.w + 1;
|
||||
coords_part.y1 = coords.y1;
|
||||
coords_part.x2 = coords.x2;
|
||||
coords_part.y2 = coords.y1 + header.h - 1;
|
||||
lv_draw_img(&coords_part, clip_area, src, &img_dsc);
|
||||
}
|
||||
|
||||
src = imgbtn->img_src_mid[state];
|
||||
if(src) {
|
||||
lv_area_t clip_center_area;
|
||||
clip_center_area.x1 = coords.x1 + left_w;
|
||||
clip_center_area.x2 = coords.x2 - right_w;
|
||||
clip_center_area.y1 = coords.y1;
|
||||
clip_center_area.y2 = coords.y2;
|
||||
|
||||
bool comm_res;
|
||||
comm_res = _lv_area_intersect(&clip_center_area, &clip_center_area, clip_area);
|
||||
if(comm_res) {
|
||||
lv_coord_t i;
|
||||
lv_img_decoder_get_info(src, &header);
|
||||
|
||||
coords_part.x1 = coords.x1 + left_w;
|
||||
coords_part.y1 = coords.y1;
|
||||
coords_part.x2 = coords_part.x1 + header.w - 1;
|
||||
coords_part.y2 = coords_part.y1 + header.h - 1;
|
||||
|
||||
for(i = 0; i < clip_center_area.x2 + header.w - 1; i += header.w) {
|
||||
|
||||
lv_draw_img(&coords_part, &clip_center_area, src, &img_dsc);
|
||||
coords_part.x1 = coords_part.x2 + 1;
|
||||
coords_part.x2 += header.w;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void refr_img(lv_obj_t * obj)
|
||||
|
@ -12,6 +12,7 @@
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
#define MY_CLASS &lv_led_class
|
||||
|
||||
#define LV_LED_WIDTH_DEF (LV_DPI_DEF / 5)
|
||||
#define LV_LED_HEIGHT_DEF (LV_DPI_DEF / 5)
|
||||
@ -32,7 +33,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_led_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static lv_draw_res_t lv_led_draw(lv_obj_t * led, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_led_event(lv_obj_t * obj, lv_event_t e);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -40,7 +41,7 @@ static lv_draw_res_t lv_led_draw(lv_obj_t * led, const lv_area_t * clip_area, lv
|
||||
const lv_obj_class_t lv_led_class = {
|
||||
.base_class = &lv_obj_class,
|
||||
.constructor_cb = lv_led_constructor,
|
||||
.draw_cb = lv_led_draw,
|
||||
.event_cb = lv_led_event,
|
||||
.instance_size = sizeof(lv_led_t),
|
||||
};
|
||||
|
||||
@ -159,14 +160,15 @@ static void lv_led_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
lv_obj_set_size(obj, LV_LED_WIDTH_DEF, LV_LED_HEIGHT_DEF);
|
||||
}
|
||||
|
||||
|
||||
static lv_draw_res_t lv_led_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
static void lv_led_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
/*Return false if the object is not covers the clip_area area*/
|
||||
return lv_obj_draw_base(&lv_led_class, obj, clip_area, mode);
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = lv_obj_event_base(MY_CLASS, obj, e);
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
if(e == LV_EVENT_DRAW_MAIN) {
|
||||
/*Make darker colors in a temporary style according to the brightness*/
|
||||
lv_led_t * led = (lv_led_t *)obj;
|
||||
|
||||
@ -191,12 +193,13 @@ static lv_draw_res_t lv_led_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv
|
||||
/*Set the current shadow width according to brightness proportionally between LV_LED_BRIGHT_OFF
|
||||
* and LV_LED_BRIGHT_ON*/
|
||||
rect_dsc.shadow_width = ((led->bright - LV_LED_BRIGHT_MIN) * rect_dsc.shadow_width) /
|
||||
(LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN);
|
||||
(LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN);
|
||||
rect_dsc.shadow_spread = ((led->bright - LV_LED_BRIGHT_MIN) * rect_dsc.shadow_spread) /
|
||||
(LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN);
|
||||
(LV_LED_BRIGHT_MAX - LV_LED_BRIGHT_MIN);
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_draw_rect(&obj->coords, clip_area, &rect_dsc);
|
||||
}
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -31,7 +31,7 @@
|
||||
**********************/
|
||||
|
||||
static void lv_arc_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static lv_draw_res_t lv_arc_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_arc_draw(lv_obj_t * obj);
|
||||
static void lv_arc_event(lv_obj_t * obj, lv_event_t e);
|
||||
static void inv_arc_area(lv_obj_t * arc, uint16_t start_angle, uint16_t end_angle, uint8_t part);
|
||||
static void get_center(lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r);
|
||||
@ -44,7 +44,6 @@ static void value_update(lv_obj_t * arc);
|
||||
const lv_obj_class_t lv_arc_class = {
|
||||
.constructor_cb = lv_arc_constructor,
|
||||
.event_cb = lv_arc_event,
|
||||
.draw_cb = lv_arc_draw,
|
||||
.instance_size = sizeof(lv_arc_t),
|
||||
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
|
||||
.base_class = &lv_obj_class
|
||||
@ -530,67 +529,6 @@ static void lv_arc_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
LV_TRACE_OBJ_CREATE("finished");
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_arc_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
|
||||
lv_point_t center;
|
||||
lv_coord_t arc_r;
|
||||
get_center(obj, ¢er, &arc_r);
|
||||
|
||||
/*Draw the background arc*/
|
||||
lv_draw_arc_dsc_t arc_dsc;
|
||||
if(arc_r > 0) {
|
||||
lv_draw_arc_dsc_init(&arc_dsc);
|
||||
lv_obj_init_draw_arc_dsc(obj, LV_PART_MAIN, &arc_dsc);
|
||||
|
||||
lv_draw_arc(center.x, center.y, arc_r,arc->bg_angle_start +arc->rotation,
|
||||
arc->bg_angle_end + arc->rotation, clip_area,
|
||||
&arc_dsc);
|
||||
}
|
||||
|
||||
/*make the indicator arc smaller or larger according to its greatest padding value*/
|
||||
lv_coord_t left_indic = lv_obj_get_style_pad_left(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t right_indic = lv_obj_get_style_pad_right(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t top_indic = lv_obj_get_style_pad_top(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t bottom_indic = lv_obj_get_style_pad_bottom(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t indic_r = arc_r - LV_MAX4(left_indic, right_indic, top_indic, bottom_indic);
|
||||
|
||||
if(indic_r > 0) {
|
||||
lv_draw_arc_dsc_init(&arc_dsc);
|
||||
lv_obj_init_draw_arc_dsc(obj, LV_PART_INDICATOR, &arc_dsc);
|
||||
|
||||
lv_draw_arc(center.x, center.y, indic_r,arc->indic_angle_start +arc->rotation,
|
||||
arc->indic_angle_end +arc->rotation, clip_area,
|
||||
&arc_dsc);
|
||||
}
|
||||
|
||||
lv_area_t knob_area;
|
||||
get_knob_area(obj, ¢er, arc_r, &knob_area);
|
||||
|
||||
lv_draw_rect_dsc_t knob_rect_dsc;
|
||||
lv_draw_rect_dsc_init(&knob_rect_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc);
|
||||
|
||||
lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc);
|
||||
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_arc_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
@ -747,9 +685,59 @@ static void lv_arc_event(lv_obj_t * obj, lv_event_t e)
|
||||
|
||||
lv_coord_t * s = lv_event_get_param();
|
||||
*s = LV_MAX(*s, knob_pad - bg_pad);
|
||||
} else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_arc_draw(obj);
|
||||
}
|
||||
}
|
||||
|
||||
static void lv_arc_draw(lv_obj_t * obj)
|
||||
{
|
||||
lv_arc_t * arc = (lv_arc_t *)obj;
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
lv_point_t center;
|
||||
lv_coord_t arc_r;
|
||||
get_center(obj, ¢er, &arc_r);
|
||||
|
||||
/*Draw the background arc*/
|
||||
lv_draw_arc_dsc_t arc_dsc;
|
||||
if(arc_r > 0) {
|
||||
lv_draw_arc_dsc_init(&arc_dsc);
|
||||
lv_obj_init_draw_arc_dsc(obj, LV_PART_MAIN, &arc_dsc);
|
||||
|
||||
lv_draw_arc(center.x, center.y, arc_r,arc->bg_angle_start +arc->rotation,
|
||||
arc->bg_angle_end + arc->rotation, clip_area,
|
||||
&arc_dsc);
|
||||
}
|
||||
|
||||
/*make the indicator arc smaller or larger according to its greatest padding value*/
|
||||
lv_coord_t left_indic = lv_obj_get_style_pad_left(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t right_indic = lv_obj_get_style_pad_right(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t top_indic = lv_obj_get_style_pad_top(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t bottom_indic = lv_obj_get_style_pad_bottom(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t indic_r = arc_r - LV_MAX4(left_indic, right_indic, top_indic, bottom_indic);
|
||||
|
||||
if(indic_r > 0) {
|
||||
lv_draw_arc_dsc_init(&arc_dsc);
|
||||
lv_obj_init_draw_arc_dsc(obj, LV_PART_INDICATOR, &arc_dsc);
|
||||
|
||||
lv_draw_arc(center.x, center.y, indic_r,arc->indic_angle_start +arc->rotation,
|
||||
arc->indic_angle_end +arc->rotation, clip_area,
|
||||
&arc_dsc);
|
||||
}
|
||||
|
||||
lv_area_t knob_area;
|
||||
get_knob_area(obj, ¢er, arc_r, &knob_area);
|
||||
|
||||
lv_draw_rect_dsc_t knob_rect_dsc;
|
||||
lv_draw_rect_dsc_init(&knob_rect_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc);
|
||||
|
||||
lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc);
|
||||
}
|
||||
|
||||
static void inv_arc_area(lv_obj_t * obj, uint16_t start_angle, uint16_t end_angle, uint8_t part)
|
||||
{
|
||||
LV_ASSERT_OBJ(obj, MY_CLASS);
|
||||
|
@ -47,9 +47,8 @@
|
||||
**********************/
|
||||
static void lv_bar_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_bar_destructor(lv_obj_t * obj);
|
||||
static lv_draw_res_t lv_bar_draw(lv_obj_t * bar, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_bar_event(lv_obj_t * bar, lv_event_t e);
|
||||
static void draw_indic(lv_obj_t * bar, const lv_area_t * clip_area);
|
||||
static void draw_indic(lv_obj_t * bar);
|
||||
static void lv_bar_set_value_with_anim(lv_obj_t * obj, int16_t new_value, int16_t * value_ptr,
|
||||
lv_bar_anim_t * anim_info, lv_anim_enable_t en);
|
||||
static void lv_bar_init_anim(lv_obj_t * bar, lv_bar_anim_t * bar_anim);
|
||||
@ -63,7 +62,6 @@ const lv_obj_class_t lv_bar_class = {
|
||||
.constructor_cb = lv_bar_constructor,
|
||||
.destructor_cb = lv_bar_destructor,
|
||||
.event_cb = lv_bar_event,
|
||||
.draw_cb = lv_bar_draw,
|
||||
.instance_size = sizeof(lv_bar_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -240,27 +238,12 @@ static void lv_bar_destructor(lv_obj_t * obj)
|
||||
lv_anim_del(&bar->start_value_anim, NULL);
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_bar_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
/*Return false if the object is not covers the mask area*/
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
/*Draw the background*/
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
draw_indic(obj, clip_area);
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void draw_indic(lv_obj_t * obj, const lv_area_t * clip_area)
|
||||
static void draw_indic(lv_obj_t * obj)
|
||||
{
|
||||
lv_bar_t * bar = (lv_bar_t *)obj;
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
lv_area_t bar_coords;
|
||||
lv_obj_get_coords(obj, &bar_coords);
|
||||
|
||||
@ -528,6 +511,8 @@ static void lv_bar_event(lv_obj_t * obj, lv_event_t e)
|
||||
if(pad < 0) {
|
||||
*s = LV_MAX(*s, -pad);
|
||||
}
|
||||
} else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_indic(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
static void lv_btnmatrix_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_btnmatrix_destructor(lv_obj_t * obj);
|
||||
static void lv_btnmatrix_event(lv_obj_t * obj, lv_event_t e);
|
||||
static lv_draw_res_t lv_btnmatrix_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void draw_main(lv_obj_t * obj);
|
||||
|
||||
static uint8_t get_button_width(lv_btnmatrix_ctrl_t ctrl_bits);
|
||||
static bool button_is_hidden(lv_btnmatrix_ctrl_t ctrl_bits);
|
||||
@ -58,7 +58,6 @@ const lv_obj_class_t lv_btnmatrix_class = {
|
||||
.constructor_cb = lv_btnmatrix_constructor,
|
||||
.destructor_cb = lv_btnmatrix_destructor,
|
||||
.event_cb = lv_btnmatrix_event,
|
||||
.draw_cb = lv_btnmatrix_draw,
|
||||
.instance_size = sizeof(lv_btnmatrix_t),
|
||||
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
|
||||
.base_class = &lv_obj_class
|
||||
@ -390,166 +389,6 @@ static void lv_btnmatrix_destructor(lv_obj_t * obj)
|
||||
btnm->ctrl_bits = NULL;
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_btnmatrix_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
|
||||
if(btnm->btn_cnt == 0) return LV_DRAW_RES_OK;
|
||||
|
||||
obj->style_list.skip_trans = 1;
|
||||
|
||||
lv_area_t area_obj;
|
||||
lv_obj_get_coords(obj, &area_obj);
|
||||
|
||||
lv_area_t btn_area;
|
||||
|
||||
uint16_t btn_i = 0;
|
||||
uint16_t txt_i = 0;
|
||||
|
||||
lv_draw_rect_dsc_t draw_rect_dsc_act;
|
||||
lv_draw_label_dsc_t draw_label_dsc_act;
|
||||
|
||||
lv_draw_rect_dsc_t draw_rect_dsc_def;
|
||||
lv_draw_label_dsc_t draw_label_dsc_def;
|
||||
|
||||
lv_text_flag_t recolor_flag = btnm->recolor ? LV_TEXT_FLAG_RECOLOR : 0;
|
||||
|
||||
lv_state_t state_ori = obj->state;
|
||||
obj->state = LV_STATE_DEFAULT;
|
||||
obj->style_list.skip_trans = 1;
|
||||
lv_draw_rect_dsc_init(&draw_rect_dsc_def);
|
||||
lv_draw_label_dsc_init(&draw_label_dsc_def);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &draw_rect_dsc_def);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_ITEMS, &draw_label_dsc_def);
|
||||
draw_label_dsc_act.flag |= recolor_flag;
|
||||
obj->style_list.skip_trans = 0;
|
||||
obj->state = state_ori;
|
||||
|
||||
lv_coord_t ptop = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t pbottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
lv_coord_t pleft = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t pright = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
|
||||
#if LV_USE_ARABIC_PERSIAN_CHARS
|
||||
const size_t txt_ap_size = 256 ;
|
||||
char * txt_ap = lv_mem_buf_get(txt_ap_size);
|
||||
#endif
|
||||
|
||||
lv_obj_draw_dsc_t dsc;
|
||||
lv_obj_draw_dsc_init(&dsc, clip_area);
|
||||
dsc.part = LV_PART_ITEMS;
|
||||
dsc.rect_dsc = &draw_rect_dsc_act;
|
||||
dsc.label_dsc = &draw_label_dsc_act;
|
||||
|
||||
for(btn_i = 0; btn_i < btnm->btn_cnt; btn_i++, txt_i++) {
|
||||
/*Search the next valid text in the map*/
|
||||
while(strcmp(btnm->map_p[txt_i], "\n") == 0) {
|
||||
txt_i++;
|
||||
}
|
||||
|
||||
/*Skip hidden buttons*/
|
||||
if(button_is_hidden(btnm->ctrl_bits[btn_i])) continue;
|
||||
|
||||
/*Get the state of the button*/
|
||||
lv_state_t btn_state = LV_STATE_DEFAULT;
|
||||
if(button_get_checked(btnm->ctrl_bits[btn_i])) btn_state |= LV_STATE_CHECKED;
|
||||
if(button_is_inactive(btnm->ctrl_bits[btn_i])) btn_state |= LV_STATE_DISABLED;
|
||||
if(btn_i == btnm->btn_id_sel) {
|
||||
if(state_ori & LV_STATE_PRESSED) btn_state |= LV_STATE_PRESSED;
|
||||
if(state_ori & LV_STATE_FOCUSED) btn_state |= LV_STATE_FOCUSED;
|
||||
if(state_ori & LV_STATE_FOCUS_KEY) btn_state |= LV_STATE_FOCUS_KEY;
|
||||
if(state_ori & LV_STATE_EDITED) btn_state |= LV_STATE_EDITED;
|
||||
}
|
||||
|
||||
/*Get the button's area*/
|
||||
lv_area_copy(&btn_area, &btnm->button_areas[btn_i]);
|
||||
btn_area.x1 += area_obj.x1;
|
||||
btn_area.y1 += area_obj.y1;
|
||||
btn_area.x2 += area_obj.x1;
|
||||
btn_area.y2 += area_obj.y1;
|
||||
|
||||
/*Set up the draw descriptors*/
|
||||
if(btn_state == LV_STATE_DEFAULT) {
|
||||
lv_memcpy(&draw_rect_dsc_act, &draw_rect_dsc_def, sizeof(lv_draw_rect_dsc_t));
|
||||
lv_memcpy(&draw_label_dsc_act, &draw_label_dsc_def, sizeof(lv_draw_label_dsc_t));
|
||||
}
|
||||
/*In other cases get the styles directly without caching them*/
|
||||
else {
|
||||
obj->state = btn_state;
|
||||
obj->style_list.skip_trans = 1;
|
||||
lv_draw_rect_dsc_init(&draw_rect_dsc_act);
|
||||
lv_draw_label_dsc_init(&draw_label_dsc_act);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &draw_rect_dsc_act);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_ITEMS, &draw_label_dsc_act);
|
||||
draw_label_dsc_act.flag = recolor_flag;
|
||||
obj->state = state_ori;
|
||||
obj->style_list.skip_trans = 0;
|
||||
}
|
||||
|
||||
dsc.draw_area = &btn_area;
|
||||
dsc.id = btn_i;
|
||||
lv_event_send(obj,LV_EVENT_DRAW_PART_BEGIN, &dsc);
|
||||
|
||||
/*Remove borders on the edges if `LV_BORDER_SIDE_INTERNAL`*/
|
||||
if(draw_rect_dsc_act.border_side & LV_BORDER_SIDE_INTERNAL) {
|
||||
draw_rect_dsc_act.border_side = LV_BORDER_SIDE_FULL;
|
||||
if(btn_area.x1 == obj->coords.x1 + pleft) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_LEFT;
|
||||
if(btn_area.x2 == obj->coords.x2 - pright) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_RIGHT;
|
||||
if(btn_area.y1 == obj->coords.y1 + ptop) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_TOP;
|
||||
if(btn_area.y2 == obj->coords.y2 - pbottom) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_BOTTOM;
|
||||
}
|
||||
|
||||
/*Draw the background*/
|
||||
lv_draw_rect(&btn_area, clip_area, &draw_rect_dsc_act);
|
||||
|
||||
/*Calculate the size of the text*/
|
||||
const lv_font_t * font = draw_label_dsc_act.font;
|
||||
lv_coord_t letter_space = draw_label_dsc_act.letter_space;
|
||||
lv_coord_t line_space = draw_label_dsc_act.line_space;
|
||||
const char * txt = btnm->map_p[txt_i];
|
||||
|
||||
#if LV_USE_ARABIC_PERSIAN_CHARS
|
||||
/*Get the size of the Arabic text and process it*/
|
||||
size_t len_ap = _lv_txt_ap_calc_bytes_cnt(txt);
|
||||
if(len_ap < txt_ap_size) {
|
||||
_lv_txt_ap_proc(txt, txt_ap);
|
||||
txt = txt_ap;
|
||||
}
|
||||
#endif
|
||||
|
||||
lv_point_t txt_size;
|
||||
lv_txt_get_size(&txt_size, txt, font, letter_space,
|
||||
line_space, lv_area_get_width(&area_obj), recolor_flag);
|
||||
|
||||
btn_area.x1 += (lv_area_get_width(&btn_area) - txt_size.x) / 2;
|
||||
btn_area.y1 += (lv_area_get_height(&btn_area) - txt_size.y) / 2;
|
||||
btn_area.x2 = btn_area.x1 + txt_size.x;
|
||||
btn_area.y2 = btn_area.y1 + txt_size.y;
|
||||
|
||||
/*Draw the text*/
|
||||
lv_draw_label(&btn_area, clip_area, &draw_label_dsc_act, txt, NULL);
|
||||
|
||||
|
||||
lv_event_send(obj,LV_EVENT_DRAW_PART_END, &dsc);
|
||||
}
|
||||
|
||||
obj->style_list.skip_trans = 0;
|
||||
#if LV_USE_ARABIC_PERSIAN_CHARS
|
||||
lv_mem_buf_release(txt_ap);
|
||||
#endif
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_btnmatrix_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
@ -795,9 +634,160 @@ static void lv_btnmatrix_event(lv_obj_t * obj, lv_event_t e)
|
||||
}
|
||||
|
||||
invalidate_button_area(obj, btnm->btn_id_sel);
|
||||
} else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_main(obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void draw_main(lv_obj_t * obj)
|
||||
{
|
||||
lv_btnmatrix_t * btnm = (lv_btnmatrix_t *)obj;
|
||||
if(btnm->btn_cnt == 0) return;
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
obj->style_list.skip_trans = 1;
|
||||
|
||||
lv_area_t area_obj;
|
||||
lv_obj_get_coords(obj, &area_obj);
|
||||
|
||||
lv_area_t btn_area;
|
||||
|
||||
uint16_t btn_i = 0;
|
||||
uint16_t txt_i = 0;
|
||||
|
||||
lv_draw_rect_dsc_t draw_rect_dsc_act;
|
||||
lv_draw_label_dsc_t draw_label_dsc_act;
|
||||
|
||||
lv_draw_rect_dsc_t draw_rect_dsc_def;
|
||||
lv_draw_label_dsc_t draw_label_dsc_def;
|
||||
|
||||
lv_text_flag_t recolor_flag = btnm->recolor ? LV_TEXT_FLAG_RECOLOR : 0;
|
||||
|
||||
lv_state_t state_ori = obj->state;
|
||||
obj->state = LV_STATE_DEFAULT;
|
||||
obj->style_list.skip_trans = 1;
|
||||
lv_draw_rect_dsc_init(&draw_rect_dsc_def);
|
||||
lv_draw_label_dsc_init(&draw_label_dsc_def);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &draw_rect_dsc_def);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_ITEMS, &draw_label_dsc_def);
|
||||
draw_label_dsc_act.flag |= recolor_flag;
|
||||
obj->style_list.skip_trans = 0;
|
||||
obj->state = state_ori;
|
||||
|
||||
lv_coord_t ptop = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t pbottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
lv_coord_t pleft = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t pright = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
|
||||
#if LV_USE_ARABIC_PERSIAN_CHARS
|
||||
const size_t txt_ap_size = 256 ;
|
||||
char * txt_ap = lv_mem_buf_get(txt_ap_size);
|
||||
#endif
|
||||
|
||||
lv_obj_draw_dsc_t dsc;
|
||||
lv_obj_draw_dsc_init(&dsc, clip_area);
|
||||
dsc.part = LV_PART_ITEMS;
|
||||
dsc.rect_dsc = &draw_rect_dsc_act;
|
||||
dsc.label_dsc = &draw_label_dsc_act;
|
||||
|
||||
for(btn_i = 0; btn_i < btnm->btn_cnt; btn_i++, txt_i++) {
|
||||
/*Search the next valid text in the map*/
|
||||
while(strcmp(btnm->map_p[txt_i], "\n") == 0) {
|
||||
txt_i++;
|
||||
}
|
||||
|
||||
/*Skip hidden buttons*/
|
||||
if(button_is_hidden(btnm->ctrl_bits[btn_i])) continue;
|
||||
|
||||
/*Get the state of the button*/
|
||||
lv_state_t btn_state = LV_STATE_DEFAULT;
|
||||
if(button_get_checked(btnm->ctrl_bits[btn_i])) btn_state |= LV_STATE_CHECKED;
|
||||
if(button_is_inactive(btnm->ctrl_bits[btn_i])) btn_state |= LV_STATE_DISABLED;
|
||||
if(btn_i == btnm->btn_id_sel) {
|
||||
if(state_ori & LV_STATE_PRESSED) btn_state |= LV_STATE_PRESSED;
|
||||
if(state_ori & LV_STATE_FOCUSED) btn_state |= LV_STATE_FOCUSED;
|
||||
if(state_ori & LV_STATE_FOCUS_KEY) btn_state |= LV_STATE_FOCUS_KEY;
|
||||
if(state_ori & LV_STATE_EDITED) btn_state |= LV_STATE_EDITED;
|
||||
}
|
||||
|
||||
/*Get the button's area*/
|
||||
lv_area_copy(&btn_area, &btnm->button_areas[btn_i]);
|
||||
btn_area.x1 += area_obj.x1;
|
||||
btn_area.y1 += area_obj.y1;
|
||||
btn_area.x2 += area_obj.x1;
|
||||
btn_area.y2 += area_obj.y1;
|
||||
|
||||
/*Set up the draw descriptors*/
|
||||
if(btn_state == LV_STATE_DEFAULT) {
|
||||
lv_memcpy(&draw_rect_dsc_act, &draw_rect_dsc_def, sizeof(lv_draw_rect_dsc_t));
|
||||
lv_memcpy(&draw_label_dsc_act, &draw_label_dsc_def, sizeof(lv_draw_label_dsc_t));
|
||||
}
|
||||
/*In other cases get the styles directly without caching them*/
|
||||
else {
|
||||
obj->state = btn_state;
|
||||
obj->style_list.skip_trans = 1;
|
||||
lv_draw_rect_dsc_init(&draw_rect_dsc_act);
|
||||
lv_draw_label_dsc_init(&draw_label_dsc_act);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &draw_rect_dsc_act);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_ITEMS, &draw_label_dsc_act);
|
||||
draw_label_dsc_act.flag = recolor_flag;
|
||||
obj->state = state_ori;
|
||||
obj->style_list.skip_trans = 0;
|
||||
}
|
||||
|
||||
dsc.draw_area = &btn_area;
|
||||
dsc.id = btn_i;
|
||||
lv_event_send(obj,LV_EVENT_DRAW_PART_BEGIN, &dsc);
|
||||
|
||||
/*Remove borders on the edges if `LV_BORDER_SIDE_INTERNAL`*/
|
||||
if(draw_rect_dsc_act.border_side & LV_BORDER_SIDE_INTERNAL) {
|
||||
draw_rect_dsc_act.border_side = LV_BORDER_SIDE_FULL;
|
||||
if(btn_area.x1 == obj->coords.x1 + pleft) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_LEFT;
|
||||
if(btn_area.x2 == obj->coords.x2 - pright) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_RIGHT;
|
||||
if(btn_area.y1 == obj->coords.y1 + ptop) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_TOP;
|
||||
if(btn_area.y2 == obj->coords.y2 - pbottom) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_BOTTOM;
|
||||
}
|
||||
|
||||
/*Draw the background*/
|
||||
lv_draw_rect(&btn_area, clip_area, &draw_rect_dsc_act);
|
||||
|
||||
/*Calculate the size of the text*/
|
||||
const lv_font_t * font = draw_label_dsc_act.font;
|
||||
lv_coord_t letter_space = draw_label_dsc_act.letter_space;
|
||||
lv_coord_t line_space = draw_label_dsc_act.line_space;
|
||||
const char * txt = btnm->map_p[txt_i];
|
||||
|
||||
#if LV_USE_ARABIC_PERSIAN_CHARS
|
||||
/*Get the size of the Arabic text and process it*/
|
||||
size_t len_ap = _lv_txt_ap_calc_bytes_cnt(txt);
|
||||
if(len_ap < txt_ap_size) {
|
||||
_lv_txt_ap_proc(txt, txt_ap);
|
||||
txt = txt_ap;
|
||||
}
|
||||
#endif
|
||||
|
||||
lv_point_t txt_size;
|
||||
lv_txt_get_size(&txt_size, txt, font, letter_space,
|
||||
line_space, lv_area_get_width(&area_obj), recolor_flag);
|
||||
|
||||
btn_area.x1 += (lv_area_get_width(&btn_area) - txt_size.x) / 2;
|
||||
btn_area.y1 += (lv_area_get_height(&btn_area) - txt_size.y) / 2;
|
||||
btn_area.x2 = btn_area.x1 + txt_size.x;
|
||||
btn_area.y2 = btn_area.y1 + txt_size.y;
|
||||
|
||||
/*Draw the text*/
|
||||
lv_draw_label(&btn_area, clip_area, &draw_label_dsc_act, txt, NULL);
|
||||
|
||||
|
||||
lv_event_send(obj,LV_EVENT_DRAW_PART_END, &dsc);
|
||||
}
|
||||
|
||||
obj->style_list.skip_trans = 0;
|
||||
#if LV_USE_ARABIC_PERSIAN_CHARS
|
||||
lv_mem_buf_release(txt_ap);
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
* Create the required number of buttons and control bytes according to a map
|
||||
* @param obj pointer to button matrix object
|
||||
|
@ -38,7 +38,6 @@
|
||||
**********************/
|
||||
static void lv_chart_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_chart_destructor(lv_obj_t * obj);
|
||||
static lv_draw_res_t lv_chart_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_chart_event(lv_obj_t * obj, lv_event_t e);
|
||||
|
||||
static void draw_div_lines(lv_obj_t * obj , const lv_area_t * mask);
|
||||
@ -56,7 +55,6 @@ const lv_obj_class_t lv_chart_class = {
|
||||
.constructor_cb = lv_chart_constructor,
|
||||
.destructor_cb = lv_chart_destructor,
|
||||
.event_cb = lv_chart_event,
|
||||
.draw_cb = lv_chart_draw,
|
||||
.instance_size = sizeof(lv_chart_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -619,29 +617,6 @@ static void lv_chart_destructor(lv_obj_t * obj)
|
||||
_lv_ll_clear(&chart->series_ll);
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_chart_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
draw_div_lines(obj, clip_area);
|
||||
draw_axes(obj, clip_area);
|
||||
|
||||
lv_chart_t * chart = (lv_chart_t *)obj;
|
||||
if(chart->type & LV_CHART_TYPE_LINE) draw_series_line(obj, clip_area);
|
||||
else if(chart->type & LV_CHART_TYPE_BAR) draw_series_bar(obj, clip_area);
|
||||
|
||||
draw_cursors(obj, clip_area);
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_chart_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
/* Include the ancient signal function */
|
||||
@ -670,6 +645,16 @@ static void lv_chart_event(lv_obj_t * obj, lv_event_t e)
|
||||
lv_coord_t * s = lv_event_get_param();
|
||||
*s = LV_MAX4(*s, chart->tick[LV_CHART_AXIS_X].draw_size,
|
||||
chart->tick[LV_CHART_AXIS_PRIMARY_Y].draw_size, chart->tick[LV_CHART_AXIS_SECONDARY_Y].draw_size);
|
||||
} else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
draw_div_lines(obj, clip_area);
|
||||
draw_axes(obj, clip_area);
|
||||
|
||||
lv_chart_t * chart = (lv_chart_t *)obj;
|
||||
if(chart->type & LV_CHART_TYPE_LINE) draw_series_line(obj, clip_area);
|
||||
else if(chart->type & LV_CHART_TYPE_BAR) draw_series_bar(obj, clip_area);
|
||||
|
||||
draw_cursors(obj, clip_area);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,8 +28,8 @@
|
||||
**********************/
|
||||
static void lv_checkbox_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_checkbox_destructor(lv_obj_t * obj);
|
||||
static lv_draw_res_t lv_checkbox_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_checkbox_event(lv_obj_t * obj, lv_event_t e);
|
||||
static void lv_checkbox_draw(lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -38,7 +38,6 @@ const lv_obj_class_t lv_checkbox_class = {
|
||||
.constructor_cb = lv_checkbox_constructor,
|
||||
.destructor_cb = lv_checkbox_destructor,
|
||||
.event_cb = lv_checkbox_event,
|
||||
.draw_cb = lv_checkbox_draw,
|
||||
.instance_size = sizeof(lv_checkbox_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -139,75 +138,6 @@ static void lv_checkbox_destructor(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_checkbox_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/* A label never covers an area */
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK)
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
/*Draw the background*/
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
lv_checkbox_t * cb = (lv_checkbox_t *)obj;
|
||||
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
lv_coord_t font_h = lv_font_get_line_height(font);
|
||||
|
||||
lv_coord_t bg_topp = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_leftp = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_colp = lv_obj_get_style_pad_column(obj, LV_PART_MAIN);
|
||||
|
||||
lv_coord_t marker_leftp = lv_obj_get_style_pad_left(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t marker_rightp = lv_obj_get_style_pad_right(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t marker_topp = lv_obj_get_style_pad_top(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t marker_bottomp = lv_obj_get_style_pad_bottom(obj, LV_PART_INDICATOR);
|
||||
|
||||
lv_coord_t transf_w = lv_obj_get_style_transform_width(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t transf_h = lv_obj_get_style_transform_height(obj, LV_PART_INDICATOR);
|
||||
|
||||
lv_draw_rect_dsc_t marker_dsc;
|
||||
lv_draw_rect_dsc_init(&marker_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_INDICATOR, &marker_dsc);
|
||||
lv_area_t marker_area;
|
||||
marker_area.x1 = obj->coords.x1 + bg_leftp;
|
||||
marker_area.x2 = marker_area.x1 + font_h + marker_leftp + marker_rightp - 1;
|
||||
marker_area.y1 = obj->coords.y1 + bg_topp;
|
||||
marker_area.y2 = marker_area.y1 + font_h + marker_topp + marker_bottomp - 1;
|
||||
|
||||
lv_area_t marker_area_transf;
|
||||
lv_area_copy(&marker_area_transf, &marker_area);
|
||||
marker_area_transf.x1 -= transf_w;
|
||||
marker_area_transf.x2 += transf_w;
|
||||
marker_area_transf.y1 -= transf_h;
|
||||
marker_area_transf.y2 += transf_h;
|
||||
|
||||
lv_draw_rect(&marker_area_transf, clip_area, &marker_dsc);
|
||||
|
||||
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
|
||||
lv_coord_t letter_space = lv_obj_get_style_text_letter_space(obj, LV_PART_MAIN);
|
||||
|
||||
lv_point_t txt_size;
|
||||
lv_txt_get_size(&txt_size, cb->txt, font, letter_space, line_space, LV_COORD_MAX, LV_TEXT_FLAG_NONE);
|
||||
|
||||
lv_draw_label_dsc_t txt_dsc;
|
||||
lv_draw_label_dsc_init(&txt_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &txt_dsc);
|
||||
|
||||
lv_coord_t y_ofs = (lv_area_get_height(&marker_area) - font_h) / 2;
|
||||
lv_area_t txt_area;
|
||||
txt_area.x1 = marker_area.x2 + bg_colp;
|
||||
txt_area.x2 = txt_area.x1 + txt_size.x;
|
||||
txt_area.y1 = obj->coords.y1 + bg_topp + y_ofs;
|
||||
txt_area.y2 = txt_area.y1 + txt_size.y;
|
||||
|
||||
lv_draw_label(&txt_area, clip_area, &txt_dsc, cb->txt, NULL);
|
||||
} else {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_checkbox_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
@ -251,7 +181,66 @@ static void lv_checkbox_event(lv_obj_t * obj, lv_event_t e)
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
lv_obj_invalidate(obj);
|
||||
} else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
lv_checkbox_draw(obj);
|
||||
}
|
||||
}
|
||||
|
||||
static void lv_checkbox_draw(lv_obj_t * obj)
|
||||
{
|
||||
lv_checkbox_t * cb = (lv_checkbox_t *)obj;
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
lv_coord_t font_h = lv_font_get_line_height(font);
|
||||
|
||||
lv_coord_t bg_topp = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_leftp = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_colp = lv_obj_get_style_pad_column(obj, LV_PART_MAIN);
|
||||
|
||||
lv_coord_t marker_leftp = lv_obj_get_style_pad_left(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t marker_rightp = lv_obj_get_style_pad_right(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t marker_topp = lv_obj_get_style_pad_top(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t marker_bottomp = lv_obj_get_style_pad_bottom(obj, LV_PART_INDICATOR);
|
||||
|
||||
lv_coord_t transf_w = lv_obj_get_style_transform_width(obj, LV_PART_INDICATOR);
|
||||
lv_coord_t transf_h = lv_obj_get_style_transform_height(obj, LV_PART_INDICATOR);
|
||||
|
||||
lv_draw_rect_dsc_t marker_dsc;
|
||||
lv_draw_rect_dsc_init(&marker_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_INDICATOR, &marker_dsc);
|
||||
lv_area_t marker_area;
|
||||
marker_area.x1 = obj->coords.x1 + bg_leftp;
|
||||
marker_area.x2 = marker_area.x1 + font_h + marker_leftp + marker_rightp - 1;
|
||||
marker_area.y1 = obj->coords.y1 + bg_topp;
|
||||
marker_area.y2 = marker_area.y1 + font_h + marker_topp + marker_bottomp - 1;
|
||||
|
||||
lv_area_t marker_area_transf;
|
||||
lv_area_copy(&marker_area_transf, &marker_area);
|
||||
marker_area_transf.x1 -= transf_w;
|
||||
marker_area_transf.x2 += transf_w;
|
||||
marker_area_transf.y1 -= transf_h;
|
||||
marker_area_transf.y2 += transf_h;
|
||||
|
||||
lv_draw_rect(&marker_area_transf, clip_area, &marker_dsc);
|
||||
|
||||
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
|
||||
lv_coord_t letter_space = lv_obj_get_style_text_letter_space(obj, LV_PART_MAIN);
|
||||
|
||||
lv_point_t txt_size;
|
||||
lv_txt_get_size(&txt_size, cb->txt, font, letter_space, line_space, LV_COORD_MAX, LV_TEXT_FLAG_NONE);
|
||||
|
||||
lv_draw_label_dsc_t txt_dsc;
|
||||
lv_draw_label_dsc_init(&txt_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &txt_dsc);
|
||||
|
||||
lv_coord_t y_ofs = (lv_area_get_height(&marker_area) - font_h) / 2;
|
||||
lv_area_t txt_area;
|
||||
txt_area.x1 = marker_area.x2 + bg_colp;
|
||||
txt_area.x2 = txt_area.x1 + txt_size.x;
|
||||
txt_area.y1 = obj->coords.y1 + bg_topp + y_ofs;
|
||||
txt_area.y2 = txt_area.y1 + txt_size.y;
|
||||
|
||||
lv_draw_label(&txt_area, clip_area, &txt_dsc, cb->txt, NULL);
|
||||
}
|
||||
#endif
|
||||
|
@ -38,13 +38,13 @@
|
||||
static lv_obj_t * lv_dropdown_list_create(lv_obj_t * parent, const lv_obj_t * copy);
|
||||
static void lv_dropdown_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_dropdown_destructor(lv_obj_t * obj);
|
||||
static lv_draw_res_t lv_dropdown_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_dropdown_event(lv_obj_t * obj, lv_event_t e);
|
||||
static void draw_main(lv_obj_t * obj);
|
||||
|
||||
static void lv_dropdown_list_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_dropdown_list_destructor(lv_obj_t * list_obj);
|
||||
static lv_draw_res_t lv_dropdown_list_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_dropdown_list_event(lv_obj_t * list, lv_event_t e);
|
||||
static void draw_list(lv_obj_t * obj);
|
||||
|
||||
static void draw_box(lv_obj_t * dropdown_obj, const lv_area_t * clip_area, uint16_t id, lv_state_t state);
|
||||
static void draw_box_label(lv_obj_t * dropdown_obj, const lv_area_t * clip_area, uint16_t id, lv_state_t state);
|
||||
@ -61,7 +61,6 @@ const lv_obj_class_t lv_dropdown_class = {
|
||||
.constructor_cb = lv_dropdown_constructor,
|
||||
.destructor_cb = lv_dropdown_destructor,
|
||||
.event_cb = lv_dropdown_event,
|
||||
.draw_cb = lv_dropdown_draw,
|
||||
.instance_size = sizeof(lv_dropdown_t),
|
||||
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
|
||||
.base_class = &lv_obj_class
|
||||
@ -71,7 +70,6 @@ const lv_obj_class_t lv_dropdown_list_class = {
|
||||
.constructor_cb = lv_dropdown_list_constructor,
|
||||
.destructor_cb = lv_dropdown_list_destructor,
|
||||
.event_cb = lv_dropdown_list_event,
|
||||
.draw_cb = lv_dropdown_list_draw,
|
||||
.instance_size = sizeof(lv_dropdown_list_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -592,178 +590,6 @@ static void lv_dropdown_destructor(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_dropdown_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
lv_dropdown_t * dropdown = (lv_dropdown_t *)obj;
|
||||
|
||||
lv_coord_t left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
lv_coord_t top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_dsc);
|
||||
|
||||
/*If no text specified use the selected option*/
|
||||
const char * opt_txt;
|
||||
if(dropdown->text) opt_txt = dropdown->text;
|
||||
else {
|
||||
char * buf = lv_mem_buf_get(128);
|
||||
lv_dropdown_get_selected_str(obj, buf, 128);
|
||||
opt_txt = buf;
|
||||
}
|
||||
|
||||
bool symbol_to_left = false;
|
||||
if(dropdown->dir == LV_DIR_LEFT) symbol_to_left = true;
|
||||
if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) symbol_to_left = true;
|
||||
|
||||
if(dropdown->symbol) {
|
||||
lv_img_src_t symbol_type = lv_img_src_get_type(dropdown->symbol);
|
||||
lv_coord_t symbol_w;
|
||||
lv_coord_t symbol_h;
|
||||
if(symbol_type == LV_IMG_SRC_SYMBOL) {
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, dropdown->symbol, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag);
|
||||
symbol_w = size.x;
|
||||
symbol_h = size.y;
|
||||
} else {
|
||||
lv_img_header_t header;
|
||||
lv_res_t res = lv_img_decoder_get_info(dropdown->symbol, &header);
|
||||
if(res == LV_RES_OK) {
|
||||
symbol_w = header.w;
|
||||
symbol_h = header.h;
|
||||
} else {
|
||||
symbol_w = -1;
|
||||
symbol_h = -1;
|
||||
}
|
||||
}
|
||||
|
||||
lv_area_t symbol_area;
|
||||
if(symbol_to_left) {
|
||||
symbol_area.x1 = obj->coords.x1 + left;
|
||||
symbol_area.x2 = symbol_area.x1 + symbol_w - 1;
|
||||
} else {
|
||||
symbol_area.x1 = obj->coords.x2 - right - symbol_w;
|
||||
symbol_area.x2 = symbol_area.x1 + symbol_w - 1;
|
||||
}
|
||||
|
||||
if(symbol_type == LV_IMG_SRC_SYMBOL) {
|
||||
symbol_area.y1 = obj->coords.y1 + top;
|
||||
symbol_area.y2 = symbol_area.y1 + symbol_h - 1;
|
||||
lv_draw_label(&symbol_area, clip_area, &label_dsc, dropdown->symbol, NULL);
|
||||
} else {
|
||||
symbol_area.y1 = obj->coords.y1 + (lv_obj_get_height(obj) - symbol_h) / 2;
|
||||
symbol_area.y2 = symbol_area.y1 + symbol_h - 1;
|
||||
lv_draw_img_dsc_t img_dsc;
|
||||
lv_draw_img_dsc_init(&img_dsc);
|
||||
lv_obj_init_draw_img_dsc(obj, LV_PART_MAIN, &img_dsc);
|
||||
img_dsc.pivot.x = symbol_w / 2;
|
||||
img_dsc.pivot.y = symbol_h / 2;
|
||||
img_dsc.angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
|
||||
lv_draw_img(&symbol_area, clip_area, dropdown->symbol, &img_dsc);
|
||||
}
|
||||
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, opt_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag);
|
||||
|
||||
lv_area_t txt_area;
|
||||
txt_area.y1 = obj->coords.y1 + top;
|
||||
txt_area.y2 = txt_area.y1 + size.y;
|
||||
/*Center align the text if no symbol*/
|
||||
if(dropdown->symbol == NULL) {
|
||||
txt_area.x1 = obj->coords.x1 + (lv_obj_get_width(obj) - size.x) / 2;
|
||||
txt_area.x2 = txt_area.x1 + size.x;
|
||||
}
|
||||
else {
|
||||
/*Text to the right*/
|
||||
if(symbol_to_left) {
|
||||
txt_area.x1 = obj->coords.x2 - right - size.x;
|
||||
txt_area.x2 = txt_area.x1 + size.x;
|
||||
} else {
|
||||
txt_area.x1 = obj->coords.x1 + left;
|
||||
txt_area.x2 = txt_area.x1 + size.x;
|
||||
}
|
||||
}
|
||||
lv_draw_label(&txt_area, clip_area, &label_dsc, opt_txt, NULL);
|
||||
}
|
||||
|
||||
if(dropdown->text == NULL) {
|
||||
lv_mem_buf_release((char *)opt_txt);
|
||||
}
|
||||
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the drawing related tasks of the drop down list's list
|
||||
* @param list pointer to an object
|
||||
* @param clip_area the object will be drawn only in this area
|
||||
* @param mode LV_DRAW_COVER_CHK: only check if the object fully covers the 'mask_p' area
|
||||
* (return 'true' if yes)
|
||||
* LV_DRAW_DRAW: draw the object (always return 'true')
|
||||
* LV_DRAW_DRAW_POST: drawing after every children are drawn
|
||||
* @param return an element of `lv_draw_res_t`
|
||||
*/
|
||||
static lv_draw_res_t lv_dropdown_list_draw(lv_obj_t * list_obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return lv_obj_draw_base(MY_CLASS_LIST, list_obj, clip_area, mode);
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS_LIST, list_obj, clip_area, mode);
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
|
||||
lv_dropdown_list_t * list = (lv_dropdown_list_t *)list_obj;
|
||||
lv_obj_t * dropdown_obj = list->dropdown;
|
||||
lv_dropdown_t * dropdown = (lv_dropdown_t *)dropdown_obj;
|
||||
|
||||
/*Draw the box labels if the list is not being deleted*/
|
||||
if(dropdown->list) {
|
||||
/* Clip area might be too large too to shadow but
|
||||
* the selected option can be drawn on only the background*/
|
||||
lv_area_t clip_area_core;
|
||||
bool has_common;
|
||||
has_common = _lv_area_intersect(&clip_area_core, clip_area, &dropdown->list->coords);
|
||||
if(has_common) {
|
||||
if(dropdown->selected_highlight) {
|
||||
if(dropdown->pr_opt_id == dropdown->sel_opt_id) {
|
||||
draw_box(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_CHECKED | LV_STATE_PRESSED);
|
||||
draw_box_label(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_CHECKED | LV_STATE_PRESSED);
|
||||
} else {
|
||||
draw_box(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED);
|
||||
draw_box_label(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED);
|
||||
draw_box(dropdown_obj, &clip_area_core, dropdown->sel_opt_id, LV_STATE_CHECKED);
|
||||
draw_box_label(dropdown_obj, &clip_area_core, dropdown->sel_opt_id, LV_STATE_CHECKED);
|
||||
}
|
||||
} else {
|
||||
draw_box(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED);
|
||||
draw_box_label(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
lv_obj_draw_base(MY_CLASS_LIST, list_obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_dropdown_list_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
{
|
||||
LV_TRACE_OBJ_CREATE("begin");
|
||||
@ -870,15 +696,11 @@ static void lv_dropdown_event(lv_obj_t * obj, lv_event_t e)
|
||||
lv_dropdown_close(obj);
|
||||
}
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_main(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the drop down list's scrollable part
|
||||
* @param scrl pointer to a drop down list's scrollable part
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
||||
*/
|
||||
static void lv_dropdown_list_event(lv_obj_t * list, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
@ -902,6 +724,144 @@ static void lv_dropdown_list_event(lv_obj_t * list, lv_event_t e)
|
||||
dropdown->pr_opt_id = LV_DROPDOWN_PR_NONE;
|
||||
lv_obj_invalidate(list);
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_POST) {
|
||||
draw_list(list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void draw_main(lv_obj_t * obj)
|
||||
{
|
||||
lv_dropdown_t * dropdown = (lv_dropdown_t *)obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
lv_coord_t left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
lv_coord_t top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_dsc);
|
||||
|
||||
/*If no text specified use the selected option*/
|
||||
const char * opt_txt;
|
||||
if(dropdown->text) opt_txt = dropdown->text;
|
||||
else {
|
||||
char * buf = lv_mem_buf_get(128);
|
||||
lv_dropdown_get_selected_str(obj, buf, 128);
|
||||
opt_txt = buf;
|
||||
}
|
||||
|
||||
bool symbol_to_left = false;
|
||||
if(dropdown->dir == LV_DIR_LEFT) symbol_to_left = true;
|
||||
if(lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL) symbol_to_left = true;
|
||||
|
||||
if(dropdown->symbol) {
|
||||
lv_img_src_t symbol_type = lv_img_src_get_type(dropdown->symbol);
|
||||
lv_coord_t symbol_w;
|
||||
lv_coord_t symbol_h;
|
||||
if(symbol_type == LV_IMG_SRC_SYMBOL) {
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, dropdown->symbol, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag);
|
||||
symbol_w = size.x;
|
||||
symbol_h = size.y;
|
||||
} else {
|
||||
lv_img_header_t header;
|
||||
lv_res_t res = lv_img_decoder_get_info(dropdown->symbol, &header);
|
||||
if(res == LV_RES_OK) {
|
||||
symbol_w = header.w;
|
||||
symbol_h = header.h;
|
||||
} else {
|
||||
symbol_w = -1;
|
||||
symbol_h = -1;
|
||||
}
|
||||
}
|
||||
|
||||
lv_area_t symbol_area;
|
||||
if(symbol_to_left) {
|
||||
symbol_area.x1 = obj->coords.x1 + left;
|
||||
symbol_area.x2 = symbol_area.x1 + symbol_w - 1;
|
||||
} else {
|
||||
symbol_area.x1 = obj->coords.x2 - right - symbol_w;
|
||||
symbol_area.x2 = symbol_area.x1 + symbol_w - 1;
|
||||
}
|
||||
|
||||
if(symbol_type == LV_IMG_SRC_SYMBOL) {
|
||||
symbol_area.y1 = obj->coords.y1 + top;
|
||||
symbol_area.y2 = symbol_area.y1 + symbol_h - 1;
|
||||
lv_draw_label(&symbol_area, clip_area, &label_dsc, dropdown->symbol, NULL);
|
||||
} else {
|
||||
symbol_area.y1 = obj->coords.y1 + (lv_obj_get_height(obj) - symbol_h) / 2;
|
||||
symbol_area.y2 = symbol_area.y1 + symbol_h - 1;
|
||||
lv_draw_img_dsc_t img_dsc;
|
||||
lv_draw_img_dsc_init(&img_dsc);
|
||||
lv_obj_init_draw_img_dsc(obj, LV_PART_MAIN, &img_dsc);
|
||||
img_dsc.pivot.x = symbol_w / 2;
|
||||
img_dsc.pivot.y = symbol_h / 2;
|
||||
img_dsc.angle = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
|
||||
lv_draw_img(&symbol_area, clip_area, dropdown->symbol, &img_dsc);
|
||||
}
|
||||
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, opt_txt, label_dsc.font, label_dsc.letter_space, label_dsc.line_space, LV_COORD_MAX, label_dsc.flag);
|
||||
|
||||
lv_area_t txt_area;
|
||||
txt_area.y1 = obj->coords.y1 + top;
|
||||
txt_area.y2 = txt_area.y1 + size.y;
|
||||
/*Center align the text if no symbol*/
|
||||
if(dropdown->symbol == NULL) {
|
||||
txt_area.x1 = obj->coords.x1 + (lv_obj_get_width(obj) - size.x) / 2;
|
||||
txt_area.x2 = txt_area.x1 + size.x;
|
||||
}
|
||||
else {
|
||||
/*Text to the right*/
|
||||
if(symbol_to_left) {
|
||||
txt_area.x1 = obj->coords.x2 - right - size.x;
|
||||
txt_area.x2 = txt_area.x1 + size.x;
|
||||
} else {
|
||||
txt_area.x1 = obj->coords.x1 + left;
|
||||
txt_area.x2 = txt_area.x1 + size.x;
|
||||
}
|
||||
}
|
||||
lv_draw_label(&txt_area, clip_area, &label_dsc, opt_txt, NULL);
|
||||
}
|
||||
|
||||
if(dropdown->text == NULL) {
|
||||
lv_mem_buf_release((char *)opt_txt);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_list(lv_obj_t * list_obj)
|
||||
{
|
||||
lv_dropdown_list_t * list = (lv_dropdown_list_t *)list_obj;
|
||||
lv_obj_t * dropdown_obj = list->dropdown;
|
||||
lv_dropdown_t * dropdown = (lv_dropdown_t *)dropdown_obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
/*Draw the box labels if the list is not being deleted*/
|
||||
if(dropdown->list) {
|
||||
/* Clip area might be too large too to shadow but
|
||||
* the selected option can be drawn on only the background*/
|
||||
lv_area_t clip_area_core;
|
||||
bool has_common;
|
||||
has_common = _lv_area_intersect(&clip_area_core, clip_area, &dropdown->list->coords);
|
||||
if(has_common) {
|
||||
if(dropdown->selected_highlight) {
|
||||
if(dropdown->pr_opt_id == dropdown->sel_opt_id) {
|
||||
draw_box(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_CHECKED | LV_STATE_PRESSED);
|
||||
draw_box_label(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_CHECKED | LV_STATE_PRESSED);
|
||||
} else {
|
||||
draw_box(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED);
|
||||
draw_box_label(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED);
|
||||
draw_box(dropdown_obj, &clip_area_core, dropdown->sel_opt_id, LV_STATE_CHECKED);
|
||||
draw_box_label(dropdown_obj, &clip_area_core, dropdown->sel_opt_id, LV_STATE_CHECKED);
|
||||
}
|
||||
} else {
|
||||
draw_box(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED);
|
||||
draw_box_label(dropdown_obj, &clip_area_core, dropdown->pr_opt_id, LV_STATE_PRESSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_box(lv_obj_t * dropdown_obj, const lv_area_t * clip_area, uint16_t id, lv_state_t state)
|
||||
|
@ -30,8 +30,8 @@
|
||||
**********************/
|
||||
static void lv_img_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_img_destructor(lv_obj_t * obj);
|
||||
static lv_draw_res_t lv_img_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_img_event(lv_obj_t * obj, lv_event_t e);
|
||||
static void draw_img(lv_obj_t * obj, lv_event_t e);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -40,7 +40,6 @@ const lv_obj_class_t lv_img_class = {
|
||||
.constructor_cb = lv_img_constructor,
|
||||
.destructor_cb = lv_img_destructor,
|
||||
.event_cb = lv_img_event,
|
||||
.draw_cb = lv_img_draw,
|
||||
.instance_size = sizeof(lv_img_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -410,151 +409,14 @@ static void lv_img_destructor(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_img_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
lv_img_t * img = (lv_img_t *)obj;
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
if(lv_obj_get_style_clip_corner(obj, LV_PART_MAIN)) return LV_DRAW_RES_MASKED;
|
||||
|
||||
if(img->src_type == LV_IMG_SRC_UNKNOWN || img->src_type == LV_IMG_SRC_SYMBOL) return LV_DRAW_RES_NOT_COVER;
|
||||
|
||||
/*Non true color format might have "holes"*/
|
||||
if(img->cf != LV_IMG_CF_TRUE_COLOR && img->cf != LV_IMG_CF_RAW) return LV_DRAW_RES_NOT_COVER;
|
||||
|
||||
/*With not LV_OPA_COVER images can't cover an area */
|
||||
if(lv_obj_get_style_img_opa(obj, LV_PART_MAIN) != LV_OPA_COVER) return LV_DRAW_RES_NOT_COVER;
|
||||
|
||||
int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
|
||||
angle_final += img->angle;
|
||||
|
||||
if(angle_final != 0) return LV_DRAW_RES_NOT_COVER;
|
||||
|
||||
int32_t zoom_final = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
|
||||
zoom_final = (zoom_final * img->zoom) >> 8;
|
||||
|
||||
if(zoom_final == LV_IMG_ZOOM_NONE) {
|
||||
if(_lv_area_is_in(clip_area, &obj->coords, 0) == false) return LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
else {
|
||||
lv_area_t a;
|
||||
_lv_img_buf_get_transformed_area(&a, lv_obj_get_width(obj), lv_obj_get_height(obj), 0, zoom_final, &img->pivot);
|
||||
a.x1 += obj->coords.x1;
|
||||
a.y1 += obj->coords.y1;
|
||||
a.x2 += obj->coords.x1;
|
||||
a.y2 += obj->coords.y1;
|
||||
|
||||
if(_lv_area_is_in(clip_area, &a, 0) == false) return LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
|
||||
#if LV_DRAW_COMPLEX
|
||||
if(lv_obj_get_style_blend_mode(obj, LV_PART_MAIN) != LV_BLEND_MODE_NORMAL) return LV_DRAW_RES_NOT_COVER;
|
||||
#endif
|
||||
|
||||
return LV_DRAW_RES_COVER;
|
||||
}
|
||||
|
||||
int32_t zoom_final = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
|
||||
zoom_final = (zoom_final * img->zoom) >> 8;
|
||||
|
||||
int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
|
||||
angle_final += img->angle;
|
||||
|
||||
lv_coord_t obj_w = lv_obj_get_width(obj);
|
||||
lv_coord_t obj_h = lv_obj_get_height(obj);
|
||||
|
||||
lv_coord_t pleft = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t pright = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
lv_coord_t ptop = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t pbottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
|
||||
lv_point_t bg_pivot;
|
||||
bg_pivot.x = img->pivot.x + pleft;
|
||||
bg_pivot.y = img->pivot.y + ptop;
|
||||
lv_area_t bg_coords;
|
||||
_lv_img_buf_get_transformed_area(&bg_coords, obj_w, obj_h,
|
||||
angle_final, zoom_final, &bg_pivot);
|
||||
|
||||
/*Modify the coordinates to draw the background for the rotated and scaled coordinates*/
|
||||
bg_coords.x1 += obj->coords.x1;
|
||||
bg_coords.y1 += obj->coords.y1;
|
||||
bg_coords.x2 += obj->coords.x1;
|
||||
bg_coords.y2 += obj->coords.y1;
|
||||
|
||||
lv_area_t ori_coords;
|
||||
lv_area_copy(&ori_coords, &obj->coords);
|
||||
lv_area_copy(&obj->coords, &bg_coords);
|
||||
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
lv_area_copy(&obj->coords, &ori_coords);
|
||||
|
||||
if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
if(img->h == 0 || img->w == 0) return true;
|
||||
|
||||
if(zoom_final == 0) return LV_DRAW_RES_OK;
|
||||
|
||||
lv_area_t img_max_area;
|
||||
lv_area_copy(&img_max_area, &obj->coords);
|
||||
img_max_area.x1 += pleft;
|
||||
img_max_area.y1 += ptop;
|
||||
img_max_area.x2 -= pright;
|
||||
img_max_area.y2 -= pbottom;
|
||||
|
||||
if(img->src_type == LV_IMG_SRC_FILE || img->src_type == LV_IMG_SRC_VARIABLE) {
|
||||
lv_draw_img_dsc_t img_dsc;
|
||||
lv_draw_img_dsc_init(&img_dsc);
|
||||
lv_obj_init_draw_img_dsc(obj, LV_PART_MAIN, &img_dsc);
|
||||
|
||||
img_dsc.zoom = zoom_final;
|
||||
img_dsc.angle = angle_final;
|
||||
img_dsc.pivot.x = img->pivot.x;
|
||||
img_dsc.pivot.y = img->pivot.y;
|
||||
img_dsc.antialias = img->antialias;
|
||||
|
||||
lv_area_t img_clip_area;
|
||||
img_clip_area.x1 = bg_coords.x1 + pleft;
|
||||
img_clip_area.y1 = bg_coords.y1 + ptop;
|
||||
img_clip_area.x2 = bg_coords.x2 - pright;
|
||||
img_clip_area.y2 = bg_coords.y2 - pbottom;
|
||||
|
||||
_lv_area_intersect(&img_clip_area, clip_area, &img_clip_area);
|
||||
|
||||
lv_area_t coords_tmp;
|
||||
coords_tmp.y1 = img_max_area.y1 + img->offset.y;
|
||||
if(coords_tmp.y1 > img_max_area.y1) coords_tmp.y1 -= img->h;
|
||||
coords_tmp.y2 = coords_tmp.y1 + img->h - 1;
|
||||
|
||||
for(; coords_tmp.y1 < img_max_area.y2; coords_tmp.y1 += img->h, coords_tmp.y2 += img->h) {
|
||||
coords_tmp.x1 = img_max_area.x1 + img->offset.x;
|
||||
if(coords_tmp.x1 > img_max_area.x1) coords_tmp.x1 -= img->w;
|
||||
coords_tmp.x2 = coords_tmp.x1 + img->w - 1;
|
||||
|
||||
for(; coords_tmp.x1 < img_max_area.x2; coords_tmp.x1 += img->w, coords_tmp.x2 += img->w) {
|
||||
lv_draw_img(&coords_tmp, &img_clip_area, img->src, &img_dsc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(img->src_type == LV_IMG_SRC_SYMBOL) {
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_dsc);
|
||||
|
||||
lv_draw_label(&obj->coords, clip_area, &label_dsc, img->src, NULL);
|
||||
}
|
||||
else {
|
||||
/*Trigger the error handler of image draw*/
|
||||
LV_LOG_WARN("lv_img_draw: image source type is unknown");
|
||||
lv_draw_img(&obj->coords, clip_area, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_img_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
/* Include the ancient signal function */
|
||||
lv_res_t res = lv_obj_event_base(MY_CLASS, obj, e);
|
||||
if(res != LV_RES_OK) return;
|
||||
/*Ancestor events will be called during drawing*/
|
||||
if(e != LV_EVENT_DRAW_MAIN && e != LV_EVENT_DRAW_POST) {
|
||||
/* Include the ancient signal function */
|
||||
lv_res_t res = lv_obj_event_base(MY_CLASS, obj, e);
|
||||
if(res != LV_RES_OK) return;
|
||||
}
|
||||
|
||||
lv_img_t * img = (lv_img_t *)obj;
|
||||
|
||||
@ -621,6 +483,166 @@ static void lv_img_event(lv_obj_t * obj, lv_event_t e)
|
||||
p->x = img->w;
|
||||
p->y = img->h;
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN || e == LV_EVENT_DRAW_POST || e == LV_EVENT_COVER_CHECK) {
|
||||
draw_img(obj, e);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_img(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_img_t * img = (lv_img_t *)obj;
|
||||
if(e == LV_EVENT_COVER_CHECK) {
|
||||
lv_cover_check_info_t * info = lv_event_get_param();
|
||||
if(info->res == LV_DRAW_RES_MASKED) return;
|
||||
if(img->src_type == LV_IMG_SRC_UNKNOWN || img->src_type == LV_IMG_SRC_SYMBOL) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
|
||||
/*Non true color format might have "holes"*/
|
||||
if(img->cf != LV_IMG_CF_TRUE_COLOR && img->cf != LV_IMG_CF_RAW) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
|
||||
/*With not LV_OPA_COVER images can't cover an area */
|
||||
if(lv_obj_get_style_img_opa(obj, LV_PART_MAIN) != LV_OPA_COVER) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
|
||||
angle_final += img->angle;
|
||||
|
||||
if(angle_final != 0) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t zoom_final = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
|
||||
zoom_final = (zoom_final * img->zoom) >> 8;
|
||||
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
if(zoom_final == LV_IMG_ZOOM_NONE) {
|
||||
if(_lv_area_is_in(clip_area, &obj->coords, 0) == false) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
lv_area_t a;
|
||||
_lv_img_buf_get_transformed_area(&a, lv_obj_get_width(obj), lv_obj_get_height(obj), 0, zoom_final, &img->pivot);
|
||||
a.x1 += obj->coords.x1;
|
||||
a.y1 += obj->coords.y1;
|
||||
a.x2 += obj->coords.x1;
|
||||
a.y2 += obj->coords.y1;
|
||||
|
||||
if(_lv_area_is_in(clip_area, &a, 0) == false) {
|
||||
info->res = LV_DRAW_RES_NOT_COVER;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN || e == LV_EVENT_DRAW_POST) {
|
||||
|
||||
int32_t zoom_final = lv_obj_get_style_transform_zoom(obj, LV_PART_MAIN);
|
||||
zoom_final = (zoom_final * img->zoom) >> 8;
|
||||
|
||||
int32_t angle_final = lv_obj_get_style_transform_angle(obj, LV_PART_MAIN);
|
||||
angle_final += img->angle;
|
||||
|
||||
lv_coord_t obj_w = lv_obj_get_width(obj);
|
||||
lv_coord_t obj_h = lv_obj_get_height(obj);
|
||||
|
||||
lv_coord_t pleft = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t pright = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
lv_coord_t ptop = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t pbottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
|
||||
lv_point_t bg_pivot;
|
||||
bg_pivot.x = img->pivot.x + pleft;
|
||||
bg_pivot.y = img->pivot.y + ptop;
|
||||
lv_area_t bg_coords;
|
||||
_lv_img_buf_get_transformed_area(&bg_coords, obj_w, obj_h,
|
||||
angle_final, zoom_final, &bg_pivot);
|
||||
|
||||
/*Modify the coordinates to draw the background for the rotated and scaled coordinates*/
|
||||
bg_coords.x1 += obj->coords.x1;
|
||||
bg_coords.y1 += obj->coords.y1;
|
||||
bg_coords.x2 += obj->coords.x1;
|
||||
bg_coords.y2 += obj->coords.y1;
|
||||
|
||||
lv_area_t ori_coords;
|
||||
lv_area_copy(&ori_coords, &obj->coords);
|
||||
lv_area_copy(&obj->coords, &bg_coords);
|
||||
|
||||
lv_res_t res = lv_obj_event_base(MY_CLASS, obj, e);
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
lv_area_copy(&obj->coords, &ori_coords);
|
||||
|
||||
if(e == LV_EVENT_DRAW_MAIN) {
|
||||
if(img->h == 0 || img->w == 0) return;
|
||||
if(zoom_final == 0) return;
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
lv_area_t img_max_area;
|
||||
lv_area_copy(&img_max_area, &obj->coords);
|
||||
img_max_area.x1 += pleft;
|
||||
img_max_area.y1 += ptop;
|
||||
img_max_area.x2 -= pright;
|
||||
img_max_area.y2 -= pbottom;
|
||||
|
||||
if(img->src_type == LV_IMG_SRC_FILE || img->src_type == LV_IMG_SRC_VARIABLE) {
|
||||
lv_draw_img_dsc_t img_dsc;
|
||||
lv_draw_img_dsc_init(&img_dsc);
|
||||
lv_obj_init_draw_img_dsc(obj, LV_PART_MAIN, &img_dsc);
|
||||
|
||||
img_dsc.zoom = zoom_final;
|
||||
img_dsc.angle = angle_final;
|
||||
img_dsc.pivot.x = img->pivot.x;
|
||||
img_dsc.pivot.y = img->pivot.y;
|
||||
img_dsc.antialias = img->antialias;
|
||||
|
||||
lv_area_t img_clip_area;
|
||||
img_clip_area.x1 = bg_coords.x1 + pleft;
|
||||
img_clip_area.y1 = bg_coords.y1 + ptop;
|
||||
img_clip_area.x2 = bg_coords.x2 - pright;
|
||||
img_clip_area.y2 = bg_coords.y2 - pbottom;
|
||||
|
||||
_lv_area_intersect(&img_clip_area, clip_area, &img_clip_area);
|
||||
|
||||
lv_area_t coords_tmp;
|
||||
coords_tmp.y1 = img_max_area.y1 + img->offset.y;
|
||||
if(coords_tmp.y1 > img_max_area.y1) coords_tmp.y1 -= img->h;
|
||||
coords_tmp.y2 = coords_tmp.y1 + img->h - 1;
|
||||
|
||||
for(; coords_tmp.y1 < img_max_area.y2; coords_tmp.y1 += img->h, coords_tmp.y2 += img->h) {
|
||||
coords_tmp.x1 = img_max_area.x1 + img->offset.x;
|
||||
if(coords_tmp.x1 > img_max_area.x1) coords_tmp.x1 -= img->w;
|
||||
coords_tmp.x2 = coords_tmp.x1 + img->w - 1;
|
||||
|
||||
for(; coords_tmp.x1 < img_max_area.x2; coords_tmp.x1 += img->w, coords_tmp.x2 += img->w) {
|
||||
lv_draw_img(&coords_tmp, &img_clip_area, img->src, &img_dsc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(img->src_type == LV_IMG_SRC_SYMBOL) {
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_dsc);
|
||||
|
||||
lv_draw_label(&obj->coords, clip_area, &label_dsc, img->src, NULL);
|
||||
}
|
||||
else {
|
||||
/*Trigger the error handler of image draw*/
|
||||
LV_LOG_WARN("draw_img: image source type is unknown");
|
||||
lv_draw_img(&obj->coords, clip_area, NULL, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -36,8 +36,8 @@
|
||||
**********************/
|
||||
static void lv_label_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_label_destructor(lv_obj_t * obj);
|
||||
static void lv_label_event_cb(lv_obj_t * label, lv_event_t e);
|
||||
static lv_draw_res_t lv_label_draw(lv_obj_t * label, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_label_event_cb(lv_obj_t * obj, lv_event_t e);
|
||||
static void draw_main(lv_obj_t * obj);
|
||||
|
||||
static void lv_label_refr_text(lv_obj_t * obj);
|
||||
static void lv_label_revert_dots(lv_obj_t * label);
|
||||
@ -56,7 +56,6 @@ const lv_obj_class_t lv_label_class = {
|
||||
.constructor_cb = lv_label_constructor,
|
||||
.destructor_cb = lv_label_destructor,
|
||||
.event_cb = lv_label_event_cb,
|
||||
.draw_cb = lv_label_draw,
|
||||
.instance_size = sizeof(lv_label_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -738,103 +737,6 @@ static void lv_label_destructor(lv_obj_t * obj)
|
||||
label->text = NULL;
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_label_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/* A label never covers an area */
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK)
|
||||
return LV_DRAW_RES_NOT_COVER;
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
lv_label_t * label = (lv_label_t *)obj;
|
||||
lv_area_t txt_coords;
|
||||
get_txt_coords(obj, &txt_coords);
|
||||
|
||||
lv_area_t txt_clip;
|
||||
bool is_common = _lv_area_intersect(&txt_clip, clip_area, &txt_coords);
|
||||
if(!is_common) return LV_DRAW_RES_OK;
|
||||
|
||||
lv_text_align_t align = lv_obj_get_style_text_align(obj, LV_PART_MAIN);
|
||||
lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
|
||||
if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
|
||||
if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
|
||||
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TEXT_FLAG_FIT;
|
||||
|
||||
lv_draw_label_dsc_t label_draw_dsc;
|
||||
lv_draw_label_dsc_init(&label_draw_dsc);
|
||||
|
||||
label_draw_dsc.ofs_x = label->offset.x;
|
||||
label_draw_dsc.ofs_y = label->offset.y;
|
||||
label_draw_dsc.flag = flag;
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_draw_dsc);
|
||||
|
||||
label_draw_dsc.sel_start = lv_label_get_text_sel_start(obj);
|
||||
label_draw_dsc.sel_end = lv_label_get_text_sel_end(obj);
|
||||
if(label_draw_dsc.sel_start != LV_DRAW_LABEL_NO_TXT_SEL && label_draw_dsc.sel_end != LV_DRAW_LABEL_NO_TXT_SEL) {
|
||||
label_draw_dsc.sel_color = lv_obj_get_style_text_color_filtered(obj, LV_PART_SELECTED);
|
||||
label_draw_dsc.sel_bg_color = lv_obj_get_style_bg_color(obj, LV_PART_SELECTED);
|
||||
}
|
||||
|
||||
/* In SROLL and SROLL_CIRC mode the CENTER and RIGHT are pointless so remove them.
|
||||
* (In addition they will result misalignment is this case)*/
|
||||
if((label->long_mode == LV_LABEL_LONG_SCROLL || label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR) &&
|
||||
(align == LV_TEXT_ALIGN_CENTER || align == LV_TEXT_ALIGN_RIGHT)) {
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, label->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space,
|
||||
LV_COORD_MAX, flag);
|
||||
if(size.x > lv_area_get_width(&txt_coords)) {
|
||||
label_draw_dsc.align = LV_TEXT_ALIGN_LEFT;
|
||||
}
|
||||
}
|
||||
#if LV_LABEL_LONG_TXT_HINT
|
||||
lv_draw_label_hint_t * hint = &label->hint;
|
||||
if(label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR || lv_area_get_height(&txt_coords) < LV_LABEL_HINT_HEIGHT_LIMIT)
|
||||
hint = NULL;
|
||||
|
||||
#else
|
||||
/*Just for compatibility*/
|
||||
lv_draw_label_hint_t * hint = NULL;
|
||||
#endif
|
||||
|
||||
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
|
||||
|
||||
if(label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR) {
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, label->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space,
|
||||
LV_COORD_MAX, flag);
|
||||
|
||||
/*Draw the text again on label to the original to make an circular effect */
|
||||
if(size.x > lv_area_get_width(&txt_coords)) {
|
||||
label_draw_dsc.ofs_x = label->offset.x + size.x +
|
||||
lv_font_get_glyph_width(label_draw_dsc.font, ' ', ' ') * LV_LABEL_WAIT_CHAR_COUNT;
|
||||
label_draw_dsc.ofs_y = label->offset.y;
|
||||
|
||||
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
|
||||
}
|
||||
|
||||
/*Draw the text again below the original to make an circular effect */
|
||||
if(size.y > lv_area_get_height(&txt_coords)) {
|
||||
label_draw_dsc.ofs_x = label->offset.x;
|
||||
label_draw_dsc.ofs_y = label->offset.y + size.y + lv_font_get_line_height(label_draw_dsc.font);
|
||||
|
||||
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
|
||||
}
|
||||
}
|
||||
} else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signal function of the label
|
||||
* @param label pointer to a label object
|
||||
* @param sign a signal type from lv_signal_t enum
|
||||
* @param param pointer to a signal specific variable
|
||||
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
||||
*/
|
||||
static void lv_label_event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
@ -862,9 +764,92 @@ static void lv_label_event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
if(label->static_txt == 0) lv_label_set_text(obj, NULL);
|
||||
#endif
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_main(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void draw_main(lv_obj_t * obj)
|
||||
{
|
||||
lv_label_t * label = (lv_label_t *)obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
lv_area_t txt_coords;
|
||||
get_txt_coords(obj, &txt_coords);
|
||||
|
||||
lv_area_t txt_clip;
|
||||
bool is_common = _lv_area_intersect(&txt_clip, clip_area, &txt_coords);
|
||||
if(!is_common) return;
|
||||
|
||||
lv_text_align_t align = lv_obj_get_style_text_align(obj, LV_PART_MAIN);
|
||||
lv_text_flag_t flag = LV_TEXT_FLAG_NONE;
|
||||
if(label->recolor != 0) flag |= LV_TEXT_FLAG_RECOLOR;
|
||||
if(label->expand != 0) flag |= LV_TEXT_FLAG_EXPAND;
|
||||
if(label->long_mode == LV_LABEL_LONG_EXPAND) flag |= LV_TEXT_FLAG_FIT;
|
||||
|
||||
lv_draw_label_dsc_t label_draw_dsc;
|
||||
lv_draw_label_dsc_init(&label_draw_dsc);
|
||||
|
||||
label_draw_dsc.ofs_x = label->offset.x;
|
||||
label_draw_dsc.ofs_y = label->offset.y;
|
||||
label_draw_dsc.flag = flag;
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_MAIN, &label_draw_dsc);
|
||||
|
||||
label_draw_dsc.sel_start = lv_label_get_text_sel_start(obj);
|
||||
label_draw_dsc.sel_end = lv_label_get_text_sel_end(obj);
|
||||
if(label_draw_dsc.sel_start != LV_DRAW_LABEL_NO_TXT_SEL && label_draw_dsc.sel_end != LV_DRAW_LABEL_NO_TXT_SEL) {
|
||||
label_draw_dsc.sel_color = lv_obj_get_style_text_color_filtered(obj, LV_PART_SELECTED);
|
||||
label_draw_dsc.sel_bg_color = lv_obj_get_style_bg_color(obj, LV_PART_SELECTED);
|
||||
}
|
||||
|
||||
/* In SROLL and SROLL_CIRC mode the CENTER and RIGHT are pointless so remove them.
|
||||
* (In addition they will result misalignment is this case)*/
|
||||
if((label->long_mode == LV_LABEL_LONG_SCROLL || label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR) &&
|
||||
(align == LV_TEXT_ALIGN_CENTER || align == LV_TEXT_ALIGN_RIGHT)) {
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, label->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space,
|
||||
LV_COORD_MAX, flag);
|
||||
if(size.x > lv_area_get_width(&txt_coords)) {
|
||||
label_draw_dsc.align = LV_TEXT_ALIGN_LEFT;
|
||||
}
|
||||
}
|
||||
#if LV_LABEL_LONG_TXT_HINT
|
||||
lv_draw_label_hint_t * hint = &label->hint;
|
||||
if(label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR || lv_area_get_height(&txt_coords) < LV_LABEL_HINT_HEIGHT_LIMIT)
|
||||
hint = NULL;
|
||||
|
||||
#else
|
||||
/*Just for compatibility*/
|
||||
lv_draw_label_hint_t * hint = NULL;
|
||||
#endif
|
||||
|
||||
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
|
||||
|
||||
if(label->long_mode == LV_LABEL_LONG_SCROLL_CIRCULAR) {
|
||||
lv_point_t size;
|
||||
lv_txt_get_size(&size, label->text, label_draw_dsc.font, label_draw_dsc.letter_space, label_draw_dsc.line_space,
|
||||
LV_COORD_MAX, flag);
|
||||
|
||||
/*Draw the text again on label to the original to make an circular effect */
|
||||
if(size.x > lv_area_get_width(&txt_coords)) {
|
||||
label_draw_dsc.ofs_x = label->offset.x + size.x +
|
||||
lv_font_get_glyph_width(label_draw_dsc.font, ' ', ' ') * LV_LABEL_WAIT_CHAR_COUNT;
|
||||
label_draw_dsc.ofs_y = label->offset.y;
|
||||
|
||||
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
|
||||
}
|
||||
|
||||
/*Draw the text again below the original to make an circular effect */
|
||||
if(size.y > lv_area_get_height(&txt_coords)) {
|
||||
label_draw_dsc.ofs_x = label->offset.x;
|
||||
label_draw_dsc.ofs_y = label->offset.y + size.y + lv_font_get_line_height(label_draw_dsc.font);
|
||||
|
||||
lv_draw_label(&txt_coords, &txt_clip, &label_draw_dsc, label->text, hint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresh the label with its text stored in its labelended data
|
||||
* @param label pointer to a label object
|
||||
|
@ -29,7 +29,6 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_line_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static lv_draw_res_t lv_line_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_line_event(lv_obj_t * obj, lv_event_t e);
|
||||
|
||||
/**********************
|
||||
@ -38,7 +37,6 @@ static void lv_line_event(lv_obj_t * obj, lv_event_t e);
|
||||
const lv_obj_class_t lv_line_class = {
|
||||
.constructor_cb = lv_line_constructor,
|
||||
.event_cb = lv_line_event,
|
||||
.draw_cb = lv_line_draw,
|
||||
.instance_size = sizeof(lv_line_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -130,53 +128,6 @@ static void lv_line_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
LV_TRACE_OBJ_CREATE("finished");
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_line_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/*A line never covers an area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK)
|
||||
return LV_DRAW_RES_NOT_COVER;
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
lv_line_t * line = (lv_line_t *)obj;
|
||||
|
||||
if(line->point_num == 0 || line->point_array == NULL) return false;
|
||||
|
||||
lv_area_t area;
|
||||
lv_obj_get_coords(obj, &area);
|
||||
lv_coord_t x_ofs = area.x1 - lv_obj_get_scroll_x(obj);
|
||||
lv_coord_t y_ofs = area.y1 - lv_obj_get_scroll_y(obj);
|
||||
lv_point_t p1;
|
||||
lv_point_t p2;
|
||||
lv_coord_t h = lv_obj_get_height(obj);
|
||||
uint16_t i;
|
||||
|
||||
lv_draw_line_dsc_t line_dsc;
|
||||
lv_draw_line_dsc_init(&line_dsc);
|
||||
lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_dsc);
|
||||
|
||||
/*Read all points and draw the lines*/
|
||||
for(i = 0; i < line->point_num - 1; i++) {
|
||||
|
||||
p1.x = line->point_array[i].x + x_ofs;
|
||||
p2.x = line->point_array[i + 1].x + x_ofs;
|
||||
|
||||
if(line->y_inv == 0) {
|
||||
p1.y = line->point_array[i].y + y_ofs;
|
||||
p2.y = line->point_array[i + 1].y + y_ofs;
|
||||
}
|
||||
else {
|
||||
p1.y = h - line->point_array[i].y + y_ofs;
|
||||
p2.y = h - line->point_array[i + 1].y + y_ofs;
|
||||
}
|
||||
lv_draw_line(&p1, &p2, clip_area, &line_dsc);
|
||||
line_dsc.round_start = 0; /*Draw the rounding only on the end points after the first line*/
|
||||
}
|
||||
} else if (mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_line_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
@ -210,6 +161,42 @@ static void lv_line_event(lv_obj_t * obj, lv_event_t e)
|
||||
p->x = w;
|
||||
p->y = h;
|
||||
}
|
||||
} else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
lv_line_t * line = (lv_line_t *)obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
if(line->point_num == 0 || line->point_array == NULL) return;
|
||||
|
||||
lv_area_t area;
|
||||
lv_obj_get_coords(obj, &area);
|
||||
lv_coord_t x_ofs = area.x1 - lv_obj_get_scroll_x(obj);
|
||||
lv_coord_t y_ofs = area.y1 - lv_obj_get_scroll_y(obj);
|
||||
lv_point_t p1;
|
||||
lv_point_t p2;
|
||||
lv_coord_t h = lv_obj_get_height(obj);
|
||||
uint16_t i;
|
||||
|
||||
lv_draw_line_dsc_t line_dsc;
|
||||
lv_draw_line_dsc_init(&line_dsc);
|
||||
lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_dsc);
|
||||
|
||||
/*Read all points and draw the lines*/
|
||||
for(i = 0; i < line->point_num - 1; i++) {
|
||||
|
||||
p1.x = line->point_array[i].x + x_ofs;
|
||||
p2.x = line->point_array[i + 1].x + x_ofs;
|
||||
|
||||
if(line->y_inv == 0) {
|
||||
p1.y = line->point_array[i].y + y_ofs;
|
||||
p2.y = line->point_array[i + 1].y + y_ofs;
|
||||
}
|
||||
else {
|
||||
p1.y = h - line->point_array[i].y + y_ofs;
|
||||
p2.y = h - line->point_array[i + 1].y + y_ofs;
|
||||
}
|
||||
lv_draw_line(&p1, &p2, clip_area, &line_dsc);
|
||||
line_dsc.round_start = 0; /*Draw the rounding only on the end points after the first line*/
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -29,7 +29,7 @@
|
||||
**********************/
|
||||
static void lv_meter_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_meter_destructor(lv_obj_t * obj);
|
||||
static lv_draw_res_t lv_meter_draw(lv_obj_t * lmeter, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_meter_event(lv_obj_t * obj, lv_event_t e);
|
||||
static void draw_arcs(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area);
|
||||
static void draw_ticks_and_labels(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area);
|
||||
static void draw_needles(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area);
|
||||
@ -43,7 +43,7 @@ static void inv_line(lv_obj_t * obj, lv_meter_indicator_t * indic, int32_t value
|
||||
const lv_obj_class_t lv_meter_class = {
|
||||
.constructor_cb = lv_meter_constructor,
|
||||
.destructor_cb = lv_meter_destructor,
|
||||
.draw_cb = lv_meter_draw,
|
||||
.event_cb = lv_meter_event,
|
||||
.instance_size = sizeof(lv_meter_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -290,16 +290,13 @@ static void lv_meter_destructor(lv_obj_t * obj)
|
||||
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_meter_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
static void lv_meter_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
lv_res_t res = lv_obj_event_base(MY_CLASS, obj, e);
|
||||
if(res != LV_RES_OK) return;
|
||||
|
||||
if(e == LV_EVENT_DRAW_MAIN) {
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_area_t scale_area;
|
||||
lv_obj_get_coords_fit(obj, &scale_area);
|
||||
|
||||
@ -323,15 +320,8 @@ static lv_draw_res_t lv_meter_draw(lv_obj_t * obj, const lv_area_t * clip_area,
|
||||
nm_cord.y2 = scale_center.y + size;
|
||||
lv_draw_rect(&nm_cord, clip_area, &mid_dsc);
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
|
||||
static void draw_arcs(lv_obj_t * obj, const lv_area_t * clip_area, const lv_area_t * scale_area)
|
||||
{
|
||||
lv_meter_t * meter = (lv_meter_t *)obj;
|
||||
|
@ -29,10 +29,10 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_roller_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static lv_draw_res_t lv_roller_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static lv_draw_res_t lv_roller_label_draw(lv_obj_t * label_obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_roller_event(lv_obj_t * obj, lv_event_t e);
|
||||
static void lv_roller_label_event(lv_obj_t * label, lv_event_t e);
|
||||
static void draw_main(lv_obj_t * obj, lv_event_t e);
|
||||
static void draw_label(lv_obj_t * label_obj, lv_event_t e);
|
||||
static void refr_position(lv_obj_t * obj, lv_anim_enable_t animen);
|
||||
static lv_res_t release_handler(lv_obj_t * obj);
|
||||
static void inf_normalize(lv_obj_t * obj_scrl);
|
||||
@ -47,7 +47,6 @@ static void set_y_anim(void * obj, int32_t v);
|
||||
const lv_obj_class_t lv_roller_class = {
|
||||
.constructor_cb = lv_roller_constructor,
|
||||
.event_cb = lv_roller_event,
|
||||
.draw_cb = lv_roller_draw,
|
||||
.instance_size = sizeof(lv_roller_t),
|
||||
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
|
||||
.base_class = &lv_obj_class
|
||||
@ -55,7 +54,6 @@ const lv_obj_class_t lv_roller_class = {
|
||||
|
||||
const lv_obj_class_t lv_roller_label_class = {
|
||||
.event_cb = lv_roller_label_event,
|
||||
.draw_cb = lv_roller_label_draw,
|
||||
.instance_size = sizeof(lv_label_t),
|
||||
.base_class = &lv_label_class
|
||||
};
|
||||
@ -286,7 +284,6 @@ uint16_t lv_roller_get_option_cnt(const lv_obj_t * obj)
|
||||
|
||||
static void lv_roller_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
{
|
||||
|
||||
lv_roller_t * roller = (lv_roller_t*)obj;
|
||||
|
||||
roller->mode = LV_ROLLER_MODE_NORMAL;
|
||||
@ -314,138 +311,6 @@ static void lv_roller_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
}
|
||||
|
||||
LV_LOG_TRACE("finshed");
|
||||
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_roller_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
/*Draw the selected rectangle*/
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
|
||||
lv_coord_t font_h = lv_font_get_line_height(font);
|
||||
lv_area_t rect_area;
|
||||
rect_area.y1 = obj->coords.y1 + (lv_obj_get_height(obj) - font_h - line_space) / 2;
|
||||
rect_area.y2 = rect_area.y1 + font_h + line_space - 1;
|
||||
lv_area_t roller_coords;
|
||||
lv_obj_get_coords(obj, &roller_coords);
|
||||
|
||||
rect_area.x1 = roller_coords.x1;
|
||||
rect_area.x2 = roller_coords.x2;
|
||||
|
||||
lv_draw_rect_dsc_t sel_dsc;
|
||||
lv_draw_rect_dsc_init(&sel_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_SELECTED, &sel_dsc);
|
||||
lv_draw_rect(&rect_area, clip_area, &sel_dsc);
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_SELECTED, &label_dsc);
|
||||
|
||||
lv_coord_t bg_font_h = lv_font_get_line_height(lv_obj_get_style_text_font(obj, LV_PART_MAIN));
|
||||
|
||||
/*Redraw the text on the selected area*/
|
||||
lv_area_t rect_area;
|
||||
rect_area.y1 = obj->coords.y1 + (lv_obj_get_height(obj) - bg_font_h - label_dsc.line_space) / 2;
|
||||
rect_area.y2 = rect_area.y1 + bg_font_h + label_dsc.line_space - 1;
|
||||
rect_area.x1 = obj->coords.x1;
|
||||
rect_area.x2 = obj->coords.x2;
|
||||
lv_area_t mask_sel;
|
||||
bool area_ok;
|
||||
area_ok = _lv_area_intersect(&mask_sel, clip_area, &rect_area);
|
||||
if(area_ok) {
|
||||
lv_obj_t * label = get_label(obj);
|
||||
|
||||
/*Get the size of the "selected text"*/
|
||||
lv_point_t res_p;
|
||||
lv_txt_get_size(&res_p, lv_label_get_text(label), label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
|
||||
lv_obj_get_width(obj), LV_TEXT_FLAG_EXPAND);
|
||||
|
||||
/*Move the selected label proportionally with the background label*/
|
||||
lv_coord_t roller_h = lv_obj_get_height(obj);
|
||||
int32_t label_y_prop = label->coords.y1 - (roller_h / 2 +
|
||||
obj->coords.y1); /*label offset from the middle line of the roller*/
|
||||
label_y_prop = (label_y_prop << 14) / lv_obj_get_height(
|
||||
label); /*Proportional position from the middle line (upscaled)*/
|
||||
|
||||
/*Apply a correction with different line heights*/
|
||||
const lv_font_t * normal_label_font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
lv_coord_t corr = (label_dsc.font->line_height - normal_label_font->line_height) / 2;
|
||||
|
||||
/*Apply the proportional position to the selected text*/
|
||||
res_p.y -= corr;
|
||||
int32_t label_sel_y = roller_h / 2 + obj->coords.y1;
|
||||
label_sel_y += (label_y_prop * res_p.y) >> 14;
|
||||
label_sel_y -= corr;
|
||||
|
||||
/*Draw the selected text*/
|
||||
lv_area_t label_sel_area;
|
||||
label_sel_area.x1 = label->coords.x1;
|
||||
label_sel_area.y1 = label_sel_y;
|
||||
label_sel_area.x2 = label->coords.x2;
|
||||
label_sel_area.y2 = label_sel_area.y1 + res_p.y;
|
||||
|
||||
label_dsc.flag |= LV_TEXT_FLAG_EXPAND;
|
||||
lv_draw_label(&label_sel_area, &mask_sel, &label_dsc, lv_label_get_text(label), NULL);
|
||||
}
|
||||
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_roller_label_draw(lv_obj_t * label_obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return lv_obj_draw_base(MY_CLASS_LABEL, label_obj, clip_area, mode);
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
/* Split the drawing of the label into an upper (above the selected area)
|
||||
* and a lower (below the selected area)*/
|
||||
lv_obj_t * roller = lv_obj_get_parent(label_obj);
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(roller, LV_PART_MAIN);
|
||||
lv_coord_t line_space = lv_obj_get_style_text_line_space(roller, LV_PART_MAIN);
|
||||
lv_coord_t font_h = lv_font_get_line_height(font);
|
||||
|
||||
lv_area_t rect_area;
|
||||
rect_area.y1 = roller->coords.y1 + (lv_obj_get_height(roller) - font_h - line_space) / 2;
|
||||
if((font_h & 0x1) && (line_space & 0x1)) rect_area.y1--; /*Compensate the two rounding error*/
|
||||
rect_area.y2 = rect_area.y1 + font_h + line_space - 1;
|
||||
lv_area_t roller_coords;
|
||||
lv_obj_get_coords(roller, &roller_coords);
|
||||
|
||||
rect_area.x1 = roller_coords.x1;
|
||||
rect_area.x2 = roller_coords.x2;
|
||||
|
||||
lv_area_t clip2;
|
||||
clip2.x1 = label_obj->coords.x1;
|
||||
clip2.y1 = label_obj->coords.y1;
|
||||
clip2.x2 = label_obj->coords.x2;
|
||||
clip2.y2 = rect_area.y1;
|
||||
if(_lv_area_intersect(&clip2, clip_area, &clip2)) {
|
||||
lv_obj_draw_base(MY_CLASS_LABEL, label_obj, clip_area, mode);
|
||||
}
|
||||
|
||||
clip2.x1 = label_obj->coords.x1;
|
||||
clip2.y1 = rect_area.y2;
|
||||
clip2.x2 = label_obj->coords.x2;
|
||||
clip2.y2 = label_obj->coords.y2;
|
||||
if(_lv_area_intersect(&clip2, clip_area, &clip2)) {
|
||||
lv_obj_draw_base(MY_CLASS_LABEL, label_obj, clip_area, mode);
|
||||
}
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_roller_event(lv_obj_t * obj, lv_event_t e)
|
||||
@ -543,15 +408,21 @@ static void lv_roller_event(lv_obj_t * obj, lv_event_t e)
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN || e == LV_EVENT_DRAW_POST) {
|
||||
draw_main(obj, e);
|
||||
}
|
||||
}
|
||||
|
||||
static void lv_roller_label_event(lv_obj_t * label, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
|
||||
/* Include the ancient signal function */
|
||||
res = lv_obj_event_base(MY_CLASS_LABEL, label, e);
|
||||
if(res != LV_RES_OK) return;
|
||||
/*LV_EVENT_DRAW_MAIN will be called in the draw function*/
|
||||
if(e != LV_EVENT_DRAW_MAIN) {
|
||||
/* Include the ancient signal function */
|
||||
res = lv_obj_event_base(MY_CLASS_LABEL, label, e);
|
||||
if(res != LV_RES_OK) return;
|
||||
}
|
||||
|
||||
if(e == LV_EVENT_REFR_EXT_DRAW_SIZE) {
|
||||
/*If the selected text has a larger font it needs some extra space to draw it*/
|
||||
@ -561,8 +432,130 @@ static void lv_roller_label_event(lv_obj_t * label, lv_event_t e)
|
||||
lv_coord_t label_w = lv_obj_get_width(label);
|
||||
*s = LV_MAX(*s, sel_w - label_w);
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_label(label, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void draw_main(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
if(e == LV_EVENT_DRAW_MAIN) {
|
||||
/*Draw the selected rectangle*/
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
|
||||
lv_coord_t font_h = lv_font_get_line_height(font);
|
||||
lv_area_t rect_area;
|
||||
rect_area.y1 = obj->coords.y1 + (lv_obj_get_height(obj) - font_h - line_space) / 2;
|
||||
rect_area.y2 = rect_area.y1 + font_h + line_space - 1;
|
||||
lv_area_t roller_coords;
|
||||
lv_obj_get_coords(obj, &roller_coords);
|
||||
|
||||
rect_area.x1 = roller_coords.x1;
|
||||
rect_area.x2 = roller_coords.x2;
|
||||
|
||||
lv_draw_rect_dsc_t sel_dsc;
|
||||
lv_draw_rect_dsc_init(&sel_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_SELECTED, &sel_dsc);
|
||||
lv_draw_rect(&rect_area, clip_area, &sel_dsc);
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(e == LV_EVENT_DRAW_POST) {
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
lv_draw_label_dsc_t label_dsc;
|
||||
lv_draw_label_dsc_init(&label_dsc);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_SELECTED, &label_dsc);
|
||||
|
||||
lv_coord_t bg_font_h = lv_font_get_line_height(lv_obj_get_style_text_font(obj, LV_PART_MAIN));
|
||||
|
||||
/*Redraw the text on the selected area*/
|
||||
lv_area_t rect_area;
|
||||
rect_area.y1 = obj->coords.y1 + (lv_obj_get_height(obj) - bg_font_h - label_dsc.line_space) / 2;
|
||||
rect_area.y2 = rect_area.y1 + bg_font_h + label_dsc.line_space - 1;
|
||||
rect_area.x1 = obj->coords.x1;
|
||||
rect_area.x2 = obj->coords.x2;
|
||||
lv_area_t mask_sel;
|
||||
bool area_ok;
|
||||
area_ok = _lv_area_intersect(&mask_sel, clip_area, &rect_area);
|
||||
if(area_ok) {
|
||||
lv_obj_t * label = get_label(obj);
|
||||
|
||||
/*Get the size of the "selected text"*/
|
||||
lv_point_t res_p;
|
||||
lv_txt_get_size(&res_p, lv_label_get_text(label), label_dsc.font, label_dsc.letter_space, label_dsc.line_space,
|
||||
lv_obj_get_width(obj), LV_TEXT_FLAG_EXPAND);
|
||||
|
||||
/*Move the selected label proportionally with the background label*/
|
||||
lv_coord_t roller_h = lv_obj_get_height(obj);
|
||||
int32_t label_y_prop = label->coords.y1 - (roller_h / 2 +
|
||||
obj->coords.y1); /*label offset from the middle line of the roller*/
|
||||
label_y_prop = (label_y_prop << 14) / lv_obj_get_height(
|
||||
label); /*Proportional position from the middle line (upscaled)*/
|
||||
|
||||
/*Apply a correction with different line heights*/
|
||||
const lv_font_t * normal_label_font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
|
||||
lv_coord_t corr = (label_dsc.font->line_height - normal_label_font->line_height) / 2;
|
||||
|
||||
/*Apply the proportional position to the selected text*/
|
||||
res_p.y -= corr;
|
||||
int32_t label_sel_y = roller_h / 2 + obj->coords.y1;
|
||||
label_sel_y += (label_y_prop * res_p.y) >> 14;
|
||||
label_sel_y -= corr;
|
||||
|
||||
/*Draw the selected text*/
|
||||
lv_area_t label_sel_area;
|
||||
label_sel_area.x1 = label->coords.x1;
|
||||
label_sel_area.y1 = label_sel_y;
|
||||
label_sel_area.x2 = label->coords.x2;
|
||||
label_sel_area.y2 = label_sel_area.y1 + res_p.y;
|
||||
|
||||
label_dsc.flag |= LV_TEXT_FLAG_EXPAND;
|
||||
lv_draw_label(&label_sel_area, &mask_sel, &label_dsc, lv_label_get_text(label), NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_label(lv_obj_t * label_obj, lv_event_t e)
|
||||
{
|
||||
/* Split the drawing of the label into an upper (above the selected area)
|
||||
* and a lower (below the selected area)*/
|
||||
lv_obj_t * roller = lv_obj_get_parent(label_obj);
|
||||
const lv_font_t * font = lv_obj_get_style_text_font(roller, LV_PART_MAIN);
|
||||
lv_coord_t line_space = lv_obj_get_style_text_line_space(roller, LV_PART_MAIN);
|
||||
lv_coord_t font_h = lv_font_get_line_height(font);
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
lv_area_t rect_area;
|
||||
rect_area.y1 = roller->coords.y1 + (lv_obj_get_height(roller) - font_h - line_space) / 2;
|
||||
if((font_h & 0x1) && (line_space & 0x1)) rect_area.y1--; /*Compensate the two rounding error*/
|
||||
rect_area.y2 = rect_area.y1 + font_h + line_space - 1;
|
||||
lv_area_t roller_coords;
|
||||
lv_obj_get_coords(roller, &roller_coords);
|
||||
|
||||
rect_area.x1 = roller_coords.x1;
|
||||
rect_area.x2 = roller_coords.x2;
|
||||
|
||||
lv_area_t clip2;
|
||||
clip2.x1 = label_obj->coords.x1;
|
||||
clip2.y1 = label_obj->coords.y1;
|
||||
clip2.x2 = label_obj->coords.x2;
|
||||
clip2.y2 = rect_area.y1;
|
||||
if(_lv_area_intersect(&clip2, clip_area, &clip2)) {
|
||||
lv_obj_event_base(MY_CLASS_LABEL, label_obj, e);
|
||||
}
|
||||
|
||||
clip2.x1 = label_obj->coords.x1;
|
||||
clip2.y1 = rect_area.y2;
|
||||
clip2.x2 = label_obj->coords.x2;
|
||||
clip2.y2 = label_obj->coords.y2;
|
||||
if(_lv_area_intersect(&clip2, clip_area, &clip2)) {
|
||||
lv_obj_event_base(MY_CLASS_LABEL, label_obj, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Refresh the position of the roller. It uses the id stored in: roller->ddlist.selected_option_id
|
||||
* @param roller pointer to a roller object
|
||||
|
@ -32,10 +32,9 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void lv_slider_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static lv_draw_res_t lv_slider_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_slider_event(lv_obj_t * obj, lv_event_t e);
|
||||
static void position_knob(lv_obj_t * obj, lv_area_t * knob_area, lv_coord_t knob_size, bool hor);
|
||||
static void draw_knob(lv_obj_t * obj, const lv_area_t * clip_area);
|
||||
static void draw_knob(lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -43,7 +42,6 @@ static void draw_knob(lv_obj_t * obj, const lv_area_t * clip_area);
|
||||
const lv_obj_class_t lv_slider_class = {
|
||||
.constructor_cb = lv_slider_constructor,
|
||||
.event_cb = lv_slider_event,
|
||||
.draw_cb = lv_slider_draw,
|
||||
.editable = LV_OBJ_CLASS_EDITABLE_TRUE,
|
||||
.instance_size = sizeof(lv_slider_t),
|
||||
.base_class = &lv_bar_class
|
||||
@ -98,29 +96,6 @@ static void lv_slider_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_slider_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
/* The ancestor draw function will draw the background and the indicator.
|
||||
* It also sets slider->bar.indic_area*/
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
draw_knob(obj, clip_area);
|
||||
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_slider_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
@ -340,12 +315,16 @@ static void lv_slider_event(lv_obj_t * obj, lv_event_t e)
|
||||
res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
if(res != LV_RES_OK) return;
|
||||
}
|
||||
} else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
draw_knob(obj);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_knob(lv_obj_t * obj, const lv_area_t * clip_area)
|
||||
static void draw_knob(lv_obj_t * obj)
|
||||
{
|
||||
lv_slider_t * slider = (lv_slider_t *)obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(obj);
|
||||
|
||||
lv_coord_t objw = lv_obj_get_width(obj);
|
||||
|
@ -35,7 +35,7 @@
|
||||
**********************/
|
||||
static void lv_switch_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_switch_event(lv_obj_t * obj, lv_event_t e);
|
||||
static lv_draw_res_t lv_switch_draw(lv_obj_t * sw, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void draw_main(lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -43,7 +43,6 @@ static lv_draw_res_t lv_switch_draw(lv_obj_t * sw, const lv_area_t * clip_area,
|
||||
const lv_obj_class_t lv_switch_class = {
|
||||
.constructor_cb = lv_switch_constructor,
|
||||
.event_cb = lv_switch_event,
|
||||
.draw_cb = lv_switch_draw,
|
||||
.instance_size = sizeof(lv_switch_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -86,85 +85,6 @@ static void lv_switch_constructor(lv_obj_t * obj, const lv_obj_t * copy)
|
||||
LV_TRACE_OBJ_CREATE("finished");
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_switch_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return LV_DRAW_RES_NOT_COVER;
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
/*The ancestor draw function will draw the background.*/
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(obj);
|
||||
|
||||
/*Calculate the indicator area*/
|
||||
lv_coord_t bg_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
|
||||
bool chk = lv_obj_get_state(obj) & LV_STATE_CHECKED;
|
||||
/*Draw the indicator in checked state*/
|
||||
if(chk) {
|
||||
/*Respect the background's padding*/
|
||||
lv_area_t indic_area;
|
||||
lv_area_copy(&indic_area, &obj->coords);
|
||||
indic_area.x1 += bg_left;
|
||||
indic_area.x2 -= bg_right;
|
||||
indic_area.y1 += bg_top;
|
||||
indic_area.y2 -= bg_bottom;
|
||||
|
||||
lv_draw_rect_dsc_t draw_indic_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_indic_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_INDICATOR, &draw_indic_dsc);
|
||||
lv_draw_rect(&indic_area, clip_area, &draw_indic_dsc);
|
||||
}
|
||||
|
||||
/*Draw the knob*/
|
||||
lv_coord_t objh = lv_obj_get_height(obj);
|
||||
lv_coord_t knob_size = objh;
|
||||
lv_area_t knob_area;
|
||||
|
||||
/*Left*/
|
||||
if((base_dir != LV_BIDI_DIR_RTL && !chk) || (base_dir == LV_BIDI_DIR_RTL && chk)) {
|
||||
knob_area.x1 = obj->coords.x1 + bg_left;
|
||||
knob_area.x2 = knob_area.x1 + knob_size;
|
||||
}
|
||||
else {
|
||||
knob_area.x2 = obj->coords.x2 - bg_right;
|
||||
knob_area.x1 = knob_area.x2 - knob_size;
|
||||
}
|
||||
|
||||
knob_area.y1 = obj->coords.y1 + bg_top;
|
||||
knob_area.y2 = obj->coords.y2 - bg_bottom;
|
||||
|
||||
lv_coord_t knob_left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB);
|
||||
lv_coord_t knob_right = lv_obj_get_style_pad_right(obj, LV_PART_KNOB);
|
||||
lv_coord_t knob_top = lv_obj_get_style_pad_top(obj, LV_PART_KNOB);
|
||||
lv_coord_t knob_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_KNOB);
|
||||
|
||||
/*Apply the paddings on the knob area*/
|
||||
knob_area.x1 -= knob_left;
|
||||
knob_area.x2 += knob_right;
|
||||
knob_area.y1 -= knob_top;
|
||||
knob_area.y2 += knob_bottom;
|
||||
|
||||
lv_draw_rect_dsc_t knob_rect_dsc;
|
||||
lv_draw_rect_dsc_init(&knob_rect_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc);
|
||||
|
||||
lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc);
|
||||
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_switch_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
@ -201,6 +121,74 @@ static void lv_switch_event(lv_obj_t * obj, lv_event_t e)
|
||||
|
||||
lv_obj_invalidate(obj);
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_main(obj);
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_main(lv_obj_t * obj)
|
||||
{
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_bidi_dir_t base_dir = lv_obj_get_base_dir(obj);
|
||||
|
||||
/*Calculate the indicator area*/
|
||||
lv_coord_t bg_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
|
||||
bool chk = lv_obj_get_state(obj) & LV_STATE_CHECKED;
|
||||
/*Draw the indicator in checked state*/
|
||||
if(chk) {
|
||||
/*Respect the background's padding*/
|
||||
lv_area_t indic_area;
|
||||
lv_area_copy(&indic_area, &obj->coords);
|
||||
indic_area.x1 += bg_left;
|
||||
indic_area.x2 -= bg_right;
|
||||
indic_area.y1 += bg_top;
|
||||
indic_area.y2 -= bg_bottom;
|
||||
|
||||
lv_draw_rect_dsc_t draw_indic_dsc;
|
||||
lv_draw_rect_dsc_init(&draw_indic_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_INDICATOR, &draw_indic_dsc);
|
||||
lv_draw_rect(&indic_area, clip_area, &draw_indic_dsc);
|
||||
}
|
||||
|
||||
/*Draw the knob*/
|
||||
lv_coord_t objh = lv_obj_get_height(obj);
|
||||
lv_coord_t knob_size = objh;
|
||||
lv_area_t knob_area;
|
||||
|
||||
/*Left*/
|
||||
if((base_dir != LV_BIDI_DIR_RTL && !chk) || (base_dir == LV_BIDI_DIR_RTL && chk)) {
|
||||
knob_area.x1 = obj->coords.x1 + bg_left;
|
||||
knob_area.x2 = knob_area.x1 + knob_size;
|
||||
}
|
||||
else {
|
||||
knob_area.x2 = obj->coords.x2 - bg_right;
|
||||
knob_area.x1 = knob_area.x2 - knob_size;
|
||||
}
|
||||
|
||||
knob_area.y1 = obj->coords.y1 + bg_top;
|
||||
knob_area.y2 = obj->coords.y2 - bg_bottom;
|
||||
|
||||
lv_coord_t knob_left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB);
|
||||
lv_coord_t knob_right = lv_obj_get_style_pad_right(obj, LV_PART_KNOB);
|
||||
lv_coord_t knob_top = lv_obj_get_style_pad_top(obj, LV_PART_KNOB);
|
||||
lv_coord_t knob_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_KNOB);
|
||||
|
||||
/*Apply the paddings on the knob area*/
|
||||
knob_area.x1 -= knob_left;
|
||||
knob_area.x2 += knob_right;
|
||||
knob_area.y1 -= knob_top;
|
||||
knob_area.y2 += knob_bottom;
|
||||
|
||||
lv_draw_rect_dsc_t knob_rect_dsc;
|
||||
lv_draw_rect_dsc_init(&knob_rect_dsc);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc);
|
||||
|
||||
lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -31,8 +31,8 @@
|
||||
**********************/
|
||||
static void lv_table_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_table_destructor(lv_obj_t * obj);
|
||||
static lv_draw_res_t lv_table_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_table_event(lv_obj_t * obj, lv_event_t e);
|
||||
static void draw_main(lv_obj_t * obj);
|
||||
static lv_coord_t get_row_height(lv_obj_t * obj, uint16_t row_id, const lv_font_t * font,
|
||||
lv_coord_t letter_space, lv_coord_t line_space,
|
||||
lv_coord_t cell_left, lv_coord_t cell_right, lv_coord_t cell_top, lv_coord_t cell_bottom);
|
||||
@ -46,7 +46,6 @@ const lv_obj_class_t lv_table_class = {
|
||||
.constructor_cb = lv_table_constructor,
|
||||
.destructor_cb = lv_table_destructor,
|
||||
.event_cb = lv_table_event,
|
||||
.draw_cb = lv_table_draw,
|
||||
.base_class = &lv_obj_class,
|
||||
.instance_size = sizeof(lv_table_t),
|
||||
};
|
||||
@ -447,203 +446,6 @@ static void lv_table_destructor(lv_obj_t * obj)
|
||||
if(table->row_h) lv_mem_free(table->row_h);
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_table_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
/*Draw the object*/
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
/*Draw the background*/
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
|
||||
lv_table_t * table = (lv_table_t *)obj;
|
||||
|
||||
lv_point_t txt_size;
|
||||
lv_area_t cell_area;
|
||||
lv_area_t txt_area;
|
||||
lv_text_flag_t txt_flags;
|
||||
|
||||
lv_coord_t bg_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
|
||||
lv_coord_t cell_left = lv_obj_get_style_pad_left(obj, LV_PART_ITEMS);
|
||||
lv_coord_t cell_right = lv_obj_get_style_pad_right(obj, LV_PART_ITEMS);
|
||||
lv_coord_t cell_top = lv_obj_get_style_pad_top(obj, LV_PART_ITEMS);
|
||||
lv_coord_t cell_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_ITEMS);
|
||||
|
||||
lv_state_t state_ori = obj->state;
|
||||
obj->state = LV_STATE_DEFAULT;
|
||||
obj->style_list.skip_trans = 1;
|
||||
lv_draw_rect_dsc_t rect_dsc_def;
|
||||
lv_draw_rect_dsc_t rect_dsc_act; /*Passed to the event to modify it*/
|
||||
lv_draw_rect_dsc_init(&rect_dsc_def);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &rect_dsc_def);
|
||||
|
||||
lv_draw_label_dsc_t label_dsc_def;
|
||||
lv_draw_label_dsc_t label_dsc_act; /*Passed to the event to modify it*/
|
||||
lv_draw_label_dsc_init(&label_dsc_def);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_ITEMS, &label_dsc_def);
|
||||
obj->state = state_ori;
|
||||
obj->style_list.skip_trans = 0;
|
||||
|
||||
uint16_t col;
|
||||
uint16_t row;
|
||||
uint16_t cell = 0;
|
||||
|
||||
cell_area.y2 = obj->coords.y1 + bg_top - 1 - lv_obj_get_scroll_y(obj) ;
|
||||
lv_coord_t scroll_x = lv_obj_get_scroll_x(obj) ;
|
||||
bool rtl = lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL ? true : false;
|
||||
|
||||
/*Handle custom drawer*/
|
||||
lv_obj_draw_dsc_t dsc;
|
||||
lv_obj_draw_dsc_init(&dsc, clip_area);
|
||||
dsc.part = LV_PART_ITEMS;
|
||||
dsc.rect_dsc = &rect_dsc_act;
|
||||
dsc.label_dsc = &label_dsc_act;
|
||||
|
||||
for(row = 0; row < table->row_cnt; row++) {
|
||||
lv_coord_t h_row = table->row_h[row];
|
||||
|
||||
cell_area.y1 = cell_area.y2 + 1;
|
||||
cell_area.y2 = cell_area.y1 + h_row - 1;
|
||||
|
||||
if(cell_area.y1 > clip_area->y2) return LV_DRAW_RES_OK;
|
||||
|
||||
if(rtl) cell_area.x1 = obj->coords.x2 - bg_right - 1 - scroll_x;
|
||||
else cell_area.x2 = obj->coords.x1 + bg_left - 1 - scroll_x;
|
||||
|
||||
for(col = 0; col < table->col_cnt; col++) {
|
||||
lv_table_cell_ctrl_t ctrl = 0;
|
||||
if(table->cell_data[cell]) ctrl = table->cell_data[cell][0];
|
||||
|
||||
if(rtl) {
|
||||
cell_area.x2 = cell_area.x1 - 1;
|
||||
cell_area.x1 = cell_area.x2 - table->col_w[col] + 1;
|
||||
}
|
||||
else {
|
||||
cell_area.x1 = cell_area.x2 + 1;
|
||||
cell_area.x2 = cell_area.x1 + table->col_w[col] - 1;
|
||||
}
|
||||
|
||||
uint16_t col_merge = 0;
|
||||
for(col_merge = 0; col_merge + col < table->col_cnt - 1; col_merge++) {
|
||||
if(table->cell_data[cell + col_merge]) {
|
||||
char * next_cell_data = table->cell_data[cell + col_merge];
|
||||
if(next_cell_data) ctrl = next_cell_data[0];
|
||||
if(ctrl & LV_TABLE_CELL_CTRL_MERGE_RIGHT)
|
||||
if(rtl) cell_area.x1 -= table->col_w[col + col_merge + 1];
|
||||
else cell_area.x2 += table->col_w[col + col_merge + 1];
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(cell_area.y2 < clip_area->y1) {
|
||||
cell += col_merge + 1;
|
||||
col += col_merge;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*Expand the cell area with a half border to avoid drawing 2 borders next to each other*/
|
||||
lv_area_t cell_area_border;
|
||||
lv_area_copy(&cell_area_border, &cell_area);
|
||||
if((rect_dsc_def.border_side & LV_BORDER_SIDE_LEFT) && cell_area_border.x1 > obj->coords.x1 + bg_left) {
|
||||
cell_area_border.x1 -= rect_dsc_def.border_width / 2;
|
||||
}
|
||||
if((rect_dsc_def.border_side & LV_BORDER_SIDE_TOP) && cell_area_border.y1 > obj->coords.y1 + bg_top) {
|
||||
cell_area_border.y1 -= rect_dsc_def.border_width / 2;
|
||||
}
|
||||
if((rect_dsc_def.border_side & LV_BORDER_SIDE_RIGHT) && cell_area_border.x2 < obj->coords.x2 - bg_right - 1) {
|
||||
cell_area_border.x2 += rect_dsc_def.border_width / 2 + (rect_dsc_def.border_width & 0x1);
|
||||
}
|
||||
if((rect_dsc_def.border_side & LV_BORDER_SIDE_BOTTOM) &&
|
||||
cell_area_border.y2 < obj->coords.y2 - bg_bottom - 1) {
|
||||
cell_area_border.y2 += rect_dsc_def.border_width / 2 + (rect_dsc_def.border_width & 0x1);
|
||||
}
|
||||
|
||||
lv_state_t cell_state = LV_STATE_DEFAULT;
|
||||
if(row == table->row_act && col == table->col_act) {
|
||||
if(obj->state & LV_STATE_PRESSED) cell_state |= LV_STATE_PRESSED;
|
||||
if(obj->state & LV_STATE_FOCUSED) cell_state |= LV_STATE_FOCUSED;
|
||||
if(obj->state & LV_STATE_FOCUS_KEY) cell_state |= LV_STATE_FOCUS_KEY;
|
||||
if(obj->state & LV_STATE_EDITED) cell_state |= LV_STATE_EDITED;
|
||||
}
|
||||
|
||||
/*Set up the draw descriptors*/
|
||||
if(cell_state == LV_STATE_DEFAULT) {
|
||||
lv_memcpy(&rect_dsc_act, &rect_dsc_def, sizeof(lv_draw_rect_dsc_t));
|
||||
lv_memcpy(&label_dsc_act, &label_dsc_def, sizeof(lv_draw_label_dsc_t));
|
||||
}
|
||||
/*In other cases get the styles directly without caching them*/
|
||||
else {
|
||||
obj->state = cell_state;
|
||||
obj->style_list.skip_trans = 1;
|
||||
lv_draw_rect_dsc_init(&rect_dsc_act);
|
||||
lv_draw_label_dsc_init(&label_dsc_act);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &rect_dsc_act);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_ITEMS, &label_dsc_act);
|
||||
obj->state = state_ori;
|
||||
obj->style_list.skip_trans = 0;
|
||||
}
|
||||
|
||||
dsc.draw_area = &cell_area_border;
|
||||
dsc.id = row * table->col_cnt + col;
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc);
|
||||
|
||||
lv_draw_rect(&cell_area_border, clip_area, &rect_dsc_act);
|
||||
|
||||
if(table->cell_data[cell]) {
|
||||
txt_area.x1 = cell_area.x1 + cell_left;
|
||||
txt_area.x2 = cell_area.x2 - cell_right;
|
||||
txt_area.y1 = cell_area.y1 + cell_top;
|
||||
txt_area.y2 = cell_area.y2 - cell_bottom;
|
||||
|
||||
/*Align the content to the middle if not cropped*/
|
||||
bool crop = ctrl & LV_TABLE_CELL_CTRL_TEXT_CROP ? true : false;
|
||||
if(crop) txt_flags = LV_TEXT_FLAG_EXPAND;
|
||||
else txt_flags = LV_TEXT_FLAG_NONE;
|
||||
|
||||
lv_txt_get_size(&txt_size, table->cell_data[cell] + 1, label_dsc_def.font,
|
||||
label_dsc_act.letter_space, label_dsc_act.line_space,
|
||||
lv_area_get_width(&txt_area), txt_flags);
|
||||
|
||||
/*Align the content to the middle if not cropped*/
|
||||
if(!crop) {
|
||||
txt_area.y1 = cell_area.y1 + h_row / 2 - txt_size.y / 2;
|
||||
txt_area.y2 = cell_area.y1 + h_row / 2 + txt_size.y / 2;
|
||||
}
|
||||
|
||||
lv_area_t label_mask;
|
||||
bool label_mask_ok;
|
||||
label_mask_ok = _lv_area_intersect(&label_mask, clip_area, &cell_area);
|
||||
if(label_mask_ok) {
|
||||
lv_draw_label(&txt_area, &label_mask, &label_dsc_act, table->cell_data[cell] + 1, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc);
|
||||
|
||||
cell += col_merge + 1;
|
||||
col += col_merge;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*Post draw when the children are drawn*/
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_table_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
@ -726,10 +528,194 @@ static void lv_table_event(lv_obj_t * obj, lv_event_t e)
|
||||
res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
if(res != LV_RES_OK) return;
|
||||
}
|
||||
} else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_main(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void draw_main(lv_obj_t * obj)
|
||||
{
|
||||
lv_table_t * table = (lv_table_t *)obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
|
||||
lv_point_t txt_size;
|
||||
lv_area_t cell_area;
|
||||
lv_area_t txt_area;
|
||||
lv_text_flag_t txt_flags;
|
||||
|
||||
lv_coord_t bg_top = lv_obj_get_style_pad_top(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_left = lv_obj_get_style_pad_left(obj, LV_PART_MAIN);
|
||||
lv_coord_t bg_right = lv_obj_get_style_pad_right(obj, LV_PART_MAIN);
|
||||
|
||||
lv_coord_t cell_left = lv_obj_get_style_pad_left(obj, LV_PART_ITEMS);
|
||||
lv_coord_t cell_right = lv_obj_get_style_pad_right(obj, LV_PART_ITEMS);
|
||||
lv_coord_t cell_top = lv_obj_get_style_pad_top(obj, LV_PART_ITEMS);
|
||||
lv_coord_t cell_bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_ITEMS);
|
||||
|
||||
lv_state_t state_ori = obj->state;
|
||||
obj->state = LV_STATE_DEFAULT;
|
||||
obj->style_list.skip_trans = 1;
|
||||
lv_draw_rect_dsc_t rect_dsc_def;
|
||||
lv_draw_rect_dsc_t rect_dsc_act; /*Passed to the event to modify it*/
|
||||
lv_draw_rect_dsc_init(&rect_dsc_def);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &rect_dsc_def);
|
||||
|
||||
lv_draw_label_dsc_t label_dsc_def;
|
||||
lv_draw_label_dsc_t label_dsc_act; /*Passed to the event to modify it*/
|
||||
lv_draw_label_dsc_init(&label_dsc_def);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_ITEMS, &label_dsc_def);
|
||||
obj->state = state_ori;
|
||||
obj->style_list.skip_trans = 0;
|
||||
|
||||
uint16_t col;
|
||||
uint16_t row;
|
||||
uint16_t cell = 0;
|
||||
|
||||
cell_area.y2 = obj->coords.y1 + bg_top - 1 - lv_obj_get_scroll_y(obj) ;
|
||||
lv_coord_t scroll_x = lv_obj_get_scroll_x(obj) ;
|
||||
bool rtl = lv_obj_get_base_dir(obj) == LV_BIDI_DIR_RTL ? true : false;
|
||||
|
||||
/*Handle custom drawer*/
|
||||
lv_obj_draw_dsc_t dsc;
|
||||
lv_obj_draw_dsc_init(&dsc, clip_area);
|
||||
dsc.part = LV_PART_ITEMS;
|
||||
dsc.rect_dsc = &rect_dsc_act;
|
||||
dsc.label_dsc = &label_dsc_act;
|
||||
|
||||
for(row = 0; row < table->row_cnt; row++) {
|
||||
lv_coord_t h_row = table->row_h[row];
|
||||
|
||||
cell_area.y1 = cell_area.y2 + 1;
|
||||
cell_area.y2 = cell_area.y1 + h_row - 1;
|
||||
|
||||
if(cell_area.y1 > clip_area->y2) return;
|
||||
|
||||
if(rtl) cell_area.x1 = obj->coords.x2 - bg_right - 1 - scroll_x;
|
||||
else cell_area.x2 = obj->coords.x1 + bg_left - 1 - scroll_x;
|
||||
|
||||
for(col = 0; col < table->col_cnt; col++) {
|
||||
lv_table_cell_ctrl_t ctrl = 0;
|
||||
if(table->cell_data[cell]) ctrl = table->cell_data[cell][0];
|
||||
|
||||
if(rtl) {
|
||||
cell_area.x2 = cell_area.x1 - 1;
|
||||
cell_area.x1 = cell_area.x2 - table->col_w[col] + 1;
|
||||
}
|
||||
else {
|
||||
cell_area.x1 = cell_area.x2 + 1;
|
||||
cell_area.x2 = cell_area.x1 + table->col_w[col] - 1;
|
||||
}
|
||||
|
||||
uint16_t col_merge = 0;
|
||||
for(col_merge = 0; col_merge + col < table->col_cnt - 1; col_merge++) {
|
||||
if(table->cell_data[cell + col_merge]) {
|
||||
char * next_cell_data = table->cell_data[cell + col_merge];
|
||||
if(next_cell_data) ctrl = next_cell_data[0];
|
||||
if(ctrl & LV_TABLE_CELL_CTRL_MERGE_RIGHT)
|
||||
if(rtl) cell_area.x1 -= table->col_w[col + col_merge + 1];
|
||||
else cell_area.x2 += table->col_w[col + col_merge + 1];
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(cell_area.y2 < clip_area->y1) {
|
||||
cell += col_merge + 1;
|
||||
col += col_merge;
|
||||
continue;
|
||||
}
|
||||
|
||||
/*Expand the cell area with a half border to avoid drawing 2 borders next to each other*/
|
||||
lv_area_t cell_area_border;
|
||||
lv_area_copy(&cell_area_border, &cell_area);
|
||||
if((rect_dsc_def.border_side & LV_BORDER_SIDE_LEFT) && cell_area_border.x1 > obj->coords.x1 + bg_left) {
|
||||
cell_area_border.x1 -= rect_dsc_def.border_width / 2;
|
||||
}
|
||||
if((rect_dsc_def.border_side & LV_BORDER_SIDE_TOP) && cell_area_border.y1 > obj->coords.y1 + bg_top) {
|
||||
cell_area_border.y1 -= rect_dsc_def.border_width / 2;
|
||||
}
|
||||
if((rect_dsc_def.border_side & LV_BORDER_SIDE_RIGHT) && cell_area_border.x2 < obj->coords.x2 - bg_right - 1) {
|
||||
cell_area_border.x2 += rect_dsc_def.border_width / 2 + (rect_dsc_def.border_width & 0x1);
|
||||
}
|
||||
if((rect_dsc_def.border_side & LV_BORDER_SIDE_BOTTOM) &&
|
||||
cell_area_border.y2 < obj->coords.y2 - bg_bottom - 1) {
|
||||
cell_area_border.y2 += rect_dsc_def.border_width / 2 + (rect_dsc_def.border_width & 0x1);
|
||||
}
|
||||
|
||||
lv_state_t cell_state = LV_STATE_DEFAULT;
|
||||
if(row == table->row_act && col == table->col_act) {
|
||||
if(obj->state & LV_STATE_PRESSED) cell_state |= LV_STATE_PRESSED;
|
||||
if(obj->state & LV_STATE_FOCUSED) cell_state |= LV_STATE_FOCUSED;
|
||||
if(obj->state & LV_STATE_FOCUS_KEY) cell_state |= LV_STATE_FOCUS_KEY;
|
||||
if(obj->state & LV_STATE_EDITED) cell_state |= LV_STATE_EDITED;
|
||||
}
|
||||
|
||||
/*Set up the draw descriptors*/
|
||||
if(cell_state == LV_STATE_DEFAULT) {
|
||||
lv_memcpy(&rect_dsc_act, &rect_dsc_def, sizeof(lv_draw_rect_dsc_t));
|
||||
lv_memcpy(&label_dsc_act, &label_dsc_def, sizeof(lv_draw_label_dsc_t));
|
||||
}
|
||||
/*In other cases get the styles directly without caching them*/
|
||||
else {
|
||||
obj->state = cell_state;
|
||||
obj->style_list.skip_trans = 1;
|
||||
lv_draw_rect_dsc_init(&rect_dsc_act);
|
||||
lv_draw_label_dsc_init(&label_dsc_act);
|
||||
lv_obj_init_draw_rect_dsc(obj, LV_PART_ITEMS, &rect_dsc_act);
|
||||
lv_obj_init_draw_label_dsc(obj, LV_PART_ITEMS, &label_dsc_act);
|
||||
obj->state = state_ori;
|
||||
obj->style_list.skip_trans = 0;
|
||||
}
|
||||
|
||||
dsc.draw_area = &cell_area_border;
|
||||
dsc.id = row * table->col_cnt + col;
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_BEGIN, &dsc);
|
||||
|
||||
lv_draw_rect(&cell_area_border, clip_area, &rect_dsc_act);
|
||||
|
||||
if(table->cell_data[cell]) {
|
||||
txt_area.x1 = cell_area.x1 + cell_left;
|
||||
txt_area.x2 = cell_area.x2 - cell_right;
|
||||
txt_area.y1 = cell_area.y1 + cell_top;
|
||||
txt_area.y2 = cell_area.y2 - cell_bottom;
|
||||
|
||||
/*Align the content to the middle if not cropped*/
|
||||
bool crop = ctrl & LV_TABLE_CELL_CTRL_TEXT_CROP ? true : false;
|
||||
if(crop) txt_flags = LV_TEXT_FLAG_EXPAND;
|
||||
else txt_flags = LV_TEXT_FLAG_NONE;
|
||||
|
||||
lv_txt_get_size(&txt_size, table->cell_data[cell] + 1, label_dsc_def.font,
|
||||
label_dsc_act.letter_space, label_dsc_act.line_space,
|
||||
lv_area_get_width(&txt_area), txt_flags);
|
||||
|
||||
/*Align the content to the middle if not cropped*/
|
||||
if(!crop) {
|
||||
txt_area.y1 = cell_area.y1 + h_row / 2 - txt_size.y / 2;
|
||||
txt_area.y2 = cell_area.y1 + h_row / 2 + txt_size.y / 2;
|
||||
}
|
||||
|
||||
lv_area_t label_mask;
|
||||
bool label_mask_ok;
|
||||
label_mask_ok = _lv_area_intersect(&label_mask, clip_area, &cell_area);
|
||||
if(label_mask_ok) {
|
||||
lv_draw_label(&txt_area, &label_mask, &label_dsc_act, table->cell_data[cell] + 1, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
lv_event_send(obj, LV_EVENT_DRAW_PART_END, &dsc);
|
||||
|
||||
cell += col_merge + 1;
|
||||
col += col_merge;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void refr_size(lv_obj_t * obj, uint32_t strat_row)
|
||||
{
|
||||
lv_table_t * table = (lv_table_t *)obj;
|
||||
|
@ -47,7 +47,6 @@
|
||||
**********************/
|
||||
static void lv_textarea_constructor(lv_obj_t * obj, const lv_obj_t * copy);
|
||||
static void lv_textarea_destructor(lv_obj_t * obj);
|
||||
static lv_draw_res_t lv_textarea_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode);
|
||||
static void lv_textarea_event(lv_obj_t * obj, lv_event_t e);
|
||||
static void cursor_blink_anim_cb(void * obj, int32_t show);
|
||||
static void pwd_char_hider_anim(void * obj, int32_t x);
|
||||
@ -58,8 +57,8 @@ static void start_cursor_blink(lv_obj_t * obj);
|
||||
static void refr_cursor_area(lv_obj_t * obj);
|
||||
static void update_cursor_position_on_click(lv_obj_t * obj, lv_event_t e);
|
||||
static lv_res_t insert_handler(lv_obj_t * obj, const char * txt);
|
||||
static void draw_placeholder(lv_obj_t * obj, const lv_area_t * clip_area);
|
||||
static void draw_cursor(lv_obj_t * obj, const lv_area_t * clip_area);
|
||||
static void draw_placeholder(lv_obj_t * obj);
|
||||
static void draw_cursor(lv_obj_t * obj);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@ -68,7 +67,6 @@ const lv_obj_class_t lv_textarea_class = {
|
||||
.constructor_cb = lv_textarea_constructor,
|
||||
.destructor_cb = lv_textarea_destructor,
|
||||
.event_cb = lv_textarea_event,
|
||||
.draw_cb = lv_textarea_draw,
|
||||
.instance_size = sizeof(lv_textarea_t),
|
||||
.base_class = &lv_obj_class
|
||||
};
|
||||
@ -1022,25 +1020,6 @@ static void lv_textarea_destructor(lv_obj_t * obj)
|
||||
}
|
||||
}
|
||||
|
||||
static lv_draw_res_t lv_textarea_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode)
|
||||
{
|
||||
if(mode == LV_DRAW_MODE_COVER_CHECK) {
|
||||
/*Return false if the object is not covers the mask_p area*/
|
||||
return lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_MAIN_DRAW) {
|
||||
/*Draw the object*/
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
draw_placeholder(obj, clip_area);
|
||||
|
||||
}
|
||||
else if(mode == LV_DRAW_MODE_POST_DRAW) {
|
||||
lv_obj_draw_base(MY_CLASS, obj, clip_area, mode);
|
||||
draw_cursor(obj, clip_area);
|
||||
}
|
||||
return LV_DRAW_RES_OK;
|
||||
}
|
||||
|
||||
static void lv_textarea_event(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
lv_res_t res;
|
||||
@ -1117,6 +1096,12 @@ static void lv_textarea_event(lv_obj_t * obj, lv_event_t e)
|
||||
e == LV_EVENT_RELEASED) {
|
||||
update_cursor_position_on_click(obj, e);
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_MAIN) {
|
||||
draw_placeholder(obj);
|
||||
}
|
||||
else if(e == LV_EVENT_DRAW_POST) {
|
||||
draw_cursor(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1471,9 +1456,10 @@ static lv_res_t insert_handler(lv_obj_t * obj, const char * txt)
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
static void draw_placeholder(lv_obj_t * obj, const lv_area_t * clip_area)
|
||||
static void draw_placeholder(lv_obj_t * obj)
|
||||
{
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
const char * txt = lv_label_get_text(ta->label);
|
||||
|
||||
/*Draw the place holder*/
|
||||
@ -1496,9 +1482,10 @@ static void draw_placeholder(lv_obj_t * obj, const lv_area_t * clip_area)
|
||||
}
|
||||
}
|
||||
|
||||
static void draw_cursor(lv_obj_t * obj, const lv_area_t * clip_area)
|
||||
static void draw_cursor(lv_obj_t * obj)
|
||||
{
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
lv_textarea_t * ta = (lv_textarea_t *)obj;
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
const char * txt = lv_label_get_text(ta->label);
|
||||
|
||||
if(ta->cursor.show == 0) return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user