Browse Source

Fix menu highlight glitch, tweak scrolling code (#9957)

Scott Lahteine 7 years ago
parent
commit
f9cafc4001
No account linked to committer's email address
1 changed files with 42 additions and 23 deletions
  1. 42
    23
      Marlin/src/lcd/ultralcd.cpp

+ 42
- 23
Marlin/src/lcd/ultralcd.cpp View File

154
 uint16_t max_display_update_time = 0;
154
 uint16_t max_display_update_time = 0;
155
 
155
 
156
 #if ENABLED(DOGLCD)
156
 #if ENABLED(DOGLCD)
157
-  bool drawing_screen = false;
157
+  bool drawing_screen, // = false
158
+       first_page;
159
+#else
160
+  constexpr bool first_page = true;
158
 #endif
161
 #endif
159
 
162
 
160
 #if ENABLED(DAC_STEPPER_CURRENT)
163
 #if ENABLED(DAC_STEPPER_CURRENT)
173
   #endif
176
   #endif
174
 
177
 
175
   bool no_reentry = false;
178
   bool no_reentry = false;
179
+  constexpr int8_t menu_bottom = LCD_HEIGHT - (TALL_FONT_CORRECTION);
176
 
180
 
177
   ////////////////////////////////////////////
181
   ////////////////////////////////////////////
178
   ///////////////// Menu Tree ////////////////
182
   ///////////////// Menu Tree ////////////////
394
    *   _lcdLineNr is the index of the LCD line (e.g., 0-3)
398
    *   _lcdLineNr is the index of the LCD line (e.g., 0-3)
395
    *   _menuLineNr is the menu item to draw and process
399
    *   _menuLineNr is the menu item to draw and process
396
    *   _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
400
    *   _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
397
-   *   _countedItems is the total number of items in the menu (after one call)
401
+   *   screen_items is the total number of items in the menu (after one call)
398
    */
402
    */
399
   #define START_SCREEN_OR_MENU(LIMIT) \
403
   #define START_SCREEN_OR_MENU(LIMIT) \
400
     ENCODER_DIRECTION_MENUS(); \
404
     ENCODER_DIRECTION_MENUS(); \
401
     ENCODER_RATE_MULTIPLY(false); \
405
     ENCODER_RATE_MULTIPLY(false); \
402
     if (encoderPosition > 0x8000) encoderPosition = 0; \
406
     if (encoderPosition > 0x8000) encoderPosition = 0; \
403
-    static int8_t _countedItems = 0; \
404
-    int8_t encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
405
-    if (_countedItems > 0 && encoderLine >= _countedItems - (LIMIT)) { \
406
-      encoderLine = max(0, _countedItems - (LIMIT)); \
407
+    if (first_page) encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM); \
408
+    if (screen_items > 0 && encoderLine >= screen_items - (LIMIT)) { \
409
+      encoderLine = max(0, screen_items - (LIMIT)); \
407
       encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
410
       encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM); \
408
     }
411
     }
409
 
412
 
410
   #define SCREEN_OR_MENU_LOOP() \
413
   #define SCREEN_OR_MENU_LOOP() \
411
     int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
414
     int8_t _menuLineNr = encoderTopLine, _thisItemNr; \
412
-    for (int8_t _lcdLineNr = 0; _lcdLineNr < LCD_HEIGHT - (TALL_FONT_CORRECTION); _lcdLineNr++, _menuLineNr++) { \
415
+    for (int8_t _lcdLineNr = 0; _lcdLineNr < menu_bottom; _lcdLineNr++, _menuLineNr++) { \
413
       _thisItemNr = 0
416
       _thisItemNr = 0
414
 
417
 
415
   /**
418
   /**
420
    *               Scroll as-needed to keep the selected line in view.
423
    *               Scroll as-needed to keep the selected line in view.
421
    */
424
    */
422
   #define START_SCREEN() \
425
   #define START_SCREEN() \
423
-    START_SCREEN_OR_MENU(LCD_HEIGHT - (TALL_FONT_CORRECTION)); \
424
-    encoderTopLine = encoderLine; \
426
+    scroll_screen(menu_bottom, false); \
425
     bool _skipStatic = false; \
427
     bool _skipStatic = false; \
426
     SCREEN_OR_MENU_LOOP()
428
     SCREEN_OR_MENU_LOOP()
427
 
429
 
428
   #define START_MENU() \
430
   #define START_MENU() \
429
-    START_SCREEN_OR_MENU(1); \
430
-    screen_changed = false; \
431
-    NOMORE(encoderTopLine, encoderLine); \
432
-    if (encoderLine >= encoderTopLine + LCD_HEIGHT - (TALL_FONT_CORRECTION)) { \
433
-      encoderTopLine = encoderLine - (LCD_HEIGHT - (TALL_FONT_CORRECTION) - 1); \
434
-    } \
431
+    scroll_screen(1, true); \
435
     bool _skipStatic = true; \
432
     bool _skipStatic = true; \
436
     SCREEN_OR_MENU_LOOP()
433
     SCREEN_OR_MENU_LOOP()
437
 
434
 
438
   #define END_SCREEN() \
435
   #define END_SCREEN() \
439
     } \
436
     } \
