Rise
The Vieneo Province
Toggle main menu visibility
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>
5
#include "
Rendering/ClientRuntime11.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
17
namespace
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;
50
struct
MarqueePosition
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
93
class
KeyboardChart
94
{
95
public
:
96
HRESULT
OnCreateDevice
(
Rendering::RenderDevice
* device);
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
104
private
:
105
Rendering::RenderTexture
*
blankKeyboard
=
nullptr
;
106
Rendering::RenderFont
*
font
=
nullptr
;
107
bool
wasVisible
=
false
;
108
double
visibleSeconds
= 0.0;
109
Keychart::Labels
previousLabels
{};
110
std::wstring
previousTitle
;
111
struct
TextLayout
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
};
ClientRuntime11.h
HRESULT
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
binding.h
BindingEnum
BindingEnum
Definition
binding.h:6
ENUMERATION
@ ENUMERATION
Definition
binding.h:106
ADMIN
@ ADMIN
Definition
binding.h:115
KeyboardChart
Definition
KeyboardChart.h:94
KeyboardChart::Draw
void Draw(Rendering::RenderSprite *sprite, const Keychart::Labels &labels, const std::wstring &title, int displayWidth, int displayHeight)
Definition
KeyboardChart.cpp:202
KeyboardChart::OnLostDevice
void OnLostDevice()
Definition
KeyboardChart.cpp:174
KeyboardChart::font
Rendering::RenderFont * font
Definition
KeyboardChart.h:106
KeyboardChart::Update
void Update(bool visible, float elapsedSeconds)
Definition
KeyboardChart.cpp:193
KeyboardChart::OnDestroyDevice
void OnDestroyDevice()
Definition
KeyboardChart.cpp:184
KeyboardChart::visibleSeconds
double visibleSeconds
Definition
KeyboardChart.h:108
KeyboardChart::textLayouts
std::map< std::tuple< std::wstring, std::wstring, LONG >, TextLayout > textLayouts
Definition
KeyboardChart.h:117
KeyboardChart::OnCreateDevice
HRESULT OnCreateDevice(Rendering::RenderDevice *device)
Definition
KeyboardChart.cpp:125
KeyboardChart::blankKeyboard
Rendering::RenderTexture * blankKeyboard
Definition
KeyboardChart.h:105
KeyboardChart::wasVisible
bool wasVisible
Definition
KeyboardChart.h:107
KeyboardChart::previousTitle
std::wstring previousTitle
Definition
KeyboardChart.h:110
KeyboardChart::OnResetDevice
void OnResetDevice()
Definition
KeyboardChart.cpp:179
KeyboardChart::previousLabels
Keychart::Labels previousLabels
Definition
KeyboardChart.h:109
Rendering::RenderDevice
Definition
ClientRenderer11.h:92
Rendering::RenderFont
Definition
ClientRenderer11.h:222
Rendering::RenderSprite
Definition
ClientRenderer11.h:198
Rendering::RenderTexture
Definition
ClientRenderer11.h:32
Keychart
Definition
KeyboardChart.h:18
Keychart::Layout
const std::vector< Key > & Layout()
Definition
KeyboardChart.cpp:42
Keychart::MarqueeEndHold
constexpr double MarqueeEndHold
Definition
KeyboardChart.h:48
Keychart::ControlLabel
Label ControlLabel(BindingEnum function, const Label &normal)
Definition
KeyboardChart.cpp:5
Keychart::Marquee
MarqueePosition Marquee(double elapsedSeconds, LONG textWidth, LONG availableWidth)
Definition
KeyboardChart.cpp:30
Keychart::BuildLabels
Labels BuildLabels(const std::vector< KeyBinding > &bindings, char profile, bool admin, Translate translate)
Definition
KeyboardChart.h:60
Keychart::LabelTop
constexpr int LabelTop
Definition
KeyboardChart.h:22
Keychart::MarqueePixelsPerSecond
constexpr double MarqueePixelsPerSecond
Definition
KeyboardChart.h:49
Keychart::MarqueeStartHold
constexpr double MarqueeStartHold
Definition
KeyboardChart.h:47
Keychart::Width
constexpr int Width
Definition
KeyboardChart.h:19
Keychart::Labels
std::array< std::array< Label, ModifierCount >, 256 > Labels
Definition
KeyboardChart.h:44
Keychart::Height
constexpr int Height
Definition
KeyboardChart.h:24
Keychart::ModifierCount
constexpr int ModifierCount
Definition
KeyboardChart.h:20
Keychart::KeyRowHeight
constexpr int KeyRowHeight
Definition
KeyboardChart.h:21
Keychart::LabelHeight
constexpr int LabelHeight
Definition
KeyboardChart.h:23
KeyboardChart::TextLayout
Definition
KeyboardChart.h:112
KeyboardChart::TextLayout::selected
std::wstring selected
Definition
KeyboardChart.h:114
KeyboardChart::TextLayout::fitted
std::wstring fitted
Definition
KeyboardChart.h:115
KeyboardChart::TextLayout::width
LONG width
Definition
KeyboardChart.h:113
Keychart::Key
Definition
KeyboardChart.h:27
Keychart::Key::scancode
short scancode
Definition
KeyboardChart.h:28
Keychart::Key::bounds
RECT bounds
Definition
KeyboardChart.h:29
Keychart::Key::caption
const wchar_t * caption
Definition
KeyboardChart.h:30
Keychart::Label
Definition
KeyboardChart.h:35
Keychart::Label::full
std::wstring full
Definition
KeyboardChart.h:36
Keychart::Label::shortName
std::wstring shortName
Definition
KeyboardChart.h:37
Keychart::Label::operator==
bool operator==(const Label &other) const
Definition
KeyboardChart.h:39
Keychart::MarqueePosition
Definition
KeyboardChart.h:51
Keychart::MarqueePosition::showEllipsis
bool showEllipsis
Definition
KeyboardChart.h:53
Keychart::MarqueePosition::offset
double offset
Definition
KeyboardChart.h:52
KeyboardChart.h
Generated on
for Rise by
1.18.0