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 <memory>
7 
8 namespace openmsx {
9 
10 class OSDText final : public OSDImageBasedWidget
11 {
12 protected:
13  static constexpr auto textProperties = [] {
14  using namespace std::literals;
15  return concatArray(
17  std::array{
18  "-text"sv, "-font"sv, "-size"sv,
19  "-wrap"sv, "-wrapw"sv, "-wraprelw"sv,
20  "-query-size"sv,
21  });
22  }();
23 
24 public:
25  OSDText(Display& display, const TclObject& name);
26 
27  [[nodiscard]] span<const std::string_view> getProperties() const override {
28  return textProperties;
29  }
30  void setProperty(Interpreter& interp,
31  std::string_view name, const TclObject& value) override;
32  void getProperty(std::string_view name, TclObject& result) const override;
33  [[nodiscard]] std::string_view getType() const override;
34 
35 private:
36  void invalidateLocal() override;
37  [[nodiscard]] gl::vec2 getSize(const OutputSurface& output) const override;
38  [[nodiscard]] uint8_t getFadedAlpha() const override;
39  [[nodiscard]] std::unique_ptr<BaseImage> createSDL(OutputSurface& output) override;
40  [[nodiscard]] std::unique_ptr<BaseImage> createGL (OutputSurface& output) override;
41  template<typename IMAGE> [[nodiscard]] std::unique_ptr<BaseImage> create(
42  OutputSurface& output);
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 
53  [[nodiscard]] gl::vec2 getRenderedSize() const;
54 
55 private:
56  enum WrapMode { NONE, WORD, CHAR };
57 
58  std::string text;
59  std::string fontfile;
60  TTFFont font;
61  int size;
62  WrapMode wrapMode;
63  float wrapw, wraprelw;
64 
65  friend struct SplitAtChar;
66 };
67 
68 } // namespace openmsx
69 
70 #endif
Represents the output window/screen of openMSX.
Definition: Display.hh:33
static constexpr auto imageBasedProperties
static constexpr auto textProperties
Definition: OSDText.hh:13
OSDText(Display &display, const TclObject &name)
Definition: OSDText.cc:28
span< const std::string_view > getProperties() const override
Definition: OSDText.hh:27
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
A frame buffer where pixels can be written to.
Definition: span.hh:126
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:390