440
-    _countedItems = _thisItemNr
437
+    screen_items = _thisItemNr
441
 
438
 
442
   #define END_MENU() \
439
   #define END_MENU() \
443
     } \
440
     } \
444
-    _countedItems = _thisItemNr; \
441
+    screen_items = _thisItemNr; \
445
     UNUSED(_skipStatic)
442
     UNUSED(_skipStatic)
446
 
443
 
447
   ////////////////////////////////////////////
444
   ////////////////////////////////////////////
643
     lcd_goto_previous_menu();
640
     lcd_goto_previous_menu();
644
   }
641
   }
645
 
642
 
643
+  /**
644
+   * Scrolling for menus and other line-based screens
645
+   */
646
+  int8_t encoderLine, screen_items;
647
+  void scroll_screen(const uint8_t limit, const bool is_menu) {
648
+    if (encoderPosition > 0x8000) encoderPosition = 0;
649
+    if (first_page) {
650
+      encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM);
651
+      screen_changed = false;
652
+    }
653
+    if (screen_items > 0 && encoderLine >= screen_items - limit) {
654
+      encoderLine = max(0, screen_items - limit);
655
+      encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM);
656
+    }
657
+    if (is_menu) {
658
+      NOMORE(encoderTopLine, encoderLine);
659
+      if (encoderLine >= encoderTopLine + menu_bottom)
660
+        encoderTopLine = encoderLine - menu_bottom + 1;
661
+    }
662
+    else
663
+      encoderTopLine = encoderLine;
664
+  }
665
+
646
 #endif // ULTIPANEL
666
 #endif // ULTIPANEL
647
 
667
 
648
 /**
668
 /**
785
 
805
 
786
   void lcd_quick_feedback(const bool clear_buttons) {
806
   void lcd_quick_feedback(const bool clear_buttons) {
787
     lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
807
     lcdDrawUpdate = LCDVIEW_CLEAR_CALL_REDRAW;
788
-
789
-    if (clear_buttons)
790
-      buttons = 0;
791
-
808
+    if (clear_buttons) buttons = 0;
792
     next_button_update_ms = millis() + 500;
809
     next_button_update_ms = millis() + 500;
793
 
810
 
794
     // Buzz and wait. The delay is needed for buttons to settle!
811
     // Buzz and wait. The delay is needed for buttons to settle!
3232
     #endif
3249
     #endif
3233
 
3250
 
3234
     #if HAS_LCD_CONTRAST
3251
     #if HAS_LCD_CONTRAST
3235
-      // please don't remove the "(int16_t*)" - it's needed for the VIKI2 display  --- see PR #9132 before changing it
3236
       MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
3252
       MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
3237
     #endif
3253
     #endif
3238
     #if ENABLED(FWRETRACT)
3254
     #if ENABLED(FWRETRACT)
5193
         if (do_u8g_loop) {
5209
         if (do_u8g_loop) {
5194
           if (!drawing_screen) {                        // If not already drawing pages
5210
           if (!drawing_screen) {                        // If not already drawing pages
5195
             u8g.firstPage();                            // Start the first page
5211
             u8g.firstPage();                            // Start the first page
5196
-            drawing_screen = 1;                         // Flag as drawing pages
5212
+            drawing_screen = first_page = true;         // Flag as drawing pages
5197
           }
5213
           }
5198
           lcd_setFont(FONT_MENU);                       // Setup font for every page draw
5214
           lcd_setFont(FONT_MENU);                       // Setup font for every page draw
5199
           u8g.setColorIndex(1);                         // And reset the color
5215
           u8g.setColorIndex(1);                         // And reset the color
5200
           CURRENTSCREEN();                              // Draw and process the current screen
5216
           CURRENTSCREEN();                              // Draw and process the current screen
5217
+          first_page = false;
5201
 
5218
 
5202
           // The screen handler can clear drawing_screen for an action that changes the screen.
5219
           // The screen handler can clear drawing_screen for an action that changes the screen.
5203
           // If still drawing and there's another page, update max-time and return now.
5220
           // If still drawing and there's another page, update max-time and return now.
5380
         #if BUTTON_EXISTS(EN1)
5397
         #if BUTTON_EXISTS(EN1)
5381
           if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
5398
           if (BUTTON_PRESSED(EN1)) newbutton |= EN_A;
5382
         #endif
5399
         #endif
5400
+
5383
         #if BUTTON_EXISTS(EN2)
5401
         #if BUTTON_EXISTS(EN2)
5384
           if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
5402
           if (BUTTON_PRESSED(EN2)) newbutton |= EN_B;
5385
         #endif
5403
         #endif
5404
+
5386
         #if BUTTON_EXISTS(ENC)
5405
         #if BUTTON_EXISTS(ENC)
5387
           if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
5406
           if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
5388
         #endif
5407
         #endif

Loading…
Cancel
Save