Mladen Adamovic / F746_GUI

Dependencies:   Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG

Dependents:   Spectrogram

Fork of F746_GUI by 不韋 呂

Files at this revision

API Documentation at this revision

Comitter:
MikamiUitOpen
Date:
Sat Apr 30 06:33:32 2016 +0000
Parent:
11:7debdaa7b503
Child:
13:9ae055fac9cf
Commit message:
13

Changed in this revision

SeekBar.cpp Show annotated file Show diff for this revision Revisions of this file
SeekBar.hpp Show annotated file Show diff for this revision Revisions of this file
SeekbarGroup.cpp Show annotated file Show diff for this revision Revisions of this file
SeekbarGroup.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/SeekBar.cpp	Wed Apr 27 07:28:04 2016 +0000
+++ b/SeekBar.cpp	Sat Apr 30 06:33:32 2016 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  SeekBar class
 //
-//  2016/04/27, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/04/30, Copyright (c) 2016 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "SeekBar.hpp"
@@ -19,13 +19,24 @@
         : GuiBase(x, y, Font12, GuiBase::ENUM_TEXT, backColor, thumbColor),
           L_(length), W_(width),
           SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH),
-          MIN_(min), MAX_(max), ORIENT_(Holizontal),
-          v_(initialValue), slided_(false), active_(true)
+          MIN_(min), MAX_(max), ORIENT_(Holizontal), v_(initialValue),
+          labelOn_(true), slided_(false), active_(true)
     {
         Draw(initialValue);
-        labelL = new Label(x, y-28, left, Label::CENTER);
-        labelC = new Label(x+length/2, y-28, center, Label::CENTER);
-        labelR = new Label(x+length, y-28, right, Label::CENTER);
+        labelLCR = new Label *[3];
+        uint16_t y0 = y - thumbSize/2 - 13;
+        labelLCR[0] = new Label(x, y0, left, Label::CENTER);
+        labelLCR[1] = new Label(x+length/2, y0, center, Label::CENTER);
+        labelLCR[2] = new Label(x+length, y0, right, Label::CENTER);
+    }
+
+    SeekBar::~SeekBar()
+    {
+        if (labelOn_)
+        {
+            for (int n=0; n<3; n++) delete labelLCR[n];
+            delete[] labelLCR;
+        }
     }
 
     // Slide thumb
@@ -43,13 +54,12 @@
 
         uint16_t x, y;
         bool rtn = IsOnThumb(x, y);
-        if (rtn)
+        if (rtn || slided_)
         {
-            v_ = ToValue(Point(x, y));
-            Draw(v_, true);
-            slided_ = true;
+            if (rtn) v_ = ToValue(Point(x, y));
+            Draw(v_, rtn);
+            slided_ = rtn;
         }
-
         return rtn;
     }
 
@@ -57,24 +67,16 @@
     {
         active_ = true;
         Draw(v_);
-        if (labelL != NULL)
-        {
-            labelL->Draw(TEXT_COLOR_); 
-            labelC->Draw(TEXT_COLOR_); 
-            labelR->Draw(TEXT_COLOR_); 
-        }
+        if (labelOn_)
+            for (int n=0; n<3; n++) labelLCR[n]->Draw(TEXT_COLOR_);
     }
 
     void SeekBar::Inactivate()
     {
         active_ = false;
         Draw(v_);
-        if (labelL != NULL)
-        {
-            labelL->Draw(INACTIVE_TEXT_COLOR_);
-            labelC->Draw(INACTIVE_TEXT_COLOR_);
-            labelR->Draw(INACTIVE_TEXT_COLOR_);
-        }
+        if (labelOn_)
+            for (int n=0; n<3; n++) labelLCR[n]->Draw(INACTIVE_TEXT_COLOR_);
     }
 
     // If touched position is on the thumb, return true
@@ -83,16 +85,17 @@
         x = state_.touchX[0];
         y = state_.touchY[0];
 
+        uint16_t th = SIZE_/2;
         Point pt = ToPoint(v_);
         if (ORIENT_ == Holizontal)
         {
-            if ( (pt.x-SIZE_/5 <= x) && (x <= pt.x+SIZE_/5) &&
-                 (pt.y-SIZE_ <= y) && (y <= pt.y+SIZE_) ) return true;
+            if ( (pt.x-th <= x) && (x <= pt.x+th) &&
+                 (pt.y-th <= y) && (y <= pt.y+th) ) return true;
         }
         else
         {
-            if ( (pt.x-SIZE_ <= x) && (x <= pt.x+SIZE_) &&
-                 (pt.y-SIZE_/5 <= y) && (y <= pt.y+SIZE_/5) ) return true;
+            if ( (pt.x-th <= x) && (x <= pt.x+th) &&
+                 (pt.y-th <= y) && (y <= pt.y+th) ) return true;
         }
 
         return false;
@@ -115,9 +118,9 @@
         // Draw upper line
         if (active_) lcd_.SetTextColor(COLOR_H_);
         else         lcd_.SetTextColor(INACTIVE_TEXT_COLOR_-0x404040);
-        if (ORIENT_ == Holizontal)
+        if ((ORIENT_ == Holizontal) && ((X_+L_-pt.x) > 0))
             lcd_.FillRect(pt.x, Y_-W_/4, X_+L_-pt.x, W_/2);
