swift
drawable.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #ifndef SWIFT_SIM_XSWIFTBUS_DRAWABLE_H
5 #define SWIFT_SIM_XSWIFTBUS_DRAWABLE_H
6 
8 
9 #include <XPLMDisplay.h>
10 
11 namespace XSwiftBus
12 {
13 
17  class CDrawable
18  {
19  public:
21  CDrawable(XPLMDrawingPhase phase, bool before) : m_phase(phase), m_before(before) {}
22 
24  virtual ~CDrawable() { hide(); }
25 
27  bool isVisible() const { return m_visible; }
28 
30  void show()
31  {
32  if (m_visible) { return; }
33  m_visible = true;
34  XPLMRegisterDrawCallback(callback, m_phase, m_before, static_cast<void *>(this));
35  }
36 
38  void hide()
39  {
40  if (!m_visible) { return; }
41  m_visible = false;
42  XPLMUnregisterDrawCallback(callback, m_phase, m_before, static_cast<void *>(this));
43  }
44 
45  protected:
47  virtual void draw() = 0;
48 
49  private:
50  static int callback(XPLMDrawingPhase, int, void *refcon)
51  {
52  static_cast<CDrawable *>(refcon)->draw();
53  return 1;
54  }
55 
56  XPLMDrawingPhase m_phase;
57  bool m_before = false;
58  bool m_visible = false;
59  };
60 
61 } // namespace XSwiftBus
62 
63 #endif // SWIFT_SIM_XSWIFTBUS_DRAWABLE_H
Class-based interface to X-Plane's drawing callback API.
Definition: drawable.h:18
void show()
Register the draw callback.
Definition: drawable.h:30
virtual ~CDrawable()
Destructor.
Definition: drawable.h:24
virtual void draw()=0
Callback to draw the thing.
void hide()
Unregister the draw callback.
Definition: drawable.h:38
CDrawable(XPLMDrawingPhase phase, bool before)
Constructor.
Definition: drawable.h:21
bool isVisible() const
Is currently shown.
Definition: drawable.h:27
Plugin loaded by X-Plane which publishes a DBus service.
Definition: command.h:14