From 011488eaf1a6569c47a10eb7a9e48ea1e8155ff2 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Fri, 25 Sep 2015 00:49:18 +0100 Subject: [PATCH] refs #271 C++ API wrapper for the X-Plane Plugin SDK's C API for drawing callbacks. --- src/xbus/drawable.h | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/xbus/drawable.h diff --git a/src/xbus/drawable.h b/src/xbus/drawable.h new file mode 100644 index 000000000..66341dfe3 --- /dev/null +++ b/src/xbus/drawable.h @@ -0,0 +1,61 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKSIM_XBUS_DRAWABLE_H +#define BLACKSIM_XBUS_DRAWABLE_H + +//! \file + +#include + +namespace XBus +{ + + /*! + * Class-based interface to X-Plane's drawing callback API. + */ + class CDrawable + { + public: + //! Constructor. + CDrawable(XPLMDrawingPhase phase, bool before) : m_phase(phase), m_before(before) {} + + //! Destructor. + ~CDrawable() { hide(); } + + //! Register the draw callback. + virtual void show() + { + XPLMRegisterDrawCallback(callback, m_phase, m_before, static_cast(this)); + } + + //! Unregister the draw callback. + virtual void hide() + { + XPLMUnregisterDrawCallback(callback, m_phase, m_before, static_cast(this)); + } + + protected: + //! Callback to draw the thing. + virtual void draw() = 0; + + private: + static int callback(XPLMDrawingPhase, int, void *refcon) + { + static_cast(refcon)->draw(); + return 1; + } + + const XPLMDrawingPhase m_phase; + const bool m_before; + }; + +} + +#endif