This repository was archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGDI_Text.h
More file actions
138 lines (114 loc) · 5.22 KB
/
GDI_Text.h
File metadata and controls
138 lines (114 loc) · 5.22 KB
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
#pragma once
#ifndef GUID_6E018332_34C7_4D85_8C9E_6BB59E236EE0
#define GUID_6E018332_34C7_4D85_8C9E_6BB59E236EE0
/*******************************************************************************
*******************************************************************************
* Copyright (c) 2009-2023 ectotropic (ectotropic@gmail.com, *
* https://github.com/ectotropic) *
* *
* This program is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation, either version 2.1 of the License, or (at *
* your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
* for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
* *
*******************************************************************************
******************************************************************************/
//--------------------------------------
//
#include "Windows/GDI/GDI.h"
//--------------------------------------
//--------------------------------------
//
#include "GDI_Drawable.h"
#include "GDI_TextLine.h"
#include "GDI_Scroller.h"
//--------------------------------------
namespace Windows::GDI {
struct ScrollParams {
ScrollMode eMode{ ScrollMode::None };
float fSpeed{ 0.f };
float fDelay{ 0.f };
float fGapFactor{ 0.f };
};
class CText : public CDrawable {
private:
using thisClass = CText;
using baseClass = CDrawable;
using lineList = std::vector<CTextLine>;
public:
CText(_In_ HDC hDC);
virtual ~CText() = default;
void SetText(_In_reads_z_(nLength) LPCTSTR szText,
_In_ int nLength,
_In_ int nMaxLines = -1);
void SetFont(_In_ const LOGFONT& logFont,
_In_ bool bAllowOverlap = false);
void SetVAlign(_In_ Text::Align::Vertical eAlign) noexcept { m_eVAlign = eAlign; }
void SetVScroll(_In_ const ScrollParams& params) noexcept;
void SetVScroll(_In_ ScrollMode eMode,
_In_ float fSpeed,
_In_ float fDelay,
_In_ float fGapFactor) noexcept {
SetVScroll(ScrollParams{ eMode, fSpeed, fDelay, fGapFactor });
}
void SetHAlign(_In_ Text::Align::Horizontal eAlign) noexcept;
void SetHScroll(_In_ const ScrollParams& params) noexcept;
void SetHScroll(_In_ ScrollMode eMode,
_In_ float fSpeed,
_In_ float fDelay,
_In_ float fGapFactor) noexcept {
SetHScroll(ScrollParams{ eMode, fSpeed, fDelay, fGapFactor });
}
void SetBGClear(bool bClear) noexcept;
void Reset() noexcept;
void Update();
explicit operator bool() const noexcept { return !m_Lines.empty(); }
protected:
virtual void OnDraw(float fInterp) override;
virtual void OnChanged(_In_ GDIChange eWhat,
_In_ LPARAM lparam,
_In_ WPARAM wparam) noexcept override;
private:
void Update(int iWidth, int iHeight);
void DrawLines(int iOffsetX, int iOffsetY);
void SetLineCount(lineList::size_type iCount);
void ResumeLineScroll(bool bDelay) noexcept;
/*constexpr*/ auto GetLineHeight(const CTextLine& line) const noexcept {
return m_bAllowOverlap ? line.Ascent() : line.Size().cy;
}
/*constexpr*/ auto GetLineHeight(int i) const noexcept {
if (i >= 0 && i < static_cast<int>(m_Lines.size())) {
return GetLineHeight(m_Lines[i]);
} else {
return 0L;
}
}
private:
CFont m_Font{};
bool m_bAllowOverlap{ false };
private:
Text::Align::Vertical m_eVAlign{ Text::Align::Vertical::Centre };
CScroller m_Scroller;
float m_fLoopGapFactor{ 0.f };
float m_fLoopGap{ 0.f };
private:
Text::Align::Horizontal m_eHAlign{ Text::Align::Horizontal::Centre };
ScrollParams m_ScrollH{};
float m_fTarget{ .0f };
bool m_bBGClear{ false };
private:
lineList m_Lines;
bool m_bScrollStaggered{ false };
int m_iScrollLineID{ 0 };
ScrollStatus m_eScrollLastStatus{ ScrollStatus::None };
};
} // namespace Windows::GDI
#endif // GUID_6E018332_34C7_4D85_8C9E_6BB59E236EE0