#ifndef BUTTON_WIDGET_H_INCLUDED #define BUTTON_WIDGET_H_INCLUDED #include "include/Render/RenderMisc.h" #include "include/Render/RenderParams.h" #include "include/Utils/Utils.h" #include "include/FontManager/FontManager.h" namespace SE { class TInstancingWidgetAncestor { protected: public: TRenderPairList TriangleListVector; vec2 LeftBottomPos; virtual void Update(cardinal dt); virtual bool CheckClick(vec2 mousePos); virtual void OnTapDown(vec2 pos) { } virtual void OnTapUp(vec2 pos) { } virtual void OnTapUpAfterMove(vec2 pos) { } virtual void OnTapUpAfterMoveOut(vec2 pos) { } virtual void OnMove(vec2 shift) { } virtual void OnMoveOut() { } virtual void OnKeyPress(int key) { } virtual bool IsTransparentForInput() { return false; } virtual ~TInstancingWidgetAncestor(); }; struct TTextParams : public TSerializeInterface { std::string Text; std::string FontName; TTextBasicAreaParams BasicTextAreaParams; TRenderParams RenderParams; TTextParams() { } TTextParams(const std::string& text) : Text(text) { } TTextParams(const std::string& text, const std::string& fontName, int height, float horizontalPadding, float verticalPadding, TTextHorizontalAlignment textHorizontalAlignment, TTextVerticalAlignment textVerticalAlignment) : Text(text) , FontName(fontName) , BasicTextAreaParams(height, horizontalPadding, verticalPadding, textHorizontalAlignment, textVerticalAlignment) { } virtual void Serialize(boost::property_tree::ptree& propertyTree) { Text = propertyTree.get("Text"); FontName = propertyTree.get("Font"); BasicTextAreaParams.Serialize(propertyTree.find("TextAreaParams")->second); if (propertyTree.count("RenderParams") != 0) { RenderParams.Serialize(propertyTree.find("RenderParams")->second); } } }; struct TSquareStatic : public TInstancingWidgetAncestor { float Width; float Height; TSquareStatic() : Width(0) , Height(0) { } virtual bool CheckClick(vec2 mousePos); static TSquareStatic* CreateStatic(vec2 posFrom, vec2 posTo); static TSquareStatic* CreateStaticWithFiller(vec2 posFrom, vec2 posTo, boost::function staticFillerFunc); static TSquareStatic* CreateStaticWithFillers(vec2 posFrom, vec2 posTo, std::vector> staticFillerFuncArr); static void StaticTextureFiller(vec2 posFrom, vec2 posTo, const std::string& texName, TSquareStatic* staticToFill); static void StaticTextFiller(vec2 posFrom, vec2 posTo, TTextParams buttonTextParams, TSquareStatic* staticToFill); static TSquareStatic* CreateStaticTexture(vec2 posFrom, vec2 posTo, const std::string& texName); static TSquareStatic* CreateStaticText(vec2 posFrom, vec2 posTo, TTextParams buttonTextParams); }; struct TDynamicText : public TInstancingWidgetAncestor { protected: boost::signals::connection SmartValueConnection; TTextParams LastTextParams; TRenderPairList::iterator TextRenderPairItr; public: float Width; float Height; TDynamicText(); ~TDynamicText(); virtual bool CheckClick(vec2 mousePos); void UpdateText(std::string text); static TDynamicText* CreateDynamicText(vec2 posFrom, vec2 posTo); static TDynamicText* CreateDynamicTextWithFiller(vec2 posFrom, vec2 posTo, boost::function dynamicTextFillerFunc); static TDynamicText* CreateDynamicTextWithFillers(vec2 posFrom, vec2 posTo, std::vector> dynamicTextFillerFuncArr); static void TextParamsFiller(vec2 posFrom, vec2 posTo, TTextParams textParams, TDynamicText* dynamicTextToFill); static void SmartValueTextFiller(const std::string& dictionaryName, const std::string& smartValueName, TDynamicText* dynamicTextToFill); }; TTriangleList CreateTriangleListForText(vec2 posFrom, vec2 posTo, TTextParams buttonTextParams); class TUniversalButton : public TInstancingWidgetAncestor { protected: enum { BS_NORMAL, BS_GO_PRESSED, BS_PRESSED, BS_GO_NORMAL } ButtonState; float ButtonStateTimer; public: std::vector NormalTextureIteratorArr; std::vector PressedTextureIteratorArr; float Width; float Height; TUniversalButton(); virtual void Update(cardinal dt); virtual bool CheckClick(vec2 mousePos); virtual void OnTapDown(vec2 pos); virtual void OnTapUp(vec2 pos); virtual void OnTapUpAfterMove(vec2 pos); virtual void OnMoveOut(); static TUniversalButton* CreateButton(vec2 posFrom, vec2 posTo); static TUniversalButton* CreateButtonWithFiller(vec2 posFrom, vec2 posTo, boost::function buttonFillerFunc); static TUniversalButton* CreateButtonWithFillers(vec2 posFrom, vec2 posTo, std::vector > buttonFillerFuncArr); static void SquareButtonFiller(vec2 posFrom, vec2 posTo, const std::string& texName, const std::string& texNamePressed, TUniversalButton* buttonToFill); static void TextButtonFiller(vec2 posFrom, vec2 posTo, TTextParams buttonTextParamsNormal, TTextParams buttonTextParamsPressed, TUniversalButton* buttonToFill); static TUniversalButton* CreateSquareButton(vec2 posFrom, vec2 posTo, const std::string& texName, const std::string& texNamePressed); static TUniversalButton* CreateTextOnlyButton(vec2 posFrom, vec2 posTo, TTextParams buttonTextParamsNormal, TTextParams buttonTextParamsPressed); static TUniversalButton* CreateSquareAndTextButton(vec2 posFrom, vec2 posTo, const std::string& texName, const std::string& texNamePressed, TTextParams buttonTextParamsNormal, TTextParams buttonTextParamsPressed); }; class TEdit : public TInstancingWidgetAncestor { protected: float Width; float Height; TTextParams TextParams; void RefreshTextTriangleList(); boost::signals::connection InputConnection; boost::signals::connection SetTextSlotConnection; public: ~TEdit(); TRenderPairList::iterator TextIterator; boost::signal OnTextChanged; virtual bool CheckClick(vec2 mousePos); virtual void OnKeyPress(int key); virtual void OnTapDown(vec2 pos); void SetText(const std::string& newText); void OnSetAllText(std::string newText); //For iOS only std::string GetText(); static TEdit* CreateEdit(vec2 posFrom, vec2 posTo); static TEdit* CreateEditWithFiller(vec2 posFrom, vec2 posTo, boost::function fillerFunc); static TEdit* CreateEditWithFillers(vec2 posFrom, vec2 posTo, std::vector > fillerFuncArr); static void EditFiller(vec2 posFrom, vec2 posTo, const std::string& texName, TTextParams textParams, TEdit* edit); static void SmartValueTextFiller(const std::string& dictionaryName, const std::string& smartValueName, TEdit* edit); //static TEdit* CreateEdit(vec2 posFrom, vec2 posTo, const std::string& texName, TTextParams textParams); }; class TCheckBox : public TInstancingWidgetAncestor { protected: bool IsChecked; //To be set immediately on tap up boost::signals::connection SetCheckedSlotConnection; void RefreshVisibility(); public: std::vector StaticTextureIteratorArr; std::vector CheckedTextureIteratorArr; float Width; float Height; TCheckBox(); ~TCheckBox(); virtual bool CheckClick(vec2 mousePos); virtual void Update(cardinal dt); virtual void OnTapDown(vec2 pos); virtual void OnTapUp(vec2 pos); virtual void OnMoveOut(); //Logic: void SetChecked(bool isChecked); boost::signal OnSetChecked; static TCheckBox* CreateCheckBox(vec2 posFrom, vec2 posTo); static TCheckBox* CreateCheckBoxWithFiller(vec2 posFrom, vec2 posTo, boost::function checkBoxFillerFunc); static TCheckBox* CreateCheckBoxWithFillers(vec2 posFrom, vec2 posTo, std::vector > checkBoxFillerFuncArr); static void TextureFiller(vec2 posFrom, vec2 posTo, const std::string& texName, const std::string& texNameChecked, TCheckBox* checkBoxToFill); static void TextFiller(vec2 posFrom, vec2 posTo, TTextParams textParams, TCheckBox* checkBoxToFill); static void CheckedFiller(bool isChecked, TCheckBox* checkBoxToFill); static void SmartValueFiller(const std::string& dictionaryName, const std::string& smartValueName, TCheckBox* checkBoxToFill); static TCheckBox* CreateSimpleCheckBox(vec2 posFrom, vec2 posTo, const std::string& texName, const std::string& texNameChecked); static TCheckBox* CreateCheckBoxWithText(vec2 posFrom, vec2 posTo, const std::string& texName, const std::string& texNameChecked, vec2 textPosFrom, vec2 textPosTo, TTextParams textParams); }; class TRadioButton : public TInstancingWidgetAncestor { protected: bool IsChecked; //To be set immediately on tap up boost::signals::connection SetCheckedSlotConnection; void RefreshVisibility(); public: std::vector StaticTextureIteratorArr; std::vector CheckedTextureIteratorArr; float Width; float Height; TRadioButton(); ~TRadioButton(); virtual bool CheckClick(vec2 mousePos); virtual void Update(cardinal dt); virtual void OnTapDown(vec2 pos); virtual void OnTapUp(vec2 pos); virtual void OnMoveOut(); //Logic: void SetChecked(bool isChecked); boost::signal OnSetChecked; static TRadioButton* CreateRadioButton(vec2 posFrom, vec2 posTo); static TRadioButton* CreateRadioButtonWithFiller(vec2 posFrom, vec2 posTo, boost::function radioButtonFillerFunc); static TRadioButton* CreateRadioButtonWithFillers(vec2 posFrom, vec2 posTo, std::vector > radioButtonFillerFuncArr); static void TextureFiller(vec2 posFrom, vec2 posTo, const std::string& texName, const std::string& texNameChecked, TRadioButton* radioButtonToFill); static void TextFiller(vec2 posFrom, vec2 posTo, TTextParams textParams, TRadioButton* radioButtonToFill); static void CheckedFiller(bool isChecked, TRadioButton* radioButtonToFill); template static void SmartValueFiller(const std::string& dictionaryName, const std::string& smartValueName, TYPENAME value, TRadioButton* radioButtonToFill); static TRadioButton* CreateSimpleRadioButton(vec2 posFrom, vec2 posTo, const std::string& texName, const std::string& texNameChecked); static TRadioButton* CreateRadioButtonWithText(vec2 posFrom, vec2 posTo, const std::string& texName, const std::string& texNameChecked, vec2 textPosFrom, vec2 textPosTo, TTextParams textParams); }; class TMover : public TInstancingWidgetAncestor { protected: float PosCursor; public: float Width; float Height; float MaxHeight; std::string GroupName; std::string SelfName; //For exclusion TMover(); ~TMover(); virtual void Update(cardinal dt); virtual bool CheckClick(vec2 mousePos); virtual void OnTapDown(vec2 pos); virtual void OnTapUp(vec2 pos); virtual void OnMove(vec2 shift); virtual void OnMoveOut(); virtual bool IsTransparentForInput() { return true; } static TMover* CreateMover(vec2 posFrom, vec2 posTo, std::string groupName, std::string selfName, float maxHeight); }; } //namespace SE #endif