tdlight/td/telegram/BackgroundType.hpp

85 lines
2.3 KiB
C++
Raw Normal View History

//
2022-01-01 01:35:39 +01:00
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// 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();
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();
store(type_, storer);
if (is_freeform_gradient) {
store(fill_.top_color_, storer);
store(fill_.bottom_color_, storer);
store(fill_.third_color_, storer);
store(fill_.fourth_color_, storer);
} else if (has_fill) {
store(fill_.top_color_, storer);
if (is_gradient) {
store(fill_.bottom_color_, storer);
store(fill_.rotation_angle_, storer);
}
}
if (has_intensity) {
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();
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();
parse(type_, parser);
if (is_freeform_gradient) {
parse(fill_.top_color_, parser);
parse(fill_.bottom_color_, parser);
parse(fill_.third_color_, parser);
parse(fill_.fourth_color_, parser);
} else if (has_fill) {
parse(fill_.top_color_, parser);
if (is_gradient) {
parse(fill_.bottom_color_, parser);
parse(fill_.rotation_angle_, parser);
} else {
fill_.bottom_color_ = fill_.top_color_;
}
}
if (has_intensity) {
parse(intensity_, parser);
}
}
} // namespace td