void lcd_menu_material()
{
#if EXTRUDERS > 1
    lcd_tripple_menu(PSTR("PRIMARY|NOZZLE"), PSTR("SECONDARY|NOZZLE"), PSTR("RETURN"));

    if (lcd_lib_button_pressed)
    {
        if (IS_SELECTED_MAIN(0))
        {
            active_extruder = 0;
            lcd_change_to_menu(lcd_menu_material_main);
        }
        else if (IS_SELECTED_MAIN(1))
        {
            active_extruder = 1;
            lcd_change_to_menu(lcd_menu_material_main);
        }
        else if (IS_SELECTED_MAIN(2))
            lcd_change_to_menu(lcd_menu_main);
    }

    lcd_lib_update_screen();
#else
    currentMenu = lcd_menu_material_main;
#endif
}
void lcd_info_screen(menuFunc_t cancelMenu, menuFunc_t callbackOnCancel, const char* cancelButtonText)
{
    if (lcd_lib_encoder_pos != ENCODER_NO_SELECTION)
    {
        if (lcd_lib_encoder_pos < 0)
            lcd_lib_encoder_pos += 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
        if (lcd_lib_encoder_pos >= 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM)
            lcd_lib_encoder_pos -= 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
    }
    if (lcd_lib_button_pressed && IS_SELECTED_MAIN(0))
    {
        if (callbackOnCancel) callbackOnCancel();
        if (cancelMenu) lcd_change_to_menu(cancelMenu);
    }

    lcd_basic_screen();

    if (!cancelButtonText) cancelButtonText = PSTR("CANCEL");
    if (IS_SELECTED_MAIN(0))
    {
        lcd_lib_draw_box(3+2, 49+2, 125-2, 63-2);
        lcd_lib_set(3+3, 49+3, 125-3, 63-3);
        lcd_lib_clear_stringP(65 - strlen_P(cancelButtonText) * 3, 53, cancelButtonText);
    }else{
        lcd_lib_draw_stringP(65 - strlen_P(cancelButtonText) * 3, 53, cancelButtonText);
    }
}
void lcd_menu_maintenance()
{
    lcd_tripple_menu(PSTR("BUILD-|PLATE"), PSTR("ADVANCED"), PSTR("RETURN"));

    if (lcd_lib_button_pressed)
    {
        if (IS_SELECTED_MAIN(0))
            lcd_change_to_menu(lcd_menu_first_run_start_bed_leveling);
        else if (IS_SELECTED_MAIN(1))
            lcd_change_to_menu(lcd_menu_maintenance_advanced);
        else if (IS_SELECTED_MAIN(2))
            lcd_change_to_menu(lcd_menu_main);
    }

    lcd_lib_update_screen();
}
void lcd_menu_maintenance()
{
    lcd_tripple_menu(PSTR("TISKOVA|PODLOZKA"), PSTR("POKROCILE|NASTAVENI"), PSTR("ZPET"));

    if (lcd_lib_button_pressed)
    {
        if (IS_SELECTED_MAIN(0))
            lcd_change_to_menu(lcd_menu_first_run_start_bed_leveling);
        else if (IS_SELECTED_MAIN(1))
            lcd_change_to_menu(lcd_menu_maintenance_advanced);
        else if (IS_SELECTED_MAIN(2))
            lcd_change_to_menu(lcd_menu_main);
    }

    lcd_lib_update_screen();
}
void lcd_info_screen(menuFunc_t cancelMenu, menuFunc_t callbackOnCancel, const char* cancelButtonText, uint8_t direction)
{
  lcd_lib_encoder_pos = 0;

  if (lcd_lib_button_pressed && IS_SELECTED_MAIN(0))
  {
    if (cancelMenu) lcd_change_to_menu(cancelMenu,MAIN_MENU_ITEM_POS(0), direction);
    if (callbackOnCancel) callbackOnCancel();
  }

  lcd_basic_screen();

  if (!cancelButtonText) cancelButtonText = LS(PSTR("CANCEL"),
                                               PSTR("\xD8" "\x80"  "\xD9" "\x80"  ),
                                               PSTR("\xFF" "\x82"  "\xC6" "\x82"  )) ;
  
  

  switch (languageType) {
  case LANGUAGE_CHINESE:
  case LANGUAGE_KOREAN:
    if (IS_SELECTED_MAIN(0))
    {
      lcd_lib_draw_box(3+3, 54-3+1, 63+61-3, 64-1);
      lcd_lib_set(3+4, 54-3+2, 63+61-4, 64-2);
      lcd_lib_clear_stringP(65 - strlen_P(cancelButtonText) * 3, 56-3, cancelButtonText);
    }else{
      lcd_lib_draw_stringP(65 - strlen_P(cancelButtonText) * 3, 56-3, cancelButtonText);
    }
    break;
  case LANGUAGE_ENGLISH:
    if (IS_SELECTED_MAIN(0))
    {
      lcd_lib_draw_box(3+3, 54+1, 63+61-3, 64-1);
      lcd_lib_set(3+4, 54+2, 63+61-4, 64-2);
      lcd_lib_clear_stringP(65 - strlen_P(cancelButtonText) * 3, 56, cancelButtonText);
    }else{
      lcd_lib_draw_stringP(65 - strlen_P(cancelButtonText) * 3, 56, cancelButtonText);
    }
    break;
  default:
    break;
  }


}
void lcd_tripple_menu(const char* left, const char* right, const char* bottom)
{
    if (lcd_lib_encoder_pos != ENCODER_NO_SELECTION)
    {
        if (lcd_lib_encoder_pos < 0)
            lcd_lib_encoder_pos += 3*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
        if (lcd_lib_encoder_pos >= 3*ENCODER_TICKS_PER_MAIN_MENU_ITEM)
            lcd_lib_encoder_pos -= 3*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
    }

    lcd_lib_clear();
    lcd_lib_draw_vline(64, 5, 45);
    lcd_lib_draw_hline(3, 124, 48);

    if (IS_SELECTED_MAIN(0))
    {
        lcd_lib_draw_box(3+2, 5+2, 64-3-2, 45-2);
        lcd_lib_set(3+3, 5+3, 64-3-3, 45-3);
        lcd_lib_clear_string_center_atP(33, 22, left);
    }else{
        lcd_lib_draw_string_center_atP(33, 22, left);
    }

    if (IS_SELECTED_MAIN(1))
    {
        lcd_lib_draw_box(64+3+2, 5+2, 125-2, 45-2);
        lcd_lib_set(64+3+3, 5+3, 125-3, 45-3);
        lcd_lib_clear_string_center_atP(64 + 33, 22, right);
    }else{
        lcd_lib_draw_string_center_atP(64 + 33, 22, right);
    }

    if (bottom != NULL)
    {
        if (IS_SELECTED_MAIN(2))
        {
            lcd_lib_draw_box(3+2, 49+2, 125-2, 63-2);
            lcd_lib_set(3+3, 49+3, 125-3, 63-3);
            lcd_lib_clear_string_centerP(53, bottom);
        }else{
            lcd_lib_draw_string_centerP(53, bottom);
        }
    }
}
static void lcd_menu_material_main()
{
    lcd_tripple_menu(PSTR("CHANGE"), PSTR("SETTINGS"), PSTR("RETURN"));

    if (lcd_lib_button_pressed)
    {
        if (IS_SELECTED_MAIN(0))
        {
            minProgress = 0;
            lcd_change_to_menu(lcd_menu_change_material_preheat);
        }
        else if (IS_SELECTED_MAIN(1))
            lcd_change_to_menu(lcd_menu_material_select, SCROLL_MENU_ITEM_POS(0));
        else if (IS_SELECTED_MAIN(2))
            lcd_change_to_menu(lcd_menu_main);
    }

    lcd_lib_update_screen();
}
void lcd_question_screen(menuFunc_t optionAMenu, menuFunc_t callbackOnA, const char* AButtonText, menuFunc_t optionBMenu, menuFunc_t callbackOnB, const char* BButtonText)
{
    if (lcd_lib_encoder_pos != ENCODER_NO_SELECTION)
    {
        if (lcd_lib_encoder_pos < 0)
            lcd_lib_encoder_pos += 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
        if (lcd_lib_encoder_pos >= 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM)
            lcd_lib_encoder_pos -= 2*ENCODER_TICKS_PER_MAIN_MENU_ITEM;
    }
    if (lcd_lib_button_pressed)
    {
        if (IS_SELECTED_MAIN(0))
        {
            if (callbackOnA) callbackOnA();
            if (optionAMenu) lcd_change_to_menu(optionAMenu);
        }else if (IS_SELECTED_MAIN(1))
        {
            if (callbackOnB) callbackOnB();
            if (optionBMenu) lcd_change_to_menu(optionBMenu);
        }
    }

    lcd_basic_screen();

    if (IS_SELECTED_MAIN(0))
    {
        lcd_lib_draw_box(3+2, 49+2, 64-2, 63-2);
        lcd_lib_set(3+3, 49+3, 64-3, 63-3);
        lcd_lib_clear_stringP(35 - strlen_P(AButtonText) * 3, 53, AButtonText);
    }else{
        lcd_lib_draw_stringP(35 - strlen_P(AButtonText) * 3, 53, AButtonText);
    }
    if (IS_SELECTED_MAIN(1))
    {
        lcd_lib_draw_box(64+2, 49+2, 64+60-2, 63-2);
        lcd_lib_set(64+3, 49+3, 64+60-3, 63-3);
        lcd_lib_clear_stringP(64+31 - strlen_P(BButtonText) * 3, 53, BButtonText);
    }else{
        lcd_lib_draw_stringP(64+31 - strlen_P(BButtonText) * 3, 53, BButtonText);
    }
}
static void lcd_menu_material_main()
{
    lcd_tripple_menu(PSTR("CHANGE"), PSTR("SETTINGS"), PSTR("RETURN"));

    if (lcd_lib_button_pressed)
    {
        if (IS_SELECTED_MAIN(0) && !is_command_queued())
        {
            minProgress = 0;
            char buffer[32];
            enquecommand_P(PSTR("G28 X0 Y0"));
            sprintf_P(buffer, PSTR("G1 F%i X%i Y%i"), int(homing_feedrate[0]), X_MAX_LENGTH/2, 10);
            enquecommand(buffer);
            lcd_change_to_menu_change_material(lcd_menu_material_main_return);
        }
        else if (IS_SELECTED_MAIN(1))
            lcd_change_to_menu(lcd_menu_material_select, SCROLL_MENU_ITEM_POS(0));
        else if (IS_SELECTED_MAIN(2))
            lcd_change_to_menu(lcd_menu_main);
    }

    lcd_lib_update_screen();
}
static void lcd_menu_first_run_material_select_pla_abs()
{
    LED_GLOW();
    lcd_tripple_menu(PSTR("PLA"), PSTR("ABS"), NULL);
    DRAW_PROGRESS_NR(17);
    lcd_lib_update_screen();
    
    if (lcd_lib_button_pressed)
    {
        digipot_current(2, motor_current_setting[2]);//Set E motor power to default.
        if (IS_SELECTED_MAIN(0))
        {
            lcd_material_reset_defaults();
            lcd_material_set_material(0);
            lcd_change_to_menu(lcd_menu_first_run_material_select_confirm_pla);
        }
        else if (IS_SELECTED_MAIN(1))
        {
            lcd_material_reset_defaults();
            lcd_material_set_material(1);
            lcd_change_to_menu(lcd_menu_first_run_material_select_confirm_abs);
        }
    }
}
void lcd_question_screen(menuFunc_t optionAMenu, menuFunc_t callbackOnA, const char* AButtonText, menuFunc_t optionBMenu, menuFunc_t callbackOnB, const char* BButtonText, uint8_t directionA, uint8_t directionB)
{
  if (lcd_lib_encoder_pos <= 0) {
    lcd_lib_encoder_pos=0;
  }
  else{
    lcd_lib_encoder_pos=1;
  }

  if (lcd_lib_button_pressed)
  {
    if (IS_SELECTED_MAIN(0))
    {
      if (optionAMenu) lcd_change_to_menu(optionAMenu,MAIN_MENU_ITEM_POS(0),directionA);
      if (callbackOnA) callbackOnA();
    }else if (IS_SELECTED_MAIN(1))
    {
      if (optionBMenu) lcd_change_to_menu(optionBMenu,MAIN_MENU_ITEM_POS(0),directionB);
      if (callbackOnB) callbackOnB();
    }
  }

  lcd_basic_screen();

  switch (languageType) {
  case LANGUAGE_CHINESE:
  case LANGUAGE_KOREAN:
    if (IS_SELECTED_MAIN(0))
    {
      lcd_lib_draw_box(3+3, 54-3+1, 63-3, 64-1);
      lcd_lib_set(3+4, 54-3+2, 63-4, 64-2);
      lcd_lib_clear_stringP(34 - strlen_P(AButtonText) * 3, 56-3, AButtonText);
    }else{
      lcd_lib_draw_stringP(34 - strlen_P(AButtonText) * 3, 56-3, AButtonText);
    }
    if (IS_SELECTED_MAIN(1))
    {
      lcd_lib_draw_box(3+61+3, 54-3+1, 63+61-3, 64-1);
      lcd_lib_set(3+61+4, 54-3+2, 63+61-4, 64-2);
      lcd_lib_clear_stringP(34+61 - strlen_P(BButtonText) * 3, 56-3, BButtonText);
    }else{
      lcd_lib_draw_stringP(34+61 - strlen_P(BButtonText) * 3, 56-3, BButtonText);
    }
    break;
  case LANGUAGE_ENGLISH:
    if (IS_SELECTED_MAIN(0))
    {
      lcd_lib_draw_box(3+3, 54+1, 63-3, 64-1);
      lcd_lib_set(3+4, 54+2, 63-4, 64-2);
      lcd_lib_clear_stringP(34 - strlen_P(AButtonText) * 3, 56, AButtonText);
    }else{
      lcd_lib_draw_stringP(34 - strlen_P(AButtonText) * 3, 56, AButtonText);
    }
    if (IS_SELECTED_MAIN(1))
    {
      lcd_lib_draw_box(3+61+3, 54+1, 63+61-3, 64-1);
      lcd_lib_set(3+61+4, 54+2, 63+61-4, 64-2);
      lcd_lib_clear_stringP(34+61 - strlen_P(BButtonText) * 3, 56, BButtonText);
    }else{
      lcd_lib_draw_stringP(34+61 - strlen_P(BButtonText) * 3, 56, BButtonText);
    }
    break;
  default:
    break;
  }



}