openMSX
OSDImageBasedWidget.hh
Go to the documentation of this file.
1#ifndef OSDIMAGEBASEDWIDGET_HH
2#define OSDIMAGEBASEDWIDGET_HH
3
4#include "OSDWidget.hh"
5#include "stl.hh"
6#include <array>
7#include <cstdint>
8#include <optional>
9#include <span>
10
11namespace openmsx {
12
13class GLImage;
14class Display;
15
17{
18protected:
19 static constexpr auto imageBasedProperties = [] {
20 using namespace std::literals;
21 return concatArray(
23 std::array{
24 "-rgba"sv, "-rgb"sv, "-alpha"sv,
25 "-fadePeriod"sv, "-fadeTarget"sv,
26 "-fadeCurrent"sv,
27 "-scrollSpeed"sv,
28 "-scrollPauseLeft"sv,
29 "-scrollPauseRight"sv,
30 "-query-size"sv,
31 });
32 }();
33
34public:
35 [[nodiscard]] gl::vec2 getPos() const override;
36 [[nodiscard]] uint32_t getRGBA(uint32_t corner) const { return rgba[corner]; }
37 [[nodiscard]] std::span<const uint32_t, 4> getRGBA4() const { return rgba; }
38
39 [[nodiscard]] virtual uint8_t getFadedAlpha() const = 0;
40
41 [[nodiscard]] std::span<const std::string_view> getProperties() const override {
43 }
44 void setProperty(Interpreter& interp,
45 std::string_view name, const TclObject& value) override;
46 void getProperty(std::string_view name, TclObject& result) const override;
47 [[nodiscard]] float getRecursiveFadeValue() const override;
48 [[nodiscard]] bool isVisible() const override;
49 [[nodiscard]] bool isRecursiveFading() const override;
50
51protected:
52 OSDImageBasedWidget(Display& display, const TclObject& name);
54 [[nodiscard]] bool hasConstantAlpha() const;
55 void createImage(OutputSurface& output);
56 void invalidateLocal() override;
57 void paint(OutputSurface& output) override;
58 [[nodiscard]] virtual std::unique_ptr<GLImage> create(OutputSurface& output) = 0;
59 [[nodiscard]] gl::vec2 getRenderedSize() const;
60
61 void setError(std::string message);
62 [[nodiscard]] bool hasError() const { return error; }
63
64 std::unique_ptr<GLImage> image;
65
66private:
67 void setRGBA(std::span<const uint32_t, 4> newRGBA);
68 [[nodiscard]] bool isFading() const;
69 [[nodiscard]] float getCurrentFadeValue() const;
70 [[nodiscard]] float getCurrentFadeValue(uint64_t now) const;
71 [[nodiscard]] bool isAnimating() const;
72 [[nodiscard]] std::optional<float> getScrollWidth() const;
73 void updateCurrentFadeValue();
74
75 [[nodiscard]] gl::vec2 getTransformedPos(const OutputSurface& output) const;
76
77private:
78 uint64_t startFadeTime = 0;
79 float fadePeriod = 0.0f;
80 float fadeTarget = 1.0f;
81 mutable float startFadeValue = 1.0f;
82 float scrollSpeed = 0.0f; // 0 means disabled
83 float scrollPauseLeft = 0.0f;
84 float scrollPauseRight = 0.0f;
85 uint64_t startScrollTime = 0;
86 std::array<uint32_t, 4> rgba;
87 bool error = false;
88};
89
90} // namespace openmsx
91
92#endif
Represents the output window/screen of openMSX.
Definition Display.hh:31
static constexpr auto imageBasedProperties
uint32_t getRGBA(uint32_t corner) const
std::span< const uint32_t, 4 > getRGBA4() const
virtual std::unique_ptr< GLImage > create(OutputSurface &output)=0
gl::vec2 getPos() const override
void setProperty(Interpreter &interp, std::string_view name, const TclObject &value) override
std::span< const std::string_view > getProperties() const override
void createImage(OutputSurface &output)
virtual uint8_t getFadedAlpha() const =0
float getRecursiveFadeValue() const override
void paint(OutputSurface &output) override
bool isRecursiveFading() const override
std::unique_ptr< GLImage > image
void setError(std::string message)
void getProperty(std::string_view name, TclObject &result) const override
static constexpr auto widgetProperties
Definition OSDWidget.hh:25
A frame buffer where pixels can be written to.
This file implemented 3 utility functions:
Definition Autofire.cc:11
constexpr auto concatArray(const std::array< T, X > &x, const std::array< T, Y > &y)
Definition stl.hh:393