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
52
53
54
61
62
67
68
73
74
75
76
81
86
87
88
89
90
91
92
93
94
/* ... */
#include <gui/graph_screen/LegendEntry.hpp>
#include <touchgfx/Color.hpp>
#include <BitmapDatabase.hpp>
LegendEntry::LegendEntry() :
onButtonPressed(this, &LegendEntry::buttonPressedHandler)
{
square.setBitmap(Bitmap(BITMAP_PIE_CHART_LEGEND_BLUE_ID));
square.setXY(0, 0);
add(square);
text.setColor(Color::getColorFrom24BitRGB(0xBE, 0xC0, 0xC4));
text.setPosition(square.getRect().right() + 6, 2, 80, 26);
add(text);
valueText.setWildcard(valueTextBuffer);
valueText.setTypedText(TypedText(T_GRAPH_LEGEND_VALUE_TEXT));
valueText.setColor(text.getColor());
valueText.setPosition(text.getRect().right() + 6, text.getY(), 50, 26);
add(valueText);
setWidth(valueText.getRect().right());
setHeight(square.getRect().bottom() + 20);
selectButton.setPosition(0, 0, getWidth(), getHeight());
selectButton.setAction(onButtonPressed);
add(selectButton);
}{ ... }
LegendEntry::~LegendEntry()
{
}{ ... }
void LegendEntry::setBitmaps(BitmapId squareNotSelectedBmp, BitmapId squareSelectedBmp)
{
squareNotSelected = squareNotSelectedBmp;
squareSelected = squareSelectedBmp;
setSelected(false);
}{ ... }
void LegendEntry::setText(TEXTS textId)
{
text.setTypedText(TypedText(textId));
text.invalidate();
}{ ... }
void LegendEntry::setValueText(int value)
{
Unicode::snprintf(valueTextBuffer, 6, "%i", value);
valueText.invalidate();
}{ ... }
void LegendEntry::setSelected(bool selected)
{
if (selected)
{
square.setBitmap(Bitmap(squareSelected));
text.setColor(Color::getColorFrom24BitRGB(0x0, 0x0, 0x0));
}if (selected) { ... }
else
{
square.setBitmap(Bitmap(squareNotSelected));
text.setColor(Color::getColorFrom24BitRGB(0xBE, 0xC0, 0xC4));
}else { ... }
valueText.setColor(text.getColor());
valueText.setVisible(selected);
square.invalidate();
text.invalidate();
valueText.invalidate();
}{ ... }
void LegendEntry::buttonPressedHandler(const AbstractButton& button)
{
if (selectionAction && selectionAction->isValid())
{
selectionAction->execute(*this);
}if (selectionAction && selectionAction->isValid()) { ... }
}{ ... }