-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootapp.cpp
More file actions
93 lines (88 loc) · 3.91 KB
/
bootapp.cpp
File metadata and controls
93 lines (88 loc) · 3.91 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
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
#include "bootapp.h"
using namespace app;
using namespace cat;
// ----------------------------------------------------------------------------
BootApp::BootApp() {
}
// ----------------------------------------------------------------------------
BootApp::~BootApp() {
}
// ----------------------------------------------------------------------------
// App Lifecycle: cb_startup -> cb_resume <-> cb_pause -> cb_shutdown
// ----------------------------------------------------------------------------
// cb_startup is called upon kernel->run(app)
// ----------------------------------------------------------------------------
bool BootApp::cb_startup(Timestamp now) {
Logger::d("App", "cb_startup");
kernel()->vfs()->write("/doc/test.txt", Buffer("test"));
Buffer b;
if (kernel()->vfs()->read("/doc/test.txt", &b)) {
Logger::d("App", "read: %s", b.ptr());
}
return true;
}
// cb_resume is called when the program has resumed
// ----------------------------------------------------------------------------
void BootApp::cb_resume() {
Logger::d("App", "cb_resume");
}
// cb_pause is called when the program is going background
// ----------------------------------------------------------------------------
void BootApp::cb_pause() {
Logger::d("App", "cb_pause");
}
// cb_shutdown is called after app->exit()
// ----------------------------------------------------------------------------
void BootApp::cb_shutdown(Timestamp now) {
Logger::d("App", "cb_shutdown");
}
// ----------------------------------------------------------------------------
// OpenGL Context. Everything retained from ResourceManager is managed and
// automatically restored upon cb_context_restored()
// You only need to handle your own resources here.
// ----------------------------------------------------------------------------
// cb_context_lost is called when the GL context is lost
// you should release any manual created gfx resources here.
// resources retained by resource manager will be auto reloaded by the kernel.
// ----------------------------------------------------------------------------
void BootApp::cb_context_lost() {
Logger::d("App", "cb_context_lost");
}
// cb_context_restored is called when the GL context is restored
// you should reload any manual created gfx resources here.
// resources retained by resource manager will be auto reloaded by the kernel.
// ----------------------------------------------------------------------------
bool BootApp::cb_context_restored() {
Logger::d("App", "cb_context_restored");
return true;
}
// cb_resize is called when the screen is resized, you may adjust ui scale here
// ----------------------------------------------------------------------------
void BootApp::cb_resize(int width, int height) {
int preferredW, preferredH;
switch (kernel()->platform()) {
case Platform::Windows: preferredW = 1280; preferredH = 720; break;
case Platform::Mac: preferredW = 1280; preferredH = 720; break;
case Platform::IOS: preferredW = 512; preferredH = 960; break;
case Platform::Android: preferredW = 512; preferredH = 960; break;
default: preferredW = 512; preferredH = 960;
}
float scaleX = (float)width / preferredW;
float scaleY = (float)height / preferredH;
kernel()->ui()->scale(scaleX<scaleY ? scaleX : scaleY);
}
// cb_render is called in the render pipeline
// ----------------------------------------------------------------------------
void BootApp::cb_render(Renderer* r, Timestamp now) {
Rect2i rect;
TextStyle style;
rect.set(10, 10, 100, 40);
style.color = 0xffff00ff;
r->draw2d.drawtext(rect, "Hello", style);
}
// ----------------------------------------------------------------------------
bool BootApp::cb_timer(Timestamp now, int msg) {
Logger::d("App", "cb_timer");
return true;
}
// ----------------------------------------------------------------------------