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
|
#include "stdafx.h"
#include "CLCDGfx.h"
#include "CLCDObject.h"
#include "CLCDTextObject.h"
//************************************************************************
// constructor
//************************************************************************
CLCDTextObject::CLCDTextObject()
{
m_hFont = NULL;
m_iFontHeight = 0;
// Initialize DRAWTEXTPARAMS
memset(&m_dtp, 0, sizeof(DRAWTEXTPARAMS));
m_dtp.cbSize = sizeof(DRAWTEXTPARAMS);
// Initialize alignment
m_iTextFormat = m_iTextAlignment = (DT_LEFT | DT_NOPREFIX);
}
//************************************************************************
// destructor
//************************************************************************
CLCDTextObject::~CLCDTextObject()
{
if(m_hFont)
{
DeleteObject(m_hFont);
}
}
//************************************************************************
// initializes the textobject
//************************************************************************
bool CLCDTextObject::Initialize()
{
m_hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
if(NULL != m_hFont)
{
SetFontFaceName(_T("Small Fonts"));
SetFontPointSize(6);
}
return true;
}
//************************************************************************
// deinitializes the textobject
//************************************************************************
bool CLCDTextObject::Shutdown()
{
return true;
}
//************************************************************************
// draws the textobject
//************************************************************************
bool CLCDTextObject::Draw(CLCDGfx *pGfx)
{
return true;
}
//************************************************************************
// updates the textobject
//************************************************************************
bool CLCDTextObject::Update()
{
return true;
}
//************************************************************************
// sets the textobject's font
//************************************************************************
bool CLCDTextObject::SetFont(LOGFONT& lf)
{
if (m_hFont)
{
DeleteObject(m_hFont);
m_hFont = NULL;
}
m_hFont = CreateFontIndirect(&lf);
if(!m_hFont)
return false;
// Calculate the font's height
HDC hDC = CreateCompatibleDC(NULL);
SelectObject(hDC, m_hFont);
TEXTMETRIC tmFontInfo;
GetTextMetrics(hDC,&tmFontInfo);
m_iFontHeight = tmFontInfo.tmHeight;
DeleteObject(hDC);
OnFontChanged();
return true;
}
//************************************************************************
// sets the textobject's font's facename
//************************************************************************
void CLCDTextObject::SetFontFaceName(tstring strFontName)
{
// if NULL, uses the default gui font
if (strFontName.empty())
return;
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
GetObject(m_hFont, sizeof(LOGFONT), &lf);
mir_tstrncpy(lf.lfFaceName, strFontName.c_str(), LF_FACESIZE);
SetFont(lf);
}
//************************************************************************
// sets the textobject's font's point size
//************************************************************************
void CLCDTextObject::SetFontPointSize(int nPointSize)
{
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
GetObject(m_hFont, sizeof(LOGFONT), &lf);
lf.lfHeight = -MulDiv(nPointSize, 96, 72);
SetFont(lf);
}
//************************************************************************
// sets the textobject's font to italic
//************************************************************************
void CLCDTextObject::SetFontItalic(bool flag) {
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
GetObject(m_hFont, sizeof(LOGFONT), &lf);
lf.lfItalic = flag;
SetFont(lf);
}
//************************************************************************
// sets the textobject's font's weight
//************************************************************************
void CLCDTextObject::SetFontWeight(int nWeight)
{
LOGFONT lf;
memset(&lf, 0, sizeof(lf));
GetObject(m_hFont, sizeof(LOGFONT), &lf);
lf.lfWeight = nWeight;
SetFont(lf);
}
//************************************************************************
// sets the textobject's alignment
//************************************************************************
void CLCDTextObject::SetAlignment(int iAlignment)
{
m_iTextFormat &= ~m_iTextAlignment;
m_iTextFormat |= iAlignment;
m_iTextAlignment = iAlignment;
}
//************************************************************************
// sets the textobject's wordwrap mode
//************************************************************************
void CLCDTextObject::SetWordWrap(bool bWrap)
{
m_bWordWrap = bWrap;
if (bWrap)
m_iTextFormat |= DT_WORDBREAK;
else
m_iTextFormat &= ~DT_WORDBREAK;
}
//************************************************************************
// called when the textobject's font has changed
//************************************************************************
void CLCDTextObject::OnFontChanged()
{
}
|