Debian Codegraph @

editor/MegacellKeypad.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 // MegacellKeypad.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23 #include "editor.h"
24 #include "MegacellKeypad.h"
25 #include "megacell.h"
26 #include "terrain.h"
27 #include "terraindialog.h"
28
29 #ifdef _DEBUG
30 #define new DEBUG_NEW
31 #undef THIS_FILE
32 static char THIS_FILE[] = __FILE__;
33 #endif
34
35 /////////////////////////////////////////////////////////////////////////////
36 // CMegacellKeypad dialog
37
38 int CMegacellKeypad::m_Instances = 0;
39
40 CMegacellKeypad::CMegacellKeypad(CWnd *pParent /*=NULL*/) : CKeypadDialog(CMegacellKeypad::IDD, pParent) {
41 //{{AFX_DATA_INIT(CMegacellKeypad)
42 // NOTE: the ClassWizard will add member initialization here
43 //}}AFX_DATA_INIT
44 }
45
46 void CMegacellKeypad::DoDataExchange(CDataExchange *pDX) {
47 CDialog::DoDataExchange(pDX);
48 //{{AFX_DATA_MAP(CMegacellKeypad)
49 // NOTE: the ClassWizard will add DDX and DDV calls here
50 //}}AFX_DATA_MAP
51 }
52
53 BEGIN_MESSAGE_MAP(CMegacellKeypad, CDialog)
54 //{{AFX_MSG_MAP(CMegacellKeypad)
55 ON_WM_DESTROY()
56 ON_WM_SIZE()
57 ON_WM_VSCROLL()
58 ON_WM_HSCROLL()
59 ON_BN_CLICKED(IDC_NEXT_MEGA_SET, OnNextMegaSet)
60 ON_BN_CLICKED(IDC_PREV_MEGA_SET, OnPrevMegaSet)
61 ON_WM_PAINT()
62 ON_BN_CLICKED(IDC_FILL_WITH_MEGACELL, OnFillWithMegacell)
63 ON_BN_CLICKED(IDC_RANDOMIZE_MEGACELL_CHECK, OnRandomizeMegacellCheck)
64 ON_BN_CLICKED(IDC_SELECT_FROM_MEGACELL, OnSelectFromMegacell)
65 ON_BN_CLICKED(IDC_UNIFY_MEGACELL, OnUnifyMegacell)
66 ON_WM_HELPINFO()
67 ON_EN_KILLFOCUS(IDC_X_GRANULAR_EDIT, OnKillfocusXGranularEdit)
68 ON_EN_KILLFOCUS(IDC_Y_GRANULAR_EDIT, OnKillfocusYGranularEdit)
69 ON_BN_CLICKED(IDC_HIGHLIGHT_BORDERS, OnHighlightBorders)
70 ON_BN_CLICKED(IDC_MEGACELL_SKYDOME, OnMegacellSkydome)
71 ON_BN_CLICKED(IDC_MEGACELL_SKYBAND, OnMegacellSkyband)
72 //}}AFX_MSG_MAP
73 END_MESSAGE_MAP()
74
75 /////////////////////////////////////////////////////////////////////////////
76 // CMegacellKeypad message handlers
77
78 void CMegacellKeypad::OnDestroy() {
79 CDialog::OnDestroy();
80
81 if (m_Instances > 0)
82 m_Instances--;
83 }
84
85 BOOL CMegacellKeypad::OnInitDialog() {
86 CDialog::OnInitDialog();
87
88 ((CButton *)GetDlgItem(IDC_RANDOMIZE_MEGACELL_CHECK))->SetCheck(D3EditState.randomize_megacell);
89
90 m_Instances++;
91 m_xgran = 1;
92 m_ygran = 1;
93
94 UpdateDialog();
95
96 return TRUE; // return TRUE unless you set the focus to a control
97 // EXCEPTION: OCX Property Pages should return FALSE
98 }
99
100 void CMegacellKeypad::OnSize(UINT nType, int cx, int cy) {
101 CKeypadDialog::OnSize(nType, cx, cy);
102
103 // Add your code here, sweetie.
104 }
105
106 void CMegacellKeypad::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) {
107 // TODO: Add your message handler code here and/or call default
108
109 CKeypadDialog::OnVScroll(nSBCode, nPos, pScrollBar);
110 }
111
112 void CMegacellKeypad::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar) {
113 // TODO: Add your message handler code here and/or call default
114
115 CKeypadDialog::OnHScroll(nSBCode, nPos, pScrollBar);
116 }
117
118 void CMegacellKeypad::OnNextMegaSet() {
119 D3EditState.current_megacell = GetNextMegacell(D3EditState.current_megacell);
120 m_xgran = m_ygran = 1;
121 UpdateDialog();
122 }
123
124 void CMegacellKeypad::OnPrevMegaSet() {
125 D3EditState.current_megacell = GetPrevMegacell(D3EditState.current_megacell);
126 m_xgran = m_ygran = 1;
127 UpdateDialog();
128 }
129
130 void CMegacellKeypad::OnPaint() {
131 CPaintDC dc(this); // device context for painting
132
133 // This is added so we don't paint this dialog when it's inactive.
134 if (!m_Active)
135 return;
136
137 UpdateDialog();
138 }
139
140 void CMegacellKeypad::UpdateDialog() {
141 if (Num_megacells < 1)
142 return;
143
144 int n = D3EditState.current_megacell;
145 char str[255];
146 CEdit *ebox;
147
148 if (!Megacells[n].used) {
149 n = GetNextMegacell(n);
150 D3EditState.current_megacell = n;
151 }
152
153 ebox = (CEdit *)GetDlgItem(IDC_MEGACELL_NAME_STATIC);
154 sprintf(str, "Megacell name: %s", Megacells[n].name);
155 ebox->SetWindowText(str);
156
157 ebox = (CEdit *)GetDlgItem(IDC_MEGA_WIDTH_STATIC);
158 sprintf(str, "Width: %d", Megacells[n].width);
159 ebox->SetWindowText(str);
160
161 ebox = (CEdit *)GetDlgItem(IDC_MEGA_HEIGHT_STATIC);
162 sprintf(str, "Height: %d", Megacells[n].height);
163 ebox->SetWindowText(str);
164
165 ebox = (CEdit *)GetDlgItem(IDC_X_GRANULAR_EDIT);
166 sprintf(str, "%d", m_xgran);
167 ebox->SetWindowText(str);
168
169 ebox = (CEdit *)GetDlgItem(IDC_Y_GRANULAR_EDIT);
170 sprintf(str, "%d", m_ygran);
171 ebox->SetWindowText(str);
172
173 UpdateMegaSetView();
174 }
175
176 void CMegacellKeypad::UpdateMegaSetView() {
177 int n = D3EditState.current_megacell;
178 CWnd *texwnd;
179 RECT rect;
180 int x, y, bm_handle, w, h;
181 int megawidth = Megacells[n].width;
182 int megaheight = Megacells[n].height;
183 int i, t;
184
185 Desktop_surf->attach_to_window((unsigned)m_hWnd);
186
187 texwnd = GetDlgItem(IDC_MEGACELL_SET_VIEW);
188 texwnd->GetWindowRect(&rect);
189 ScreenToClient(&rect);
190 w = rect.right - rect.left;
191 h = rect.bottom - rect.top;
192
193 Desktop_surf->clear(rect.left, rect.top, w, h);
194
195 if (megawidth > 0) {
196 int texwidth = w / megawidth;
197 int texheight = h / megaheight;
198
199 // Don't have to clear if we're overwriting the whole area!
200
201 for (i = 0; i < megaheight; i++) {
202 for (t = 0; t < megawidth; t++) {
203 m_TextureSurf.create(texwidth, texheight, BPP_16);
204
205 bm_handle = GetTextureBitmap(Megacells[n].texture_handles[i * MAX_MEGACELL_WIDTH + t], 0);
206 m_TextureSurf.load(bm_handle);
207
208 x = 1 + rect.left + (t * texwidth);
209 y = 1 + rect.top + (i * texheight);
210
211 Desktop_surf->blt(x, y, &m_TextureSurf);
212
213 m_TextureSurf.free();
214 }
215 }
216 }
217
218 Desktop_surf->attach_to_window((unsigned)NULL);
219 }
220
221 void CMegacellKeypad::OnFillWithMegacell() { return; }
222
223 void CMegacellKeypad::OnRandomizeMegacellCheck() {
224 // TODO: Add your control notification handler code here
225 D3EditState.randomize_megacell = (((CButton *)GetDlgItem(IDC_RANDOMIZE_MEGACELL_CHECK))->GetCheck() != 0);
226 }
227
228 // Selects all the cells that has textures from the currently selected megacell
229 void CMegacellKeypad::OnSelectFromMegacell() {}
230
231 // Fill only the selected cells with this megacell
232 void CMegacellKeypad::OnUnifyMegacell() {}
233
234 BOOL CMegacellKeypad::OnHelpInfo(HELPINFO *pHelpInfo) {
235 // TODO: Add your message handler code here and/or call default
236 WinHelp(HID_MEGACELLTAB, HELP_CONTEXT);
237 return TRUE;
238 // return CDialog::OnHelpInfo(pHelpInfo);
239 }
240
241 void CMegacellKeypad::OnKillfocusXGranularEdit() {
242 CEdit *ebox;
243 char name[20];
244 int n = D3EditState.current_megacell;
245 int val;
246
247 ebox = (CEdit *)GetDlgItem(IDC_X_GRANULAR_EDIT);
248 ebox->GetWindowText(name, 20);
249
250 val = atoi(name);
251
252 if (val < 1)
253 val = 1;
254 if (val > Megacells[n].width)
255 val = Megacells[n].width;
256
257 m_xgran = val;
258
259 UpdateDialog();
260 }
261
262 void CMegacellKeypad::OnKillfocusYGranularEdit() {
263 CEdit *ebox;
264 char name[20];
265 int n = D3EditState.current_megacell;
266 int val;
267
268 ebox = (CEdit *)GetDlgItem(IDC_Y_GRANULAR_EDIT);
269 ebox->GetWindowText(name, 20);
270
271 val = atoi(name);
272
273 if (val < 1)
274 val = 1;
275 if (val > Megacells[n].height)
276 val = Megacells[n].height;
277
278 m_ygran = val;
279
280 UpdateDialog();
281 }
282
283 void CMegacellKeypad::OnHighlightBorders() {}
284
285 void CMegacellKeypad::OnMegacellSkydome() {}
286
287 void CMegacellKeypad::OnMegacellSkyband() {}