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 "span.hh"
6 #include "stl.hh"
7 #include <cstdint>
8 
9 namespace openmsx {
10 
11 class BaseImage;
12 class Display;
13 
15 {
16 protected:
17  static constexpr auto imageBasedProperties = [] {
18  using namespace std::literals;
19  return concatArray(
21  std::array{
22  "-rgba"sv, "-rgb"sv, "-alpha"sv,
23  "-fadePeriod"sv, "-fadeTarget"sv,
24  "-fadeCurrent"sv,
25  });
26  }();
27 
28 public:
29  [[nodiscard]] uint32_t getRGBA(uint32_t corner) const { return rgba[corner]; }
30  [[nodiscard]] span<const uint32_t, 4> getRGBA4() const { return rgba; }
31 
32  [[nodiscard]] virtual uint8_t getFadedAlpha() const = 0;
33 
34  [[nodiscard]] span<const std::string_view> getProperties() const override {
35  return imageBasedProperties;
36  }
37  void setProperty(Interpreter& interp,
38  std::string_view name, const TclObject& value) override;
39  void getProperty(std::string_view name, TclObject& result) const override;
40  [[nodiscard]] float getRecursiveFadeValue() const override;
41  [[nodiscard]] bool isVisible() const override;
42  [[nodiscard]] bool isRecursiveFading() const override;
43 
44 protected:
45  OSDImageBasedWidget(Display& display, const TclObject& name);
47  [[nodiscard]] bool hasConstantAlpha() const;
48  void createImage(OutputSurface& output);
49  void invalidateLocal() override;
50  void paintSDL(OutputSurface& output) override;
51  void paintGL (OutputSurface& output) override;
52  [[nodiscard]] virtual std::unique_ptr<BaseImage> createSDL(OutputSurface& output) = 0;
53  [[nodiscard]] virtual std::unique_ptr<BaseImage> createGL (OutputSurface& output) = 0;
54 
55  void setError(std::string message);
56  [[nodiscard]] bool hasError() const { return error; }
57 
58  std::unique_ptr<BaseImage> image;
59 
60 private:
61  void setRGBA(const uint32_t newRGBA[4]);
62  [[nodiscard]] bool isFading() const;
63  [[nodiscard]] float getCurrentFadeValue() const;
64  [[nodiscard]] float getCurrentFadeValue(uint64_t now) const;
65  void updateCurrentFadeValue();
66 
67  void paint(OutputSurface& output, bool openGL);
68  [[nodiscard]] gl::vec2 getTransformedPos(const OutputSurface& output) const;
69 
70 private:
71  uint64_t startFadeTime;
72  float fadePeriod;
73  float fadeTarget;
74  mutable float startFadeValue;
75  uint32_t rgba[4];
76  bool error;
77 };
78 
79 } // namespace openmsx
80 
81 #endif
Represents the output window/screen of openMSX.
Definition: Display.hh:33
span< const std::string_view > getProperties() const override
static constexpr auto imageBasedProperties
span< const uint32_t, 4 > getRGBA4() const
uint32_t getRGBA(uint32_t corner) const
virtual std::unique_ptr< BaseImage > createSDL(OutputSurface &output)=0
void setProperty(Interpreter &interp, std::string_view name, const TclObject &value) override
std::unique_ptr< BaseImage > image
void createImage(OutputSurface &output)
virtual uint8_t getFadedAlpha() const =0
virtual std::unique_ptr< BaseImage > createGL(OutputSurface &output)=0
float getRecursiveFadeValue() const override
bool isRecursiveFading() const override
OSDImageBasedWidget(Display &display, const TclObject &name)
void paintGL(OutputSurface &output) override
void setError(std::string message)
void getProperty(std::string_view name, TclObject &result) const override
void paintSDL(OutputSurface &output) override
static constexpr auto widgetProperties
Definition: OSDWidget.hh:21
A frame buffer where pixels can be written to.
Definition: span.hh:126
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr auto concatArray(const std::array< T, X > &x, const std::array< T, Y > &y)
Definition: stl.hh:390