-        else
+        if ((ORIENT_ == Vertical) && ((pt.y-Y_) > 0))
             lcd_.FillRect(X_-W_/4, Y_, W_/2, pt.y-Y_);
 
         // Draw lower line
@@ -144,11 +147,12 @@
         {
             lcd_.DrawRect(xPos, yPos, width, height);
             lcd_.DrawHLine(pt.x+width/2, pt.y+height/2, 1);
-            if (v_ == MAX_) lcd_.DrawHLine(xPos, yPos, width);  // should not be necessary
+            lcd_.DrawRect(xPos+1, yPos+1, width-2, height-2);
+            lcd_.DrawHLine(pt.x+width/2-1, pt.y+height/2-1, 1);
             if (ORIENT_ == Holizontal)
-                lcd_.DrawVLine(pt.x, yPos+3, SIZE_-5);
+                lcd_.DrawVLine(pt.x, yPos+4, SIZE_-7);
             else
-                lcd_.DrawHLine(xPos+3, pt.y, SIZE_-5);
+                lcd_.DrawHLine(xPos+4, pt.y, SIZE_-7);
         }
     }
 
--- a/SeekBar.hpp	Wed Apr 27 07:28:04 2016 +0000
+++ b/SeekBar.hpp	Sat Apr 30 06:33:32 2016 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  SeekBar class -- Header
 //
-//  2016/04/27, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/04/30, Copyright (c) 2016 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #ifndef F746_SEEKBAR_HPP
@@ -27,7 +27,7 @@
         SeekBar(uint16_t x, uint16_t y, uint16_t length,
                 float min, float max, float initialValue,
                 Orientation hv = Holizontal,
-                uint32_t thumbColor = LCD_COLOR_WHITE,
+                uint32_t thumbColor = 0xFFB0B0FF,
                 uint16_t thumbSize = 30, uint16_t width = 4,
                 uint32_t colorL = LCD_COLOR_LIGHTGRAY,
                 uint32_t colorH = 0xFFB0B0B0,
@@ -35,21 +35,22 @@
             : GuiBase(x, y, Font12, 0, backColor, thumbColor),
               L_(length), W_(width),
               SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH),
-              MIN_(min), MAX_(max), ORIENT_(hv),
-              labelL(NULL), labelC(NULL), labelR(NULL),
-              v_(initialValue), active_(true)
+              MIN_(min), MAX_(max), ORIENT_(hv), v_(initialValue),
+                labelOn_(false), slided_(false), active_(true)
         {   Draw(initialValue); }
 
         // Constructor with scale value (only horizontal)
         SeekBar(uint16_t x, uint16_t y, uint16_t length,
                 float min, float max, float initialValue,
                 string left, string center, string right,
-                uint32_t thumbColor = LCD_COLOR_WHITE,
+                uint32_t thumbColor = 0xFFB0B0FF,
                 uint16_t thumbSize = 30, uint16_t width = 4,
                 uint32_t colorL = LCD_COLOR_LIGHTGRAY,
                 uint32_t colorH = 0xFFB0B0B0,
                 uint32_t backColor = GuiBase::ENUM_BACK);
 
+        ~SeekBar();
+        
         bool Slide();
         float GetValue() { return v_; }
         int GetIntValue() { return Round(v_); }
@@ -75,8 +76,9 @@
         const float MIN_, MAX_;
         const Orientation ORIENT_;
 
-        Label *labelL, *labelC, *labelR;
+        Label **labelLCR;
         float v_;             // value of seekbar
+        bool labelOn_;
         bool slided_;
         bool active_;
 
@@ -89,4 +91,3 @@
     };
 }
 #endif  // F746_SEEKBAR_HPP
-
--- a/SeekbarGroup.cpp	Wed Apr 27 07:28:04 2016 +0000
+++ b/SeekbarGroup.cpp	Sat Apr 30 06:33:32 2016 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  SeekbarGroup class
 //
-//  2016/04/27, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/04/30, Copyright (c) 2016 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "SeekbarGroup.hpp"
@@ -38,7 +38,7 @@
     SeekbarGroup::~SeekbarGroup()
     {
         for (int n=0; n<numberOfSeekBar_; n++) delete seekBars_[n];
-        delete[] *seekBars_;
+        delete[] seekBars_;
     }
 
     // Get slided number
@@ -74,6 +74,7 @@
                 seekBars_[n]->SetSlided(true);
                 rtn = true;
             }
+            if (rtn) break;
         }
         return rtn;
     }
--- a/SeekbarGroup.hpp	Wed Apr 27 07:28:04 2016 +0000
+++ b/SeekbarGroup.hpp	Sat Apr 30 06:33:32 2016 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  SeekbarGroup class -- Header
 //
-//  2016/04/27, Copyright (c) 2016 MIKAMI, Naoki
+//  2016/04/30, Copyright (c) 2016 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #ifndef F746_SEEKBAR_GROUP_HPP
@@ -18,7 +18,7 @@
                      uint16_t number, uint16_t space,
                      float min, float max, float initialValue,
                      SeekBar::Orientation hv = SeekBar::Holizontal,
-                     uint32_t thumbColor = LCD_COLOR_WHITE,
+                     uint32_t thumbColor = 0xFFB0B0FF,
                      uint16_t thumbSize = 30, uint16_t width = 4,
                      uint32_t colorL = LCD_COLOR_LIGHTGRAY,
                      uint32_t colorH = 0xFFB0B0B0,