forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FontViewerScreen.cpp
137 lines (112 loc) · 3.5 KB
/
FontViewerScreen.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
//--------------------------------------------------------------------------------------
// FontViewerScreen.cpp
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "FontViewerScreen.h"
#include "FontManager.h"
#include "FrontPanel/FrontPanelDisplay.h"
using namespace ATG;
const wchar_t *FontViewerScreen::s_defaultSampleText = L"ABCEDFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n0123456789";
FontViewerScreen::FontViewerScreen(FrontPanelManager * owner, const wchar_t * faceName, unsigned titleHeight, const wchar_t * fileName)
: PanelScreen(owner)
, m_titleHeight(titleHeight)
, m_faceName(faceName)
{
m_currentFont = m_heightToFontFile.cbegin();
AddFontFile(titleHeight, fileName);
}
void FontViewerScreen::AddFontFile(unsigned height, const wchar_t * fileName, const wchar_t *sampleText)
{
unsigned curHeight = height;
if (m_currentFont != m_heightToFontFile.cend())
{
curHeight = m_currentFont->first;
}
FontData data{ fileName, sampleText };
m_heightToFontFile[height] = data;
m_currentFont = m_heightToFontFile.find(curHeight);
}
void FontViewerScreen::RenderFrontPanel()
{
// Get the fonts
ATG::RasterFont &titleFont = FontManager::Instance().LoadFont(m_heightToFontFile[m_titleHeight].filename);
ATG::RasterFont &curFont = FontManager::Instance().LoadFont(m_currentFont->second.filename);
auto &frontPanelDisplay = FrontPanelDisplay::Get();
frontPanelDisplay.Clear();
BufferDesc fpDesc = frontPanelDisplay.GetBufferDescriptor();
int x = 0;
int y = 0;
// Draw the title text
titleFont.DrawStringFmt(fpDesc, x, y, L"%s %i", m_faceName, m_currentFont->first);
y += titleFont.GetLineSpacing();
// Draw the sample text
curFont.DrawString(fpDesc, x, y, m_currentFont->second.sampleText);
// Draw the navigation hints
{
x = fpDesc.width - m_nav.GetWidth();
y = 0;
if (m_currentFont != m_heightToFontFile.cbegin())
{
m_nav.DrawLeftIndicator(fpDesc, x, y);
}
auto tmp = m_currentFont;
++tmp;
if (tmp != m_heightToFontFile.cend())
{
m_nav.DrawRightIndicator(fpDesc, x, y);
}
if (m_upNeighbor)
{
m_nav.DrawUpIndicator(fpDesc, x, y);
}
if (m_downNeighbor)
{
m_nav.DrawDownIndicator(fpDesc, x, y);
}
}
frontPanelDisplay.Present();
}
bool FontViewerScreen::OnButtonPressed(XBOX_FRONT_PANEL_BUTTONS whichButton)
{
switch (whichButton)
{
case XBOX_FRONT_PANEL_BUTTONS_LEFT:
if (m_currentFont != m_heightToFontFile.cbegin())
{
--m_currentFont;
RenderFrontPanel();
return true;
}
break;
case XBOX_FRONT_PANEL_BUTTONS_RIGHT:
{
auto tmp = m_currentFont;
++tmp;
if (tmp != m_heightToFontFile.cend())
{
m_currentFont = tmp;
RenderFrontPanel();
return true;
}
}
break;
case XBOX_FRONT_PANEL_BUTTONS_UP:
if (m_upNeighbor)
{
m_upNeighbor->Resume(this);
return true;
}
break;
case XBOX_FRONT_PANEL_BUTTONS_DOWN:
if (m_downNeighbor)
{
m_downNeighbor->Resume(this);
return true;
}
break;
}
return false;
}