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.
Dependents: F746_SpectralAnalysis_NoPhoto F746_Fourier_series_of_square_wave_01 F746_ButtonGroup_Demo F746_Mandelbrot ... more
button_group.cpp
- Committer:
- MikamiUitOpen
- Date:
- 2015-12-05
- Revision:
- 4:543ec60c2814
- Parent:
- 3:d99d9c0324b7
- Child:
- 5:2cc388e91bde
File content as of revision 4:543ec60c2814:
//-----------------------------------------------------------
// Button group class -- Header
//
// 2015/12/05, Copyright (c) 2015 MIKAMI, Naoki
//-----------------------------------------------------------
#include "button_group.hpp"
namespace Mikami
{
// Constructor
ButtonGroup::ButtonGroup(LCD_DISCO_F746NG &lcd, TS_DISCO_F746NG &ts,
uint16_t x0, uint16_t y0,
uint16_t width, uint16_t height,
uint32_t color, uint32_t backColor,
uint16_t number, const string str[],
uint16_t spaceX, uint16_t spaceY,
uint16_t column,
sFONT &fonts, uint32_t textColor)
: numberOfButtons_(number)
{
buttons_ = new Button *[number];
for (int n=0; n<number; n++)
{
div_t u1 = div(n, column);
uint16_t x = x0 + u1.rem*(width + spaceX);
uint16_t y = y0 + u1.quot*(height + spaceY);
buttons_[n] = new Button(lcd, ts, x, y, width, height,
color, backColor,
str[n], fonts, textColor);
}
}
// Destructor
ButtonGroup::~ButtonGroup()
{
for (int n=0; n<numberOfButtons_; n++) delete buttons_[n];
delete[] *buttons_;
}
// Get touched number
bool ButtonGroup::GetTouchedNumber(int &num)
{
for (int n=0; n<numberOfButtons_; n++)
if (buttons_[n]->Touched())
{
num = n;
return true;
}
return false;
}
// Get touched number and redraw button if touched
bool ButtonGroup::GetTouchedNumber(int &num, uint32_t color)
{
if (GetTouchedNumber(num))
{
for (int n=0; n<numberOfButtons_; n++)
if (n == num)
buttons_[n]->Draw(color);
else
buttons_[n]->Draw(buttons_[n]->GetOriginalColor());
return true;
}
else
return false;
}
}