From 9d39702824e8fae5127e09fb5a05b521b48cd028 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 9 Nov 2008 11:43:28 +0000 Subject: docking menus --- src/core/descriptions.h | 128 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 src/core/descriptions.h (limited to 'src/core/descriptions.h') diff --git a/src/core/descriptions.h b/src/core/descriptions.h new file mode 100644 index 0000000..345d354 --- /dev/null +++ b/src/core/descriptions.h @@ -0,0 +1,128 @@ +/* + core/descriptions.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_CORE_DESCRIPTIONS_H__ +#define __INCLUDED_CORE_DESCRIPTIONS_H__ + +#include +#include +#include + +namespace core { +class ButtonDescription; +class MenuDescription; +} + +#include "core/entity.h" +#include "model/model.h" +#include "filesystem/inifile.h" + +namespace core { + +/// description of a menu button +class ButtonDescription +{ +public: + enum Align {Center=0, Left=1, Right=2}; + + ButtonDescription(); + ~ButtonDescription(); + + /* -- inspectors ------------------------------------------- */ + + /// button text + inline const std::string & text() const { return button_text; } + + /// button command + inline const std::string & command() const { return button_command; } + + /// button info view model name + inline const std::string & modelname() const { return button_modelname; } + + /// button info view model + inline const model::Model *model() { return button_model; } + + /// button text alignment + inline Align alignment() const { return button_align; } + + /* -- mutators -------------------------------------------- */ + + /// set button text + void set_text(const std::string &text); + + /// set button command + void set_command(const std::string &command); + + /// set button name + void set_modelname(const std::string &modelname); + + /// set text alignment + void set_alignment(Align align); + +private: + std::string button_text; + std::string button_command; + std::string button_modelname; + Align button_align; + + model::Model *button_model; +}; + +/// description of an entity menu +class MenuDescription +{ +public: + MenuDescription(); + ~MenuDescription(); + + typedef std::list Buttons; + + /* -- inspectors ------------------------------------------- */ + + /// menu label + inline const std::string & label() const { return menu_label; } + + /// menu text + inline const std::string & text() const { return menu_text; } + + /// menu buttons + inline Buttons &buttons() { return menu_buttons; } + + /* -- mutators -------------------------------------------- */ + + /// set menu text + void set_text(const std::string &text); + + /// set menu label + void set_label(const std::string &label); + + /// add a menu button + void add_button(ButtonDescription *button); + +private: + std::string menu_label; + std::string menu_text; + + Buttons menu_buttons; +}; + + +/// descriptions loader class +class Descriptions { +public: + /// read entity menus from ini file + static bool load_entity_menus(core::Entity *entity, const std::string &menufilename); + /// serialize entity menus to a stream + static void serialize(MenuDescription *menu, std::ostream & os); + /// read entity menus from a stream + static MenuDescription * receive(std::istream &is); +}; + +} + +#endif // __INCLUDED_CORE_DESCRIPTIONS_H__ + + -- cgit v1.2.3