2015-11-21 01:14:49 +00:00
|
|
|
#ifndef SPECTER_CONTROL_HPP
|
|
|
|
#define SPECTER_CONTROL_HPP
|
|
|
|
|
2015-12-06 01:24:51 +00:00
|
|
|
#include "View.hpp"
|
|
|
|
|
|
|
|
namespace Specter
|
|
|
|
{
|
2016-01-07 00:39:18 +00:00
|
|
|
class Control;
|
|
|
|
class Button;
|
2015-12-06 01:24:51 +00:00
|
|
|
|
|
|
|
struct IControlBinding
|
|
|
|
{
|
2016-01-07 00:39:18 +00:00
|
|
|
virtual const char* name(const Control* control) const=0;
|
|
|
|
virtual const char* help(const Control* control) const {return nullptr;}
|
2015-12-06 01:24:51 +00:00
|
|
|
};
|
|
|
|
|
2015-12-08 04:26:29 +00:00
|
|
|
struct IButtonBinding : IControlBinding
|
|
|
|
{
|
2015-12-14 04:56:02 +00:00
|
|
|
/** Pressed/Released while Hovering action,
|
|
|
|
* cancellable by holding the button and releasing outside */
|
2016-01-07 00:39:18 +00:00
|
|
|
virtual void activated(const Button* button, const boo::SWindowCoord& coord) {}
|
|
|
|
|
|
|
|
/** Pass-through down action */
|
|
|
|
virtual void down(const Button* button, const boo::SWindowCoord& coord) {}
|
|
|
|
|
|
|
|
/** Pass-through up action */
|
|
|
|
virtual void up(const Button* button, const boo::SWindowCoord& coord) {}
|
2016-01-13 01:31:50 +00:00
|
|
|
|
|
|
|
/** Optional style of menu to bind to button */
|
|
|
|
enum class MenuStyle
|
|
|
|
{
|
|
|
|
None, /**< No menu; normal button */
|
|
|
|
Primary, /**< Menu button replaces normal button */
|
|
|
|
Auxiliary /**< Menu button placed alongside normal button */
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Informs button which MenuStyle to present to user */
|
|
|
|
virtual MenuStyle menuStyle(const Specter::Button* button) const {return MenuStyle::None;}
|
|
|
|
|
|
|
|
/** Called when user requests menu, Button assumes modal ownership */
|
|
|
|
virtual std::unique_ptr<View> buildMenu(const Specter::Button* button) {return std::unique_ptr<View>();}
|
2015-12-08 04:26:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IFloatBinding : IControlBinding
|
|
|
|
{
|
2016-01-07 00:39:18 +00:00
|
|
|
virtual float getDefault(const Control* control) const {return 0.0;}
|
|
|
|
virtual std::pair<float,float> getBounds(const Control* control) const {return std::make_pair(FLT_MIN, FLT_MAX);}
|
|
|
|
virtual void changed(const Control* control, float val)=0;
|
2015-12-08 04:26:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct IIntBinding : IControlBinding
|
|
|
|
{
|
2016-01-07 00:39:18 +00:00
|
|
|
virtual int getDefault(const Control* control) const {return 0;}
|
|
|
|
virtual std::pair<int,int> getBounds(const Control* control) const {return std::make_pair(INT_MIN, INT_MAX);}
|
|
|
|
virtual void changed(const Control* control, int val)=0;
|
2015-12-08 04:26:29 +00:00
|
|
|
};
|
|
|
|
|
2015-12-18 03:26:10 +00:00
|
|
|
struct IStringBinding : IControlBinding
|
|
|
|
{
|
2016-01-07 00:39:18 +00:00
|
|
|
virtual std::string getDefault(const Control* control) const {return "";}
|
|
|
|
virtual void changed(const Control* control, const std::string& val)=0;
|
2015-12-18 03:26:10 +00:00
|
|
|
};
|
|
|
|
|
2015-12-06 01:24:51 +00:00
|
|
|
struct CVarControlBinding : IControlBinding
|
|
|
|
{
|
|
|
|
HECL::CVar* m_cvar;
|
|
|
|
CVarControlBinding(HECL::CVar* cvar)
|
|
|
|
: m_cvar(cvar) {}
|
2016-01-07 00:39:18 +00:00
|
|
|
const char* name(const Control* control) const {return m_cvar->name().c_str();}
|
|
|
|
const char* help(const Control* control) const {return m_cvar->rawHelp().c_str();}
|
2015-12-06 01:24:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Control : public View
|
|
|
|
{
|
|
|
|
protected:
|
2015-12-10 03:14:38 +00:00
|
|
|
IControlBinding* m_controlBinding = nullptr;
|
2015-12-06 01:24:51 +00:00
|
|
|
public:
|
2015-12-10 03:14:38 +00:00
|
|
|
Control(ViewResources& res, View& parentView, IControlBinding* controlBinding);
|
2015-12-06 01:24:51 +00:00
|
|
|
};
|
2015-12-27 22:42:45 +00:00
|
|
|
|
|
|
|
class ITextInputView : public Control, public boo::ITextInputCallback
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
static std::recursive_mutex m_textInputLk;
|
|
|
|
ITextInputView(ViewResources& res, View& parentView,
|
|
|
|
IControlBinding* controlBinding)
|
|
|
|
: Control(res, parentView, controlBinding) {}
|
2015-12-27 23:25:10 +00:00
|
|
|
public:
|
|
|
|
virtual void clipboardCopy() {}
|
|
|
|
virtual void clipboardCut() {}
|
|
|
|
virtual void clipboardPaste() {}
|
2015-12-27 22:42:45 +00:00
|
|
|
};
|
2015-12-06 01:24:51 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-21 01:14:49 +00:00
|
|
|
#endif // SPECTER_CONTROL_HPP
|