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