Skip to content

Commit

Permalink
June 2016
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn committed Jul 1, 2016
1 parent 5936be6 commit 550385d
Show file tree
Hide file tree
Showing 418 changed files with 79,632 additions and 6,909 deletions.
215 changes: 215 additions & 0 deletions Kits/ATGTK/ControllerFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,219 @@ namespace DX
textFont->DrawString(spriteBatch, strBuffer, outPos, color, 0.f, XMFLOAT2(0.f, 0.f), XMFLOAT2(scale, scale));
}
}

inline RECT XM_CALLCONV MeasureControllerDrawBounds(_In_ DirectX::SpriteFont* textFont, _In_ DirectX::SpriteFont* butnFont,
_In_z_ wchar_t const* text, DirectX::XMFLOAT2 const& position, float scale = 1)
{
using namespace DirectX;

size_t textLen = wcslen(text);
if (textLen >= 4096)
{
throw std::out_of_range("String is too long");
}

float buttonHeight = butnFont->GetLineSpacing();
float buttonScale = (textFont->GetLineSpacing() * scale) / buttonHeight;
float offsetY = buttonScale / 2.f;

size_t j = 0;
wchar_t strBuffer[4096] = { 0 };

bool buttonText = false;

XMFLOAT2 outPos = position;

RECT result = { LONG_MAX, LONG_MAX, 0, 0 };
for (size_t ch = 0; ch < textLen; ++ch)
{
if (buttonText)
{
strBuffer[j++] = text[ch];

if (text[ch] == L']')
{
wchar_t button[2] = { 0 };

if (_wcsicmp(strBuffer, L"[A]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::AButton);
}
else if (_wcsicmp(strBuffer, L"[B]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::BButton);
}
else if (_wcsicmp(strBuffer, L"[X]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::XButton);
}
else if (_wcsicmp(strBuffer, L"[Y]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::YButton);
}
else if (_wcsicmp(strBuffer, L"[DPad]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::DPad);
}
else if (_wcsicmp(strBuffer, L"[View]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::View);
}
else if (_wcsicmp(strBuffer, L"[Menu]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::Menu);
}
else if (_wcsicmp(strBuffer, L"[Nexus]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::Nexus);
}
else if (_wcsicmp(strBuffer, L"[RThumb]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::RightThumb);
}
else if (_wcsicmp(strBuffer, L"[LThumb]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::LeftThumb);
}
else if (_wcsicmp(strBuffer, L"[RB]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::RightShoulder);
}
else if (_wcsicmp(strBuffer, L"[LB]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::LeftShoulder);
}
else if (_wcsicmp(strBuffer, L"[RT]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::RightTrigger);
}
else if (_wcsicmp(strBuffer, L"[LT]") == 0)
{
*button = static_cast<wchar_t>(ControllerFont::LeftTrigger);
}

if (*button)
{
float bsize = XMVectorGetX(butnFont->MeasureString(button));
float offsetX = (bsize * buttonScale / 2.f);

if (outPos.x < result.left)
result.left = long(outPos.x);

if (outPos.y < result.top)
result.top = long(outPos.y);

outPos.x += offsetX;
outPos.y -= offsetY;

if (outPos.x < result.left)
result.left = long(outPos.x);

if (outPos.y < result.top)
result.top = long(outPos.y);

outPos.x += bsize * buttonScale;
outPos.y += offsetY;

if (result.right < outPos.x)
result.right = long(outPos.x);

if (result.bottom < outPos.y)
result.bottom = long(outPos.y);
}

memset(strBuffer, 0, sizeof(strBuffer));
j = 0;

buttonText = false;
}
}
else
{
switch (text[ch])
{
case '\r':
break;

case '[':
if (*strBuffer)
{
if (outPos.x < result.left)
result.left = long(outPos.x);

if (outPos.y < result.top)
result.top = long(outPos.y);

outPos.x += XMVectorGetX(textFont->MeasureString(strBuffer)) * scale;

if (result.right < outPos.x)
result.right = long(outPos.x);

if (result.bottom < outPos.y)
result.bottom = long(outPos.y);

memset(strBuffer, 0, sizeof(strBuffer));
j = 0;
}
buttonText = true;
*strBuffer = L'[';
++j;
break;

case '\n':
if (*strBuffer)
{
if (outPos.x < result.left)
result.left = long(outPos.x);

if (outPos.y < result.top)
result.top = long(outPos.y);

outPos.x += XMVectorGetX(textFont->MeasureString(strBuffer)) * scale;

if (result.right < outPos.x)
result.right = long(outPos.x);

if (result.bottom < outPos.y)
result.bottom = long(outPos.y);

memset(strBuffer, 0, sizeof(strBuffer));
j = 0;
}
outPos.x = position.x;
outPos.y += textFont->GetLineSpacing() * scale;
break;

default:
strBuffer[j++] = text[ch];
break;
}
}
}

if (*strBuffer)
{
if (outPos.x < result.left)
result.left = long(outPos.x);

if (outPos.y < result.top)
result.top = long(outPos.y);

outPos.x += XMVectorGetX(textFont->MeasureString(strBuffer)) * scale;

if (result.right < outPos.x)
result.right = long(outPos.x);

if (result.bottom < outPos.y)
result.bottom = long(outPos.y);
}

if (result.left == LONG_MAX)
{
result.left = 0;
result.top = 0;
}

return result;
}
}
4 changes: 2 additions & 2 deletions Kits/ATGTK/TextConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ void TextConsole::SetWindow(const RECT& layout)
float lineSpacing = m_font->GetLineSpacing();
unsigned int rows = std::max<unsigned int>(1, static_cast<unsigned int>(float(layout.bottom - layout.top) / lineSpacing));

auto charSize = m_font->MeasureString(L"M");
unsigned int columns = std::max<unsigned int>(1, static_cast<unsigned int>(float(layout.right - layout.left) / XMVectorGetX(charSize)));
RECT fontLayout = m_font->MeasureDrawBounds(L"X", XMFLOAT2(0,0));
unsigned int columns = std::max<unsigned int>(1, static_cast<unsigned int>(float(layout.right - layout.left) / float(fontLayout.right - fontLayout.left)));

std::unique_ptr<wchar_t[]> buffer(new wchar_t[(columns + 1) * rows]);
memset(buffer.get(), 0, sizeof(wchar_t) * (columns + 1) * rows);
Expand Down
6 changes: 5 additions & 1 deletion Kits/DirectXTK/DirectXTK_Windows10.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@
<ClInclude Include="Src\dds.h" />
<ClInclude Include="Src\DemandCreate.h" />
<ClInclude Include="Src\EffectCommon.h" />
<ClInclude Include="Src\Geometry.h" />
<ClInclude Include="Src\LoaderHelpers.h" />
<ClInclude Include="Src\pch.h" />
<ClInclude Include="Src\PlatformHelpers.h" />
<ClInclude Include="Src\SDKMesh.h" />
<ClInclude Include="Src\SharedResourcePool.h" />
<ClInclude Include="Src\vbo.h" />
</ItemGroup>
<ItemGroup>
<None Include="Inc\SimpleMath.inl" />
Expand Down Expand Up @@ -151,7 +155,6 @@
<None Include="Src\Shaders\CompileShaders.cmd" />
<None Include="Src\Shaders\Lighting.fxh" />
<None Include="Src\Shaders\Structures.fxh" />
<None Include="Src\sources" />
<None Include="Src\TeapotData.inc" />
</ItemGroup>
<ItemGroup>
Expand All @@ -176,6 +179,7 @@
<ClCompile Include="Src\EnvironmentMapEffect.cpp" />
<ClCompile Include="Src\GamePad.cpp" />
<ClCompile Include="Src\GeometricPrimitive.cpp" />
<ClCompile Include="Src\Geometry.cpp" />
<ClCompile Include="Src\GraphicsMemory.cpp" />
<ClCompile Include="Src\Keyboard.cpp" />
<ClCompile Include="Src\Model.cpp" />
Expand Down
Loading

0 comments on commit 550385d

Please sign in to comment.