Debian Codegraph @

editor/StatusDlg.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 // StatusDlg.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23 #include "editor.h"
24 #include "StatusDlg.h"
25 #include "pserror.h"
26
27 #ifdef _DEBUG
28 #define new DEBUG_NEW
29 #undef THIS_FILE
30 static char THIS_FILE[] = __FILE__;
31 #endif
32
33 /////////////////////////////////////////////////////////////////////////////
34 // CStatusDlg dialog
35
36 CStatusDlg::CStatusDlg(CWnd *pParent /*=NULL*/) : CDialog(CStatusDlg::IDD, pParent) {
37 //{{AFX_DATA_INIT(CStatusDlg)
38 // NOTE: the ClassWizard will add member initialization here
39 //}}AFX_DATA_INIT
40 }
41
42 void CStatusDlg::DoDataExchange(CDataExchange *pDX) {
43 CDialog::DoDataExchange(pDX);
44 //{{AFX_DATA_MAP(CStatusDlg)
45 // NOTE: the ClassWizard will add DDX and DDV calls here
46 //}}AFX_DATA_MAP
47 }
48
49 void CStatusDlg::Init(int min, int max, int delta) {
50 CProgressCtrl *progress;
51
52 progress = (CProgressCtrl *)GetDlgItem(IDC_STATUSPROGRESS);
53 progress->SetRange(min, max);
54 progress->SetPos(min);
55 progress->SetStep(delta);
56
57 mprintf(0, "Progress Control Create: Min= %d Max= %d Step= %d\n", min, max, delta);
58 }
59
60 int CStatusDlg::Step() {
61 CProgressCtrl *progress;
62
63 progress = (CProgressCtrl *)GetDlgItem(IDC_STATUSPROGRESS);
64 return progress->StepIt();
65 }
66
67 void CStatusDlg::Text(char *string) {
68 CWnd *text;
69 text = GetDlgItem(IDC_STATUSTEXT);
70 text->SetWindowText(string);
71 }
72
73 void CStatusDlg::SetTo(int set) {
74 CProgressCtrl *progress;
75
76 progress = (CProgressCtrl *)GetDlgItem(IDC_STATUSPROGRESS);
77 progress->SetPos(set);
78 }
79
80 BEGIN_MESSAGE_MAP(CStatusDlg, CDialog)
81 //{{AFX_MSG_MAP(CStatusDlg)
82 // NOTE: the ClassWizard will add message map macros here
83 //}}AFX_MSG_MAP
84 END_MESSAGE_MAP()
85
86 /////////////////////////////////////////////////////////////////////////////
87 // CStatusDlg message handlers
88
89 // Initializes the Progress Window. This MUST MUST MUST be called first, the parent parameter can be
90 // NULL to set the parent to the main window.
91 // min/max: these are the range of the progress indicator
92 // iterations: If you plan on using CProgress:IncreaseProgress() then this is how many times you plan on
93 // calling CProgress::IncreaseProgress(). If you are going to use
94 //CProgress::SetProgressPercentage() then you should call the version of InitProgress(CWnd *parent) below.
95 // Returns true if the progress dialog was created
96 bool CProgress::InitProgress(fix min, fix max, int32_t iterations, CWnd *parent) {
97 int nmin, nmax, Step;
98 nmin = FixToInt(min);
99 nmax = FixToInt(max);
100
101 float delta;
102 delta = (float)(((float)(nmax - nmin)) / ((float)iterations));
103 while (delta < 1.0) {
104 delta *= 10;
105 nmax *= 10;
106 }
107 Step = (int)delta;
108 m_Max = nmax;
109 m_Min = nmin;
110
111 if (!iterations)
112 return false;
113 m_StatusDlg = new CStatusDlg;
114 if (!m_StatusDlg)
115 return false;
116 m_StatusDlg->Create(IDD_STATUSDLG, parent);
117 m_StatusDlg->ShowWindow(SW_SHOW);
118 m_StatusDlg->Init(nmin, nmax, Step);
119 return true;
120 }
121
122 // This is a quick way of initializing the progress indicator, with a range 0-100 step size 1. This is what you
123 // should call if you plan on using CProgress::SetProgressPercentage(). Again, parent can be NULL if you want it to
124 // be the main application as the parent
125 bool CProgress::InitProgress(CWnd *parent) {
126 m_Max = 100;
127 m_Min = 0;
128
129 m_StatusDlg = new CStatusDlg;
130 if (!m_StatusDlg)
131 return false;
132 m_StatusDlg->Create(IDD_STATUSDLG, parent);
133 m_StatusDlg->ShowWindow(SW_SHOW);
134 m_StatusDlg->Init(0, 100, 1);
135 return true;
136 }
137
138 // YOU MUST call this after you are done with the progress indicator. This frees up some allocated memory
139 void CProgress::DestroyProgress() {
140 ASSERT(m_StatusDlg != NULL);
141 m_StatusDlg->DestroyWindow();
142 if (m_StatusDlg)
143 delete m_StatusDlg;
144 }
145
146 // By default the progress indicator says "Please wait...", here you can change that text...make sure you call
147 // this after InitProgress()
148 void CProgress::SetProgressText(char *string) {
149 ASSERT(m_StatusDlg != NULL);
150 m_StatusDlg->Text(string);
151 }
152
153 // This is the iterator function. Call this in your loop or whatever to increase the progress indicator. You can also
154 // use CProgress::SetProgressPercentage() instead
155 bool CProgress::IncreaseProgress() {
156 ASSERT(m_StatusDlg != NULL);
157 int ret;
158 ret = m_StatusDlg->Step();
159 if (ret >= m_Max)
160 return true;
161 else
162 return false;
163 }
164
165 // Sets the progress indicator to a certain percentage
166 void CProgress::SetProgressPercentage(int percent) {
167 ASSERT(m_StatusDlg != NULL);
168 float per;
169 per = ((float)percent) / ((float)100.0);
170 m_StatusDlg->SetTo(m_Min + ((int)(per * (m_Max - m_Min))));
171 }
172
173 void CProgress::SetProgressPercentage(float percent) {
174 ASSERT(m_StatusDlg != NULL);
175 m_StatusDlg->SetTo(m_Min + ((int)(percent * (m_Max - m_Min))));
176 }