-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppsMenu.h
124 lines (97 loc) · 3.28 KB
/
AppsMenu.h
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
121
122
123
// AppsMenu.h
#ifndef _APPSMENU_h
#define _APPSMENU_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#include "LinkedList.h"
#include "Layout.h"
#include "Widget.h"
#include "SettingsManager.h"
#include "Animation.h"
#include "UserInterface.h"
#include "StaticResources.h"
#include "BuiltInApplication.h"
#include "SettingsScreen.h"
class AppsMenu :public CustomScreen {
protected:
int delay = 80;
int maxOffset = 10;
int step = 1;
public:
int offset = 15;
int currentIndex = 0;
int spacing = 3;
int lineHeight = 10;
LinkedList<int*>* offsets = new LinkedList<int*>();
UserInterfaceClass* UI;
SettingsManager* settingsManager;
AppsMenu(UserInterfaceClass* UI, SettingsManager* settingsManager) {
this->UI = UI;
this->settingsManager = settingsManager;
this->offsets->add(new int(maxOffset));
}
virtual int CalculateHeight(Renderer& renderer) override {
return renderer.GetScreenHeight();
}
virtual int CalculateWidth(Renderer& renderer) override {
return renderer.GetScreenWidth();
}
virtual void Up(Renderer& renderer) override {
if (*offsets->get(currentIndex) != 0) {
auto a = new Animation(*offsets->get(currentIndex), 0, delay, -step);
UI->RegisterAnimation(a);
}
currentIndex--;
if (currentIndex < 0) currentIndex = settingsManager->appsManager->builtInApps->size() - 1;
auto a2 = new Animation(*offsets->get(currentIndex), maxOffset, delay, step);
UI->RegisterAnimation(a2);
}
virtual void Back(Renderer& r) override {
UI->SetLayoutInFocues(*UI->GetMainLayout());
}
virtual void Down(Renderer& renderer) override {
if (*offsets->get(currentIndex) != 0) {
auto a = new Animation(*offsets->get(currentIndex), 0, delay, -step);
UI->RegisterAnimation(a);
}
currentIndex++;
if (currentIndex >= settingsManager->appsManager->builtInApps->size()) currentIndex = 0;
auto a2 = new Animation(*offsets->get(currentIndex), maxOffset, delay, step);
UI->RegisterAnimation(a2);
}
virtual void Ok(Renderer& renderer) override {
settingsManager->appsManager->builtInApps->get(currentIndex)->getApplication()->Open();
}
virtual void Draw(Renderer& renderer) override {
while (offsets->size()< settingsManager->appsManager->builtInApps->size())
this->offsets->add(new int(0));
int y = offset;
int x = 0;
Serial.println(settingsManager->appsManager->builtInApps->size());
for (int i = 0; i < settingsManager->appsManager->builtInApps->size(); i++) {
Serial.println(settingsManager->appsManager->builtInApps->get(i)->name);
if (currentIndex != i) {
renderer.DrawString(x + GlobalX + *offsets->get(i), GlobalY + y,settingsManager->appsManager->builtInApps->get(i)->name);
}
else {
renderer.DrawString(x + GlobalX + *offsets->get(i)- 10, GlobalY + y, ">");
renderer.DrawString(x + GlobalX + *offsets->get(i), GlobalY + y, settingsManager->appsManager->builtInApps->get(i)->name);
}
y = y + lineHeight + spacing;
if (y > renderer.GetScreenHeight()) {
y = offset;
x = x + renderer.GetScreenWidth() / 2;
}
}
}
virtual void CalculateLayout(Renderer& renderer) override {
CalculateSizesPostOrderTreeWalk(renderer);
ApplyGlobalCoordinatesPreorderTreeWalk(this, renderer);
}
virtual void OnGetInFocus(Renderer& r) override {
}
};
#endif