2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-13 14:05:52 +00:00

Fixed Toolbar on top of space

This commit is contained in:
Jack Andersen 2015-12-04 19:57:51 -10:00
parent 0f4c689545
commit fc67d86b29
5 changed files with 36 additions and 30 deletions

View File

@ -38,20 +38,20 @@ private:
ViewBlock m_tbBlock;
boo::IGraphicsBufferD* m_tbBlockBuf;
TexShaderVert m_tbVerts[10];
int m_gauge = 25;
int m_nomHeight = 25;
int m_padding = 10;
void setHorizontalVerts(int width)
{
m_tbVerts[0].m_pos.assign(0, 1 + m_gauge, 0);
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_gauge, 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_gauge, 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_gauge, 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_gauge, 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);
@ -79,15 +79,15 @@ private:
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_gauge, height, 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_gauge, height, 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_gauge, 0, 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_gauge, height, 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_gauge, 0, 0);
m_tbVerts[9].m_pos.assign(1 + m_nomHeight, 0, 0);
m_tbVerts[9].m_uv.assign(1, 0);
}
@ -105,7 +105,7 @@ public:
void resetResources(ViewResources& res);
void draw(boo::IGraphicsCommandQueue* gfxQ);
int gauge() const {return m_gauge;}
int nominalHeight() const {return m_nomHeight;}
void clear() {m_children.clear();}
void push_back(std::unique_ptr<View>&& v) {m_children.push_back(std::move(v));}

View File

@ -14,7 +14,7 @@ RootView::RootView(ViewResources& res, boo::IWindow* window)
m_renderTex = res.m_factory->newRenderTexture(rect.size[0], rect.size[1], 1);
commitResources(res);
m_splitView.reset(new SplitView(res, *this, SplitView::Axis::Horizontal));
Space* space1 = new Space(res, *m_splitView, Toolbar::Position::Bottom);
Space* space1 = new Space(res, *m_splitView, Toolbar::Position::Top);
space1->toolbar().push_back(std::make_unique<Button>(res, space1->toolbar(), "Hello Button"));
MultiLineTextView* textView1 = new MultiLineTextView(res, *this, res.m_heading18);
space1->setContentView(std::unique_ptr<MultiLineTextView>(textView1));

View File

