Screen.cpp
Screen.cpp
CPP1/* Copyright Statement:2 *3 * (C) 2021-2024 Cubios Inc. All rights reserved.4 */56#include "Screen.h"7#include "native.h"89namespace Cubios {1011Screen::Screen(uint8_t id)12: displayId(id),13 orientationMode(ORIENTATION_MODE_MENU),14 inBegin(false),15 enableAR(false)16{17 SetOrientation(orientationMode);18}1920void Screen::SetOrientation(TOPOLOGY_orientation_mode_t mode)21{22 orientationMode = mode;23 angle = TOPOLOGY_getAngle(cubeN, displayId, orientationMode);24 TOPOLOGY_getPlace(cubeN, displayId, orientationMode, &place);25}2627uint8_t Screen::Position() const28{29 return place.position;30}3132TOPOLOGY_orientation_t Screen::Direction() const33{34 TOPOLOGY_orientation_t result = (TOPOLOGY_orientation_t)TOPOLOGY_getFaceletOrientation(cubeN, displayId);35 return result;36}3738uint8_t Screen::OppositeFace() const39{40 TOPOLOGY_orientation_t orientation = this->Direction();41 uint8_t result = 0;42 if (orientation == ORIENTATION_UP){43 result = TOPOLOGY_getFace(ORIENTATION_DOWN);44 } else if (orientation == ORIENTATION_DOWN) {45 result = TOPOLOGY_getFace(ORIENTATION_UP);46 } else if (orientation == ORIENTATION_FRONT) {47 result = TOPOLOGY_getFace(ORIENTATION_BACK);48 } else if (orientation == ORIENTATION_BACK) {49 result = TOPOLOGY_getFace(ORIENTATION_FRONT);50 } else if (orientation == ORIENTATION_LEFT) {51 result = TOPOLOGY_getFace(ORIENTATION_RIGHT);52 } else if (orientation == ORIENTATION_RIGHT) {53 result = TOPOLOGY_getFace(ORIENTATION_LEFT);54 }55 return result;56}5758uint8_t Screen::Face() const59{60 return place.face;61}6263SceneObject* Screen::Add(SceneObject* obj)64{65 if(!this->inBegin)66 {67 LOG_w("Screen:Scene objects can only be added withing Begin/End block!\n");68 obj->Parent = nullptr;69 return obj;70 }71 if(!obj->Visible) return obj;7273 obj->Parent = this;74 obj->InBegin = this->inBegin;7576 if(this->enableAR) obj->ScreenAngle = angle; else obj->ScreenAngle = 0;7778 this->objects.push_back(obj);7980 return obj;81}8283SceneObject* Screen::AddCopy(SceneObject* obj)84{85 SceneObject* object = this->Add(obj);8687 if(object!=nullptr)88 {89 this->copies.push_back(object);90 }9192 return object;93}9495void Screen::Begin(TOPOLOGY_orientation_mode_t mode, bool autorotation)96{97 this->inBegin = true;98 this->enableAR = autorotation;99100 this->orientationMode = mode;101102 angle = TOPOLOGY_getAngle(cubeN, displayId, orientationMode);103 TOPOLOGY_getPlace(cubeN, displayId, orientationMode, &place);104105 this->objects.clear();106}107108void Screen::End()109{110 this->inBegin = false;111 this->present();112113 for(size_t i=0;i<this->copies.size();i++)114 {115 delete this->copies[i];116 }117 this->copies.clear();118}119120void Screen::present()121{122 if (objects.empty()) return;123124 GFX_setRenderTarget(displayId);125 for(auto obj: objects)126 {127 obj->Render();128 obj->InBegin = this->inBegin;129 }130 GFX_render();131}132133134}135136
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.