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