Example: GfxBitmaps.cpp
1// This file is generated by WOWCube SDK project wizard23#include <stdint.h>4#include <string>5#include <vector>6#include <string>7#include <memory>89#include "AppManager.h"10#include "GfxBitmaps.h"1112using namespace Cubios;13using namespace Cubios::Math;14using namespace Cubios::Gfx;1516//Applicaton initialization callback. Called once when CUB application starts17void OnInit(Cubios::AppManager& appMgr)18{19 GfxBitmaps* theApp = new GfxBitmaps();2021 appMgr.SetApplication(theApp,"AAbbCCddEE");2223 theApp->InitializeResources();24}252627GfxBitmaps::GfxBitmaps():offsets{{0,0},{240,0},{240,240},{0,240}}28{29}3031GfxBitmaps::~GfxBitmaps()32{33 this->Scene.DisposeAllObjects();34}3536void GfxBitmaps::InitializeResources()37{38 //Create a Cubios::Gfx::Background object39 this->Scene.CreateObjectWithID(GfxObjects::myBackground,new Background(0,0,0));4041 //Create a Cubios::Gfx::Sprite object4243 this->scroller.Sides[0][2] = this->Scene.CreateObject(new Sprite("s1_1.webp",Transform(120,120,0)));44 this->scroller.Sides[0][3] = this->Scene.CreateObject(new Sprite("s1_2.webp",Transform(120,120,0)));45 this->scroller.Sides[0][0] = this->Scene.CreateObject(new Sprite("s1_3.webp",Transform(120,120,0)));46 this->scroller.Sides[0][1] = this->Scene.CreateObject(new Sprite("s1_4.webp",Transform(120,120,0)));4748 this->scroller.Sides[1][2] = this->Scene.CreateObject(new Sprite("s2_1.webp",Transform(120,120,0)));49 this->scroller.Sides[1][3] = this->Scene.CreateObject(new Sprite("s2_2.webp",Transform(120,120,0)));50 this->scroller.Sides[1][0] = this->Scene.CreateObject(new Sprite("s2_3.webp",Transform(120,120,0)));51 this->scroller.Sides[1][1] = this->Scene.CreateObject(new Sprite("s2_4.webp",Transform(120,120,0)));5253 this->scroller.Sides[2][2] = this->Scene.CreateObject(new Sprite("s3_1.webp",Transform(120,120,0)));54 this->scroller.Sides[2][3] = this->Scene.CreateObject(new Sprite("s3_2.webp",Transform(120,120,0)));55 this->scroller.Sides[2][0] = this->Scene.CreateObject(new Sprite("s3_3.webp",Transform(120,120,0)));56 this->scroller.Sides[2][1] = this->Scene.CreateObject(new Sprite("s3_4.webp",Transform(120,120,0)));5758 this->scroller.Sides[3][2] = this->Scene.CreateObject(new Sprite("s4_1.webp",Transform(120,120,0)));59 this->scroller.Sides[3][3] = this->Scene.CreateObject(new Sprite("s4_2.webp",Transform(120,120,0)));60 this->scroller.Sides[3][0] = this->Scene.CreateObject(new Sprite("s4_3.webp",Transform(120,120,0)));61 this->scroller.Sides[3][1] = this->Scene.CreateObject(new Sprite("s4_4.webp",Transform(120,120,0)));626364 this->Scene.CreateObjectWithID(GfxObjects::myText,new Text("WOWCUBE",120,120,12,Colors::gold));6566}6768//This callback is called every "tick" of cubeapp application loop69void GfxBitmaps::on_Tick(uint32_t currentTime, uint32_t deltaTime)70{71 if(this->Module==0)72 {73 this->scroller.Tick();7475 //Send the position to other modules76 this->networkMessage.Reset(true);77 this->networkMessage.WriteInt(this->scroller.Offset,32);78 this->SendNetworkMessage(0, &this->networkMessage);79 }80}8182//This callback is called every time device is about to render visuals. Use it for calling your rendering code.83void GfxBitmaps::on_Render(std::array<Cubios::Screen, 3>& screens)84{85 Cubios::TOPOLOGY_place_t place;86 std::vector<Sprite_t> spr;8788 for(auto it = screens.begin(); it != screens.end(); ++it)89 {90 spr.clear();9192 //Start adding objects to a screen93 it->Begin(TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,true);9495 TOPOLOGY_orientation_t dir = it->Direction();9697 if(dir!=TOPOLOGY_orientation_t::ORIENTATION_UP && dir!=TOPOLOGY_orientation_t::ORIENTATION_DOWN)98 {99 Cubios::TOPOLOGY_getPlace(this->Module, it->ID(),TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY, &place);100101 //add fullscreen sprite102 this->scroller.GetSprites(dir, place.position, &spr);103104 for(int i=0;i<spr.size();i++)105 {106 it->Add(this->Scene[this->scroller.Sides[spr[i].side][spr[i].place]])->SetPosition(spr[i].xOffset,120);107 }108 }109 else110 {111 it->Add(Scene[myBackground]);112 }113114 //Finish adding objects115 it->End();116 }117}118119//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.120void GfxBitmaps::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)121{122}123124//This callback is called on programmable timer (if any)125void GfxBitmaps::on_Timer(uint8_t timerID)126{127}128129//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed130void GfxBitmaps::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)131{132}133134//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module135void GfxBitmaps::on_Message(uint32_t type, uint8_t* pkt, u32_t size)136{137 NetworkMessage nm(pkt,size);138139 if(this->Module!=0)140 {141 this->scroller.Offset = nm.ReadInt(32);142 }143144}145146//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source147void GfxBitmaps::on_ExternalMessage(uint8_t* pkt, u32_t size)148{149}150151//Screen pat callback152void GfxBitmaps::on_Pat(uint32_t count)153{154}