From 454b0e2a11fa7cce24d7e7cb4c2c7bae983c71a0 Mon Sep 17 00:00:00 2001 From: Gabor Date: Thu, 22 Dec 2016 15:00:22 +0100 Subject: [PATCH] App connection added --- lv_app/lv_app.c | 843 +++++++++++++++++++++++++-------------- lv_app/lv_app.h | 7 +- lv_appx/lv_app_example.c | 22 +- lv_draw/lv_draw_vbasic.c | 36 +- lv_misc/font.h | 8 - lv_misc/text.c | 8 +- lv_obj/lv_obj.h | 4 +- lv_objx/lv_btn.c | 14 +- lv_objx/lv_btnm.c | 3 +- lv_objx/lv_page.c | 34 +- 10 files changed, 620 insertions(+), 359 deletions(-) diff --git a/lv_app/lv_app.c b/lv_app/lv_app.c index d9df9530b..8f3135441 100644 --- a/lv_app/lv_app.c +++ b/lv_app/lv_app.c @@ -19,43 +19,52 @@ /********************** * TYPEDEFS **********************/ +typedef struct { + lv_app_inst_t * sender; + lv_app_inst_t * receiver; +}lv_app_con_t; /********************** * STATIC PROTOTYPES **********************/ +static void lv_app_init_desktop(void); + /*Actions*/ static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_dispi_t * dispi); static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_dispi_t * dispi); static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * sc, lv_dispi_t * dispi); -static lv_action_res_t lv_app_sc_page_pr_action(lv_obj_t * sc, lv_dispi_t * dispi); static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi); -static lv_action_res_t lv_app_sc_pr_action(lv_obj_t * sc, lv_dispi_t * dispi); +static lv_action_res_t lv_app_sc_lpr_action(lv_obj_t * sc, lv_dispi_t * dispi); static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t * dispi); -static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_btn, lv_dispi_t * dispi); -#if LV_APP_ANIM_LEVEL != 0 && LV_APP_ANIM_WIN != 0 +static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_minim, lv_dispi_t * dispi); + +static lv_action_res_t lv_app_win_open_anim_create(lv_app_inst_t * app); +static lv_action_res_t lv_app_win_minim_anim_create(lv_app_inst_t * app); +#if LV_APP_EFFECT_ANIM != 0 && LV_APP_ANIM_WIN != 0 static void lv_app_win_close_anim_cb(lv_obj_t * app_win); -static void lv_app_win_minim_anim_cb(lv_obj_t * app_win); #endif static void lv_app_init_icons(void); static void lv_app_init_style(void); + /********************** * STATIC VARIABLES **********************/ -static ll_dsc_t app_dsc_ll; /*Store a pointer to the app descriptors*/ +static ll_dsc_t app_dsc_ll; /*Store a pointer to the app. descriptors*/ static ll_dsc_t app_inst_ll; /*Store the running apps*/ +static ll_dsc_t app_con_ll; /*Store the communication connection between the apps*/ +static lv_obj_t * app_scr; /*Screen of the applications*/ +static lv_obj_t * menuh; /*Holder of timg_bubbleshe menu on the top*/ +static lv_obj_t * app_btn; /*The "Apps" button on the menu*/ +static lv_obj_t * sys_apph; /*Holder of the system app. buttons*/ +static lv_obj_t * clock; /*Clock on the menu bar (right top)*/ +static lv_obj_t * app_list; /*A list which is opened on 'app_btn' release*/ +static lv_obj_t * sc_page; /*A page for the shortcuts */ +static lv_app_inst_t * con_send; /*The sender application in connection mode. Not NLL means connection mode is active*/ +static lv_app_style_t app_style; /*Styles for application related things*/ -static lv_obj_t * app_scr; -static lv_obj_t * menuh; /*Holder of timg_bubbleshe menu on the top*/ -static lv_obj_t * app_btn; /*The "Apps" button on the menu*/ -static lv_obj_t * sys_apph; /*Holder of the system app. buttons*/ -static lv_obj_t * clock; /*Clock on the menu bar (right top)*/ -static lv_obj_t * app_list; -static lv_obj_t * sc_page; -static lv_app_style_t app_style; -#include "lvgl/lv_objx/lv_img.h" /*Declare icons*/ LV_IMG_DECLARE(img_add); LV_IMG_DECLARE(img_battery_empty); @@ -96,55 +105,20 @@ LV_IMG_DECLARE(img_volume); */ void lv_app_init(void) { + /*Init linked lists*/ ll_init(&app_dsc_ll, sizeof(lv_app_dsc_t *)); ll_init(&app_inst_ll, sizeof(lv_app_inst_t)); + ll_init(&app_con_ll, sizeof(lv_app_con_t)); app_scr = lv_scr_act(); - lv_app_init_icons(); lv_app_init_style(); /*Create the desktop elements*/ - - /*Shortcut area*/ - sc_page = lv_page_create(lv_scr_act(), NULL); - lv_obj_set_style(sc_page, &app_style.sc_page_style); - lv_obj_set_size(sc_page, LV_HOR_RES, LV_VER_RES); - lv_obj_set_pos(sc_page, 0, 0); - lv_rect_set_fit(lv_page_get_scrable(sc_page), false, true); - lv_rect_set_layout(lv_page_get_scrable(sc_page), LV_RECT_LAYOUT_GRID); - lv_page_set_rel_action(sc_page, lv_app_sc_page_rel_action); - lv_page_set_pr_action(sc_page, lv_app_sc_page_pr_action); - - /*Menu on the top*/ - menuh = lv_rect_create(lv_scr_act(), NULL); - lv_obj_set_size(menuh, LV_HOR_RES, app_style.menu_h); - lv_obj_set_pos(menuh, 0, 0); - lv_obj_set_style(menuh, &app_style.menu_style); - - app_btn = lv_btn_create(menuh, NULL); - lv_obj_set_style(app_btn, &app_style.menu_btn_style); - lv_obj_set_height(app_btn, app_style.menu_h); - lv_rect_set_fit(app_btn, true, false); - lv_btn_set_rel_action(app_btn, lv_app_menu_rel_action); - lv_obj_t * app_label = lv_label_create(app_btn, NULL); - lv_obj_set_style(app_label, &app_style.menu_btn_label_style); - lv_label_set_text(app_label, "Apps"); - lv_obj_set_pos(app_btn, 0, 0); - - sys_apph = lv_rect_create(menuh, NULL); - lv_rect_set_layout(sys_apph, LV_RECT_LAYOUT_ROW_M); - lv_rect_set_fit(sys_apph, true, false); - lv_obj_set_height(sys_apph, app_style.menu_h); - lv_obj_set_style(sys_apph, lv_rects_get(LV_RECTS_TRANSP, NULL)); - clock = lv_label_create(sys_apph, NULL); - lv_obj_set_style(clock, &app_style.menu_btn_label_style); - lv_label_set_text(clock, "20:17"); - lv_obj_align(sys_apph, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); - lv_app_refr_style(); - + lv_app_init_desktop(); /*Initialize all application descriptors*/ + /*ADD NEW APPLICATION INITS HERE!!!*/ const lv_app_dsc_t ** dsc; #if USE_LV_APP_EXAMPLE != 0 dsc = ll_ins_head(&app_dsc_ll); @@ -166,7 +140,7 @@ lv_app_inst_t * lv_app_run(const lv_app_dsc_t * app_dsc, const char * cstr) app->dsc = app_dsc; app->app_data = dm_alloc(app_dsc->app_data_size); app->name = NULL; - lv_app_rename(app, app_dsc->name); + lv_app_rename(app, app_dsc->name); /*Set a default name*/ /*Call the application specific run function*/ app_dsc->app_run(app, cstr); @@ -189,19 +163,6 @@ void lv_app_close(lv_app_inst_t * app) dm_free(app->name); } -/** - * Send data to other applications - * @param app_send pointer to the application which is sending the message - * @param type type of data from 'lv_app_com_type_t' enum - * @param data pointer to the sent data - * @param len length of 'data' in bytes - * @return number application which were received the message - */ -uint16_t lv_app_com_send(lv_app_inst_t * app_send, lv_app_com_type_t type , void * data, uint32_t len) -{ - return 0; -} - /** * Open a shortcut for an application * @param app pointer to an application @@ -212,6 +173,7 @@ lv_obj_t * lv_app_sc_open(lv_app_inst_t * app) /*Save the current position of the scrollable part of the page*/ cord_t scrl_y = lv_obj_get_y(lv_page_get_scrable(sc_page)); + /*Create a basic shortcut*/ app->sc = lv_btn_create(sc_page, NULL); lv_obj_set_free_p(app->sc, app); lv_obj_set_style(app->sc, &app_style.sc_style); @@ -219,24 +181,32 @@ lv_obj_t * lv_app_sc_open(lv_app_inst_t * app) lv_obj_set_size(app->sc, LV_APP_SC_WIDTH, LV_APP_SC_HEIGHT); lv_rect_set_layout(app->sc, LV_RECT_LAYOUT_OFF); lv_btn_set_rel_action(app->sc, lv_app_sc_rel_action); - lv_btn_set_pr_action(app->sc, lv_app_sc_pr_action); + lv_btn_set_lpr_action(app->sc, lv_app_sc_lpr_action); lv_page_glue_obj(app->sc, true); + /*Create a title on top of the shortcut*/ + app->sc_title = lv_label_create(app->sc, NULL); + lv_obj_set_style(app->sc_title, &app_style.sc_title_style); +#if LV_APP_EFFECT_ANIM != 0 + lv_label_set_long_mode(app->sc_title, LV_LABEL_LONG_SCROLL); +#else + lv_obj_set_size(app->sc_title, LV_APP_SC_WIDTH, font_get_height(font_get(app_style.sc_title_style.font))); + lv_label_set_long_mode(app->sc_title, LV_LABEL_LONG_DOTS); +#endif + lv_label_set_text(app->sc_title, app->name); + lv_obj_align_us(app->sc_title, NULL, LV_ALIGN_IN_TOP_MID, 0, app_style.sc_title_margin); + + /*Allocate data and call the app specific sc_open function*/ app->sc_data = dm_alloc(app->dsc->sc_data_size); app->dsc->sc_open(app, app->sc); - app->sc_title = lv_label_create(app->sc, NULL); - lv_obj_set_style(app->sc_title, &app_style.sc_title_style); - //lv_label_set_long_mode(app->sc_title, LV_LABEL_LONG_SCROLL); - lv_label_set_text(app->sc_title, app->name); - lv_obj_align_us(app->sc_title, NULL, LV_ALIGN_IN_TOP_MID, 0, app_style.sc_title_margin); - - /*Restore position of the scrollable part of the page*/ + /* Restore position of the scrollable part of the page because + * it moved when the shortcut is created*/ lv_obj_set_y(lv_page_get_scrable(sc_page), scrl_y); -#if LV_APP_ANIM_LEVEL != 0 - lv_page_focus(sc_page, app->sc, true); +#if LV_APP_EFFECT_ANIM == 0 + lv_page_focus(sc_page, app->sc, false); #else - lv_page_focus(sc_page, app->sc, false); + lv_page_focus(sc_page, app->sc, true); #endif return app->sc; @@ -301,17 +271,103 @@ void lv_app_win_close(lv_app_inst_t * app) dm_free(app->win_data); app->win_data = NULL; } - - -void lv_app_refr_style(void) +/** + * Send data to other applications + * @param app_send pointer to the application which is sending the message + * @param type type of data from 'lv_app_com_type_t' enum + * @param data pointer to the sent data + * @param len length of 'data' in bytes + * @return number application which were received the message + */ +uint16_t lv_app_com_send(lv_app_inst_t * app_send, lv_app_com_type_t type , const void * data, uint32_t len) { - lv_obj_set_opa(menuh, app_style.menu_opa); - lv_obj_set_opa(app_btn, app_style.menu_btn_opa); + lv_app_con_t * con; + uint16_t rec_cnt = 0; - lv_obj_set_width(lv_page_get_scrable(sc_page), - LV_HOR_RES - 2 * (app_style.sc_page_style.bg_rects.hpad)); + LL_READ(app_con_ll, con) { + if(con->sender == app_send) { + if(con->receiver->dsc->com_rec != NULL) + con->receiver->dsc->com_rec(app_send, con->receiver, type, data, len); + rec_cnt ++; + } + } + + return rec_cnt; } +/** + * Test an application communication connection + * @param sender pointer to an application which sends data + * @param receiver pointer to an application which receives data + * @return false: no connection, true: there is connection + */ +bool lv_app_check_con(lv_app_inst_t * sender, lv_app_inst_t * receiver) +{ + lv_app_con_t * con; + + LL_READ(app_con_ll, con) { + if(con->sender == sender && con->receiver == receiver) { + return true; + } + } + + return false; +} + +/** + * Create a new connection between two applications + * @param sender pointer to a data sender application + * @param receiver pointer to a data receiver application + */ +void lv_app_set_con(lv_app_inst_t * sender, lv_app_inst_t * receiver) +{ + if(lv_app_check_con(sender, receiver) == false) { + lv_app_con_t * con; + con = ll_ins_head(&app_con_ll); + con->sender = sender; + con->receiver = receiver; + } +} + +/** + * Delete a communication connection + * @param sender pointer to a data sender application + * @param receiver pointer to a data receiver application + */ +void lv_app_del_con(lv_app_inst_t * sender, lv_app_inst_t * receiver) +{ + lv_app_con_t * con; + + LL_READ(app_con_ll, con) { + if(con->sender == sender && con->receiver == receiver) { + ll_rem(&app_con_ll, con); + dm_free(con); + } + } +} + +/** + * Get the application descriptor from its name + * @param name name of the app. dsc. + * @return pointer to the app. dsc. + */ +const lv_app_dsc_t * lv_app_get_dsc(const char * name) +{ + const lv_app_dsc_t ** dsc; + LL_READ(app_dsc_ll, dsc) { + if(strcmp((*dsc)->name, name) == 0) { + return *dsc; + } + } + + return NULL; +} + +/** + * Rename an application + * @param app pointer to an application + * @param name a string with the new name + */ void lv_app_rename(lv_app_inst_t * app, const char * name) { dm_free(app->name); @@ -323,6 +379,11 @@ void lv_app_rename(lv_app_inst_t * app, const char * name) } } +/** + * Get the window object from an object located on the window + * @param obj pointer to an object on the window + * @return pointer to the window of 'obj' + */ lv_obj_t * lv_app_get_win_from_obj(lv_obj_t * obj) { lv_obj_t * par = obj; @@ -337,17 +398,6 @@ lv_obj_t * lv_app_get_win_from_obj(lv_obj_t * obj) return win; } -const lv_app_dsc_t * lv_app_get_dsc(const char * name) -{ - const lv_app_dsc_t ** dsc; - LL_READ(app_dsc_ll, dsc) { - if(strcmp((*dsc)->name, name) == 0) { - return *dsc; - } - } - - return NULL; -} /** * Read the list of the running applications. (Get he next element) @@ -371,16 +421,88 @@ lv_app_inst_t * lv_app_get_next_app(lv_app_inst_t * prev, lv_app_dsc_t * dsc) return NULL; } +/** + * Refresh the style of the applications + * */ +void lv_app_refr_style(void) +{ + lv_style_refr_all(NULL); + lv_obj_set_opa(menuh, app_style.menu_opa); + lv_obj_set_opa(app_btn, app_style.menu_btn_opa); + + lv_obj_set_width(lv_page_get_scrable(sc_page), + LV_HOR_RES - 2 * (app_style.sc_page_style.bg_rects.hpad)); +} + + +/** + * Get a pointer to the application style structure. If modified then 'lv_app_refr_style' should be called + * @return pointer to the application style structure + */ lv_app_style_t * lv_app_get_style(void) { - return &app_style; + return &app_style; } /********************** * STATIC FUNCTIONS **********************/ +/** + * Create the object on the desktop + */ +static void lv_app_init_desktop(void) +{ + /*Shortcut area*/ + sc_page = lv_page_create(lv_scr_act(), NULL); + lv_obj_set_style(sc_page, &app_style.sc_page_style); + lv_obj_set_size(sc_page, LV_HOR_RES, LV_VER_RES); + lv_obj_set_pos(sc_page, 0, 0); + lv_rect_set_fit(lv_page_get_scrable(sc_page), false, true); + lv_rect_set_layout(lv_page_get_scrable(sc_page), LV_RECT_LAYOUT_GRID); + lv_page_set_rel_action(sc_page, lv_app_sc_page_rel_action); + + /*Menu on the top*/ + menuh = lv_rect_create(lv_scr_act(), NULL); + lv_obj_set_size(menuh, LV_HOR_RES, app_style.menu_h); + lv_obj_set_pos(menuh, 0, 0); + lv_obj_set_style(menuh, &app_style.menu_style); + + app_btn = lv_btn_create(menuh, NULL); + lv_obj_set_style(app_btn, &app_style.menu_btn_style); + lv_obj_set_height(app_btn, app_style.menu_h); + lv_rect_set_fit(app_btn, true, false); + lv_btn_set_rel_action(app_btn, lv_app_menu_rel_action); + lv_obj_t * app_label = lv_label_create(app_btn, NULL); + lv_obj_set_style(app_label, &app_style.menu_btn_label_style); + lv_label_set_text(app_label, "Apps"); + lv_obj_set_pos(app_btn, 0, 0); + + sys_apph = lv_rect_create(menuh, NULL); + lv_rect_set_layout(sys_apph, LV_RECT_LAYOUT_ROW_M); + lv_rect_set_fit(sys_apph, true, false); + lv_obj_set_height(sys_apph, app_style.menu_h); + lv_obj_set_style(sys_apph, lv_rects_get(LV_RECTS_TRANSP, NULL)); + clock = lv_label_create(sys_apph, NULL); + lv_obj_set_style(clock, &app_style.menu_btn_label_style); + lv_label_set_text(clock, "20:17"); + lv_obj_align(sys_apph, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); + + lv_app_refr_style(); +} + + +/*----------------------- + APP. MENU ACTIONS + ------------------------*/ + +/** + * CAlled when the "Apps" button is released to open or close the app. list + * @param app_btn pointer to the "Apps" button + * @param dispi pointer to the caller display input + * @return LV_ACTION_RES_OK because the "Apps" button is never deleted + */ static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_dispi_t * dispi) { /*Close the list if opened*/ @@ -434,6 +556,12 @@ static lv_action_res_t lv_app_menu_rel_action(lv_obj_t * app_btn, lv_dispi_t * d return LV_ACTION_RES_OK; } +/** + * Called when an element of the app list is released + * @param app_elem_btn pointer to an element of app list + * @param dispi pointer to the caller display input + * @return LV_ACTION_RES_INV because the list is dleted on release + */ static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_dispi_t * dispi) { lv_app_dsc_t * dsc = lv_obj_get_free_p(app_elem_btn); @@ -445,15 +573,25 @@ static lv_action_res_t lv_app_menu_elem_rel_action(lv_obj_t * app_elem_btn, lv_d lv_app_inst_t * app = lv_app_run(dsc, ""); lv_app_sc_open(app); -#if LV_APP_ANIM_LEVEL == 2 && LV_APP_ANIM_SC != 0 +#if LV_APP_EFFECT_ANIM != 0 && LV_APP_EFFECT_OPA != 0 && LV_APP_ANIM_SC != 0 lv_obj_anim(app->sc, LV_ANIM_FADE | ANIM_IN, LV_APP_ANIM_SC, 0, NULL); #endif - return LV_ACTION_RES_INV; } -static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * sc, lv_dispi_t * dispi) +/*----------------------- + SHORTCUT ACTIONS + ------------------------*/ + +/** + * Called when the shortcut page is released to hide the app list and/or + * go back from connection mode + * @param page pointer to the sc page + * @param dispi pointer to the caller display input + * @return LV_ACTION_RES_OK because the sc page is not deleted + */ +static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * page, lv_dispi_t * dispi) { /*Close the list if opened*/ if(app_list != NULL) { @@ -461,104 +599,111 @@ static lv_action_res_t lv_app_sc_page_rel_action(lv_obj_t * sc, lv_dispi_t * dis app_list = NULL; } - return LV_ACTION_RES_OK; -} - -static lv_action_res_t lv_app_sc_page_pr_action(lv_obj_t * sc, lv_dispi_t * dispi) -{ - /*Close the list if opened*/ - if(app_list != NULL) { - lv_obj_del(app_list); - app_list = NULL; - } + if(con_send != NULL) { + lv_app_inst_t * i; + LL_READ(app_inst_ll, i) { + if(i->sc != NULL) lv_obj_set_style(i->sc, &app_style.sc_style); + } + con_send = NULL; + } return LV_ACTION_RES_OK; } +/** + * Called when a shortcut is released to open its window (or close app list if opened) (in normal mode) or + * add/remove it to/form a connection (in connection mode) + * @param sc pointer to the releases shortcut object + * @param dispi pointer to the caller display input + * @return LV_ACTION_RES_OK because the sc page is not deleted + */ static lv_action_res_t lv_app_sc_rel_action(lv_obj_t * sc, lv_dispi_t * dispi) { -#if LV_APP_ANIM_LEVEL != 0 - lv_page_focus(sc_page, sc, true); + /*Normal mode*/ + if(con_send == NULL) { + +#if LV_APP_EFFECT_ANIM == 0 + lv_page_focus(sc_page, sc, false); #else - lv_page_focus(sc_page, sc, false); + lv_page_focus(sc_page, sc, true); #endif - /*Close the list if opened*/ - if(app_list != NULL) { - lv_obj_del(app_list); - app_list = NULL; - } - /*Else open the window of the shortcut*/ - else { - lv_app_inst_t * app = lv_obj_get_free_p(sc); - lv_app_win_open(app); + /*Close the list if opened*/ + if(app_list != NULL) { + lv_obj_del(app_list); + app_list = NULL; + } + /*Else open the window of the shortcut*/ + else { + lv_app_inst_t * app = lv_obj_get_free_p(sc); + lv_app_win_open(app); -/*Make an animation on window open*/ -#if LV_APP_ANIM_WIN != 0 && LV_APP_ANIM_LEVEL != 0 - -#if LV_APP_ANIM_LEVEL == 1 - lv_obj_anim(app->win, LV_ANIM_FLOAT_LEFT | ANIM_IN, LV_APP_ANIM_WIN, 0, NULL); -#else /*LV_APP_ANIM_LEVEL == 2*/ - area_t cords; - if(app->sc == NULL) { - cords.x1 = LV_HOR_RES / 2 - LV_APP_SC_WIDTH / 2; - cords.y1 = LV_VER_RES / 2 - LV_APP_SC_HEIGHT / 2; - cords.x2 = cords.x1 + LV_APP_SC_WIDTH; - cords.y2 = cords.y1 + LV_APP_SC_HEIGHT; - } else { - lv_obj_get_cords(app->sc, &cords); - } - - anim_t a; - a.act_time = 0; - a.time = LV_APP_ANIM_WIN; - a.end_cb = NULL; - a.playback = 0; - a.repeat = 0; - a.var = app->win; - a.path = anim_get_path(ANIM_PATH_LIN); - - a.start = lv_obj_get_width(app->sc); - a.end = LV_HOR_RES; - a.fp = (anim_fp_t) lv_obj_set_width; - anim_create(&a); - - a.start = lv_obj_get_height(app->sc); - a.end = LV_VER_RES; - a.fp = (anim_fp_t) lv_obj_set_height; - anim_create(&a); - - a.start = cords.x1; - a.end = 0; - a.fp = (anim_fp_t) lv_obj_set_x; - anim_create(&a); - - a.start = cords.y1; - a.end = 0; - a.fp = (anim_fp_t) lv_obj_set_y; - anim_create(&a); - - a.start = OPA_TRANSP; - a.end = OPA_COVER; - a.fp = (anim_fp_t) lv_obj_set_opar; - anim_create(&a); -#endif /*LV_APP_ANIM_LEVEL == 2*/ -#endif /*LLV_APP_ANIM_WIN != 0 && LV_APP_ANIM_LEVEL != 0*/ - } + lv_app_win_open_anim_create(app); + } + } + /*Connection mode: toggle the connection of 'con_sender' and this app */ + else { + lv_app_inst_t * app = lv_obj_get_free_p(sc); + lv_btns_t * style = lv_obj_get_style(sc); + /*Add connection to this application*/ + if(style == &app_style.sc_style) { + lv_obj_set_style(sc, &app_style.sc_rec_style); + lv_app_set_con(con_send, app); + } else { /*Remove the applications connection*/ + lv_obj_set_style(sc, &app_style.sc_style); + lv_app_del_con(con_send, app); + } + } return LV_ACTION_RES_OK; } -static lv_action_res_t lv_app_sc_pr_action(lv_obj_t * sc, lv_dispi_t * dispi) +/** + * Called when a shortcut id long pressed to toggle normal and connection mode + * @param sc pointer to the long presse shortcut + * @param dispi pointer to the caller display input + * @return LV_ACTION_RES_OK because the shortcut is not deleted + */ +static lv_action_res_t lv_app_sc_lpr_action(lv_obj_t * sc, lv_dispi_t * dispi) { - /*Close the list if opened*/ - if(app_list != NULL) { - lv_obj_del(app_list); - app_list = NULL; - } + lv_app_inst_t * app_send = lv_obj_get_free_p(sc); - return LV_ACTION_RES_OK; + if(con_send == app_send) { + lv_app_inst_t * i; + LL_READ(app_inst_ll, i) { + if(i->sc != NULL) lv_obj_set_style(i->sc, &app_style.sc_style); + } + con_send = NULL; + } else { + if(con_send != NULL) { + lv_app_inst_t * i; + LL_READ(app_inst_ll, i) { + if(i->sc != NULL) lv_obj_set_style(i->sc, &app_style.sc_style); + } + } + + con_send = app_send; + lv_obj_set_style(sc, &app_style.sc_send_style); + lv_app_inst_t * i; + LL_READ(app_inst_ll, i) { + if(i->sc != NULL && lv_app_check_con(con_send, i) != false) { + lv_obj_set_style(i->sc, &app_style.sc_rec_style); + } + } + } + + return LV_ACTION_RES_OK; } +/*----------------------- + WINDOW ACTIONS + ------------------------*/ + +/** + * Called when the close button of window is released + * @param close_btn pointer to the close button + * @param dispi pointer to the caller display input + * @return LV_ACTION_RES_OK or LV_ACTION_RES_INC depending on LV_APP_EFFECT_... settings type + */ static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t * dispi) { lv_obj_t * win = lv_win_get_from_ctrl_btn(close_btn); @@ -566,133 +711,181 @@ static lv_action_res_t lv_app_win_close_action(lv_obj_t * close_btn, lv_dispi_t lv_app_kb_close(false); -#if LV_APP_ANIM_WIN != 0 && LV_APP_ANIM_LEVEL != 0 - #if LV_APP_ANIM_LEVEL == 1 - lv_obj_anim(app->win, LV_ANIM_FLOAT_LEFT | ANIM_OUT, LV_APP_ANIM_WIN, 0, lv_app_win_close_anim_cb); - lv_app_sc_close(app); - #else /*LV_APP_ANIM_LEVEL == 2*/ +#if LV_APP_EFFECT_ANIM != 0 && LV_APP_EFFECT_OPA != 0 && LV_APP_ANIM_WIN != 0 lv_obj_anim(app->win, LV_ANIM_FADE | ANIM_OUT, LV_APP_ANIM_WIN, 0, lv_app_win_close_anim_cb); lv_app_sc_close(app); - #endif /*LV_APP_ANIM_LEVEL*/ -#else /*LV_APP_ANIM_WIN == 0 && LV_APP_ANIM_LEVEL != 0*/ + /*The animation will close the window*/ + return LV_ACTION_RES_OK; +#else lv_app_close(app); return LV_ACTION_RES_INV; -#endif /*LV_APP_ANIM_WIN*/ - - return LV_ACTION_RES_OK; +#endif } - -static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_btn, lv_dispi_t * dispi) +/** + * Called when the minimization button of window is released + * @param close_minimointer to the minim. button + * @param dispi pointer to the caller display input + * @return LV_ACTION_RES_OK or LV_ACTION_RES_INC depending on LV_APP_EFFECT_... settings type + */ +static lv_action_res_t lv_app_win_minim_action(lv_obj_t * close_minim, lv_dispi_t * dispi) { - lv_obj_t * win = lv_win_get_from_ctrl_btn(close_btn); + lv_obj_t * win = lv_win_get_from_ctrl_btn(close_minim); lv_app_inst_t * app = lv_obj_get_free_p(win); lv_app_kb_close(false); - /*Make an animation on window open*/ -#if LV_APP_ANIM_WIN != 0 && LV_APP_ANIM_LEVEL != 0 - #if LV_APP_ANIM_LEVEL == 1 - lv_obj_anim(app->win, LV_ANIM_FLOAT_BOTTOM | ANIM_OUT, LV_APP_ANIM_WIN, 0, lv_app_win_minim_anim_cb); - #else /*LV_APP_ANIM_LEVEL == 2*/ - area_t cords; - if(app->sc == NULL) { - cords.x1 = LV_HOR_RES / 2 - LV_APP_SC_WIDTH / 2; - cords.y1 = LV_VER_RES / 2 - LV_APP_SC_HEIGHT / 2; - cords.x2 = cords.x1 + LV_APP_SC_WIDTH; - cords.y2 = cords.y1 + LV_APP_SC_HEIGHT; - } else { - lv_obj_get_cords(app->sc, &cords); - } + /*Make an animation on window minimization*/ + lv_action_res_t res; + res = lv_app_win_minim_anim_create(app); - anim_t a; - a.act_time = 0; - a.time = LV_APP_ANIM_WIN; - a.end_cb = NULL; - a.playback = 0; - a.repeat = 0; - a.var = app->win; - a.path = anim_get_path(ANIM_PATH_LIN); - - - a.end = lv_obj_get_width(app->sc); - a.start = LV_HOR_RES; - a.fp = (anim_fp_t) lv_obj_set_width; - anim_create(&a); - - a.end = lv_obj_get_height(app->sc); - a.start = LV_VER_RES; - a.fp = (anim_fp_t) lv_obj_set_height; - anim_create(&a); - - a.end = cords.x1; - a.start = 0; - a.fp = (anim_fp_t) lv_obj_set_x; - anim_create(&a); - - a.end = cords.y1; - a.start = 0; - a.fp = (anim_fp_t) lv_obj_set_y; - anim_create(&a); - - a.end = OPA_TRANSP; - a.start = OPA_COVER; - a.fp = (anim_fp_t) lv_obj_set_opar; - a.end_cb = (void (*)(void *))lv_app_win_minim_anim_cb; - //a.time = 500; - anim_create(&a); - #endif /*LV_APP_ANIM_LEVEL*/ -#else /*LV_APP_ANIM_WIN == 0 || LV_APP_ANIM_LEVEL == 0*/ - lv_app_win_close(app); - return LV_ACTION_RES_INV; -#endif - - return LV_ACTION_RES_OK; + return res; } -#if LV_APP_ANIM_LEVEL != 0 && LV_APP_ANIM_WIN != 0 +/*----------------------- + ANIMATIONS + ------------------------*/ + +/** + * Create a window open animation + * @param app pointer to an application + * @return LV_ACTION_RES_OK: because the window is not deleted here + */ +static lv_action_res_t lv_app_win_open_anim_create(lv_app_inst_t * app) +{ + /*Make an animation on window open*/ +#if LV_APP_EFFECT_ANIM != 0 && LV_APP_ANIM_WIN != 0 + + area_t cords; /*If no shortcut simulate one or load the its coordinates*/ + if(app->sc == NULL) { + cords.x1 = LV_HOR_RES / 2 - LV_APP_SC_WIDTH / 2; + cords.y1 = LV_VER_RES / 2 - LV_APP_SC_HEIGHT / 2; + cords.x2 = cords.x1 + LV_APP_SC_WIDTH; + cords.y2 = cords.y1 + LV_APP_SC_HEIGHT; + } else { + lv_obj_get_cords(app->sc, &cords); + } + + anim_t a; + a.act_time = 0; + a.time = LV_APP_ANIM_WIN; + a.end_cb = NULL; + a.playback = 0; + a.repeat = 0; + a.var = app->win; + a.path = anim_get_path(ANIM_PATH_LIN); + + a.start = lv_obj_get_width(app->sc); + a.end = LV_HOR_RES; + a.fp = (anim_fp_t) lv_obj_set_width; + anim_create(&a); + + a.start = lv_obj_get_height(app->sc); + a.end = LV_VER_RES; + a.fp = (anim_fp_t) lv_obj_set_height; + anim_create(&a); + + a.start = cords.x1; + a.end = 0; + a.fp = (anim_fp_t) lv_obj_set_x; + anim_create(&a); + + a.start = cords.y1; + a.end = 0; + a.fp = (anim_fp_t) lv_obj_set_y; + anim_create(&a); + +#if LV_APP_EFFECT_OPA != 0 + a.start = OPA_TRANSP; + a.end = OPA_COVER; + a.fp = (anim_fp_t) lv_obj_set_opar; + anim_create(&a); +#endif /*LV_APP_EFFECT_OPA != 0*/ +#endif /*LV_APP_EFFECT_ANIM != 0 && LV_APP_ANIM_WIN != 0*/ + + return LV_ACTION_RES_OK; +} + +/** + * Create a window minimization animation + * @param app pointer to an application + * @return LV_ACTION_RES_OK or LV_ACTION_RES_INV depending on LV_APP_EFFECT_... settings + */ +static lv_action_res_t lv_app_win_minim_anim_create(lv_app_inst_t * app) +{ +#if LV_APP_EFFECT_ANIM != 0 && LV_APP_ANIM_WIN != 0 + area_t cords; + if(app->sc == NULL) { + cords.x1 = LV_HOR_RES / 2 - LV_APP_SC_WIDTH / 2; + cords.y1 = LV_VER_RES / 2 - LV_APP_SC_HEIGHT / 2; + cords.x2 = cords.x1 + LV_APP_SC_WIDTH; + cords.y2 = cords.y1 + LV_APP_SC_HEIGHT; + } else { + lv_obj_get_cords(app->sc, &cords); + } + + anim_t a; + a.act_time = 0; + a.time = LV_APP_ANIM_WIN; + a.end_cb = NULL; + a.playback = 0; + a.repeat = 0; + a.var = app->win; + a.path = anim_get_path(ANIM_PATH_LIN); + + + a.end = lv_obj_get_width(app->sc); + a.start = LV_HOR_RES; + a.fp = (anim_fp_t) lv_obj_set_width; + anim_create(&a); + + a.end = lv_obj_get_height(app->sc); + a.start = LV_VER_RES; + a.fp = (anim_fp_t) lv_obj_set_height; + anim_create(&a); + + a.end = cords.x1; + a.start = 0; + a.fp = (anim_fp_t) lv_obj_set_x; + anim_create(&a); + + a.end = cords.y1; + a.start = 0; + a.fp = (anim_fp_t) lv_obj_set_y; +#if LV_APP_EFFECT_OPA == 0 + a.end_cb = (void (*)(void *))lv_app_win_close_anim_cb; +#endif + anim_create(&a); + +#if LV_APP_EFFECT_OPA != 0 + a.end = OPA_TRANSP; + a.start = OPA_COVER; + a.fp = (anim_fp_t) lv_obj_set_opar; + a.end_cb = (void (*)(void *))lv_app_win_minim_anim_cb; + anim_create(&a); +#endif + return LV_ACTION_RES_OK; +#else /*LV_APP_ANIM_WIN == 0 || LV_APP_ANIM_LEVEL == 0*/ + lv_app_win_close(app); + return LV_ACTION_RES_INV; +#endif +} + +#if LV_APP_EFFECT_ANIM != 0 +/** + * Called when the window close or minimization animation is ready to close the window + * @param app_win pointer to a window + */ static void lv_app_win_close_anim_cb(lv_obj_t * app_win) { - lv_app_inst_t * app = lv_obj_get_free_p(app_win); - lv_app_close(app); -} - -static void lv_app_win_minim_anim_cb(lv_obj_t * app_win) -{ - lv_app_inst_t * app = lv_obj_get_free_p(app_win); - lv_app_win_close(app); + lv_app_inst_t * app = lv_obj_get_free_p(app_win); + lv_app_win_close(app); } #endif -static void lv_app_init_icons(void) -{ - lv_img_create_file("icon_add", img_add); - lv_img_create_file("icon_battery_empty", img_battery_empty); - lv_img_create_file("icon_battery_full", img_battery_full); - lv_img_create_file("icon_battery_half", img_battery_half); - lv_img_create_file("icon_bubble", img_bubble); - lv_img_create_file("icon_calendar", img_calendar); - lv_img_create_file("icon_clock", img_clock); - lv_img_create_file("icon_close", img_close); - lv_img_create_file("icon_down", img_down); - lv_img_create_file("icon_driver", img_driver); - lv_img_create_file("icon_eject", img_eject); - lv_img_create_file("icon_folder", img_folder); - lv_img_create_file("icon_image", img_image); - lv_img_create_file("icon_left", img_left); - lv_img_create_file("icon_music", img_music); - lv_img_create_file("icon_ok", img_ok); - lv_img_create_file("icon_play", img_play); - lv_img_create_file("icon_right", img_right); - lv_img_create_file("icon_settings", img_settings); - lv_img_create_file("icon_shut_down", img_shut_down); - lv_img_create_file("icon_star", img_star); - lv_img_create_file("icon_up", img_up); - lv_img_create_file("icon_user", img_user); - lv_img_create_file("icon_video", img_video); - lv_img_create_file("icon_volume", img_volume); -} - +/** + * Init the application styles + */ static void lv_app_init_style(void) { /*Coordinates*/ @@ -702,9 +895,15 @@ static void lv_app_init_style(void) app_style.sc_title_margin = 2 * LV_DOWNSCALE; /*Opacity*/ - app_style.menu_opa = OPA_80; - app_style.menu_btn_opa = OPA_50; - app_style.sc_opa = OPA_70; +#if LV_APP_EFFECT_OPA == 0 + app_style.menu_opa = OPA_COVER; + app_style.menu_btn_opa = OPA_COVER; + app_style.sc_opa = OPA_COVER; +#else + app_style.menu_opa = OPA_80; + app_style.menu_btn_opa = OPA_50; + app_style.sc_opa = OPA_70; +#endif /*Menu style*/ lv_rects_get(LV_RECTS_DEF,&app_style.menu_style); @@ -775,6 +974,33 @@ static void lv_app_init_style(void) app_style.sc_style.rects.bopa = 70; app_style.sc_style.rects.bwidth = 1 * LV_DOWNSCALE; + memcpy(&app_style.sc_send_style, &app_style.sc_style, sizeof(lv_btns_t)); + app_style.sc_send_style.mcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0xFF, 0xE0, 0xE0); + app_style.sc_send_style.gcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x50, 0x20, 0x00); + app_style.sc_send_style.bcolor[LV_BTN_STATE_REL] = COLOR_BLACK; + app_style.sc_send_style.flags[LV_BTN_STATE_REL].light_en = 1; + app_style.sc_send_style.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xFF, 0xB0, 0xB0); + app_style.sc_send_style.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x20, 0x10, 0x00); + app_style.sc_send_style.bcolor[LV_BTN_STATE_PR] = COLOR_BLACK; + app_style.sc_send_style.flags[LV_BTN_STATE_PR].light_en = 1; + app_style.sc_send_style.rects.light = 10 * LV_DOWNSCALE; + app_style.sc_send_style.rects.bopa = 30; + app_style.sc_send_style.rects.bwidth = 3 * LV_DOWNSCALE; + + memcpy(&app_style.sc_rec_style, &app_style.sc_style, sizeof(lv_btns_t)); + app_style.sc_rec_style.mcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0xE0, 0xFF, 0xE0); + app_style.sc_rec_style.gcolor[LV_BTN_STATE_REL] = COLOR_MAKE(0x20, 0x50, 0x20); + app_style.sc_rec_style.bcolor[LV_BTN_STATE_REL] = COLOR_BLACK; + app_style.sc_rec_style.flags[LV_BTN_STATE_REL].light_en = 1; + app_style.sc_rec_style.mcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0xB0, 0xFF, 0xB0); + app_style.sc_rec_style.gcolor[LV_BTN_STATE_PR] = COLOR_MAKE(0x20, 0x20, 0x10); + app_style.sc_rec_style.bcolor[LV_BTN_STATE_PR] = COLOR_BLACK; + app_style.sc_rec_style.flags[LV_BTN_STATE_PR].light_en = 1; + app_style.sc_rec_style.rects.light = 10 * LV_DOWNSCALE; + app_style.sc_rec_style.rects.bopa = 30; + app_style.sc_rec_style.rects.bwidth = 3 * LV_DOWNSCALE; + + lv_labels_get(LV_LABELS_DEF,&app_style.sc_title_style); app_style.sc_title_style.font = LV_APP_FONT_SMALL; app_style.sc_title_style.objs.color = COLOR_MAKE(0x20, 0x30, 0x40); @@ -798,6 +1024,37 @@ static void lv_app_init_style(void) app_style.win_style.content.scrable_rects.objs.transp = 1; } +/** + * Create files for the icons + */ +static void lv_app_init_icons(void) +{ + lv_img_create_file("icon_add", img_add); + lv_img_create_file("icon_battery_empty", img_battery_empty); + lv_img_create_file("icon_battery_full", img_battery_full); + lv_img_create_file("icon_battery_half", img_battery_half); + lv_img_create_file("icon_bubble", img_bubble); + lv_img_create_file("icon_calendar", img_calendar); + lv_img_create_file("icon_clock", img_clock); + lv_img_create_file("icon_close", img_close); + lv_img_create_file("icon_down", img_down); + lv_img_create_file("icon_driver", img_driver); + lv_img_create_file("icon_eject", img_eject); + lv_img_create_file("icon_folder", img_folder); + lv_img_create_file("icon_image", img_image); + lv_img_create_file("icon_left", img_left); + lv_img_create_file("icon_music", img_music); + lv_img_create_file("icon_ok", img_ok); + lv_img_create_file("icon_play", img_play); + lv_img_create_file("icon_right", img_right); + lv_img_create_file("icon_settings", img_settings); + lv_img_create_file("icon_shut_down", img_shut_down); + lv_img_create_file("icon_star", img_star); + lv_img_create_file("icon_up", img_up); + lv_img_create_file("icon_user", img_user); + lv_img_create_file("icon_video", img_video); + lv_img_create_file("icon_volume", img_volume); +} #endif /*LV_APP_ENABLE != 0*/ diff --git a/lv_app/lv_app.h b/lv_app/lv_app.h index fa1cf1738..4bc1681ca 100644 --- a/lv_app/lv_app.h +++ b/lv_app/lv_app.h @@ -61,7 +61,7 @@ typedef struct __LV_APP_DSC_T lv_app_mode_t mode; void (*app_run)(lv_app_inst_t *, const char *); void (*app_close) (lv_app_inst_t *); - void (*com_rec) (lv_app_inst_t *, lv_app_inst_t *, lv_app_com_type_t, void *, uint32_t); + void (*com_rec) (lv_app_inst_t *, lv_app_inst_t *, lv_app_com_type_t, const void *, uint32_t); void (*sc_open) (lv_app_inst_t *, lv_obj_t *); void (*sc_close) (lv_app_inst_t *); void (*win_open) (lv_app_inst_t *, lv_obj_t *); @@ -80,6 +80,8 @@ typedef struct { lv_pages_t sc_page_style; lv_wins_t win_style; lv_btns_t sc_style; + lv_btns_t sc_send_style; + lv_btns_t sc_rec_style; lv_labels_t sc_title_style; opa_t menu_opa; @@ -99,7 +101,7 @@ typedef struct { void lv_app_init(void); lv_app_inst_t * lv_app_run(const lv_app_dsc_t * app_dsc, const char * cstr); void lv_app_close(lv_app_inst_t * app); -uint16_t lv_app_com_send(lv_app_inst_t * app_send, lv_app_com_type_t type , void * data, uint32_t len); +uint16_t lv_app_com_send(lv_app_inst_t * app_send, lv_app_com_type_t type , const void * data, uint32_t len); lv_obj_t * lv_app_sc_open(lv_app_inst_t * app); void lv_app_sc_close(lv_app_inst_t * app); lv_obj_t * lv_app_win_open(lv_app_inst_t * app); @@ -107,6 +109,7 @@ void lv_app_win_close(lv_app_inst_t * app); lv_obj_t * lv_app_get_win_from_obj(lv_obj_t * obj); const lv_app_dsc_t * lv_app_get_dsc(const char * name); +void lv_app_set_con(lv_app_inst_t * sender, lv_app_inst_t * receiver); lv_app_style_t * lv_app_get_style(void); void lv_app_rename(lv_app_inst_t * app, const char * name); void lv_app_refr_style(void); diff --git a/lv_appx/lv_app_example.c b/lv_appx/lv_app_example.c index 5170a2eb5..0b68e9b2b 100644 --- a/lv_appx/lv_app_example.c +++ b/lv_appx/lv_app_example.c @@ -44,7 +44,7 @@ typedef struct **********************/ static void my_app_run(lv_app_inst_t * app, const char * cstr); static void my_app_close(lv_app_inst_t * app); -static void my_com_rec(lv_app_inst_t * app_rec, lv_app_inst_t * app_sender, lv_app_com_type_t type , void * data, uint32_t len); +static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, lv_app_com_type_t type , const void * data, uint32_t len); static void my_sc_open(lv_app_inst_t * app, lv_obj_t * sc); static void my_sc_close(lv_app_inst_t * app); static void my_win_open(lv_app_inst_t * app, lv_obj_t * win); @@ -123,17 +123,22 @@ static void my_app_close(lv_app_inst_t * app) /** * Read the data have been sent to this application - * @param app_rec pointer to an application which is receiving the message * @param app_send pointer to an application which sent the message + * @param app_rec pointer to an application which is receiving the message * @param type type of data from 'lv_app_com_type_t' enum * @param data pointer to the sent data * @param len length of 'data' in bytes */ -static void my_com_rec(lv_app_inst_t * app_rec, lv_app_inst_t * app_send, - lv_app_com_type_t type , void * data, uint32_t len) +static void my_com_rec(lv_app_inst_t * app_send, lv_app_inst_t * app_rec, + lv_app_com_type_t type , const void * data, uint32_t len) { if(type == LV_APP_COM_TYPE_STR) { /*data: string*/ + my_sc_data_t * sc_data = app_rec->sc_data; + if (sc_data->label != NULL) { + lv_label_set_text(sc_data->label, data); + lv_obj_align(sc_data->label , NULL,LV_ALIGN_CENTER, 0, 0); + } } else if(type == LV_APP_COM_TYPE_BIN) { /*data: array of 'int32_t' */ @@ -186,11 +191,18 @@ static void my_win_open(lv_app_inst_t * app, lv_obj_t * win) lv_obj_set_size_us(ta, 200, 100); lv_obj_set_pos_us(ta, 20, 200); lv_page_set_rel_action(ta, kb_open); + lv_obj_set_free_p(ta, app); +} + +void kb_ok(lv_obj_t * ta) { + lv_app_inst_t * app = lv_obj_get_free_p(ta); + const char * txt = lv_ta_get_txt(ta); + lv_app_com_send(app, LV_APP_COM_TYPE_STR, txt, strlen(txt) + 1); } lv_action_res_t kb_open(lv_obj_t * ta, lv_dispi_t * dispi) { - lv_app_kb_open(ta, LV_APP_KB_MODE_TXT, NULL, NULL); + lv_app_kb_open(ta, LV_APP_KB_MODE_TXT, NULL, kb_ok); return LV_ACTION_RES_OK; } diff --git a/lv_draw/lv_draw_vbasic.c b/lv_draw/lv_draw_vbasic.c index 3c1a4216c..4b613cae8 100644 --- a/lv_draw/lv_draw_vbasic.c +++ b/lv_draw/lv_draw_vbasic.c @@ -141,13 +141,7 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, vdb_buf_tmp += (row_start * vdb_width) + col_start; /*Move on the map too*/ -#if LV_UPSCALE_FONT == 0 || LV_DOWNSCALE == 1 map_p += (row_start * font_p->width_byte) + (col_start>>3); -#elif LV_DOWNSCALE == 2 - map_p += ((row_start >> 1) * font_p->width_byte) + ((col_start >> 1)>>3); -#elif LV_DOWNSCALE == 4 - map_p += ((row_start >> 2) * font_p->width_byte) + ((col_start >> 2)>>3); -#endif for(row = row_start; row < row_end; row ++) { col_byte_cnt = 0; @@ -161,34 +155,16 @@ void lv_vletter(const point_t * pos_p, const area_t * mask_p, vdb_buf_tmp++; /*Use a col. more times depending on LV_UPSCALE_FONT*/ -#if LV_UPSCALE_FONT == 0 || LV_DOWNSCALE == 1 - /*Use all cols.*/ -#elif LV_DOWNSCALE == 2 - if((col & 0x01) == 0) -#elif LV_DOWNSCALE == 4 - if((col & 0x03) == 0) -#endif - { - if(col_bit != 0) col_bit --; - else { - col_bit = 7; - col_byte_cnt ++; - map_p ++; - } + if(col_bit != 0) col_bit --; + else { + col_bit = 7; + col_byte_cnt ++; + map_p ++; + } } - /*Use a row more times depending on LV_UPSCALE_FONT*/ -#if LV_UPSCALE_FONT == 0 || LV_DOWNSCALE == 1 map_p += font_p->width_byte - col_byte_cnt; -#elif LV_DOWNSCALE == 2 - if((row & 0x01) == 0) map_p += font_p->width_byte - col_byte_cnt; /*Next row in the map*/ - else map_p -= col_byte_cnt; /*Reset the row*/ -#elif LV_DOWNSCALE == 4 - if((row & 0x03) == 0) map_p += font_p->width_byte - col_byte_cnt; /*Next row in the map*/ - else map_p -= col_byte_cnt; /*Reset the row*/ -#endif - vdb_buf_tmp += vdb_width - (col_end - col_start); /*Next row in VDB*/ } } diff --git a/lv_misc/font.h b/lv_misc/font.h index d919040b0..3fb8e4376 100644 --- a/lv_misc/font.h +++ b/lv_misc/font.h @@ -88,11 +88,7 @@ static inline const uint8_t * font_get_bitmap(const font_t * font_p, uint8_t let */ static inline uint8_t font_get_height(const font_t * font_p) { -#if LV_DOWNSCALE > 1 && LV_UPSCALE_FONT != 0 - return font_p->height_row * LV_DOWNSCALE; -#else return font_p->height_row; -#endif } /** @@ -112,11 +108,7 @@ static inline uint8_t font_get_width(const font_t * font_p, uint8_t letter) font_p->width_bit_a[letter]; } - #if LV_DOWNSCALE > 1 && LV_UPSCALE_FONT != 0 - return w * LV_DOWNSCALE; - #else return w; -#endif } #endif diff --git a/lv_misc/text.c b/lv_misc/text.c index 90601e877..b0a4be7fd 100644 --- a/lv_misc/text.c +++ b/lv_misc/text.c @@ -64,10 +64,10 @@ void txt_get_size(point_t * size_res, const char * text, const font_t * font, size_res->y += letter_height + line_space; } - /*Correction with the last line space*/ - if(size_res->y >= 0) { - size_res->y -= line_space; - } + /*Correction with the last line space or set the height manually if the text is empty*/ + if(size_res->y == 0) size_res->y = letter_height; + else size_res->y -= line_space; + } /** diff --git a/lv_obj/lv_obj.h b/lv_obj/lv_obj.h index 81ab34afd..472d27bac 100644 --- a/lv_obj/lv_obj.h +++ b/lv_obj/lv_obj.h @@ -28,8 +28,8 @@ #error "LV: LV_DOWNSCALE can be only 1, 2 or 4" #endif -#if LV_VDB_SIZE == 0 && (LV_DOWNSCALE != 1 || LV_UPSCALE_MAP != 0 || LV_UPSCALE_FONT != 0 || LV_UPSCALE_STYLE != 0) -#error "LV: If LV_VDB_SIZE == 0 then LV_DOWNSCALE must be 1, LV_UPSCALE_MAP 0, LV_UPSCALE_FONT 0, LV_UPSCALE_STYLE 0" +#if LV_VDB_SIZE == 0 && (LV_DOWNSCALE != 1 || LV_UPSCALE_MAP != 0 || LV_UPSCALE_STYLE != 0) +#error "LV: If LV_VDB_SIZE == 0 then LV_DOWNSCALE must be 1, LV_UPSCALE_MAP 0, LV_UPSCALE_STYLE 0" #endif /*New defines*/ diff --git a/lv_objx/lv_btn.c b/lv_objx/lv_btn.c index 7e200b2ae..759c3681b 100644 --- a/lv_objx/lv_btn.c +++ b/lv_objx/lv_btn.c @@ -120,7 +120,7 @@ bool lv_btn_signal(lv_obj_t * btn, lv_signal_t sign, void* param) lv_btn_ext_t * ext = lv_obj_get_ext(btn); bool tgl = lv_btn_get_tgl(btn); - switch (sign){ + switch (sign) { case LV_SIGNAL_PRESSED: /*Refresh the state*/ if(ext->state == LV_BTN_STATE_REL) { @@ -357,7 +357,17 @@ static bool lv_btn_design(lv_obj_t * btn, const area_t * mask, lv_design_mode_t /* Because of the radius it is not sure the area is covered*/ if(mode == LV_DESIGN_COVER_CHK) { - return ancestor_design_f(btn, mask, mode); + /*Temporally set a rectangle style for the button to look like as rectangle*/ + lv_rects_t rects_tmp; + lv_btns_t * btns_tmp = lv_obj_get_style(btn); + bool ret = false; + lv_btn_style_load(btn, &rects_tmp); + if(rects_tmp.objs.transp == 0) { + btn->style_p = &rects_tmp; + ret = ancestor_design_f(btn, mask, mode); /*Draw the rectangle*/ + btn->style_p = btns_tmp; /*Reload the original button style*/ + } + return ret; } else if(mode == LV_DESIGN_DRAW_MAIN) { area_t area; lv_obj_get_cords(btn, &area); diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index 956c1130b..3829f3ec3 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -140,6 +140,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) } break; case LV_SIGNAL_RELEASED: + case LV_SIGNAL_LONG_PRESS_REP: if(ext->cb != NULL && ext->btn_pr != LV_BTNM_BTN_PR_INVALID) { uint16_t txt_i = 0; @@ -153,7 +154,7 @@ bool lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) ext->cb(btnm, txt_i); } - ext->btn_pr = LV_BTNM_BTN_PR_INVALID; + if(sign == LV_SIGNAL_RELEASED) ext->btn_pr = LV_BTNM_BTN_PR_INVALID; lv_obj_inv(btnm); break; default: diff --git a/lv_objx/lv_page.c b/lv_objx/lv_page.c index 381169041..6491430d2 100644 --- a/lv_objx/lv_page.c +++ b/lv_objx/lv_page.c @@ -159,6 +159,18 @@ bool lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) lv_page_sb_refresh(page); } break; + case LV_SIGNAL_PRESSED: + if(ext->pr_action != NULL) { + ext->pr_action(page, param); + } + break; + case LV_SIGNAL_RELEASED: + if(lv_dispi_is_dragging(param) == false) { + if(ext->rel_action != NULL) { + ext->rel_action(page, param); + } + } + break; default: break; @@ -268,17 +280,17 @@ static bool lv_scrolling_signal(lv_obj_t * scrolling, lv_signal_t sign, void* pa } break; case LV_SIGNAL_PRESSED: - if(page_ext->pr_action != NULL) { - page_ext->pr_action(page, param); - } - break; + if(page_ext->pr_action != NULL) { + page_ext->pr_action(page, param); + } + break; case LV_SIGNAL_RELEASED: - if(lv_dispi_is_dragging(param) == false) { - if(page_ext->rel_action != NULL) { - page_ext->rel_action(page, param); - } - } - break; + if(lv_dispi_is_dragging(param) == false) { + if(page_ext->rel_action != NULL) { + page_ext->rel_action(page, param); + } + } + break; default: break; @@ -491,8 +503,6 @@ static bool lv_page_design(lv_obj_t * page, const area_t * mask, lv_design_mode_ */ static void lv_page_sb_refresh(lv_obj_t * page) { - - lv_page_ext_t * page_ext = lv_obj_get_ext(page); lv_pages_t * pages = lv_obj_get_style(page); lv_obj_t * scrolling = page_ext->scrolling;