-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCCartoucheBlock.cpp
131 lines (101 loc) · 2.39 KB
/
CCartoucheBlock.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
// CCartoucheBlock.cpp
//
// CCartoucheBlock class
// Copyright (c) 2018 Kronosaur Productions, LLC. All Rights Reserved.
#include <windows.h>
#include "Alchemy.h"
#include "DirectXUtil.h"
#include <math.h>
#include <stdio.h>
#include "TextFormat.h"
void CCartoucheBlock::Add (const TArray<SCartoucheDesc> &List)
// Add
//
// Adds a list of cartouches.
{
m_Data.GrowToFit(List.GetCount());
for (int i = 0; i < List.GetCount(); i++)
AddCartouche(List[i].sText, List[i].rgbColor, List[i].rgbBack);
}
void CCartoucheBlock::AddCartouche (const CString &sText, CG32bitPixel rgbColor, CG32bitPixel rgbBack)
// AddCartouche
//
// Adds a new cartouche.
{
SCartouche *pEntry = m_Data.Insert();
pEntry->sText = sText;
pEntry->rgbColor = rgbColor;
pEntry->rgbBack = rgbBack;
Invalidate();
}
void CCartoucheBlock::Format (int cxWidth)
// Format
//
// Formats the block to the given width.
{
if (m_bFormatted || m_pFont == NULL)
return;
m_cxWidth = cxWidth;
int cxLeft = cxWidth;
int x = 0;
int y = 0;
for (int i = 0; i < m_Data.GetCount(); i++)
{
int cxText = (ATTRIB_PADDING_X * 2) + m_pFont->MeasureText(m_Data[i].sText);
int cyText = (ATTRIB_PADDING_Y * 2) + m_pFont->GetHeight();
if (cxText > cxLeft && cxLeft != cxWidth)
{
x = 0;
y += cyText + ATTRIB_SPACING_Y;
cxLeft = cxWidth;
}
m_Data[i].x = x;
m_Data[i].y = y;
m_Data[i].cx = cxText;
m_Data[i].cy = cyText;
x += cxText + ATTRIB_SPACING_X;
cxLeft -= cxText + ATTRIB_SPACING_X;
}
if (m_Data.GetCount() > 0)
m_cyHeight = y + (ATTRIB_PADDING_Y * 2) + m_pFont->GetHeight();
else
m_cyHeight = 0;
m_bFormatted = true;
}
RECT CCartoucheBlock::GetBounds (void) const
// GetBounds
//
// Returns the rectangular bounds.
{
RECT rcRect;
rcRect.left = 0;
rcRect.top = 0;
rcRect.right = m_cxWidth;
rcRect.bottom = m_cyHeight;
return rcRect;
}
void CCartoucheBlock::Paint (CG32bitImage &Dest, int x, int y) const
// Paint
//
// Paint at the given position.
{
if (!m_bFormatted || m_pFont == NULL)
return;
for (int i = 0; i < m_Data.GetCount(); i++)
{
// Draw the background
CGDraw::RoundedRect(Dest,
x + m_Data[i].x,
y + m_Data[i].y,
m_Data[i].cx,
m_Data[i].cy,
RADIUS,
m_Data[i].rgbBack);
// Draw the text
m_pFont->DrawText(Dest,
x + m_Data[i].x + ATTRIB_PADDING_X,
y + m_Data[i].y + ATTRIB_PADDING_Y,
m_Data[i].rgbColor,
m_Data[i].sText);
}
}