/* This file is part of Telegram Desktop, the official desktop version of Telegram messaging app, see https://telegram.org Telegram Desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. In addition, as a special exception, the copyright holders give permission to link the code of portions of this program with the OpenSSL library. Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once #include "history/history_item_components.h" class SharedMediaWithLastSlice; class UserPhotosSlice; namespace Media { namespace View { class GroupThumbs { public: static void Refresh( std::unique_ptr &instance, const SharedMediaWithLastSlice &slice, int index, int availableWidth); static void Refresh( std::unique_ptr &instance, const UserPhotosSlice &slice, int index, int availableWidth); void clear(); void resizeToWidth(int newWidth); int height() const; bool hiding() const; bool hidden() const; void checkForAnimationStart(); void paint(Painter &p, int x, int y, int outerWidth, TimeMs ms); rpl::producer updateRequests() const { return _updateRequests.events(); } rpl::lifetime &lifetime() { return _lifetime; } using Context = base::optional_variant; using Key = base::variant; GroupThumbs(Context context); ~GroupThumbs(); private: class Thumb; template static void RefreshFromSlice( std::unique_ptr &instance, const Slice &slice, int index, int availableWidth); template void fillItems(const Slice &slice, int from, int index, int till); void updateContext(Context context); void markCacheStale(); not_null validateCacheEntry(Key key); std::unique_ptr createThumb(Key key); std::unique_ptr createThumb(Key key, ImagePtr image); void update(); void countUpdatedRect(); void animateAliveItems(int current); void fillDyingItems(const std::vector> &old); void markAsDying(not_null thumb); void markRestAsDying(); void animatePreviouslyAlive(const std::vector> &old); void startDelayedAnimation(); Context _context; bool _waitingForAnimationStart = true; Animation _animation; std::vector> _items; std::vector> _dying; base::flat_map> _cache; int _width = 0; int _limit = 0; rpl::event_stream _updateRequests; rpl::lifetime _lifetime; QRect _updatedRect; }; } // namespace View } // namespace Media