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 <string_view>
7 #include <vector>
8 #include <memory>
9 
10 namespace openmsx {
11 
12 class Display;
13 class OutputSurface;
14 class Interpreter;
15 
16 class OSDWidget
17 {
18  using SubWidgets = std::vector<std::unique_ptr<OSDWidget>>;
19 public:
20  virtual ~OSDWidget() = default;
21 
22  std::string_view getName() const { return name.getString(); }
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; }
29  const SubWidgets& getChildren() const { return subWidgets; }
30  void addWidget(std::unique_ptr<OSDWidget> widget);
31  void deleteWidget(OSDWidget& widget);
32 
33  virtual std::vector<std::string_view> getProperties() const;
34  virtual void setProperty(Interpreter& interp,
35  std::string_view name, const TclObject& value);
36  virtual void getProperty(std::string_view name, TclObject& result) const;
37  virtual float getRecursiveFadeValue() const;
38  virtual std::string_view getType() const = 0;
39 
40  void invalidateRecursive();
41  void paintSDLRecursive(OutputSurface& output);
42  void paintGLRecursive (OutputSurface& output);
43 
44  int getScaleFactor(const OutputSurface& output) const;
45  gl::vec2 transformPos(const OutputSurface& output,
46  gl::vec2 pos, gl::vec2 relPos) const;
47  void getBoundingBox(const OutputSurface& output,
48  gl::vec2& pos, gl::vec2& size) const;
49  virtual gl::vec2 getSize(const OutputSurface& output) const = 0;
50 
51  Display& getDisplay() const { return display; }
52 
53 protected:
54  OSDWidget(Display& display, const TclObject& 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  gl::vec2 getMouseCoord() const;
64  gl::vec2 transformReverse(const OutputSurface& output,
65  gl::vec2 pos) const;
66  void setParent(OSDWidget* parent_) { parent = parent_; }
67  void resortUp (OSDWidget* elem);
68  void resortDown(OSDWidget* elem);
69 
72  SubWidgets subWidgets;
73 
74  Display& display;
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
openmsx::OSDWidget::getRecursiveFadeValue
virtual float getRecursiveFadeValue() const
Definition: OSDWidget.cc:305
openmsx::OSDWidget::paintSDL
virtual void paintSDL(OutputSurface &output)=0
openmsx::OSDWidget::getParent
OSDWidget * getParent()
Definition: OSDWidget.hh:27
openmsx::OSDWidget::getChildren
const SubWidgets & getChildren() const
Definition: OSDWidget.hh:29
openmsx::OSDWidget::paintGL
virtual void paintGL(OutputSurface &output)=0
TclObject.hh
openmsx::OSDWidget::getName
std::string_view getName() const
Definition: OSDWidget.hh:22
utf8::unchecked::size
size_t size(std::string_view utf8)
Definition: utf8_unchecked.hh:227
gl_vec.hh
openmsx::OSDWidget::getScaleFactor
int getScaleFactor(const OutputSurface &output) const
Definition: OSDWidget.cc:367
openmsx::OSDWidget::deleteWidget
void deleteWidget(OSDWidget &widget)
Definition: OSDWidget.cc:173
openmsx::OSDWidget
Definition: OSDWidget.hh:17
openmsx::OSDWidget::getParent
const OSDWidget * getParent() const
Definition: OSDWidget.hh:28
openmsx::OSDWidget::OSDWidget
OSDWidget(Display &display, const TclObject &name)
Definition: OSDWidget.cc:139
openmsx::OSDWidget::invalidateLocal
virtual void invalidateLocal()=0
openmsx::OSDWidget::setProperty
virtual void setProperty(Interpreter &interp, std::string_view name, const TclObject &value)
Definition: OSDWidget.cc:233
openmsx::OSDWidget::invalidateChildren
void invalidateChildren()
Definition: OSDWidget.cc:316
openmsx::OSDWidget::addWidget
void addWidget(std::unique_ptr< OSDWidget > widget)
Definition: OSDWidget.cc:150
gl::vecN
Definition: gl_vec.hh:36
openmsx::OSDWidget::getProperties
virtual std::vector< std::string_view > getProperties() const
Definition: OSDWidget.cc:224
openmsx::OSDWidget::getRelPos
gl::vec2 getRelPos() const
Definition: OSDWidget.hh:24
openmsx::OSDWidget::getZ
float getZ() const
Definition: OSDWidget.hh:25
openmsx::OSDWidget::needSuppressErrors
bool needSuppressErrors() const
Definition: OSDWidget.cc:323
openmsx::OSDWidget::transformPos
gl::vec2 transformPos(const OutputSurface &output, gl::vec2 pos, gl::vec2 relPos) const
Definition: OSDWidget.cc:378
openmsx::OSDWidget::~OSDWidget
virtual ~OSDWidget()=default
openmsx::OSDWidget::getPos
gl::vec2 getPos() const
Definition: OSDWidget.hh:23
openmsx::OSDWidget::getDisplay
Display & getDisplay() const
Definition: OSDWidget.hh:51
openmsx::OSDWidget::invalidateRecursive
void invalidateRecursive()
Definition: OSDWidget.cc:310
openmsx::OSDWidget::getProperty
virtual void getProperty(std::string_view name, TclObject &result) const
Definition: OSDWidget.cc:277
openmsx::Display
Represents the output window/screen of openMSX.
Definition: Display.hh:33
openmsx::TclObject::getString
std::string_view getString() const
Definition: TclObject.cc:102
openmsx::OutputSurface
A frame buffer where pixels can be written to.
Definition: OutputSurface.hh:20
openmsx::TclObject
Definition: TclObject.hh:22
openmsx::Interpreter
Definition: Interpreter.hh:17
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5
openmsx::OSDWidget::getType
virtual std::string_view getType() const =0
openmsx::OSDWidget::paintGLRecursive
void paintGLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:348
openmsx::OSDWidget::paintSDLRecursive
void paintSDLRecursive(OutputSurface &output)
Definition: OSDWidget.cc:332
openmsx::OSDWidget::getBoundingBox
void getBoundingBox(const OutputSurface &output, gl::vec2 &pos, gl::vec2 &size) const
Definition: OSDWidget.cc:443
openmsx::OSDWidget::getSize
virtual gl::vec2 getSize(const OutputSurface &output) const =0