From ff63ec54f4f98a7345ca9d3bfe197b03f3c52fdf Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 29 Dec 2015 16:20:24 -1000 Subject: [PATCH] Table rendering adjustments; ScrollView work --- specter/include/Specter/ScrollView.hpp | 20 ++++- specter/include/Specter/Table.hpp | 5 +- specter/include/Specter/ViewResources.hpp | 4 + specter/lib/FileBrowser.cpp | 2 +- specter/lib/ScrollView.cpp | 94 ++++++++++++++++++++--- specter/lib/Table.cpp | 58 ++++++++------ 6 files changed, 145 insertions(+), 38 deletions(-) diff --git a/specter/include/Specter/ScrollView.hpp b/specter/include/Specter/ScrollView.hpp index e6d7fade8..606f51bfb 100644 --- a/specter/include/Specter/ScrollView.hpp +++ b/specter/include/Specter/ScrollView.hpp @@ -12,16 +12,25 @@ class ScrollView : public View public: enum class Style { - + Plain, + ThinIndicator }; private: + Style m_style; View* m_contentView = nullptr; int m_scroll[2] = {}; int m_targetScroll[2] = {}; + bool m_drawInd = false; + + SolidShaderVert m_verts[4]; + boo::IGraphicsBufferD* m_vertsBuf = nullptr; + boo::IVertexFormat* m_vtxFmt = nullptr; /* OpenGL only */ + boo::IShaderDataBinding* m_shaderBinding = nullptr; + public: - ScrollView(ViewResources& res, View& parentView); + ScrollView(ViewResources& res, View& parentView, Style style); void setContentView(View* v) { m_contentView = v; @@ -35,6 +44,13 @@ public: int nominalWidth() const {return subRect().size[0];} int nominalHeight() const {return subRect().size[1];} + void setMultiplyColor(const Zeus::CColor& color) + { + View::setMultiplyColor(color); + if (m_contentView) + m_contentView->setMultiplyColor(color); + } + void think(); void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub); void draw(boo::IGraphicsCommandQueue* gfxQ); diff --git a/specter/include/Specter/Table.hpp b/specter/include/Specter/Table.hpp index d06a0fb87..739200b85 100644 --- a/specter/include/Specter/Table.hpp +++ b/specter/include/Specter/Table.hpp @@ -7,7 +7,8 @@ namespace Specter { -#define SPECTER_TABLE_MAX_ROWS 128 +#define SPECTER_TABLE_MAX_ROWS 128ul +#define SPECTER_TABLE_MAX_COLUMNS 32ul enum class SortDirection { @@ -57,7 +58,7 @@ class Table : public View { Table& m_t; - SolidShaderVert m_verts[SPECTER_TABLE_MAX_ROWS * 6]; + SolidShaderVert m_verts[SPECTER_TABLE_MAX_ROWS * SPECTER_TABLE_MAX_COLUMNS * 6]; boo::IGraphicsBufferD* m_vertsBuf = nullptr; boo::IVertexFormat* m_vtxFmt = nullptr; /* OpenGL only */ boo::IShaderDataBinding* m_shaderBinding = nullptr; diff --git a/specter/include/Specter/ViewResources.hpp b/specter/include/Specter/ViewResources.hpp index 66909b795..ca8909c0a 100644 --- a/specter/include/Specter/ViewResources.hpp +++ b/specter/include/Specter/ViewResources.hpp @@ -46,6 +46,8 @@ class ThemeData Zeus::CColor m_tableCellBg1 = {0.1725, 0.1725, 0.1725, 0.75}; Zeus::CColor m_tableCellBg2 = {0.2425, 0.2425, 0.2425, 0.75}; + Zeus::CColor m_scrollIndicator = {0.2823, 0.2823, 0.2823, 1.0}; + public: virtual const Zeus::CColor& uiText() const {return m_uiText;} virtual const Zeus::CColor& fieldText() const {return m_fieldText;} @@ -80,6 +82,8 @@ public: virtual const Zeus::CColor& tableCellBg1() const {return m_tableCellBg1;} virtual const Zeus::CColor& tableCellBg2() const {return m_tableCellBg2;} + + virtual const Zeus::CColor& scrollIndicator() const {return m_scrollIndicator;} }; class ViewResources diff --git a/specter/lib/FileBrowser.cpp b/specter/lib/FileBrowser.cpp index d92e9eca5..479e09129 100644 --- a/specter/lib/FileBrowser.cpp +++ b/specter/lib/FileBrowser.cpp @@ -178,7 +178,7 @@ void FileBrowser::resized(const boo::SWindowRect& root, const boo::SWindowRect& boo::SWindowRect centerRect = subRect(); centerRect.location[0] = root.size[0] / 2 - (centerRect.size[0] / 2.0) + 2 * pf; - centerRect.location[1] = root.size[1] / 2 - (centerRect.size[1] / 2.0) + 2 * pf;; + centerRect.location[1] = root.size[1] / 2 - (centerRect.size[1] / 2.0) + 2 * pf; centerRect.size[0] -= 4 * pf; centerRect.size[1] -= 4 * pf; diff --git a/specter/lib/ScrollView.cpp b/specter/lib/ScrollView.cpp index 70fe0e063..acb307cfe 100644 --- a/specter/lib/ScrollView.cpp +++ b/specter/lib/ScrollView.cpp @@ -1,12 +1,37 @@ #include "Specter/ScrollView.hpp" +#include "Specter/ViewResources.hpp" +#include "Specter/RootView.hpp" namespace Specter { #define MAX_SCROLL_SPEED 100 -ScrollView::ScrollView(ViewResources& res, View& parentView) -: View(res, parentView) +ScrollView::ScrollView(ViewResources& res, View& parentView, Style style) +: View(res, parentView), m_style(style) { + m_vertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SolidShaderVert), 4); + + if (!res.m_viewRes.m_texVtxFmt) + { + boo::VertexElementDescriptor vdescs[] = + { + {m_vertsBuf, nullptr, boo::VertexSemantic::Position4}, + {m_vertsBuf, nullptr, boo::VertexSemantic::Color} + }; + m_vtxFmt = res.m_factory->newVertexFormat(2, vdescs); + boo::IGraphicsBuffer* bufs[] = {m_viewVertBlockBuf}; + m_shaderBinding = res.m_factory->newShaderDataBinding(res.m_viewRes.m_solidShader, + m_vtxFmt, m_vertsBuf, nullptr, + nullptr, 1, bufs, 0, nullptr); + } + else + { + boo::IGraphicsBuffer* bufs[] = {m_viewVertBlockBuf}; + m_shaderBinding = res.m_factory->newShaderDataBinding(res.m_viewRes.m_solidShader, + res.m_viewRes.m_texVtxFmt, + m_vertsBuf, nullptr, + nullptr, 1, bufs, 0, nullptr); + } commitResources(res); } @@ -14,12 +39,27 @@ void ScrollView::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& { if (m_contentView) { - double mult = 10.0; + float ratio = subRect().size[1] / float(m_contentView->nominalHeight()); + if (ratio >= 1.f) + { + m_scroll[0] = 0; + m_scroll[1] = 0; + m_targetScroll[0] = 0; + m_targetScroll[1] = 0; + updateSize(); + } + + float pf = rootView().viewRes().pixelFactor(); + double mult = 20.0 * pf; if (scroll.isFine) - mult = 1.0; - m_targetScroll[0] += scroll.delta[0] * mult; - m_targetScroll[1] += scroll.delta[1] * mult; - m_targetScroll[1] = std::min(m_targetScroll[1], 0); + mult = 1.0 * pf; + //m_targetScroll[0] -= scroll.delta[0] * mult; + m_targetScroll[1] -= scroll.delta[1] * mult; + + m_targetScroll[1] = std::max(m_targetScroll[1], 0); + int scrollHeight = m_contentView->nominalHeight() - subRect().size[1]; + m_targetScroll[1] = std::min(m_targetScroll[1], scrollHeight); + if (scroll.isFine) { m_scroll[0] = m_targetScroll[0]; @@ -40,8 +80,9 @@ void ScrollView::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& void ScrollView::think() { bool update = false; + float pf = rootView().viewRes().pixelFactor(); - int xSpeed = std::max(1, std::min(abs(m_targetScroll[0] - m_scroll[0]) / 10, MAX_SCROLL_SPEED)); + int xSpeed = std::max(1, std::min(abs(m_targetScroll[0] - m_scroll[0]) / int(5*pf), int(pf*MAX_SCROLL_SPEED))); if (m_scroll[0] < m_targetScroll[0]) { m_scroll[0] += xSpeed; @@ -53,7 +94,7 @@ void ScrollView::think() update = true; } - int ySpeed = std::max(1, std::min(abs(m_targetScroll[1] - m_scroll[1]) / 10, MAX_SCROLL_SPEED)); + int ySpeed = std::max(1, std::min(abs(m_targetScroll[1] - m_scroll[1]) / int(5*pf), int(pf*MAX_SCROLL_SPEED))); if (m_scroll[1] < m_targetScroll[1]) { m_scroll[1] += ySpeed; @@ -64,6 +105,7 @@ void ScrollView::think() m_scroll[1] -= ySpeed; update = true; } + if (update) updateSize(); } @@ -75,17 +117,49 @@ void ScrollView::resized(const boo::SWindowRect& root, const boo::SWindowRect& s { boo::SWindowRect cRect = sub; cRect.location[0] += m_scroll[0]; - cRect.location[1] += sub.size[1] - m_contentView->nominalHeight() - m_scroll[1]; + cRect.location[1] += sub.size[1] - m_contentView->nominalHeight() + m_scroll[1]; cRect.size[0] = m_contentView->nominalWidth(); cRect.size[1] = m_contentView->nominalHeight(); m_contentView->resized(root, cRect, sub); + + if (m_style == Style::ThinIndicator) + { + float ratio = sub.size[1] / float(cRect.size[1]); + m_drawInd = ratio < 1.f; + if (m_drawInd) + { + float pf = rootView().viewRes().pixelFactor(); + int barHeight = sub.size[1] * ratio; + int scrollHeight = sub.size[1] - barHeight; + float prog = m_scroll[1] / float(cRect.size[1] - sub.size[1]); + int x = sub.size[0]; + int y = sub.size[1] - scrollHeight * prog; + m_verts[0].m_pos.assign(x, y, 0); + m_verts[1].m_pos.assign(x, y-barHeight, 0); + m_verts[2].m_pos.assign(x+2*pf, y, 0); + m_verts[3].m_pos.assign(x+2*pf, y-barHeight, 0); + const Zeus::CColor& color = rootView().themeData().scrollIndicator(); + for (int i=0 ; i<4 ; ++i) + m_verts[i].m_color = color; + m_vertsBuf->load(m_verts, sizeof(m_verts)); + } + } } } void ScrollView::draw(boo::IGraphicsCommandQueue* gfxQ) { if (m_contentView) + { m_contentView->draw(gfxQ); + + if (m_style == Style::ThinIndicator && m_drawInd) + { + gfxQ->setShaderDataBinding(m_shaderBinding); + gfxQ->setDrawPrimitive(boo::Primitive::TriStrips); + gfxQ->draw(0, 4); + } + } } } diff --git a/specter/lib/Table.cpp b/specter/lib/Table.cpp index 6f26e22ca..0cae67016 100644 --- a/specter/lib/Table.cpp +++ b/specter/lib/Table.cpp @@ -5,14 +5,14 @@ namespace Specter { #define ROW_HEIGHT 18 -#define ROW_SPACING 2 +#define CELL_MARGIN 1 Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state) : View(res, parentView), m_data(data), m_state(state), m_rowsView(*this, res) { commitResources(res); - m_scroll.m_view.reset(new ScrollView(res, *this)); + m_scroll.m_view.reset(new ScrollView(res, *this, ScrollView::Style::ThinIndicator)); m_scroll.m_view->setContentView(&m_rowsView); updateData(); } @@ -21,7 +21,7 @@ Table::RowsView::RowsView(Table& t, ViewResources& res) : View(res, t), m_t(t) { m_vertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SolidShaderVert), - SPECTER_TABLE_MAX_ROWS * 6); + SPECTER_TABLE_MAX_ROWS * SPECTER_TABLE_MAX_COLUMNS * 6); if (!res.m_viewRes.m_texVtxFmt) { @@ -60,7 +60,8 @@ void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWind float pf = rootView().viewRes().pixelFactor(); int div = sub.size[0] / m_t.m_cellViews.size(); - int spacing = (ROW_HEIGHT + ROW_SPACING) * pf; + int spacing = (ROW_HEIGHT + CELL_MARGIN * 2) * pf; + int margin = CELL_MARGIN * pf; int rowHeight = ROW_HEIGHT * pf; int yOff = 0; int idx = 0; @@ -71,30 +72,38 @@ void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWind } int startIdx = std::max(0, int(m_t.m_rows) - idx); - size_t i; - for (i=0 ; i= scissor.location[1] ; ++i) + size_t r, c; + for (r=0 ; r= scissor.location[1] ; ++r) { - v[0].m_pos.assign(0, yOff, 0); - v[0].m_color = (i&1) ? theme.tableCellBg1() : theme.tableCellBg2(); - v[1] = v[0]; - v[2].m_pos.assign(0, yOff - rowHeight, 0); - v[2].m_color = v[0].m_color; - v[3].m_pos.assign(sub.size[0], yOff, 0); - v[3].m_color = v[0].m_color; - v[4].m_pos.assign(sub.size[0], yOff - rowHeight, 0); - v[4].m_color = v[0].m_color; - v[5] = v[4]; + const Zeus::CColor& color = (r&1) ? theme.tableCellBg1() : theme.tableCellBg2(); + int xOff = 0; + for (c=0 ; cload(m_verts, sizeof(SolidShaderVert) * 6 * i); + m_visibleRows = r; + m_vertsBuf->load(m_verts, sizeof(SolidShaderVert) * 6 * r * c); } void Table::setMultiplyColor(const Zeus::CColor& color) { View::setMultiplyColor(color); + if (m_scroll.m_view) + m_scroll.m_view->setMultiplyColor(color); for (std::unique_ptr& hv : m_headerViews) if (hv) hv->m_text->setMultiplyColor(color); @@ -213,7 +222,10 @@ void Table::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub) int Table::RowsView::nominalHeight() const { float pf = rootView().viewRes().pixelFactor(); - return m_t.m_rows * (ROW_HEIGHT + ROW_SPACING) * pf; + int rows = m_t.m_rows; + if (m_t.m_header) + rows += 1; + return rows * (ROW_HEIGHT + CELL_MARGIN * 2) * pf; } void Table::RowsView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub, @@ -230,7 +242,7 @@ void Table::RowsView::resized(const boo::SWindowRect& root, const boo::SWindowRe boo::SWindowRect cell = sub; cell.size[1] = ROW_HEIGHT * pf; cell.location[1] += sub.size[1] - cell.size[1]; - int spacing = (ROW_HEIGHT + ROW_SPACING) * pf; + int spacing = (ROW_HEIGHT + CELL_MARGIN * 2) * pf; int hStart = cell.location[1]; for (auto& col : m_t.m_cellViews) { @@ -254,7 +266,7 @@ void Table::CellView::resized(const boo::SWindowRect& root, const boo::SWindowRe boo::SWindowRect textRect = sub; float pf = rootView().viewRes().pixelFactor(); textRect.location[0] += 5 * pf; - textRect.location[1] += 6 * pf; + textRect.location[1] += 5 * pf; m_text->resized(root, textRect); } @@ -271,7 +283,7 @@ void Table::RowsView::draw(boo::IGraphicsCommandQueue* gfxQ) gfxQ->setScissor(m_scissorRect); size_t rows = std::min(m_visibleRows, m_t.m_rows); - gfxQ->draw(1, rows * 6 - 2); + gfxQ->draw(1, rows * m_t.m_columns * 6 - 2); for (auto& col : m_t.m_cellViews) { size_t idx = 0;