openMSX
OSDText.hh
Go to the documentation of this file.
1#ifndef OSDTEXT_HH
2#define OSDTEXT_HH
3
5#include "TTFFont.hh"
6
7#include "stl.hh"
8
9#include <array>
10#include <memory>
11
12namespace openmsx {
13
14class OSDText final : public OSDImageBasedWidget
15{
16private:
17 static constexpr auto textProperties = [] {
18 using namespace std::literals;
19 return concatArray(
21 std::array{
22 "-text"sv, "-font"sv, "-size"sv,
23 "-wrap"sv, "-wrapw"sv, "-wraprelw"sv,
24 });
25 }();
26
27public:
28 OSDText(Display& display, const TclObject& name);
29
30 [[nodiscard]] std::span<const std::string_view> getProperties() const override {
31 return textProperties;
32 }
33 void setProperty(Interpreter& interp,
34 std::string_view name, const TclObject& value) override;
35 void getProperty(std::string_view name, TclObject& result) const override;
36 [[nodiscard]] std::string_view getType() const override;
37
38private:
39 void invalidateLocal() override;
40 [[nodiscard]] gl::vec2 getSize(const OutputSurface& output) const override;
41 [[nodiscard]] uint8_t getFadedAlpha() const override;
42 [[nodiscard]] std::unique_ptr<GLImage> create(OutputSurface& output) override;
43
44 template<typename FindSplitPointFunc, typename CantSplitFunc>
45 [[nodiscard]] size_t split(const std::string& line, unsigned maxWidth,
46 FindSplitPointFunc findSplitPoint, CantSplitFunc cantSplit,
47 bool removeTrailingSpaces) const;
48 [[nodiscard]] size_t splitAtChar(const std::string& line, unsigned maxWidth) const;
49 [[nodiscard]] size_t splitAtWord(const std::string& line, unsigned maxWidth) const;
50 [[nodiscard]] std::string getCharWrappedText(const std::string& txt, unsigned maxWidth) const;
51 [[nodiscard]] std::string getWordWrappedText(const std::string& txt, unsigned maxWidth) const;
52
53private:
54 enum WrapMode { NONE, WORD, CHAR };
55
56 std::string text;
57 std::string fontFile;
58 TTFFont font;
59 int size = 12;
60 WrapMode wrapMode = NONE;
61 float wrapw = 0.0f, wraprelw = 1.0f;
62
63 friend struct SplitAtChar;
64};
65
66} // namespace openmsx
67
68#endif
Represents the output window/screen of openMSX.
Definition Display.hh:31
static constexpr auto imageBasedProperties
std::span< const std::string_view > getProperties() const override
Definition OSDText.hh:30
void getProperty(std::string_view name, TclObject &result) const override
Definition OSDText.cc:97
void setProperty(Interpreter &interp, std::string_view name, const TclObject &value) override
Definition OSDText.cc:34
std::string_view getType() const override
Definition OSDText.cc:130
A frame buffer where pixels can be written to.
This file implemented 3 utility functions:
Definition Autofire.cc:11
constexpr auto concatArray(const std::array< T, X > &x, const std::array< T, Y > &y)
Definition stl.hh:393