-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathIListData.cpp
243 lines (184 loc) · 4.54 KB
/
IListData.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
// IListData.cpp
//
// IListData and subclasses
// Copyright (c) 2017 Kronosaur Productions, LLC. All Rights Reserved.
#include "PreComp.h"
#define FIELD_DESC CONSTLIT("desc")
#define FIELD_ICON CONSTLIT("icon")
#define FIELD_ICON_SCALE CONSTLIT("iconScale")
#define FIELD_TITLE CONSTLIT("title")
const CItem g_DummyItem;
CItemList g_DummyItemList;
CItemListManipulator g_DummyItemListManipulator(g_DummyItemList);
// CItemListWrapper -----------------------------------------------------------
CItemListWrapper::CItemListWrapper (CSpaceObject *pSource) :
m_pSource(pSource),
m_ItemList(pSource->GetItemList())
// CItemListWrapper constructor
{
}
CItemListWrapper::CItemListWrapper (CItemList &ItemList) :
m_pSource(NULL),
m_ItemList(ItemList)
// CItemListWrapper constructor
{
}
// CListWrapper ---------------------------------------------------------------
//
// This class handles arbitrary lists. We expect the data to be a CC list. Each
// entry can be either a list or a struct.
//
// If a list, we expect the following members:
//
// 0. Title
// 1. Icon descriptor
// 2. Description
//
// For structs, we expect the following members:
//
// title: The title of the entry
// icon: An icon descriptor
// desc: A longer description of the entry.
const int TITLE_INDEX = 0;
const int ICON_INDEX = 1;
const int DESC_INDEX = 2;
CListWrapper::CListWrapper (CCodeChain *pCC, ICCItem *pList) :
m_pCC(pCC),
m_pList(pList->Reference()),
m_iCursor(-1)
// CListWrapper constructor
{
}
CString CListWrapper::GetDescAtCursor (void)
// GetDescAtCursor
//
// Returns the description of the list element
{
if (IsCursorValid())
{
ICCItem *pItem = m_pList->GetElement(m_iCursor);
if (pItem->IsSymbolTable())
return pItem->GetStringAt(FIELD_DESC);
else if (DESC_INDEX < pItem->GetCount())
{
ICCItem *pDesc = pItem->GetElement(DESC_INDEX);
if (pDesc->IsNil())
return NULL_STR;
return pDesc->GetStringValue();
}
}
return NULL_STR;
}
ICCItem *CListWrapper::GetEntryAtCursor (CCodeChain &CC)
// GetEntryAtCursor
//
// Returns the entry at the cursor
{
if (!IsCursorValid())
return CC.CreateNil();
ICCItem *pItem = m_pList->GetElement(m_iCursor);
return pItem->Reference();
}
DWORD CListWrapper::GetImageDescAtCursor (RECT *retrcImage, Metric *retrScale) const
// GetImageDescAtCursor
//
// Returns the image descriptor
{
if (!IsCursorValid())
return 0;
// Get the item at cursor
ICCItem *pItem = m_pList->GetElement(m_iCursor);
// Get the icon element
ICCItem *pIcon;
Metric rScale = 1.0;
if (pItem->IsSymbolTable())
{
pIcon = pItem->GetElement(FIELD_ICON);
if (pIcon == NULL)
return 0;
// See if we specify an icon scale
rScale = pItem->GetDoubleAt(FIELD_ICON_SCALE, 1.0);
}
else
{
if (pItem->GetCount() <= ICON_INDEX)
return 0;
pIcon = pItem->GetElement(ICON_INDEX);
}
if (retrScale)
*retrScale = rScale;
// Get the image descriptor
return CTLispConvert::AsImageDesc(pIcon, retrcImage);
}
CString CListWrapper::GetTitleAtCursor (void)
// GetTitleAtCursor
//
// Returns the title of the list element
{
if (IsCursorValid())
{
ICCItem *pItem = m_pList->GetElement(m_iCursor);
if (pItem->IsSymbolTable())
return pItem->GetStringAt(FIELD_TITLE);
else if (TITLE_INDEX < pItem->GetCount())
{
ICCItem *pTitle = pItem->GetElement(TITLE_INDEX);
if (pTitle->IsNil())
return NULL_STR;
return pTitle->GetStringValue();
}
}
return NULL_STR;
}
bool CListWrapper::MoveCursorBack (void)
// MoveCursorBack
//
// Move cursor back
{
if (m_iCursor <= 0)
return false;
else
{
m_iCursor--;
return true;
}
}
bool CListWrapper::MoveCursorForward (void)
// MoveCursorForward
//
// Moves the cursor forward
{
if (m_iCursor + 1 == GetCount())
return false;
else
{
m_iCursor++;
return true;
}
}
void CListWrapper::PaintImageAtCursor (CG32bitImage &Dest, int x, int y, int cxWidth, int cyHeight, Metric rScale)
// PaintImageAtCursor
//
// Paints the image for the current element
{
RECT rcImage;
Metric rIconScale;
DWORD dwUNID = GetImageDescAtCursor(&rcImage, &rIconScale);
if (dwUNID == 0)
return;
if (rIconScale != 1.0)
rScale = rIconScale;
CG32bitImage *pImage = g_pUniverse->GetLibraryBitmap(dwUNID);
if (pImage == NULL)
return;
CPaintHelper::PaintScaledImage(Dest, x, y, cxWidth, cyHeight, *pImage, rcImage, rScale);
}
void CListWrapper::SyncCursor (void)
// SyncCursor
//
// Make sure the cursor is inbounds
{
if (m_iCursor != -1
&& m_iCursor >= m_pList->GetCount())
m_iCursor = m_pList->GetCount() - 1;
}