Same as original

Committer:
MikamiUitOpen
Date:
Fri Dec 11 14:23:01 2015 +0000
Revision:
7:6913aebb3905
Parent:
6:d268555e2f50
Child:
8:479ed9f0ba20
8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MikamiUitOpen 0:d3038879fed6 1 //-----------------------------------------------------------
MikamiUitOpen 5:2cc388e91bde 2 // Button group class
MikamiUitOpen 0:d3038879fed6 3 //
MikamiUitOpen 7:6913aebb3905 4 // 2015/12/11, Copyright (c) 2015 MIKAMI, Naoki
MikamiUitOpen 0:d3038879fed6 5 //-----------------------------------------------------------
MikamiUitOpen 0:d3038879fed6 6
MikamiUitOpen 0:d3038879fed6 7 #include "button_group.hpp"
MikamiUitOpen 0:d3038879fed6 8
MikamiUitOpen 0:d3038879fed6 9 namespace Mikami
MikamiUitOpen 0:d3038879fed6 10 {
MikamiUitOpen 0:d3038879fed6 11 // Constructor
MikamiUitOpen 0:d3038879fed6 12 ButtonGroup::ButtonGroup(LCD_DISCO_F746NG &lcd, TS_DISCO_F746NG &ts,
MikamiUitOpen 0:d3038879fed6 13 uint16_t x0, uint16_t y0,
MikamiUitOpen 0:d3038879fed6 14 uint16_t width, uint16_t height,
MikamiUitOpen 0:d3038879fed6 15 uint32_t color, uint32_t backColor,
MikamiUitOpen 3:d99d9c0324b7 16 uint16_t number, const string str[],
MikamiUitOpen 0:d3038879fed6 17 uint16_t spaceX, uint16_t spaceY,
MikamiUitOpen 0:d3038879fed6 18 uint16_t column,
MikamiUitOpen 0:d3038879fed6 19 sFONT &fonts, uint32_t textColor)
MikamiUitOpen 0:d3038879fed6 20 : numberOfButtons_(number)
MikamiUitOpen 0:d3038879fed6 21 {
MikamiUitOpen 0:d3038879fed6 22 buttons_ = new Button *[number];
MikamiUitOpen 0:d3038879fed6 23 for (int n=0; n<number; n++)
MikamiUitOpen 0:d3038879fed6 24 {
MikamiUitOpen 0:d3038879fed6 25 div_t u1 = div(n, column);
MikamiUitOpen 0:d3038879fed6 26 uint16_t x = x0 + u1.rem*(width + spaceX);
MikamiUitOpen 0:d3038879fed6 27 uint16_t y = y0 + u1.quot*(height + spaceY);
MikamiUitOpen 0:d3038879fed6 28 buttons_[n] = new Button(lcd, ts, x, y, width, height,
MikamiUitOpen 0:d3038879fed6 29 color, backColor,
MikamiUitOpen 0:d3038879fed6 30 str[n], fonts, textColor);
MikamiUitOpen 0:d3038879fed6 31 }
MikamiUitOpen 0:d3038879fed6 32 }
MikamiUitOpen 0:d3038879fed6 33
MikamiUitOpen 0:d3038879fed6 34 // Destructor
MikamiUitOpen 0:d3038879fed6 35 ButtonGroup::~ButtonGroup()
MikamiUitOpen 0:d3038879fed6 36 {
MikamiUitOpen 0:d3038879fed6 37 for (int n=0; n<numberOfButtons_; n++) delete buttons_[n];
MikamiUitOpen 0:d3038879fed6 38 delete[] *buttons_;
MikamiUitOpen 0:d3038879fed6 39 }
MikamiUitOpen 0:d3038879fed6 40
MikamiUitOpen 6:d268555e2f50 41 // Check touch detected for specified button and redraw
MikamiUitOpen 6:d268555e2f50 42 bool ButtonGroup::Touched(int num, uint32_t color,
MikamiUitOpen 6:d268555e2f50 43 uint32_t textColor)
MikamiUitOpen 6:d268555e2f50 44 {
MikamiUitOpen 6:d268555e2f50 45 if (buttons_[num]->Touched(color, textColor))
MikamiUitOpen 6:d268555e2f50 46 {
MikamiUitOpen 6:d268555e2f50 47 for (int n=0; n<numberOfButtons_; n++)
MikamiUitOpen 6:d268555e2f50 48 if (n != num) buttons_[n]->Redraw();
MikamiUitOpen 6:d268555e2f50 49 return true;
MikamiUitOpen 6:d268555e2f50 50 }
MikamiUitOpen 6:d268555e2f50 51 else
MikamiUitOpen 6:d268555e2f50 52 return false;
MikamiUitOpen 6:d268555e2f50 53 }
MikamiUitOpen 6:d268555e2f50 54
MikamiUitOpen 7:6913aebb3905 55 // Get touched number
MikamiUitOpen 7:6913aebb3905 56 bool ButtonGroup::GetTouchedNumber(int &num)
MikamiUitOpen 7:6913aebb3905 57 {
MikamiUitOpen 7:6913aebb3905 58 for (int n=0; n<numberOfButtons_; n++)
MikamiUitOpen 7:6913aebb3905 59 if (buttons_[n]->Touched())
MikamiUitOpen 7:6913aebb3905 60 {
MikamiUitOpen 7:6913aebb3905 61 num = n;
MikamiUitOpen 7:6913aebb3905 62 return true;
MikamiUitOpen 7:6913aebb3905 63 }
MikamiUitOpen 7:6913aebb3905 64 return false;
MikamiUitOpen 7:6913aebb3905 65 }
MikamiUitOpen 7:6913aebb3905 66
MikamiUitOpen 0:d3038879fed6 67 // Get touched number and redraw button if touched
MikamiUitOpen 1:57fe493e8db2 68 bool ButtonGroup::GetTouchedNumber(int &num, uint32_t color)
MikamiUitOpen 0:d3038879fed6 69 {
MikamiUitOpen 0:d3038879fed6 70 if (GetTouchedNumber(num))
MikamiUitOpen 0:d3038879fed6 71 {
MikamiUitOpen 0:d3038879fed6 72 for (int n=0; n<numberOfButtons_; n++)
MikamiUitOpen 0:d3038879fed6 73 if (n == num)
MikamiUitOpen 1:57fe493e8db2 74 buttons_[n]->Draw(color);
MikamiUitOpen 0:d3038879fed6 75 else
MikamiUitOpen 6:d268555e2f50 76 buttons_[n]->Redraw();
MikamiUitOpen 0:d3038879fed6 77 return true;
MikamiUitOpen 0:d3038879fed6 78 }
MikamiUitOpen 0:d3038879fed6 79 else
MikamiUitOpen 0:d3038879fed6 80 return false;
MikamiUitOpen 0:d3038879fed6 81 }
MikamiUitOpen 0:d3038879fed6 82 }