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