forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationHint.cpp
157 lines (137 loc) · 4.58 KB
/
NavigationHint.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
//--------------------------------------------------------------------------------------
// NavigationHint.hpp
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include "pch.h"
#include "NavigationHint.h"
#include "FontManager.h"
NavigationHint::NavigationHint(
const wchar_t *fontName,
wchar_t leftIndicator,
wchar_t rightIndicator,
wchar_t upIndicator,
wchar_t downIndicator,
unsigned clientWidth,
unsigned clientHeight)
: m_font(FontManager::Instance().LoadFont(fontName))
, m_leftIndicator(leftIndicator)
, m_rightIndicator(rightIndicator)
, m_upIndicator(upIndicator)
, m_downIndicator(downIndicator)
, m_width(0)
, m_height(0)
, m_leftOffsetX(0)
, m_leftOffsetY(0)
, m_rightOffsetX(0)
, m_rightOffsetY(0)
, m_upOffsetX(0)
, m_upOffsetY(0)
, m_downOffsetX(0)
, m_downOffsetY(0)
{
SetClientDimensions(clientWidth, clientHeight);
}
NavigationHint::~NavigationHint()
{
}
void NavigationHint::DrawLeftIndicator(const ATG::BufferDesc &desc, int x, int y)
{
if (m_leftIndicator)
{
m_font.DrawGlyph(desc, x + m_leftOffsetX, y + m_leftOffsetY, m_leftIndicator);
}
}
void NavigationHint::DrawRightIndicator(const ATG::BufferDesc & desc, int x, int y)
{
if (m_rightIndicator)
{
m_font.DrawGlyph(desc, x + m_rightOffsetX, y + m_rightOffsetY, m_rightIndicator);
}
}
void NavigationHint::DrawUpIndicator(const ATG::BufferDesc & desc, int x, int y)
{
if (m_upIndicator)
{
m_font.DrawGlyph(desc, x + m_upOffsetX, y + m_upOffsetY, m_upIndicator);
}
}
void NavigationHint::DrawDownIndicator(const ATG::BufferDesc & desc, int x, int y)
{
if (m_downIndicator)
{
m_font.DrawGlyph(desc, x + m_downOffsetX, y + m_downOffsetY, m_downIndicator);
}
}
void NavigationHint::SetClientDimensions(unsigned clientWidth, unsigned clientHeight)
{
unsigned upWidth = 0;
unsigned upHeight = 0;
if (m_upIndicator)
{
auto upMeasurement = m_font.MeasureGlyph(m_upIndicator);
upWidth = upMeasurement.right - upMeasurement.left;
upHeight = upMeasurement.bottom - upMeasurement.top;
}
unsigned downWidth = 0;
unsigned downHeight = 0;
if(m_downIndicator)
{
auto downMeasurement = m_font.MeasureGlyph(m_downIndicator);
downWidth = downMeasurement.right - downMeasurement.left;
downHeight = downMeasurement.bottom - downMeasurement.top;
}
unsigned leftWidth = 0;
unsigned leftHeight = 0;
if (m_leftIndicator)
{
auto leftMeasurement = m_font.MeasureGlyph(m_leftIndicator);
leftWidth = leftMeasurement.right - leftMeasurement.left;
leftHeight = leftMeasurement.bottom - leftMeasurement.top;
}
unsigned rightWidth = 0;
unsigned rightHeight = 0;
if(m_rightIndicator)
{
auto rightMeasurement = m_font.MeasureGlyph(m_rightIndicator);
rightWidth = rightMeasurement.right - rightMeasurement.left;
rightHeight = rightMeasurement.bottom - rightMeasurement.top;
}
unsigned cw = 1;
cw = std::max(cw, clientWidth);
cw = std::max(cw, upWidth + 2);
cw = std::max(cw, downWidth + 2);
unsigned ch = 1;
ch = std::max(ch, clientHeight);
// update the client rectangle
m_clientRect.left = leftWidth;
m_clientRect.right = leftWidth + cw;
m_clientRect.top = upHeight;
m_clientRect.bottom = upHeight + ch;
// Compute the width and height
m_width = leftWidth + cw + rightWidth;
m_height = upHeight + ch + downHeight;
m_height = std::max(m_height, leftHeight);
m_height = std::max(m_height, rightHeight);
// Compute the coordinates for the left indicator
m_leftOffsetX = 0;
m_leftOffsetY = static_cast<unsigned>(floor(0.5f + (m_height - leftHeight) / 2.0f));
// Compute the coordinates for the right indicator
m_rightOffsetX = leftWidth + cw;
m_rightOffsetY = static_cast<unsigned>(floor(0.5f + (m_height - rightHeight) / 2.0f));
// Compute the cooridates for the up indicator
m_upOffsetX = static_cast<unsigned>(floor(0.5f + (m_width - upWidth) / 2.0f));
m_upOffsetY = 0;
// Compute the coordinates for the down indicator
m_downOffsetX = static_cast<unsigned>(floor(0.5f + (m_width - downWidth) / 2.0f));
m_downOffsetY = upHeight + ch;
}
BasicNavigationHint::BasicNavigationHint()
: NavigationHint(
L"assets\\LucidaConsole12.rasterfont",
0x25C4, 0x25BA, 0x25B2, 0x25BC,
0, 0
)
{
}