First blood

This commit is contained in:
vladislav.khorev committed 2013-01-19 20:02:34 +00:00
1 parent 04f270f322
commit 5720f8322b
250 files changed
+33215

No files matched your search

+344
View File
@@ -0,0 +1,344 @@
#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 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<std::string>("Text");
FontName = propertyTree.get<std::string>("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<void(TSquareStatic*)> staticFillerFunc);
static TSquareStatic* CreateStaticWithFillers(vec2 posFrom, vec2 posTo, std::vector<boost::function<void(TSquareStatic*)>> 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<void(TDynamicText*)> dynamicTextFillerFunc);
static TDynamicText* CreateDynamicTextWithFillers(vec2 posFrom, vec2 posTo, std::vector<boost::function<void(TDynamicText*)>> 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<TRenderPairList::iterator> NormalTextureIteratorArr;
std::vector<TRenderPairList::iterator> 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 OnMoveOut();
static TUniversalButton* CreateButton(vec2 posFrom, vec2 posTo);
static TUniversalButton* CreateButtonWithFiller(vec2 posFrom, vec2 posTo, boost::function<void(TUniversalButton*)> buttonFillerFunc);
static TUniversalButton* CreateButtonWithFillers(vec2 posFrom, vec2 posTo, std::vector<boost::function<void(TUniversalButton*)> > 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<void(std::string)> OnTextChanged;
virtual bool CheckClick(vec2 mousePos);
virtual void OnKeyPress(int key);
virtual void OnTapDown(vec2 pos);
void SetText(const std::string& newText);
static TEdit* CreateEdit(vec2 posFrom, vec2 posTo);
static TEdit* CreateEditWithFiller(vec2 posFrom, vec2 posTo, boost::function<void(TEdit*)> fillerFunc);
static TEdit* CreateEditWithFillers(vec2 posFrom, vec2 posTo, std::vector<boost::function<void(TEdit*)> > 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<TRenderPairList::iterator> StaticTextureIteratorArr;
std::vector<TRenderPairList::iterator> 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<void(bool)> OnSetChecked;
static TCheckBox* CreateCheckBox(vec2 posFrom, vec2 posTo);
static TCheckBox* CreateCheckBoxWithFiller(vec2 posFrom, vec2 posTo, boost::function<void(TCheckBox*)> checkBoxFillerFunc);
static TCheckBox* CreateCheckBoxWithFillers(vec2 posFrom, vec2 posTo, std::vector<boost::function<void(TCheckBox*)> > 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<TRenderPairList::iterator> StaticTextureIteratorArr;
std::vector<TRenderPairList::iterator> 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<void(bool)> OnSetChecked;
static TRadioButton* CreateRadioButton(vec2 posFrom, vec2 posTo);
static TRadioButton* CreateRadioButtonWithFiller(vec2 posFrom, vec2 posTo, boost::function<void(TRadioButton*)> radioButtonFillerFunc);
static TRadioButton* CreateRadioButtonWithFillers(vec2 posFrom, vec2 posTo, std::vector<boost::function<void(TRadioButton*)> > 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 <typename TYPENAME>
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
+184
View File
@@ -0,0 +1,184 @@
#ifndef GUIMANAGER_H_INCLUDED
#define GUIMANAGER_H_INCLUDED
#include "include/Render/RenderMisc.h"
#include "include/GUIManager/ButtonWidget.h"
#include "include/GUIManager/WidgetXmlParsers.h"
#include "include/Utils/Utils.h"
#include "include/ScriptManager/ScriptManager.h"
#include "boost/variant.hpp"
#include "boost/thread.hpp"
namespace SE
{
extern const std::string CONST_HOLD_SIGNAL_NAME;
extern const std::string CONST_CLICK_SIGNAL_NAME;
extern const std::string CONST_DRAG_SIGNAL_NAME;
typedef boost::variant<cardinal, vec2> TSignalParam;
struct TWidgetStruct
{
std::string Name;
std::string GroupName;
int Order;
bool IsMouseDown;
std::shared_ptr<TInstancingWidgetAncestor> Widget;
std::map<std::string, std::shared_ptr<boost::signal<void (TSignalParam)>>> SignalMap;
TWidgetStruct(const std::string& name, const std::string& groupName, std::shared_ptr<TInstancingWidgetAncestor> widget, int order = 0)
: Name(name)
, GroupName(groupName)
, Order(order)
, IsMouseDown(false)
, Widget(widget)
{
SignalMap[CONST_HOLD_SIGNAL_NAME] = std::shared_ptr<boost::signal<void (TSignalParam)>>(new boost::signal<void (TSignalParam)>());
SignalMap[CONST_CLICK_SIGNAL_NAME] = std::shared_ptr<boost::signal<void (TSignalParam)>>(new boost::signal<void (TSignalParam)>());
SignalMap[CONST_DRAG_SIGNAL_NAME] = std::shared_ptr<boost::signal<void (TSignalParam)>>(new boost::signal<void (TSignalParam)>());
}
TWidgetStruct(const TWidgetStruct& widgetStruct)
{
Name = widgetStruct.Name;
Widget = widgetStruct.Widget;
GroupName = widgetStruct.GroupName;
IsMouseDown = widgetStruct.IsMouseDown;
Order = widgetStruct.Order;
SignalMap = widgetStruct.SignalMap;
}
TWidgetStruct& operator=(const TWidgetStruct& widgetStruct)
{
//Self-assignment is ok
Name = widgetStruct.Name;
Widget = widgetStruct.Widget;
GroupName = widgetStruct.GroupName;
IsMouseDown = widgetStruct.IsMouseDown;
Order = widgetStruct.Order;
SignalMap = widgetStruct.SignalMap;
return *this;
}
~TWidgetStruct()
{
}
//For sorting
bool operator>(const TWidgetStruct& widget) const
{
return Order > widget.Order;
}
bool operator<(const TWidgetStruct& widget) const
{
return Order < widget.Order;
}
bool operator==(const TWidgetStruct& widget) const
{
return Order == widget.Order;
}
};
struct TWidgetTransformTask
{
std::string GroupName;
vec2 PosTo;
int CurrentTime;
int TotalTime;
enum TMoveStyle
{
MS_LINEAR,
MS_SQR,
MS_SQRT
} MoveStyle;
TWidgetTransformTask(const std::string& groupName, vec2 posTo, int totalTime, int currentTime, TMoveStyle moveStyle)
: GroupName(groupName)
, PosTo(posTo)
, TotalTime(totalTime)
, CurrentTime(currentTime)
, MoveStyle(moveStyle)
{
}
};
typedef std::list<TWidgetTransformTask> TWidgetTrasfromTaskList;
typedef std::vector<TWidgetStruct> TWidgetArr;
class TGUIManager : public TFunctionBinderInterface
{
protected:
TWidgetArr WidgetArr;
TWidgetTrasfromTaskList WidgetTrasfromTaskList;
void MoveWidgetByIterator(TWidgetArr::iterator widget, vec2 shift);
TWidgetArr::iterator FindWidgetInArr(const std::string& widgetName);
vec2 LastTapPos;
vec2 TotalShift;
boost::mutex WidgetListMutex;
public:
boost::signal<void(int)> KeyPressedSignal;
boost::signal<void()> PostUpdateSignal;
~TGUIManager();
void AddWidget(std::shared_ptr<TInstancingWidgetAncestor> widgetAncestor, const std::string& name, const std::string& groupName, int order = 0);
void DeleteWidget(std::string name);
void DeleteWidgetGroup(std::string groupName);
void DeleteWidgetOnUpdate(const std::string& name);
void DeleteWidgetGroupOnUpdate(const std::string& groupName);
void Update(cardinal dt);
void Draw();
void MoveWidget(const std::string& widgetName, vec2 shift);
void MoveWidgetGroup(const std::string& widgetGroupName, const std::string& exceptWidget, vec2 shift);
void AddWidgetTransformTask(TWidgetTransformTask widgetTransformTask);
void OnMouseDown(vec2 pos);
void OnMouseUp(vec2 pos);
void OnMove(vec2 shift);
void PrintWidgetList();
std::shared_ptr<boost::signal<void (TSignalParam)>> GetOnClickSignal(const std::string& widgetName);
std::shared_ptr<boost::signal<void (TSignalParam)>> GetOnHoldSignal(const std::string& widgetName);
std::shared_ptr<boost::signal<void (TSignalParam)>> GetSignal(const std::string& signalName, const std::string& widgetName);
//TFunctionBinderInterface implementation:
void SQ_MoveWidget(const SQChar *widgetName, float x, float y);
virtual void BindFunctions();
};
} //namespace SE
#endif
+36
View File
@@ -0,0 +1,36 @@
// This file contains templates for widgets
// This file must be included somewhere in HalibutEngine.h just after ResourceManager is declared
namespace SE
{
template <typename TYPENAME>
void TRadioButton::SmartValueFiller(const std::string& dictionaryName, const std::string& smartValueName, TYPENAME value, TRadioButton* radioButtonToFill)
{
radioButtonToFill->SetChecked(ResourceManager->SmartValueManager.GetImmediateValue<TYPENAME>(dictionaryName, smartValueName) == value);
radioButtonToFill->OnSetChecked.connect
(
[dictionaryName, smartValueName, value](bool checked)
{
if (checked)
{
if (ResourceManager->SmartValueManager.GetImmediateValue<TYPENAME>(dictionaryName, smartValueName) != value)
{
ResourceManager->SmartValueManager.SetImmediateValue<TYPENAME>(dictionaryName, smartValueName, value);
}
}
}
);
radioButtonToFill->SetCheckedSlotConnection = ResourceManager->SmartValueManager.GetSignal<TYPENAME>(dictionaryName, smartValueName).connect
(
[radioButtonToFill, value](const TYPENAME& newValue)
{
radioButtonToFill->SetChecked(value == newValue);
}
);
}
} //namespace SE
+55
View File
@@ -0,0 +1,55 @@
#ifndef WIDGET_XML_PARSERS_H_INCLUDED
#define WIDGET_XML_PARSERS_H_INCLUDED
#include "ButtonWidget.h"
namespace SE
{
struct TStaticWidgetParser : public TSerializeInterface
{
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TDynamicTextWidgetParser : public TSerializeInterface
{
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TButtonWidgetParser : public TSerializeInterface
{
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TEditWidgetParser : public TSerializeInterface
{
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TCheckBoxWidgetParser : public TSerializeInterface
{
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TRadioButtonWidgetParser : public TSerializeInterface
{
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TWidgetParser : public TSerializeInterface
{
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
struct TWidgetListParser : public TSerializeInterface
{
virtual void Serialize(boost::property_tree::ptree& propertyTree);
};
} //namespace SE
#endif