metaforce/specter/include/Specter/Control.hpp

97 lines
3.0 KiB
C++
Raw Normal View History

2015-11-21 01:14:49 +00:00
#ifndef SPECTER_CONTROL_HPP
#define SPECTER_CONTROL_HPP
#include "View.hpp"
namespace Specter
{
class Control;
class Button;
struct IControlBinding
{
virtual const char* name(const Control* control) const=0;
virtual const char* help(const Control* control) const {return nullptr;}
};
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 */
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
{
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
{
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
{
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
};
struct CVarControlBinding : IControlBinding
{
HECL::CVar* m_cvar;
CVarControlBinding(HECL::CVar* cvar)
: m_cvar(cvar) {}
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();}
};
class Control : public View
{
protected:
IControlBinding* m_controlBinding = nullptr;
public:
Control(ViewResources& res, View& parentView, IControlBinding* controlBinding);
};
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-11-21 01:14:49 +00:00
#endif // SPECTER_CONTROL_HPP