| 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 |
|
| 14 |
namespace openmsx { |
| 15 |
|
| 16 |
class Display; |
| 17 |
class OutputSurface; |
| 18 |
class Interpreter; |
| 19 |
|
| 20 |
class OSDWidget |
| 21 |
{ |
| 22 |
using SubWidgets = std::vector<std::unique_ptr<OSDWidget>>; |
| 23 |
|
| 24 |
protected: |
| 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 |
|
| 33 |
public: |
| 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 |
|
| 57 |
void invalidateRecursive(); |
| 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 |
struct BoundingBox { gl::vec2 pos; gl::vec2 size; }; |
| 64 |
[[nodiscard]] BoundingBox getBoundingBox(const OutputSurface& output) const; |
| 65 |
[[nodiscard]] virtual gl::vec2 getSize(const OutputSurface& output) const = 0; |
| 66 |
|
| 67 |
|
| 68 |
[[nodiscard]] virtual bool isVisible() const = 0; |
| 69 |
|
| 70 |
[[nodiscard]] Display& getDisplay() const { return display; } |
| 71 |
|
| 72 |
protected: |
| 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 |
|
| 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 (const OSDWidget* elem); |
| 86 |
void resortDown(const OSDWidget* elem); |
| 87 |
|
| 88 |
private: |
| 89 |
|
| 90 |
|
| 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 |
} |
| 106 |
|
| 107 |
#endif |