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