R G / Interfacage

Dependencies:   Array_Matrix TS_DISCO_F746NG LCD_DISCO_F746NG BSP_DISCO_F746NG

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ButtonGroup.hpp Source File

ButtonGroup.hpp

00001 //-----------------------------------------------------------
00002 //  ButtonGroup class -- Header
00003 //
00004 //  2017/01/25, Copyright (c) 2017 MIKAMI, Naoki
00005 //-----------------------------------------------------------
00006 
00007 #ifndef F746_BUTTON_GROUP_HPP
00008 #define F746_BUTTON_GROUP_HPP
00009 
00010 #include "Button.hpp"
00011 #include "Array.hpp"
00012 
00013 namespace Mikami
00014 {
00015     class ButtonGroup
00016     {
00017     public:
00018         // Constructor
00019         ButtonGroup(uint16_t x0, uint16_t y0,
00020                     uint16_t width, uint16_t height,
00021                     uint16_t number, const string str[],
00022                     uint16_t spaceX = 0, uint16_t spaceY = 0,
00023                     uint16_t column = 1,
00024                     int touched = -1,   // number for button initially touched-color
00025                     sFONT &fonts = Font12,
00026                     uint32_t textColor         = GuiBase::ENUM_TEXT,
00027                     uint32_t backColor         = GuiBase::ENUM_BACK,
00028                     uint32_t createdColor      = GuiBase::ENUM_CREATED,
00029                     uint32_t touchedColor      = GuiBase::ENUM_TOUCHED,
00030                     uint32_t inactiveColor     = GuiBase::ENUM_INACTIVE,
00031                     uint32_t inactiveTextColor = GuiBase::ENUM_INACTIVE_TEXT);
00032 
00033         // Destructor
00034         virtual ~ButtonGroup()
00035         {   for (int n=0; n<NUMBER_; n++) delete buttons_[n]; }
00036 
00037         // Draw button
00038         bool Draw(int num, uint32_t color, uint32_t textColor);
00039         bool Draw(int num) { return Draw(num, CREATED_COLOR_, TEXT_COLOR_); }
00040 
00041         // Change to touched color
00042         bool TouchedColor(int num);
00043 
00044         // Draw all buttons
00045         void DrawAll(uint32_t color, uint32_t textColor)
00046         {   for (int n=0; n<NUMBER_; n++) Draw(n, color, textColor); }
00047         void DrawAll() { DrawAll(CREATED_COLOR_, TEXT_COLOR_); }
00048 
00049         // Erase button
00050         bool Erase(int num);
00051         void EraseAll()
00052         {   for (int n=0; n<NUMBER_; n++) Erase(n); }
00053 
00054         // Check touch detected for specified button
00055         bool Touched(int num);
00056 
00057         // Get touched number, return value: true or false
00058         bool GetTouchedNumber(int &num);
00059         // Get touched number, return value: touched number
00060         int GetTouchedNumber();
00061 
00062         // Wait until touched
00063         void WaitTouched(int num)
00064         {   while (!Touched(num)) {} }
00065         // Wait until touched and get touched number
00066         int WaitTouchedAndGet();
00067 
00068         // Activate and inactivate button(s)
00069         bool Activate(int num);
00070         void ActivateAll()
00071         {   for (int n=0; n<NUMBER_; n++) Activate(n); }
00072         bool Inactivate(int num);
00073         void InactivateAll()
00074         {   for (int n=0; n<NUMBER_; n++) Inactivate(n); }
00075 
00076     private:
00077         const uint32_t TEXT_COLOR_;
00078         const uint32_t CREATED_COLOR_;
00079         const uint32_t TOUCHED_COLOR_;
00080         const int NUMBER_;
00081 
00082         Array<Button *> buttons_;
00083         __IO int prevNum_;
00084 
00085         // Check range of argument
00086         bool Range(int n)
00087         { return ((n >= 0) && (n < NUMBER_)); }
00088 
00089         // disallow copy constructor and assignment operator
00090         ButtonGroup(const ButtonGroup&);
00091         ButtonGroup& operator=(const ButtonGroup&);
00092     };
00093 }
00094 #endif  // F746_BUTTON_GROUP_HPP
00095