-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataCDInfo.cpp
executable file
·328 lines (270 loc) · 9.3 KB
/
DataCDInfo.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
#include "StdAfx.h"
#include "CdCoverCreator2.h"
#include "datacdinfo.h"
#include "TextRenderer.h"
#include <math.h>
IMPLEMENT_SERIAL (CDataCDInfo, CObject, VERSIONABLE_SCHEMA | 1)
CDataCDInfo::CDataCDInfo (void)
{
m_pDirTree = NULL;
}
CDataCDInfo::CDataCDInfo (CDataCDInfo& info)
{
m_pDirTree = NULL;
*this = info;
}
CDataCDInfo::~CDataCDInfo(void)
{
if (m_pDirTree != NULL)
delete m_pDirTree;
}
void CDataCDInfo::Render (CRenderDC& rdc, RenderType rt, CStyleTemplate& style)
{
if (m_pDirTree == NULL)
return;
// render the title
CPoint pt;
if (rt != Inlay || style.GetMediumType () != MediumSlimCase) // draw the title on inlays only if this is no slim case
CRTFTitles::DrawTitle2 (rdc, rt, style, pt);
if (rt == Label)
{
CalcLabelTitleRect (rdc, style);
DrawLabelTitle (rdc, style);
}
if (rt == Inlay)
{
CalcInlaySideBarRect (rdc, style);
DrawSideBars (rdc, style);
}
// render the directory tree
CRect r;
switch (rt)
{
// case Cover:
// r = *(style.GetCoverTrackRect (rdc));
// break;
case Back:
r = *(style.GetBackTrackRect (rdc));
break;
case Inlay:
r = *(style.GetInlayTrackRect (rdc));
break;
// case Label:
// r = *(style.GetLabelTrackRect (rdc));
// break;
}
if (style.GetMediumType () == MediumSlimCase && rt == Inlay)
return; // don't draw stuff on Inlay of slim case
if (style.GetDisplayTrackGroups (rt) && (rt != Label) && (rt != Cover)) // don't display on label and on cover
m_pDirTree->Render (rdc, r, style, rdc.m_hndPrinter != NULL);
}
void CDataCDInfo::DrawLabelTitle (CRenderDC& rdc, CStyleTemplate& style)
{
if (style.GetDisplayTitles (Label))
{
if (style.IsLabelTitleRound ())
{
bool bFlip = style.GetTitleAlign (Label) == 0 ||
(style.GetTitleAlign (Label) == 2 && style.GetLabelTitlePosition () == 0);
CRect r = *style.GetLabelTitleRect (rdc);
CFont* pOldFont = style.SelectTitleFont (rdc, Label, m_dTitleFontFactor);
int nHeight = rdc.m_pDC->GetTextExtent ("X").cy;
// split lines
int nPos;
for (int nOldPos = 0; ; )
{
nPos = m_strCDTitle.Find ('\n', nOldPos);
if (nPos != -1)
{
CTextRenderer::DrawRoundText (rdc.m_pDC, rdc.m_hndPrinter, r, !bFlip,
m_strCDTitle.Mid (nOldPos, nPos - nOldPos - 1),
style.GetDisplayTrackGroups (Label) || style.IsLabelTrackDisplayed () ? PI : 2 * PI - 0.2);
r.DeflateRect (nHeight, nHeight);
}
else
{
CTextRenderer::DrawRoundText (rdc.m_pDC, rdc.m_hndPrinter, r, !bFlip,
m_strCDTitle.Mid (nOldPos),
style.GetDisplayTrackGroups (Label) || style.IsLabelTrackDisplayed () ? PI : 2 * PI - 0.2);
break;
}
nOldPos = nPos + 1;
}
pOldFont = rdc.m_pDC->SelectObject (pOldFont);
if (pOldFont != NULL)
pOldFont->DeleteObject ();
}
else
{
CRect r1 = *style.GetLabelTitleRect (rdc);
CRect r2 = r1;
r1.bottom = r2.top = (LONG) (r1.top + 0.6 * r1.Height ());
UINT nFormat = style.GetDrawRectAlignment (2) | style.GetDrawRectVAlignment (style.GetTitleAlign (Label));
CFont* pOldFont = style.SelectTitleFont (rdc, Label, m_dTitleFontFactor);
rdc.m_pDC->DrawText (m_strCDTitle, &r1, nFormat);
pOldFont = rdc.m_pDC->SelectObject (pOldFont);
if (pOldFont != NULL)
pOldFont->DeleteObject ();
}
}
}
void CDataCDInfo::CalcLabelTitleRect (CRenderDC& rdc, CStyleTemplate& style)
{
CFont* pOldFont = style.SelectTitleFont (rdc, Label);
CSize szTitle = rdc.m_pDC->GetTextExtent (m_strCDTitle);
CRect* pRect = style.GetLabelTitleRect (rdc);
if (style.IsLabelTitleRound ())
{
int y = style.GetTotalLabelRect (rdc)->Height () -
2 * style.MapY ((int) (style.GetTitleMargin (Label) * 1000), rdc, Label);
m_dTitleFontFactor = y / 160.0; // y reflects zoom factor. Normal y on a 512x512 approx. 480 (depending on margins), allow magn. factor 3 for that
}
else
{
// r^2=x^2+y^2
// y=height/2 - vmargin - text.cy
// r=width/2
// ==> x=sqrt((width/2)^2 - (height/2 - vmargin - text.cy)^2)
// ==> width=2x
CRect* pRcTotal = style.GetTotalLabelRect (rdc);
int y;
if (style.GetTitleAlign (Label) < 2) // top, bottom
y = pRcTotal->Height () / 2 - style.MapY ((int) (style.GetTitleMargin (Label) * 1000), rdc, Label);
else // center
y = pRcTotal->Height () / 3;
int width = (int) sqrt ((double) (pRcTotal->Width () * pRcTotal->Width () - 4 * y * y));
m_dTitleFontFactor = min (
width / ((double) (szTitle.cx + 1)),
pRect->Height () / ((double) (szTitle.cy + 1)));
}
}
void CDataCDInfo::DrawSideBars(CRenderDC &rdc, CStyleTemplate &style)
{
if (style.GetInlayDisplaySidebarTitles ())
{
// draw left side
CFont* pOldFont = style.SelectInlaySideFont (rdc, true, m_dSideFontFactor);
if (style.GetInlaySideTextDirection ())
{
int nTop = style.GetInlaySideVAlignTop (rdc, rdc.m_pDC->GetTextExtent (m_strCDTitle).cx);
CRect* pRect = style.GetInlayLeftSideRect (rdc);
if (pRect->Width () > 0)
rdc.m_pDC->ExtTextOut (pRect->left, pRect->bottom - nTop, ETO_CLIPPED, NULL, m_strCDTitle, NULL);
}
else
{
int nTop = style.GetInlaySideVAlignTop (rdc, rdc.m_pDC->GetTextExtent (m_strCDTitle).cx);
CRect* pRect = style.GetInlayLeftSideRect (rdc);
if (pRect->Width () > 0)
rdc.m_pDC->ExtTextOut (pRect->right, nTop, ETO_CLIPPED, NULL, m_strCDTitle, NULL);
}
pOldFont = rdc.m_pDC->SelectObject (pOldFont);
if (pOldFont != NULL)
pOldFont->DeleteObject ();
// draw right side
pOldFont = style.SelectInlaySideFont (rdc, false, m_dSideFontFactor);
if ((style.GetInlaySideTextDirection () && !style.IsInlaySideAntiparallel ()) || (!style.GetInlaySideTextDirection () && style.IsInlaySideAntiparallel ()))
{
int nTop = style.GetInlaySideVAlignTop (rdc, rdc.m_pDC->GetTextExtent (m_strCDTitle).cx);
CRect* pRect = style.GetInlayRightSideRect (rdc);
if (pRect->Width () > 0)
rdc.m_pDC->ExtTextOut (pRect->left, pRect->bottom - nTop, ETO_CLIPPED, NULL, m_strCDTitle, NULL);
}
else
{
int nTop = style.GetInlaySideVAlignTop (rdc, rdc.m_pDC->GetTextExtent (m_strCDTitle).cx);
CRect* pRect = style.GetInlayRightSideRect (rdc);
if (pRect->Width () > 0)
rdc.m_pDC->ExtTextOut (pRect->right, nTop, ETO_CLIPPED, NULL, m_strCDTitle, NULL);
}
pOldFont = rdc.m_pDC->SelectObject (pOldFont);
if (pOldFont != NULL)
pOldFont->DeleteObject ();
/*
// draw sides
CFont* pOldFont = style.SelectInlaySideFont (rdc, m_dSideFontFactor);
if (style.GetInlaySideTextDirection ())
{
int nTop = style.GetInlaySideVAlignTop (rdc, rdc.m_pDC->GetTextExtent (m_strCDTitle).cx);
CRect* pRect = style.GetInlayLeftSideRect (rdc);
if (pRect->Width () > 0)
rdc.m_pDC->ExtTextOut (pRect->left, pRect->bottom - nTop, ETO_CLIPPED, NULL, m_strCDTitle, NULL);
pRect = style.GetInlayRightSideRect (rdc);
if (pRect->Width () > 0)
rdc.m_pDC->ExtTextOut (pRect->left, pRect->bottom - nTop, ETO_CLIPPED, NULL, m_strCDTitle, NULL);
}
else
{
CRect* pRect = style.GetInlayLeftSideRect (rdc);
int nTop = style.GetInlaySideVAlignTop (rdc, rdc.m_pDC->GetTextExtent (m_strCDTitle).cx);
if (pRect->Width () > 0)
rdc.m_pDC->ExtTextOut (pRect->right, nTop, ETO_CLIPPED, NULL, m_strCDTitle, NULL);
pRect = style.GetInlayRightSideRect (rdc);
if (pRect->Width () > 0)
rdc.m_pDC->ExtTextOut (pRect->right, nTop, ETO_CLIPPED, NULL, m_strCDTitle, NULL);
}
pOldFont = rdc.m_pDC->SelectObject (pOldFont);
if (pOldFont != NULL)
pOldFont->DeleteObject ();
*/
}
}
void CDataCDInfo::CalcInlaySideBarRect (CRenderDC& rdc, CStyleTemplate& style)
{
// sides font factor
CFont* pOldFont = style.SelectInlaySideFont (rdc, true);
CSize szSides = rdc.m_pDC->GetTextExtent (m_strCDTitle);
CRect* pRect = style.GetInlayRightSideRect (rdc);
// since the font is rotated (by 90°) and GetTextExtent does not
// take into account font rotation, "compute" the rotation explicitely, i.e.
// cx <- cy, cy <- cx.
m_dSideFontFactor = min (
pRect->Width () / ((double) (szSides.cy + 1)),
pRect->Height () / ((double) (szSides.cx + 1)));
pOldFont = rdc.m_pDC->SelectObject (pOldFont);
if (pOldFont != NULL)
pOldFont->DeleteObject ();
}
void CDataCDInfo::Serialize (CArchive& ar)
{
if (ar.IsLoading ())
{
ar >> m_strCDTitle;
for (int i = 0; i < NUM_RENDER_TYPES; i++)
ar >> m_strRTFTitle[i];
}
else
{
ar << m_strCDTitle;
for (int i = 0; i < NUM_RENDER_TYPES; i++)
ar << m_strRTFTitle[i];
}
if (m_pDirTree == NULL)
m_pDirTree = new CDirTree ();
m_pDirTree->Serialize (ar);
}
CDataCDInfo& CDataCDInfo::operator = (CDataCDInfo& info)
{
for (int i = 0; i < NUM_RENDER_TYPES; i++)
m_strRTFTitle[i] = info.GetRTFTitle ((RenderType) i);
m_strCDTitle = info.m_strCDTitle;
if (m_pDirTree == NULL)
m_pDirTree = new CDirTree ();
*m_pDirTree = *(info.m_pDirTree);
return *this;
}
bool CDataCDInfo::operator == (CDataCDInfo& info)
{
for (int i = 0; i < NUM_RENDER_TYPES; i++)
if (m_strRTFTitle[i] != info.GetRTFTitle ((RenderType) i))
return false;
if (m_strCDTitle != info.m_strCDTitle)
return false;
if (*m_pDirTree != *(info.m_pDirTree))
return false;
return true;
}
bool CDataCDInfo::operator != (CDataCDInfo& info)
{
return !(*this == info);
}