metaforce/specter/include/Specter/Button.hpp

122 lines
3.8 KiB
C++
Raw Normal View History

2015-11-21 01:14:49 +00:00
#ifndef SPECTER_BUTTON_HPP
#define SPECTER_BUTTON_HPP
2015-12-05 00:42:46 +00:00
#include "Specter/TextView.hpp"
#include "Specter/Control.hpp"
2015-12-05 00:42:46 +00:00
namespace Specter
{
class Button : public Control
2015-12-05 00:42:46 +00:00
{
2015-12-13 21:00:30 +00:00
public:
enum class Style
{
Block,
Text,
};
private:
Style m_style;
2016-01-13 01:31:50 +00:00
IButtonBinding::MenuStyle m_menuStyle = IButtonBinding::MenuStyle::None;
2015-12-13 21:00:30 +00:00
Zeus::CColor m_textColor;
2015-12-05 00:42:46 +00:00
std::string m_textStr;
std::unique_ptr<TextView> m_text;
2016-01-13 01:31:50 +00:00
SolidShaderVert m_verts[40];
VertexBufferBinding m_vertsBinding;
2015-12-05 00:42:46 +00:00
2015-12-22 01:33:27 +00:00
RectangleConstraint m_constraint;
2015-12-05 00:42:46 +00:00
int m_nomWidth, m_nomHeight;
2016-01-13 01:31:50 +00:00
int m_textWidth;
2015-12-05 00:42:46 +00:00
2016-01-13 01:31:50 +00:00
struct ButtonTarget : View
{
Button& m_button;
bool m_pressed = false;
bool m_hovered = false;
void setInactive();
void setHover();
void setPressed();
void setDisabled();
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseEnter(const boo::SWindowCoord&);
void mouseLeave(const boo::SWindowCoord&);
ButtonTarget(ViewResources& res, Button& button) : View(res, button), m_button(button) {}
};
ViewChild<std::unique_ptr<ButtonTarget>> m_buttonTarget;
struct MenuTarget : View
{
Button& m_button;
bool m_pressed = false;
bool m_hovered = false;
void setInactive();
void setHover();
void setPressed();
void setDisabled();
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseEnter(const boo::SWindowCoord&);
void mouseLeave(const boo::SWindowCoord&);
MenuTarget(ViewResources& res, Button& button) : View(res, button), m_button(button) {}
};
ViewChild<std::unique_ptr<MenuTarget>> m_menuTarget;
ViewChild<std::unique_ptr<View>> m_modalMenu;
2015-12-13 21:00:30 +00:00
2015-12-05 00:42:46 +00:00
public:
class Resources
{
friend class ViewResources;
friend class Button;
void init(boo::IGraphicsDataFactory* factory, const IThemeData& theme);
2015-12-05 00:42:46 +00:00
};
2016-01-15 23:32:14 +00:00
~Button() {closeMenu({});}
Button(ViewResources& res, View& parentView,
2015-12-13 21:00:30 +00:00
IButtonBinding* controlBinding, const std::string& text,
2015-12-22 01:33:27 +00:00
Style style=Style::Block, RectangleConstraint constraint=RectangleConstraint());
2015-12-13 21:00:30 +00:00
Button(ViewResources& res, View& parentView,
IButtonBinding* controlBinding, const std::string& text,
2015-12-22 01:33:27 +00:00
const Zeus::CColor& textColor, Style style=Style::Block,
RectangleConstraint constraint=RectangleConstraint());
2015-12-05 00:42:46 +00:00
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
2016-01-13 01:31:50 +00:00
void mouseMove(const boo::SWindowCoord&);
2015-12-05 00:42:46 +00:00
void mouseLeave(const boo::SWindowCoord&);
2016-01-15 23:32:14 +00:00
void think();
2015-12-22 01:33:27 +00:00
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
2015-12-05 00:42:46 +00:00
void draw(boo::IGraphicsCommandQueue* gfxQ);
2015-12-13 21:00:30 +00:00
void setText(const std::string& text, const Zeus::CColor& textColor);
2015-12-05 00:42:46 +00:00
void setText(const std::string& text);
const std::string& getText() const {return m_textStr;}
2015-12-13 21:00:30 +00:00
void colorGlyphs(const Zeus::CColor& newColor);
2015-12-05 00:42:46 +00:00
int nominalWidth() const {return m_nomWidth;}
int nominalHeight() const {return m_nomHeight;}
2016-01-15 23:32:14 +00:00
void closeMenu(const boo::SWindowCoord& coord);
ViewChild<std::unique_ptr<View>>& getMenu() {return m_modalMenu;}
void setMultiplyColor(const Zeus::CColor& color)
{
View::setMultiplyColor(color);
2015-12-17 21:28:37 +00:00
m_viewVertBlock.m_color = color;
m_viewVertBlockBuf->load(&m_viewVertBlock, sizeof(ViewBlock));
m_text->setMultiplyColor(color);
}
2015-12-05 00:42:46 +00:00
};
}
2015-11-21 01:14:49 +00:00
#endif // SPECTER_BUTTON_HPP