Test for STM32F4

Dependents:   Nucleo_SSD1331

Fork of RGB_OLED_SSD1331 by Juergen M

Revision:
17:1bcdc92af126
Parent:
15:c49040bf0e1d
--- a/src/SGL.cpp	Thu Dec 08 22:08:16 2016 +0000
+++ b/src/SGL.cpp	Sat Dec 10 22:51:06 2016 +0000
@@ -37,7 +37,7 @@
 //---------------------------------------------------------------------------------------
 template <class T>
 SGL<T>::SGL(T width, T height):
-    _width(width), _height(height),
+    _displayWidth(width), _displayHeight(height),
     _currentFont(0),     
     _fontWidth(0),
     _fontHeight(0),
@@ -73,7 +73,7 @@
 template <class T>
 void SGL<T>::drawVLine(T x, T y, T length,uint16_t color)
 {
-    T y1 = MIN(y+length,_height-1);
+    T y1 = MIN(y+length,_displayHeight-1);
     for(T i = y; i < y1; ++i)
     {
         drawPixel(x, i, color);
@@ -84,7 +84,7 @@
 template <class T>
 void SGL<T>::drawHLine(T x, T y, T length, uint16_t color)
 {
-    T x1 = MIN(x+length,_width-1);
+    T x1 = MIN(x+length,_displayWidth-1);
     for(T i = x; i < x1; ++i)
     {
         drawPixel(i, y, color);
@@ -223,6 +223,8 @@
     if((ascii < _fontStart)||(ascii > _fontStop)){
         return;
     }
+    
+    clearArea(x, y, x+_fontWidth, y+_fontHeight);
 
     for(uint8_t i = 0; i < _fontWidth; ++i )
     {
@@ -269,28 +271,33 @@
 }
 
 //---------------------------------------------------------------------------------------
-/*template <class T>
-void SGL<T>::drawString(const char *string, T x, T y, uint16_t color, float zoom, uint8_t fontSpace)
+template <class T>
+void SGL<T>::drawString(const char *string, T x, T y, uint16_t color, float zoom, int8_t fontSpace)
 {
     if(!_currentFont && !*_currentFont)
         return;
         
+    T tempX = x;
+    T tempY = y;
+        
     while(*string)
-    {
-        drawChar(*string, x, y, color, zoom);
+    {  
+        drawChar(*string, tempX, tempY, color, zoom);
         *string++;
-        x += fontSpace*zoom;
-        if(x >= _width-1)
+        tempX += _fontWidth+fontSpace;
+        
+        // New line when end of display reached 
+        if(tempX >= _displayWidth-1)
         {
-            y += _fontHeight*zoom;
-            x = 0;
+            tempY += _fontHeight*zoom;
+            tempX = 0;
         }
     }
-}*/
+}
 
 //---------------------------------------------------------------------------------------
 template <class T>
-Rect<T> SGL<T>::drawString(const char *string, T x, T y, uint16_t color, float zoom, uint8_t fontSpace)
+Rect<T> SGL<T>::boundingRect(const char *string, T x, T y, float zoom, int8_t fontSpace)
 {
     if(!_currentFont && !*_currentFont)
         return Rect<T>();
@@ -299,18 +306,20 @@
         
     while(*string)
     {
-        boundingWidth += _fontWidth;
-        drawChar(*string, x, y, color, zoom);
+        boundingWidth += (_fontWidth+fontSpace*zoom);        
         *string++;
-        x += fontSpace*zoom;
-        if(x >= _width-1)
-        {
-            y += _fontHeight*zoom;
-            x = 0;
-        }
     }
     
-    return Rect<T>(x, y, boundingWidth, _fontHeight );
+    T rectX = x-2;
+    T rectY = y-2;
+    
+    if(rectX > _displayWidth)
+        rectX = 0;
+        
+    if(rectY > _displayHeight)
+        rectY = 0;
+    
+    return Rect<T>(rectX, rectY, boundingWidth, _fontHeight+3 );
 }
 
 //---------------------------------------------------------------------------------------
@@ -335,7 +344,7 @@
 template <class T>
 void SGL<T>::fillScreen(uint16_t color)
 {
-    fillRect(0, 0, _width, _height, color);
+    fillRect(0, 0, _displayWidth, _displayHeight, color);
 }
 
 //---------------------------------------------------------------------------------------