added advanced scrolling options.

Fork of Adafruit_GFX by Neal Horman

Files at this revision

API Documentation at this revision

Comitter:
hthoffma
Date:
Fri Feb 24 09:17:19 2017 +0000
Parent:
17:005fab139cc2
Commit message:
added various scrolling options.

Changed in this revision

Adafruit_GFX.cpp Show annotated file Show diff for this revision Revisions of this file
Adafruit_GFX.h Show annotated file Show diff for this revision Revisions of this file
Adafruit_GFX_Config.h Show annotated file Show diff for this revision Revisions of this file
diff -r 005fab139cc2 -r de8c0b7e17c4 Adafruit_GFX.cpp
--- a/Adafruit_GFX.cpp	Sun Jan 22 16:38:55 2017 +0000
+++ b/Adafruit_GFX.cpp	Fri Feb 24 09:17:19 2017 +0000
@@ -376,14 +376,31 @@
     {
         drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize);
         cursor_x += textsize*6;
-        if (wrap && (cursor_x > (_width - textsize*6)))
+        if (line_wrap != H_NO_WRAP && (cursor_x > (_width - textsize*6)))
         {
             cursor_x = 0;
-            if (screen_wrap && (cursor_y > _height - textsize*14)) {
-                scroll();
+            
+            if ((cursor_y > _height - textsize*9)) {
+                switch (screen_wrap) {
+                    case V_NO_WRAP:
+                        cursor_y += textsize*8;
+                    break;
+                    case V_SCROLL:
+                        scroll();
+                    break;
+                    case V_WRAP:
+                        cursor_y = 0;
+                }
             } else {
                 cursor_y += textsize*8;
             }
+            
+            if (line_wrap == H_WRAP_N_CLEAR)
+            {
+#if defined(GFX_WANT_ABSTRACTS) || defined(GFX_SIZEABLE_TEXT)
+                fillRect(0, cursor_y, _width, textsize*8, textbgcolor);
+#endif          
+            }
         }
     }
     return 1;
diff -r 005fab139cc2 -r de8c0b7e17c4 Adafruit_GFX.h
--- a/Adafruit_GFX.h	Sun Jan 22 16:38:55 2017 +0000
+++ b/Adafruit_GFX.h	Fri Feb 24 09:17:19 2017 +0000
@@ -60,7 +60,7 @@
         , textbgcolor(BLACK)
         , textsize(1)
         , rotation(0)
-        , wrap(true)
+        , line_wrap(H_NO_WRAP)
         {};
 
     virtual void scroll(void) =0; 
@@ -163,10 +163,30 @@
     inline void setTextColor(uint16_t c) { textcolor = c; textbgcolor = c; }
     /// Set the text foreground and background colors independantly
     inline void setTextColor(uint16_t c, uint16_t b) { textcolor = c; textbgcolor = b; };
+    enum hwrap_mode {
+        H_NO_WRAP,
+        H_WRAP,
+        H_WRAP_N_CLEAR
+    };
+    enum vwrap_mode {
+        V_NO_WRAP,
+        V_SCROLL,
+        V_WRAP
+    };
     /// Set text wraping mode true or false
-    inline void setTextWrap(bool w) { wrap = w; };
-    inline void setScreenWrap(bool w) {screen_wrap = w;};
-
+    inline void setTextWrap(bool w)
+    {
+        if (w) line_wrap = H_WRAP; 
+        else line_wrap = H_NO_WRAP;
+    }
+    inline void setTextWrapMode(enum hwrap_mode w) { line_wrap = w; };
+    inline void setScreenWrapMode(enum vwrap_mode w) {screen_wrap = w;};
+ 
+    inline void getDimentions(uint16_t *width, uint16_t *height)
+    {
+        *width = _width;
+        *height = _height;
+    }
 
     /// Set the display rotation, 1, 2, 3, or 4
     void setRotation(uint8_t r);
@@ -180,8 +200,8 @@
     uint16_t textcolor, textbgcolor;
     uint8_t  textsize;
     uint8_t  rotation;
-    bool  wrap; // If set, 'wrap' text at right edge of display
-    bool screen_wrap;
+    enum hwrap_mode line_wrap; // If set, 'wrap' text at right edge of display
+    enum vwrap_mode screen_wrap;
 };
 
 #endif
diff -r 005fab139cc2 -r de8c0b7e17c4 Adafruit_GFX_Config.h
--- a/Adafruit_GFX_Config.h	Sun Jan 22 16:38:55 2017 +0000
+++ b/Adafruit_GFX_Config.h	Fri Feb 24 09:17:19 2017 +0000
@@ -5,10 +5,10 @@
 #define NO_SPLASH_ADAFRUIT
 
 // Uncomment this to enable all functionality
-//#define GFX_WANT_ABSTRACTS
+#define GFX_WANT_ABSTRACTS
 
 // Uncomment this to enable only runtime font scaling, without all the rest of the Abstracts
-//#define GFX_SIZEABLE_TEXT
+#define GFX_SIZEABLE_TEXT
 
 
 #endif
\ No newline at end of file