Fix menu highlight glitch, tweak scrolling code.

- Backport of fix by thinkyhead for LCD scrolling glitch (#9954)
- May fix T1613?
master
Scott Lahteine 6 years ago committed by Marcio Teixeira
parent ff936a5f92
commit ac4fac7b6f

@ -138,7 +138,10 @@ uint8_t lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW; // Set when the LCD needs to
uint16_t max_display_update_time = 0;
#if ENABLED(DOGLCD)
bool drawing_screen = false;
bool drawing_screen, // = false
first_page;
#else
constexpr bool first_page = true;
#endif
#if ENABLED(DAC_STEPPER_CURRENT)
@ -160,6 +163,9 @@ uint16_t max_display_update_time = 0;
extern bool powersupply_on;
#endif
bool no_reentry = false;
constexpr int8_t menu_bottom = LCD_HEIGHT - (TALL_FONT_CORRECTION);
////////////////////////////////////////////
///////////////// Menu Tree ////////////////
////////////////////////////////////////////
@ -356,22 +362,21 @@ uint16_t max_display_update_time = 0;
* _lcdLineNr is the index of the LCD line (e.g., 0-3)
* _menuLineNr is the menu item to draw and process
* _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
* _countedItems is the total number of items in the menu (after one call)
* screen_items is the total number of items in the menu (after one call)
*/
#define START_SCREEN_OR_MENU(LIMIT) \
ENCODER_DIRECTION_MENUS(); \
ENCODER_RATE_MULTIPLY(false); \
if (encoderPosition > 0x8000) encoderPosition = 0; \
static int8_t _countedItems = 0; \
int8_t encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
if (_countedItems > 0 && encoderLine >= _countedItems - (LIMIT)) { \
encoderLine = max(0, _countedItems - (LIMIT)); \
if (first_page) encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
if (screen_items > 0 && encoderLine >= screen_items - (LIMIT)) { \
encoderLine = max(0, screen_items - (LIMIT)); \
encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
}
#define SCREEN_OR_MENU_LOOP() \
int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT - (TALL_FONT_CORRECTION); _lcdLineNr++, _menuLineNr++) { \
for (int8_t _lcdLineNr = 0; _lcdLineNr < menu_bottom; _lcdLineNr++, _menuLineNr++) { \
_thisItemNr = 0
/**
@ -382,28 +387,22 @@ uint16_t max_display_update_time = 0;
* Scroll as-needed to keep the selected line in view.
*/
#define START_SCREEN() \
START_SCREEN_OR_MENU(LCD_HEIGHT - (TALL_FONT_CORRECTION)); \
encoderTopLine = encoderLine; \
scroll_screen(menu_bottom, false); \
bool _skipStatic = false; \
SCREEN_OR_MENU_LOOP()
#define START_MENU() \
START_SCREEN_OR_MENU(1); \
screen_changed = false; \
NOMORE(encoderTopLine, encoderLine); \
if (encoderLine >= encoderTopLine + LCD_HEIGHT - (TALL_FONT_CORRECTION)) { \
encoderTopLine = encoderLine - (LCD_HEIGHT - (TALL_FONT_CORRECTION) - 1); \
} \
scroll_screen(1, true); \
bool _skipStatic = true; \
SCREEN_OR_MENU_LOOP()
#define END_SCREEN() \
} \
_countedItems = _thisItemNr
screen_items = _thisItemNr
#define END_MENU() \
} \
_countedItems = _thisItemNr; \
screen_items = _thisItemNr; \
UNUSED(_skipStatic)
////////////////////////////////////////////
@ -600,6 +599,29 @@ uint16_t max_display_update_time = 0;
lcd_goto_previous_menu();
}
/**
* Scrolling for menus and other line-based screens
*/
int8_t encoderLine, screen_items;
void scroll_screen(const uint8_t limit, const bool is_menu) {
if (encoderPosition > 0x8000) encoderPosition = 0;
if (first_page) {
encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM);
screen_changed = false;
}
if (screen_items > 0 && encoderLine >= screen_items - limit) {
encoderLine = max(0, screen_items - limit);
encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM);
}
if (is_menu) {
NOMORE(encoderTopLine, encoderLine);
if (encoderLine >= encoderTopLine + menu_bottom)
encoderTopLine = encoderLine - menu_bottom + 1;
}
else
encoderTopLine = encoderLine;
}
#endif // ULTIPANEL
/**
@ -4989,11 +5011,12 @@ void lcd_update() {
#endif
if (!drawing_screen) { // If not already drawing pages
u8g.firstPage(); // Start the first page
drawing_screen = 1; // Flag as drawing pages
drawing_screen = first_page = true; // Flag as drawing pages
}
lcd_setFont(FONT_MENU); // Setup font for every page draw
u8g.setColorIndex(1); // And reset the color
CURRENTSCREEN(); // Draw and process the current screen
first_page = false;
// The screen handler can clear drawing_screen for an action that changes the screen.
// If still drawing and there's another page, update max-time and return now.

Loading…
Cancel
Save