Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
brushoptions.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
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// brushoptions.cpp : implementation file
20//
21
22#include "stdafx.h"
23#include "resource.h"
24#include "Lib\BaseType.h"
25#include "brushoptions.h"
26#include "WorldBuilderView.h"
27#include "BrushTool.h"
28
35
36
37BrushOptions::BrushOptions(CWnd* pParent /*=NULL*/)
38{
39 //{{AFX_DATA_INIT(BrushOptions)
40 // NOTE: the ClassWizard will add member initialization here
41 //}}AFX_DATA_INIT
42}
43
45void BrushOptions::DoDataExchange(CDataExchange* pDX)
46{
47 CDialog::DoDataExchange(pDX);
48 //{{AFX_DATA_MAP(BrushOptions)
49 // NOTE: the ClassWizard will add DDX and DDV calls here
50 //}}AFX_DATA_MAP
51}
52
54
56{
57 CString buf;
58 buf.Format("%d", feather);
59 m_currentFeather = feather;
60 if (m_staticThis && !m_staticThis->m_updating) {
61 CWnd *pEdit = m_staticThis->GetDlgItem(IDC_FEATHER_EDIT);
62 if (pEdit) pEdit->SetWindowText(buf);
63 }
64}
65
67
69{
70 CString buf;
71 buf.Format("%d", width);
72 m_currentWidth = width;
73 if (m_staticThis && !m_staticThis->m_updating) {
74 CWnd *pEdit = m_staticThis->GetDlgItem(IDC_SIZE_EDIT);
75 if (pEdit) pEdit->SetWindowText(buf);
76 }
77}
78
80{
81 char buffer[50];
82 sprintf(buffer, "%d", height);
83 m_currentHeight = height;
84 if (m_staticThis && !m_staticThis->m_updating) {
85 CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT);
86 if (pEdit) pEdit->SetWindowText(buffer);
87 }
88}
89
90
91
93// BrushOptions message handlers
94
96
99{
100 CDialog::OnInitDialog();
101
102 m_updating = true;
103 m_brushWidthPopup.SetupPopSliderButton(this, IDC_SIZE_POPUP, this);
104 m_brushFeatherPopup.SetupPopSliderButton(this, IDC_FEATHER_POPUP, this);
105 m_brushHeightPopup.SetupPopSliderButton(this, IDC_HEIGHT_POPUP, this);
106
107
108 m_staticThis = this;
109 m_updating = false;
113 return TRUE; // return TRUE unless you set the focus to a control
114 // EXCEPTION: OCX Property Pages should return FALSE
115}
116
118
121{
122 if (m_updating) return;
123 CWnd *pEdit = m_staticThis->GetDlgItem(IDC_FEATHER_EDIT);
124 char buffer[_MAX_PATH];
125 if (pEdit) {
126 pEdit->GetWindowText(buffer, sizeof(buffer));
127 Int feather;
128 m_updating = true;
129 if (1==sscanf(buffer, "%d", &feather)) {
130 m_currentFeather = feather;
132 sprintf(buffer, "%.1f FEET.", m_currentFeather*MAP_XY_FACTOR);
133 pEdit = m_staticThis->GetDlgItem(IDC_FEATHER_LABEL);
134 if (pEdit) pEdit->SetWindowText(buffer);
135 }
136 m_updating = false;
137 }
138}
139
141
144{
145 if (m_updating) return;
146 CWnd *pEdit = m_staticThis->GetDlgItem(IDC_SIZE_EDIT);
147 char buffer[_MAX_PATH];
148 if (pEdit) {
149 pEdit->GetWindowText(buffer, sizeof(buffer));
150 Int width;
151 m_updating = true;
152 if (1==sscanf(buffer, "%d", &width)) {
153 m_currentWidth = width;
155 sprintf(buffer, "%.1f FEET.", m_currentWidth*MAP_XY_FACTOR);
156 pEdit = m_staticThis->GetDlgItem(IDC_WIDTH_LABEL);
157 if (pEdit) pEdit->SetWindowText(buffer);
158 }
159 m_updating = false;
160 }
161}
162
164
167{
168 if (m_updating) return;
169 CWnd *pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT);
170 char buffer[_MAX_PATH];
171 if (pEdit) {
172 pEdit->GetWindowText(buffer, sizeof(buffer));
173 Int height;
174 m_updating = true;
175 if (1==sscanf(buffer, "%d", &height)) {
176 m_currentHeight = height;
178 sprintf(buffer, "%.1f FEET.", m_currentHeight*MAP_HEIGHT_SCALE);
179 pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_LABEL);
180 if (pEdit) pEdit->SetWindowText(buffer);
181 }
182 m_updating = false;
183 }
184}
185
186void BrushOptions::GetPopSliderInfo(const long sliderID, long *pMin, long *pMax, long *pLineSize, long *pInitial)
187{
188 switch (sliderID) {
189
190 case IDC_SIZE_POPUP:
191 *pMin = 1;
192 *pMax = 30;
193 *pInitial = m_currentWidth;
194 *pLineSize = 1;
195 break;
196
197 case IDC_HEIGHT_POPUP:
198 *pMin = 0;
199 *pMax = 255;
200 *pInitial = m_currentHeight;
201 *pLineSize = 1;
202 break;
203
205 *pMin = 0;
206 *pMax = 20;
207 *pInitial = m_currentFeather;
208 *pLineSize = 1;
209 break;
210
211 default:
212 // uh-oh!
213 DEBUG_CRASH(("Slider message from unknown control"));
214 break;
215 } // switch
216}
217
218void BrushOptions::PopSliderChanged(const long sliderID, long theVal)
219{
220 CString str;
221 CWnd *pEdit;
222 switch (sliderID) {
223
224 case IDC_SIZE_POPUP:
225 m_currentWidth = theVal;
226 str.Format("%d",m_currentWidth);
227 pEdit = m_staticThis->GetDlgItem(IDC_SIZE_EDIT);
228 if (pEdit) pEdit->SetWindowText(str);
230 break;
231
232 case IDC_HEIGHT_POPUP:
233 m_currentHeight = theVal;
234 str.Format("%d",m_currentHeight);
235 pEdit = m_staticThis->GetDlgItem(IDC_HEIGHT_EDIT);
236 if (pEdit) pEdit->SetWindowText(str);
238 break;
239
241 m_currentFeather = theVal;
242 str.Format("%d",m_currentFeather);
243 pEdit = m_staticThis->GetDlgItem(IDC_FEATHER_EDIT);
244 if (pEdit) pEdit->SetWindowText(str);
246 break;
247
248 default:
249 // uh-oh!
250 DEBUG_CRASH(("Slider message from unknown control"));
251 break;
252 } // switch
253}
254
255void BrushOptions::PopSliderFinished(const long sliderID, long theVal)
256{
257 switch (sliderID) {
258 case IDC_SIZE_POPUP:
259 break;
260 case IDC_HEIGHT_POPUP:
261 break;
263 break;
264
265 default:
266 // uh-oh!
267 DEBUG_CRASH(("Slider message from unknown control"));
268 break;
269 } // switch
270
271}
272
273
274BEGIN_MESSAGE_MAP(BrushOptions, COptionsPanel)
275 //{{AFX_MSG_MAP(BrushOptions)
276 ON_EN_CHANGE(IDC_FEATHER_EDIT, OnChangeFeatherEdit)
277 ON_EN_CHANGE(IDC_SIZE_EDIT, OnChangeSizeEdit)
278 ON_EN_CHANGE(IDC_HEIGHT_EDIT, OnChangeHeightEdit)
279 ON_WM_HSCROLL()
280 //}}AFX_MSG_MAP
281END_MESSAGE_MAP()
282
283
#define NULL
Definition BaseType.h:92
#define TRUE
Definition BaseType.h:109
#define DEBUG_CRASH(m)
Definition Debug.h:192
#define MAP_XY_FACTOR
Definition MapObject.h:60
#define MAP_HEIGHT_SCALE
Definition MapObject.h:61
#define IDC_HEIGHT_LABEL
Definition resource.h:198
#define IDC_FEATHER_LABEL
Definition resource.h:200
#define IDC_SIZE_POPUP
Definition resource.h:205
#define IDC_FEATHER_EDIT
Definition resource.h:155
#define IDC_SIZE_EDIT
Definition resource.h:206
#define IDC_HEIGHT_POPUP
Definition resource.h:189
#define IDC_FEATHER_POPUP
Definition resource.h:179
#define IDC_HEIGHT_EDIT
Definition resource.h:150
#define IDC_WIDTH_LABEL
Definition resource.h:197
#define BOOL
Definition Wnd_File.h:57
BrushOptions modeless (floating) dialog - allows entry and display of brush width and feather.
virtual void DoDataExchange(CDataExchange *pDX)
Windows default stuff.
static Int m_currentFeather
current feather width in the ui.
virtual void GetPopSliderInfo(const long sliderID, long *pMin, long *pMax, long *pLineSize, long *pInitial)
static void setFeather(Int feather)
Sets the feather value in the dialog.
static void setHeight(Int height)
afx_msg void OnChangeSizeEdit()
Handles width edit ui messages.
static BrushOptions * m_staticThis
Reference to the floating panel so SetWidth and SetFeather can be static.
BrushOptions(CWnd *pParent=NULL)
BrushOptions dialog trivial construstor - Create does the real work.
WBPopupSliderButton m_brushWidthPopup
afx_msg void OnChangeHeightEdit()
Handles width edit ui messages.
static void setWidth(Int width)
Sets the brush width value in the dialog.
virtual void PopSliderChanged(const long sliderID, long theVal)
afx_msg void OnChangeFeatherEdit()
Handles feather edit ui messages.
virtual void PopSliderFinished(const long sliderID, long theVal)
static Int m_currentWidth
current brush width in the ui.
WBPopupSliderButton m_brushHeightPopup
static Int m_currentHeight
Bool m_updating
true if the ui is updating itself.
WBPopupSliderButton m_brushFeatherPopup
virtual BOOL OnInitDialog()
Modeless dialogs don't close on ESC, so eat this for modeless.
static void setWidth(Int width)
Returns height.
Definition BrushTool.cpp:76
static void setHeight(Int height)
Set the brush height and notify the height options panel of the change.
Definition BrushTool.cpp:66
static void setFeather(Int feather)
Set the brush feather and notify the height options panel of the change.
Definition BrushTool.cpp:87