openMSX
OSDTopWidget.cc
Go to the documentation of this file.
1 #include "OSDTopWidget.hh"
2 #include "OutputSurface.hh"
3 #include "Display.hh"
4 #include "CliComm.hh"
5 #include "view.hh"
6 
7 namespace openmsx {
8 
10  : OSDWidget(display_, TclObject())
11 {
12  addName(*this);
13 }
14 
15 std::string_view OSDTopWidget::getType() const
16 {
17  return "top";
18 }
19 
21 {
22  return gl::vec2(output.getLogicalSize()); // int -> float
23 }
24 
26 {
27  return false;
28 }
29 
31 {
32  return false; // not fading
33 }
34 
36 {
37  // nothing
38 }
39 
41 {
42  // nothing
43 }
44 
46 {
47  // nothing
48 }
49 
50 void OSDTopWidget::queueError(std::string message)
51 {
52  errors.push_back(std::move(message));
53 }
54 
56 {
57  auto& cliComm = getDisplay().getCliComm();
58  for (auto& message : errors) {
59  cliComm.printWarning(std::move(message));
60  }
61  errors.clear();
62 }
63 
64 OSDWidget* OSDTopWidget::findByName(std::string_view widgetName)
65 {
66  auto it = widgetsByName.find(widgetName);
67  return (it != end(widgetsByName)) ? *it : nullptr;
68 }
69 
70 const OSDWidget* OSDTopWidget::findByName(std::string_view widgetName) const
71 {
72  return const_cast<OSDTopWidget*>(this)->findByName(widgetName);
73 }
74 
76 {
77  assert(!widgetsByName.contains(widget.getName()));
78  widgetsByName.emplace_noDuplicateCheck(&widget);
79 }
80 
82 {
83  auto it = widgetsByName.find(widget.getName());
84  assert(it != end(widgetsByName));
85  for (auto& child : (*it)->getChildren()) {
86  removeName(*child);
87  }
88  widgetsByName.erase(it);
89 }
90 
91 std::vector<std::string_view> OSDTopWidget::getAllWidgetNames() const
92 {
93  return to_vector(view::transform(widgetsByName,
94  [](auto* p) { return p->getName(); }));
95 }
96 
97 } // namespace openmsx
void printWarning(std::string_view message)
Definition: CliComm.cc:10
Represents the output window/screen of openMSX.
Definition: Display.hh:33
CliComm & getCliComm() const
Definition: Display.cc:132
std::string_view getType() const override
Definition: OSDTopWidget.cc:15
OSDWidget * findByName(std::string_view name)
Definition: OSDTopWidget.cc:64
std::vector< std::string_view > getAllWidgetNames() const
Definition: OSDTopWidget.cc:91
bool isRecursiveFading() const override
Definition: OSDTopWidget.cc:30
void addName(OSDWidget &widget)
Definition: OSDTopWidget.cc:75
void queueError(std::string message)
Definition: OSDTopWidget.cc:50
gl::vec2 getSize(const OutputSurface &output) const override
Definition: OSDTopWidget.cc:20
void removeName(OSDWidget &widget)
Definition: OSDTopWidget.cc:81
void paintGL(OutputSurface &output) override
Definition: OSDTopWidget.cc:45
bool isVisible() const override
Definition: OSDTopWidget.cc:25
void invalidateLocal() override
Definition: OSDTopWidget.cc:35
OSDTopWidget(Display &display)
Definition: OSDTopWidget.cc:9
void paintSDL(OutputSurface &output) override
Definition: OSDTopWidget.cc:40
Display & getDisplay() const
Definition: OSDWidget.hh:55
std::string_view getName() const
Definition: OSDWidget.hh:22
A frame buffer where pixels can be written to.
gl::ivec2 getLogicalSize() const
vecN< 2, float > vec2
Definition: gl_vec.hh:139
This file implemented 3 utility functions:
Definition: Autofire.cc:9
constexpr auto transform(Range &&range, UnaryOp op)
Definition: view.hh:306
auto to_vector(Range &&range) -> std::vector< detail::ToVectorType< T, decltype(std::begin(range))>>
Definition: stl.hh:316
constexpr auto end(const zstring_view &x)
Definition: zstring_view.hh:83