/* * InterfaceBuilder.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * * License: GNU General Public License v2.0 or later * Full text of license available in license.txt file, in main folder * */ #pragma once #include "CIntObject.h" #include "../../lib/JsonNode.h" class CPicture; class CLabel; class CToggleGroup; class CToggleButton; class CButton; class CLabelGroup; class InterfaceObjectConfigurable: public CIntObject { public: InterfaceObjectConfigurable(); InterfaceObjectConfigurable(const JsonNode & config); protected: //must be called after adding callbacks void init(const JsonNode & config); void addCallback(const std::string & callbackName, std::function callback); template const std::shared_ptr widget(const std::string & name) const { auto iter = widgets.find(name); if(iter == widgets.end()) return nullptr; return std::dynamic_pointer_cast(iter->second); } virtual std::shared_ptr buildCustomWidget(const JsonNode & config) const; private: //field deserializers //basic serializers Point readPosition(const JsonNode &) const; ETextAlignment readTextAlignment(const JsonNode &) const; SDL_Color readColor(const JsonNode &) const; EFonts readFont(const JsonNode &) const; std::string readText(const JsonNode &) const; std::pair readHintText(const JsonNode &) const; //basic widgets std::shared_ptr buildPicture(const JsonNode &) const; std::shared_ptr buildLabel(const JsonNode &) const; std::shared_ptr buildToggleGroup(const JsonNode &) const; std::shared_ptr buildToggleButton(const JsonNode &) const; std::shared_ptr buildButton(const JsonNode &) const; std::shared_ptr buildLabelGroup(const JsonNode &) const; std::shared_ptr buildWidget(const JsonNode & config) const; private: std::map> widgets; std::map> callbacks; };