Debian Codegraph @

editor/BriefTextEdit.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 // BriefTextEdit.cpp : implementation file
20 //
21
22 #include "stdafx.h"
23 #include "editor.h"
24 #include "BriefTextEdit.h"
25 #include "BriefEdit.h"
26 #include "BriefMissionFlagsDlg.h"
27
28 #ifdef _DEBUG
29 #define new DEBUG_NEW
30 #undef THIS_FILE
31 static char THIS_FILE[] = __FILE__;
32 #endif
33
34 /////////////////////////////////////////////////////////////////////////////
35 // CBriefTextEdit dialog
36
37 CBriefTextEdit::CBriefTextEdit(int curr_screen, TCTEXTDESC *d, char *text_buffer, int id, CWnd *pParent /*=NULL*/)
38 : CDialog(CBriefTextEdit::IDD, pParent) {
39 m_Screen = curr_screen;
40 //{{AFX_DATA_INIT(CBriefTextEdit)
41 m_iID = 0;
42 m_iBY = 0;
43 m_iRX = 0;
44 m_fSpeed = 0.0f;
45 m_fStartTime = 0.0f;
46 m_iTY = 0;
47 m_iLX = 0;
48 m_iEffectType = -1;
49 m_sDesc = _T("");
50 m_iBlue = 0;
51 m_iGreen = 0;
52 m_iRed = 0;
53 m_TabStop = FALSE;
54 //}}AFX_DATA_INIT
55
56 memset(&desc, 0, sizeof(TCTEXTDESC));
57
58 // set defaults
59 desc.type = TC_TEXT_STATIC;
60 desc.font = BRIEF_FONT_INDEX;
61 desc.color = GR_GREEN;
62 desc.speed = 1.0f;
63 desc.looping = false;
64 desc.waittime = 0;
65 desc.textbox.left = desc.textbox.top = 0;
66 desc.textbox.right = 639;
67 desc.textbox.bottom = 479;
68 desc.mission_mask_set = 0;
69 desc.mission_mask_unset = 0;
70
71 m_TabStop = false;
72 if (d) {
73 desc.caps = d->caps;
74 desc.flags = d->flags;
75 desc.type = d->type;
76 // fill in values
77 if (d->caps & TCTD_FONT)
78 desc.font = d->font;
79 if (d->caps & TCTD_COLOR)
80 desc.color = d->color;
81 if (d->caps & TCTD_SPEED)
82 desc.speed = d->speed;
83 if (d->caps & TCTD_LOOPING)
84 desc.looping = d->looping;
85 if (d->caps & TCTD_TEXTBOX)
86 memcpy(&desc.textbox, &d->textbox, sizeof(tc_text));
87 if (d->caps & TCTD_WAITTIME)
88 desc.waittime = d->waittime;
89 if (d->caps & TCTD_TABSTOP)
90 m_TabStop = true;
91
92 desc.mission_mask_set = d->mission_mask_set;
93 desc.mission_mask_unset = d->mission_mask_unset;
94 }
95
96 if (text_buffer)
97 m_Text = text_buffer;
98 else
99 m_Text = "";
100
101 // Set window dialog information
102 m_iID = id;
103 m_iBY = desc.textbox.bottom;
104 m_iRX = desc.textbox.right;
105 m_iTY = desc.textbox.top;
106 m_iLX = desc.textbox.left;
107 m_fSpeed = desc.speed;
108 m_fStartTime = desc.waittime;
109 m_iRed = GR_COLOR_RED(desc.color);
110 m_iGreen = GR_COLOR_GREEN(desc.color);
111 m_iBlue = GR_COLOR_BLUE(desc.color);
112
113 switch (desc.type) {
114 case TC_TEXT_STATIC:
115 m_iEffectType = 0;
116 break;
117 case TC_TEXT_SCROLL:
118 switch (desc.flags) {
119 case TC_TEXTF_L2R:
120 m_iEffectType = 4;
121 break;
122 case TC_TEXTF_R2L:
123 m_iEffectType = 5;
124 break;
125 case TC_TEXTF_T2B:
126 m_iEffectType = 6;
127 break;
128 case TC_TEXTF_B2T:
129 m_iEffectType = 7;
130 break;
131 default:
132 m_iEffectType = 4;
133 break;
134 }
135 break;
136 case TC_TEXT_FADE:
137 switch (desc.flags) {
138 case TC_TEXTF_IN:
139 m_iEffectType = 2;
140 break;
141 case TC_TEXTF_OUT:
142 m_iEffectType = 3;
143 break;
144 default:
145 m_iEffectType = 2;
146 break;
147 }
148 break;
149 case TC_TEXT_FLASH:
150 m_iEffectType = 1;
151 break;
152 default:
153 m_iEffectType = 0;
154 }
155 }
156
157 void CBriefTextEdit::DoDataExchange(CDataExchange *pDX) {
158 CDialog::DoDataExchange(pDX);
159 //{{AFX_DATA_MAP(CBriefTextEdit)
160 DDX_Text(pDX, IDC_BRIEF_T_ID, m_iID);
161 DDX_Text(pDX, IDC_BRIEF_T_LR_Y, m_iBY);
162 DDV_MinMaxInt(pDX, m_iBY, 0, 479);
163 DDX_Text(pDX, IDC_BRIEF_T_LR_X, m_iRX);
164 DDV_MinMaxInt(pDX, m_iRX, 0, 639);
165 DDX_Text(pDX, IDC_BRIEF_T_SPEED, m_fSpeed);
166 DDV_MinMaxFloat(pDX, m_fSpeed, 0.f, 99999.f);
167 DDX_Text(pDX, IDC_BRIEF_T_STARTTIME, m_fStartTime);
168 DDV_MinMaxFloat(pDX, m_fStartTime, 0.f, 99999.f);
169 DDX_Text(pDX, IDC_BRIEF_T_UL_Y, m_iTY);
170 DDV_MinMaxInt(pDX, m_iTY, 0, 479);
171 DDX_Text(pDX, IDC_BRIEF_T_UL_X, m_iLX);
172 DDV_MinMaxInt(pDX, m_iLX, 0, 639);
173 DDX_Radio(pDX, IDC_BRIEF_T_STATIC, m_iEffectType);
174 DDX_Text(pDX, IDC_BRIEF_T_DESC, m_sDesc);
175 DDX_Text(pDX, IDC_BRIEF_COLOR_B, m_iBlue);
176 DDX_Text(pDX, IDC_BRIEF_COLOR_G, m_iGreen);
177 DDX_Text(pDX, IDC_BRIEF_COLOR_R, m_iRed);
178 DDX_Check(pDX, IDC_TABSTOP, m_TabStop);
179 //}}AFX_DATA_MAP
180 }
181
182 BEGIN_MESSAGE_MAP(CBriefTextEdit, CDialog)
183 //{{AFX_MSG_MAP(CBriefTextEdit)
184 ON_BN_CLICKED(IDC_BRIEF_COLOR_PAL, OnBriefColorPal)
185 ON_CBN_SELCHANGE(IDC_BRIEF_T_PREDEF, OnSelchangeBriefTPredef)
186 ON_BN_CLICKED(IDC_MISSIONFLAGS, OnMissionflags)
187 //}}AFX_MSG_MAP
188 END_MESSAGE_MAP()
189
190 /////////////////////////////////////////////////////////////////////////////
191 // CBriefTextEdit message handlers
192
193 void CBriefTextEdit::OnOK() {
194 UpdateData(true);
195
196 // Set window dialog information
197 desc.caps = TCTD_FONT | TCTD_COLOR | TCTD_SPEED | TCTD_LOOPING | TCTD_WAITTIME | TCTD_TEXTBOX | TCTD_SCROLL;
198 desc.textbox.bottom = m_iBY;
199 desc.textbox.right = m_iRX;
200 desc.textbox.top = m_iTY;
201 desc.textbox.left = m_iLX;
202 desc.speed = m_fSpeed;
203 desc.waittime = m_fStartTime;
204 desc.color = GR_RGB(m_iRed, m_iGreen, m_iBlue);
205
206 if (m_TabStop)
207 desc.caps |= TCTD_TABSTOP;
208
209 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_T_FONT);
210 if (combo->GetCurSel() == 1)
211 desc.font = BBRIEF_FONT_INDEX;
212 else
213 desc.font = BRIEF_FONT_INDEX;
214
215 switch (m_iEffectType) {
216 case 0:
217 desc.type = TC_TEXT_STATIC;
218 break;
219 case 1:
220 desc.type = TC_TEXT_FLASH;
221 break;
222 case 2:
223 desc.type = TC_TEXT_FADE;
224 desc.flags = TC_TEXTF_IN;
225 break;
226 case 3:
227 desc.type = TC_TEXT_FADE;
228 desc.flags = TC_TEXTF_OUT;
229 break;
230 case 4:
231 desc.type = TC_TEXT_SCROLL;
232 desc.flags = TC_TEXTF_L2R;
233 break;
234 case 5:
235 desc.type = TC_TEXT_SCROLL;
236 desc.flags = TC_TEXTF_R2L;
237 break;
238 case 6:
239 desc.type = TC_TEXT_SCROLL;
240 desc.flags = TC_TEXTF_T2B;
241 break;
242 case 7:
243 desc.type = TC_TEXT_SCROLL;
244 desc.flags = TC_TEXTF_B2T;
245 break;
246 };
247
248 m_RichEdit.GetWindowText(m_Text);
249
250 CDialog::OnOK();
251 }
252
253 BOOL CBriefTextEdit::OnInitDialog() {
254 RECT rect;
255 CWnd *wnd;
256 PARAFORMAT pf;
257 CHARFORMAT cf;
258
259 m_RichEditInit = false;
260
261 CDialog::OnInitDialog();
262
263 // Create our Rich Edit Control add keyboard handler for those SPECIAL keys like TAB.
264 wnd = GetDlgItem(IDC_RICHFRAME);
265 wnd->GetWindowRect(&rect);
266 rect.left += 2;
267 rect.right -= 2;
268 rect.top += 2;
269 rect.bottom -= 2;
270 ScreenToClient(&rect);
271 m_RichEdit.Create(WS_CHILD | WS_VISIBLE | ES_LEFT | ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL | ES_SAVESEL |
272 ES_NOHIDESEL | WS_VSCROLL,
273 rect, this, IDC_SCRIPTVIEW);
274 m_RichEdit.SetEventMask(ENM_KEYEVENTS | ENM_MOUSEEVENTS);
275
276 m_RichEdit.LimitText(0);
277 m_RichEdit.GetParaFormat(pf);
278
279 pf.cbSize = sizeof(pf);
280 pf.dwMask = PFM_TABSTOPS;
281 pf.cTabCount = MAX_TAB_STOPS;
282 for (int i = 0; i < pf.cTabCount; i++)
283 pf.rgxTabs[i] = 360 * (i + 1);
284
285 m_RichEdit.SetParaFormat(pf);
286
287 // sets character format
288 ZeroMemory(&cf, sizeof(cf));
289 cf.dwMask = CFM_FACE | CFM_CHARSET | CFM_BOLD;
290 strcpy(cf.szFaceName, "Courier");
291 cf.bCharSet = DEFAULT_CHARSET;
292 cf.bPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
293 m_RichEdit.SetDefaultCharFormat(cf);
294
295 ///////////////
296
297 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_T_FONT);
298
299 combo->AddString("sm_brief");
300 combo->AddString("lg_brief");
301
302 if (desc.font == BRIEF_FONT_INDEX)
303 combo->SetCurSel(0);
304 else
305 combo->SetCurSel(1);
306
307 combo = (CComboBox *)GetDlgItem(IDC_BRIEF_T_PREDEF);
308 combo->AddString("<Raw>");
309 combo->SetCurSel(0);
310
311 int layout = -1;
312
313 for (int i = 0; i < (*PBnum_layouts); i++) {
314 if (!stricmp(Briefing_screens[m_Screen].layout, PBlayouts[i].filename))
315 layout = i;
316 }
317
318 if (layout != -1) {
319 int count = PBlayouts[layout].num_texts;
320 for (int j = 0; j < count; j++) {
321 char buffer[100];
322 sprintf(buffer, "(%d,%d)->(%d,%d)", PBlayouts[layout].texts[j].lx, PBlayouts[layout].texts[j].ty,
323 PBlayouts[layout].texts[j].rx, PBlayouts[layout].texts[j].by);
324 combo->AddString(buffer);
325 }
326 }
327
328 m_RichEdit.SetWindowText((LPCSTR)m_Text.GetBuffer(0));
329
330 UpdateData(false);
331
332 return TRUE;
333 }
334
335 void CBriefTextEdit::OnBriefColorPal() {
336 UpdateData(true);
337 CColorDialog dlg;
338
339 if (dlg.DoModal() == IDOK) {
340 COLORREF ref;
341 ref = dlg.GetColor();
342 m_iRed = GetRValue(ref);
343 m_iGreen = GetGValue(ref);
344 m_iBlue = GetBValue(ref);
345 }
346 UpdateData(false);
347 }
348
349 void CBriefTextEdit::OnSelchangeBriefTPredef() {
350 CComboBox *combo = (CComboBox *)GetDlgItem(IDC_BRIEF_T_PREDEF);
351 int item = combo->GetCurSel();
352
353 if (item <= 0)
354 return;
355
356 UpdateData(true);
357
358 int layout = -1;
359
360 for (int i = 0; i < (*PBnum_layouts); i++) {
361 if (!stricmp(Briefing_screens[m_Screen].layout, PBlayouts[i].filename))
362 layout = i;
363 }
364
365 if (layout != -1) {
366 m_iLX = PBlayouts[layout].texts[item - 1].lx;
367 m_iTY = PBlayouts[layout].texts[item - 1].ty;
368 m_iRX = PBlayouts[layout].texts[item - 1].rx;
369 m_iBY = PBlayouts[layout].texts[item - 1].by;
370 UpdateData(false);
371 }
372 }
373
374 void CBriefTextEdit::OnMissionflags() {
375 CBriefMissionFlagsDlg dlg(desc.mission_mask_set, desc.mission_mask_unset);
376
377 if (dlg.DoModal()) {
378 desc.mission_mask_set = dlg.m_Set;
379 desc.mission_mask_unset = dlg.m_UnSet;
380 }
381 }