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 
16 {
17  return "top";
18 }
19 
21 {
22  return gl::vec2(output.getLogicalSize()); // int -> float
23 }
24 
26 {
27  // nothing
28 }
29 
31 {
32  // nothing
33 }
34 
36 {
37  // nothing
38 }
39 
40 void OSDTopWidget::queueError(std::string message)
41 {
42  errors.push_back(std::move(message));
43 }
44 
46 {
47  auto& cliComm = getDisplay().getCliComm();
48  for (auto& message : errors) {
49  cliComm.printWarning(std::move(message));
50  }
51  errors.clear();
52 }
53 
55 {
56  auto it = widgetsByName.find(widgetName);
57  return (it != end(widgetsByName)) ? *it : nullptr;
58 }
59 
61 {
62  return const_cast<OSDTopWidget*>(this)->findByName(widgetName);
63 }
64 
66 {
67  assert(!widgetsByName.contains(widget.getName()));
68  widgetsByName.emplace_noDuplicateCheck(&widget);
69 }
70 
72 {
73  auto it = widgetsByName.find(widget.getName());
74  assert(it != end(widgetsByName));
75  for (auto& child : (*it)->getChildren()) {
76  removeName(*child);
77  }
78  widgetsByName.erase(it);
79 }
80 
81 std::vector<string_view> OSDTopWidget::getAllWidgetNames() const
82 {
83  return to_vector(view::transform(widgetsByName,
84  [](auto* p) { return p->getName(); }));
85 }
86 
87 } // namespace openmsx
auto transform(Range &&range, UnaryOp op)
Definition: view.hh:312
OSDWidget * findByName(string_view name)
Definition: OSDTopWidget.cc:54
Represents the output window/screen of openMSX.
Definition: Display.hh:31
void removeName(OSDWidget &widget)
Definition: OSDTopWidget.cc:71
std::vector< string_view > getAllWidgetNames() const
Definition: OSDTopWidget.cc:81
void queueError(std::string message)
Definition: OSDTopWidget.cc:40
gl::ivec2 getLogicalSize() const
A frame buffer where pixels can be written to.
gl::vec2 getSize(const OutputSurface &output) const override
Definition: OSDTopWidget.cc:20
CliComm & getCliComm() const
Definition: Display.cc:131
string_view getType() const override
Definition: OSDTopWidget.cc:15
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void paintGL(OutputSurface &output) override
Definition: OSDTopWidget.cc:35
string_view getName() const
Definition: OSDWidget.hh:22
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
Display & getDisplay() const
Definition: OSDWidget.hh:51
void addName(OSDWidget &widget)
Definition: OSDTopWidget.cc:65
void paintSDL(OutputSurface &output) override
Definition: OSDTopWidget.cc:30
void invalidateLocal() override
Definition: OSDTopWidget.cc:25
vecN< 2, float > vec2
Definition: gl_vec.hh:139
void printWarning(string_view message)
Definition: CliComm.cc:20
auto to_vector(Range &&range) -> std::vector< detail::ToVectorType< T, decltype(std::begin(range))>>
Definition: stl.hh:325
OSDTopWidget(Display &display)
Definition: OSDTopWidget.cc:9
auto end(const string_view &x)
Definition: string_view.hh:152