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 <vector>
7 #include <memory>
8 
9 namespace openmsx {
10 
11 class OutputRectangle;
12 class OutputSurface;
13 class TclObject;
14 
15 class OSDWidget
16 {
17 public:
18  virtual ~OSDWidget();
19 
20  const std::string& getName() const;
21  double getX() const { return x; }
22  double getY() const { return y; }
23  double getZ() const { return z; }
24  double getRelX() const { return relx; }
25  double getRelY() const { return rely; }
26 
28  const OSDWidget* getParent() const;
30  const OSDWidget* findSubWidget(string_ref name) const;
31  void addWidget(const std::shared_ptr<OSDWidget>& widget);
32  void deleteWidget(OSDWidget& widget);
33 
34  virtual std::vector<string_ref> getProperties() const;
35  virtual void setProperty(string_ref name, const TclObject& value);
36  virtual void getProperty(string_ref name, TclObject& result) const;
37  virtual double getRecursiveFadeValue() const;
38  virtual string_ref getType() const = 0;
39 
40  void invalidateRecursive();
41  void paintSDLRecursive(OutputSurface& output);
42  void paintGLRecursive (OutputSurface& output);
43 
44  int getScaleFactor(const OutputRectangle& surface) const;
45  void transformXY(const OutputRectangle& output,
46  double x, double y, double relx, double rely,
47  double& outx, double& outy) const;
48  void getBoundingBox(const OutputRectangle& output,
49  int& x, int& y, int& w, int& h);
50  virtual void getWidthHeight(const OutputRectangle& output,
51  double& width, double& height) const = 0;
52 
53 protected:
54  explicit OSDWidget(const std::string& name);
55  void invalidateChildren();
56  bool needSuppressErrors() const;
57 
58  virtual void invalidateLocal() = 0;
59  virtual void paintSDL(OutputSurface& output) = 0;
60  virtual void paintGL (OutputSurface& output) = 0;
61 
62 private:
63  void getMouseCoord(double& outx, double& outy) const;
64  void transformReverse(const OutputRectangle& output,
65  double x, double y,
66  double& outx, double& outy) const;
67  void setParent(OSDWidget* parent);
68  void resortUp (OSDWidget* elem);
69  void resortDown(OSDWidget* elem);
70 
71  void listWidgetNames(const std::string& parentName,
72  std::vector<std::string>& result) const;
73  friend class OSDCommand;
74 
77  // note: must be shared_ptr (not unique_ptr), see OSDWidget::paintSDLRecursive()
78  std::vector<std::shared_ptr<OSDWidget>> subWidgets;
79 
83  StringMap<OSDWidget*> subWidgetsMap;
84 
85  OSDWidget* parent;
86 
87  const std::string name;
88  double x, y, z;
89  double relx, rely;
90  bool scaled;
91  bool clip;
92  bool suppressErrors;
93 };
94 
95 } // namespace openmsx
96 
97 #endif
OSDWidget * getParent()
Definition: OSDWidget.cc:141
virtual string_ref getType() const =0
int getScaleFactor(const OutputRectangle &surface) const
Definition: OSDWidget.cc:404
void invalidateRecursive()
Definition: OSDWidget.cc:341
void deleteWidget(OSDWidget &widget)
Definition: OSDWidget.cc:196
virtual void setProperty(string_ref name, const TclObject &value)
Definition: OSDWidget.cc:263
bool needSuppressErrors() const
Definition: OSDWidget.cc:354
virtual void getWidthHeight(const OutputRectangle &output, double &width, double &height) const =0
virtual double getRecursiveFadeValue() const
Definition: OSDWidget.cc:336
OSDWidget * findSubWidget(string_ref name)
Definition: OSDWidget.cc:156
double getRelX() const
Definition: OSDWidget.hh:24
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.
double getX() const
Definition: OSDWidget.hh:21
double getRelY() const
Definition: OSDWidget.hh:25
void paintGLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:384
virtual void getProperty(string_ref name, TclObject &result) const
Definition: OSDWidget.cc:306
const std::string & getName() const
Definition: OSDWidget.cc:136
void paintSDLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:363
double getZ() const
Definition: OSDWidget.hh:23
virtual ~OSDWidget()
Definition: OSDWidget.cc:132
void addWidget(const std::shared_ptr< OSDWidget > &widget)
Definition: OSDWidget.cc:172
virtual void paintSDL(OutputSurface &output)=0
double getY() const
Definition: OSDWidget.hh:22
void invalidateChildren()
Definition: OSDWidget.cc:347
virtual void paintGL(OutputSurface &output)=0
void transformXY(const OutputRectangle &output, double x, double y, double relx, double rely, double &outx, double &outy) const
Definition: OSDWidget.cc:415
OSDWidget(const std::string &name)
Definition: OSDWidget.cc:121
void getBoundingBox(const OutputRectangle &output, int &x, int &y, int &w, int &h)
Definition: OSDWidget.cc:493
virtual void invalidateLocal()=0
int clip(int x)
Clips x to the range [LO,HI].
Definition: Math.hh:29
virtual std::vector< string_ref > getProperties() const
Definition: OSDWidget.cc:254