Table rendering adjustments; ScrollView work

This commit is contained in:
Jack Andersen 2015-12-29 16:20:24 -10:00
parent 4866ac6d4c
commit ff63ec54f4
6 changed files with 145 additions and 38 deletions

View File

@ -12,16 +12,25 @@ class ScrollView : public View
public: public:
enum class Style enum class Style
{ {
Plain,
ThinIndicator
}; };
private: private:
Style m_style;
View* m_contentView = nullptr; View* m_contentView = nullptr;
int m_scroll[2] = {}; int m_scroll[2] = {};
int m_targetScroll[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: public:
ScrollView(ViewResources& res, View& parentView); ScrollView(ViewResources& res, View& parentView, Style style);
void setContentView(View* v) void setContentView(View* v)
{ {
m_contentView = v; m_contentView = v;
@ -35,6 +44,13 @@ public:
int nominalWidth() const {return subRect().size[0];} int nominalWidth() const {return subRect().size[0];}
int nominalHeight() const {return subRect().size[1];} 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 think();
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub); void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub);
void draw(boo::IGraphicsCommandQueue* gfxQ); void draw(boo::IGraphicsCommandQueue* gfxQ);

View File

@ -7,7 +7,8 @@
namespace Specter namespace Specter
{ {
#define SPECTER_TABLE_MAX_ROWS 128 #define SPECTER_TABLE_MAX_ROWS 128ul
#define SPECTER_TABLE_MAX_COLUMNS 32ul
enum class SortDirection enum class SortDirection
{ {
@ -57,7 +58,7 @@ class Table : public View
{ {
Table& m_t; 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::IGraphicsBufferD* m_vertsBuf = nullptr;
boo::IVertexFormat* m_vtxFmt = nullptr; /* OpenGL only */ boo::IVertexFormat* m_vtxFmt = nullptr; /* OpenGL only */
boo::IShaderDataBinding* m_shaderBinding = nullptr; boo::IShaderDataBinding* m_shaderBinding = nullptr;

View File

@ -46,6 +46,8 @@ class ThemeData
Zeus::CColor m_tableCellBg1 = {0.1725, 0.1725, 0.1725, 0.75}; 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_tableCellBg2 = {0.2425, 0.2425, 0.2425, 0.75};
Zeus::CColor m_scrollIndicator = {0.2823, 0.2823, 0.2823, 1.0};
public: public:
virtual const Zeus::CColor& uiText() const {return m_uiText;} virtual const Zeus::CColor& uiText() const {return m_uiText;}
virtual const Zeus::CColor& fieldText() const {return m_fieldText;} 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& tableCellBg1() const {return m_tableCellBg1;}
virtual const Zeus::CColor& tableCellBg2() const {return m_tableCellBg2;} virtual const Zeus::CColor& tableCellBg2() const {return m_tableCellBg2;}
virtual const Zeus::CColor& scrollIndicator() const {return m_scrollIndicator;}
}; };
class ViewResources class ViewResources

View File

@ -178,7 +178,7 @@ void FileBrowser::resized(const boo::SWindowRect& root, const boo::SWindowRect&
boo::SWindowRect centerRect = subRect(); boo::SWindowRect centerRect = subRect();
centerRect.location[0] = root.size[0] / 2 - (centerRect.size[0] / 2.0) + 2 * pf; 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[0] -= 4 * pf;
centerRect.size[1] -= 4 * pf; centerRect.size[1] -= 4 * pf;

View File

@ -1,12 +1,37 @@
#include "Specter/ScrollView.hpp" #include "Specter/ScrollView.hpp"
#include "Specter/ViewResources.hpp"
#include "Specter/RootView.hpp"
namespace Specter namespace Specter
{ {
#define MAX_SCROLL_SPEED 100 #define MAX_SCROLL_SPEED 100
ScrollView::ScrollView(ViewResources& res, View& parentView) ScrollView::ScrollView(ViewResources& res, View& parentView, Style style)
: View(res, parentView) : 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); commitResources(res);
} }
@ -14,12 +39,27 @@ void ScrollView::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta&
{ {
if (m_contentView) 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) if (scroll.isFine)
mult = 1.0; mult = 1.0 * pf;
m_targetScroll[0] += scroll.delta[0] * mult; //m_targetScroll[0] -= scroll.delta[0] * mult;
m_targetScroll[1] += scroll.delta[1] * mult; m_targetScroll[1] -= scroll.delta[1] * mult;
m_targetScroll[1] = std::min(m_targetScroll[1], 0);
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) if (scroll.isFine)
{ {
m_scroll[0] = m_targetScroll[0]; m_scroll[0] = m_targetScroll[0];
@ -40,8 +80,9 @@ void ScrollView::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta&
void ScrollView::think() void ScrollView::think()
{ {
bool update = false; 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]) if (m_scroll[0] < m_targetScroll[0])
{ {
m_scroll[0] += xSpeed; m_scroll[0] += xSpeed;
@ -53,7 +94,7 @@ void ScrollView::think()
update = true; 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]) if (m_scroll[1] < m_targetScroll[1])
{ {
m_scroll[1] += ySpeed; m_scroll[1] += ySpeed;
@ -64,6 +105,7 @@ void ScrollView::think()
m_scroll[1] -= ySpeed; m_scroll[1] -= ySpeed;
update = true; update = true;
} }
if (update) if (update)
updateSize(); updateSize();
} }
@ -75,17 +117,49 @@ void ScrollView::resized(const boo::SWindowRect& root, const boo::SWindowRect& s
{ {
boo::SWindowRect cRect = sub; boo::SWindowRect cRect = sub;
cRect.location[0] += m_scroll[0]; 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[0] = m_contentView->nominalWidth();
cRect.size[1] = m_contentView->nominalHeight(); cRect.size[1] = m_contentView->nominalHeight();
m_contentView->resized(root, cRect, sub); 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) void ScrollView::draw(boo::IGraphicsCommandQueue* gfxQ)
{ {
if (m_contentView) if (m_contentView)
{
m_contentView->draw(gfxQ); m_contentView->draw(gfxQ);
if (m_style == Style::ThinIndicator && m_drawInd)
{
gfxQ->setShaderDataBinding(m_shaderBinding);
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
gfxQ->draw(0, 4);
}
}
} }
} }

View File

@ -5,14 +5,14 @@
namespace Specter namespace Specter
{ {
#define ROW_HEIGHT 18 #define ROW_HEIGHT 18
#define ROW_SPACING 2 #define CELL_MARGIN 1
Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state) Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data, ITableStateBinding* state)
: View(res, parentView), m_data(data), m_state(state), m_rowsView(*this, res) : View(res, parentView), m_data(data), m_state(state), m_rowsView(*this, res)
{ {
commitResources(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); m_scroll.m_view->setContentView(&m_rowsView);
updateData(); updateData();
} }
@ -21,7 +21,7 @@ Table::RowsView::RowsView(Table& t, ViewResources& res)
: View(res, t), m_t(t) : View(res, t), m_t(t)
{ {
m_vertsBuf = res.m_factory->newDynamicBuffer(boo::BufferUse::Vertex, sizeof(SolidShaderVert), 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) 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(); float pf = rootView().viewRes().pixelFactor();
int div = sub.size[0] / m_t.m_cellViews.size(); 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 rowHeight = ROW_HEIGHT * pf;
int yOff = 0; int yOff = 0;
int idx = 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); int startIdx = std::max(0, int(m_t.m_rows) - idx);
size_t i; size_t r, c;
for (i=0 ; i<SPECTER_TABLE_MAX_ROWS && (sub.location[1] + yOff + spacing) >= scissor.location[1] ; ++i) for (r=0 ; r<SPECTER_TABLE_MAX_ROWS && (sub.location[1] + yOff + spacing) >= scissor.location[1] ; ++r)
{ {
v[0].m_pos.assign(0, yOff, 0); const Zeus::CColor& color = (r&1) ? theme.tableCellBg1() : theme.tableCellBg2();
v[0].m_color = (i&1) ? theme.tableCellBg1() : theme.tableCellBg2(); int xOff = 0;
for (c=0 ; c<std::min(SPECTER_TABLE_MAX_COLUMNS, m_t.m_columns) ; ++c)
{
v[0].m_pos.assign(xOff + margin, yOff - margin, 0);
v[0].m_color = color;
v[1] = v[0]; v[1] = v[0];
v[2].m_pos.assign(0, yOff - rowHeight, 0); v[2].m_pos.assign(xOff + margin, yOff - margin - rowHeight, 0);
v[2].m_color = v[0].m_color; v[2].m_color = color;
v[3].m_pos.assign(sub.size[0], yOff, 0); v[3].m_pos.assign(xOff + div - margin, yOff - margin, 0);
v[3].m_color = v[0].m_color; v[3].m_color = color;
v[4].m_pos.assign(sub.size[0], yOff - rowHeight, 0); v[4].m_pos.assign(xOff + div - margin, yOff - margin - rowHeight, 0);
v[4].m_color = v[0].m_color; v[4].m_color = color;
v[5] = v[4]; v[5] = v[4];
yOff -= spacing;
v += 6; v += 6;
xOff += div;
}
yOff -= spacing;
} }
m_visibleStart = startIdx; m_visibleStart = startIdx;
m_visibleRows = i; m_visibleRows = r;
m_vertsBuf->load(m_verts, sizeof(SolidShaderVert) * 6 * i); m_vertsBuf->load(m_verts, sizeof(SolidShaderVert) * 6 * r * c);
} }
void Table::setMultiplyColor(const Zeus::CColor& color) void Table::setMultiplyColor(const Zeus::CColor& color)
{ {
View::setMultiplyColor(color); View::setMultiplyColor(color);
if (m_scroll.m_view)
m_scroll.m_view->setMultiplyColor(color);
for (std::unique_ptr<CellView>& hv : m_headerViews) for (std::unique_ptr<CellView>& hv : m_headerViews)
if (hv) if (hv)
hv->m_text->setMultiplyColor(color); 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 int Table::RowsView::nominalHeight() const
{ {
float pf = rootView().viewRes().pixelFactor(); 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, 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; boo::SWindowRect cell = sub;
cell.size[1] = ROW_HEIGHT * pf; cell.size[1] = ROW_HEIGHT * pf;
cell.location[1] += sub.size[1] - cell.size[1]; 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]; int hStart = cell.location[1];
for (auto& col : m_t.m_cellViews) 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; boo::SWindowRect textRect = sub;
float pf = rootView().viewRes().pixelFactor(); float pf = rootView().viewRes().pixelFactor();
textRect.location[0] += 5 * pf; textRect.location[0] += 5 * pf;
textRect.location[1] += 6 * pf; textRect.location[1] += 5 * pf;
m_text->resized(root, textRect); m_text->resized(root, textRect);
} }
@ -271,7 +283,7 @@ void Table::RowsView::draw(boo::IGraphicsCommandQueue* gfxQ)
gfxQ->setScissor(m_scissorRect); gfxQ->setScissor(m_scissorRect);
size_t rows = std::min(m_visibleRows, m_t.m_rows); 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) for (auto& col : m_t.m_cellViews)
{ {
size_t idx = 0; size_t idx = 0;