1/*
2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors.
3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com>
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#pragma once
10#include "../../Devices/Screen.h"
11#include <libg/Color.h>
12#include <libg/PixelBitmap.h>
13#include <memory>
14
15namespace WinServer {
16
17template <typename T, int Cost = 1>
18class AfterComponentLoadProgress {
19public:
20 static const int cost = Cost;
21 static const size_t progress;
22};
23
24static size_t total_cost = 0;
25template <int Cost>
26inline size_t __calc_total_cost()
27{
28 return total_cost += Cost;
29}
30
31template <typename T, int Cost>
32const size_t AfterComponentLoadProgress<T, Cost>::progress = __calc_total_cost<Cost>();
33
34class LoadingScreen {
35public:
36 inline static LoadingScreen& the()
37 {
38 extern LoadingScreen* s_WinServer_LoadingScreen_the;
39 return *s_WinServer_LoadingScreen_the;
40 }
41
42 inline static void destroy_the()
43 {
44 extern LoadingScreen* s_WinServer_LoadingScreen_the;
45 delete s_WinServer_LoadingScreen_the;
46 s_WinServer_LoadingScreen_the = nullptr;
47 }
48
49 LoadingScreen();
50 ~LoadingScreen() = default;
51
52 template <typename T, int cost = 1>
53 inline void move_progress() { display_status_bar(AfterComponentLoadProgress<T, cost>::progress, total_cost); }
54
55private:
56 static constexpr int progress_line_height() { return 4; }
57 static constexpr int progress_line_width() { return 128; }
58 void display_status_bar(int current_progress, int max_progress);
59
60 Screen& m_screen;
61 int m_progress_line_min_x { 0 };
62 int m_progress_line_min_y { 0 };
63 LG::PixelBitmap m_logo;
64};
65
66} // namespace WinServer