QRCode.cpp
QRCode.cpp
CPP1/* Copyright Statement:2 *3 * (C) 2021-2024 Cubios Inc. All rights reserved.4 */5#include "QRCode.h"6#include "Screen.h"7#include "Colors.h"89namespace Cubios10{11namespace Gfx12{13u32_t QRCode::rtc = 0;1415QRCode::QRCode(std::string data, const Cubios::Math::Transform& t):ColorZeros(Cubios::Gfx::Colors::black),ColorOnes(Cubios::Gfx::Colors::white),Size(8)16{17 this->Transform = t;1819 if(data.size()<256)20 this->data = data;21 else22 this->data = "";2324 this->resourceId = this->getNextID();25}2627QRCode::QRCode(std::string data, float x, float y):ColorZeros(Cubios::Gfx::Colors::black),ColorOnes(Cubios::Gfx::Colors::white),Size(8)28{29 this->Transform.Position.X = x;30 this->Transform.Position.Y = y;3132 if(data.size()<256)33 this->data = data;34 else35 this->data = "";3637 this->resourceId = this->getNextID();38}3940QRCode::QRCode(std::string data, const Cubios::Math::Transform& t, u32_t size):ColorZeros(Cubios::Gfx::Colors::black),ColorOnes(Cubios::Gfx::Colors::white),Size(size)41{42 this->Transform = t;4344 if(data.size()<256)45 this->data = data;46 else47 this->data = "";4849 this->resourceId = this->getNextID();50}5152QRCode::QRCode(std::string data, float x, float y, u32_t size):ColorZeros(Cubios::Gfx::Colors::black),ColorOnes(Cubios::Gfx::Colors::white),Size(size)53{54 this->Transform.Position.X = x;55 this->Transform.Position.Y = y;5657 if(data.size()<256)58 this->data = data;59 else60 this->data = "";6162 this->resourceId = this->getNextID();63}6465QRCode::QRCode(const QRCode& qr)66{67 this->Transform = qr.Transform;68 this->data = qr.data;69 this->resourceId = qr.resourceId;70 this->ColorZeros = qr.ColorZeros;71 this->ColorOnes = qr.ColorOnes;72 this->Size = qr.Size;73}7475QRCode::~QRCode() {}7677Cubios::SceneObject* QRCode::SetSize(u32_t size)78{79 this->Size = size;80 return this;81}8283Cubios::SceneObject* QRCode::SetColor(const Math::Color& color)84{85 this->ColorOnes = color;86 return this;87}8889Cubios::SceneObject* QRCode::SetBackgroundColor(const Math::Color& color)90{91 this->ColorZeros = color;92 return this;93}9495Cubios::SceneObject* QRCode::SetData(std::string data)96{97 if(data.size()<256)98 this->data = data;99 else100 this->data = "";101102 return this;103}104105void QRCode::Render()106{107 Math::Vec2 pos = this->ScreenPosition();108 Cubios::GFX_drawQRCode(pos.X, pos.Y, this->Size, this->ColorZeros.Value(),this->ColorOnes.Value(), Transform.SafeRotation()+ScreenAngle, this->resourceId, this->data.c_str());109}110}111}112
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.