Toolbar additions, PathButtons self-sizing

This commit is contained in:
Jack Andersen 2016-01-26 14:41:44 -10:00
parent c08a9e5355
commit b86b523ea0
7 changed files with 144 additions and 91 deletions

View File

@ -46,6 +46,7 @@ class PathButtons : public ScrollView
int m_pathButtonPending = -1; int m_pathButtonPending = -1;
IPathButtonsBinding& m_binding; IPathButtonsBinding& m_binding;
bool m_fillContainer;
struct PathButton : IButtonBinding struct PathButton : IButtonBinding
{ {
PathButtons& m_pb; PathButtons& m_pb;
@ -63,10 +64,17 @@ class PathButtons : public ScrollView
std::vector<PathButton> m_pathButtons; std::vector<PathButton> m_pathButtons;
public: public:
PathButtons(ViewResources& res, View& parentView, IPathButtonsBinding& binding); PathButtons(ViewResources& res, View& parentView, IPathButtonsBinding& binding, bool fillContainer=false);
void setButtons(const std::vector<HECL::SystemString>& comps); void setButtons(const std::vector<HECL::SystemString>& comps);
void setMultiplyColor(const Zeus::CColor& color); void setMultiplyColor(const Zeus::CColor& color);
/* Fill all available space in container when requested */
void containerResized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
{
if (m_fillContainer)
View::resized(root, sub);
}
}; };
} }

View File

@ -50,7 +50,8 @@ class Space : public View
ViewChild<std::unique_ptr<CornerView>> m_cornerView; ViewChild<std::unique_ptr<CornerView>> m_cornerView;
public: public:
Space(ViewResources& res, View& parentView, ISpaceController& controller, Toolbar::Position toolbarPos); Space(ViewResources& res, View& parentView, ISpaceController& controller,
Toolbar::Position toolbarPos, unsigned tbUnits);
View* setContentView(View* view); View* setContentView(View* view);
Toolbar* toolbar() {return m_toolbar.m_view.get();} Toolbar* toolbar() {return m_toolbar.m_view.get();}
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);

View File

@ -27,68 +27,22 @@ public:
}; };
private: private:
Position m_tbPos; Position m_tbPos;
std::vector<ViewChild<View*>> m_children; unsigned m_units;
std::vector<std::vector<ViewChild<View*>>> m_children;
ViewBlock m_tbBlock; ViewBlock m_tbBlock;
boo::IGraphicsBufferD* m_tbBlockBuf; boo::IGraphicsBufferD* m_tbBlockBuf;
TexShaderVert m_tbVerts[10]; TexShaderVert m_tbVerts[10];
int m_nomHeight = 25; int m_nomGauge = 25;
int m_padding = 10; int m_padding = 10;
void setHorizontalVerts(int width) void setHorizontalVerts(int width);
{ void setVerticalVerts(int height);
m_tbVerts[0].m_pos.assign(0, 1 + m_nomHeight, 0);
m_tbVerts[0].m_uv.assign(0, 0);
m_tbVerts[1].m_pos.assign(0, -1 + m_nomHeight, 0);
m_tbVerts[1].m_uv.assign(0.5, 0);
m_tbVerts[2].m_pos.assign(width, 1 + m_nomHeight, 0);
m_tbVerts[2].m_uv.assign(0, 0);
m_tbVerts[3].m_pos.assign(width, -1 + m_nomHeight, 0);
m_tbVerts[3].m_uv.assign(0.5, 0);
m_tbVerts[4].m_pos.assign(width, -1 + m_nomHeight, 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 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_nomHeight, height, 0);
m_tbVerts[5].m_uv.assign(0.5, 0);
m_tbVerts[6].m_pos.assign(-1 + m_nomHeight, height, 0);
m_tbVerts[6].m_uv.assign(0.5, 0);
m_tbVerts[7].m_pos.assign(-1 + m_nomHeight, 0, 0);
m_tbVerts[7].m_uv.assign(0.5, 0);
m_tbVerts[8].m_pos.assign(1 + m_nomHeight, height, 0);
m_tbVerts[8].m_uv.assign(1, 0);
m_tbVerts[9].m_pos.assign(1 + m_nomHeight, 0, 0);
m_tbVerts[9].m_uv.assign(1, 0);
}
VertexBufferBinding m_vertsBinding; VertexBufferBinding m_vertsBinding;
public: public:
Toolbar(ViewResources& res, View& parentView, Position toolbarPos); Toolbar(ViewResources& res, View& parentView, Position toolbarPos, unsigned units);
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey); void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey);
void mouseMove(const boo::SWindowCoord&); void mouseMove(const boo::SWindowCoord&);
@ -97,21 +51,25 @@ public:
void resized(const boo::SWindowRect& rootView, const boo::SWindowRect& sub); void resized(const boo::SWindowRect& rootView, const boo::SWindowRect& sub);
void draw(boo::IGraphicsCommandQueue* gfxQ); void draw(boo::IGraphicsCommandQueue* gfxQ);
int nominalHeight() const {return m_nomHeight;} int nominalHeight() const
void clear() {m_children.clear();}
void push_back(View* v)
{ {
m_children.emplace_back(); return m_nomGauge;
m_children.back().m_view = v;
} }
void clear()
{
for (std::vector<ViewChild<View*>>& u : m_children)
u.clear();
}
void push_back(View* v, unsigned unit);
void setMultiplyColor(const Zeus::CColor& color) void setMultiplyColor(const Zeus::CColor& color)
{ {
View::setMultiplyColor(color); View::setMultiplyColor(color);
for (ViewChild<View*>& c : m_children) for (std::vector<ViewChild<View*>>& u : m_children)
if (c.m_view) for (ViewChild<View*>& c : u)
c.m_view->setMultiplyColor(color); if (c.m_view)
c.m_view->setMultiplyColor(color);
} }
}; };

