2021-07-25 10:52:01 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// MassBuilderSaveTool
|
2022-01-30 11:36:56 +01:00
|
|
|
// Copyright (C) 2021-2022 Guillaume Jacquemin
|
2021-07-25 10:52:01 +02:00
|
|
|
//
|
|
|
|
// This program 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.
|
|
|
|
//
|
|
|
|
// This program 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.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
#include <Corrade/Containers/String.h>
|
|
|
|
|
2021-07-25 10:52:01 +02:00
|
|
|
#include <Magnum/Magnum.h>
|
|
|
|
#include <Magnum/Animation/Track.h>
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
using namespace Corrade;
|
2021-07-25 10:52:01 +02:00
|
|
|
using namespace Magnum;
|
|
|
|
|
|
|
|
class Toast {
|
|
|
|
public:
|
|
|
|
enum class Type : UnsignedByte {
|
|
|
|
Default, Success, Info, Warning, Error
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Phase : UnsignedByte {
|
|
|
|
FadeIn, Wait, FadeOut, TimedOut
|
|
|
|
};
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
explicit Toast(Type type, Containers::StringView message,
|
2021-07-25 10:52:01 +02:00
|
|
|
std::chrono::milliseconds timeout = std::chrono::milliseconds{3000});
|
|
|
|
|
|
|
|
Toast(const Toast& other) = delete;
|
|
|
|
Toast& operator=(const Toast& other) = delete;
|
|
|
|
|
|
|
|
Toast(Toast&& other) = default;
|
|
|
|
Toast& operator=(Toast&& other) = default;
|
|
|
|
|
|
|
|
auto type() -> Type;
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
auto message() -> Containers::StringView;
|
2021-07-25 10:52:01 +02:00
|
|
|
|
|
|
|
auto timeout() -> std::chrono::milliseconds;
|
|
|
|
|
|
|
|
auto creationTime() -> std::chrono::steady_clock::time_point;
|
|
|
|
|
|
|
|
auto elapsedTime() -> std::chrono::milliseconds;
|
|
|
|
|
|
|
|
auto phase() -> Phase;
|
|
|
|
|
|
|
|
auto opacity() -> Float;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Type _type{Type::Default};
|
2022-03-04 21:18:55 +01:00
|
|
|
Containers::StringView _message;
|
2021-07-25 10:52:01 +02:00
|
|
|
std::chrono::milliseconds _timeout;
|
|
|
|
std::chrono::steady_clock::time_point _creationTime;
|
|
|
|
Animation::Track<UnsignedInt, Phase> _phaseTrack;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ToastQueue {
|
|
|
|
public:
|
|
|
|
void addToast(Toast&& toast);
|
|
|
|
|
2022-03-04 21:18:55 +01:00
|
|
|
void addToast(Toast::Type type, Containers::StringView message,
|
2021-07-25 10:52:01 +02:00
|
|
|
std::chrono::milliseconds timeout = std::chrono::milliseconds{3000});
|
|
|
|
|
|
|
|
void draw(Vector2i viewport_size);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void removeToast(Long index);
|
|
|
|
|
|
|
|
std::vector<Toast> _toasts;
|
|
|
|
};
|