2015-12-15 21:53:15 +00:00
|
|
|
#include "Specter/Table.hpp"
|
2015-12-23 00:25:46 +00:00
|
|
|
#include "Specter/ViewResources.hpp"
|
2015-12-29 02:02:43 +00:00
|
|
|
#include "Specter/RootView.hpp"
|
2016-01-13 01:31:50 +00:00
|
|
|
#include "Specter/ScrollView.hpp"
|
2015-12-15 21:53:15 +00:00
|
|
|
|
|
|
|
namespace Specter
|
|
|
|
{
|
2016-01-01 00:12:19 +00:00
|
|
|
static LogVisor::LogModule Log("Specter::Table");
|
2015-12-29 02:02:43 +00:00
|
|
|
#define ROW_HEIGHT 18
|
2015-12-30 02:20:24 +00:00
|
|
|
#define CELL_MARGIN 1
|
2015-12-15 21:53:15 +00:00
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
Table::Table(ViewResources& res, View& parentView, ITableDataBinding* data,
|
|
|
|
ITableStateBinding* state, size_t maxColumns)
|
2016-01-01 00:12:19 +00:00
|
|
|
: View(res, parentView), m_data(data), m_state(state), m_maxColumns(maxColumns),
|
|
|
|
m_hVerts(new SolidShaderVert[maxColumns * 6]), m_rowsView(*this, res)
|
2015-12-29 22:58:09 +00:00
|
|
|
{
|
2016-01-01 00:12:19 +00:00
|
|
|
if (!maxColumns)
|
|
|
|
Log.report(LogVisor::FatalError, "0-column tables not supported");
|
|
|
|
|
2016-01-08 00:06:21 +00:00
|
|
|
m_vertsBinding.initSolid(res, maxColumns * 6, m_viewVertBlockBuf);
|
2015-12-29 22:58:09 +00:00
|
|
|
commitResources(res);
|
|
|
|
|
2015-12-30 02:20:24 +00:00
|
|
|
m_scroll.m_view.reset(new ScrollView(res, *this, ScrollView::Style::ThinIndicator));
|
2015-12-29 22:58:09 +00:00
|
|
|
m_scroll.m_view->setContentView(&m_rowsView);
|
|
|
|
updateData();
|
|
|
|
}
|
|
|
|
|
|
|
|
Table::RowsView::RowsView(Table& t, ViewResources& res)
|
2015-12-31 20:26:04 +00:00
|
|
|
: View(res, t), m_t(t), m_verts(new SolidShaderVert[SPECTER_TABLE_MAX_ROWS * t.m_maxColumns * 6])
|
2015-12-15 21:53:15 +00:00
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
m_vertsBinding.initSolid(res, SPECTER_TABLE_MAX_ROWS * t.m_maxColumns * 6, m_viewVertBlockBuf);
|
2015-12-22 01:33:27 +00:00
|
|
|
commitResources(res);
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 00:06:21 +00:00
|
|
|
Table::CellView::CellView(Table& t, ViewResources& res)
|
|
|
|
: View(res, t), m_t(t), m_text(new TextView(res, *this, res.m_mainFont)), m_c(-1), m_r(-1) {}
|
2016-01-01 00:12:19 +00:00
|
|
|
|
|
|
|
void Table::_setHeaderVerts(const boo::SWindowRect& sub)
|
|
|
|
{;
|
|
|
|
if (m_headerViews.empty())
|
|
|
|
return;
|
|
|
|
SolidShaderVert* v = m_hVerts.get();
|
2016-01-10 06:40:23 +00:00
|
|
|
const IThemeData& theme = rootView().themeData();
|
2016-01-01 00:12:19 +00:00
|
|
|
|
|
|
|
float pf = rootView().viewRes().pixelFactor();
|
|
|
|
int margin = CELL_MARGIN * pf;
|
|
|
|
int rowHeight = ROW_HEIGHT * pf;
|
|
|
|
int xOff = 0;
|
|
|
|
int yOff = sub.size[1];
|
|
|
|
size_t c;
|
|
|
|
auto it = m_headerViews.cbegin();
|
|
|
|
|
|
|
|
size_t sCol = -1;
|
|
|
|
SortDirection sDir = SortDirection::None;
|
|
|
|
if (m_state)
|
|
|
|
sDir = m_state->getSort(sCol);
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
boo::SWindowRect headRowRect = sub;
|
|
|
|
headRowRect.size[1] = rowHeight;
|
|
|
|
headRowRect.location[1] = sub.size[1] - rowHeight;
|
|
|
|
m_hCellRects = getCellRects(headRowRect);
|
|
|
|
auto cellRectsIt = m_hCellRects.begin();
|
|
|
|
|
2016-01-01 00:12:19 +00:00
|
|
|
for (c=0 ; c<std::min(m_maxColumns, m_columns) ; ++c)
|
|
|
|
{
|
|
|
|
const ViewChild<std::unique_ptr<CellView>>& hv = *it;
|
|
|
|
const Zeus::CColor* c1 = &theme.button1Inactive();
|
|
|
|
const Zeus::CColor* c2 = &theme.button2Inactive();
|
|
|
|
if (hv.m_mouseDown && hv.m_mouseIn)
|
|
|
|
{
|
|
|
|
c1 = &theme.button1Press();
|
|
|
|
c2 = &theme.button2Press();
|
|
|
|
}
|
|
|
|
else if (hv.m_mouseIn)
|
|
|
|
{
|
|
|
|
c1 = &theme.button1Hover();
|
|
|
|
c2 = &theme.button2Hover();
|
|
|
|
}
|
|
|
|
|
|
|
|
Zeus::CColor cm1 = *c1;
|
|
|
|
Zeus::CColor cm2 = *c2;
|
|
|
|
if (sCol == c)
|
|
|
|
{
|
|
|
|
if (sDir == SortDirection::Ascending)
|
|
|
|
{
|
|
|
|
cm1 *= Zeus::CColor::skGreen;
|
|
|
|
cm2 *= Zeus::CColor::skGreen;
|
|
|
|
}
|
|
|
|
else if (sDir == SortDirection::Descending)
|
|
|
|
{
|
|
|
|
cm1 *= Zeus::CColor::skRed;
|
|
|
|
cm2 *= Zeus::CColor::skRed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
int div = cellRectsIt->size[0];
|
2016-01-01 00:12:19 +00:00
|
|
|
v[0].m_pos.assign(xOff + margin, yOff - margin, 0);
|
|
|
|
v[0].m_color = cm1;
|
|
|
|
v[1] = v[0];
|
|
|
|
v[2].m_pos.assign(xOff + margin, yOff - margin - rowHeight, 0);
|
|
|
|
v[2].m_color = cm2;
|
|
|
|
v[3].m_pos.assign(xOff + div - margin, yOff - margin, 0);
|
|
|
|
v[3].m_color = cm1;
|
|
|
|
v[4].m_pos.assign(xOff + div - margin, yOff - margin - rowHeight, 0);
|
|
|
|
v[4].m_color = cm2;
|
|
|
|
v[5] = v[4];
|
|
|
|
v += 6;
|
|
|
|
xOff += div;
|
|
|
|
++it;
|
2016-01-02 02:26:04 +00:00
|
|
|
++cellRectsIt;
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c)
|
2016-01-08 00:06:21 +00:00
|
|
|
m_vertsBinding.load(m_hVerts.get(), sizeof(SolidShaderVert) * 6 * c);
|
2016-01-01 00:12:19 +00:00
|
|
|
|
|
|
|
m_headerNeedsUpdate = false;
|
|
|
|
}
|
2015-12-29 02:02:43 +00:00
|
|
|
|
2015-12-29 22:58:09 +00:00
|
|
|
void Table::RowsView::_setRowVerts(const boo::SWindowRect& sub, const boo::SWindowRect& scissor)
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
2015-12-31 20:26:04 +00:00
|
|
|
SolidShaderVert* v = m_verts.get();
|
2016-01-10 06:40:23 +00:00
|
|
|
const IThemeData& theme = rootView().themeData();
|
2015-12-29 22:58:09 +00:00
|
|
|
|
2016-01-08 00:06:21 +00:00
|
|
|
if (m_t.m_cellPools.empty())
|
2015-12-29 22:58:09 +00:00
|
|
|
return;
|
|
|
|
|
2015-12-29 02:02:43 +00:00
|
|
|
float pf = rootView().viewRes().pixelFactor();
|
2015-12-30 02:20:24 +00:00
|
|
|
int spacing = (ROW_HEIGHT + CELL_MARGIN * 2) * pf;
|
|
|
|
int margin = CELL_MARGIN * pf;
|
2015-12-29 02:02:43 +00:00
|
|
|
int rowHeight = ROW_HEIGHT * pf;
|
2015-12-29 22:58:09 +00:00
|
|
|
int yOff = 0;
|
|
|
|
int idx = 0;
|
|
|
|
while (sub.location[1] + yOff < scissor.location[1] + scissor.size[1] || (idx & 1) != 0)
|
|
|
|
{
|
|
|
|
yOff += spacing;
|
|
|
|
++idx;
|
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
int startIdx = int(m_t.m_rows) - idx;
|
2016-01-02 02:26:04 +00:00
|
|
|
|
|
|
|
std::vector<boo::SWindowRect> cellRects = m_t.getCellRects(sub);
|
2015-12-29 22:58:09 +00:00
|
|
|
|
2015-12-30 02:20:24 +00:00
|
|
|
size_t r, c;
|
2016-01-02 02:26:04 +00:00
|
|
|
for (r=0, c=0 ; r<SPECTER_TABLE_MAX_ROWS &&
|
|
|
|
(sub.location[1] + yOff + spacing) >= scissor.location[1] ; ++r)
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
2016-01-01 00:12:19 +00:00
|
|
|
const Zeus::CColor& color = (startIdx+r==m_t.m_selectedRow) ? theme.tableCellBgSelected() :
|
|
|
|
((r&1) ? theme.tableCellBg1() : theme.tableCellBg2());
|
2015-12-30 02:20:24 +00:00
|
|
|
int xOff = 0;
|
2016-01-02 02:26:04 +00:00
|
|
|
auto cellRectsIt = cellRects.begin();
|
2015-12-31 20:26:04 +00:00
|
|
|
for (c=0 ; c<std::min(m_t.m_maxColumns, m_t.m_columns) ; ++c)
|
2015-12-30 02:20:24 +00:00
|
|
|
{
|
2016-01-02 02:26:04 +00:00
|
|
|
int div = cellRectsIt->size[0];
|
2015-12-30 02:20:24 +00:00
|
|
|
v[0].m_pos.assign(xOff + margin, yOff - margin, 0);
|
|
|
|
v[0].m_color = color;
|
|
|
|
v[1] = v[0];
|
|
|
|
v[2].m_pos.assign(xOff + margin, yOff - margin - rowHeight, 0);
|
|
|
|
v[2].m_color = color;
|
|
|
|
v[3].m_pos.assign(xOff + div - margin, yOff - margin, 0);
|
|
|
|
v[3].m_color = color;
|
|
|
|
v[4].m_pos.assign(xOff + div - margin, yOff - margin - rowHeight, 0);
|
|
|
|
v[4].m_color = color;
|
|
|
|
v[5] = v[4];
|
|
|
|
v += 6;
|
|
|
|
xOff += div;
|
2016-01-02 02:26:04 +00:00
|
|
|
++cellRectsIt;
|
2015-12-30 02:20:24 +00:00
|
|
|
}
|
2015-12-29 22:58:09 +00:00
|
|
|
yOff -= spacing;
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
m_visibleStart = std::max(0, startIdx);
|
2015-12-30 02:20:24 +00:00
|
|
|
m_visibleRows = r;
|
2015-12-31 06:37:32 +00:00
|
|
|
if (r * c)
|
2016-01-08 00:06:21 +00:00
|
|
|
m_vertsBinding.load(m_verts.get(), sizeof(SolidShaderVert) * 6 * r * c);
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Table::cycleSortColumn(size_t c)
|
|
|
|
{
|
|
|
|
if (c >= m_columns)
|
|
|
|
Log.report(LogVisor::FatalError, "cycleSortColumn out of bounds (%" PRISize ", %" PRISize ")",
|
|
|
|
c, m_columns);
|
|
|
|
if (m_state)
|
|
|
|
{
|
|
|
|
size_t cIdx;
|
|
|
|
SortDirection dir = m_state->getSort(cIdx);
|
|
|
|
if (dir == SortDirection::None || cIdx != c)
|
|
|
|
m_state->setSort(c, SortDirection::Ascending);
|
|
|
|
else if (dir == SortDirection::Ascending)
|
|
|
|
m_state->setSort(c, SortDirection::Descending);
|
|
|
|
else if (dir == SortDirection::Descending)
|
|
|
|
m_state->setSort(c, SortDirection::Ascending);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Table::selectRow(size_t r)
|
|
|
|
{
|
2016-01-03 04:04:02 +00:00
|
|
|
if (m_inSelectRow)
|
|
|
|
return;
|
2016-01-01 00:12:19 +00:00
|
|
|
if (r >= m_rows && r != -1)
|
|
|
|
Log.report(LogVisor::FatalError, "selectRow out of bounds (%" PRISize ", %" PRISize ")",
|
|
|
|
r, m_rows);
|
|
|
|
if (r == m_selectedRow)
|
2016-01-03 02:42:52 +00:00
|
|
|
{
|
|
|
|
if (m_state)
|
2016-01-03 04:04:02 +00:00
|
|
|
{
|
|
|
|
m_inSelectRow = true;
|
2016-01-03 02:42:52 +00:00
|
|
|
m_state->setSelectedRow(r);
|
2016-01-03 04:04:02 +00:00
|
|
|
m_inSelectRow = false;
|
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
return;
|
2016-01-03 02:42:52 +00:00
|
|
|
}
|
2016-01-08 00:06:21 +00:00
|
|
|
|
|
|
|
if (m_selectedRow != -1 && m_activePool != -1)
|
|
|
|
{
|
|
|
|
size_t poolIdx = m_selectedRow / SPECTER_TABLE_MAX_ROWS;
|
|
|
|
int pool0 = (poolIdx & 1) != 0;
|
|
|
|
int pool1 = (poolIdx & 1) == 0;
|
|
|
|
if (m_activePool == poolIdx)
|
2016-01-01 00:12:19 +00:00
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
for (auto& col : m_cellPools)
|
|
|
|
{
|
|
|
|
ViewChild<std::unique_ptr<CellView>>& cv = col[pool0].at(m_selectedRow % SPECTER_TABLE_MAX_ROWS);
|
|
|
|
if (cv.m_view)
|
|
|
|
cv.m_view->deselect();
|
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
2016-01-08 00:06:21 +00:00
|
|
|
else if (m_activePool+1 == poolIdx)
|
|
|
|
{
|
|
|
|
for (auto& col : m_cellPools)
|
|
|
|
{
|
|
|
|
ViewChild<std::unique_ptr<CellView>>& cv = col[pool1].at(m_selectedRow % SPECTER_TABLE_MAX_ROWS);
|
|
|
|
if (cv.m_view)
|
|
|
|
cv.m_view->deselect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-01 00:12:19 +00:00
|
|
|
m_selectedRow = r;
|
2016-01-08 00:06:21 +00:00
|
|
|
|
|
|
|
if (m_selectedRow != -1 && m_activePool != -1)
|
|
|
|
{
|
|
|
|
size_t poolIdx = m_selectedRow / SPECTER_TABLE_MAX_ROWS;
|
|
|
|
int pool0 = (poolIdx & 1) != 0;
|
|
|
|
int pool1 = (poolIdx & 1) == 0;
|
|
|
|
if (m_activePool == poolIdx)
|
2016-01-01 00:12:19 +00:00
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
for (auto& col : m_cellPools)
|
|
|
|
{
|
|
|
|
ViewChild<std::unique_ptr<CellView>>& cv = col[pool0].at(m_selectedRow % SPECTER_TABLE_MAX_ROWS);
|
|
|
|
if (cv.m_view)
|
|
|
|
cv.m_view->select();
|
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
2016-01-08 00:06:21 +00:00
|
|
|
else if (m_activePool+1 == poolIdx)
|
|
|
|
{
|
|
|
|
for (auto& col : m_cellPools)
|
|
|
|
{
|
|
|
|
ViewChild<std::unique_ptr<CellView>>& cv = col[pool1].at(m_selectedRow % SPECTER_TABLE_MAX_ROWS);
|
|
|
|
if (cv.m_view)
|
|
|
|
cv.m_view->select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-01 00:12:19 +00:00
|
|
|
updateSize();
|
2016-01-08 00:06:21 +00:00
|
|
|
|
2016-01-01 00:12:19 +00:00
|
|
|
if (m_state)
|
2016-01-03 04:04:02 +00:00
|
|
|
{
|
|
|
|
m_inSelectRow = true;
|
2016-01-01 00:12:19 +00:00
|
|
|
m_state->setSelectedRow(r);
|
2016-01-03 04:04:02 +00:00
|
|
|
m_inSelectRow = false;
|
|
|
|
}
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Table::setMultiplyColor(const Zeus::CColor& color)
|
|
|
|
{
|
|
|
|
View::setMultiplyColor(color);
|
2015-12-30 02:20:24 +00:00
|
|
|
if (m_scroll.m_view)
|
|
|
|
m_scroll.m_view->setMultiplyColor(color);
|
2016-01-01 00:12:19 +00:00
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& hv : m_headerViews)
|
|
|
|
if (hv.m_view)
|
|
|
|
hv.m_view->m_text->setMultiplyColor(color);
|
2016-01-08 00:06:21 +00:00
|
|
|
for (auto& col : m_cellPools)
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[0])
|
|
|
|
if (cv.m_view)
|
|
|
|
cv.m_view->m_text->setMultiplyColor(color);
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[1])
|
2016-01-01 00:12:19 +00:00
|
|
|
if (cv.m_view)
|
|
|
|
cv.m_view->m_text->setMultiplyColor(color);
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
2015-12-23 00:25:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-01 00:12:19 +00:00
|
|
|
void Table::CellView::select()
|
|
|
|
{
|
|
|
|
m_selected = true;
|
|
|
|
m_text->colorGlyphs(rootView().themeData().fieldText());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Table::CellView::deselect()
|
|
|
|
{
|
|
|
|
m_selected = false;
|
|
|
|
m_text->colorGlyphs(rootView().themeData().uiText());
|
|
|
|
}
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
void Table::mouseDown(const boo::SWindowCoord& coord,
|
|
|
|
boo::EMouseButton button, boo::EModifierKey mod)
|
2015-12-23 00:25:46 +00:00
|
|
|
{
|
2016-01-02 02:26:04 +00:00
|
|
|
if (m_state && m_state->columnSplitResizeAllowed())
|
|
|
|
{
|
|
|
|
size_t cIdx = 0;
|
|
|
|
for (const boo::SWindowRect& rect : m_hCellRects)
|
|
|
|
{
|
|
|
|
if (cIdx == 0)
|
|
|
|
{
|
|
|
|
++cIdx;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (abs(coord.pixel[0] - rect.location[0]) < 4 &&
|
|
|
|
unsigned(coord.pixel[1] - subRect().location[1] -
|
2016-01-02 04:17:47 +00:00
|
|
|
subRect().size[1] + rect.size[1]) < unsigned(rect.size[1]))
|
2016-01-02 02:26:04 +00:00
|
|
|
{
|
|
|
|
m_hDraggingIdx = cIdx;
|
|
|
|
rootView().setActiveDragView(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
++cIdx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-23 00:25:46 +00:00
|
|
|
m_scroll.mouseDown(coord, button, mod);
|
2016-01-01 00:12:19 +00:00
|
|
|
if (m_headerNeedsUpdate)
|
|
|
|
_setHeaderVerts(subRect());
|
2016-01-02 04:17:47 +00:00
|
|
|
|
|
|
|
if (m_deferredActivation != -1 && m_state)
|
|
|
|
{
|
|
|
|
m_state->rowActivated(m_deferredActivation);
|
|
|
|
m_deferredActivation = -1;
|
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
void Table::RowsView::mouseDown(const boo::SWindowCoord& coord,
|
|
|
|
boo::EMouseButton button, boo::EModifierKey mod)
|
2016-01-01 00:12:19 +00:00
|
|
|
{
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
|
|
|
|
if (hv.mouseDown(coord, button, mod))
|
|
|
|
return; /* Trap header event */
|
2016-01-08 00:06:21 +00:00
|
|
|
for (auto& col : m_t.m_cellPools)
|
|
|
|
{
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[0])
|
|
|
|
cv.mouseDown(coord, button, mod);
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[1])
|
2016-01-01 00:12:19 +00:00
|
|
|
cv.mouseDown(coord, button, mod);
|
2016-01-08 00:06:21 +00:00
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
void Table::CellView::mouseDown(const boo::SWindowCoord& coord,
|
|
|
|
boo::EMouseButton button, boo::EModifierKey mod)
|
2016-01-01 00:12:19 +00:00
|
|
|
{
|
|
|
|
if (m_r != -1)
|
|
|
|
{
|
|
|
|
m_t.selectRow(m_r);
|
2016-01-02 04:17:47 +00:00
|
|
|
if (m_t.m_clickFrames < 15)
|
|
|
|
m_t.m_deferredActivation = m_r;
|
2016-01-01 00:12:19 +00:00
|
|
|
else
|
|
|
|
m_t.m_clickFrames = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_t.m_headerNeedsUpdate = true;
|
2015-12-23 00:25:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
void Table::mouseUp(const boo::SWindowCoord& coord,
|
|
|
|
boo::EMouseButton button, boo::EModifierKey mod)
|
2015-12-23 00:25:46 +00:00
|
|
|
{
|
|
|
|
m_scroll.mouseUp(coord, button, mod);
|
2016-01-01 00:12:19 +00:00
|
|
|
if (m_headerNeedsUpdate)
|
|
|
|
_setHeaderVerts(subRect());
|
2016-01-02 02:26:04 +00:00
|
|
|
if (m_hDraggingIdx)
|
|
|
|
{
|
|
|
|
rootView().setActiveDragView(nullptr);
|
|
|
|
m_hDraggingIdx = 0;
|
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
void Table::RowsView::mouseUp(const boo::SWindowCoord& coord,
|
|
|
|
boo::EMouseButton button, boo::EModifierKey mod)
|
2016-01-01 00:12:19 +00:00
|
|
|
{
|
|
|
|
size_t idx = 0;
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
|
|
|
|
{
|
|
|
|
if (hv.m_mouseDown && hv.m_mouseIn)
|
|
|
|
m_t.cycleSortColumn(idx);
|
|
|
|
hv.mouseUp(coord, button, mod);
|
|
|
|
++idx;
|
|
|
|
}
|
2016-01-08 00:06:21 +00:00
|
|
|
for (auto& col : m_t.m_cellPools)
|
|
|
|
{
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[0])
|
2016-01-01 00:12:19 +00:00
|
|
|
cv.mouseUp(coord, button, mod);
|
2016-01-08 00:06:21 +00:00
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[1])
|
|
|
|
cv.mouseUp(coord, button, mod);
|
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
void Table::CellView::mouseUp(const boo::SWindowCoord& coord,
|
|
|
|
boo::EMouseButton button, boo::EModifierKey mod)
|
2016-01-01 00:12:19 +00:00
|
|
|
{
|
|
|
|
if (m_r == -1)
|
|
|
|
m_t.m_headerNeedsUpdate = true;
|
2015-12-23 00:25:46 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 02:02:43 +00:00
|
|
|
void Table::mouseMove(const boo::SWindowCoord& coord)
|
|
|
|
{
|
2016-01-02 02:26:04 +00:00
|
|
|
if (m_state && m_state->columnSplitResizeAllowed())
|
|
|
|
{
|
|
|
|
if (m_hDraggingIdx)
|
|
|
|
{
|
|
|
|
float split = (coord.pixel[0] - subRect().location[0]) / float(subRect().size[0]);
|
|
|
|
|
|
|
|
if (m_hDraggingIdx <= 1)
|
|
|
|
split = std::max(0.03f, split);
|
|
|
|
else
|
|
|
|
split = std::max(m_state->getColumnSplit(m_hDraggingIdx-1)+0.03f, split);
|
|
|
|
|
|
|
|
if (m_hDraggingIdx >= m_columns - 1)
|
|
|
|
split = std::min(0.97f, split);
|
|
|
|
else
|
|
|
|
split = std::min(m_state->getColumnSplit(m_hDraggingIdx+1)-0.03f, split);
|
|
|
|
|
|
|
|
m_state->setColumnSplit(m_hDraggingIdx, split);
|
|
|
|
updateSize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
size_t cIdx = 0;
|
|
|
|
bool hovering = false;
|
|
|
|
for (const boo::SWindowRect& rect : m_hCellRects)
|
|
|
|
{
|
|
|
|
if (cIdx++ == 0)
|
|
|
|
continue;
|
|
|
|
if (abs(coord.pixel[0] - rect.location[0]) < 4 &&
|
|
|
|
unsigned(coord.pixel[1] - subRect().location[1] -
|
2016-01-02 04:17:47 +00:00
|
|
|
subRect().size[1] + rect.size[1]) < unsigned(rect.size[1]))
|
2016-01-02 02:26:04 +00:00
|
|
|
{
|
|
|
|
hovering = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rootView().setVerticalSplitHover(hovering);
|
|
|
|
}
|
|
|
|
|
2015-12-29 02:02:43 +00:00
|
|
|
m_scroll.mouseMove(coord);
|
2016-01-01 00:12:19 +00:00
|
|
|
if (m_headerNeedsUpdate)
|
|
|
|
_setHeaderVerts(subRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Table::RowsView::mouseMove(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
|
|
|
|
hv.mouseMove(coord);
|
2016-01-08 00:06:21 +00:00
|
|
|
for (auto& col : m_t.m_cellPools)
|
|
|
|
{
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[0])
|
2016-01-01 00:12:19 +00:00
|
|
|
cv.mouseMove(coord);
|
2016-01-08 00:06:21 +00:00
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[1])
|
|
|
|
cv.mouseMove(coord);
|
|
|
|
}
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
|
|
|
|
2015-12-23 00:25:46 +00:00
|
|
|
void Table::mouseEnter(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
m_scroll.mouseEnter(coord);
|
2016-01-01 00:12:19 +00:00
|
|
|
if (m_headerNeedsUpdate)
|
|
|
|
_setHeaderVerts(subRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Table::CellView::mouseEnter(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
if (m_r == -1)
|
|
|
|
m_t.m_headerNeedsUpdate = true;
|
2015-12-23 00:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Table::mouseLeave(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
m_scroll.mouseLeave(coord);
|
2016-01-01 00:12:19 +00:00
|
|
|
if (m_headerNeedsUpdate)
|
|
|
|
_setHeaderVerts(subRect());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Table::RowsView::mouseLeave(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
|
|
|
|
hv.mouseLeave(coord);
|
2016-01-08 00:06:21 +00:00
|
|
|
for (auto& col : m_t.m_cellPools)
|
|
|
|
{
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[0])
|
|
|
|
cv.mouseLeave(coord);
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[1])
|
2016-01-01 00:12:19 +00:00
|
|
|
cv.mouseLeave(coord);
|
2016-01-08 00:06:21 +00:00
|
|
|
}
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Table::CellView::mouseLeave(const boo::SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
if (m_r == -1)
|
|
|
|
m_t.m_headerNeedsUpdate = true;
|
2015-12-23 00:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Table::scroll(const boo::SWindowCoord& coord, const boo::SScrollDelta& scroll)
|
|
|
|
{
|
|
|
|
m_scroll.scroll(coord, scroll);
|
|
|
|
}
|
|
|
|
|
2015-12-29 22:58:09 +00:00
|
|
|
void Table::think()
|
|
|
|
{
|
|
|
|
if (m_scroll.m_view)
|
|
|
|
m_scroll.m_view->think();
|
2016-01-01 00:12:19 +00:00
|
|
|
++m_clickFrames;
|
2015-12-29 22:58:09 +00:00
|
|
|
}
|
2016-01-08 00:06:21 +00:00
|
|
|
|
|
|
|
void Table::CellView::reset()
|
|
|
|
{
|
|
|
|
m_c = -1;
|
|
|
|
m_r = -1;
|
|
|
|
if (m_textHash)
|
|
|
|
{
|
|
|
|
m_text->typesetGlyphs("");
|
|
|
|
m_textHash = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Table::CellView::reset(size_t c)
|
|
|
|
{
|
|
|
|
m_c = c;
|
|
|
|
m_r = -1;
|
|
|
|
const std::string* headerText = m_t.m_data->header(c);
|
|
|
|
if (headerText)
|
|
|
|
{
|
|
|
|
uint64_t hash = XXH64(headerText->data(), headerText->size(), 0);
|
|
|
|
if (hash != m_textHash)
|
|
|
|
{
|
|
|
|
m_text->typesetGlyphs(*headerText, rootView().themeData().uiText());
|
|
|
|
m_textHash = hash;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (m_textHash)
|
|
|
|
{
|
|
|
|
m_text->typesetGlyphs("");
|
|
|
|
m_textHash = 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-29 22:58:09 +00:00
|
|
|
|
2016-01-08 00:06:21 +00:00
|
|
|
bool Table::CellView::reset(size_t c, size_t r)
|
|
|
|
{
|
|
|
|
m_c = c;
|
|
|
|
m_r = r;
|
|
|
|
const std::string* cellText = m_t.m_data->cell(c, r);
|
|
|
|
if (cellText)
|
|
|
|
{
|
|
|
|
uint64_t hash = XXH64(cellText->data(), cellText->size(), 0);
|
|
|
|
if (hash != m_textHash)
|
|
|
|
{
|
|
|
|
m_text->typesetGlyphs(*cellText, rootView().themeData().uiText());
|
|
|
|
m_textHash = hash;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (m_textHash)
|
|
|
|
{
|
|
|
|
m_text->typesetGlyphs("");
|
|
|
|
m_textHash = 0;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<Table::ColumnPool>& Table::ensureCellPools(size_t rows, size_t cols, ViewResources& res)
|
|
|
|
{
|
|
|
|
if (m_cellPools.size() < cols)
|
|
|
|
{
|
|
|
|
m_cellPools.reserve(cols);
|
|
|
|
for (size_t i=m_cellPools.size() ; i<cols ; ++i)
|
|
|
|
m_cellPools.emplace_back();
|
|
|
|
m_ensuredRows = 0;
|
|
|
|
}
|
|
|
|
if (m_ensuredRows < rows)
|
|
|
|
{
|
|
|
|
for (size_t i=0 ; i<cols ; ++i)
|
|
|
|
{
|
|
|
|
ColumnPool& cp = m_cellPools[i];
|
|
|
|
if (rows > SPECTER_TABLE_MAX_ROWS)
|
|
|
|
{
|
|
|
|
for (int p=0 ; p<2 ; ++p)
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : cp[p])
|
|
|
|
if (!cv.m_view)
|
|
|
|
cv.m_view.reset(new CellView(*this, res));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size_t r = 0;
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : cp[0])
|
|
|
|
{
|
|
|
|
if (!cv.m_view)
|
|
|
|
cv.m_view.reset(new CellView(*this, res));
|
|
|
|
++r;
|
|
|
|
if (r >= rows)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_ensuredRows = rows;
|
|
|
|
}
|
|
|
|
return m_cellPools;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Table::_updateData()
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
|
|
|
m_header = false;
|
2016-01-01 00:12:19 +00:00
|
|
|
bool newViewChildren = false;
|
2016-01-08 00:06:21 +00:00
|
|
|
if (m_columns != m_data->columnCount() || m_rows > m_data->rowCount() + SPECTER_TABLE_MAX_ROWS)
|
2016-01-01 00:12:19 +00:00
|
|
|
newViewChildren = true;
|
|
|
|
|
2015-12-29 02:02:43 +00:00
|
|
|
m_rows = m_data->rowCount();
|
|
|
|
m_columns = m_data->columnCount();
|
|
|
|
if (!m_columns)
|
|
|
|
return;
|
|
|
|
|
2016-01-08 00:06:21 +00:00
|
|
|
ViewResources& res = rootView().viewRes();
|
2016-01-01 00:12:19 +00:00
|
|
|
if (newViewChildren)
|
|
|
|
{
|
|
|
|
m_headerViews.clear();
|
2016-01-08 00:06:21 +00:00
|
|
|
m_cellPools.clear();
|
2016-01-01 00:12:19 +00:00
|
|
|
m_headerViews.reserve(m_columns);
|
|
|
|
for (size_t c=0 ; c<m_columns ; ++c)
|
|
|
|
m_headerViews.emplace_back();
|
2016-01-08 00:06:21 +00:00
|
|
|
m_ensuredRows = 0;
|
2016-01-01 00:12:19 +00:00
|
|
|
}
|
2016-01-08 00:06:21 +00:00
|
|
|
ensureCellPools(m_rows, m_columns, res);
|
|
|
|
|
|
|
|
size_t poolIdx = m_rowsView.m_visibleStart / SPECTER_TABLE_MAX_ROWS;
|
|
|
|
size_t startRow = poolIdx * SPECTER_TABLE_MAX_ROWS;
|
|
|
|
int pool0 = (poolIdx & 1) != 0;
|
|
|
|
int pool1 = (poolIdx & 1) == 0;
|
|
|
|
|
2015-12-29 02:02:43 +00:00
|
|
|
for (size_t c=0 ; c<m_columns ; ++c)
|
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
std::unique_ptr<CellView>& cv = m_headerViews[c].m_view;
|
|
|
|
if (!cv)
|
|
|
|
cv.reset(new CellView(*this, res));
|
|
|
|
if (cv->reset(c))
|
2015-12-29 02:02:43 +00:00
|
|
|
m_header = true;
|
|
|
|
|
2016-01-08 00:06:21 +00:00
|
|
|
ColumnPool& col = m_cellPools[c];
|
|
|
|
|
|
|
|
if (poolIdx != m_activePool)
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
for (size_t r=startRow, i=0 ; i<SPECTER_TABLE_MAX_ROWS ; ++r, ++i)
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
ViewChild<std::unique_ptr<CellView>>& cv = col[pool0][i];
|
|
|
|
if (cv.m_view)
|
|
|
|
{
|
|
|
|
if (r < m_rows)
|
|
|
|
cv.m_view->reset(c, r);
|
|
|
|
else
|
|
|
|
cv.m_view->reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (size_t r=startRow+SPECTER_TABLE_MAX_ROWS, i=0 ; i<SPECTER_TABLE_MAX_ROWS ; ++r, ++i)
|
|
|
|
{
|
|
|
|
ViewChild<std::unique_ptr<CellView>>& cv = col[pool1][i];
|
|
|
|
if (cv.m_view)
|
|
|
|
{
|
|
|
|
if (r < m_rows)
|
|
|
|
cv.m_view->reset(c, r);
|
|
|
|
else
|
|
|
|
cv.m_view->reset();
|
|
|
|
}
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-08 00:06:21 +00:00
|
|
|
|
|
|
|
m_activePool = poolIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Table::updateData()
|
|
|
|
{
|
|
|
|
m_activePool = -1;
|
2015-12-29 02:02:43 +00:00
|
|
|
updateSize();
|
|
|
|
}
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
std::vector<boo::SWindowRect> Table::getCellRects(const boo::SWindowRect& sub) const
|
|
|
|
{
|
|
|
|
if (!m_columns)
|
|
|
|
return {};
|
|
|
|
float pf = rootView().viewRes().pixelFactor();
|
|
|
|
|
|
|
|
/* Validate column split values */
|
|
|
|
bool valid = false;
|
|
|
|
std::vector<float> splits;
|
|
|
|
splits.reserve(m_columns);
|
|
|
|
if (m_state)
|
|
|
|
{
|
|
|
|
float lastSplit = 0.0;
|
|
|
|
size_t i;
|
|
|
|
for (i=0 ; i<m_columns ; ++i)
|
|
|
|
{
|
|
|
|
float split = m_state->getColumnSplit(i);
|
|
|
|
if (split < lastSplit || split < 0.0 || split > 1.0)
|
|
|
|
break;
|
|
|
|
splits.push_back(split);
|
|
|
|
lastSplit = split;
|
|
|
|
}
|
|
|
|
if (i == m_columns)
|
|
|
|
valid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Uniform split otherwise */
|
|
|
|
if (!valid)
|
|
|
|
{
|
|
|
|
float split = 0.0;
|
|
|
|
for (size_t i=0 ; i<m_columns ; ++i)
|
|
|
|
{
|
|
|
|
splits.push_back(split);
|
|
|
|
split += 1.0 / float(m_columns);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<boo::SWindowRect> ret;
|
|
|
|
ret.reserve(m_columns);
|
|
|
|
|
|
|
|
int lastX = 0;
|
|
|
|
for (size_t i=0 ; i<m_columns ; ++i)
|
|
|
|
{
|
|
|
|
float nextSplit = (i==m_columns-1) ? 1.0 : splits[i+1];
|
|
|
|
int x = nextSplit * sub.size[0];
|
2016-01-02 21:18:15 +00:00
|
|
|
ret.push_back({sub.location[0] + lastX, sub.location[1],
|
|
|
|
x - lastX, int(ROW_HEIGHT * pf)});
|
2016-01-02 02:26:04 +00:00
|
|
|
lastX = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-23 00:25:46 +00:00
|
|
|
void Table::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub)
|
|
|
|
{
|
2015-12-29 02:02:43 +00:00
|
|
|
View::resized(root, sub);
|
|
|
|
if (m_scroll.m_view)
|
|
|
|
m_scroll.m_view->resized(root, sub);
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
boo::SWindowRect headRow = sub;
|
2015-12-29 02:02:43 +00:00
|
|
|
float pf = rootView().viewRes().pixelFactor();
|
2016-01-02 02:26:04 +00:00
|
|
|
headRow.location[1] += sub.size[1] - ROW_HEIGHT * pf;
|
|
|
|
std::vector<boo::SWindowRect> cellRects = getCellRects(headRow);
|
2016-01-01 00:12:19 +00:00
|
|
|
_setHeaderVerts(sub);
|
2016-01-02 02:26:04 +00:00
|
|
|
size_t cIdx = 0;
|
2016-01-01 00:12:19 +00:00
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& hv : m_headerViews)
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
2016-01-01 00:12:19 +00:00
|
|
|
if (hv.m_view)
|
2016-01-02 02:26:04 +00:00
|
|
|
hv.m_view->resized(root, cellRects[cIdx], sub);
|
|
|
|
++cIdx;
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
2015-12-29 22:58:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Table::RowsView::nominalHeight() const
|
|
|
|
{
|
|
|
|
float pf = rootView().viewRes().pixelFactor();
|
2016-01-08 00:06:21 +00:00
|
|
|
int rows = m_t.m_rows + 1;
|
2015-12-30 02:20:24 +00:00
|
|
|
return rows * (ROW_HEIGHT + CELL_MARGIN * 2) * pf;
|
2015-12-29 22:58:09 +00:00
|
|
|
}
|
2015-12-29 02:02:43 +00:00
|
|
|
|
2015-12-29 22:58:09 +00:00
|
|
|
void Table::RowsView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub,
|
|
|
|
const boo::SWindowRect& scissor)
|
|
|
|
{
|
|
|
|
View::resized(root, sub);
|
|
|
|
_setRowVerts(sub, scissor);
|
2016-01-08 00:06:21 +00:00
|
|
|
m_t._updateData();
|
2015-12-29 22:58:09 +00:00
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
if (!m_t.m_columns)
|
2015-12-29 22:58:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
float pf = rootView().viewRes().pixelFactor();
|
2016-01-03 05:17:18 +00:00
|
|
|
boo::SWindowRect cellScissor = scissor;
|
|
|
|
cellScissor.size[1] -= 2 * pf;
|
2016-01-02 02:26:04 +00:00
|
|
|
boo::SWindowRect rowRect = sub;
|
|
|
|
rowRect.location[1] += sub.size[1] - ROW_HEIGHT * pf;
|
2015-12-30 02:20:24 +00:00
|
|
|
int spacing = (ROW_HEIGHT + CELL_MARGIN * 2) * pf;
|
2016-01-02 02:26:04 +00:00
|
|
|
std::vector<boo::SWindowRect> cellRects = m_t.getCellRects(rowRect);
|
|
|
|
auto cellRectIt = cellRects.begin();
|
2016-01-08 00:06:21 +00:00
|
|
|
int poolIdx = m_visibleStart / SPECTER_TABLE_MAX_ROWS;
|
|
|
|
int pool0 = (poolIdx & 1) != 0;
|
|
|
|
int pool1 = (poolIdx & 1) == 0;
|
|
|
|
int locationStart = spacing * poolIdx * SPECTER_TABLE_MAX_ROWS;
|
|
|
|
for (auto& col : m_t.m_cellPools)
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
cellRectIt->location[1] -= locationStart;
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[pool0])
|
|
|
|
{
|
|
|
|
cellRectIt->location[1] -= spacing;
|
|
|
|
if (cv.m_view)
|
|
|
|
cv.m_view->resized(root, *cellRectIt, cellScissor);
|
|
|
|
}
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[pool1])
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
2016-01-02 02:26:04 +00:00
|
|
|
cellRectIt->location[1] -= spacing;
|
2016-01-01 00:12:19 +00:00
|
|
|
if (cv.m_view)
|
2016-01-03 05:17:18 +00:00
|
|
|
cv.m_view->resized(root, *cellRectIt, cellScissor);
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
2016-01-02 02:26:04 +00:00
|
|
|
++cellRectIt;
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
|
|
|
|
2015-12-29 22:58:09 +00:00
|
|
|
m_scissorRect = scissor;
|
|
|
|
m_scissorRect.size[1] -= spacing;
|
2015-12-23 00:25:46 +00:00
|
|
|
}
|
|
|
|
|
2016-01-02 02:26:04 +00:00
|
|
|
void Table::CellView::resized(const boo::SWindowRect& root, const boo::SWindowRect& sub,
|
|
|
|
const boo::SWindowRect& scissor)
|
2015-12-23 00:25:46 +00:00
|
|
|
{
|
2015-12-29 02:02:43 +00:00
|
|
|
View::resized(root, sub);
|
|
|
|
boo::SWindowRect textRect = sub;
|
|
|
|
float pf = rootView().viewRes().pixelFactor();
|
|
|
|
textRect.location[0] += 5 * pf;
|
2015-12-30 02:20:24 +00:00
|
|
|
textRect.location[1] += 5 * pf;
|
2015-12-29 02:02:43 +00:00
|
|
|
m_text->resized(root, textRect);
|
2016-01-02 02:26:04 +00:00
|
|
|
m_scissorRect = sub.intersect(scissor);
|
2015-12-23 00:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Table::draw(boo::IGraphicsCommandQueue* gfxQ)
|
|
|
|
{
|
2015-12-29 02:02:43 +00:00
|
|
|
if (m_scroll.m_view)
|
|
|
|
m_scroll.m_view->draw(gfxQ);
|
2015-12-23 00:25:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Table::RowsView::draw(boo::IGraphicsCommandQueue* gfxQ)
|
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
gfxQ->setShaderDataBinding(m_vertsBinding);
|
2015-12-29 02:02:43 +00:00
|
|
|
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
|
2015-12-29 22:58:09 +00:00
|
|
|
|
|
|
|
gfxQ->setScissor(m_scissorRect);
|
2015-12-30 22:04:58 +00:00
|
|
|
gfxQ->draw(1, m_visibleRows * m_t.m_columns * 6 - 2);
|
2016-01-08 00:06:21 +00:00
|
|
|
|
|
|
|
int poolIdx = m_t.m_activePool;
|
|
|
|
int pool0 = (poolIdx & 1) != 0;
|
|
|
|
int pool1 = (poolIdx & 1) == 0;
|
|
|
|
for (auto& col : m_t.m_cellPools)
|
2015-12-29 02:02:43 +00:00
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
size_t idx = poolIdx * SPECTER_TABLE_MAX_ROWS;
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[pool0])
|
|
|
|
{
|
|
|
|
if (cv.m_view && idx >= m_visibleStart && idx < m_visibleStart + m_visibleRows)
|
|
|
|
cv.m_view->draw(gfxQ);
|
|
|
|
++idx;
|
|
|
|
}
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& cv : col[pool1])
|
2015-12-29 22:58:09 +00:00
|
|
|
{
|
2016-01-01 00:12:19 +00:00
|
|
|
if (cv.m_view && idx >= m_visibleStart && idx < m_visibleStart + m_visibleRows)
|
|
|
|
cv.m_view->draw(gfxQ);
|
2015-12-29 22:58:09 +00:00
|
|
|
++idx;
|
|
|
|
}
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
2015-12-29 22:58:09 +00:00
|
|
|
|
2015-12-30 22:04:58 +00:00
|
|
|
if (m_t.m_header)
|
|
|
|
{
|
2016-01-08 00:06:21 +00:00
|
|
|
gfxQ->setShaderDataBinding(m_t.m_vertsBinding);
|
2016-01-01 00:12:19 +00:00
|
|
|
gfxQ->setDrawPrimitive(boo::Primitive::TriStrips);
|
2016-01-02 02:26:04 +00:00
|
|
|
gfxQ->setScissor(rootView().subRect());
|
2016-01-01 00:12:19 +00:00
|
|
|
gfxQ->draw(1, m_t.m_columns * 6 - 2);
|
|
|
|
for (ViewChild<std::unique_ptr<CellView>>& hv : m_t.m_headerViews)
|
|
|
|
if (hv.m_view)
|
|
|
|
hv.m_view->draw(gfxQ);
|
2015-12-30 22:04:58 +00:00
|
|
|
}
|
2016-01-02 02:26:04 +00:00
|
|
|
|
|
|
|
gfxQ->setScissor(rootView().subRect());
|
2015-12-29 02:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Table::CellView::draw(boo::IGraphicsCommandQueue* gfxQ)
|
|
|
|
{
|
2016-01-02 02:26:04 +00:00
|
|
|
if (m_scissorRect.size[0] && m_scissorRect.size[1])
|
|
|
|
{
|
|
|
|
gfxQ->setScissor(m_scissorRect);
|
|
|
|
m_text->draw(gfxQ);
|
|
|
|
}
|
2015-12-15 21:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|