-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXUI_Engine.cpp
More file actions
65 lines (51 loc) · 1.57 KB
/
XUI_Engine.cpp
File metadata and controls
65 lines (51 loc) · 1.57 KB
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
#include "XUI_Engine.h"
XUI_Engine::XUI_Engine(XUI_Display* display, XUI_Screen* homeScreen){
xuiDisplay = display;
xuiHome = homeScreen;
xuiPrevScreen = homeScreen;
xuiScreen = homeScreen;
xuiScreen->init(this, xuiPrevScreen);
xuiScreen->start();
// button listeners
bttnUp = new OneButton(BTTN_UP);
bttnUp->attachClick([](void *scope) { ((XUI_Engine *) scope)->bttnUp_Click();}, this);
bttnDown = new OneButton(BTTN_DOWN);
bttnDown->attachClick([](void *scope) { ((XUI_Engine *) scope)->bttnDown_Click();}, this);
bttnLeft = new OneButton(BTTN_LEFT);
bttnLeft->attachClick([](void *scope) { ((XUI_Engine *) scope)->bttnLeft_Click();}, this);
bttnRight = new OneButton(BTTN_RIGHT);
bttnRight->attachClick([](void *scope) { ((XUI_Engine *) scope)->bttnRight_Click();}, this);
}
void XUI_Engine::run(){
//TODO Validar que se ha llamado a init ¿?
// draw current screen
xuiScreen->run();
bttnUp->tick();
bttnDown->tick();
bttnLeft->tick();
bttnRight->tick();
// fps stats
millis_time_last = millis_time;
millis_time = millis();
fps = millis_time - millis_time_last;
fps = round(1000.0/fps*1.0);
}
void XUI_Engine::nav(XUI_Screen* toScreen){
if (xuiScreen->end()){
xuiPrevScreen = xuiScreen;
xuiScreen = toScreen;
xuiScreen->start();
}
}
void XUI_Engine::bttnUp_Click(){
xuiScreen->bttn_event(BTTN_UP);
}
void XUI_Engine::bttnDown_Click(){
xuiScreen->bttn_event(BTTN_DOWN);
}
void XUI_Engine::bttnLeft_Click(){
xuiScreen->bttn_event(BTTN_LEFT);
}
void XUI_Engine::bttnRight_Click(){
xuiScreen->bttn_event(BTTN_RIGHT);
}