-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSGDesitnationCombo.cpp
177 lines (155 loc) · 5.08 KB
/
CSGDesitnationCombo.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
/* Copyright (c) 2002-2012 Croteam Ltd.
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as published by
the Free Software Foundation
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
// CSGDesitnationCombo.cpp : implementation file
//
#include "StdH.h"
#include "CSGDesitnationCombo.h"
#ifdef _DEBUG
#undef new
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCSGDesitnationCombo
CCSGDesitnationCombo::CCSGDesitnationCombo()
{
// set dummy document ptr
m_pLastDoc = (CWorldEditorDoc *) 0x12345678;
}
CCSGDesitnationCombo::~CCSGDesitnationCombo()
{
}
BEGIN_MESSAGE_MAP(CCSGDesitnationCombo, CComboBox)
//{{AFX_MSG_MAP(CCSGDesitnationCombo)
ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
ON_CONTROL_REFLECT(CBN_DROPDOWN, OnDropdown)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCSGDesitnationCombo message handlers
BOOL CCSGDesitnationCombo::OnIdle(LONG lCount)
{
// get document ptr
CWorldEditorDoc* pDoc = theApp.GetActiveDocument();
// if document ptr has changed
// or if document was closed (pDoc == NULL and pLastDoc != NULL)
// or if document was changed from last OnIdle, refresh CSG destination combo box
if( (m_pLastDoc != pDoc) ||
((pDoc == NULL) && (m_pLastDoc != NULL)) ||
((pDoc != NULL) && !pDoc->m_chDocument.IsUpToDate( m_udComboEntries)) )
{
CEntity *penPreviouslySelectedEntity = NULL;
INDEX iCurrentSelection = GetCurSel();
if( iCurrentSelection != CB_ERR)
{
penPreviouslySelectedEntity = (CEntity *) GetItemData( iCurrentSelection);
}
// remove all combo entries
ResetContent();
// select entry one by default
INDEX iSelectedEntryByName = -1;
INDEX iSelectedEntryByPtr = -1;
// if document doesn't exist
if( pDoc == NULL)
{
AddString(_T("None Available"));
}
// if document exists
else
{
// for all of the world's entities
FOREACHINDYNAMICCONTAINER(pDoc->m_woWorld.wo_cenEntities, CEntity, iten)
{
// if the entity is brush
CEntity::RenderType rt = iten->GetRenderType();
if (rt==CEntity::RT_BRUSH || rt==CEntity::RT_FIELDBRUSH)
{
CTString strEntityName = iten->GetName();
// and it has name property defined
if( strEntityName != "")
{
// add it to CSG destination combo
INDEX iComboEntry = AddString( CString(strEntityName));
// set item's data as ptr to current entity
SetItemData( iComboEntry, (ULONG)(&*iten));
// try to select previously selected combo entry
if( strEntityName == m_strLastSelectedName)
{
iSelectedEntryByName = iComboEntry;
}
if( &iten.Current() == penPreviouslySelectedEntity)
{
iSelectedEntryByPtr = iComboEntry;
}
}
}
}
ASSERT( (GetCount() != CB_ERR) && (GetCount() != 0) );
}
if( iSelectedEntryByPtr != -1) SetCurSel( iSelectedEntryByPtr);
else if( iSelectedEntryByName != -1) SetCurSel( iSelectedEntryByName);
else SetCurSel( 0);
m_udComboEntries.MarkUpdated();
m_pLastDoc = pDoc;
}
return TRUE;
}
void CCSGDesitnationCombo::SelectBrushEntity( CEntity *penBrush)
{
// loop all entries in combo box
for( INDEX i=0; i<GetCount(); i++)
{
// if this is searched brush entity
if( ((CEntity *) GetItemData( i)) == penBrush)
{
// select it
SetCurSel( i);
m_strLastSelectedName = penBrush->GetName();
break;
}
}
}
CEntity *CCSGDesitnationCombo::GetSelectedBrushEntity(void)
{
// assure valid brush entity ptr
OnIdle( 0);
INDEX iCurrentSelection = GetCurSel();
if( iCurrentSelection == CB_ERR)
{
return NULL;
}
return (CEntity *) GetItemData( iCurrentSelection);
}
void CCSGDesitnationCombo::OnSelchange()
{
CEntity *penSelected = GetSelectedBrushEntity();
if( penSelected != NULL)
{
m_strLastSelectedName = penSelected->GetName();
}
}
void CCSGDesitnationCombo::OnDropdown()
{
INDEX ctItems = GetCount();
if( ctItems == CB_ERR) return;
CRect rectCombo;
GetWindowRect( &rectCombo);
PIX pixScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
PIX pixMaxHeight = pixScreenHeight - rectCombo.top;
CWnd *pwndParent = GetParent();
if( pwndParent == NULL) return;
pwndParent->ScreenToClient( &rectCombo);
PIX pixNewHeight = GetItemHeight(0)*(ctItems+2);
rectCombo.bottom = rectCombo.top + ClampUp( pixNewHeight, pixMaxHeight);
MoveWindow( rectCombo);
}