Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Array_Matrix BSP_DISCO_F746NG LCD_DISCO_F746NG TS_DISCO_F746NG
Fork of F746_GUI by
Revision 9:c379410bda15, committed 2016-04-24
- Comitter:
- MikamiUitOpen
- Date:
- Sun Apr 24 11:49:42 2016 +0000
- Parent:
- 8:8c5107c91d02
- Child:
- 10:5a2068884fd9
- Commit message:
- 10
Changed in this revision
--- a/Label.cpp Thu Apr 21 01:12:59 2016 +0000
+++ b/Label.cpp Sun Apr 24 11:49:42 2016 +0000
@@ -1,7 +1,7 @@
//-----------------------------------------------------------
// Label class
//
-// 2016/04/07, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki
//-----------------------------------------------------------
#include "Label.hpp"
@@ -35,4 +35,16 @@
lcd_.SetTextColor(textColor);
DrawString(PosX(X_), Y_, str);
}
+
+ uint16_t Label::PosX(uint16_t x)
+ {
+ if (MODE_ == LEFT) return x;
+ else
+ {
+ if (MODE_ == CENTER)
+ return x - length_*FONTS_->Width/2;
+ else
+ return x - length_*FONTS_->Width;
+ }
+ }
}
--- a/Label.hpp Thu Apr 21 01:12:59 2016 +0000
+++ b/Label.hpp Sun Apr 24 11:49:42 2016 +0000
@@ -1,7 +1,7 @@
//-----------------------------------------------------------
// Label class -- Header
//
-// 2016/04/07, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki
//-----------------------------------------------------------
#ifndef F746_LABEL_HPP
@@ -14,7 +14,7 @@
class Label : public GuiBase
{
public:
- enum TextAlignMode { LEFT, CENTER };
+ enum TextAlignMode { LEFT, CENTER, RIGHT };
// Constructor
Label(uint16_t x, uint16_t y, const string str,
TextAlignMode mode = LEFT,
@@ -48,11 +48,8 @@
const string STR_;
uint8_t length_;
-
- uint16_t PosX(uint16_t x)
- { return (MODE_ == LEFT) ?
- x : x - length_*FONTS_->Width/2; }
-
+ uint16_t PosX(uint16_t x);
+
// disallow copy constructor and assignment operator
Label(const Label&);
Label& operator=(const Label&);
--- a/SeekBar.cpp Thu Apr 21 01:12:59 2016 +0000
+++ b/SeekBar.cpp Sun Apr 24 11:49:42 2016 +0000
@@ -1,7 +1,7 @@
//-----------------------------------------------------------
// SeekBar class
//
-// 2016/04/12, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki
//-----------------------------------------------------------
#include "SeekBar.hpp"
@@ -20,7 +20,7 @@
L_(length), W_(width),
SIZE_(thumbSize), COLOR_L_(colorL), COLOR_H_(colorH),
MIN_(min), MAX_(max), ORIENT_(Holizontal),
- v_(initialValue), active_(true)
+ v_(initialValue), slided_(false), active_(true)
{
Draw(initialValue);
labelL = new Label(x, y-28, left, Label::CENTER);
@@ -77,6 +77,27 @@
}
}
+ // If touched position is on the thumb, return true
+ bool SeekBar::IsOnThumb(uint16_t &x, uint16_t &y)
+ {
+ x = state_.touchX[0];
+ y = state_.touchY[0];
+
+ 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;
+ }
+ else
+ {
+ if ( (pt.x-SIZE_ <= x) && (x <= pt.x+SIZE_) &&
+ (pt.y-SIZE_/5 <= y) && (y <= pt.y+SIZE_/5) ) return true;
+ }
+
+ return false;
+ }
+
// Draw seekbar
void SeekBar::Draw(float value, bool fill)
{
@@ -87,7 +108,8 @@
else
lcd_.FillRect(X_-SIZE_/2, Y_-SIZE_/2, SIZE_+1, L_+SIZE_+1);
- Point pt = ToPoint(Saturate(value)); // Position of thumb
+ v_ = Saturate(value); // current value
+ Point pt = ToPoint(v_); // Position of thumb
// Draw upper line
if (active_) lcd_.SetTextColor(COLOR_H_);
@@ -114,27 +136,6 @@
lcd_.DrawCircle(pt.x, pt.y, SIZE_/2);
}
- // If touched position is on the button, return true
- bool SeekBar::IsOnThumb(uint16_t &x, uint16_t &y)
- {
- x = state_.touchX[0];
- y = state_.touchY[0];
-
- 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;
- }
- else
- {
- if ( (pt.x-SIZE_ <= x) && (x <= pt.x+SIZE_) &&
- (pt.y-SIZE_/5 <= y) && (y <= pt.y+SIZE_/5) ) return true;
- }
-
- return false;
- }
-
SeekBar::Point SeekBar::ToPoint(float value)
{
if (ORIENT_ == Holizontal)
--- a/SeekBar.hpp Thu Apr 21 01:12:59 2016 +0000
+++ b/SeekBar.hpp Sun Apr 24 11:49:42 2016 +0000
@@ -1,7 +1,7 @@
//-----------------------------------------------------------
// SeekBar class -- Header
//
-// 2016/04/12, Copyright (c) 2016 MIKAMI, Naoki
+// 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki
//-----------------------------------------------------------
#ifndef F746_SEEKBAR_HPP
@@ -17,6 +17,12 @@
public:
enum Orientation { Holizontal, Vertical };
+ struct Point
+ {
+ uint16_t x, y;
+ Point(uint16_t x0 = 0, uint16_t y0 = 0) : x(x0), y(y0) {}
+ };
+
// Constructor
SeekBar(uint16_t x, uint16_t y, uint16_t length,
float min, float max, float initialValue,
@@ -47,16 +53,22 @@
bool Slide();
float GetValue() { return v_; }
int GetIntValue() { return Round(v_); }
+
void Activate();
void Inactivate();
+ bool IsActive() { return active_; }
+
+ bool IsOnThumb(uint16_t &x, uint16_t &y);
+ void Draw(float value, bool fill = false);
+ float ToValue(Point pt);
+
+ void SetValue(float v) { v_ = v; }
+ void SetSlided(bool tf) { slided_ = tf; }
+ bool GetSlided() { return slided_; }
+
+ int Round(float x) { return x + 0.5f - (x < 0); } // Round up on 5
private:
- struct Point
- {
- uint16_t x, y;
- Point(uint16_t x0 = 0, uint16_t y0 = 0) : x(x0), y(y0) {}
- };
-
const uint16_t L_, W_;
const uint16_t SIZE_; // Size of thumb
const uint32_t COLOR_L_, COLOR_H_;
@@ -68,11 +80,7 @@
bool slided_;
bool active_;
- void Draw(float value, bool fill = false);
- bool IsOnThumb(uint16_t &x, uint16_t &y);
Point ToPoint(float value);
- float ToValue(Point pt);
- int Round(float x) { return x + 0.5f - (x < 0); } // Round up on 5
float Saturate(float value);
// disallow copy constructor and assignment operator
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SeekBarGroup.cpp Sun Apr 24 11:49:42 2016 +0000
@@ -0,0 +1,78 @@
+//-----------------------------------------------------------
+// SeekBarGroup class
+//
+// 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki
+//-----------------------------------------------------------
+
+#include "SeekBarGroup.hpp"
+
+namespace Mikami
+{
+ SeekbarGroup::SeekbarGroup(
+ uint16_t x0, uint16_t y0, uint16_t length,
+ 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)
+ {
+ seekBars_ = new SeekBar *[number];
+ for (int n=0; n<number; n++)
+ {
+ uint16_t x = x0;
+ uint16_t y = y0;
+ if (hv == SeekBar::Holizontal) y += space*n;
+ else x += space*n;
+ seekBars_[n] =
+ new SeekBar(x, y, length, min, max, initialValue, hv,
+ thumbColor, thumbSize, width,
+ colorL, colorH, backColor);
+ }
+ }
+
+ // 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++)
+ if (seekBars_[n]->IsActive()) active = true;
+ if (!active) return false;
+
+ if (!PanelTouched())
+ {
+ for (int n=0; n<numberOfSeekBar_; n++)
+ {
+ if (seekBars_[n]->GetSlided())
+ seekBars_[n]->Draw(seekBars_[n]->GetValue());
+ seekBars_[n]->SetSlided(false);
+ }
+ return false;
+ }
+
+ bool rtn = false;
+ uint16_t x, y;
+ for (int n=0; n<numberOfSeekBar_; n++)
+ {
+ if (seekBars_[n]->IsOnThumb(x, y))
+ {
+ num = n;
+ seekBars_[n]->SetValue(seekBars_[n]->ToValue(SeekBar::Point(x, y)));
+ seekBars_[n]->Draw(seekBars_[n]->GetValue(), true);
+ seekBars_[n]->SetSlided(true);
+ rtn = true;
+ }
+ }
+ return rtn;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SeekBarGroup.hpp Sun Apr 24 11:49:42 2016 +0000
@@ -0,0 +1,67 @@
+//-----------------------------------------------------------
+// SeekBarGroup class -- Header
+//
+// 2016/04/24, Copyright (c) 2016 MIKAMI, Naoki
+//-----------------------------------------------------------
+
+#ifndef F746_SEEKBAR_GROUP_HPP
+#define F746_SEEKBAR_GROUP_HPP
+
+#include "SeekBar.hpp"
+
+namespace Mikami
+{
+ class SeekbarGroup : public GuiBase
+ {
+ public:
+ SeekbarGroup(uint16_t x0, uint16_t y0, uint16_t length,
+ uint16_t number, uint16_t space,
+ float min, float max, float initialValue,
+ SeekBar::Orientation hv = SeekBar::Holizontal,
+ uint32_t thumbColor = LCD_COLOR_WHITE,
+ uint16_t thumbSize = 30, uint16_t width = 4,
+ uint32_t colorL = LCD_COLOR_LIGHTGRAY,
+ uint32_t colorH = 0xFFB0B0B0,
+ uint32_t backColor = GuiBase::ENUM_BACK);
+
+ ~SeekbarGroup();
+
+ bool Slide(int num) { return seekBars_[num]->Slide(); }
+ float GetValue(int num) { return seekBars_[num]->GetValue(); }
+ int GetIntValue(int num) { return seekBars_[num]->Round(seekBars_[num]->GetIntValue()); }
+
+ // Get slided number
+ bool GetSlidedNumber(int &num);
+
+ void Draw(int num, float value, bool fill = false)
+ { seekBars_[num]->Draw(value, 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++)
+ seekBars_[n]->Activate();
+ }
+ void InactivateAll()
+ {
+ for (int n=0; n<numberOfSeekBar_; n++)
+ seekBars_[n]->Inactivate();
+ }
+
+ private:
+ SeekBar **seekBars_;
+ int numberOfSeekBar_;
+
+ // Check range of argument
+ bool Range(int n)
+ { return ((n >= 0) && (n < numberOfSeekBar_)); }
+
+ // disallow copy constructor and assignment operator
+ SeekbarGroup(const SeekbarGroup&);
+ SeekbarGroup& operator=(const SeekbarGroup&);
+ };
+}
+#endif // F746_SEEKBAR_GROUP_HPP
