openMSX
OSDWidget.hh
Go to the documentation of this file.
1 #ifndef OSDWIDGET_HH
2 #define OSDWIDGET_HH
3 
4 #include "StringMap.hh"
5 #include "string_ref.hh"
6 #include "gl_vec.hh"
7 #include <vector>
8 #include <memory>
9 
10 namespace openmsx {
11 
12 class OutputRectangle;
13 class OutputSurface;
14 class TclObject;
15 class Interpreter;
16 
17 class OSDWidget
18 {
19 public:
20  virtual ~OSDWidget();
21 
22  const std::string& getName() const { return name; }
23  gl::vec2 getPos() const { return pos; }
24  gl::vec2 getRelPos() const { return relPos; }
25  float getZ() const { return z; }
26 
27  OSDWidget* getParent() { return parent; }
28  const OSDWidget* getParent() const { return parent; }
30  const OSDWidget* findSubWidget(string_ref name) const;
31  void addWidget(std::unique_ptr<OSDWidget> widget);
32  void deleteWidget(OSDWidget& widget);
33 
34  virtual std::vector<string_ref> getProperties() const;
35  virtual void setProperty(Interpreter& interp,
36  string_ref name, const TclObject& value);
37  virtual void getProperty(string_ref name, TclObject& result) const;
38  virtual float getRecursiveFadeValue() const;
39  virtual string_ref getType() const = 0;
40 
41  void invalidateRecursive();
42  void paintSDLRecursive(OutputSurface& output);
43  void paintGLRecursive (OutputSurface& output);
44 
45  int getScaleFactor(const OutputRectangle& surface) const;
47  gl::vec2 pos, gl::vec2 relPos) const;
48  void getBoundingBox(const OutputRectangle& output,
49  gl::ivec2& pos, gl::ivec2& size);
50  virtual gl::vec2 getSize(const OutputRectangle& output) const = 0;
51 
52  // for OSDGUI::OSDCommand
53  void listWidgetNames(const std::string& parentName,
54  std::vector<std::string>& result) const;
55 
56 protected:
57  explicit OSDWidget(const std::string& name);
58  void invalidateChildren();
59  bool needSuppressErrors() const;
60 
61  virtual void invalidateLocal() = 0;
62  virtual void paintSDL(OutputSurface& output) = 0;
63  virtual void paintGL (OutputSurface& output) = 0;
64 
65 private:
66  gl::vec2 getMouseCoord() const;
67  gl::vec2 transformReverse(const OutputRectangle& output,
68  gl::vec2 pos) const;
69  void setParent(OSDWidget* parent_) { parent = parent_; }
70  void resortUp (OSDWidget* elem);
71  void resortDown(OSDWidget* elem);
72 
75  std::vector<std::unique_ptr<OSDWidget>> subWidgets;
76 
80  StringMap<OSDWidget*> subWidgetsMap;
81 
82  OSDWidget* parent;
83 
84  const std::string name;
85  gl::vec2 pos;
86  gl::vec2 relPos;
87  float z;
88  bool scaled;
89  bool clip;
90  bool suppressErrors;
91 };
92 
93 } // namespace openmsx
94 
95 #endif
virtual string_ref getType() const =0
int getScaleFactor(const OutputRectangle &surface) const
Definition: OSDWidget.cc:380
void invalidateRecursive()
Definition: OSDWidget.cc:321
void deleteWidget(OSDWidget &widget)
Definition: OSDWidget.cc:176
gl::vec2 getPos() const
Definition: OSDWidget.hh:23
bool needSuppressErrors() const
Definition: OSDWidget.cc:334
OSDWidget * findSubWidget(string_ref name)
Definition: OSDWidget.cc:136
void getBoundingBox(const OutputRectangle &output, gl::ivec2 &pos, gl::ivec2 &size)
Definition: OSDWidget.cc:457
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:360
virtual void getProperty(string_ref name, TclObject &result) const
Definition: OSDWidget.cc:287
void addWidget(std::unique_ptr< OSDWidget > widget)
Definition: OSDWidget.cc:152
void paintSDLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:343
gl::vec2 getRelPos() const
Definition: OSDWidget.hh:24
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:391
float getZ() const
Definition: OSDWidget.hh:25
virtual void paintSDL(OutputSurface &output)=0
void invalidateChildren()
Definition: OSDWidget.cc:327
virtual void paintGL(OutputSurface &output)=0
OSDWidget * getParent()
Definition: OSDWidget.hh:27
OSDWidget(const std::string &name)
Definition: OSDWidget.cc:122
size_t size() const
virtual void invalidateLocal()=0
virtual std::vector< string_ref > getProperties() const
Definition: OSDWidget.cc:234
virtual float getRecursiveFadeValue() const
Definition: OSDWidget.cc:316
const OSDWidget * getParent() const
Definition: OSDWidget.hh:28
void listWidgetNames(const std::string &parentName, std::vector< std::string > &result) const
Definition: OSDWidget.cc:466
virtual void setProperty(Interpreter &interp, string_ref name, const TclObject &value)
Definition: OSDWidget.cc:243
const std::string & getName() const
Definition: OSDWidget.hh:22