-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextureDialog.cpp
621 lines (514 loc) · 15.2 KB
/
TextureDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/****************************************************************************************/
/* TextureDialog.cpp */
/* */
/* Author: Jim Mischel, Ken Baird, Jeff Lomax, John Moore */
/* Description: Texture tab code */
/* */
/* The contents of this file are subject to the Genesis3D Public License */
/* Version 1.01 (the "License"); you may not use this file except in */
/* compliance with the License. You may obtain a copy of the License at */
/* http://www.genesis3d.com */
/* */
/* Software distributed under the License is distributed on an "AS IS" */
/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
/* the License for the specific language governing rights and limitations */
/* under the License. */
/* */
/* The Original Code is Genesis3D, released March 25, 1999. */
/* Genesis3D Version 1.1 released November 15, 1999 */
/* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */
/* */
/****************************************************************************************/
#include "stdafx.h"
#include "TextureDialog.h"
#include "FusionTabControls.h"
#include "FUSIONDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define LB_BORDER_SIZE_TOP 5
#define LB_BORDER_SIZE_LEFT 5
#define LB_WIDTH 150
#define LB_HEIGHT 175
#define BM_BORDER_SIZE_TOP 185
#define BM_BORDER_SIZE_LEFT 60
#define BM_WIDTH 256
#define BM_HEIGHT 256
#define SIZETEXT_BORDER_SIZE_TOP 452
#define SIZETEXT_BORDER_SIZE_LEFT 60
//extern TexInfo TexInf[MAX_EDGES];
CTextureDialog::CTextureDialog(CFusionTabControls* pParent /*=NULL*/, CFusionDoc* pDoc)
: CDialog(CTextureDialog::IDD, (CWnd*) pParent)
{
//{{AFX_DATA_INIT(CTextureDialog)
//}}AFX_DATA_INIT
// Let's save our pointers...
m_pDoc = pDoc;
m_pParentCtrl = pParent;
CDialog::Create( IDD, (CWnd*) pParent );
//SetupDialog();
}
CTextureDialog::~CTextureDialog()
{
m_TxlibChanged = false;
}
void CTextureDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTextureDialog)
DDX_Control(pDX, IDC_REMOVETEXTURE, m_RemoveTexture);
DDX_Control(pDX, IDC_NEWTEXTURE, m_NewTexture);
DDX_Control(pDX, IDC_EDITTEXTURE, m_EditTexture);
DDX_Control(pDX, IDC_SIZETEXT, m_SizeText);
DDX_Control(pDX, IDC_APPLYTEXTURE, m_ApplyButton);
DDX_Control(pDX, IDC_TEXTUREIMAGE, m_TextureImage);
DDX_Control(pDX, IDC_TEXTURELIST, m_TextureList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTextureDialog, CDialog)
//{{AFX_MSG_MAP(CTextureDialog)
ON_BN_CLICKED(IDC_APPLYTEXTURE, OnApply)
ON_CBN_SELCHANGE(IDC_TEXTURELIST, OnSelchangetexturelist)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTextureDialog message handlers
void CTextureDialog::FillTheListbox ()
{
CWadFile *pWad;
m_TextureList.ResetContent();
pWad = Level_GetWadFile (m_pDoc->pLevel);
// fill list box with texture names...
for (int index = 0; index < pWad->mBitmapCount; index++)
{
CString Name = pWad->mBitmaps[index].Name;
// Listbox is sorted, so we need to put the wad file index into the item data.
int lbIndex = m_TextureList.AddString( (LPCTSTR) Name );
if (lbIndex != LB_ERR)
{
m_TextureList.SetItemData (lbIndex, index);
}
}
}
BOOL CTextureDialog::OnInitDialog()
{
//
// At this point, all of the controls are created, but
// they're in the wrong places.
// We position and size them here...
//
CDialog::OnInitDialog ();
// Position the new dialog on the tab...
RECT rect;
RECT rect2;
m_pParentCtrl->GetClientRect( &rect );
m_pParentCtrl->GetItemRect( 0, &rect2 );
rect.top = rect2.bottom + FTC_BORDER_SIZE_TOP;
rect.left = rect.left + FTC_BORDER_SIZE_LEFT;
rect.right = rect.right - FTC_BORDER_SIZE_RIGHT ;
rect.bottom = rect.bottom - FTC_BORDER_SIZE_BOTTOM ;
SetWindowPos( NULL, rect.left,
rect.top, rect.right, rect.bottom, SWP_NOZORDER );
rect.left = LB_BORDER_SIZE_LEFT;
rect.top = LB_BORDER_SIZE_TOP;
rect.right = rect.left + LB_WIDTH;
rect.bottom = rect.top + LB_HEIGHT;
m_TextureList.SetWindowPos
(
NULL,
LB_BORDER_SIZE_LEFT, LB_BORDER_SIZE_TOP, // position
LB_WIDTH, LB_HEIGHT, // size
(SWP_NOACTIVATE | SWP_NOZORDER)
);
// pWad = Level_GetWadFile (m_pDoc->pLevel);
FillTheListbox ();
// move the button...
int left = rect.right + 10;
int top = rect.top;
// put the button to the right of the listbox
m_ApplyButton.SetWindowPos (NULL, left, top, 0, 0, (SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
m_EditTexture.SetWindowPos (NULL, left, top+30, 0, 0, (SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
m_NewTexture.SetWindowPos (NULL, left, top+60, 0, 0, (SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
m_RemoveTexture.SetWindowPos (NULL, left, top+90, 0, 0, (SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
// and the size text at the bottom of the listbox
m_SizeText.GetClientRect (&rect2);
top = rect.bottom - rect2.bottom;
m_SizeText.SetWindowPos (NULL, left, top, 0, 0, (SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER));
// Create the bitmap image...
m_TextureRect.top = rect.bottom + 10; //BM_BORDER_SIZE_TOP;
m_TextureRect.left = rect.left; //BM_BORDER_SIZE_LEFT;
m_TextureRect.bottom = m_TextureRect.top + BM_HEIGHT;
m_TextureRect.right = m_TextureRect.left + BM_WIDTH;
m_TextureImage.SetWindowPos
(
NULL,
m_TextureRect.left, m_TextureRect.top,
BM_HEIGHT, BM_WIDTH,
(SWP_NOACTIVATE | SWP_NOZORDER)
);
// Set the current selection to the first...
int index=0;
CString FirstName;
m_TextureList.SetCurSel(0);
index = m_TextureList.GetCurSel ();
if (index == LB_ERR)
{
m_CurrentTexture = "Invalid";
return TRUE;
}
index = 0;
m_TextureList.GetText(0, FirstName);
while(!isalpha(FirstName[0]))
m_TextureList.GetText(++index, FirstName);
m_TextureList.GetText( m_TextureList.GetCurSel(), FirstName );
m_CurrentTexture = FirstName;
// Update bitmap image and size
UpdateBitmap();
UpdateSize();
return TRUE;
}
static void TextureFace
(
Face *pFace,
int SelId,
char const *Name,
WadFileEntry* pbmp // changed QD 12/03
)
{
Face_SetTextureDibId (pFace, SelId);
Face_SetTextureName (pFace, Name);
// changed QD 12/03
Face_SetTextureSize (pFace, pbmp->Width, pbmp->Height);
// end change
}
// changed QD 12/03
static void TextureBrushList(BrushList *pList, int SelId, char const *Name, WadFileEntry* pbmp);
static void TextureBrush
(
Brush *pBrush,
int SelId,
char const *Name,
WadFileEntry* pbmp // changed QD 12/03
)
{
int j;
assert(pBrush);
if(Brush_IsMulti(pBrush))
{
// changed QD 12/03
TextureBrushList((BrushList *)Brush_GetBrushList(pBrush), SelId, Name, pbmp);
}
else
{
for (j = 0; j < Brush_GetNumFaces (pBrush); ++j)
{
Face *pFace;
pFace = Brush_GetFace (pBrush, j);
TextureFace (pFace, SelId, Name, pbmp); // changed QD 12/03
}
}
}
static void TextureBrushList
(
BrushList *pList,
int SelId,
char const *Name,
WadFileEntry* pbmp // changed QD 12/03
)
{
Brush *b;
BrushIterator bi;
assert(pList);
assert(Name);
#pragma message ("Change this and the function above to use BrushList_EnumAll")
for(b=BrushList_GetFirst(pList, &bi);b;b=BrushList_GetNext(&bi))
{
TextureBrush(b, SelId, Name, pbmp); // changed QD 12/03
}
}
// We need to set the current texture to all applicable faces
// in the document's active brush list...
void CTextureDialog::OnApply()
{
int SelectedItem;
int SelId;
int i;
SelectedItem =m_TextureList.GetCurSel();
SelId = m_TextureList.GetItemData (SelectedItem);
if(m_pDoc->mModeTool==ID_TOOLS_TEMPLATE)
return;
switch (m_pDoc->mAdjustMode)
{
case ADJUST_MODE_FACE :
{
int Size;
Size = SelFaceList_GetSize (m_pDoc->pSelFaces);
for (i = 0; i < Size; ++i)
{
Face *pFace;
pFace = SelFaceList_GetFace (m_pDoc->pSelFaces, i);
// changed QD 12/03
WadFileEntry* BitmapPtr = m_pDoc->GetDibBitmap( m_CurrentTexture );
::TextureFace (pFace, SelId, (LPCSTR)m_CurrentTexture, BitmapPtr);
// end change
}
// have to go through the selected brushes and update their child faces
int NumSelBrushes = SelBrushList_GetSize (m_pDoc->pSelBrushes);
for (i = 0; i < NumSelBrushes; ++i)
{
Brush *pBrush;
pBrush = SelBrushList_GetBrush (m_pDoc->pSelBrushes, i);
Brush_UpdateChildFaces (pBrush);
}
break;
}
case ADJUST_MODE_BRUSH :
{
if(m_pDoc->GetSelState() & MULTIBRUSH)
{
int NumSelBrushes = SelBrushList_GetSize (m_pDoc->pSelBrushes);
for (i = 0; i < NumSelBrushes; ++i)
{
Brush *pBrush = SelBrushList_GetBrush (m_pDoc->pSelBrushes, i);
// changed QD 12/03
WadFileEntry* BitmapPtr = m_pDoc->GetDibBitmap( m_CurrentTexture );
::TextureBrush (pBrush, SelId, (LPCSTR)m_CurrentTexture, BitmapPtr);
// end change
Brush_UpdateChildFaces (pBrush);
}
}
else
{
// changed QD 12/03
WadFileEntry* BitmapPtr = m_pDoc->GetDibBitmap( m_CurrentTexture );
::TextureBrush (m_pDoc->CurBrush, SelId, (LPCSTR)m_CurrentTexture, BitmapPtr);
// end change
Brush_UpdateChildFaces (m_pDoc->CurBrush);
}
break;
}
default :
return;
}
if(m_pParentCtrl->LastView)
m_pParentCtrl->LastView->SetFocus();
m_pDoc->UpdateAllViews(UAV_ALL3DVIEWS, NULL);
}
void CTextureDialog::OnSelchangetexturelist()
{
// Let's set the current texture to this one...
int SelNum = m_TextureList.GetCurSel();
m_TextureList.GetText( SelNum, m_CurrentTexture );
UpdateBitmap();
UpdateSize();
// ConPrintf("%s: SelNum %d: Dib %d\n", (LPCSTR)m_CurrentTexture, SelNum, CurTexInfo.Dib);
// Also set the current selection value in the document...
m_pDoc->mCurTextureSelection = SelNum;
}
void CTextureDialog::SelectTexture(int SelNum)
{
for (int i = 0; i < m_TextureList.GetCount(); ++i)
{
int SelId = m_TextureList.GetItemData (i);
if (SelNum == SelId)
{
m_TextureList.SetCurSel(i);
OnSelchangetexturelist();
return;
}
}
}
void CTextureDialog::UpdateBitmap()
{
// Draw the texture image bitmap...
WadFileEntry* BitmapPtr = m_pDoc->GetDibBitmap( m_CurrentTexture );
if( BitmapPtr == NULL )
return;
if( m_TextureImage.GetSafeHwnd() == NULL )
return;
CDC* pDC = m_TextureImage.GetDC();
ClearTextureImage( pDC );
// Create a BITMAPINFOHEADER structure for blitting...
BITMAPINFOHEADER bmih;
bmih.biSize = sizeof (BITMAPINFOHEADER);
bmih.biWidth = BitmapPtr->Width;
bmih.biHeight = -BitmapPtr->Height;
bmih.biPlanes = 1;
bmih.biBitCount = 16;
bmih.biCompression = BI_RGB;
bmih.biSizeImage = 0;
bmih.biXPelsPerMeter = 0;
bmih.biYPelsPerMeter = 0;
bmih.biClrUsed = 0;
bmih.biClrImportant = 0;
// changed QD
int width = BitmapPtr->Width;
int height = BitmapPtr->Height;
if(width>256)
width = 256;
if(height>256)
height = 256;
// end change
if( StretchDIBits(
(HDC)*pDC,
0,
0,
// changed QD
width, //BitmapPtr->Width,
height, //BitmapPtr->Height,
// end change
0,
0,
BitmapPtr->Width,
BitmapPtr->Height,
BitmapPtr->BitsPtr,
(BITMAPINFO *) &bmih,
DIB_RGB_COLORS,
SRCCOPY ) == GDI_ERROR )
{
TRACE("Could not blit to screen!");
_ASSERT(0);
}
m_TextureImage.ReleaseDC( pDC );
}
void CTextureDialog::ClearTextureImage(CDC* pDC)
{
/* This is a little hack. We're grabbing the color of
the pixel in the main dialog and using that color to
clear the texture image space.
For the moment, I can't think of an easier way to just
grab the dialog's color.
- John Moore
*/
CBrush* pBrush;
CDC* pDCDialog = GetDC();
COLORREF BkColor = pDCDialog->GetPixel( 0, 0 );
ReleaseDC( pDCDialog );
pBrush = new CBrush( BkColor );
pDC->SelectObject( pBrush );
CRgn rgn;
rgn.CreateRectRgn( 0, 0, BM_WIDTH, BM_HEIGHT );
pDC->PaintRgn( &rgn );
delete pBrush;
}
void CTextureDialog::UpdateSize()
{
CString size;
int width, height;
WadFileEntry* BitmapPtr = m_pDoc->GetDibBitmap( m_CurrentTexture );
if( BitmapPtr == NULL )
return;
width = BitmapPtr->Width;
height = BitmapPtr->Height;
size.Format( "%d X %d", width, height );
m_SizeText.SetWindowText (size);
}
/*
void CTextureDialog::ClearSizeImage( CDC* pDC )
{
// Same as clearing a bitmap area, only for the size string...
CBrush* pBrush;
CDC* pDCDialog = GetDC();
COLORREF BkColor = pDCDialog->GetPixel( 0, 0 );
ReleaseDC( pDCDialog );
pBrush = new CBrush( BkColor );
pDC->SelectObject( pBrush );
pDC->SetBkColor( BkColor );
CRgn rgn;
RECT rect;
rect.left = SIZETEXT_BORDER_SIZE_LEFT;
rect.top = SIZETEXT_BORDER_SIZE_TOP;
rect.right = rect.left + 70;
rect.bottom = rect.top + 16;
rgn.CreateRectRgn(
rect.left,
rect.top,
rect.right,
rect.bottom );
pDC->PaintRgn( &rgn );
delete pBrush;
}
*/
BOOL CTextureDialog::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
switch( nID )
{
case IDC_TEXTURELIST:
return CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
case IDC_APPLYTEXTURE:
return CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
default:
// Let's update stuff first...
//UpdateBitmap();
//UpdateSize();
return TRUE;
}
}
void CTextureDialog::Update( CFusionDoc* pDoc )
{
// int index;
// int PolyNum;
CString Name;
CString FirstName;
if ((m_pDoc == pDoc) && (m_TxlibChanged == false))
{
// Document is the same, so just redraw stuff...
UpdateBitmap();
UpdateSize();
}
else if (pDoc)
{
int CurSel;
// CWadFile *pWad;
m_pDoc = pDoc;
// Document changed, so we need to change our list values...
FillTheListbox ();
/*
m_TextureList.ResetContent();
pWad = Level_GetWadFile (m_pDoc->pLevel);
for (index = 0; index < pWad->mBitmapCount; index++)
{
// Insert the names, one by one...
Name = pWad->mBitmaps[index].Name;
int lbIndex = m_TextureList.AddString( (LPCTSTR) Name );
if (lbIndex != LB_ERR)
{
m_TextureList.SetItemData (lbIndex, index);
}
}
*/
// Set the current selection to whatever is pointed to in the document...
m_TextureList.SetCurSel( m_pDoc->mCurTextureSelection );
CurSel = m_TextureList.GetCurSel ();
if (CurSel != LB_ERR)
{
m_TextureList.GetText( CurSel, FirstName );
m_CurrentTexture = FirstName;
// update the bitmap image...
UpdateBitmap();
// Finally, update the size...
UpdateSize();
}
}
else
{
// Documents all closed. Update any values that need to be...
m_pDoc = NULL;
m_TextureList.ResetContent();
}
m_TxlibChanged = false;
}
void CTextureDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
// Let's redraw our bitmap and size...
UpdateBitmap();
UpdateSize();
}
const char *CTextureDialog::GetCurrentTexture()
{
return (LPCSTR)m_CurrentTexture;
}