/* Copyright (C) 2013 * 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. 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_XSWIFTBUS_MENUS_H #define BLACKSIM_XSWIFTBUS_MENUS_H //! \file #include #include #include #include #include namespace XSwiftBus { class CMenu; /*! * Class-based interface to X-Plane SDK menu items. */ class CMenuItem { public: //! Construct an uninitialized menu item object CMenuItem() = default; //! Returns true if the menu item is checked bool getChecked() const; //! Sets the checked status of the menu item void setChecked(bool checked); //! Enables or disabled the menu item void setEnabled(bool enabled); private: friend class CMenu; CMenuItem(XPLMMenuID parent, int item, bool checkable, std::function callback); void setIndex(int index) { m_data->index = index; } struct Data { Data(XPLMMenuID parent_, int index_, bool checkable_, std::function callback_) : parent(parent_), index(index_), checkable(checkable_), callback(callback_) {} XPLMMenuID parent; int index; bool checkable; std::function callback; }; std::shared_ptr m_data; }; /*! * Class-based interface to X-Plane SDK menus. */ class CMenu { public: //! Construct an uninitialized menu object CMenu() = default; //! Returns a menu object representing the top-level menu of all plugins. static CMenu mainMenu(); //! Appends an item to the menu and returns it. CMenuItem item(const std::string &name, std::function callback); //! Appends a checkbox item to the menu and returns it. CMenuItem checkableItem(const std::string &name, bool checked, std::function callback); //! Removes item from the menu void removeItem(const CMenuItem &item); //! Appends a separator to the menu. void sep(); //! Appends an item to the menu which opens a sub-menu, and returns it. CMenu subMenu(const std::string &name); private: // Using std::list, since it does not invalidate pointers. using ItemList = std::list; // CMenu(XPLMMenuID id, bool isMainMenu, std::unique_ptr callbacks); CMenu(XPLMMenuID id, bool isMainMenu, std::unique_ptr items); static void handler(void *menuRef, void *itemRef); struct Data { Data(XPLMMenuID id_, bool isMainMenu_, std::unique_ptr items_) : id(id_), isMainMenu(isMainMenu_), items(std::move(items_)) {} XPLMMenuID id; bool isMainMenu; std::unique_ptr items; ~Data(); Data(const Data &) = delete; Data &operator =(const Data &) = delete; }; std::shared_ptr m_data; }; } #endif // guard