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"
|
2015-12-06 01:24:51 +00:00
|
|
|
#include "Specter/Control.hpp"
|
2016-01-18 23:32:16 +00:00
|
|
|
#include "Specter/Icon.hpp"
|
2015-12-05 00:42:46 +00:00
|
|
|
|
|
|
|
namespace Specter
|
|
|
|
{
|
|
|
|
|
2015-12-06 01:24:51 +00:00
|
|
|
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;
|
2016-01-18 23:32:16 +00:00
|
|
|
Zeus::CColor m_bgColor;
|
2015-12-05 00:42:46 +00:00
|
|
|
std::string m_textStr;
|
|
|
|
std::unique_ptr<TextView> m_text;
|
2016-01-18 23:32:16 +00:00
|
|
|
std::unique_ptr<IconView> m_icon;
|
2015-12-05 00:42:46 +00:00
|
|
|
|
2016-01-13 01:31:50 +00:00
|
|
|
SolidShaderVert m_verts[40];
|
2016-01-08 00:06:21 +00:00
|
|
|
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-18 23:32:16 +00:00
|
|
|
int m_textWidth, m_textIconWidth;
|
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;
|
|
|
|
|
2016-01-10 06:40:23 +00:00
|
|
|
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({});}
|
2015-12-06 01:24:51 +00:00
|
|
|
Button(ViewResources& res, View& parentView,
|
2016-01-18 23:32:16 +00:00
|
|
|
IButtonBinding* controlBinding, const std::string& text, Icon* icon=nullptr,
|
|
|
|
Style style=Style::Block, const Zeus::CColor& bgColor=Zeus::CColor::skWhite,
|
|
|
|
RectangleConstraint constraint=RectangleConstraint());
|
2015-12-13 21:00:30 +00:00
|
|
|
Button(ViewResources& res, View& parentView,
|
2016-01-18 00:37:13 +00:00
|
|
|
IButtonBinding* controlBinding, const std::string& text, const Zeus::CColor& textColor,
|
2016-01-18 23:32:16 +00:00
|
|
|
Icon* icon=nullptr, Style style=Style::Block, const Zeus::CColor& bgColor=Zeus::CColor::skWhite,
|
2015-12-22 01:33:27 +00:00
|
|
|
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);
|
2016-01-18 23:32:16 +00:00
|
|
|
void setIcon(Icon* icon=nullptr);
|
2015-12-15 21:53:15 +00:00
|
|
|
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;}
|
2015-12-15 21:53:15 +00:00
|
|
|
|
2016-01-15 23:32:14 +00:00
|
|
|
void closeMenu(const boo::SWindowCoord& coord);
|
|
|
|
ViewChild<std::unique_ptr<View>>& getMenu() {return m_modalMenu;}
|
|
|
|
|
2015-12-15 21:53:15 +00:00
|
|
|
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));
|
2015-12-15 21:53:15 +00:00
|
|
|
m_text->setMultiplyColor(color);
|
2016-01-18 23:32:16 +00:00
|
|
|
if (m_icon)
|
|
|
|
m_icon->setMultiplyColor(color);
|
2015-12-15 21:53:15 +00:00
|
|
|
}
|
2015-12-05 00:42:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-11-21 01:14:49 +00:00
|
|
|
#endif // SPECTER_BUTTON_HPP
|