Plasma Engine  2.0
Loading...
Searching...
No Matches
Progress.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Communication/Event.h>
5#include <Foundation/Strings/String.h>
6
7class plProgress;
9
15struct PL_FOUNDATION_DLL plProgressEvent
16{
17 enum class Type
18 {
19 ProgressStarted,
20 ProgressEnded,
21 ProgressChanged,
22 CancelClicked,
23 };
24
25 Type m_Type;
26 plProgress* m_pProgressbar;
27};
28
35class PL_FOUNDATION_DLL plProgress
36{
37public:
38 plProgress();
40
42 float GetCompletion() const;
43
45 void SetCompletion(float fCompletion);
46
48 plStringView GetMainDisplayText() const;
49
51 plStringView GetStepDisplayText() const;
52
54 void UserClickedCancel();
55
57 bool WasCanceled() const;
58
60 bool AllowUserCancel() const;
61
63 static plProgress* GetGlobalProgressbar();
64
66 static void SetGlobalProgressbar(plProgress* pProgress);
67
70
72 void* m_pUserData = nullptr;
73
74private:
75 friend class plProgressRange;
76 void SetActiveRange(plProgressRange* pRange);
77
78 plProgressRange* m_pActiveRange = nullptr;
79
80 plString m_sCurrentDisplayText;
81 bool m_bCancelClicked = false;
82 bool m_bEnableCancel = true;
83
84 float m_fLastReportedCompletion = 0.0f;
85 float m_fCurrentCompletion = 0.0f;
86};
87
96class PL_FOUNDATION_DLL plProgressRange
97{
98 PL_DISALLOW_COPY_AND_ASSIGN(plProgressRange);
99
100public:
108 plProgressRange(plStringView sDisplayText, plUInt32 uiSteps, bool bAllowCancel, plProgress* pProgressbar = nullptr);
109
111 plProgressRange(plStringView sDisplayText, bool bAllowCancel, plProgress* pProgressbar = nullptr);
112
116
118 plProgress* GetProgressbar() const;
119
125 void SetStepWeighting(plUInt32 uiStep, float fWeight);
126
132 bool BeginNextStep(plStringView sStepDisplayText, plUInt32 uiNumSteps = 1);
133
135 bool SetCompletion(double fCompletionFactor);
136
138 bool WasCanceled() const;
139
140private:
141 friend class plProgress;
142
143 void Init(plStringView sDisplayText, bool bAllowCancel, plProgress* pProgressbar);
144 float GetStepWeight(plUInt32 uiStep) const;
145 void ComputeCurStepBaseAndRange(double& out_base, double& out_range);
146
147 plProgressRange* m_pParentRange = nullptr;
148 plProgress* m_pProgressbar = nullptr;
149
150 plInt32 m_iCurrentStep = 0;
151 plString m_sDisplayText;
152 plString m_sStepDisplayText;
153 plHashTable<plUInt32, float> m_StepWeights;
154
155 bool m_bAllowCancel = false;
156 double m_fPercentageBase = 0.0;
157 double m_fPercentageRange = 0.0;
158 double m_fWeightedCompletion = 0.0;
159 double m_fSummedWeight = 0.0;
160};
Definition Event.h:177
Definition HashTable.h:333
Manages the way a progress bar is subdivided and advanced.
Definition Progress.h:36
plEvent< const plProgressEvent & > m_Events
Events are sent when the progress changes.
Definition Progress.h:69
plProgressRange is the preferred method to inform the system of progress.
Definition Progress.h:97
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Through these events the state of an plProgress instance is communicated.
Definition Progress.h:16
Type
Definition Progress.h:18