2020-06-16 02:05:33 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 03:20:14 +00:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-06-16 02:05:33 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "../../../../inc/MarlinConfigPre.h"
|
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
#if HAS_TFT_LVGL_UI
|
2020-06-16 02:05:33 +00:00
|
|
|
|
|
|
|
#include "draw_ui.h"
|
2020-10-21 17:45:27 +00:00
|
|
|
#include <lv_conf.h>
|
2020-06-16 02:05:33 +00:00
|
|
|
//#include "../lvgl/src/lv_objx/lv_imgbtn.h"
|
|
|
|
//#include "../lvgl/src/lv_objx/lv_img.h"
|
|
|
|
//#include "../lvgl/src/lv_core/lv_disp.h"
|
|
|
|
//#include "../lvgl/src/lv_core/lv_refr.h"
|
|
|
|
|
2020-10-21 17:45:27 +00:00
|
|
|
#include "../../../../inc/MarlinConfig.h"
|
2020-06-16 02:05:33 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
enum {
|
|
|
|
ID_CN = 1,
|
|
|
|
ID_T_CN,
|
|
|
|
ID_EN,
|
|
|
|
ID_RU,
|
|
|
|
ID_ES,
|
|
|
|
ID_FR,
|
|
|
|
ID_IT,
|
|
|
|
ID_L_RETURN
|
|
|
|
};
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
#define SELECTED 1
|
|
|
|
#define UNSELECTED 0
|
2020-06-16 02:05:33 +00:00
|
|
|
|
|
|
|
static void disp_language(uint8_t language, uint8_t state);
|
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
extern lv_group_t *g;
|
|
|
|
static lv_obj_t *scr;
|
2020-06-16 02:05:33 +00:00
|
|
|
static lv_obj_t *buttonCN, *buttonT_CN, *buttonEN, *buttonRU;
|
2020-10-24 04:37:45 +00:00
|
|
|
static lv_obj_t *buttonES, *buttonFR, *buttonIT;
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
static void event_handler(lv_obj_t *obj, lv_event_t event) {
|
|
|
|
if (event != LV_EVENT_RELEASED) return;
|
2020-06-16 02:05:33 +00:00
|
|
|
switch (obj->mks_obj_id) {
|
|
|
|
case ID_CN:
|
2020-10-24 04:37:45 +00:00
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
|
|
|
lv_imgbtn_set_src_both(buttonCN, "F:/bmp_simplified_cn_sel.bin");
|
|
|
|
lv_obj_refresh_ext_draw_pad(buttonCN);
|
|
|
|
gCfgItems.language = LANG_SIMPLE_CHINESE;
|
|
|
|
update_spi_flash();
|
|
|
|
disp_language_init();
|
2020-06-16 02:05:33 +00:00
|
|
|
break;
|
|
|
|
case ID_T_CN:
|
2020-10-24 04:37:45 +00:00
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
|
|
|
lv_imgbtn_set_src_both(buttonT_CN, "F:/bmp_traditional_cn_sel.bin");
|
|
|
|
lv_obj_refresh_ext_draw_pad(buttonT_CN);
|
|
|
|
gCfgItems.language = LANG_COMPLEX_CHINESE;
|
|
|
|
update_spi_flash();
|
|
|
|
disp_language_init();
|
2020-06-16 02:05:33 +00:00
|
|
|
break;
|
|
|
|
case ID_EN:
|
2020-10-24 04:37:45 +00:00
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
|
|
|
lv_imgbtn_set_src_both(buttonEN, "F:/bmp_english_sel.bin");
|
|
|
|
lv_obj_refresh_ext_draw_pad(buttonEN);
|
|
|
|
gCfgItems.language = LANG_ENGLISH;
|
|
|
|
update_spi_flash();
|
|
|
|
disp_language_init();
|
2020-06-16 02:05:33 +00:00
|
|
|
break;
|
|
|
|
case ID_RU:
|
2020-10-24 04:37:45 +00:00
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
|
|
|
lv_imgbtn_set_src_both(buttonRU, "F:/bmp_russian_sel.bin");
|
|
|
|
lv_obj_refresh_ext_draw_pad(buttonRU);
|
|
|
|
gCfgItems.language = LANG_RUSSIAN;
|
|
|
|
update_spi_flash();
|
|
|
|
disp_language_init();
|
2020-06-16 02:05:33 +00:00
|
|
|
break;
|
|
|
|
case ID_ES:
|
2020-10-24 04:37:45 +00:00
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
|
|
|
lv_imgbtn_set_src_both(buttonES, "F:/bmp_spanish_sel.bin");
|
|
|
|
lv_obj_refresh_ext_draw_pad(buttonES);
|
|
|
|
gCfgItems.language = LANG_SPANISH;
|
|
|
|
update_spi_flash();
|
|
|
|
disp_language_init();
|
2020-06-16 02:05:33 +00:00
|
|
|
break;
|
|
|
|
case ID_FR:
|
2020-10-24 04:37:45 +00:00
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
|
|
|
lv_imgbtn_set_src_both(buttonFR, "F:/bmp_french_sel.bin");
|
|
|
|
lv_obj_refresh_ext_draw_pad(buttonFR);
|
|
|
|
gCfgItems.language = LANG_FRENCH;
|
|
|
|
update_spi_flash();
|
|
|
|
disp_language_init();
|
2020-06-16 02:05:33 +00:00
|
|
|
break;
|
|
|
|
case ID_IT:
|
2020-10-24 04:37:45 +00:00
|
|
|
disp_language(gCfgItems.language, UNSELECTED);
|
|
|
|
lv_imgbtn_set_src_both(buttonIT, "F:/bmp_italy_sel.bin");
|
|
|
|
lv_obj_refresh_ext_draw_pad(buttonIT);
|
|
|
|
gCfgItems.language = LANG_ITALY;
|
|
|
|
update_spi_flash();
|
|
|
|
disp_language_init();
|
2020-06-16 02:05:33 +00:00
|
|
|
break;
|
|
|
|
case ID_L_RETURN:
|
2020-10-24 04:37:45 +00:00
|
|
|
buttonCN = nullptr;
|
|
|
|
buttonT_CN = nullptr;
|
|
|
|
buttonEN = nullptr;
|
|
|
|
buttonRU = nullptr;
|
|
|
|
buttonES = nullptr;
|
|
|
|
buttonFR = nullptr;
|
|
|
|
buttonFR = nullptr;
|
|
|
|
buttonIT = nullptr;
|
|
|
|
lv_clear_language();
|
|
|
|
lv_draw_set();
|
2020-06-16 02:05:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disp_language(uint8_t language, uint8_t state) {
|
|
|
|
uint16_t id;
|
|
|
|
lv_obj_t *obj;
|
|
|
|
|
|
|
|
public_buf_l[0] = '\0';
|
|
|
|
|
|
|
|
switch (language) {
|
|
|
|
case LANG_SIMPLE_CHINESE:
|
|
|
|
id = ID_CN;
|
2020-09-21 01:55:02 +00:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_simplified_cn"));
|
2020-06-16 02:05:33 +00:00
|
|
|
obj = buttonCN;
|
|
|
|
break;
|
|
|
|
case LANG_COMPLEX_CHINESE:
|
|
|
|
id = ID_T_CN;
|
2020-09-21 01:55:02 +00:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_traditional_cn"));
|
2020-06-16 02:05:33 +00:00
|
|
|
obj = buttonT_CN;
|
|
|
|
break;
|
|
|
|
case LANG_ENGLISH:
|
|
|
|
id = ID_EN;
|
2020-09-21 01:55:02 +00:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_english"));
|
2020-06-16 02:05:33 +00:00
|
|
|
obj = buttonEN;
|
|
|
|
break;
|
|
|
|
case LANG_RUSSIAN:
|
|
|
|
id = ID_RU;
|
2020-09-21 01:55:02 +00:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_russian"));
|
2020-06-16 02:05:33 +00:00
|
|
|
obj = buttonRU;
|
|
|
|
break;
|
|
|
|
case LANG_SPANISH:
|
|
|
|
id = ID_ES;
|
2020-09-21 01:55:02 +00:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_spanish"));
|
2020-06-16 02:05:33 +00:00
|
|
|
obj = buttonES;
|
|
|
|
break;
|
|
|
|
case LANG_FRENCH:
|
|
|
|
id = ID_FR;
|
2020-09-21 01:55:02 +00:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_french"));
|
2020-06-16 02:05:33 +00:00
|
|
|
obj = buttonFR;
|
|
|
|
break;
|
|
|
|
case LANG_ITALY:
|
|
|
|
id = ID_IT;
|
2020-09-21 01:55:02 +00:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_italy"));
|
2020-06-16 02:05:33 +00:00
|
|
|
obj = buttonIT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
id = ID_CN;
|
2020-09-21 01:55:02 +00:00
|
|
|
strcpy_P(public_buf_l, PSTR("F:/bmp_simplified_cn"));
|
2020-06-16 02:05:33 +00:00
|
|
|
obj = buttonCN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
if (state == SELECTED) strcat_P(public_buf_l, PSTR("_sel"));
|
|
|
|
|
|
|
|
strcat_P(public_buf_l, PSTR(".bin"));
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
lv_obj_set_event_cb_mks(obj, event_handler, id, nullptr, 0);
|
2020-10-23 01:22:17 +00:00
|
|
|
lv_imgbtn_set_src_both(obj, public_buf_l);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
|
|
|
if (state == UNSELECTED) lv_obj_refresh_ext_draw_pad(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
void lv_draw_language(void) {
|
|
|
|
|
|
|
|
if (disp_state_stack._disp_state[disp_state_stack._disp_index] != LANGUAGE_UI) {
|
|
|
|
disp_state_stack._disp_index++;
|
|
|
|
disp_state_stack._disp_state[disp_state_stack._disp_index] = LANGUAGE_UI;
|
|
|
|
}
|
|
|
|
disp_state = LANGUAGE_UI;
|
|
|
|
|
2020-10-24 04:37:45 +00:00
|
|
|
scr = lv_screen_create();
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-10-23 01:22:17 +00:00
|
|
|
(void)lv_label_create(scr, TITLE_XPOS, TITLE_YPOS, creat_title_text());
|
2020-06-16 02:05:33 +00:00
|
|
|
|
|
|
|
lv_refr_now(lv_refr_get_disp_refreshing());
|
|
|
|
|
2020-09-21 00:07:59 +00:00
|
|
|
// Create image buttons
|
2020-10-24 04:37:45 +00:00
|
|
|
buttonCN = lv_big_button_create(scr, "F:/bmp_simplified_cn.bin", language_menu.chinese_s, INTERVAL_V, titleHeight, event_handler, ID_CN);
|
2020-06-16 02:05:33 +00:00
|
|
|
lv_obj_clear_protect(buttonCN, LV_PROTECT_FOLLOW);
|
2020-10-24 04:37:45 +00:00
|
|
|
buttonT_CN = lv_big_button_create(scr, "F:/bmp_traditional_cn.bin", language_menu.chinese_t, BTN_X_PIXEL + INTERVAL_V * 2, titleHeight, event_handler, ID_T_CN);
|
|
|
|
buttonEN = lv_big_button_create(scr, "F:/bmp_english.bin", language_menu.english, BTN_X_PIXEL * 2 + INTERVAL_V * 3, titleHeight, event_handler, ID_EN);
|
|
|
|
buttonRU = lv_big_button_create(scr, "F:/bmp_russian.bin", language_menu.russian, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_RU);
|
|
|
|
buttonES = lv_big_button_create(scr, "F:/bmp_spanish.bin", language_menu.spanish, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_ES);
|
|
|
|
buttonFR = lv_big_button_create(scr, "F:/bmp_french.bin", language_menu.french, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_FR);
|
|
|
|
buttonIT = lv_big_button_create(scr, "F:/bmp_italy.bin", language_menu.italy, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_IT);
|
|
|
|
lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_L_RETURN);
|
2020-06-16 02:05:33 +00:00
|
|
|
|
|
|
|
disp_language(gCfgItems.language, SELECTED);
|
|
|
|
}
|
|
|
|
|
2020-09-21 01:55:02 +00:00
|
|
|
void lv_clear_language() {
|
|
|
|
#if HAS_ROTARY_ENCODER
|
|
|
|
if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
|
|
|
|
#endif
|
|
|
|
lv_obj_del(scr);
|
|
|
|
}
|
2020-06-16 02:05:33 +00:00
|
|
|
|
2020-07-25 05:52:07 +00:00
|
|
|
#endif // HAS_TFT_LVGL_UI
|