openMSX
OSDWidget.hh
Go to the documentation of this file.
1 #ifndef OSDWIDGET_HH
2 #define OSDWIDGET_HH
3 
4 #include "TclObject.hh"
5 #include "gl_vec.hh"
6 #include <array>
7 #include <span>
8 #include <string_view>
9 #include <vector>
10 #include <memory>
11 
12 namespace openmsx {
13 
14 class Display;
15 class OutputSurface;
16 class Interpreter;
17 
18 class OSDWidget
19 {
20  using SubWidgets = std::vector<std::unique_ptr<OSDWidget>>;
21 
22 protected:
23  static constexpr auto widgetProperties = [] {
24  using namespace std::literals;
25  return std::array{
26  "-type"sv, "-x"sv, "-y"sv, "-z"sv, "-relx"sv, "-rely"sv, "-scaled"sv,
27  "-clip"sv, "-mousecoord"sv, "-suppressErrors"sv,
28  };
29  }();
30 
31 public:
32  virtual ~OSDWidget() = default;
33 
34  [[nodiscard]] std::string_view getName() const { return name.getString(); }
35  [[nodiscard]] gl::vec2 getPos() const { return pos; }
36  [[nodiscard]] gl::vec2 getRelPos() const { return relPos; }
37  [[nodiscard]] float getZ() const { return z; }
38 
39  [[nodiscard]] OSDWidget* getParent() { return parent; }
40  [[nodiscard]] const OSDWidget* getParent() const { return parent; }
41  [[nodiscard]] const SubWidgets& getChildren() const { return subWidgets; }
42  void addWidget(std::unique_ptr<OSDWidget> widget);
43  void deleteWidget(OSDWidget& widget);
44 
45  [[nodiscard]] virtual std::span<const std::string_view> getProperties() const {
46  return widgetProperties;
47  }
48  virtual void setProperty(Interpreter& interp,
49  std::string_view name, const TclObject& value);
50  virtual void getProperty(std::string_view name, TclObject& result) const;
51  [[nodiscard]] virtual float getRecursiveFadeValue() const;
52  [[nodiscard]] virtual bool isRecursiveFading() const = 0;
53  [[nodiscard]] virtual std::string_view getType() const = 0;
54 
55  void invalidateRecursive();
56  void paintSDLRecursive(OutputSurface& output);
57  void paintGLRecursive (OutputSurface& output);
58 
59  [[nodiscard]] int getScaleFactor(const OutputSurface& output) const;
60  [[nodiscard]] gl::vec2 transformPos(const OutputSurface& output,
61  gl::vec2 pos, gl::vec2 relPos) const;
62  void getBoundingBox(const OutputSurface& output,
63  gl::vec2& pos, gl::vec2& size) const;
64  [[nodiscard]] virtual gl::vec2 getSize(const OutputSurface& output) const = 0;
65 
66  // Is visible? Or may become visible (fading-in).
67  [[nodiscard]] virtual bool isVisible() const = 0;
68 
69  [[nodiscard]] Display& getDisplay() const { return display; }
70 
71 protected:
72  OSDWidget(Display& display, TclObject name);
73  void invalidateChildren();
74  [[nodiscard]] bool needSuppressErrors() const;
75 
76  virtual void invalidateLocal() = 0;
77  virtual void paintSDL(OutputSurface& output) = 0;
78  virtual void paintGL (OutputSurface& output) = 0;
79 
80 private:
81  [[nodiscard]] gl::vec2 getMouseCoord() const;
82  [[nodiscard]] gl::vec2 transformReverse(const OutputSurface& output,
83  gl::vec2 pos) const;
84  void setParent(OSDWidget* parent_) { parent = parent_; }
85  void resortUp (OSDWidget* elem);
86  void resortDown(OSDWidget* elem);
87 
88 private:
91  SubWidgets subWidgets;
92 
93  Display& display;
94  OSDWidget* parent;
95 
96  TclObject name;
97  gl::vec2 pos;
98  gl::vec2 relPos;
99  float z;
100  bool scaled;
101  bool clip;
102  bool suppressErrors;
103 };
104 
105 } // namespace openmsx
106 
107 #endif
Represents the output window/screen of openMSX.
Definition: Display.hh:33
virtual void getProperty(std::string_view name, TclObject &result) const
Definition: OSDWidget.cc:259
void addWidget(std::unique_ptr< OSDWidget > widget)
Definition: OSDWidget.cc:149
Display & getDisplay() const
Definition: OSDWidget.hh:69
static constexpr auto widgetProperties
Definition: OSDWidget.hh:23
void deleteWidget(OSDWidget &widget)
Definition: OSDWidget.cc:172
int getScaleFactor(const OutputSurface &output) const
Definition: OSDWidget.cc:349
void getBoundingBox(const OutputSurface &output, gl::vec2 &pos, gl::vec2 &size) const
Definition: OSDWidget.cc:422
gl::vec2 transformPos(const OutputSurface &output, gl::vec2 pos, gl::vec2 relPos) const
Definition: OSDWidget.cc:360
const SubWidgets & getChildren() const
Definition: OSDWidget.hh:41
virtual bool isVisible() const =0
virtual void paintGL(OutputSurface &output)=0
virtual std::span< const std::string_view > getProperties() const
Definition: OSDWidget.hh:45
void paintGLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:330
virtual float getRecursiveFadeValue() const
Definition: OSDWidget.cc:287
virtual std::string_view getType() const =0
gl::vec2 getRelPos() const
Definition: OSDWidget.hh:36
gl::vec2 getPos() const
Definition: OSDWidget.hh:35
virtual ~OSDWidget()=default
std::string_view getName() const
Definition: OSDWidget.hh:34
virtual gl::vec2 getSize(const OutputSurface &output) const =0
virtual void paintSDL(OutputSurface &output)=0
bool needSuppressErrors() const
Definition: OSDWidget.cc:305
OSDWidget(Display &display, TclObject name)
Definition: OSDWidget.cc:138
const OSDWidget * getParent() const
Definition: OSDWidget.hh:40
virtual void setProperty(Interpreter &interp, std::string_view name, const TclObject &value)
Definition: OSDWidget.cc:215
void paintSDLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:314
virtual void invalidateLocal()=0
OSDWidget * getParent()
Definition: OSDWidget.hh:39
void invalidateRecursive()
Definition: OSDWidget.cc:292
void invalidateChildren()
Definition: OSDWidget.cc:298
virtual bool isRecursiveFading() const =0
float getZ() const
Definition: OSDWidget.hh:37
A frame buffer where pixels can be written to.
zstring_view getString() const
Definition: TclObject.cc:111
This file implemented 3 utility functions:
Definition: Autofire.cc:9
size_t size(std::string_view utf8)