WebCFace 2.9.0
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
canvas2d.h
Go to the documentation of this file.
1#pragma once
2#include "./base.h"
4#include <map>
5#include <optional>
6#include <unordered_map>
7#include <vector>
8#include <array>
9
10#ifndef MSGPACK_DEFINE_MAP
11#define MSGPACK_DEFINE_MAP(...)
12#endif
13
15namespace message {
16
18 int type = 0;
19 std::array<double, 2> origin_pos;
20 double origin_rot;
21 int color = 0, fill = 0;
23 std::optional<int> geometry_type;
24 std::vector<double> properties;
25 std::optional<SharedString> on_click_member, on_click_field;
28 bool operator==(const Canvas2DComponentData &other) const {
29 return type == other.type && origin_pos == other.origin_pos &&
30 origin_rot == other.origin_rot && color == other.color &&
31 fill == other.fill && stroke_width == other.stroke_width &&
32 geometry_type == other.geometry_type &&
33 properties == other.properties &&
34 on_click_member == other.on_click_member &&
35 on_click_field == other.on_click_field && text == other.text;
36 }
37 bool operator!=(const Canvas2DComponentData &other) const {
38 return !(*this == other);
39 }
40 MSGPACK_DEFINE_MAP(MSGPACK_NVP("t", type), MSGPACK_NVP("op", origin_pos),
41 MSGPACK_NVP("or", origin_rot), MSGPACK_NVP("c", color),
42 MSGPACK_NVP("f", fill), MSGPACK_NVP("s", stroke_width),
43 MSGPACK_NVP("gt", geometry_type),
44 MSGPACK_NVP("gp", properties),
45 MSGPACK_NVP("L", on_click_member),
46 MSGPACK_NVP("l", on_click_field), MSGPACK_NVP("x", text))
47};
49 double width = 0, height = 0;
50 std::map<std::string, std::shared_ptr<Canvas2DComponentData>, std::less<>>
52 std::vector<SharedString> data_ids;
53 Canvas2DData() = default;
54 Canvas2DData(double width, double height)
55 : width(width), height(height), components(), data_ids() {}
56};
57
58struct Canvas2D : public MessageBase<MessageKind::canvas2d> {
60 double width, height;
61 std::map<std::string, std::shared_ptr<Canvas2DComponentData>, std::less<>>
63 std::optional<std::vector<SharedString>> data_ids;
64 Canvas2D() = default;
65 Canvas2D(const SharedString &field, double width, double height,
66 std::map<std::string, std::shared_ptr<Canvas2DComponentData>,
67 std::less<>>
68 data_diff,
69 std::optional<std::vector<SharedString>> data_ids)
70 : field(field), width(width), height(height),
71 data_diff(std::move(data_diff)), data_ids(std::move(data_ids)) {}
72 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("w", width),
73 MSGPACK_NVP("h", height), MSGPACK_NVP("d", data_diff),
74 MSGPACK_NVP("l", data_ids))
75};
76struct Canvas2DOld : public MessageBase<MessageKind::canvas2d_old> {
78 double width, height;
79 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
80 std::size_t length;
81 Canvas2DOld() = default;
83 const SharedString &field, double width, double height,
84 const std::unordered_map<int, std::shared_ptr<Canvas2DComponentData>>
85 &data_diff,
86 std::size_t length)
87 : field(field), width(width), height(height), data_diff(),
88 length(length) {
89 for (const auto &vc : data_diff) {
90 this->data_diff.emplace(std::to_string(vc.first), vc.second);
91 }
92 }
94 const SharedString &field, double width, double height,
95 const std::map<std::string, std::shared_ptr<Canvas2DComponentData>>
96 &data_diff,
97 std::size_t length)
98 : field(field), width(width), height(height), data_diff(data_diff),
99 length(length) {}
100 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("w", width),
101 MSGPACK_NVP("h", height), MSGPACK_NVP("d", data_diff),
102 MSGPACK_NVP("l", length))
103};
104template <>
106 : public MessageBase<MessageKind::canvas2d_old + MessageKind::res> {
107 unsigned int req_id = 0;
109 double width = 0, height = 0;
110 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
111 std::size_t length;
112 Res() = default;
113 Res(unsigned int req_id, const SharedString &sub_field, double width,
114 double height,
115 const std::map<std::string, std::shared_ptr<Canvas2DComponentData>>
116 &data_diff,
117 std::size_t length)
118 : req_id(req_id), sub_field(sub_field), width(width), height(height),
119 data_diff(data_diff), length(length) {}
120 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
121 MSGPACK_NVP("w", width), MSGPACK_NVP("h", height),
122 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", length))
123};
124template <>
126 : public MessageBase<MessageKind::canvas2d + MessageKind::res> {
127 unsigned int req_id = 0;
129 double width = 0, height = 0;
130 std::map<std::string, std::shared_ptr<Canvas2DComponentData>, std::less<>>
132 std::optional<std::vector<SharedString>> data_ids;
133 Res() = default;
134 Res(unsigned int req_id, const SharedString &sub_field, double width,
135 double height,
136 const std::map<std::string, std::shared_ptr<Canvas2DComponentData>,
137 std::less<>> &data_diff,
138 const std::optional<std::vector<SharedString>> &data_ids)
139 : req_id(req_id), sub_field(sub_field), width(width), height(height),
140 data_diff(data_diff), data_ids(data_ids) {}
141 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
142 MSGPACK_NVP("w", width), MSGPACK_NVP("h", height),
143 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", data_ids))
144};
145
146} // namespace message
148
150WEBCFACE_MESSAGE_FMT(webcface::message::Res<webcface::message::Canvas2D>)
151WEBCFACE_MESSAGE_FMT(webcface::message::Entry<webcface::message::Canvas2D>)
152WEBCFACE_MESSAGE_FMT(webcface::message::Req<webcface::message::Canvas2D>)
153WEBCFACE_MESSAGE_FMT(webcface::message::Canvas2DOld)
154WEBCFACE_MESSAGE_FMT(webcface::message::Res<webcface::message::Canvas2DOld>)
155WEBCFACE_MESSAGE_FMT(webcface::message::Entry<webcface::message::Canvas2DOld>)
156WEBCFACE_MESSAGE_FMT(webcface::message::Req<webcface::message::Canvas2DOld>)
#define MSGPACK_DEFINE_MAP(...)
Definition base.h:18
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:159
#define WEBCFACE_MESSAGE_FMT(Type)
Definition fmt.h:21
Definition arg.h:14
int color
Definition canvas2d.h:21
bool operator==(const Canvas2DComponentData &other) const
Definition canvas2d.h:28
int fill
Definition canvas2d.h:21
std::array< double, 2 > origin_pos
Definition canvas2d.h:19
SharedString text
Definition canvas2d.h:26
bool operator!=(const Canvas2DComponentData &other) const
Definition canvas2d.h:37
std::optional< SharedString > on_click_member
Definition canvas2d.h:25
std::vector< double > properties
Definition canvas2d.h:24
std::optional< int > geometry_type
Definition canvas2d.h:23
int type
Definition canvas2d.h:18
double origin_rot
Definition canvas2d.h:20
double stroke_width
Definition canvas2d.h:22
std::optional< SharedString > on_click_field
Definition canvas2d.h:25
Definition canvas2d.h:48
std::vector< SharedString > data_ids
Definition canvas2d.h:52
Canvas2DData(double width, double height)
Definition canvas2d.h:54
std::map< std::string, std::shared_ptr< Canvas2DComponentData >, std::less<> > components
Definition canvas2d.h:51
Definition canvas2d.h:76
Canvas2DOld(const SharedString &field, double width, double height, const std::map< std::string, std::shared_ptr< Canvas2DComponentData > > &data_diff, std::size_t length)
Definition canvas2d.h:93
double height
Definition canvas2d.h:78
Canvas2DOld(const SharedString &field, double width, double height, const std::unordered_map< int, std::shared_ptr< Canvas2DComponentData > > &data_diff, std::size_t length)
Definition canvas2d.h:82
std::size_t length
Definition canvas2d.h:80
SharedString field
Definition canvas2d.h:77
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:79
Definition canvas2d.h:58
std::optional< std::vector< SharedString > > data_ids
Definition canvas2d.h:63
double height
Definition canvas2d.h:60
SharedString field
Definition canvas2d.h:59
Canvas2D(const SharedString &field, double width, double height, std::map< std::string, std::shared_ptr< Canvas2DComponentData >, std::less<> > data_diff, std::optional< std::vector< SharedString > > data_ids)
Definition canvas2d.h:65
std::map< std::string, std::shared_ptr< Canvas2DComponentData >, std::less<> > data_diff
Definition canvas2d.h:62
型からkindを取得するためだけのベースクラス
Definition base.h:68
Res(unsigned int req_id, const SharedString &sub_field, double width, double height, const std::map< std::string, std::shared_ptr< Canvas2DComponentData > > &data_diff, std::size_t length)
Definition canvas2d.h:113
std::size_t length
Definition canvas2d.h:111
SharedString sub_field
Definition canvas2d.h:108
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:110
std::optional< std::vector< SharedString > > data_ids
Definition canvas2d.h:132
Res(unsigned int req_id, const SharedString &sub_field, double width, double height, const std::map< std::string, std::shared_ptr< Canvas2DComponentData >, std::less<> > &data_diff, const std::optional< std::vector< SharedString > > &data_ids)
Definition canvas2d.h:134
SharedString sub_field
Definition canvas2d.h:128
std::map< std::string, std::shared_ptr< Canvas2DComponentData >, std::less<> > data_diff
Definition canvas2d.h:131
Definition base.h:73
#define WEBCFACE_NS_END
Definition webcface-config.h:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117