tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
BackgroundType.hpp
Go to the documentation of this file.
1#pragma once
5
6namespace tgbotxx {
15 BackgroundType() = default;
16 explicit BackgroundType(const nl::json& json) {
17 _fromJson(json);
18 }
19 virtual ~BackgroundType() = default;
20
22 std::string type;
23
24 virtual nl::json toJson() const {
25 nl::json json = nl::json::object();
26 OBJECT_SERIALIZE_FIELD(json, "type", type);
27 return json;
28 }
29
30 virtual void fromJson(const nl::json& json) {
31 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
32 }
33
34 private:
35 void _fromJson(const nl::json& json) {
36 fromJson(json);
37 }
38 };
39
46 explicit BackgroundTypeFill(const nl::json& json) : BackgroundType(json) {
47 BackgroundType::type = "fill";
48 }
49
52
54 std::int32_t darkThemeDimming{};
55
56 nl::json toJson() const override {
57 nl::json json = BackgroundType::toJson();
58 OBJECT_SERIALIZE_FIELD_PTR(json, "fill", fill);
59 OBJECT_SERIALIZE_FIELD(json, "dark_theme_dimming", darkThemeDimming);
60 return json;
61 }
62
63 void fromJson(const nl::json& json) override {
65 OBJECT_DESERIALIZE_FIELD_PTR(json, "fill", fill, false);
66 OBJECT_DESERIALIZE_FIELD(json, "dark_theme_dimming", darkThemeDimming, 0, false);
67 }
68 };
69
76 explicit BackgroundTypeWallpaper(const nl::json& json) : BackgroundType(json) {
77 BackgroundType::type = "wallpaper";
78 }
79
82
84 std::int32_t darkThemeDimming{};
85
87 bool isBlurred{};
88
90 bool isMoving{};
91
92 nl::json toJson() const override {
93 nl::json json = BackgroundType::toJson();
94 OBJECT_SERIALIZE_FIELD_PTR(json, "document", document);
95 OBJECT_SERIALIZE_FIELD(json, "dark_theme_dimming", darkThemeDimming);
96 OBJECT_SERIALIZE_FIELD(json, "is_blurred", isBlurred);
97 OBJECT_SERIALIZE_FIELD(json, "is_moving", isMoving);
98 return json;
99 }
100
101 void fromJson(const nl::json& json) override {
103 OBJECT_DESERIALIZE_FIELD_PTR(json, "document", document, false);
104 OBJECT_DESERIALIZE_FIELD(json, "dark_theme_dimming", darkThemeDimming, 0, false);
105 OBJECT_DESERIALIZE_FIELD(json, "is_blurred", isBlurred, false, true);
106 OBJECT_DESERIALIZE_FIELD(json, "is_moving", isMoving, false, true);
107 }
108 };
109
114 BackgroundType::type = "pattern";
115 }
116 explicit BackgroundTypePattern(const nl::json& json) : BackgroundType(json) {
117 BackgroundType::type = "pattern";
118 }
119
122
125
127 std::int32_t intensity{};
128
131
133 bool isMoving{};
134
135 nl::json toJson() const override {
136 nl::json json = BackgroundType::toJson();
137 OBJECT_SERIALIZE_FIELD_PTR(json, "document", document);
138 OBJECT_SERIALIZE_FIELD_PTR(json, "fill", fill);
139 OBJECT_SERIALIZE_FIELD(json, "intensity", intensity);
140 OBJECT_SERIALIZE_FIELD(json, "is_inverted", isInverted);
141 OBJECT_SERIALIZE_FIELD(json, "is_moving", isMoving);
142 return json;
143 }
144
145 void fromJson(const nl::json& json) override {
147 OBJECT_DESERIALIZE_FIELD_PTR(json, "document", document, false);
148 OBJECT_DESERIALIZE_FIELD_PTR(json, "fill", fill, false);
149 OBJECT_DESERIALIZE_FIELD(json, "intensity", intensity, 0, false);
150 OBJECT_DESERIALIZE_FIELD(json, "is_inverted", isInverted, false, true);
151 OBJECT_DESERIALIZE_FIELD(json, "is_moving", isMoving, false, true);
152 }
153 };
154
159 BackgroundType::type = "chat_theme";
160 }
161 explicit BackgroundTypeChatTheme(const nl::json& json) : BackgroundType(json) {
162 BackgroundType::type = "chat_theme";
163 }
164
166 std::string themeName;
167
168 nl::json toJson() const override {
169 nl::json json = BackgroundType::toJson();
170 OBJECT_SERIALIZE_FIELD(json, "theme_name", themeName);
171 return json;
172 }
173
174 void fromJson(const nl::json& json) override {
176 OBJECT_DESERIALIZE_FIELD(json, "theme_name", themeName, "", false);
177 }
178 };
179
180}
#define OBJECT_SERIALIZE_FIELD_PTR(json, json_field, field)
Definition Object.hpp:22
#define OBJECT_DESERIALIZE_FIELD_PTR(json, json_field, field, optional)
Definition Object.hpp:72
#define OBJECT_SERIALIZE_FIELD(json, json_field, field)
Available objects: https://core.telegram.org/bots/api#available-types.
Definition Object.hpp:19
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition Object.hpp:46
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
The background is taken directly from a built-in chat theme. https://core.telegram....
void fromJson(const nl::json &json) override
nl::json toJson() const override
std::string themeName
Name of the chat theme, which is usually an emoji.
BackgroundTypeChatTheme(const nl::json &json)
The background is automatically filled based on the selected colors. https://core....
Ptr< BackgroundFill > fill
The background fill.
std::int32_t darkThemeDimming
Dimming of the background in dark themes, as a percentage; 0-100.
void fromJson(const nl::json &json) override
nl::json toJson() const override
BackgroundTypeFill(const nl::json &json)
This object describes the type of a background. It can be one of:
virtual void fromJson(const nl::json &json)
virtual nl::json toJson() const
BackgroundType(const nl::json &json)
virtual ~BackgroundType()=default
std::string type
Type of the background, one of "fill", "wallpaper", "pattern", "chat_theme".
The background is a PNG or TGV pattern combined with a fill. https://core.telegram....
Ptr< Document > document
Document with the pattern.
bool isMoving
Optional. True, if the background moves slightly when the device is tilted.
void fromJson(const nl::json &json) override
Ptr< BackgroundFill > fill
The background fill that is combined with the pattern.
nl::json toJson() const override
BackgroundTypePattern(const nl::json &json)
std::int32_t intensity
Intensity of the pattern when it is shown above the filled background; 0-100.
bool isInverted
Optional. True, if the background fill must be applied only to the pattern itself....
The background is a wallpaper in JPEG format. https://core.telegram.org/bots/api#backgroundtypewallpa...
bool isMoving
Optional. True, if the background moves slightly when the device is tilted.
void fromJson(const nl::json &json) override
std::int32_t darkThemeDimming
Dimming of the background in dark themes, as a percentage; 0-100.
nl::json toJson() const override
bool isBlurred
Optional. True, if the wallpaper is downscaled to fit in a 450x450 square and then box-blurred with r...
Ptr< Document > document
Document with the wallpaper.
BackgroundTypeWallpaper(const nl::json &json)