Rise
The Vieneo Province
Loading...
Searching...
No Matches
KeyboardChart.h
Go to the documentation of this file.
1#pragma once
2
3#include <winsock2.h>
4#include <windows.h>
6#ifndef DIRECTINPUT_VERSION
7#define DIRECTINPUT_VERSION 0x0800
8#endif
9#include <dinput.h>
10#include <array>
11#include <string>
12#include <vector>
13#include <map>
14#include <tuple>
15#include "Viewscreen/binding.h"
16
17namespace Keychart
18{
19 constexpr int Width = 1815;
20 constexpr int ModifierCount = 4; // Key, Shift, Control, Control + Shift.
21 constexpr int KeyRowHeight = 124;
22 constexpr int LabelTop = 25;
23 constexpr int LabelHeight = 22;
24 constexpr int Height = 68 + 6 * KeyRowHeight + 12;
25
26 struct Key
27 {
28 short scancode;
29 RECT bounds;
30 const wchar_t* caption;
31 };
32
33 const std::vector<Key>& Layout();
34 struct Label
35 {
36 std::wstring full;
37 std::wstring shortName;
38
39 bool operator==(const Label& other) const
40 {
41 return full == other.full && shortName == other.shortName;
42 }
43 };
44 using Labels = std::array<std::array<Label, ModifierCount>, 256>;
45 Label ControlLabel(BindingEnum function, const Label& normal);
46
47 constexpr double MarqueeStartHold = 3.0;
48 constexpr double MarqueeEndHold = 1.0;
49 constexpr double MarqueePixelsPerSecond = 36.0;
51 {
52 double offset = 0.0;
53 bool showEllipsis = true;
54 };
55 MarqueePosition Marquee(double elapsedSeconds, LONG textWidth, LONG availableWidth);
56
57 // Rebuilt from the current configuration on every visible frame, including
58 // remaps, deletions, profile changes and changes to the selected language.
59 template<typename Translate>
60 Labels BuildLabels(const std::vector<KeyBinding>& bindings, char profile, bool admin, Translate translate)
61 {
62 Labels labels{};
63 for (const auto& binding : bindings)
64 {
65 const auto function = static_cast<unsigned int>(binding.function);
66 if (function >= BindingEnum::ENUMERATION || binding.scancode <= 0 || binding.scancode >= 256)
67 continue;
68 if (!(allowedUsage[function] & profile) || (!admin && (allowedUsage[function] & ProfileFlags::ADMIN)))
69 continue;
70 auto text = translate(binding.function);
71 if (text.full.empty())
72 continue;
73 auto append = [](Label& label, const Label& text)
74 {
75 if (text.full.empty()) return;
76 if (!label.full.empty())
77 {
78 // Do not silently hide conflicting active bindings in any modifier row.
79 label.full += L" / ";
80 label.shortName += L" / ";
81 }
82 label.full += text.full;
83 label.shortName += text.shortName.empty() || text.shortName == L"//" ? text.full : text.shortName;
84 };
85 const int modifier = binding.shift ? 1 : 0;
86 append(labels[binding.scancode][modifier], text);
87 append(labels[binding.scancode][modifier + 2], ControlLabel(binding.function, text));
88 }
89 return labels;
90 }
91}
92
94{
95public:
97 void OnLostDevice();
98 void OnResetDevice();
99 void OnDestroyDevice();
100 void Update(bool visible, float elapsedSeconds);
101 void Draw(Rendering::RenderSprite* sprite, const Keychart::Labels& labels,
102 const std::wstring& title, int displayWidth, int displayHeight);
103
104private:
107 bool wasVisible = false;
108 double visibleSeconds = 0.0;
110 std::wstring previousTitle;
112 {
113 LONG width;
114 std::wstring selected;
115 std::wstring fitted;
116 };
117 std::map<std::tuple<std::wstring, std::wstring, LONG>, TextLayout> textLayouts;
118};
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
BindingEnum
Definition binding.h:6
@ ENUMERATION
Definition binding.h:106
@ ADMIN
Definition binding.h:115
void Draw(Rendering::RenderSprite *sprite, const Keychart::Labels &labels, const std::wstring &title, int displayWidth, int displayHeight)
Rendering::RenderFont * font
void Update(bool visible, float elapsedSeconds)
double visibleSeconds
std::map< std::tuple< std::wstring, std::wstring, LONG >, TextLayout > textLayouts
HRESULT OnCreateDevice(Rendering::RenderDevice *device)
Rendering::RenderTexture * blankKeyboard
std::wstring previousTitle
Keychart::Labels previousLabels
const std::vector< Key > & Layout()
constexpr double MarqueeEndHold
Label ControlLabel(BindingEnum function, const Label &normal)
MarqueePosition Marquee(double elapsedSeconds, LONG textWidth, LONG availableWidth)
Labels BuildLabels(const std::vector< KeyBinding > &bindings, char profile, bool admin, Translate translate)
constexpr int LabelTop
constexpr double MarqueePixelsPerSecond
constexpr double MarqueeStartHold
constexpr int Width
std::array< std::array< Label, ModifierCount >, 256 > Labels
constexpr int Height
constexpr int ModifierCount
constexpr int KeyRowHeight
constexpr int LabelHeight
const wchar_t * caption
std::wstring full
std::wstring shortName
bool operator==(const Label &other) const