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 OutputRectangle;
15 class OutputSurface;
16 class TclObject;
17 class Interpreter;
18 
19 class OSDWidget
20 {
21  using SubWidgets = std::vector<std::unique_ptr<OSDWidget>>;
22 public:
23  virtual ~OSDWidget();
24 
25  string_ref getName() const { return name.getString(); }
26  gl::vec2 getPos() const { return pos; }
27  gl::vec2 getRelPos() const { return relPos; }
28  float getZ() const { return z; }
29 
30  OSDWidget* getParent() { return parent; }
31  const OSDWidget* getParent() const { return parent; }
32  const SubWidgets& getChildren() const { return subWidgets; }
33  void addWidget(std::unique_ptr<OSDWidget> widget);
34  void deleteWidget(OSDWidget& widget);
35 
36  virtual std::vector<string_ref> getProperties() const;
37  virtual void setProperty(Interpreter& interp,
38  string_ref name, const TclObject& value);
39  virtual void getProperty(string_ref name, TclObject& result) const;
40  virtual float getRecursiveFadeValue() const;
41  virtual string_ref getType() const = 0;
42 
43  void invalidateRecursive();
44  void paintSDLRecursive(OutputSurface& output);
45  void paintGLRecursive (OutputSurface& output);
46 
47  int getScaleFactor(const OutputRectangle& surface) const;
49  gl::vec2 pos, gl::vec2 relPos) const;
50  void getBoundingBox(const OutputRectangle& output,
51  gl::ivec2& pos, gl::ivec2& size);
52  virtual gl::vec2 getSize(const OutputRectangle& output) const = 0;
53 
54 protected:
55  OSDWidget(const TclObject& name);
56  void invalidateChildren();
57  bool needSuppressErrors() const;
58 
59  virtual void invalidateLocal() = 0;
60  virtual void paintSDL(OutputSurface& output) = 0;
61  virtual void paintGL (OutputSurface& output) = 0;
62 
63 private:
64  gl::vec2 getMouseCoord() const;
65  gl::vec2 transformReverse(const OutputRectangle& output,
66  gl::vec2 pos) const;
67  void setParent(OSDWidget* parent_) { parent = parent_; }
68  void resortUp (OSDWidget* elem);
69  void resortDown(OSDWidget* elem);
70 
73  SubWidgets subWidgets;
74 
75  OSDWidget* parent;
76 
77  TclObject name;
78  gl::vec2 pos;
79  gl::vec2 relPos;
80  float z;
81  bool scaled;
82  bool clip;
83  bool suppressErrors;
84 };
85 
86 } // namespace openmsx
87 
88 #endif
virtual string_ref getType() const =0
int getScaleFactor(const OutputRectangle &surface) const
Definition: OSDWidget.cc:356
void invalidateRecursive()
Definition: OSDWidget.cc:297
void deleteWidget(OSDWidget &widget)
Definition: OSDWidget.cc:159
gl::vec2 getPos() const
Definition: OSDWidget.hh:26
string_ref getString() const
Definition: TclObject.cc:139
bool needSuppressErrors() const
Definition: OSDWidget.cc:310
void getBoundingBox(const OutputRectangle &output, gl::ivec2 &pos, gl::ivec2 &size)
Definition: OSDWidget.cc:433
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:336
virtual void getProperty(string_ref name, TclObject &result) const
Definition: OSDWidget.cc:263
void addWidget(std::unique_ptr< OSDWidget > widget)
Definition: OSDWidget.cc:136
void paintSDLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:319
gl::vec2 getRelPos() const
Definition: OSDWidget.hh:27
OSDWidget(const TclObject &name)
Definition: OSDWidget.cc:122
virtual ~OSDWidget()
Definition: OSDWidget.cc:132
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
gl::vec2 transformPos(const OutputRectangle &output, gl::vec2 pos, gl::vec2 relPos) const
Definition: OSDWidget.cc:367
float getZ() const
Definition: OSDWidget.hh:28
virtual void paintSDL(OutputSurface &output)=0
void invalidateChildren()
Definition: OSDWidget.cc:303
virtual void paintGL(OutputSurface &output)=0
OSDWidget * getParent()
Definition: OSDWidget.hh:30
size_t size() const
const SubWidgets & getChildren() const
Definition: OSDWidget.hh:32
virtual void invalidateLocal()=0
virtual std::vector< string_ref > getProperties() const
Definition: OSDWidget.cc:210
string_ref getName() const
Definition: OSDWidget.hh:25
virtual float getRecursiveFadeValue() const
Definition: OSDWidget.cc:292
const OSDWidget * getParent() const
Definition: OSDWidget.hh:31
virtual void setProperty(Interpreter &interp, string_ref name, const TclObject &value)
Definition: OSDWidget.cc:219