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 m_state->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 m_state->getBool("clip");
35 }
36
37 void addTag(const Tag& t) {
38 auto lock = m_state->uniqueStateLock();
39
40 auto* tagsArray = m_state->dataLocked().getArray("tags");
41 const bool existedBefore = tagsArray != NULL;
42 if (!existedBefore) {
43 tagsArray = new rbjson::Array;
44 }
45 tagsArray->push_back(buildTagObject(t));
46
47 lock.unlock();
48
49 if (!existedBefore) {
50 m_state->set("tags", tagsArray);
51 m_state->markChanged("tags");
52 }
53 }
54
55 void setTags(const std::vector<Tag>& tags) {
56 auto* tagsArray = new rbjson::Array;
57 for (const auto& t : tags) {
58 tagsArray->push_back(buildTagObject(t));
59 }
60
61 m_state->set("tags", tagsArray);
62 }
63
64 void clearTags() {
65 auto* tagsArray = new rbjson::Array;
66 m_state->set("tags", tagsArray);
67 }
68
69private:
70 rbjson::Object* buildTagObject(const Tag& t) {
71 auto* tag = new rbjson::Object;
72 tag->set("id", t.id);
73 tag->set("c00", t.corners[0][0]);
74 tag->set("c01", t.corners[0][1]);
75 tag->set("c10", t.corners[1][0]);
76 tag->set("c11", t.corners[1][1]);
77 tag->set("c20", t.corners[2][0]);
78 tag->set("c21", t.corners[2][1]);
79 tag->set("c30", t.corners[3][0]);
80 tag->set("c31", t.corners[3][1]);
81 return tag;
82 }
83};
84
85};
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:55
void clearTags()
Definition camera.h:64
bool clip() const
Definition camera.h:33
bool set(const std::string &key, rbjson::Value *value)
Definition widget.cpp:47
void markChanged(const std::string &key)
Definition widget.cpp:142
std::unique_lock< std::mutex > uniqueStateLock()
Definition widget.h:136
bool getBool(const std::string &key, bool def=false) const
Definition widget.cpp:42
double getDouble(const std::string &key, double def=0.0) const
Definition widget.cpp:37
const rbjson::Object & dataLocked() const
Definition widget.h:139
WidgetState * m_state
Definition widget.h:275
Definition arm.h:8
float corners[4][2]
Definition camera.h:17