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:
Wed Jan 25 13:56:02 2017 +0000
Parent:
27:115219bcd9f5
Child:
29:551a5f1b52b9
Commit message:
22

Changed in this revision

Array_Matrix.lib Show annotated file Show diff for this revision Revisions of this file
ButtonGroup.cpp Show annotated file Show diff for this revision Revisions of this file
ButtonGroup.hpp Show annotated file Show diff for this revision Revisions of this file
GuiBase.hpp Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Array_Matrix.lib	Wed Jan 25 13:56:02 2017 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/MikamiUitOpen/code/Array_Matrix/#a25dba17218c
--- a/ButtonGroup.cpp	Mon Jan 16 00:23:53 2017 +0000
+++ b/ButtonGroup.cpp	Wed Jan 25 13:56:02 2017 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  ButtonGroup class
 //
-//  2016/11/09, Copyright (c) 2016 MIKAMI, Naoki
+//  2017/01/25, Copyright (c) 2017 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "ButtonGroup.hpp"
@@ -19,12 +19,11 @@
             uint32_t textColor, uint32_t backColor,
             uint32_t createdColor, uint32_t touchedColor,
             uint32_t inactiveColor, uint32_t inactiveTextColor)
-        : GuiBase(x0, y0, fonts, textColor, backColor,
-                  createdColor, touchedColor,
-                  inactiveColor, inactiveTextColor),
-          number_(number), prevNum_(touched)
+        : TEXT_COLOR_(textColor), CREATED_COLOR_(createdColor),
+          TOUCHED_COLOR_(touchedColor),
+          NUMBER_(number), prevNum_(touched)
     {
-        buttons_ = new Button *[number];
+        buttons_.SetSize(number);
         for (int n=0; n<number; n++)
         {
             div_t u1 = div(n, column);
@@ -32,21 +31,14 @@
             uint16_t y = y0 + u1.quot*(height + spaceY);
             buttons_[n] =
                 new Button(x, y, width, height, str[n], fonts,
-                           TEXT_COLOR_, BACK_COLOR_,
-                           CREATED_COLOR_, TOUCHED_COLOR_,
-                           INACTIVE_COLOR_, INACTIVE_TEXT_COLOR_);
+                           textColor, backColor,
+                           createdColor, touchedColor,
+                           inactiveColor, inactiveTextColor);
         }
         // On created, set touched color as needed
         if (touched >= 0) TouchedColor(touched);
     }
 
