Fix Marlin splash screen logic (#13646)
This commit is contained in:
		@@ -964,6 +964,7 @@
 | 
			
		||||
  //#define STATUS_ALT_FAN_BITMAP     // Use the alternative fan bitmap
 | 
			
		||||
  //#define STATUS_FAN_FRAMES 3       // :[0,1,2,3,4] Number of fan animation frames
 | 
			
		||||
  //#define STATUS_HEAT_PERCENT       // Show heating in a progress bar
 | 
			
		||||
  //#define BOOT_MARLIN_LOGO_SMALL    // Show a smaller Marlin logo on the Boot Screen (saving 399 bytes of flash)
 | 
			
		||||
 | 
			
		||||
  // Frivolous Game Options
 | 
			
		||||
  //#define MARLIN_BRICKOUT
 | 
			
		||||
 
 | 
			
		||||
@@ -556,3 +556,7 @@
 | 
			
		||||
    #endif
 | 
			
		||||
  #endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if ENABLED(SLIM_LCD_MENUS)
 | 
			
		||||
  #define BOOT_MARLIN_LOGO_SMALL
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -29,8 +29,6 @@
 | 
			
		||||
 | 
			
		||||
#include "../../inc/MarlinConfig.h"
 | 
			
		||||
 | 
			
		||||
//#define START_BMPHIGH // Costs 399 bytes more flash
 | 
			
		||||
 | 
			
		||||
#if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
 | 
			
		||||
 | 
			
		||||
  #include "../../../_Bootscreen.h"
 | 
			
		||||
@@ -44,7 +42,33 @@
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if ENABLED(START_BMPHIGH)
 | 
			
		||||
#if ENABLED(BOOT_MARLIN_LOGO_SMALL)
 | 
			
		||||
 | 
			
		||||
  #define START_BMPWIDTH      56
 | 
			
		||||
 | 
			
		||||
  const unsigned char start_bmp[] PROGMEM = {
 | 
			
		||||
    B00011111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
 | 
			
		||||
    B01100000,B00000000,B00000000,B00000000,B00000000,B00000001,B11111111,
 | 
			
		||||
    B01000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,
 | 
			
		||||
    B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111111,
 | 
			
		||||
    B10000011,B11001111,B00000000,B00000000,B00001100,B00110000,B00111111,
 | 
			
		||||
    B10000111,B11111111,B10000000,B00000000,B00001100,B00110000,B00011111,
 | 
			
		||||
    B10000110,B01111001,B10000000,B00000000,B00001100,B00000000,B00001111,
 | 
			
		||||
    B10001100,B00110000,B11000111,B10000011,B10001100,B00110000,B11100111,
 | 
			
		||||
    B10001100,B00110000,B11001111,B11000111,B11001100,B00110001,B11110011,
 | 
			
		||||
    B10001100,B00110000,B11011100,B11101100,B11101100,B00110011,B10111001,
 | 
			
		||||
    B10001100,B00110000,B11011000,B01101100,B01101100,B00110011,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11010000,B01101100,B00001100,B00110011,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11011000,B01101100,B00001100,B00110011,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11011100,B01101100,B00001110,B00111011,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11001111,B01111100,B00000111,B10011111,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11000111,B01111100,B00000011,B10001111,B00011001,
 | 
			
		||||
    B01000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000010,
 | 
			
		||||
    B01100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000110,
 | 
			
		||||
    B00011111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111000
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
  #define START_BMPWIDTH      112
 | 
			
		||||
 | 
			
		||||
@@ -89,32 +113,6 @@
 | 
			
		||||
    B00000001,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,B10000000
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
  #define START_BMPWIDTH      56
 | 
			
		||||
 | 
			
		||||
  const unsigned char start_bmp[] PROGMEM = {
 | 
			
		||||
    B00011111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111111,
 | 
			
		||||
    B01100000,B00000000,B00000000,B00000000,B00000000,B00000001,B11111111,
 | 
			
		||||
    B01000000,B00000000,B00000000,B00000000,B00000000,B00000000,B11111111,
 | 
			
		||||
    B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B01111111,
 | 
			
		||||
    B10000011,B11001111,B00000000,B00000000,B00001100,B00110000,B00111111,
 | 
			
		||||
    B10000111,B11111111,B10000000,B00000000,B00001100,B00110000,B00011111,
 | 
			
		||||
    B10000110,B01111001,B10000000,B00000000,B00001100,B00000000,B00001111,
 | 
			
		||||
    B10001100,B00110000,B11000111,B10000011,B10001100,B00110000,B11100111,
 | 
			
		||||
    B10001100,B00110000,B11001111,B11000111,B11001100,B00110001,B11110011,
 | 
			
		||||
    B10001100,B00110000,B11011100,B11101100,B11101100,B00110011,B10111001,
 | 
			
		||||
    B10001100,B00110000,B11011000,B01101100,B01101100,B00110011,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11010000,B01101100,B00001100,B00110011,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11011000,B01101100,B00001100,B00110011,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11011100,B01101100,B00001110,B00111011,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11001111,B01111100,B00000111,B10011111,B00011001,
 | 
			
		||||
    B10001100,B00110000,B11000111,B01111100,B00000011,B10001111,B00011001,
 | 
			
		||||
    B01000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000010,
 | 
			
		||||
    B01100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000110,
 | 
			
		||||
    B00011111,B11111111,B11111111,B11111111,B11111111,B11111111,B11111000
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef START_BMP_BYTEWIDTH
 | 
			
		||||
 
 | 
			
		||||
@@ -154,29 +154,53 @@ void MarlinUI::set_font(const MarlinFont font_nr) {
 | 
			
		||||
      lcd_custom_bootscreen();
 | 
			
		||||
    #endif
 | 
			
		||||
 | 
			
		||||
    constexpr uint8_t offy =
 | 
			
		||||
      #if ENABLED(START_BMPHIGH)
 | 
			
		||||
        (LCD_PIXEL_HEIGHT - (START_BMPHEIGHT)) / 2
 | 
			
		||||
      #else
 | 
			
		||||
        MENU_FONT_HEIGHT
 | 
			
		||||
      #endif
 | 
			
		||||
    ;
 | 
			
		||||
    // Screen dimensions.
 | 
			
		||||
    //const uint8_t width = u8g.getWidth(), height = u8g.getHeight();
 | 
			
		||||
    constexpr uint8_t width = LCD_PIXEL_WIDTH, height = LCD_PIXEL_HEIGHT;
 | 
			
		||||
 | 
			
		||||
    const uint8_t width = u8g.getWidth(), height = u8g.getHeight(),
 | 
			
		||||
                  offx = (width - (START_BMPWIDTH)) / 2;
 | 
			
		||||
    // Determine text space needed
 | 
			
		||||
    #ifndef STRING_SPLASH_LINE2
 | 
			
		||||
      constexpr uint8_t text_total_height = MENU_FONT_HEIGHT,
 | 
			
		||||
                        text_width_1 = (sizeof(STRING_SPLASH_LINE1) - 1) * (MENU_FONT_WIDTH),
 | 
			
		||||
                        text_width_2 = 0;
 | 
			
		||||
    #else
 | 
			
		||||
      constexpr uint8_t text_total_height = (MENU_FONT_HEIGHT) * 2,
 | 
			
		||||
                        text_width_1 = (sizeof(STRING_SPLASH_LINE1) - 1) * (MENU_FONT_WIDTH),
 | 
			
		||||
                        text_width_2 = (sizeof(STRING_SPLASH_LINE2) - 1) * (MENU_FONT_WIDTH);
 | 
			
		||||
    #endif
 | 
			
		||||
    constexpr uint8_t text_max_width = MAX(text_width_1, text_width_2),
 | 
			
		||||
                      rspace = width - (START_BMPWIDTH);
 | 
			
		||||
 | 
			
		||||
    int8_t offx, offy, txt_base, txt_offx_1, txt_offx_2;
 | 
			
		||||
 | 
			
		||||
    // Can the text fit to the right of the bitmap?
 | 
			
		||||
    if (text_max_width < rspace) {
 | 
			
		||||
      constexpr uint8_t inter = (width - text_max_width - (START_BMPWIDTH)) / 3; // Evenly distribute horizontal space
 | 
			
		||||
      offx = inter;                             // First the boot logo...
 | 
			
		||||
      offy = (height - (START_BMPHEIGHT)) / 2;  // ...V-aligned in the full height
 | 
			
		||||
      txt_offx_1 = txt_offx_2 = inter + (START_BMPWIDTH) + inter; // Text right of the bitmap
 | 
			
		||||
      txt_base = (height + MENU_FONT_ASCENT + text_total_height - (MENU_FONT_HEIGHT)) / 2; // Text vertical center
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      constexpr uint8_t inter = (height - text_total_height - (START_BMPHEIGHT)) / 3; // Evenly distribute vertical space
 | 
			
		||||
      offy = inter;                             // V-align boot logo proportionally
 | 
			
		||||
      offx = rspace / 2;                        // Center the boot logo in the whole space
 | 
			
		||||
      txt_offx_1 = (width - text_width_1) / 2;  // Text 1 centered
 | 
			
		||||
      txt_offx_2 = (width - text_width_2) / 2;  // Text 2 centered
 | 
			
		||||
      txt_base = offy + START_BMPHEIGHT + offy + text_total_height - (MENU_FONT_DESCENT);   // Even spacing looks best
 | 
			
		||||
    }
 | 
			
		||||
    NOLESS(offx, 0);
 | 
			
		||||
    NOLESS(offy, 0);
 | 
			
		||||
 | 
			
		||||
    u8g.firstPage();
 | 
			
		||||
    do {
 | 
			
		||||
      u8g.drawBitmapP(offx, offy, (START_BMPWIDTH + 7) / 8, START_BMPHEIGHT, start_bmp);
 | 
			
		||||
      set_font(FONT_MENU);
 | 
			
		||||
      #ifndef STRING_SPLASH_LINE2
 | 
			
		||||
        const uint8_t txt1X = width - (sizeof(STRING_SPLASH_LINE1) - 1) * (MENU_FONT_WIDTH);
 | 
			
		||||
        u8g.drawStr(txt1X, (height + MENU_FONT_HEIGHT) / 2, STRING_SPLASH_LINE1);
 | 
			
		||||
        u8g.drawStr(txt_offx_1, txt_base, STRING_SPLASH_LINE1);
 | 
			
		||||
      #else
 | 
			
		||||
        const uint8_t txt1X = (width - (sizeof(STRING_SPLASH_LINE1) - 1) * (MENU_FONT_WIDTH)) / 2,
 | 
			
		||||
                      txt2X = (width - (sizeof(STRING_SPLASH_LINE2) - 1) * (MENU_FONT_WIDTH)) / 2;
 | 
			
		||||
        u8g.drawStr(txt1X, height - (MENU_FONT_HEIGHT) * 3 / 2, STRING_SPLASH_LINE1);
 | 
			
		||||
        u8g.drawStr(txt2X, height - (MENU_FONT_HEIGHT) * 1 / 2, STRING_SPLASH_LINE2);
 | 
			
		||||
        u8g.drawStr(txt_offx_1, txt_base - (MENU_FONT_HEIGHT), STRING_SPLASH_LINE1);
 | 
			
		||||
        u8g.drawStr(txt_offx_2, txt_base, STRING_SPLASH_LINE2);
 | 
			
		||||
      #endif
 | 
			
		||||
    } while (u8g.nextPage());
 | 
			
		||||
    #ifndef BOOTSCREEN_TIMEOUT
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user