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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "stdafx.h"
#pragma warning(push, 1)
#pragma warning(disable:4701 4702 4530)
#include <fstream>
#pragma warning(pop)
#include "hammer.h"
#include "TextureWindow.h"
#include "TextureBrowser.h"
#include "CustomMessages.h"
#include "IEditorTexture.h"
#include "GameConfig.h"
#include "GlobalFunctions.h"
#include "TextureSystem.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialsystem.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
const DWORD NO_FILE_FILTER = 0xFFFFFFF0L;
const int iPadding = 4;
const int iTexNameFontHeight = 7;
const int iTexIconHeight = 12;
BEGIN_MESSAGE_MAP(CTextureWindow, CWnd)
//{{AFX_MSG_MAP(CTextureWindow)
ON_WM_PAINT()
ON_WM_SIZE()
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_KEYDOWN()
ON_WM_MOUSEWHEEL()
ON_WM_CHAR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//-----------------------------------------------------------------------------
// Purpose: Constructor. Initializes data members.
//-----------------------------------------------------------------------------
CTextureWindow::CTextureWindow(void)
{
bFirstPaint = TRUE;
m_szFilter[0] = '\0';
m_nFilters = 0;
m_szKeywords[0] = '\0';
m_nKeywords = 0;
m_pSpecificList = NULL;
szCurTexture[0] = '\0';
m_eTextureFormat = g_pGameConfig->GetTextureFormat();
m_bEnableUpdate = true;
m_nTypeFilter = ~0;
m_bShowErrors = true;
}
//-----------------------------------------------------------------------------
// Purpose: Destructor.
//-----------------------------------------------------------------------------
CTextureWindow::~CTextureWindow(void)
{
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pParentWnd -
// rect -
//-----------------------------------------------------------------------------
void CTextureWindow::Create(CWnd *pParentWnd, RECT& rect)
{
static CString TextureWndClassName;
iDisplaySize = 64;
if(TextureWndClassName.IsEmpty())
{
// create class
TextureWndClassName = AfxRegisterWndClass(CS_DBLCLKS | CS_HREDRAW |
CS_VREDRAW, LoadCursor(NULL, IDC_ARROW),
(HBRUSH) GetStockObject(BLACK_BRUSH),
AfxGetApp()->LoadIcon(IDI_TEXTUREWINDOW));
}
CWnd::Create(TextureWndClassName, "TextureBrowserWindow",
SS_SUNKEN | WS_TABSTOP | WS_CHILD | WS_VSCROLL | WS_HSCROLL,
rect, pParentWnd, IDC_TEXTUREWINDOW);
UpdateScrollSizes();
// create font
if(!TexFont.m_hObject)
TexFont.CreatePointFont(iTexNameFontHeight * 10, "Courier New");
CDC *pDC = GetDC();
pDC->SelectObject(&TexFont);
pDC->GetCharWidth('A', 'A', &iTexNameCharWidth);
ReleaseDC(pDC);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : bEnable -
//-----------------------------------------------------------------------------
void CTextureWindow::EnableUpdate(bool bEnable)
{
m_bEnableUpdate = bEnable;
}
//-----------------------------------------------------------------------------
// Purpose: Searches for all of the keywords in an array of keywords within
// a given search string, case-insensitive.
// Input : pszSearch - String to search for keywords within.
// pszKeyword - Array of pointers to keywords.
// nKeywords - Number of keywords in the array.
// Output : Returns true if all keywords were found, false otherwise.
//-----------------------------------------------------------------------------
bool CTextureWindow::MatchKeywords(const char *pszSearch, char **pszKeyword, int nKeywords)
{
if (nKeywords != 0)
{
for (int i = 0; i < nKeywords; i++)
{
if (Q_stristr(pszSearch, pszKeyword[i]) == NULL)
{
return(false);
}
}
}
return(true);
}
//-----------------------------------------------------------------------------
// Changes type filter bits
//-----------------------------------------------------------------------------
void CTextureWindow::SetTypeFilter( int filter, bool enable )
{
if (enable)
m_nTypeFilter |= filter;
else
m_nTypeFilter &= ~filter;
if (m_bEnableUpdate)
{
UpdateScrollSizes();
SelectTexture(szCurTexture, false);
if (IsWindow(m_hWnd))
{
Invalidate();
UpdateWindow();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pTE -
// bStart -
// Output : Returns TRUE on success, FALSE on failure.
//-----------------------------------------------------------------------------
BOOL CTextureWindow::EnumTexturePositions(TWENUMPOS *pTE, BOOL bStart)
{
RECT &texrect = pTE->texrect;
if (bStart)
{
pTE->cur_x = iPadding;
pTE->cur_y = iPadding;
pTE->largest_y = 0;
pTE->iTexIndex = 0;
if (IsWindow(m_hWnd))
{
GetClientRect(&pTE->clientrect);
}
SetRect(&texrect, 0, 0, 0, 0);
}
bool bFound = false;
do
{
pTE->pTex = g_Textures.EnumActiveTextures(&pTE->iTexIndex, m_eTextureFormat);
if (pTE->pTex == NULL)
continue;
bFound = false;
// If we are iterating a specific list of textures, make sure it is in the list.
// dvs: inefficient, the specific list should control the loop, not act as a filter
if (m_pSpecificList != NULL)
{
int nIndex = m_pSpecificList->Find(pTE->pTex);
if (nIndex == -1)
continue;
pTE->nUsageCount = m_pSpecificList->Element(nIndex).nUsageCount;
}
// Filter by texture name.
char szTemp[MAX_PATH];
pTE->pTex->GetShortName(szTemp);
if (MatchKeywords(szTemp, m_Filters, m_nFilters))
{
//
// Filter by keywords.
//
// NOTE: Try not to access the material here when finding the position
// because it causes the materials to be cached (slow!!)
if (m_nKeywords)
{
pTE->pTex->GetKeywords(szTemp);
if (MatchKeywords(szTemp, m_Keyword, m_nKeywords))
{
bFound = true;
}
}
else
{
bFound = true;
}
}
// Filter based on opacity, etc.
// NOTE: Try not to access the material here when finding the position
// because it causes the materials to be cached (slow!!)
if (bFound && ((m_nTypeFilter & TYPEFILTER_ALL) != TYPEFILTER_ALL))
{
IMaterial* pMaterial = pTE->pTex->GetMaterial();
if (pMaterial)
{
bFound = false;
if ( pMaterial->GetMaterialVarFlag( MATERIAL_VAR_SELFILLUM ) )
{
if (m_nTypeFilter & TYPEFILTER_SELFILLUM)
bFound = true;
}
if ( pMaterial->GetMaterialVarFlag( MATERIAL_VAR_BASEALPHAENVMAPMASK ) )
{
if (m_nTypeFilter & TYPEFILTER_ENVMASK)
bFound = true;
}
if ( pMaterial->GetMaterialVarFlag( MATERIAL_VAR_TRANSLUCENT ) )
{
if (m_nTypeFilter & TYPEFILTER_TRANSLUCENT)
bFound = true;
}
else
{
if (m_nTypeFilter & TYPEFILTER_OPAQUE)
bFound = true;
}
}
}
// Blow off zero-size materials, but only if they've been loaded...
// Otherwise we have to cache everything which will take forever...
if ( bFound && pTE->pTex->IsLoaded() )
{
if ((pTE->pTex->GetWidth() == 0) || (pTE->pTex->GetHeight() == 0))
{
bFound = false;
}
}
} while ((pTE->pTex != NULL) && (!bFound));
if ((!bFound) || (pTE->pTex == NULL))
{
return(FALSE);
}
doresize:
SetRect( &texrect, pTE->cur_x, pTE->cur_y,
pTE->cur_x + iDisplaySize,
pTE->cur_y + iDisplaySize );
// if we've got one texture on this row already, and this one goes out of
// the client area, jump to the next row. we want to have at least one texture on
// each row, or we will sit in an infinite loop.
if(pTE->cur_x > iPadding && texrect.right > pTE->clientrect.right)
{
pTE->cur_x = iPadding;
pTE->cur_y = pTE->largest_y + iPadding;
goto doresize;
}
texrect.bottom += (8 + iTexNameFontHeight + iTexIconHeight);
if(texrect.bottom > pTE->largest_y)
pTE->largest_y = texrect.bottom;
// update cur_x
pTE->cur_x = texrect.right + iPadding;
return TRUE;
}
//-----------------------------------------------------------------------------
// Purpose: Sets the dimensions of each texture within the texture window.
// Input : iSize - 32 to display as 32 x 32 textures.
// 64 to display as 64 x 64 textures.
// 128 to display as 128 x 128 textures.
// 512 to display as 512 x 512 textures
//-----------------------------------------------------------------------------
void CTextureWindow::SetDisplaySize(int iSize)
{
iDisplaySize = iSize;
UpdateScrollSizes();
SelectTexture(szCurTexture, FALSE);
RedrawWindow();
}
//-----------------------------------------------------------------------------
// Purpose: Sets the name filter that is used to filter the texture window contents.
// Input : pszFilter - Space, comma, or semicolon delimited names to filter against.
//-----------------------------------------------------------------------------
void CTextureWindow::SetNameFilter(LPCTSTR pszFilter)
{
if (m_bEnableUpdate)
{
// kill highlight
HighlightCurTexture();
}
// set filter
strcpy(m_szFilter, pszFilter);
strupr(m_szFilter);
// delimit the filter
m_nFilters = 0;
char *p = strtok(m_szFilter, " ,;");
while (p != NULL)
{
m_Filters[m_nFilters++] = p;
p = strtok(NULL, " ,;");
}
if (m_bEnableUpdate)
{
UpdateScrollSizes();
SelectTexture(szCurTexture, false);
if (IsWindow(m_hWnd))
{
Invalidate();
UpdateWindow();
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Sets the keywords that are used to filter the texture window contents.
// Input : pszFilter - Space, comma, or semicolon delimited keywords to filter against.
//-----------------------------------------------------------------------------
void CTextureWindow::SetKeywords(LPCTSTR pszKeywords)
{
if (m_bEnableUpdate)
{
// kill highlight
HighlightCurTexture();
}
// set keyword filter
strcpy(m_szKeywords, pszKeywords);
strupr(m_szKeywords);
// delimit the filter
m_nKeywords = 0;
char *p = strtok(m_szKeywords, " ,;");
while (p != NULL)
{
m_Keyword[m_nKeywords++] = p;
p = strtok(NULL, " ,;");
}
if (m_bEnableUpdate)
{
UpdateScrollSizes();
SelectTexture(szCurTexture, false);
if (IsWindow(m_hWnd))
{
Invalidate();
UpdateWindow();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTextureWindow::UpdateScrollSizes(void)
{
TWENUMPOS TE;
total_x = total_y = 0;
if(EnumTexturePositions(&TE, TRUE))
do {
if(TE.texrect.right > total_x)
total_x = TE.texrect.right;
if(TE.texrect.bottom > total_y)
total_y = TE.texrect.bottom;
} while(EnumTexturePositions(&TE));
// update total_x and total_y
total_x += iPadding;
total_y += iPadding;
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_ALL;
si.nMin = 0;
si.nPos = 0;
si.nMax = total_x;
si.nPage = TE.clientrect.right;
SetScrollInfo(SB_HORZ, &si, TRUE);
si.nMax = total_y;
si.nPage = TE.clientrect.bottom;
SetScrollInfo(SB_VERT, &si, TRUE);
char szbuf[100];
sprintf(szbuf, "Size = %d %d\n", total_y, TE.clientrect.bottom);
TRACE0(szbuf);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTextureWindow::OnPaint(void)
{
CPaintDC dc(this); // device context for painting
// setup font
dc.SelectObject(&TexFont);
dc.SetTextColor(RGB(255, 255, 255));
//dc.SetBkColor(RGB(0,0,0));
dc.SetBkMode(TRANSPARENT);
CRect clientrect;
GetClientRect(clientrect);
dc.SetWindowOrg(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
TWENUMPOS TE;
BOOL bNotDone = EnumTexturePositions(&TE, TRUE);
BOOL bFoundHighlight = FALSE;
rectHighlight.left = -1;
BOOL bFirst = TRUE;
char szDrawTexture[128];
char szFirstDrawnTexture[128];
while (bNotDone)
{
TE.pTex->GetShortName(szDrawTexture);
if (!strcmpi(szCurTexture, szDrawTexture))
{
rectHighlight = TE.texrect;
rectHighlight.InflateRect(2, 4);
bFoundHighlight = TRUE;
}
if (dc.RectVisible(&TE.texrect))
{
// ensure loaded
TE.pTex->Load();
CPalette *pOld = dc.SelectPalette(TE.pTex->HasPalette() ? TE.pTex->GetPalette() : g_pGameConfig->Palette, FALSE);
dc.RealizePalette();
int flags = drawCaption | drawIcons;
if (m_bShowErrors)
flags |= drawErrors;
DrawTexData_t DrawTexData;
DrawTexData.nFlags = flags | (m_pSpecificList ? drawUsageCount : 0);
DrawTexData.nUsageCount = TE.nUsageCount;
TE.pTex->Draw(&dc, TE.texrect, iTexNameFontHeight, iTexIconHeight, DrawTexData);
dc.SelectPalette(pOld, FALSE);
}
//
// Save the name of the first drawn texture in case we need to highlight it.
//
if (bFirst)
{
bFirst = FALSE;
strcpy(szFirstDrawnTexture, szDrawTexture);
}
// next texture & position
bNotDone = EnumTexturePositions(&TE);
}
if(bFoundHighlight)
{
HighlightCurTexture(&dc);
}
else
{
// select first texture
SelectTexture(szFirstDrawnTexture);
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : nType -
// cx -
// cy -
//-----------------------------------------------------------------------------
void CTextureWindow::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
UpdateScrollSizes();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : nSBCode -
// nPos -
// pScrollBar -
//-----------------------------------------------------------------------------
void CTextureWindow::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
int iPos = int(nPos);
SCROLLINFO si;
GetScrollInfo(SB_HORZ, &si);
int iCurPos = GetScrollPos(SB_HORZ);
int iLimit = GetScrollLimit(SB_HORZ);
switch(nSBCode)
{
case SB_LINELEFT:
iPos = -int(si.nPage / 4);
break;
case SB_LINERIGHT:
iPos = int(si.nPage / 4);
break;
case SB_PAGELEFT:
iPos = -int(si.nPage / 2);
break;
case SB_PAGERIGHT:
iPos = int(si.nPage / 2);
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
iPos -= iCurPos;
break;
}
if(iCurPos + iPos < 0)
iPos = -iCurPos;
if(iCurPos + iPos > iLimit)
iPos = iLimit - iCurPos;
if(iPos)
{
SetScrollPos(SB_HORZ, iCurPos + iPos);
ScrollWindow(-iPos, 0);
UpdateWindow();
}
CWnd::OnHScroll(nSBCode, nPos, pScrollBar);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : nSBCode -
// nPos -
// pScrollBar -
//-----------------------------------------------------------------------------
void CTextureWindow::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
SCROLLINFO si;
GetScrollInfo(SB_VERT, &si);
int iCurPos = GetScrollPos(SB_VERT);
int iLimit = GetScrollLimit(SB_VERT);
int iPos = int(si.nPos);
switch(nSBCode)
{
case SB_LINEUP:
iPos = -int(si.nPage / 4);
break;
case SB_LINEDOWN:
iPos = int(si.nPage / 4);
break;
case SB_PAGEUP:
iPos = -int(si.nPage / 2);
break;
case SB_PAGEDOWN:
iPos = int(si.nPage / 2);
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
iPos = si.nTrackPos - iCurPos;
break;
case SB_ENDSCROLL:
iPos = 0;
break;
}
if(iCurPos + iPos < 0)
iPos = -iCurPos;
if(iCurPos + iPos > iLimit)
iPos = iLimit - iCurPos;
if(iPos)
{
SetScrollPos(SB_VERT, iCurPos + iPos);
ScrollWindow(0, -iPos);
UpdateWindow();
}
CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pDC -
//-----------------------------------------------------------------------------
void CTextureWindow::HighlightCurTexture(CDC *pDC)
{
CDC dc;
BOOL bMadeDC = FALSE;
// nothing to draw
if(rectHighlight.left < 0)
return;
if(!pDC)
{
dc.Attach(::GetDC(m_hWnd));
dc.SetWindowOrg(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
bMadeDC = TRUE;
pDC = &dc;
}
pDC->SelectStockObject(WHITE_PEN);
pDC->SelectStockObject(NULL_BRUSH);
pDC->SetROP2(R2_XORPEN);
pDC->Rectangle(rectHighlight);
if(bMadeDC)
::ReleaseDC(m_hWnd, dc.Detach());
}
//-----------------------------------------------------------------------------
// Purpose: Selects a given texture by name, scrolling the window if necessary
// to make the selected texture visible.
// Input : pszTexture - Texture to select.
//-----------------------------------------------------------------------------
void CTextureWindow::SelectTexture(LPCTSTR pszTexture, BOOL bAllowRedraw)
{
TWENUMPOS TE;
BOOL bNotDone = EnumTexturePositions(&TE, TRUE);
int iTextureIndex = 0;
IEditorTexture *pTex = g_Textures.FindActiveTexture(pszTexture);
CRect r(100, 100, 500, 500);
if (IsWindow(m_hWnd))
{
GetClientRect(r);
}
int iClientHeight = r.Height();
if (pTex == NULL)
{
return;
}
while (bNotDone)
{
if (pTex == TE.pTex)
{
// found it - make sure it's visible
if (IsWindow(m_hWnd))
{
int iScrollPos = GetScrollPos(SB_VERT);
if (iScrollPos + iClientHeight < TE.texrect.top || TE.texrect.bottom < iScrollPos)
{
SetScrollPos(SB_VERT, TE.texrect.top);
ScrollWindow(0, iScrollPos - TE.texrect.top);
if (bAllowRedraw)
{
RedrawWindow();
}
}
// first remove current highlight
HighlightCurTexture();
}
pTex->GetShortName(szCurTexture);
// highlight new texture
if (IsWindow(m_hWnd))
{
rectHighlight = CRect(&TE.texrect);
rectHighlight.InflateRect(2, 4);
HighlightCurTexture();
}
GetParent()->PostMessage(TWN_SELCHANGED);
return;
}
// next texture & position
bNotDone = EnumTexturePositions(&TE);
++iTextureIndex;
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : nFlags -
// point -
//-----------------------------------------------------------------------------
void CTextureWindow::OnLButtonDown(UINT nFlags, CPoint point)
{
// find clicked texture
TWENUMPOS TE;
BOOL bNotDone = EnumTexturePositions(&TE, TRUE);
int iTextureIndex = 0;
int iHorzPos = GetScrollPos(SB_HORZ);
int iVertPos = GetScrollPos(SB_VERT);
char szNewTexture[128];
point += CPoint(iHorzPos, iVertPos);
while (bNotDone)
{
if (PtInRect(&TE.texrect, point))
{
TE.pTex->GetShortName(szNewTexture);
break;
}
// next texture & position
bNotDone = EnumTexturePositions(&TE);
++iTextureIndex;
}
if(!bNotDone)
{
// no texture was hit
return;
}
// first remove current highlight
HighlightCurTexture();
// highlight new texture
strcpy(szCurTexture, szNewTexture);
rectHighlight = CRect(&TE.texrect);
rectHighlight.InflateRect(2, 4);
HighlightCurTexture();
// tell parent we changed selection
GetParent()->PostMessage(TWN_SELCHANGED);
SetFocus();
CWnd::OnLButtonDown(nFlags, point);
}
//-----------------------------------------------------------------------------
// Purpose: Notifies our parent window of a double-click event.
// Input : nFlags -
// point -
//-----------------------------------------------------------------------------
void CTextureWindow::OnLButtonDblClk(UINT nFlags, CPoint point)
{
GetParent()->PostMessage(TWN_LBUTTONDBLCLK);
CWnd::OnLButtonDblClk(nFlags, point);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : nChar -
// nRepCnt -
// nFlags -
//-----------------------------------------------------------------------------
void CTextureWindow::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : nFlags -
// zDelta -
// point -
// Output : Returns TRUE on success, FALSE on failure.
//-----------------------------------------------------------------------------
BOOL CTextureWindow::OnMouseWheel(UINT nFlags, short zDelta, CPoint point)
{
int nScrollCode;
if (zDelta > 0)
{
nScrollCode = SB_LINEUP;
}
else
{
nScrollCode = SB_LINEDOWN;
}
SCROLLINFO si;
GetScrollInfo(SB_VERT, &si);
int iCurPos = GetScrollPos(SB_VERT);
int iLimit = GetScrollLimit(SB_VERT);
int iPos = int(si.nPos);
switch (nScrollCode)
{
case SB_LINEUP:
{
iPos = -(int)si.nPage / 4;
break;
}
case SB_LINEDOWN:
{
iPos = si.nPage / 4;
break;
}
}
if (iCurPos + iPos < 0)
{
iPos = -iCurPos;
}
if (iCurPos + iPos > iLimit)
{
iPos = iLimit - iCurPos;
}
if (iPos)
{
SetScrollPos(SB_VERT, iCurPos + iPos);
ScrollWindow(0, -iPos);
UpdateWindow();
}
return(TRUE);
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : nChar -
// nRepCnt -
// nFlags -
//-----------------------------------------------------------------------------
void CTextureWindow::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CWnd::OnChar(nChar, nRepCnt, nFlags);
}
//-----------------------------------------------------------------------------
// Purpose: Sets the contents of the texture window to a specific list of textures.
// Input : pList - Textures with which to populate the texture window.
//-----------------------------------------------------------------------------
void CTextureWindow::SetSpecificList(TextureWindowTexList *pList)
{
m_pSpecificList = pList;
if (m_hWnd != NULL)
{
UpdateScrollSizes();
SelectTexture(szCurTexture, FALSE);
RedrawWindow();
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : eTextureFormat -
//-----------------------------------------------------------------------------
void CTextureWindow::SetTextureFormat(TEXTUREFORMAT eTextureFormat)
{
m_eTextureFormat = eTextureFormat;
}
|