@ -126,11 +126,16 @@ void Space::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
View::resized(root, sub);
boo::SWindowRect tbRect = sub;
tbRect.size[1] = m_toolbar->gauge();
tbRect.size[1] = m_toolbar->nominalHeight();
if (m_tbPos == Toolbar::Position::Top)
tbRect.location[1] += sub.size[1] - tbRect.size[1];
m_toolbar->resized(root, tbRect);
if (m_contentView)
{
if (m_tbPos == Toolbar::Position::Top)
tbRect.location[1] = sub.location[1];
else
tbRect.location[1] += tbRect.size[1];
tbRect.size[1] = sub.size[1] - tbRect.size[1];
tbRect.size[1] = std::max(tbRect.size[1], 0);

View File

@ -69,12 +69,12 @@ void SplitView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton butt
if (m_axis == Axis::Horizontal)
{
int slidePx = subRect().size[1] * m_slide;
if (abs(int(coord.pixel[1]) - slidePx) < 4)
if (abs(int(coord.pixel[1] + 2) - slidePx) < 4)
{
if (button == boo::EMouseButton::Primary)
{
m_dragging = true;
setSlide(coord.pixel[1] / float(subRect().size[1]));
setSlide((coord.pixel[1] + 2) / float(subRect().size[1]));
}
else if (button == boo::EMouseButton::Secondary)
{
@ -86,12 +86,12 @@ void SplitView::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton butt
else if (m_axis == Axis::Vertical)
{
int slidePx = subRect().size[0] * m_slide;
if (abs(int(coord.pixel[0]) - slidePx) < 4)
if (abs(int(coord.pixel[0] + 2) - slidePx) < 4)
{
if (button == boo::EMouseButton::Primary)
{
m_dragging = true;
setSlide(coord.pixel[0] / float(subRect().size[0]));
setSlide((coord.pixel[0] + 2) / float(subRect().size[0]));
}
else if (button == boo::EMouseButton::Secondary)
{
@ -135,9 +135,9 @@ void SplitView::mouseMove(const boo::SWindowCoord& coord)
if (m_axis == Axis::Horizontal)
{
if (m_dragging)
setSlide(coord.pixel[1] / float(subRect().size[1]));
setSlide((coord.pixel[1] + 2) / float(subRect().size[1]));
int slidePx = subRect().size[1] * m_slide;
if (abs(int(coord.pixel[1]) - slidePx) < 4)
if (abs(int(coord.pixel[1] + 2) - slidePx) < 4)
rootView().window()->setCursor(boo::EMouseCursor::VerticalArrow);
else
rootView().window()->setCursor(boo::EMouseCursor::Pointer);
@ -145,9 +145,9 @@ void SplitView::mouseMove(const boo::SWindowCoord& coord)
else if (m_axis == Axis::Vertical)
{
if (m_dragging)
setSlide(coord.pixel[0] / float(subRect().size[0]));
setSlide((coord.pixel[0] + 2) / float(subRect().size[0]));
int slidePx = subRect().size[0] * m_slide;
if (abs(int(coord.pixel[0]) - slidePx) < 4)
if (abs(int(coord.pixel[0] + 2) - slidePx) < 4)
rootView().window()->setCursor(boo::EMouseCursor::HorizontalArrow);
else
rootView().window()->setCursor(boo::EMouseCursor::Pointer);

View File

@ -11,18 +11,19 @@ static LogVisor::LogModule Log("Specter::Space");
void Toolbar::Resources::init(boo::IGraphicsDataFactory* factory, const ThemeData& theme)
{
static const Zeus::RGBA32 tex[3] =
static const Zeus::RGBA32 tex[] =
{
{255,255,255,64},
{255,255,255,64},
{0,0,0,64},
{0,0,0,64}
};
m_shadingTex = factory->newStaticTexture(3, 1, 1, boo::TextureFormat::RGBA8, tex, 12);
m_shadingTex = factory->newStaticTexture(4, 1, 1, boo::TextureFormat::RGBA8, tex, 16);
}
Toolbar::Toolbar(ViewResources& res, View& parentView, Position tbPos)
: View(res, parentView), m_tbPos(tbPos),
m_gauge(res.pixelFactor() * TOOLBAR_GAUGE),
m_nomHeight(res.pixelFactor() * TOOLBAR_GAUGE),
m_padding(res.pixelFactor() * TOOLBAR_PADDING)
{
m_tbBlockBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Uniform, sizeof(ViewBlock), 1);
@ -65,7 +66,7 @@ void Toolbar::mouseDown(const boo::SWindowCoord& coord, boo::EMouseButton button
childRect.size[0] = c.m_view->nominalWidth();
childRect.size[1] = c.m_view->nominalHeight();
childRect.location[0] += m_padding;
childRect.location[1] = subLoc1 + (m_gauge - childRect.size[1]) / 2 - 1;
childRect.location[1] = subLoc1 + (m_nomHeight - childRect.size[1]) / 2 - 1;
if (childRect.coordInRect(coord))
{
if (!c.m_mouseDown)
@ -99,7 +100,7 @@ void Toolbar::mouseMove(const boo::SWindowCoord& coord)
childRect.size[0] = c.m_view->nominalWidth();
childRect.size[1] = c.m_view->nominalHeight();
childRect.location[0] += m_padding;
childRect.location[1] = subLoc1 + (m_gauge - childRect.size[1]) / 2 - 1;
childRect.location[1] = subLoc1 + (m_nomHeight - childRect.size[1]) / 2 - 1;
if (childRect.coordInRect(coord))
{
if (!c.m_mouseIn)
@ -139,7 +140,7 @@ void Toolbar::mouseLeave(const boo::SWindowCoord& coord)
void Toolbar::resetResources(ViewResources& res)
{
m_gauge = res.pixelFactor() * TOOLBAR_GAUGE;
m_nomHeight = res.pixelFactor() * TOOLBAR_GAUGE;
m_padding = res.pixelFactor() * TOOLBAR_PADDING;
setBackground(res.themeData().toolbarBackground());
updateSize();
@ -159,7 +160,7 @@ void Toolbar::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
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] + (m_gauge - childRect.size[1]) / 2 - 1;
childRect.location[1] = sub.location[1] + (m_nomHeight - childRect.size[1]) / 2 - 1;
c.m_view->resized(root, childRect);
childRect.location[0] += childRect.size[0];
}