-    // Destructor
-    ButtonGroup::~ButtonGroup()
-    {
-        for (int n=0; n<number_; n++) delete buttons_[n];
-        delete[] buttons_;   
-    }
-
     // Draw button
     bool ButtonGroup::Draw(int num, uint32_t color, uint32_t textColor)
     {
@@ -85,9 +77,9 @@
     bool ButtonGroup::GetTouchedNumber(int &num)
     {
         bool rtn = false;
-        if (PanelTouched())
+        if (GuiBase::PanelTouched())
         {
-            for (int n=0; n<number_; n++)
+            for (int n=0; n<NUMBER_; n++)
                 if (buttons_[n]->IsOnButton() &&
                     buttons_[n]->IsActive())
                 {
@@ -139,3 +131,4 @@
         return true;
     }
 }
+
--- a/ButtonGroup.hpp	Mon Jan 16 00:23:53 2017 +0000
+++ b/ButtonGroup.hpp	Wed Jan 25 13:56:02 2017 +0000
@@ -1,17 +1,18 @@
 //-----------------------------------------------------------
 //  ButtonGroup class -- Header
 //
-//  2016/11/09, Copyright (c) 2016 MIKAMI, Naoki
+//  2017/01/25, Copyright (c) 2017 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #ifndef F746_BUTTON_GROUP_HPP
 #define F746_BUTTON_GROUP_HPP
 
 #include "Button.hpp"
+#include "Array.hpp"
 
 namespace Mikami
 {
-    class ButtonGroup : public GuiBase
+    class ButtonGroup
     {
     public:
         // Constructor
@@ -30,7 +31,8 @@
                     uint32_t inactiveTextColor = GuiBase::ENUM_INACTIVE_TEXT);
 
         // Destructor
-        virtual ~ButtonGroup();
+        virtual ~ButtonGroup()
+        {   for (int n=0; n<NUMBER_; n++) delete buttons_[n]; }
 
         // Draw button
         bool Draw(int num, uint32_t color, uint32_t textColor);
@@ -41,13 +43,13 @@
 
         // Draw all buttons
         void DrawAll(uint32_t color, uint32_t textColor)
-        {   for (int n=0; n<number_; n++) Draw(n, color, textColor); }
+        {   for (int n=0; n<NUMBER_; n++) Draw(n, color, textColor); }
         void DrawAll() { DrawAll(CREATED_COLOR_, TEXT_COLOR_); }
 
         // Erase button
         bool Erase(int num);
         void EraseAll()
-        {   for (int n=0; n<number_; n++) Erase(n); }
+        {   for (int n=0; n<NUMBER_; n++) Erase(n); }
 
         // Check touch detected for specified button
         bool Touched(int num);
@@ -66,19 +68,23 @@
         // Activate and inactivate button(s)
         bool Activate(int num);
         void ActivateAll()
-        {   for (int n=0; n<number_; n++) Activate(n); }
+        {   for (int n=0; n<NUMBER_; n++) Activate(n); }
         bool Inactivate(int num);
         void InactivateAll()
-        {   for (int n=0; n<number_; n++) Inactivate(n); }
+        {   for (int n=0; n<NUMBER_; n++) Inactivate(n); }
 
     private:
-        Button **buttons_;
-        int number_;
+        const uint32_t TEXT_COLOR_;
+        const uint32_t CREATED_COLOR_;
+        const uint32_t TOUCHED_COLOR_;
+        const int NUMBER_;
+
+        Array<Button *> buttons_;
         __IO int prevNum_;
 
         // Check range of argument
         bool Range(int n)
-        { return ((n >= 0) && (n < number_)); }
+        { return ((n >= 0) && (n < NUMBER_)); }
 
         // disallow copy constructor and assignment operator
         ButtonGroup(const ButtonGroup&);
@@ -86,3 +92,4 @@
     };
 }
 #endif  // F746_BUTTON_GROUP_HPP
+
--- a/GuiBase.hpp	Mon Jan 16 00:23:53 2017 +0000
+++ b/GuiBase.hpp	Wed Jan 25 13:56:02 2017 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  GuiBase class (abstract base class) ---- Header
 //      
-//  2016/04/10, Copyright (c) 2016 MIKAMI, Naoki
+//  2017/01/25, Copyright (c) 2017 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #ifndef F746_GUI_BASE_HPP
@@ -49,12 +49,12 @@
         // Constructor
         GuiBase(uint16_t x =0, uint16_t y =0,
                 sFONT &fonts = Font12,
-                uint32_t textColor         = GuiBase::ENUM_TEXT,
-                uint32_t backColor         = GuiBase::ENUM_BACK,
-                uint32_t createdColor      = GuiBase::ENUM_CREATED,
-                uint32_t touchedColor      = GuiBase::ENUM_TOUCHED,
-                uint32_t inactiveColor     = GuiBase::ENUM_INACTIVE,
-                uint32_t inactiveTextColor = GuiBase::ENUM_INACTIVE_TEXT);
+                uint32_t textColor         = ENUM_TEXT,
+                uint32_t backColor         = ENUM_BACK,
+                uint32_t createdColor      = ENUM_CREATED,
+                uint32_t touchedColor      = ENUM_TOUCHED,
+                uint32_t inactiveColor     = ENUM_INACTIVE,
+                uint32_t inactiveTextColor = ENUM_INACTIVE_TEXT);
 
         void DrawString(uint16_t x, uint16_t y, const string str)
         { lcd_.DisplayStringAt(x, y, (uint8_t *)str.c_str(), LEFT_MODE); }
@@ -68,3 +68,4 @@
     };
 }
 #endif  // F746_GUI_BASE_HPP
