Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/gui/progress_dialog.h
9896 views
1
/**************************************************************************/
2
/* progress_dialog.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "scene/gui/box_container.h"
34
#include "scene/gui/button.h"
35
#include "scene/gui/center_container.h"
36
#include "scene/gui/label.h"
37
#include "scene/gui/progress_bar.h"
38
39
class BackgroundProgress : public HBoxContainer {
40
GDCLASS(BackgroundProgress, HBoxContainer);
41
42
_THREAD_SAFE_CLASS_
43
44
struct Task {
45
HBoxContainer *hb = nullptr;
46
ProgressBar *progress = nullptr;
47
};
48
49
HashMap<String, Task> tasks;
50
HashMap<String, int> updates;
51
void _update();
52
53
protected:
54
void _add_task(const String &p_task, const String &p_label, int p_steps);
55
void _task_step(const String &p_task, int p_step = -1);
56
void _end_task(const String &p_task);
57
58
public:
59
void add_task(const String &p_task, const String &p_label, int p_steps);
60
void task_step(const String &p_task, int p_step = -1);
61
void end_task(const String &p_task);
62
};
63
64
class PanelContainer;
65
66
class ProgressDialog : public CenterContainer {
67
GDCLASS(ProgressDialog, CenterContainer);
68
struct Task {
69
String task;
70
VBoxContainer *vb = nullptr;
71
ProgressBar *progress = nullptr;
72
Label *state = nullptr;
73
uint64_t last_progress_tick = 0;
74
};
75
HBoxContainer *cancel_hb = nullptr;
76
Button *cancel = nullptr;
77
78
HashMap<String, Task> tasks;
79
PanelContainer *center_panel = nullptr;
80
VBoxContainer *main = nullptr;
81
82
LocalVector<Window *> host_windows;
83
84
Size2 main_border_size;
85
86
static ProgressDialog *singleton;
87
void _popup();
88
89
void _cancel_pressed();
90
91
void _update_ui();
92
void _reparent_and_show();
93
bool canceled = false;
94
95
protected:
96
void _notification(int p_what);
97
98
public:
99
static ProgressDialog *get_singleton() { return singleton; }
100
void add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
101
bool task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_redraw = true);
102
void end_task(const String &p_task);
103
104
void add_host_window(Window *p_window);
105
void remove_host_window(Window *p_window);
106
107
ProgressDialog();
108
};
109
110