openMSX
OSDWidget.hh
Go to the documentation of this file.
1 #ifndef OSDWIDGET_HH
2 #define OSDWIDGET_HH
3 
4 #include "TclObject.hh"
5 #include "gl_vec.hh"
6 #include "hash_set.hh"
7 #include "string_ref.hh"
8 #include "xxhash.hh"
9 #include <vector>
10 #include <memory>
11 
12 namespace openmsx {
13 
14 class Display;
15 class OutputRectangle;
16 class OutputSurface;
17 class TclObject;
18 class Interpreter;
19 
20 class OSDWidget
21 {
22  using SubWidgets = std::vector<std::unique_ptr<OSDWidget>>;
23 public:
24  virtual ~OSDWidget();
25 
26  string_ref getName() const { return name.getString(); }
27  gl::vec2 getPos() const { return pos; }
28  gl::vec2 getRelPos() const { return relPos; }
29  float getZ() const { return z; }
30 
31  OSDWidget* getParent() { return parent; }
32  const OSDWidget* getParent() const { return parent; }
33  const SubWidgets& getChildren() const { return subWidgets; }
34  void addWidget(std::unique_ptr<OSDWidget> widget);
35  void deleteWidget(OSDWidget& widget);
36 
37  virtual std::vector<string_ref> getProperties() const;
38  virtual void setProperty(Interpreter& interp,
39  string_ref name, const TclObject& value);
40  virtual void getProperty(string_ref name, TclObject& result) const;
41  virtual float getRecursiveFadeValue() const;
42  virtual string_ref getType() const = 0;
43 
44  void invalidateRecursive();
45  void paintSDLRecursive(OutputSurface& output);
46  void paintGLRecursive (OutputSurface& output);
47 
48  int getScaleFactor(const OutputRectangle& surface) const;
50  gl::vec2 pos, gl::vec2 relPos) const;
51  void getBoundingBox(const OutputRectangle& output,
52  gl::ivec2& pos, gl::ivec2& size);
53  virtual gl::vec2 getSize(const OutputRectangle& output) const = 0;
54 
55  Display& getDisplay() const { return display; }
56 
57 protected:
58  OSDWidget(Display& display, const TclObject& name);
59  void invalidateChildren();
60  bool needSuppressErrors() const;
61 
62  virtual void invalidateLocal() = 0;
63  virtual void paintSDL(OutputSurface& output) = 0;
64  virtual void paintGL (OutputSurface& output) = 0;
65 
66 private:
67  gl::vec2 getMouseCoord() const;
68  gl::vec2 transformReverse(const OutputRectangle& output,
69  gl::vec2 pos) const;
70  void setParent(OSDWidget* parent_) { parent = parent_; }
71  void resortUp (OSDWidget* elem);
72  void resortDown(OSDWidget* elem);
73 
76  SubWidgets subWidgets;
77 
78  Display& display;
79  OSDWidget* parent;
80 
81  TclObject name;
82  gl::vec2 pos;
83  gl::vec2 relPos;
84  float z;
85  bool scaled;
86  bool clip;
87  bool suppressErrors;
88 };
89 
90 } // namespace openmsx
91 
92 #endif
virtual string_ref getType() const =0
Represents the output window/screen of openMSX.
Definition: Display.hh:32
void invalidateRecursive()
Definition: OSDWidget.cc:299
void deleteWidget(OSDWidget &widget)
Definition: OSDWidget.cc:161
gl::vec2 getPos() const
Definition: OSDWidget.hh:27
bool needSuppressErrors() const
Definition: OSDWidget.cc:312
gl::vec2 getRelPos() const
Definition: OSDWidget.hh:28
virtual std::vector< string_ref > getProperties() const
Definition: OSDWidget.cc:212
void getBoundingBox(const OutputRectangle &output, gl::ivec2 &pos, gl::ivec2 &size)
Definition: OSDWidget.cc:435
gl::vec2 transformPos(const OutputRectangle &output, gl::vec2 pos, gl::vec2 relPos) const
Definition: OSDWidget.cc:369
OSDWidget(Display &display, const TclObject &name)
Definition: OSDWidget.cc:123
virtual gl::vec2 getSize(const OutputRectangle &output) const =0
This class implements a subset of the proposal for std::string_ref (proposed for the next c++ standar...
Definition: string_ref.hh:18
A frame buffer where pixels can be written to.
void paintGLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:338
string_ref getName() const
Definition: OSDWidget.hh:26
void addWidget(std::unique_ptr< OSDWidget > widget)
Definition: OSDWidget.cc:138
virtual void getProperty(string_ref name, TclObject &result) const
Definition: OSDWidget.cc:265
void paintSDLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:321
virtual ~OSDWidget()
Definition: OSDWidget.cc:134
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
string_ref getString() const
Definition: TclObject.cc:139
size_t size() const
virtual void paintSDL(OutputSurface &output)=0
void invalidateChildren()
Definition: OSDWidget.cc:305
virtual void paintGL(OutputSurface &output)=0
OSDWidget * getParent()
Definition: OSDWidget.hh:31
float getZ() const
Definition: OSDWidget.hh:29
const SubWidgets & getChildren() const
Definition: OSDWidget.hh:33
const OSDWidget * getParent() const
Definition: OSDWidget.hh:32
Display & getDisplay() const
Definition: OSDWidget.hh:55
virtual void invalidateLocal()=0
int getScaleFactor(const OutputRectangle &surface) const
Definition: OSDWidget.cc:358
virtual float getRecursiveFadeValue() const
Definition: OSDWidget.cc:294
virtual void setProperty(Interpreter &interp, string_ref name, const TclObject &value)
Definition: OSDWidget.cc:221