mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-10 13:47:46 +00:00
Button widget and mouse events
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "Specter/ViewResources.hpp"
|
||||
|
||||
#define TOOLBAR_GAUGE 28
|
||||
#define TOOLBAR_PADDING 10
|
||||
|
||||
namespace Specter
|
||||
{
|
||||
@@ -20,10 +21,12 @@ void Toolbar::Resources::init(boo::IGraphicsDataFactory* factory, const ThemeDat
|
||||
}
|
||||
|
||||
Toolbar::Toolbar(ViewResources& res, View& parentView, Position tbPos)
|
||||
: View(res, parentView), m_tbPos(tbPos), m_gauge(res.pixelFactor() * TOOLBAR_GAUGE)
|
||||
: View(res, parentView), m_tbPos(tbPos),
|
||||
m_gauge(res.pixelFactor() * TOOLBAR_GAUGE),
|
||||
m_padding(res.pixelFactor() * TOOLBAR_PADDING)
|
||||
{
|
||||
m_tbBlockBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Uniform, sizeof(ViewBlock), 1);
|
||||
m_tbVertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(ToolbarVert), 10);
|
||||
m_tbVertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(TexShaderVert), 10);
|
||||
|
||||
if (!res.m_viewRes.m_texVtxFmt)
|
||||
{
|
||||
@@ -55,19 +58,87 @@ Toolbar::Toolbar(ViewResources& res, View& parentView, Position tbPos)
|
||||
|
||||
void Toolbar::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
||||
{
|
||||
boo::SWindowRect childRect = subRect();
|
||||
for (Child& c : m_children)
|
||||
{
|
||||
childRect.size[0] = c.m_view->nominalWidth();
|
||||
childRect.size[1] = c.m_view->nominalHeight();
|
||||
childRect.location[0] += m_padding;
|
||||
childRect.location[1] = (m_gauge - childRect.size[1]) / 2 - 1;
|
||||
if (childRect.coordInRect(coord))
|
||||
{
|
||||
if (!c.m_mouseDown)
|
||||
{
|
||||
c.m_view->mouseDown(coord, button, mod);
|
||||
c.m_mouseDown = true;
|
||||
}
|
||||
}
|
||||
childRect.location[0] += childRect.size[0];
|
||||
}
|
||||
}
|
||||
|
||||
void Toolbar::mouseUp(const boo::SWindowCoord& coord, boo::EMouseButton button, boo::EModifierKey mod)
|
||||
{
|
||||
for (Child& c : m_children)
|
||||
{
|
||||
if (c.m_mouseDown)
|
||||
{
|
||||
c.m_view->mouseUp(coord, button, mod);
|
||||
c.m_mouseDown = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Toolbar::mouseMove(const boo::SWindowCoord& coord)
|
||||
{
|
||||
boo::SWindowRect childRect = subRect();
|
||||
for (Child& c : m_children)
|
||||
{
|
||||
childRect.size[0] = c.m_view->nominalWidth();
|
||||
childRect.size[1] = c.m_view->nominalHeight();
|
||||
childRect.location[0] += m_padding;
|
||||
childRect.location[1] = (m_gauge - childRect.size[1]) / 2 - 1;
|
||||
if (childRect.coordInRect(coord))
|
||||
{
|
||||
if (!c.m_mouseIn)
|
||||
{
|
||||
c.m_view->mouseEnter(coord);
|
||||
c.m_mouseIn = true;
|
||||
}
|
||||
c.m_view->mouseMove(coord);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c.m_mouseIn)
|
||||
{
|
||||
c.m_view->mouseLeave(coord);
|
||||
c.m_mouseIn = false;
|
||||
}
|
||||
}
|
||||
childRect.location[0] += childRect.size[0];
|
||||
}
|
||||
}
|
||||
|
||||
void Toolbar::mouseEnter(const boo::SWindowCoord& coord)
|
||||
{
|
||||
}
|
||||
|
||||
void Toolbar::mouseLeave(const boo::SWindowCoord& coord)
|
||||
{
|
||||
for (Child& c : m_children)
|
||||
{
|
||||
if (c.m_mouseIn)
|
||||
{
|
||||
c.m_view->mouseLeave(coord);
|
||||
c.m_mouseIn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Toolbar::resetResources(ViewResources& res)
|
||||
{
|
||||
m_gauge = res.pixelFactor() * TOOLBAR_GAUGE;
|
||||
m_padding = res.pixelFactor() * TOOLBAR_PADDING;
|
||||
setBackground(res.themeData().toolbarBackground());
|
||||
updateSize();
|
||||
}
|
||||
@@ -76,9 +147,20 @@ void Toolbar::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
|
||||
{
|
||||
View::resized(root, sub);
|
||||
setHorizontalVerts(sub.size[0]);
|
||||
m_tbVertsBuf->load(&m_tbVerts, sizeof(ToolbarVert) * 10);
|
||||
m_tbVertsBuf->load(&m_tbVerts, sizeof(TexShaderVert) * 10);
|
||||
m_tbBlock.setViewRect(root, sub);
|
||||
m_tbBlockBuf->load(&m_tbBlock, sizeof(ViewBlock));
|
||||
|
||||
boo::SWindowRect childRect = sub;
|
||||
for (Child& c : m_children)
|
||||
{
|
||||
childRect.size[0] = c.m_view->nominalWidth();
|
||||
childRect.size[1] = c.m_view->nominalHeight();
|
||||
childRect.location[0] += m_padding;
|
||||
childRect.location[1] = (m_gauge - childRect.size[1]) / 2 - 1;
|
||||
c.m_view->resized(root, childRect);
|
||||
childRect.location[0] += childRect.size[0];
|
||||
}
|
||||
}
|
||||
|
||||
void Toolbar::draw(boo::IGraphicsCommandQueue* gfxQ)
|
||||
@@ -87,6 +169,9 @@ void Toolbar::draw(boo::IGraphicsCommandQueue* gfxQ)
|
||||
gfxQ->setShaderDataBinding(m_tbShaderBinding);
|
||||
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
|
||||
gfxQ->draw(0, 10);
|
||||
|
||||
for (Child& c : m_children)
|
||||
c.m_view->draw(gfxQ);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user