+
--- a/SeekBar.cpp	Mon Jan 16 00:23:53 2017 +0000
+++ b/SeekBar.cpp	Wed Jan 25 13:56:02 2017 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  SeekBar class
 //
-//  2016/07/12, Copyright (c) 2016 MIKAMI, Naoki
+//  2017/01/25, Copyright (c) 2017 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "SeekBar.hpp"
@@ -29,12 +29,6 @@
         labelLCR_[2] = new Label(x+length, y0, right, Label::CENTER);
     }
 
-    SeekBar::~SeekBar()
-    {
-        if (labelOn_)
-            for (int n=0; n<3; n++) delete labelLCR_[n];
-    }
-
     // Slide thumb
     //      If the thumb is not touched, return false
     bool SeekBar::Slide()
@@ -185,3 +179,4 @@
     }
 }
 
+
--- a/SeekBar.hpp	Mon Jan 16 00:23:53 2017 +0000
+++ b/SeekBar.hpp	Wed Jan 25 13:56:02 2017 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  SeekBar class -- Header
 //
-//  2016/07/12, Copyright (c) 2016 MIKAMI, Naoki
+//  2017/01/25, Copyright (c) 2017 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #ifndef F746_SEEKBAR_HPP
@@ -49,8 +49,9 @@
                 uint32_t colorH = 0xFFB0B0B0,
                 uint32_t backColor = GuiBase::ENUM_BACK);
 
-        virtual ~SeekBar();
-        
+        virtual ~SeekBar()
+        {   for (int n=0; n<3; n++) delete labelLCR_[n]; }
+
         bool Slide();
         float GetValue() { return v_; }
         int GetIntValue() { return Round(v_); }
@@ -91,3 +92,4 @@
     };
 }
 #endif  // F746_SEEKBAR_HPP
+
--- a/SeekbarGroup.cpp	Mon Jan 16 00:23:53 2017 +0000
+++ b/SeekbarGroup.cpp	Wed Jan 25 13:56:02 2017 +0000
@@ -1,7 +1,7 @@
 //-----------------------------------------------------------
 //  SeekbarGroup class
 //
-//  2016/04/30, Copyright (c) 2016 MIKAMI, Naoki
+//  2017/01/25, Copyright (c) 2017 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #include "SeekbarGroup.hpp"
@@ -13,14 +13,11 @@
             uint16_t number, uint16_t space,
             float min, float max, float initialValue,
             SeekBar::Orientation hv,
-            uint32_t thumbColor,
-            uint16_t thumbSize, uint16_t width,
-            uint32_t colorL, uint32_t colorH,
-            uint32_t backColor)
-        : GuiBase(x0, y0, Font12, GuiBase::ENUM_TEXT, backColor, thumbColor),
-          numberOfSeekBar_(number)
+            uint32_t thumbColor, uint16_t thumbSize, uint16_t width,
+            uint32_t colorL, uint32_t colorH, uint32_t backColor)
+        : NUMBER_(number)
     {
-        seekBars_ = new SeekBar *[number];
+        seekBars_.SetSize(number);
         for (int n=0; n<number; n++)
         {
             uint16_t x = x0;
@@ -34,24 +31,17 @@
         }
     }
 