View File

@ -217,6 +217,7 @@ public:
virtual void modKeyDown(boo::EModifierKey, bool) {} virtual void modKeyDown(boo::EModifierKey, bool) {}
virtual void modKeyUp(boo::EModifierKey) {} virtual void modKeyUp(boo::EModifierKey) {}
virtual void containerResized(const boo::SWindowRect& root, const boo::SWindowRect& sub) {}
virtual void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub); virtual void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
virtual void resized(const ViewBlock& vb, const boo::SWindowRect& sub); virtual void resized(const ViewBlock& vb, const boo::SWindowRect& sub);
virtual void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub, virtual void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub,

View File

@ -4,8 +4,8 @@
namespace Specter namespace Specter
{ {
PathButtons::PathButtons(ViewResources& res, View& parentView, IPathButtonsBinding& binding) PathButtons::PathButtons(ViewResources& res, View& parentView, IPathButtonsBinding& binding, bool fillContainer)
: ScrollView(res, parentView, ScrollView::Style::SideButtons), m_binding(binding) : ScrollView(res, parentView, ScrollView::Style::SideButtons), m_binding(binding), m_fillContainer(fillContainer)
{ {
m_contentView.m_view.reset(new ContentView(res, *this)); m_contentView.m_view.reset(new ContentView(res, *this));
setContentView(m_contentView.m_view.get()); setContentView(m_contentView.m_view.get());

View File

@ -16,7 +16,8 @@ static LogVisor::LogModule Log("Specter::Space");
#define CORNER_DRAG_THRESHOLD 20 #define CORNER_DRAG_THRESHOLD 20
Space::Space(ViewResources& res, View& parentView, ISpaceController& controller, Toolbar::Position tbPos) Space::Space(ViewResources& res, View& parentView, ISpaceController& controller,
Toolbar::Position tbPos, unsigned tbUnits)
: View(res, parentView), m_controller(controller), m_tbPos(tbPos) : View(res, parentView), m_controller(controller), m_tbPos(tbPos)
{ {
commitResources(res); commitResources(res);
@ -25,7 +26,7 @@ Space::Space(ViewResources& res, View& parentView, ISpaceController& controller,
if (controller.spaceSplitAllowed()) if (controller.spaceSplitAllowed())
m_cornerView.m_view.reset(new CornerView(res, *this, triColor)); m_cornerView.m_view.reset(new CornerView(res, *this, triColor));
if (tbPos != Toolbar::Position::None) if (tbPos != Toolbar::Position::None)
m_toolbar.m_view.reset(new Toolbar(res, *this, tbPos)); m_toolbar.m_view.reset(new Toolbar(res, *this, tbPos, tbUnits));
} }
Space::CornerView::CornerView(ViewResources& res, Space& space, const Zeus::CColor& triColor) Space::CornerView::CornerView(ViewResources& res, Space& space, const Zeus::CColor& triColor)

View File

@ -1,6 +1,7 @@
#include <LogVisor/LogVisor.hpp> #include <LogVisor/LogVisor.hpp>
#include "Specter/Toolbar.hpp" #include "Specter/Toolbar.hpp"
#include "Specter/ViewResources.hpp" #include "Specter/ViewResources.hpp"
#include "Specter/RootView.hpp"
#define TOOLBAR_PADDING 10 #define TOOLBAR_PADDING 10
@ -20,11 +21,14 @@ void Toolbar::Resources::init(boo::IGraphicsDataFactory* factory, const IThemeDa
m_shadingTex = factory->newStaticTexture(4, 1, 1, boo::TextureFormat::RGBA8, tex, 16); m_shadingTex = factory->newStaticTexture(4, 1, 1, boo::TextureFormat::RGBA8, tex, 16);
} }
Toolbar::Toolbar(ViewResources& res, View& parentView, Position tbPos) Toolbar::Toolbar(ViewResources& res, View& parentView, Position tbPos, unsigned units)
: View(res, parentView), m_tbPos(tbPos), : View(res, parentView), m_tbPos(tbPos), m_units(units),
m_nomHeight(res.pixelFactor() * SPECTER_TOOLBAR_GAUGE), m_nomGauge(res.pixelFactor() * SPECTER_TOOLBAR_GAUGE * units),
m_padding(res.pixelFactor() * TOOLBAR_PADDING) m_padding(res.pixelFactor() * TOOLBAR_PADDING)
{ {
m_children.reserve(units);
for (unsigned u=0 ; u<units ; ++u)
m_children.emplace_back();
m_tbBlockBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Uniform, sizeof(ViewBlock), 1); m_tbBlockBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Uniform, sizeof(ViewBlock), 1);
m_vertsBinding.initTex(res, 10, m_tbBlockBuf, res.m_toolbarRes.m_shadingTex); m_vertsBinding.initTex(res, 10, m_tbBlockBuf, res.m_toolbarRes.m_shadingTex);
commitResources(res); commitResources(res);
@ -33,32 +37,96 @@ Toolbar::Toolbar(ViewResources& res, View& parentView, Position tbPos)
void Toolbar::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) void Toolbar::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{ {
for (ViewChild<View*>& c : m_children) for (std::vector<ViewChild<View*>>& u : m_children)
c.mouseDown(coord, button, mod); for (ViewChild<View*>& c : u)
c.mouseDown(coord, button, mod);
} }
void Toolbar::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod) void Toolbar::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
{ {
for (ViewChild<View*>& c : m_children) for (std::vector<ViewChild<View*>>& u : m_children)
c.mouseUp(coord, button, mod); for (ViewChild<View*>& c : u)
c.mouseUp(coord, button, mod);
} }
void Toolbar::mouseMove(const boo::SWindowCoord& coord) void Toolbar::mouseMove(const boo::SWindowCoord& coord)
{ {
for (ViewChild<View*>& c : m_children) for (std::vector<ViewChild<View*>>& u : m_children)
c.mouseMove(coord); for (ViewChild<View*>& c : u)
c.mouseMove(coord);
} }
void Toolbar::mouseEnter(const boo::SWindowCoord& coord) void Toolbar::mouseEnter(const boo::SWindowCoord& coord)
{ {
for (ViewChild<View*>& c : m_children) for (std::vector<ViewChild<View*>>& u : m_children)
c.mouseEnter(coord); for (ViewChild<View*>& c : u)
c.mouseEnter(coord);
} }
void Toolbar::mouseLeave(const boo::SWindowCoord& coord) void Toolbar::mouseLeave(const boo::SWindowCoord& coord)
{ {
for (ViewChild<View*>& c : m_children) for (std::vector<ViewChild<View*>>& u : m_children)
c.mouseLeave(coord); 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)
Log.report(LogVisor::FatalError, "unit %u out of range %u", unit, m_units);
std::vector<ViewChild<View*>>& u = m_children[unit];
u.emplace_back();
u.back().m_view = v;
} }
void Toolbar::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub) void Toolbar::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
@ -69,15 +137,30 @@ void Toolbar::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
m_tbBlock.setViewRect(root, sub); m_tbBlock.setViewRect(root, sub);
m_tbBlockBuf->load(&m_tbBlock, sizeof(ViewBlock)); m_tbBlockBuf->load(&m_tbBlock, sizeof(ViewBlock));
float gaugeUnit = rootView().viewRes().pixelFactor() * SPECTER_TOOLBAR_GAUGE;
float yOff = 0.0;
boo::SWindowRect childRect = sub; boo::SWindowRect childRect = sub;
for (ViewChild<View*>& c : m_children) for (std::vector<ViewChild<View*>>& u : m_children)
{ {
childRect.size[0] = c.m_view->nominalWidth(); boo::SWindowRect containRect = sub;
childRect.size[1] = c.m_view->nominalHeight(); containRect.location[0] += m_padding;
childRect.location[0] += m_padding; containRect.size[0] -= m_padding * 2;
childRect.location[1] = sub.location[1] + (m_nomHeight - childRect.size[1]) / 2 - 1; containRect.size[1] = gaugeUnit;
c.m_view->resized(root, childRect); for (ViewChild<View*>& c : u)
childRect.location[0] += childRect.size[0]; {
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;
} }
} }
@ -88,8 +171,9 @@ void Toolbar::draw(boo::IGraphicsCommandQueue* gfxQ)
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips); gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
gfxQ->draw(0, 10); gfxQ->draw(0, 10);
for (ViewChild<View*>& c : m_children) for (std::vector<ViewChild<View*>>& u : m_children)
c.m_view->draw(gfxQ); for (ViewChild<View*>& c : u)
c.m_view->draw(gfxQ);
} }
} }