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>> components;
51 std::vector<SharedString> data_ids;
52 Canvas2DData() = default;
53 Canvas2DData(double width, double height)
54 : width(width), height(height), components(), data_ids() {}
55};
56
57struct Canvas2D : public MessageBase<MessageKind::canvas2d> {
59 double width, height;
60 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
61 std::optional<std::vector<SharedString>> data_ids;
62 Canvas2D() = default;
64 const SharedString &field, double width, double height,
65 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff,
66 std::optional<std::vector<SharedString>> data_ids)
67 : field(field), width(width), height(height),
68 data_diff(std::move(data_diff)), data_ids(std::move(data_ids)) {}
69 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("w", width),
70 MSGPACK_NVP("h", height), MSGPACK_NVP("d", data_diff),
71 MSGPACK_NVP("l", data_ids))
72};
73struct Canvas2DOld : public MessageBase<MessageKind::canvas2d_old> {
75 double width, height;
76 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
77 std::size_t length;
78 Canvas2DOld() = default;
80 const SharedString &field, double width, double height,
81 const std::unordered_map<int, std::shared_ptr<Canvas2DComponentData>>
82 &data_diff,
83 std::size_t length)
84 : field(field), width(width), height(height), data_diff(),
85 length(length) {
86 for (const auto &vc : data_diff) {
87 this->data_diff.emplace(std::to_string(vc.first), vc.second);
88 }
89 }
91 const SharedString &field, double width, double height,
92 const std::map<std::string, std::shared_ptr<Canvas2DComponentData>>
93 &data_diff,
94 std::size_t length)
95 : field(field), width(width), height(height), data_diff(data_diff),
96 length(length) {}
97 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("w", width),
98 MSGPACK_NVP("h", height), MSGPACK_NVP("d", data_diff),
99 MSGPACK_NVP("l", length))
100};
101template <>
103 : public MessageBase<MessageKind::canvas2d_old + MessageKind::res> {
104 unsigned int req_id = 0;
106 double width = 0, height = 0;
107 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
108 std::size_t length;
109 Res() = default;
110 Res(unsigned int req_id, const SharedString &sub_field, double width,
111 double height,
112 const std::map<std::string, std::shared_ptr<Canvas2DComponentData>>
113 &data_diff,
114 std::size_t length)
115 : req_id(req_id), sub_field(sub_field), width(width), height(height),
116 data_diff(data_diff), length(length) {}
117 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
118 MSGPACK_NVP("w", width), MSGPACK_NVP("h", height),
119 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", length))
120};
121template <>
123 : public MessageBase<MessageKind::canvas2d + MessageKind::res> {
124 unsigned int req_id = 0;
126 double width = 0, height = 0;
127 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
128 std::optional<std::vector<SharedString>> data_ids;
129 Res() = default;
130 Res(unsigned int req_id, const SharedString &sub_field, double width,
131 double height,
132 const std::map<std::string, std::shared_ptr<Canvas2DComponentData>>
133 &data_diff,
134 const std::optional<std::vector<SharedString>> &data_ids)
135 : req_id(req_id), sub_field(sub_field), width(width), height(height),
136 data_diff(data_diff), data_ids(data_ids) {}
137 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
138 MSGPACK_NVP("w", width), MSGPACK_NVP("h", height),
139 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", data_ids))
140};
141
142} // namespace message
144
146WEBCFACE_MESSAGE_FMT(webcface::message::Res<webcface::message::Canvas2D>)
147WEBCFACE_MESSAGE_FMT(webcface::message::Entry<webcface::message::Canvas2D>)
148WEBCFACE_MESSAGE_FMT(webcface::message::Req<webcface::message::Canvas2D>)
149WEBCFACE_MESSAGE_FMT(webcface::message::Canvas2DOld)
150WEBCFACE_MESSAGE_FMT(webcface::message::Res<webcface::message::Canvas2DOld>)
151WEBCFACE_MESSAGE_FMT(webcface::message::Entry<webcface::message::Canvas2DOld>)
152WEBCFACE_MESSAGE_FMT(webcface::message::Req<webcface::message::Canvas2DOld>)
#define MSGPACK_DEFINE_MAP(...)
Definition base.h:11
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:67
#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::map< std::string, std::shared_ptr< Canvas2DComponentData > > components
Definition canvas2d.h:50
std::vector< SharedString > data_ids
Definition canvas2d.h:51
Canvas2DData(double width, double height)
Definition canvas2d.h:53
Definition canvas2d.h:73
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:90
double height
Definition canvas2d.h:75
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:79
std::size_t length
Definition canvas2d.h:77
SharedString field
Definition canvas2d.h:74
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:76
Definition canvas2d.h:57
std::optional< std::vector< SharedString > > data_ids
Definition canvas2d.h:61
Canvas2D(const SharedString &field, double width, double height, std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff, std::optional< std::vector< SharedString > > data_ids)
Definition canvas2d.h:63
double height
Definition canvas2d.h:59
SharedString field
Definition canvas2d.h:58
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:60
型からkindを取得するためだけのベースクラス
Definition base.h:60
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:110
std::size_t length
Definition canvas2d.h:108
SharedString sub_field
Definition canvas2d.h:105
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:107
std::optional< std::vector< SharedString > > data_ids
Definition canvas2d.h:128
Res(unsigned int req_id, const SharedString &sub_field, double width, double height, const std::map< std::string, std::shared_ptr< Canvas2DComponentData > > &data_diff, const std::optional< std::vector< SharedString > > &data_ids)
Definition canvas2d.h:130
SharedString sub_field
Definition canvas2d.h:125
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:127
Definition base.h:65
#define WEBCFACE_NS_END
Definition webcface-config.h:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117