Esp32-RBGridUI
Library for creating UIs for the RBController app
Loading...
Searching...
No Matches
camera.h
Go to the documentation of this file.
1#pragma once
2
3#include "widget.h"
4
5namespace gridui {
6
9class Camera : public Widget {
10 template <typename Self, typename Finished>
12
13 using Widget::Widget;
14
15public:
16 struct Tag {
17 float corners[4][2];
18 uint8_t id;
19 };
20
21 void setRotation(float rotation) {
22 m_state->set("rotation", new rbjson::Number(rotation));
23 }
24
25 float rotation() const {
26 return data().getDouble("rotation");
27 }
28
29 void setClip(bool clip) {
30 m_state->set("clip", new rbjson::Bool(clip));
31 }
32
33 bool clip() const {
34 return data().getBool("clip");
35 }
36
37 void addTag(const Tag& t) {
38 auto* tagsArray = data().getArray("tags");
39 const bool existedBefore = tagsArray != NULL;
40 if (!existedBefore) {
41 tagsArray = new rbjson::Array;
42 }
43 tagsArray->push_back(buildTagObject(t));
44
45 if (!existedBefore) {
46 m_state->set("tags", tagsArray);
47 }
48 {
49 m_state->markChanged("tags");
50 }
51 }
52
53 void setTags(const std::vector<Tag>& tags) {
54 auto* tagsArray = new rbjson::Array;
55 for (const auto& t : tags) {
56 tagsArray->push_back(buildTagObject(t));
57 }
58
59 m_state->set("tags", tagsArray);
60 }
61
62 void clearTags() {
63 auto* tagsArray = new rbjson::Array;
64 m_state->set("tags", tagsArray);
65 }
66
67private:
68 rbjson::Object* buildTagObject(const Tag& t) {
69 auto* tag = new rbjson::Object;
70 tag->set("id", t.id);
71 tag->set("c00", t.corners[0][0]);
72 tag->set("c01", t.corners[0][1]);
73 tag->set("c10", t.corners[1][0]);
74 tag->set("c11", t.corners[1][1]);
75 tag->set("c20", t.corners[2][0]);
76 tag->set("c21", t.corners[2][1]);
77 tag->set("c30", t.corners[3][0]);
78 tag->set("c31", t.corners[3][1]);
79 return tag;
80 }
81};
82
83};
float rotation() const
Definition camera.h:25
void addTag(const Tag &t)
Definition camera.h:37
void setRotation(float rotation)
Definition camera.h:21
void setClip(bool clip)
Definition camera.h:29
void setTags(const std::vector< Tag > &tags)
Definition camera.h:53
void clearTags()
Definition camera.h:62
bool clip() const
Definition camera.h:33
bool set(const std::string &key, rbjson::Value *value)
Definition widget.cpp:25
void markChanged(const std::string &key)
Definition widget.cpp:120
WidgetState * m_state
Definition widget.h:214
const rbjson::Object & data() const
Definition widget.h:212
Definition arm.h:8
float corners[4][2]
Definition camera.h:17