-    // Destructor
-    SeekbarGroup::~SeekbarGroup()
-    {
-        for (int n=0; n<numberOfSeekBar_; n++) delete seekBars_[n];
-        delete[] seekBars_;
-    }
-
     // Get slided number
     bool SeekbarGroup::GetSlidedNumber(int &num)
     {
         bool active = false;
-        for (int n=0; n<numberOfSeekBar_; n++)
+        for (int n=0; n<NUMBER_; n++)
             if (seekBars_[n]->IsActive()) active = true;
         if (!active) return false;
 
-        if (!PanelTouched())
+        if (!GuiBase::PanelTouched())
         {
-            for (int n=0; n<numberOfSeekBar_; n++)
+            for (int n=0; n<NUMBER_; n++)
             {
                 if (seekBars_[n]->GetSlided())
                     seekBars_[n]->Draw(seekBars_[n]->GetValue());
@@ -62,7 +52,7 @@
 
         bool rtn = false;
         uint16_t x, y;
-        for (int n=0; n<numberOfSeekBar_; n++)
+        for (int n=0; n<NUMBER_; n++)
         {
             if (seekBars_[n]->IsOnThumb(x, y))
             {
@@ -79,3 +69,4 @@
         return rtn;
     }
 }
+
--- a/SeekbarGroup.hpp	Mon Jan 16 00:23:53 2017 +0000
+++ b/SeekbarGroup.hpp	Wed Jan 25 13:56:02 2017 +0000
@@ -1,17 +1,18 @@
 //-----------------------------------------------------------
 //  SeekbarGroup class -- Header
 //
-//  2016/07/12, Copyright (c) 2016 MIKAMI, Naoki
+//  2017/01/25, Copyright (c) 2017 MIKAMI, Naoki
 //-----------------------------------------------------------
 
 #ifndef F746_SEEKBAR_GROUP_HPP
 #define F746_SEEKBAR_GROUP_HPP
 
 #include "SeekBar.hpp"
+#include "Array.hpp"
 
 namespace Mikami
 {
-    class SeekbarGroup : public GuiBase
+    class SeekbarGroup
     {
     public:
         SeekbarGroup(uint16_t x0, uint16_t y0,  uint16_t length,
@@ -24,49 +25,50 @@
                      uint32_t colorH = 0xFFB0B0B0,
                      uint32_t backColor = GuiBase::ENUM_BACK);
 
-        virtual ~SeekbarGroup();
-        
+        virtual ~SeekbarGroup()
+        {   for (int n=0; n<NUMBER_; n++) delete seekBars_[n]; }
+
         bool Slide(int num) { return seekBars_[num]->Slide(); }
         float GetValue(int num) { return seekBars_[num]->GetValue(); }
         int GetIntValue(int num) { return seekBars_[num]->GetIntValue(); }
 
         // Get slided number
         bool GetSlidedNumber(int &num);
-        
+
         void Draw(int num, float value, bool fill = false)
         {   seekBars_[num]->Draw(value, fill); }
 
         // Draw all thumbs with same value
         void DrawAll(float value, bool fill = false)
-        {   for (int n=0; n<numberOfSeekBar_; n++) Draw(n, value, fill); }
+        {   for (int n=0; n<NUMBER_; n++) Draw(n, value, fill); }
 
         void Redraw(int num, bool fill = false)
         {   seekBars_[num]->Draw(seekBars_[num]->GetValue(), fill); }
 
         void RedrawAll(bool fill = false)
-        {   for (int n=0; n<numberOfSeekBar_; n++) Redraw(n, fill); }
+        {   for (int n=0; n<NUMBER_; n++) Redraw(n, fill); }
 
         // Activate and inactivate
         void Activate(int num) { seekBars_[num]->Activate(); }
         void Inactivate(int num) { seekBars_[num]->Inactivate(); }
         void ActivateAll()
-        {   
-            for (int n=0; n<numberOfSeekBar_; n++)
+        {
+            for (int n=0; n<NUMBER_; n++)
                 seekBars_[n]->Activate();
         }
         void InactivateAll()
         {
-            for (int n=0; n<numberOfSeekBar_; n++)
+            for (int n=0; n<NUMBER_; n++)
                 seekBars_[n]->Inactivate();
         }
 
     private:
-        SeekBar **seekBars_;
-        int numberOfSeekBar_;
+        const int NUMBER_;
+        Array<SeekBar *> seekBars_;
 
         // Check range of argument
         bool Range(int n)
-        { return ((n >= 0) && (n < numberOfSeekBar_)); }
+        { return ((n >= 0) && (n < NUMBER_)); }
 
         // disallow copy constructor and assignment operator
         SeekbarGroup(const SeekbarGroup&);
@@ -74,3 +76,4 @@
     };
 }
 #endif  //  F746_SEEKBAR_GROUP_HPP
+