tdlight/td/telegram/BackgroundType.hpp

85 lines
2.2 KiB
C++
Raw Normal View History

//
2021-01-01 13:57:46 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/BackgroundType.h"
#include "td/utils/tl_helpers.h"
namespace td {
template <class StorerT>
2021-06-10 00:29:42 +02:00
void BackgroundType::store(StorerT &storer) const {
using td::store;
bool has_fill = fill.top_color != 0 || fill.bottom_color != 0;
bool has_intensity = intensity != 0;
auto fill_type = fill.get_type();
2021-05-20 01:21:20 +02:00
bool is_gradient = fill_type == BackgroundFill::Type::Gradient;
bool is_freeform_gradient = fill_type == BackgroundFill::Type::FreeformGradient;
BEGIN_STORE_FLAGS();
2021-06-10 00:29:42 +02:00
STORE_FLAG(is_blurred);
STORE_FLAG(is_moving);
STORE_FLAG(has_fill);
STORE_FLAG(has_intensity);
STORE_FLAG(is_gradient);
STORE_FLAG(is_freeform_gradient);
END_STORE_FLAGS();
2021-06-10 00:29:42 +02:00
store(type, storer);
if (is_freeform_gradient) {
2021-06-10 00:29:42 +02:00
store(fill.top_color, storer);
store(fill.bottom_color, storer);
store(fill.third_color, storer);
store(fill.fourth_color, storer);
} else if (has_fill) {
2021-06-10 00:29:42 +02:00
store(fill.top_color, storer);
if (is_gradient) {
2021-06-10 00:29:42 +02:00
store(fill.bottom_color, storer);
store(fill.rotation_angle, storer);
}
}
if (has_intensity) {
2021-06-10 00:29:42 +02:00
store(intensity, storer);
}
}
template <class ParserT>
2021-06-10 00:29:42 +02:00
void BackgroundType::parse(ParserT &parser) {
using td::parse;
bool has_fill;
bool has_intensity;
bool is_gradient;
bool is_freeform_gradient;
BEGIN_PARSE_FLAGS();
2021-06-10 00:29:42 +02:00
PARSE_FLAG(is_blurred);
PARSE_FLAG(is_moving);
PARSE_FLAG(has_fill);
PARSE_FLAG(has_intensity);
PARSE_FLAG(is_gradient);
PARSE_FLAG(is_freeform_gradient);
END_PARSE_FLAGS();
2021-06-10 00:29:42 +02:00
parse(type, parser);
if (is_freeform_gradient) {
2021-06-10 00:29:42 +02:00
parse(fill.top_color, parser);
parse(fill.bottom_color, parser);
parse(fill.third_color, parser);
parse(fill.fourth_color, parser);
} else if (has_fill) {
2021-06-10 00:29:42 +02:00
parse(fill.top_color, parser);
if (is_gradient) {
2021-06-10 00:29:42 +02:00
parse(fill.bottom_color, parser);
parse(fill.rotation_angle, parser);
} else {
2021-06-10 00:29:42 +02:00
fill.bottom_color = fill.top_color;
}
}
if (has_intensity) {
2021-06-10 00:29:42 +02:00
parse(intensity, parser);
}
}
} // namespace td