-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPJPRadioGroup.cpp
120 lines (101 loc) · 2.41 KB
/
PJPRadioGroup.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//
// PJPTchPage.cpp
// PJPMidiTouch
//
// Created by Peter on 09-05-18.
// Copyright © 2018 PJP. All rights reserved.
//
#include "PJPRadioGroup.h"
#include <cmath>
namespace PJPTch
{
//constructors
PJPRadioGroup::PJPRadioGroup(Adafruit_ILI9341& tft):TchObject(tft,TS_Point(0,0,1),TSize(1,1)),count_(0)
{
}
//getters & setters
uint16_t PJPRadioGroup::Value()const
{
return TchButtons_[selectedItem_].Value();
}
uint16_t PJPRadioGroup::Value(uint16_t val)
{
TchButtons_[selectedItem_],Value(val);
TchButtons_[selectedItem_].Draw();
return TchButtons_[selectedItem_].Value();
}
//operators
//functions
void PJPRadioGroup::Add(PJPTchButton& obj)
{
TchButtons_.push_back(obj);
if(TchButtons_.size==1) boundary_.operator=(obj.boundary_);
//TchButtons_.push_back(obj);
SetBoundaries();
}
void PJPRadioGroup::Draw()
{
TchButtons_[selectedItem_].On(true);
for(uint16_t i=0;i<TchButtons_.size;i++)
{
TchButtons_[i].Draw();
}
}
bool PJPRadioGroup::Inside(TPoint p)const
{
boolean inside=false;
for(uint16_t i=0;i<TchButtons_.size;i++)
{
if(TchButtons_[i].Inside(p))
inside=true;
}
return inside;
}
void PJPRadioGroup::SetActive(uint16_t index)
{
if(index<TchButtons_.size)
{
TchButtons_[selectedItem_].On(false);
TchButtons_[selectedItem_].Draw();
selectedItem_=index;
TchButtons_[selectedItem_].On(true);
TchButtons_[selectedItem_].Draw();
}
}
void PJPRadioGroup::SetItemName(uint16_t index,char oname[16])
{
if(index<TchButtons_.size)
{
TchButtons_[index].Name(oname);
}
}
boolean PJPRadioGroup::Touched(TS_Point p)
{
if(selectedItem_>-1)
{
int16_t item=-1;;
for(uint16_t i=0;i<TchButtons_.size;i++)
{
if(TchButtons_[i].Inside(p))
{
item=i;
SetActive(i);
break;
}
}
return (item > -1);
}
return false;
}
//protected functions
void PJPRadioGroup::SetBoundaries()
{
for(uint16_t i=0;i<TchButtons_.size;i++)
{
boundary_.UL.x=fmin(TchButtons_[i].boundary_.UL.x,boundary_.UL.x);
boundary_.UL.y=fmin(TchButtons_[i].boundary_.UL.y,boundary_.UL.y);
boundary_.LR.x=fmax(TchButtons_[i].boundary_.LR.x,boundary_.LR.x);
boundary_.LR.y=fmax(TchButtons_[i].boundary_.LR.y,boundary_.LR.y);
}
}
}