Debian Codegraph @

editor/SelectRangeDialog.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 // SelectRangeDialog.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23 #include "editor.h"
24 #include "SelectRangeDialog.h"
25 #include "terrain.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 // SelectRangeDialog dialog
35
36 SelectRangeDialog::SelectRangeDialog(CWnd *pParent /*=NULL*/) : CDialog(SelectRangeDialog::IDD, pParent) {
37 //{{AFX_DATA_INIT(SelectRangeDialog)
38 // NOTE: the ClassWizard will add member initialization here
39 //}}AFX_DATA_INIT
40 }
41
42 void SelectRangeDialog::DoDataExchange(CDataExchange *pDX) {
43 CDialog::DoDataExchange(pDX);
44 //{{AFX_DATA_MAP(SelectRangeDialog)
45 // NOTE: the ClassWizard will add DDX and DDV calls here
46 //}}AFX_DATA_MAP
47 }
48
49 BEGIN_MESSAGE_MAP(SelectRangeDialog, CDialog)
50 //{{AFX_MSG_MAP(SelectRangeDialog)
51 ON_EN_KILLFOCUS(IDC_LOWER_BOUND_EDIT, OnKillfocusLowerBoundEdit)
52 ON_EN_KILLFOCUS(IDC_UPPER_BOUND_EDIT, OnKillfocusUpperBoundEdit)
53 ON_BN_CLICKED(IDC_SELECT_SLOPE_CHECK, OnSelectSlopeCheck)
54 ON_EN_KILLFOCUS(IDC_SLOPE_EDIT, OnKillfocusSlopeEdit)
55 ON_BN_CLICKED(IDC_INVERSE_CHECK, OnInverseCheck)
56 ON_BN_CLICKED(IDC_TEXTURE_GRID_CHECK, OnTextureGridCheck)
57 ON_BN_CLICKED(IDC_RANDOM_CHECK, OnRandomCheck)
58 ON_BN_CLICKED(IDC_SELECT_CUR_TEXTURE_CHECK, OnSelectCurTextureCheck)
59 //}}AFX_MSG_MAP
60 END_MESSAGE_MAP()
61
62 /////////////////////////////////////////////////////////////////////////////
63 // SelectRangeDialog message handlers
64
65 void SelectRangeDialog::OnKillfocusLowerBoundEdit() {
66 CEdit *ebox;
67 char str[20];
68 int num;
69
70 ebox = (CEdit *)GetDlgItem(IDC_LOWER_BOUND_EDIT);
71 ebox->GetWindowText(str, 20);
72
73 num = atoi(str);
74 if (num < 0)
75 num = 0;
76 if (num > 255)
77 num = 255;
78
79 LowerBound = num;
80 }
81
82 void SelectRangeDialog::OnKillfocusUpperBoundEdit() {
83 CEdit *ebox;
84 char str[20];
85 int num;
86
87 ebox = (CEdit *)GetDlgItem(IDC_UPPER_BOUND_EDIT);
88 ebox->GetWindowText(str, 20);
89
90 num = atoi(str);
91 if (num < 0)
92 num = 0;
93 if (num > 255)
94 num = 255;
95
96 UpperBound = num;
97 }
98
99 void SelectRangeDialog::OnOK() {
100 OnKillfocusUpperBoundEdit();
101 OnKillfocusLowerBoundEdit();
102 OnKillfocusSlopeEdit();
103
104 int use_slope = IsDlgButtonChecked(IDC_SELECT_SLOPE_CHECK);
105 int inverted = IsDlgButtonChecked(IDC_INVERSE_CHECK);
106 int texgrid = IsDlgButtonChecked(IDC_TEXTURE_GRID_CHECK);
107 int random = IsDlgButtonChecked(IDC_RANDOM_CHECK);
108 int cur_texture = IsDlgButtonChecked(IDC_SELECT_CUR_TEXTURE_CHECK);
109
110 if (UpperBound < LowerBound) {
111 OutrageMessageBox("Lower bound must be less than upper bound!");
112 } else {
113 for (int i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++)
114 TerrainSelected[i] = 0;
115 Num_terrain_selected = 0;
116 for (i = 0; i < TERRAIN_WIDTH * TERRAIN_DEPTH; i++) {
117 int selected = 1;
118
119 if (!(Terrain_seg[i].ypos >= LowerBound && Terrain_seg[i].ypos <= UpperBound))
120 selected = 0;
121
122 if (use_slope) {
123 int x = i % TERRAIN_WIDTH;
124 int z = i / TERRAIN_WIDTH;
125
126 if (x != (TERRAIN_WIDTH - 1)) {
127 if (!((abs(Terrain_seg[i].ypos - Terrain_seg[z * TERRAIN_WIDTH + (x + 1)].ypos)) >= SlopeAngle))
128 selected = 0;
129
130 if (z != (TERRAIN_DEPTH - 1)) {
131 if (!((abs(Terrain_seg[i].ypos - Terrain_seg[(z + 1) * TERRAIN_WIDTH + (x + 1)].ypos)) >= SlopeAngle))
132 selected = 0;
133 }
134 }
135
136 if (z != (TERRAIN_DEPTH - 1)) {
137 if (!((abs(Terrain_seg[i].ypos - Terrain_seg[(z + 1) * TERRAIN_WIDTH + (x)].ypos)) >= SlopeAngle))
138 selected = 0;
139 }
140 }
141
142 if (random) {
143 if (rand() > (RAND_MAX / 2))
144 selected = 0;
145 }
146
147 if (texgrid) {
148 int x = i % TERRAIN_WIDTH;
149 int z = i / TERRAIN_WIDTH;
150
151 if (x % (1 << (MAX_TERRAIN_LOD - 1)))
152 selected = 0;
153
154 if (z % (1 << (MAX_TERRAIN_LOD - 1)))
155 selected = 0;
156 }
157
158 if (cur_texture) {
159 if (Terrain_tex_seg[Terrain_seg[i].texseg_index].tex_index != D3EditState.texdlg_texture)
160 selected = 0;
161 }
162
163 if (inverted)
164 selected = !selected;
165
166 if (selected) {
167 TerrainSelected[i] = 1;
168 Num_terrain_selected++;
169 }
170 }
171 }
172
173 CDialog::OnOK();
174 }
175
176 void SelectRangeDialog::OnCancel() {
177 // TODO: Add extra cleanup here
178
179 CDialog::OnCancel();
180 }
181
182 void SelectRangeDialog::OnSelectSlopeCheck() {
183 int c = IsDlgButtonChecked(IDC_SELECT_SLOPE_CHECK);
184
185 CButton *bbox = (CButton *)GetDlgItem(IDC_SLOPE_EDIT);
186 bbox->EnableWindow(c);
187 }
188
189 void SelectRangeDialog::OnKillfocusSlopeEdit() {
190 CEdit *ebox;
191 char str[20];
192 int num;
193
194 ebox = (CEdit *)GetDlgItem(IDC_SLOPE_EDIT);
195 ebox->GetWindowText(str, 20);
196
197 num = atoi(str);
198 if (num < 0)
199 num = 0;
200 if (num > 255)
201 num = 255;
202
203 SlopeAngle = num;
204 }
205
206 void SelectRangeDialog::OnInverseCheck() {}
207
208 void SelectRangeDialog::OnTextureGridCheck() {
209 // TODO: Add your control notification handler code here
210 }
211
212 void SelectRangeDialog::OnRandomCheck() {
213 // TODO: Add your control notification handler code here
214 }
215
216 void SelectRangeDialog::OnSelectCurTextureCheck() {
217 // TODO: Add your control notification handler code here
218 }