1// This file is generated by WOWCube SDK project wizard
2
3#include <stdint.h>
4#include <string>
5#include <vector>
6#include <string>
7#include <memory>
8
9#include "AppManager.h"
10#include "GfxText.h"
11
12using namespace Cubios;
13using namespace Cubios::Math;
14using namespace Cubios::Gfx;
15
16//Applicaton initialization callback. Called once when CUB application starts
17void OnInit(Cubios::AppManager& appMgr)
18{
19 GfxText* theApp = new GfxText();
20
21 appMgr.SetApplication(theApp,"AAbbCCddEE");
22
23 theApp->InitializeResources();
24}
25
26
27GfxText::GfxText():a(0),currWord(0),words{"captivating","lovely","sensational","superb","undaunted","wonderful","fabulous","outstanding","grand","exemplary","trendy","posh","fresh","edgy","neat","groovy","awesome"}
28{
29}
30
31GfxText::~GfxText()
32{
33 this->Scene.DisposeAllObjects();
34}
35
36void GfxText::InitializeResources()
37{
38 //Create a Cubios::Gfx::Background object
39 this->Scene.CreateObjectWithID(GfxObjects::myBackground,new Background(255,0,0));
40
41 //Create a Cubios::Gfx::Text objects
42 this->Scene.CreateObjectWithID(GfxObjects::myText,new Text("WOWCUBE",120,60,9,Colors::gold));
43 this->Scene.CreateObjectWithID(GfxObjects::myText2,new Text("IS",120,120,12,Colors::gold));
44 this->Scene.CreateObjectWithID(GfxObjects::myText3,new Text(" ",120,180,9,Colors::gold));
45
46 this->SetTimer(1,250);
47}
48
49//This callback is called every "tick" of cubeapp application loop
50void GfxText::on_Tick(uint32_t currentTime, uint32_t deltaTime)
51{
52}
53
54//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
55void GfxText::on_Render(std::array<Cubios::Screen, 3>& screens)
56{
57 Background* bkg = (Background*)this->Scene[GfxObjects::myBackground];
58
59 for(auto it = screens.begin(); it != screens.end(); ++it)
60 {
61 //Start adding objects to a screen
62 it->Begin(TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,true);
63
64 //Set background colors
65 switch(it->ID())
66 {
67 case 0: it->Add(bkg->SetColor(Colors::darkRed)); break;
68 case 1: it->Add(bkg->SetColor(Colors::darkGreen)); break;
69 case 2: it->Add(bkg->SetColor(Colors::darkBlue)); break;
70 }
71
72 //Use in-place setters for changing Text content and position
73 dynamic_cast<Text*>(it->Add(this->Scene[GfxObjects::myText]))
74 ->SetPosition(120,60+50*sin(a));
75
76
77 dynamic_cast<Text*>(it->Add(this->Scene[GfxObjects::myText2]))
78 ->SetPosition(120,120+50*sin(a+0.6));
79
80 dynamic_cast<Text*>(it->Add(this->Scene[GfxObjects::myText3]))
81 ->SetContent(this->words.at(this->currWord))
82 ->SetPosition(120,180+50*sin(a+1.2))
83 ->SetColor(Cubios::random(0xFFCCCCCC,0xFFFFFFFF));
84
85 //Finish adding objects
86 it->End();
87 }
88}
89
90//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
91void GfxText::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
92{
93 this->a+=0.2;
94}
95
96//This callback is called on programmable timer (if any)
97void GfxText::on_Timer(uint8_t timerID)
98{
99 if(timerID==1)
100 {
101 this->currWord = Cubios::random(0,this->words.size()-1);
102 }
103}
104
105//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
106void GfxText::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
107{
108}
109
110//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
111void GfxText::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
112{
113}
114
115//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
116void GfxText::on_ExternalMessage(uint8_t* pkt, u32_t size)
117{
118}
119
120//Screen pat callback
121void GfxText::on_Pat(uint32_t count)
122{
123}