2016-03-04 23:03:47 +00:00
|
|
|
#include "logvisor/logvisor.hpp"
|
|
|
|
#include "specter/Toolbar.hpp"
|
|
|
|
#include "specter/ViewResources.hpp"
|
|
|
|
#include "specter/RootView.hpp"
|
2015-12-03 03:26:50 +00:00
|
|
|
|
2015-12-05 00:42:46 +00:00
|
|
|
#define TOOLBAR_PADDING 10
|
2015-12-04 01:35:01 +00:00
|
|
|
|
2016-03-04 23:03:47 +00:00
|
|
|
namespace specter
|
2015-12-03 03:26:50 +00:00
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
static logvisor::Module Log("specter::Space");
|
2015-12-03 03:26:50 +00:00
|
|
|
|
2016-01-10 06:40:23 +00:00
|
|
|
void Toolbar::Resources::init(boo::IGraphicsDataFactory* factory, const IThemeData& theme)
|
2015-12-03 03:26:50 +00:00
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
static const zeus::RGBA32 tex[] =
|
2015-12-03 03:26:50 +00:00
|
|
|
{
|
2015-12-31 04:55:29 +00:00
|
|
|
{{255,255,255,64}},
|
|
|
|
{{255,255,255,64}},
|
|
|
|
{{0,0,0,64}},
|
|
|
|
{{0,0,0,64}}
|
2015-12-03 03:26:50 +00:00
|
|
|
};
|
2015-12-05 05:57:51 +00:00
|
|
|
m_shadingTex = factory->newStaticTexture(4, 1, 1, boo::TextureFormat::RGBA8, tex, 16);
|
2015-12-03 03:26:50 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 00:41:44 +00:00
|
|
|
Toolbar::Toolbar(ViewResources& res, View& parentView, Position tbPos, unsigned units)
|
|
|
|
: View(res, parentView), m_tbPos(tbPos), m_units(units),
|
|
|
|
m_nomGauge(res.pixelFactor() * SPECTER_TOOLBAR_GAUGE * units),
|
2015-12-05 00:42:46 +00:00
|
|
|
m_padding(res.pixelFactor() * TOOLBAR_PADDING)
|
2015-12-03 03:26:50 +00:00
|
|
|
{
|
2016-01-27 00:41:44 +00:00
|
|
|
m_children.reserve(units);
|
|
|
|
for (unsigned u=0 ; u<units ; ++u)
|
|
|
|
m_children.emplace_back();
|
2015-12-04 01:35:01 +00:00
|
|
|
m_tbBlockBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Uniform, sizeof(ViewBlock), 1);
|
2016-01-08 00:06:21 +00:00
|
|
|
m_vertsBinding.initTex(res, 10, m_tbBlockBuf, res.m_toolbarRes.m_shadingTex);
|
2015-12-04 01:35:01 +00:00
|
|
|
commitResources(res);
|
2016-01-08 00:06:21 +00:00
|
|
|
setBackground(res.themeData().toolbarBackground());
|
2015-12-03 03:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
|
|
|
{
|
2016-01-27 00:41:44 +00:00
|
|
|
for (std::vector<ViewChild<View*>>& u : m_children)
|
|
|
|
for (ViewChild<View*>& c : u)
|
|
|
|
c.mouseDown(coord, button, mod);
|
2015-12-03 03:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
|
|
|
{
|
2016-01-27 00:41:44 +00:00
|
|
|
for (std::vector<ViewChild<View*>>& u : m_children)
|
|
|
|
for (ViewChild<View*>& c : u)
|
|
|
|
c.mouseUp(coord, button, mod);
|
2015-12-03 03:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::mouseMove(const boo::SWindowCoord& coord)
|
|
|
|
{
|
2016-01-27 00:41:44 +00:00
|
|
|
for (std::vector<ViewChild<View*>>& u : m_children)
|
|
|
|
for (ViewChild<View*>& c : u)
|
|
|
|
c.mouseMove(coord);
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::mouseEnter(const boo::SWindowCoord& coord)
|
|
|
|
{
|
2016-01-27 00:41:44 +00:00
|
|
|
for (std::vector<ViewChild<View*>>& u : m_children)
|
|
|
|
for (ViewChild<View*>& c : u)
|
|
|
|
c.mouseEnter(coord);
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::mouseLeave(const boo::SWindowCoord& coord)
|
|
|
|
{
|
2016-01-27 00:41:44 +00:00
|
|
|
for (std::vector<ViewChild<View*>>& u : m_children)
|
|
|
|
for (ViewChild<View*>& c : u)
|
|
|
|
c.mouseLeave(coord);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::setHorizontalVerts(int width)
|
|
|
|
{
|
|
|
|
m_tbVerts[0].m_pos.assign(0, 1 + m_nomGauge, 0);
|
|
|
|
m_tbVerts[0].m_uv.assign(0, 0);
|
|
|
|
m_tbVerts[1].m_pos.assign(0, -1 + m_nomGauge, 0);
|
|
|
|
m_tbVerts[1].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[2].m_pos.assign(width, 1 + m_nomGauge, 0);
|
|
|
|
m_tbVerts[2].m_uv.assign(0, 0);
|
|
|
|
m_tbVerts[3].m_pos.assign(width, -1 + m_nomGauge, 0);
|
|
|
|
m_tbVerts[3].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[4].m_pos.assign(width, -1 + m_nomGauge, 0);
|
|
|
|
m_tbVerts[4].m_uv.assign(0.5, 0);
|
|
|
|
|
|
|
|
m_tbVerts[5].m_pos.assign(0, 1, 0);
|
|
|
|
m_tbVerts[5].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[6].m_pos.assign(0, 1, 0);
|
|
|
|
m_tbVerts[6].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[7].m_pos.assign(0, -1, 0);
|
|
|
|
m_tbVerts[7].m_uv.assign(1, 0);
|
|
|
|
m_tbVerts[8].m_pos.assign(width, 1, 0);
|
|
|
|
m_tbVerts[8].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[9].m_pos.assign(width, -1, 0);
|
|
|
|
m_tbVerts[9].m_uv.assign(1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::setVerticalVerts(int height)
|
|
|
|
{
|
|
|
|
m_tbVerts[0].m_pos.assign(-1, height, 0);
|
|
|
|
m_tbVerts[0].m_uv.assign(0, 0);
|
|
|
|
m_tbVerts[1].m_pos.assign(-1, 0, 0);
|
|
|
|
m_tbVerts[1].m_uv.assign(0, 0);
|
|
|
|
m_tbVerts[2].m_pos.assign(1, height, 0);
|
|
|
|
m_tbVerts[2].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[3].m_pos.assign(1, 0, 0);
|
|
|
|
m_tbVerts[3].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[4].m_pos.assign(1, 0, 0);
|
|
|
|
m_tbVerts[4].m_uv.assign(0.5, 0);
|
|
|
|
|
|
|
|
m_tbVerts[5].m_pos.assign(-1 + m_nomGauge, height, 0);
|
|
|
|
m_tbVerts[5].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[6].m_pos.assign(-1 + m_nomGauge, height, 0);
|
|
|
|
m_tbVerts[6].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[7].m_pos.assign(-1 + m_nomGauge, 0, 0);
|
|
|
|
m_tbVerts[7].m_uv.assign(0.5, 0);
|
|
|
|
m_tbVerts[8].m_pos.assign(1 + m_nomGauge, height, 0);
|
|
|
|
m_tbVerts[8].m_uv.assign(1, 0);
|
|
|
|
m_tbVerts[9].m_pos.assign(1 + m_nomGauge, 0, 0);
|
|
|
|
m_tbVerts[9].m_uv.assign(1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::push_back(View* v, unsigned unit)
|
|
|
|
{
|
|
|
|
if (unit >= m_units)
|
2016-03-04 23:03:47 +00:00
|
|
|
Log.report(logvisor::Fatal, "unit %u out of range %u", unit, m_units);
|
2016-01-27 00:41:44 +00:00
|
|
|
std::vector<ViewChild<View*>>& u = m_children[unit];
|
|
|
|
u.emplace_back();
|
|
|
|
u.back().m_view = v;
|
2015-12-03 03:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
|
|
|
|
{
|
|
|
|
View::resized(root, sub);
|
|
|
|
setHorizontalVerts(sub.size[0]);
|
2016-01-08 00:06:21 +00:00
|
|
|
m_vertsBinding.load(m_tbVerts, sizeof(m_tbVerts));
|
2015-12-04 01:35:01 +00:00
|
|
|
m_tbBlock.setViewRect(root, sub);
|
|
|
|
m_tbBlockBuf->load(&m_tbBlock, sizeof(ViewBlock));
|
2015-12-05 00:42:46 +00:00
|
|
|
|
2016-01-27 00:41:44 +00:00
|
|
|
float gaugeUnit = rootView().viewRes().pixelFactor() * SPECTER_TOOLBAR_GAUGE;
|
|
|
|
float yOff = 0.0;
|
|
|
|
for (std::vector<ViewChild<View*>>& u : m_children)
|
2015-12-05 00:42:46 +00:00
|
|
|
{
|
2016-03-01 03:07:58 +00:00
|
|
|
boo::SWindowRect childRect = sub;
|
2016-01-27 00:41:44 +00:00
|
|
|
boo::SWindowRect containRect = sub;
|
|
|
|
containRect.location[0] += m_padding;
|
|
|
|
containRect.size[0] -= m_padding * 2;
|
|
|
|
containRect.size[1] = gaugeUnit;
|
|
|
|
for (ViewChild<View*>& c : u)
|
|
|
|
{
|
|
|
|
c.m_view->containerResized(root, containRect);
|
|
|
|
childRect.size[0] = c.m_view->nominalWidth();
|
|
|
|
childRect.size[1] = c.m_view->nominalHeight();
|
|
|
|
childRect.location[0] += m_padding;
|
|
|
|
childRect.location[1] = sub.location[1] + (gaugeUnit - childRect.size[1]) / 2 - 1 + yOff;
|
|
|
|
c.m_view->resized(root, childRect);
|
|
|
|
childRect.location[0] += childRect.size[0];
|
|
|
|
|
|
|
|
containRect.location[0] += m_padding + childRect.size[0];
|
|
|
|
containRect.size[0] -= m_padding + childRect.size[0];
|
|
|
|
containRect.size[1] = gaugeUnit;
|
|
|
|
}
|
|
|
|
yOff += gaugeUnit;
|
2015-12-05 00:42:46 +00:00
|
|
|
}
|
2015-12-03 03:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Toolbar::draw(boo::IGraphicsCommandQueue* gfxQ)
|
|
|
|
{
|
|
|
|
View::draw(gfxQ);
|
2016-01-08 00:06:21 +00:00
|
|
|
gfxQ->setShaderDataBinding(m_vertsBinding);
|
2015-12-04 01:35:01 +00:00
|
|
|
gfxQ->draw(0, 10);
|
2015-12-05 00:42:46 +00:00
|
|
|
|
2016-01-27 00:41:44 +00:00
|
|
|
for (std::vector<ViewChild<View*>>& u : m_children)
|
|
|
|
for (ViewChild<View*>& c : u)
|
|
|
|
c.m_view->draw(gfxQ);
|
2015-12-03 03:26:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|