2016-03-04 23:03:47 +00:00
|
|
|
#include "logvisor/logvisor.hpp"
|
|
|
|
#include "specter/Button.hpp"
|
|
|
|
#include "specter/ViewResources.hpp"
|
|
|
|
#include "specter/RootView.hpp"
|
2015-12-05 00:42:46 +00:00
|
|
|
|
2016-03-04 23:03:47 +00:00
|
|
|
namespace specter
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
static logvisor::Module Log("specter::Button");
|
2015-12-05 00:42:46 +00:00
|
|
|
|
2016-01-10 06:40:23 +00:00
|
|
|
void Button::Resources::init(boo::IGraphicsDataFactory* factory, const IThemeData& theme)
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-12-06 01:24:51 +00:00
|
|
|
Button::Button(ViewResources& res, View& parentView,
|
2016-01-18 23:32:16 +00:00
|
|
|
IButtonBinding* controlBinding, const std::string& text, Icon* icon,
|
2016-03-04 23:03:47 +00:00
|
|
|
Style style, const zeus::CColor& bgColor, RectangleConstraint constraint)
|
2016-01-18 23:32:16 +00:00
|
|
|
: Button(res, parentView, controlBinding, text, res.themeData().uiText(), icon, style, bgColor, constraint) {}
|
2015-12-13 21:00:30 +00:00
|
|
|
|
|
|
|
Button::Button(ViewResources& res, View& parentView,
|
2016-03-04 23:03:47 +00:00
|
|
|
IButtonBinding* controlBinding, const std::string& text, const zeus::CColor& textColor,
|
|
|
|
Icon* icon, Style style, const zeus::CColor& bgColor, RectangleConstraint constraint)
|
2015-12-22 01:33:27 +00:00
|
|
|
: Control(res, parentView, controlBinding),
|
2016-01-18 23:32:16 +00:00
|
|
|
m_style(style), m_textColor(textColor), m_bgColor(bgColor), m_textStr(text), m_constraint(constraint)
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
m_vertsBinding.initSolid(res, 40, m_viewVertBlockBuf);
|
2015-12-05 00:42:46 +00:00
|
|
|
commitResources(res);
|
2015-12-09 01:00:37 +00:00
|
|
|
|
2016-01-13 01:31:50 +00:00
|
|
|
m_buttonTarget.m_view.reset(new ButtonTarget(res, *this));
|
|
|
|
m_menuTarget.m_view.reset(new MenuTarget(res, *this));
|
|
|
|
|
2015-12-13 21:00:30 +00:00
|
|
|
if (style == Style::Block)
|
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor c1 = res.themeData().button1Inactive() * bgColor;
|
|
|
|
zeus::CColor c2 = res.themeData().button2Inactive() * bgColor;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_verts[0].m_color = c1;
|
|
|
|
m_verts[1].m_color = c2;
|
|
|
|
m_verts[2].m_color = c1;
|
|
|
|
m_verts[3].m_color = c2;
|
|
|
|
m_verts[4].m_color = c2;
|
2015-12-13 21:00:30 +00:00
|
|
|
for (int i=5 ; i<28 ; ++i)
|
2016-01-18 23:32:16 +00:00
|
|
|
m_verts[i].m_color = c2;
|
|
|
|
m_verts[31].m_color = c1;
|
|
|
|
m_verts[32].m_color = c2;
|
|
|
|
m_verts[33].m_color = c1;
|
|
|
|
m_verts[34].m_color = c2;
|
2016-01-15 23:32:14 +00:00
|
|
|
for (int i=35 ; i<39 ; ++i)
|
2016-01-18 23:32:16 +00:00
|
|
|
m_verts[i].m_color = c2;
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<4 ; ++i)
|
2016-03-04 23:03:47 +00:00
|
|
|
m_verts[i].m_color = zeus::CColor::skClear;
|
2016-01-13 01:31:50 +00:00
|
|
|
for (int i=31 ; i<35 ; ++i)
|
2016-03-04 23:03:47 +00:00
|
|
|
m_verts[i].m_color = zeus::CColor::skClear;
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
2016-01-13 01:31:50 +00:00
|
|
|
for (int i=28 ; i<31 ; ++i)
|
|
|
|
m_verts[i].m_color = m_textColor;
|
|
|
|
m_vertsBinding.load(m_verts, sizeof(m_verts));
|
|
|
|
|
|
|
|
if (controlBinding)
|
|
|
|
m_menuStyle = controlBinding->menuStyle(this);
|
2015-12-13 21:00:30 +00:00
|
|
|
|
2016-01-18 23:32:16 +00:00
|
|
|
if (icon)
|
|
|
|
m_icon.reset(new IconView(res, *this, *icon));
|
|
|
|
|
2015-12-22 01:33:27 +00:00
|
|
|
m_text.reset(new TextView(res, *this, res.m_mainFont, TextView::Alignment::Center));
|
2015-12-09 01:00:37 +00:00
|
|
|
setText(m_textStr);
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 23:32:16 +00:00
|
|
|
void Button::setText(const std::string& text)
|
2015-12-13 21:00:30 +00:00
|
|
|
{
|
|
|
|
setText(text, m_textColor);
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:03:47 +00:00
|
|
|
void Button::setText(const std::string& text, const zeus::CColor& textColor)
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
|
|
|
m_textStr = text;
|
2015-12-13 21:00:30 +00:00
|
|
|
m_textColor = textColor;
|
2015-12-05 00:42:46 +00:00
|
|
|
|
2015-12-13 21:00:30 +00:00
|
|
|
m_text->typesetGlyphs(text, textColor);
|
2015-12-08 01:44:46 +00:00
|
|
|
float pf = rootView().viewRes().pixelFactor();
|
2016-01-13 01:31:50 +00:00
|
|
|
int width, height;
|
2015-12-13 21:00:30 +00:00
|
|
|
|
|
|
|
if (m_style == Style::Block)
|
|
|
|
{
|
2016-01-18 23:32:16 +00:00
|
|
|
m_textWidth = m_text->nominalWidth();
|
|
|
|
int nomWidth = m_textWidth + 12*pf;
|
|
|
|
if (m_icon)
|
|
|
|
nomWidth += 18*pf;
|
|
|
|
std::pair<int,int> constraint = m_constraint.solve(nomWidth, 20 * pf);
|
2015-12-22 01:33:27 +00:00
|
|
|
width = constraint.first;
|
|
|
|
height = constraint.second;
|
2015-12-13 21:00:30 +00:00
|
|
|
m_verts[0].m_pos.assign(1, height+1, 0);
|
|
|
|
m_verts[1].m_pos.assign(1, 1, 0);
|
|
|
|
m_verts[2].m_pos.assign(width+1, height+1, 0);
|
|
|
|
m_verts[3].m_pos.assign(width+1, 1, 0);
|
|
|
|
m_verts[4].m_pos.assign(width+1, 1, 0);
|
|
|
|
|
2016-01-18 23:32:16 +00:00
|
|
|
m_textIconWidth = width;
|
2016-01-18 00:37:13 +00:00
|
|
|
if (m_menuStyle == IButtonBinding::MenuStyle::Primary)
|
|
|
|
width += 12*pf;
|
|
|
|
else if (m_menuStyle == IButtonBinding::MenuStyle::Auxiliary)
|
2016-01-15 23:32:14 +00:00
|
|
|
width += 16*pf;
|
|
|
|
|
2015-12-13 21:00:30 +00:00
|
|
|
m_verts[5].m_pos.assign(1, height+1, 0);
|
|
|
|
m_verts[6].m_pos.assign(1, height+1, 0);
|
|
|
|
m_verts[7].m_pos.assign(0, height+1, 0);
|
|
|
|
m_verts[8].m_pos.assign(1, 1, 0);
|
|
|
|
m_verts[9].m_pos.assign(0, 1, 0);
|
|
|
|
m_verts[10].m_pos.assign(0, 1, 0);
|
|
|
|
|
|
|
|
m_verts[11].m_pos.assign(width+2, height+1, 0);
|
|
|
|
m_verts[12].m_pos.assign(width+2, height+1, 0);
|
|
|
|
m_verts[13].m_pos.assign(width+1, height+1, 0);
|
|
|
|
m_verts[14].m_pos.assign(width+2, 1, 0);
|
|
|
|
m_verts[15].m_pos.assign(width+1, 1, 0);
|
|
|
|
m_verts[16].m_pos.assign(width+1, 1, 0);
|
|
|
|
|
|
|
|
m_verts[17].m_pos.assign(1, height+2, 0);
|
|
|
|
m_verts[18].m_pos.assign(1, height+2, 0);
|
|
|
|
m_verts[19].m_pos.assign(1, height+1, 0);
|
|
|
|
m_verts[20].m_pos.assign(width+1, height+2, 0);
|
|
|
|
m_verts[21].m_pos.assign(width+1, height+1, 0);
|
|
|
|
m_verts[22].m_pos.assign(width+1, height+1, 0);
|
|
|
|
|
|
|
|
m_verts[23].m_pos.assign(1, 1, 0);
|
|
|
|
m_verts[24].m_pos.assign(1, 1, 0);
|
|
|
|
m_verts[25].m_pos.assign(1, 0, 0);
|
|
|
|
m_verts[26].m_pos.assign(width+1, 1, 0);
|
|
|
|
m_verts[27].m_pos.assign(width+1, 0, 0);
|
|
|
|
|
2016-01-18 23:32:16 +00:00
|
|
|
int arrowX = m_textIconWidth + 5*pf;
|
2016-01-15 23:32:14 +00:00
|
|
|
int arrowY = 7*pf;
|
2016-01-18 23:32:16 +00:00
|
|
|
int menuBgX = m_textIconWidth;
|
2016-01-18 00:37:13 +00:00
|
|
|
if (m_menuStyle == IButtonBinding::MenuStyle::Primary)
|
|
|
|
{
|
|
|
|
menuBgX = 0;
|
|
|
|
arrowX -= 5*pf;
|
|
|
|
}
|
|
|
|
|
2016-01-15 23:32:14 +00:00
|
|
|
m_verts[28].m_pos.assign(arrowX + 4*pf, arrowY + 1*pf, 0);
|
|
|
|
m_verts[29].m_pos.assign(arrowX, arrowY + 5*pf, 0);
|
|
|
|
m_verts[30].m_pos.assign(arrowX + 8*pf, arrowY + 5*pf, 0);
|
|
|
|
|
2016-01-18 00:37:13 +00:00
|
|
|
m_verts[31].m_pos.assign(menuBgX+1, height+1, 0);
|
|
|
|
m_verts[32].m_pos.assign(menuBgX+1, 1, 0);
|
2016-01-15 23:32:14 +00:00
|
|
|
m_verts[33].m_pos.assign(width+1, height+1, 0);
|
|
|
|
m_verts[34].m_pos.assign(width+1, 1, 0);
|
|
|
|
|
2016-01-18 23:32:16 +00:00
|
|
|
m_verts[35].m_pos.assign(m_textIconWidth, height+1, 0);
|
|
|
|
m_verts[36].m_pos.assign(m_textIconWidth, 1, 0);
|
|
|
|
m_verts[37].m_pos.assign(m_textIconWidth+1, height+1, 0);
|
|
|
|
m_verts[38].m_pos.assign(m_textIconWidth+1, 1, 0);
|
2016-01-13 01:31:50 +00:00
|
|
|
|
|
|
|
m_vertsBinding.load(m_verts, sizeof(m_verts));
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = m_text->nominalWidth();
|
|
|
|
height = 10 * pf;
|
|
|
|
m_verts[0].m_pos.assign(1*pf, -1*pf, 0);
|
|
|
|
m_verts[1].m_pos.assign(1*pf, -2*pf, 0);
|
|
|
|
m_verts[2].m_pos.assign(width, -1*pf, 0);
|
|
|
|
m_verts[3].m_pos.assign(width, -2*pf, 0);
|
|
|
|
|
2016-01-13 01:31:50 +00:00
|
|
|
int arrowX = width + 5*pf;
|
|
|
|
m_verts[28].m_pos.assign(arrowX + 4*pf, 1*pf, 0);
|
|
|
|
m_verts[29].m_pos.assign(arrowX, 5*pf, 0);
|
|
|
|
m_verts[30].m_pos.assign(arrowX + 8*pf, 5*pf, 0);
|
|
|
|
|
|
|
|
m_textWidth = width;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_textIconWidth = width;
|
2016-01-13 01:31:50 +00:00
|
|
|
|
|
|
|
int arrowLineWidth = 7*pf;
|
|
|
|
if (m_menuStyle != IButtonBinding::MenuStyle::None)
|
|
|
|
{
|
|
|
|
width += 13*pf;
|
|
|
|
if (m_menuStyle == IButtonBinding::MenuStyle::Primary)
|
|
|
|
{
|
|
|
|
arrowLineWidth = width;
|
|
|
|
arrowX = 1*pf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_verts[31].m_pos.assign(arrowX, -1*pf, 0);
|
|
|
|
m_verts[32].m_pos.assign(arrowX, -2*pf, 0);
|
|
|
|
m_verts[33].m_pos.assign(arrowX + arrowLineWidth, -1*pf, 0);
|
|
|
|
m_verts[34].m_pos.assign(arrowX + arrowLineWidth, -2*pf, 0);
|
|
|
|
|
|
|
|
m_vertsBinding.load(m_verts, sizeof(m_verts));
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_nomWidth = width;
|
2015-12-05 00:42:46 +00:00
|
|
|
m_nomHeight = height;
|
|
|
|
}
|
|
|
|
|
2016-01-18 23:32:16 +00:00
|
|
|
void Button::setIcon(Icon* icon)
|
|
|
|
{
|
|
|
|
if (icon)
|
|
|
|
m_icon.reset(new IconView(rootView().viewRes(), *this, *icon));
|
|
|
|
else
|
|
|
|
m_icon.reset();
|
|
|
|
setText(m_textStr);
|
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
|
2016-03-04 23:03:47 +00:00
|
|
|
void Button::colorGlyphs(const zeus::CColor& newColor)
|
2015-12-13 21:00:30 +00:00
|
|
|
{
|
|
|
|
m_textColor = newColor;
|
|
|
|
m_text->colorGlyphs(newColor);
|
2016-01-16 03:57:11 +00:00
|
|
|
for (int i=28 ; i<31 ; ++i)
|
|
|
|
m_verts[i].m_color = newColor;
|
|
|
|
m_vertsBinding.load(m_verts, sizeof(m_verts));
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 01:31:50 +00:00
|
|
|
void Button::ButtonTarget::setInactive()
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_button.m_style == Style::Block)
|
2015-12-13 21:00:30 +00:00
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor c1 = rootView().themeData().button1Inactive() * m_button.m_bgColor;
|
|
|
|
zeus::CColor c2 = rootView().themeData().button2Inactive() * m_button.m_bgColor;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_button.m_verts[0].m_color = c1;
|
|
|
|
m_button.m_verts[1].m_color = c2;
|
|
|
|
m_button.m_verts[2].m_color = c1;
|
|
|
|
m_button.m_verts[3].m_color = c2;
|
|
|
|
m_button.m_verts[4].m_color = c2;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<4 ; ++i)
|
2016-03-04 23:03:47 +00:00
|
|
|
m_button.m_verts[i].m_color = zeus::CColor::skClear;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
m_button.m_text->colorGlyphs(m_button.m_textColor);
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 01:31:50 +00:00
|
|
|
void Button::MenuTarget::setInactive()
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_button.m_style == Style::Block)
|
2015-12-13 21:00:30 +00:00
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor c1 = rootView().themeData().button1Inactive() * m_button.m_bgColor;
|
|
|
|
zeus::CColor c2 = rootView().themeData().button2Inactive() * m_button.m_bgColor;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_button.m_verts[31].m_color = c1;
|
|
|
|
m_button.m_verts[32].m_color = c2;
|
|
|
|
m_button.m_verts[33].m_color = c1;
|
|
|
|
m_button.m_verts[34].m_color = c2;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i=28 ; i<31 ; ++i)
|
|
|
|
m_button.m_verts[i].m_color = m_button.m_textColor;
|
|
|
|
for (int i=31 ; i<35 ; ++i)
|
2016-03-04 23:03:47 +00:00
|
|
|
m_button.m_verts[i].m_color = zeus::CColor::skClear;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::ButtonTarget::setHover()
|
|
|
|
{
|
|
|
|
if (m_button.m_style == Style::Block)
|
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor c1 = rootView().themeData().button1Hover() * m_button.m_bgColor;
|
|
|
|
zeus::CColor c2 = rootView().themeData().button2Hover() * m_button.m_bgColor;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_button.m_verts[0].m_color = c1;
|
|
|
|
m_button.m_verts[1].m_color = c2;
|
|
|
|
m_button.m_verts[2].m_color = c1;
|
|
|
|
m_button.m_verts[3].m_color = c2;
|
|
|
|
m_button.m_verts[4].m_color = c2;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<4 ; ++i)
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_verts[i].m_color = m_button.m_textColor;
|
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
m_button.m_text->colorGlyphs(m_button.m_textColor);
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 01:31:50 +00:00
|
|
|
void Button::MenuTarget::setHover()
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_button.m_style == Style::Block)
|
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor c1 = rootView().themeData().button1Hover() * m_button.m_bgColor;
|
|
|
|
zeus::CColor c2 = rootView().themeData().button2Hover() * m_button.m_bgColor;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_button.m_verts[31].m_color = c1;
|
|
|
|
m_button.m_verts[32].m_color = c2;
|
|
|
|
m_button.m_verts[33].m_color = c1;
|
|
|
|
m_button.m_verts[34].m_color = c2;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i=28 ; i<31 ; ++i)
|
|
|
|
m_button.m_verts[i].m_color = m_button.m_textColor;
|
|
|
|
for (int i=31 ; i<35 ; ++i)
|
|
|
|
m_button.m_verts[i].m_color = m_button.m_textColor;
|
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::ButtonTarget::setPressed()
|
|
|
|
{
|
|
|
|
if (m_button.m_style == Style::Block)
|
2015-12-13 21:00:30 +00:00
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor c1 = rootView().themeData().button1Press() * m_button.m_bgColor;
|
|
|
|
zeus::CColor c2 = rootView().themeData().button2Press() * m_button.m_bgColor;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_button.m_verts[0].m_color = c1;
|
|
|
|
m_button.m_verts[1].m_color = c2;
|
|
|
|
m_button.m_verts[2].m_color = c1;
|
|
|
|
m_button.m_verts[3].m_color = c2;
|
|
|
|
m_button.m_verts[4].m_color = c2;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<4 ; ++i)
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_verts[i].m_color = m_button.m_textColor;
|
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
m_button.m_text->colorGlyphs(m_button.m_textColor);
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-13 01:31:50 +00:00
|
|
|
void Button::MenuTarget::setPressed()
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_button.m_style == Style::Block)
|
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor c1 = rootView().themeData().button1Press() * m_button.m_bgColor;
|
|
|
|
zeus::CColor c2 = rootView().themeData().button2Press() * m_button.m_bgColor;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_button.m_verts[31].m_color = c1;
|
|
|
|
m_button.m_verts[32].m_color = c2;
|
|
|
|
m_button.m_verts[33].m_color = c1;
|
|
|
|
m_button.m_verts[34].m_color = c2;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
}
|
|
|
|
else
|
2015-12-13 21:00:30 +00:00
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
for (int i=28 ; i<31 ; ++i)
|
|
|
|
m_button.m_verts[i].m_color = m_button.m_textColor;
|
|
|
|
for (int i=31 ; i<35 ; ++i)
|
|
|
|
m_button.m_verts[i].m_color = m_button.m_textColor;
|
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::ButtonTarget::setDisabled()
|
|
|
|
{
|
|
|
|
if (m_button.m_style == Style::Block)
|
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor c1 = rootView().themeData().button1Disabled() * m_button.m_bgColor;
|
|
|
|
zeus::CColor c2 = rootView().themeData().button2Disabled() * m_button.m_bgColor;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_button.m_verts[0].m_color = c1;
|
|
|
|
m_button.m_verts[1].m_color = c2;
|
|
|
|
m_button.m_verts[2].m_color = c1;
|
|
|
|
m_button.m_verts[3].m_color = c2;
|
|
|
|
m_button.m_verts[4].m_color = c2;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i=0 ; i<4 ; ++i)
|
2016-03-04 23:03:47 +00:00
|
|
|
m_button.m_verts[i].m_color = zeus::CColor::skClear;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor dimText = m_button.m_textColor;
|
2015-12-13 21:00:30 +00:00
|
|
|
dimText[3] *= 0.5;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_text->colorGlyphs(dimText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::MenuTarget::setDisabled()
|
|
|
|
{
|
|
|
|
if (m_button.m_style == Style::Block)
|
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor c1 = rootView().themeData().button1Disabled() * m_button.m_bgColor;
|
|
|
|
zeus::CColor c2 = rootView().themeData().button2Disabled() * m_button.m_bgColor;
|
2016-01-18 23:32:16 +00:00
|
|
|
m_button.m_verts[31].m_color = c1;
|
|
|
|
m_button.m_verts[32].m_color = c2;
|
|
|
|
m_button.m_verts[33].m_color = c1;
|
|
|
|
m_button.m_verts[34].m_color = c2;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
zeus::CColor dimText = m_button.m_textColor;
|
2016-01-13 01:31:50 +00:00
|
|
|
dimText[3] *= 0.5;
|
|
|
|
for (int i=28 ; i<31 ; ++i)
|
|
|
|
m_button.m_verts[i].m_color = dimText;
|
|
|
|
for (int i=31 ; i<35 ; ++i)
|
2016-03-04 23:03:47 +00:00
|
|
|
m_button.m_verts[i].m_color = zeus::CColor::skClear;
|
2016-01-13 01:31:50 +00:00
|
|
|
m_button.m_vertsBinding.load(m_button.m_verts, sizeof(m_button.m_verts));
|
2015-12-13 21:00:30 +00:00
|
|
|
}
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Button::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_menuStyle != IButtonBinding::MenuStyle::Primary)
|
|
|
|
m_buttonTarget.mouseDown(coord, button, mod);
|
|
|
|
m_menuTarget.mouseDown(coord, button, mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::ButtonTarget::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
|
|
|
{
|
|
|
|
m_pressed = true;
|
|
|
|
setPressed();
|
|
|
|
if (m_button.m_controlBinding)
|
|
|
|
static_cast<IButtonBinding&>(*m_button.m_controlBinding).down(&m_button, coord);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::MenuTarget::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
|
|
|
{
|
2015-12-05 00:42:46 +00:00
|
|
|
m_pressed = true;
|
|
|
|
setPressed();
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_hovered)
|
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
Log.report(logvisor::Info, "button menu '%s' activated", m_button.m_textStr.c_str());
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_button.m_controlBinding)
|
|
|
|
{
|
|
|
|
m_button.m_modalMenu.m_view = static_cast<IButtonBinding&>(*m_button.m_controlBinding).buildMenu(&m_button);
|
2016-01-15 23:32:14 +00:00
|
|
|
rootView().setActiveMenuButton(&m_button);
|
|
|
|
m_button.updateSize();
|
2016-01-13 01:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Button::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_menuStyle != IButtonBinding::MenuStyle::Primary)
|
|
|
|
m_buttonTarget.mouseUp(coord, button, mod);
|
|
|
|
m_menuTarget.mouseUp(coord, button, mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::ButtonTarget::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
|
|
|
{
|
2016-01-07 00:39:18 +00:00
|
|
|
if (m_pressed)
|
2015-12-08 04:26:29 +00:00
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_button.m_controlBinding)
|
|
|
|
static_cast<IButtonBinding&>(*m_button.m_controlBinding).up(&m_button, coord);
|
2016-01-07 00:39:18 +00:00
|
|
|
if (m_hovered)
|
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
Log.report(logvisor::Info, "button '%s' activated", m_button.m_textStr.c_str());
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_button.m_controlBinding)
|
|
|
|
static_cast<IButtonBinding&>(*m_button.m_controlBinding).activated(&m_button, coord);
|
2016-01-07 00:39:18 +00:00
|
|
|
}
|
|
|
|
m_pressed = false;
|
2015-12-08 04:26:29 +00:00
|
|
|
}
|
2015-12-05 00:42:46 +00:00
|
|
|
if (m_hovered)
|
|
|
|
setHover();
|
|
|
|
else
|
|
|
|
setInactive();
|
|
|
|
}
|
|
|
|
|
2016-01-13 01:31:50 +00:00
|
|
|
void Button::MenuTarget::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
|
|
|
{
|
|
|
|
m_pressed = false;
|
|
|
|
if (m_hovered)
|
|
|
|
setHover();
|
|
|
|
else
|
|
|
|
setInactive();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::mouseMove(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
if (m_menuStyle != IButtonBinding::MenuStyle::Primary)
|
|
|
|
m_buttonTarget.mouseMove(coord);
|
|
|
|
m_menuTarget.mouseMove(coord);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::ButtonTarget::mouseEnter(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
m_hovered = true;
|
|
|
|
if (m_pressed)
|
|
|
|
setPressed();
|
|
|
|
else
|
|
|
|
setHover();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::MenuTarget::mouseEnter(const boo::SWindowCoord& coord)
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
|
|
|
m_hovered = true;
|
|
|
|
if (m_pressed)
|
|
|
|
setPressed();
|
|
|
|
else
|
|
|
|
setHover();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::mouseLeave(const boo::SWindowCoord& coord)
|
|
|
|
{
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_menuStyle != IButtonBinding::MenuStyle::Primary)
|
|
|
|
m_buttonTarget.mouseLeave(coord);
|
|
|
|
m_menuTarget.mouseLeave(coord);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::ButtonTarget::mouseLeave(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
m_hovered = false;
|
|
|
|
setInactive();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::MenuTarget::mouseLeave(const boo::SWindowCoord& coord)
|
|
|
|
{
|
2015-12-05 00:42:46 +00:00
|
|
|
m_hovered = false;
|
|
|
|
setInactive();
|
|
|
|
}
|
|
|
|
|
2016-01-15 23:32:14 +00:00
|
|
|
void Button::closeMenu(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
rootView().unsetActiveMenuButton(this);
|
|
|
|
m_modalMenu.m_view.reset();
|
|
|
|
m_menuTarget.mouseMove(coord);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Button::think()
|
|
|
|
{
|
|
|
|
if (m_modalMenu.m_view)
|
|
|
|
m_modalMenu.m_view->think();
|
|
|
|
}
|
|
|
|
|
2015-12-05 00:42:46 +00:00
|
|
|
void Button::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
|
|
|
|
{
|
|
|
|
View::resized(root, sub);
|
|
|
|
boo::SWindowRect textRect = sub;
|
2015-12-13 21:00:30 +00:00
|
|
|
float pf = rootView().viewRes().pixelFactor();
|
2016-01-18 23:32:16 +00:00
|
|
|
|
|
|
|
if (m_icon)
|
|
|
|
{
|
|
|
|
textRect.location[0] += 18*pf;
|
|
|
|
boo::SWindowRect iconRect = sub;
|
|
|
|
iconRect.size[0] = 16*pf;
|
|
|
|
iconRect.size[1] = 16*pf;
|
|
|
|
iconRect.location[1] += 2*pf;
|
|
|
|
if (m_style == Style::Block)
|
|
|
|
{
|
|
|
|
iconRect.location[0] += 5*pf;
|
|
|
|
iconRect.location[1] += pf;
|
|
|
|
}
|
|
|
|
m_icon->resized(root, iconRect);
|
|
|
|
}
|
|
|
|
|
2015-12-13 21:00:30 +00:00
|
|
|
if (m_style == Style::Block)
|
2016-01-18 23:32:16 +00:00
|
|
|
{
|
|
|
|
textRect.location[0] += 6*pf;
|
|
|
|
textRect.location[1] += 7*pf;
|
|
|
|
}
|
2016-01-13 01:31:50 +00:00
|
|
|
textRect.location[0] += m_textWidth / 2;
|
|
|
|
textRect.size[0] = m_textWidth;
|
2016-01-02 02:26:04 +00:00
|
|
|
textRect.size[1] = m_nomHeight;
|
2015-12-05 00:42:46 +00:00
|
|
|
m_text->resized(root, textRect);
|
2016-01-13 01:31:50 +00:00
|
|
|
|
|
|
|
if (m_style == Style::Block)
|
|
|
|
{
|
2016-01-15 23:32:14 +00:00
|
|
|
if (m_menuStyle == IButtonBinding::MenuStyle::None)
|
|
|
|
{
|
|
|
|
m_buttonTarget.m_view->resized(root, sub);
|
|
|
|
}
|
|
|
|
else if (m_menuStyle == IButtonBinding::MenuStyle::Primary)
|
|
|
|
{
|
|
|
|
m_menuTarget.m_view->resized(root, sub);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boo::SWindowRect targetRect = sub;
|
2016-01-18 23:32:16 +00:00
|
|
|
targetRect.size[0] = m_textIconWidth;
|
2016-01-15 23:32:14 +00:00
|
|
|
m_buttonTarget.m_view->resized(root, targetRect);
|
|
|
|
targetRect.location[0] += targetRect.size[0];
|
|
|
|
targetRect.size[0] = 16*pf;
|
|
|
|
m_menuTarget.m_view->resized(root, targetRect);
|
|
|
|
}
|
2016-01-13 01:31:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_menuStyle == IButtonBinding::MenuStyle::Primary)
|
|
|
|
{
|
|
|
|
boo::SWindowRect targetRect = sub;
|
|
|
|
targetRect.size[0] = m_nomWidth;
|
|
|
|
targetRect.size[1] = m_nomHeight;
|
|
|
|
m_menuTarget.m_view->resized(root, targetRect);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
boo::SWindowRect targetRect = sub;
|
2016-01-18 23:32:16 +00:00
|
|
|
targetRect.size[0] = m_textIconWidth + 3*pf;
|
2016-01-13 01:31:50 +00:00
|
|
|
targetRect.size[1] = m_nomHeight;
|
|
|
|
m_buttonTarget.m_view->resized(root, targetRect);
|
|
|
|
targetRect.location[0] += targetRect.size[0];
|
|
|
|
targetRect.size[0] = 15*pf;
|
|
|
|
m_menuTarget.m_view->resized(root, targetRect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_modalMenu.m_view)
|
2016-01-15 23:32:14 +00:00
|
|
|
{
|
|
|
|
boo::SWindowRect menuRect = sub;
|
|
|
|
if (m_style == Style::Text)
|
|
|
|
menuRect.location[1] -= 6*pf;
|
|
|
|
m_modalMenu.m_view->resized(root, menuRect);
|
|
|
|
}
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Button::draw(boo::IGraphicsCommandQueue* gfxQ)
|
|
|
|
{
|
|
|
|
View::draw(gfxQ);
|
2016-01-08 00:06:21 +00:00
|
|
|
gfxQ->setShaderDataBinding(m_vertsBinding);
|
2015-12-13 21:00:30 +00:00
|
|
|
if (m_style == Style::Block)
|
2016-01-15 23:32:14 +00:00
|
|
|
{
|
2015-12-13 21:00:30 +00:00
|
|
|
gfxQ->draw(0, 28);
|
2016-01-15 23:32:14 +00:00
|
|
|
if (m_menuStyle != IButtonBinding::MenuStyle::None)
|
|
|
|
{
|
|
|
|
gfxQ->draw(31, 4);
|
|
|
|
gfxQ->draw(28, 3);
|
2016-01-18 00:37:13 +00:00
|
|
|
if (m_menuStyle == IButtonBinding::MenuStyle::Auxiliary)
|
|
|
|
gfxQ->draw(35, 4);
|
2016-01-15 23:32:14 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-13 21:00:30 +00:00
|
|
|
else
|
2016-01-13 01:31:50 +00:00
|
|
|
{
|
2015-12-13 21:00:30 +00:00
|
|
|
gfxQ->draw(0, 4);
|
2016-01-13 01:31:50 +00:00
|
|
|
if (m_menuStyle != IButtonBinding::MenuStyle::None)
|
|
|
|
{
|
|
|
|
gfxQ->draw(28, 3);
|
|
|
|
gfxQ->draw(31, 4);
|
|
|
|
}
|
|
|
|
}
|
2016-01-18 23:32:16 +00:00
|
|
|
|
|
|
|
if (m_icon)
|
|
|
|
m_icon->draw(gfxQ);
|
|
|
|
if (m_textStr.size())
|
|
|
|
m_text->draw(gfxQ);
|
2016-01-13 01:31:50 +00:00
|
|
|
|
|
|
|
if (m_modalMenu.m_view)
|
|
|
|
m_modalMenu.m_view->draw(gfxQ);
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|