CommonLibSSE (Parapets fork)
Loading...
Searching...
No Matches
GFxTranslator.h
Go to the documentation of this file.
1#pragma once
2
3#include "RE/G/GFxState.h"
4#include "RE/G/GFxWWHelper.h"
5
6namespace RE
7{
8 class GFxWStringBuffer;
9
10 class GFxTranslator : public GFxState
11 {
12 public:
13 inline static constexpr auto RTTI = RTTI_GFxTranslator;
14
16
17 // TranslateCaps is an enumeration type defining the translation capabilities of the Translator object. In general, capability flags are used to determine two things:
18 // * The type of strings can be passed to the Translate virtual function as a key.
19 // * The type of result strings that will be generated by Translate into the result buffer.
20 enum class TranslateCap
21 {
22 kNone = 0,
23 kReceiveHTML = 1 << 0, // Specifies that Translate key can include Flash-HTML tags. If not specified, translate will only receive stripped text content (default)
24 kStripTrailingNewLines = 1 << 1 // Forces all trailing new-line symbols to be stripped before the text is passed to Translate. This is important if the original text was in HTML format, since it can have a trailing paragraph tag that is turned into a new line
25 };
26
28 {
29 public:
30 enum Flag
31 {
32 kNone = 0,
33 kTranslated = 1 << 0,
34 kResultHTML = 1 << 1,
35 kResultSourceHTML = 1 << 2
36 };
37
39
40 [[nodiscard]] const char* GetInstanceName() const; // An input method which returns the instance name of the textfield being translated.
41 [[nodiscard]] const wchar_t* GetKey() const; // An input method which returns the 'key' string - original text value of the textfield being translated.
42 [[nodiscard]] bool IsKeyHTML() const; // Determines if the key string (returned by GetKey) is HTML or not.
43 void SetResult(const wchar_t* a_resultText, UPInt a_resultLen = UPINT_MAX); // An output method which sets the translated string as a plain text.
44 void SetResultHTML(const wchar_t* a_resultHTML, UPInt a_resultLen = UPINT_MAX); // An output method which sets translated string as a HTML text.
45
46 // members
47 const wchar_t* key; // 00
49 const char* instanceName; // 10
51 std::uint8_t pad19; // 19
52 std::uint16_t pad1A; // 1A
53 std::uint32_t pad1C; // 1C
54 };
55 static_assert(sizeof(TranslateInfo) == 0x20);
56
57 // LineFormatDesc provides information of the line text to be formatted like the length of the text, text position etc. This structure is mainly used by OnWordWrapping to control word wrapping of the text.
58 // Note that all members of LineFormatDesc marked as "[in]" are used as input values only and shouldn't be modified. Members marked as "[out]" or "[in, out]" might be modified.
60 {
61 enum class Alignment
62 {
63 kLeft = 0,
64 kRight = 1,
65 kCenter = 2,
66 kJustify = 3
67 };
68
69 // members
70 const wchar_t* paraText; // 00 - [in] Text of the current paragraph, wide-characters are used
71 UPInt paraTextLen; // 08 - [in] Length of the paragraph text, in characters
72 const float* widths; // 10 - [in] An array of line widths, in pixels, before the character at the corresponding index. The size of the array is NumCharsInLine + 1. Note, this is not the array of character widths. For example, there is a line that contains three characters: ABC. The NumCharInLine will be equal 3, the size of the pWidths will be 4; the pWidth[0] will be always 0 (since there are no characters before the A), the pWidth[1] will contain width of A symbol, pWidths[2] will contain width of A PLUS width of B, and, finally, pWidths[3] will contain total width of the line (width of A PLUS width of B PLUS width of C)
73 UPInt lineStartPos; // 18 - [in] The text position of the first character in line. ParaTextLen[LineStartPos] might be used to get the value of this character
74 UPInt numCharsInLine; // 20 - [in] Number of characters currently in the line
75 float visibleRectWidth; // 28 - [in] Width, in pixels, of client rectangle. This width might be used in calculation of word wrapping position: the total width of line should not exceed this width
76 float currentLineWidth; // 2C - [in] Current line width, in pixels
77 float lineWidthBeforeWordWrap; // 30 - [in] Line width before the proposedWordWrapPoint, in pixels. For example, if line is ABC DEF and proposedWordWrapPoint = 3 (space) then lineWidthBeforeWordWrap will contain the width of ABC (w/o space) part of the line
78 float dashSymbolWidth; // 34 - [in] Supplementary member, width of the hyphen symbol, in pixels. It might be used to calculate hyphenation
79 stl::enumeration<Alignment, std::uint8_t> alignment; // 38 - [in] Alignment of the line
80 std::uint8_t pad39; // 39
81 std::uint16_t pad3A; // 3A
82 std::uint32_t pad3C; // 3C
83 UPInt proposedWordWrapPoint; // 40 - [in,out] An index in the line of the proposed word wrap position. For example, if the line text is "ABC DEF" and only "ABC DE" fits in visibleRectWidth then the proposedWordWrapPoint will be equal to 3. Note, this is the index in line, not in text (paraText), not in line. Use lineStartPos to calculate the proposed word wrapping position in the text. The user's OnWordWrapping method should change this member if it is necessary to change the word wrapping position according to custom rules
84 bool useHyphenation; // 48 - [out] The OnWordWrapping method may set this to true to indicate to put hyphen symbol at the word-wrapping position. This might be useful for implementing hyphenation
85 std::uint8_t pad49; // 49
86 std::uint16_t pad4A; // 4A
87 std::uint32_t pad4C; // 4C
88 };
89 static_assert(sizeof(LineFormatDesc) == 0x50);
90
92 explicit GFxTranslator(WordWrappingType a_wwMode);
93 ~GFxTranslator() override = default; // 00
94
95 // add
96 [[nodiscard]] virtual TranslateCap GetCaps() const; // 01 - { return TranslateCap::kNone; } - Specifies capabilities of the Translate implementation
97 virtual void Translate(TranslateInfo* a_translateInfo); // 02 - { return; } - Translate method implements a UTF-8/UCS-2 translation interface and performs lookup of 'a_translateInfo->GetKey()' string for language translation, filling in the destination buffer by calling TranslateInfo::SetResult or TranslateInfo::SetResultHTML method. 'a_translateInfo' is guaranteed to be not null. If neither TranslateInfo::SetResult nor TranslateInfo::SetResultHTML is called then original text will not be changed
98 virtual bool OnWordWrapping(LineFormatDesc* a_desc); // 03 - OnWordWrapping is a virtual method, a callback, which is invoked once a necessity of word-wrapping for any text field is determined. This method is invoked only if custom word-wrapping is turned on by using the Translator(a_wwMode) constructor
99
100 [[nodiscard]] bool CanReceiveHTML() const;
101 [[nodiscard]] bool NeedStripNewLines() const;
102 [[nodiscard]] bool HandlesCustomWordWrapping() const;
103
104 // members
106 std::uint32_t pad1C; // 1C
107 };
108 static_assert(sizeof(GFxTranslator) == 0x20);
109}
Definition: GFxState.h:9
Definition: GFxTranslator.h:28
stl::enumeration< Flag, std::uint8_t > flags
Definition: GFxTranslator.h:50
GFxWStringBuffer * result
Definition: GFxTranslator.h:48
std::uint16_t pad1A
Definition: GFxTranslator.h:52
std::uint8_t pad19
Definition: GFxTranslator.h:51
std::uint32_t pad1C
Definition: GFxTranslator.h:53
void SetResultHTML(const wchar_t *a_resultHTML, UPInt a_resultLen=UPINT_MAX)
const char * GetInstanceName() const
Flag
Definition: GFxTranslator.h:31
@ kTranslated
Definition: GFxTranslator.h:33
@ kNone
Definition: GFxTranslator.h:32
@ kResultHTML
Definition: GFxTranslator.h:34
@ kResultSourceHTML
Definition: GFxTranslator.h:35
const wchar_t * GetKey() const
const char * instanceName
Definition: GFxTranslator.h:49
const wchar_t * key
Definition: GFxTranslator.h:47
void SetResult(const wchar_t *a_resultText, UPInt a_resultLen=UPINT_MAX)
Definition: GFxTranslator.h:11
std::uint32_t pad1C
Definition: GFxTranslator.h:106
static constexpr auto RTTI
Definition: GFxTranslator.h:13
bool NeedStripNewLines() const
bool CanReceiveHTML() const
virtual TranslateCap GetCaps() const
~GFxTranslator() override=default
stl::enumeration< WordWrappingType, std::uint32_t > wwMode
Definition: GFxTranslator.h:105
GFxTranslator(WordWrappingType a_wwMode)
virtual void Translate(TranslateInfo *a_translateInfo)
bool HandlesCustomWordWrapping() const
TranslateCap
Definition: GFxTranslator.h:21
virtual bool OnWordWrapping(LineFormatDesc *a_desc)
Definition: GFxWStringBuffer.h:6
WordWrappingType
Definition: GFxWWHelper.h:18
Definition: PCH.h:216
Definition: AbsorbEffect.h:6
constexpr REL::ID RTTI_GFxTranslator
Definition: Offsets_RTTI.h:4847
std::size_t UPInt
Definition: SFTypes.h:5
constexpr UPInt UPINT_MAX
Definition: SFTypes.h:6
Definition: GFxTranslator.h:60
UPInt proposedWordWrapPoint
Definition: GFxTranslator.h:83
std::uint8_t pad39
Definition: GFxTranslator.h:80
std::uint16_t pad3A
Definition: GFxTranslator.h:81
float currentLineWidth
Definition: GFxTranslator.h:76
std::uint32_t pad3C
Definition: GFxTranslator.h:82
Alignment
Definition: GFxTranslator.h:62
UPInt numCharsInLine
Definition: GFxTranslator.h:74
std::uint8_t pad49
Definition: GFxTranslator.h:85
float dashSymbolWidth
Definition: GFxTranslator.h:78
std::uint16_t pad4A
Definition: GFxTranslator.h:86
float visibleRectWidth
Definition: GFxTranslator.h:75
UPInt paraTextLen
Definition: GFxTranslator.h:71
const float * widths
Definition: GFxTranslator.h:72
UPInt lineStartPos
Definition: GFxTranslator.h:73
const wchar_t * paraText
Definition: GFxTranslator.h:70
float lineWidthBeforeWordWrap
Definition: GFxTranslator.h:77
stl::enumeration< Alignment, std::uint8_t > alignment
Definition: GFxTranslator.h:79
bool useHyphenation
Definition: GFxTranslator.h:84
std::uint32_t pad4C
Definition: GFxTranslator.h:87