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 class Interpreter;
15 
16 class OSDWidget
17 {
18 public:
19  virtual ~OSDWidget();
20 
21  const std::string& getName() const { return name; }
22  double getX() const { return x; }
23  double getY() const { return y; }
24  double getZ() const { return z; }
25  double getRelX() const { return relx; }
26  double getRelY() const { return rely; }
27 
28  OSDWidget* getParent() { return parent; }
29  const OSDWidget* getParent() const { return parent; }
31  const OSDWidget* findSubWidget(string_ref name) const;
32  void addWidget(std::unique_ptr<OSDWidget> widget);
33  void deleteWidget(OSDWidget& widget);
34 
35  virtual std::vector<string_ref> getProperties() const;
36  virtual void setProperty(Interpreter& interp,
37  string_ref name, const TclObject& value);
38  virtual void getProperty(string_ref name, TclObject& result) const;
39  virtual double getRecursiveFadeValue() const;
40  virtual string_ref getType() const = 0;
41 
42  void invalidateRecursive();
43  void paintSDLRecursive(OutputSurface& output);
44  void paintGLRecursive (OutputSurface& output);
45 
46  int getScaleFactor(const OutputRectangle& surface) const;
47  void transformXY(const OutputRectangle& output,
48  double x, double y, double relx, double rely,
49  double& outx, double& outy) const;
50  void getBoundingBox(const OutputRectangle& output,
51  int& x, int& y, int& w, int& h);
52  virtual void getWidthHeight(const OutputRectangle& output,
53  double& width, double& height) const = 0;
54 
55 protected:
56  explicit OSDWidget(const std::string& name);
57  void invalidateChildren();
58  bool needSuppressErrors() const;
59 
60  virtual void invalidateLocal() = 0;
61  virtual void paintSDL(OutputSurface& output) = 0;
62  virtual void paintGL (OutputSurface& output) = 0;
63 
64 private:
65  void getMouseCoord(double& outx, double& outy) const;
66  void transformReverse(const OutputRectangle& output,
67  double x, double y,
68  double& outx, double& outy) const;
69  void setParent(OSDWidget* parent_) { parent = parent_; }
70  void resortUp (OSDWidget* elem);
71  void resortDown(OSDWidget* elem);
72 
73  void listWidgetNames(const std::string& parentName,
74  std::vector<std::string>& result) const;
75  friend class OSDCommand;
76 
79  std::vector<std::unique_ptr<OSDWidget>> subWidgets;
80 
84  StringMap<OSDWidget*> subWidgetsMap;
85 
86  OSDWidget* parent;
87 
88  const std::string name;
89  double x, y, z;
90  double relx, rely;
91  bool scaled;
92  bool clip;
93  bool suppressErrors;
94 };
95 
96 } // namespace openmsx
97 
98 #endif
virtual string_ref getType() const =0
int getScaleFactor(const OutputRectangle &surface) const
Definition: OSDWidget.cc:379
void invalidateRecursive()
Definition: OSDWidget.cc:322
void deleteWidget(OSDWidget &widget)
Definition: OSDWidget.cc:176
bool needSuppressErrors() const
Definition: OSDWidget.cc:335
virtual void getWidthHeight(const OutputRectangle &output, double &width, double &height) const =0
virtual double getRecursiveFadeValue() const
Definition: OSDWidget.cc:317
int clip(int x)
Clips x to the range [LO,HI].
Definition: Math.hh:28
OSDWidget * findSubWidget(string_ref name)
Definition: OSDWidget.cc:136
double getRelX() const
Definition: OSDWidget.hh:25
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:22
double getRelY() const
Definition: OSDWidget.hh:26
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:344
double getZ() const
Definition: OSDWidget.hh:24
virtual ~OSDWidget()
Definition: OSDWidget.cc:132
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:7
virtual void paintSDL(OutputSurface &output)=0
double getY() const
Definition: OSDWidget.hh:23
void invalidateChildren()
Definition: OSDWidget.cc:328
virtual void paintGL(OutputSurface &output)=0
OSDWidget * getParent()
Definition: OSDWidget.hh:28
void transformXY(const OutputRectangle &output, double x, double y, double relx, double rely, double &outx, double &outy) const
Definition: OSDWidget.cc:390
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:468
virtual void invalidateLocal()=0
virtual std::vector< string_ref > getProperties() const
Definition: OSDWidget.cc:234
const OSDWidget * getParent() const
Definition: OSDWidget.hh:29
virtual void setProperty(Interpreter &interp, string_ref name, const TclObject &value)
Definition: OSDWidget.cc:243
const std::string & getName() const
Definition: OSDWidget.hh:21