2013-06-19 01:12:30 +00:00
|
|
|
#include "ComponentListComponent.h"
|
|
|
|
#include "../Log.h"
|
|
|
|
#include "../Renderer.h"
|
|
|
|
|
|
|
|
#define INITIAL_CELL_SIZE 12
|
|
|
|
|
2013-08-21 19:49:33 +00:00
|
|
|
ComponentListComponent::ComponentListComponent(Window* window, Eigen::Vector2i gridDimensions) : GuiComponent(window),
|
|
|
|
mGrid(NULL), mColumnWidths(NULL), mRowHeights(NULL),
|
|
|
|
mColumnWidthForced(NULL), mRowHeightForced(NULL),
|
|
|
|
mCursor(-1, -1)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
mEntries.reserve(gridDimensions.x() * gridDimensions.y());
|
2013-06-19 01:12:30 +00:00
|
|
|
makeCells(gridDimensions);
|
|
|
|
}
|
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
ComponentListComponent::~ComponentListComponent()
|
|
|
|
{
|
|
|
|
for(auto iter = mEntries.begin(); iter != mEntries.end(); iter++)
|
|
|
|
{
|
|
|
|
delete *iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void ComponentListComponent::makeCells(Eigen::Vector2i size)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
if(mGrid)
|
|
|
|
delete[] mGrid;
|
|
|
|
if(mColumnWidths)
|
|
|
|
delete[] mColumnWidths;
|
|
|
|
if(mRowHeights)
|
|
|
|
delete[] mRowHeights;
|
|
|
|
|
|
|
|
mGridSize = size;
|
2013-07-10 11:29:43 +00:00
|
|
|
mGrid = new ComponentEntry*[size.x() * size.y()];
|
|
|
|
std::fill(mGrid, mGrid + (size.x() * size.y()), (ComponentEntry*)NULL);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
mColumnWidths = new unsigned int[size.x()];
|
|
|
|
std::fill(mColumnWidths, mColumnWidths + size.x(), INITIAL_CELL_SIZE);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
mRowHeights = new unsigned int[size.y()];
|
|
|
|
std::fill(mRowHeights, mRowHeights + size.y(), INITIAL_CELL_SIZE);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-08-21 19:49:33 +00:00
|
|
|
mColumnWidthForced = new bool[size.x()];
|
|
|
|
std::fill(mColumnWidthForced, mColumnWidthForced + size.x(), false);
|
|
|
|
|
|
|
|
mRowHeightForced = new bool[size.y()];
|
|
|
|
std::fill(mRowHeightForced, mRowHeightForced + size.y(), false);
|
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
updateSize();
|
|
|
|
resetCursor();
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void ComponentListComponent::setEntry(Eigen::Vector2i pos, Eigen::Vector2i size, GuiComponent* component, bool canFocus, AlignmentType align,
|
|
|
|
Eigen::Matrix<bool, 1, 2> autoFit, UpdateBehavior updateType)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
if(pos.x() > mGridSize.x() || pos.y() > mGridSize.y() || pos.x() < 0 || pos.y() < 0)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
LOG(LogError) << "Tried to set entry beyond grid size!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(component == NULL)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "Tried to add NULL component to ComponentList!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
ComponentEntry* entry = new ComponentEntry(Eigen::Vector2i(pos.x(), pos.y()), Eigen::Vector2i(size.x(), size.y()), component, updateType, canFocus, align);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
mEntries.push_back(entry);
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
for(int y = pos.y(); y < pos.y() + size.y(); y++)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
for(int x = pos.x(); x < pos.x() + size.x(); x++)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-09-19 23:41:14 +00:00
|
|
|
setCell(x, y, mEntries.back());
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(component->getParent() != NULL)
|
|
|
|
LOG(LogError) << "ComponentListComponent ruining an existing parent-child relationship! Call a social worker!";
|
|
|
|
component->setParent(this);
|
|
|
|
|
|
|
|
if(!cursorValid() && canFocus)
|
2013-07-10 11:29:43 +00:00
|
|
|
mCursor = pos;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
//update the column width and row height
|
2013-08-21 19:49:33 +00:00
|
|
|
//if(autoFit.x() && (int)getColumnWidth(pos.x()) < component->getSize().x())
|
|
|
|
// setColumnWidth(pos.x(), (unsigned int)component->getSize().x());
|
|
|
|
//if(autoFit.y() && (int)getRowHeight(pos.y()) < component->getSize().y())
|
|
|
|
// setRowHeight(pos.y(), (unsigned int)component->getSize().y());
|
2013-09-19 23:41:14 +00:00
|
|
|
updateCellSize(mEntries.back(), autoFit.x(), autoFit.y());
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
component->setPosition(getCellOffset(pos));
|
2013-08-21 20:59:11 +00:00
|
|
|
|
|
|
|
updateSize();
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
void ComponentListComponent::removeEntriesIn(Eigen::Vector2i pos, Eigen::Vector2i size)
|
|
|
|
{
|
|
|
|
auto iter = mEntries.begin();
|
|
|
|
while(iter != mEntries.end())
|
|
|
|
{
|
|
|
|
if((*iter)->pos.x() >= pos.x() && (*iter)->pos.x() < pos.x() + size.x()
|
|
|
|
&& (*iter)->pos.y() >= pos.y() && (*iter)->pos.y() < pos.y() + size.y())
|
|
|
|
{
|
2013-09-20 23:55:05 +00:00
|
|
|
if((*iter)->component->getParent() == this)
|
|
|
|
(*iter)->component->setParent(NULL);
|
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
delete *iter;
|
|
|
|
iter = mEntries.erase(iter);
|
|
|
|
}else{
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int y = pos.y(); y < pos.y() + size.y(); y++)
|
|
|
|
{
|
|
|
|
for(int x = pos.x(); x < pos.x() + size.x(); x++)
|
|
|
|
{
|
|
|
|
setCell(x, y, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!cursorValid())
|
|
|
|
resetCursor();
|
|
|
|
}
|
|
|
|
|
2013-08-21 19:49:33 +00:00
|
|
|
void ComponentListComponent::forceRowHeight(int row, unsigned int size)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
mRowHeights[row] = size;
|
2013-08-21 19:49:33 +00:00
|
|
|
mRowHeightForced[row] = true;
|
2013-06-19 01:12:30 +00:00
|
|
|
updateSize();
|
2013-08-21 20:59:11 +00:00
|
|
|
updateComponentOffsets();
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 19:49:33 +00:00
|
|
|
void ComponentListComponent::forceColumnWidth(int col, unsigned int size)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
mColumnWidths[col] = size;
|
2013-09-19 23:41:14 +00:00
|
|
|
mColumnWidthForced[col] = true;
|
2013-06-19 01:12:30 +00:00
|
|
|
updateSize();
|
2013-08-21 20:59:11 +00:00
|
|
|
updateComponentOffsets();
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int ComponentListComponent::getRowHeight(int row) { return mRowHeights[row]; }
|
|
|
|
unsigned int ComponentListComponent::getColumnWidth(int col) { return mColumnWidths[col]; }
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector3f ComponentListComponent::getCellOffset(Eigen::Vector2i pos)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector3f offset(0, 0, 0);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
for(int y = 0; y < pos.y(); y++)
|
|
|
|
offset[1] += getRowHeight(y);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
for(int x = 0; x < pos.x(); x++)
|
|
|
|
offset[0] += getColumnWidth(x);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
ComponentEntry* entry = getCell(pos.x(), pos.y());
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-17 04:18:30 +00:00
|
|
|
Eigen::Vector2i gridSize(0, 0);
|
2013-07-10 11:29:43 +00:00
|
|
|
for(int x = pos.x(); x < pos.x() + entry->dim[0]; x++)
|
|
|
|
gridSize[0] += getColumnWidth(x);
|
|
|
|
for(int y = pos.y(); y < pos.y() + entry->dim[1]; y++)
|
|
|
|
gridSize[1] += getRowHeight(y);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
//if AlignCenter, add half of cell width - half of control width
|
|
|
|
if(entry->alignment == AlignCenter)
|
2013-07-10 11:29:43 +00:00
|
|
|
offset[0] += gridSize.x() / 2 - entry->component->getSize().x() / 2;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
//if AlignRight, add cell width - control width
|
|
|
|
if(entry->alignment == AlignRight)
|
2013-07-10 11:29:43 +00:00
|
|
|
offset[0] += gridSize.x() - entry->component->getSize().x();
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
//always center on the Y axis
|
2013-08-21 17:40:39 +00:00
|
|
|
offset[1] += gridSize.y() / 2.0f - entry->component->getSize().y() / 2.0f;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentListComponent::setCell(unsigned int x, unsigned int y, ComponentEntry* entry)
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
if(x >= (unsigned int)mGridSize.x() || y >= (unsigned int)mGridSize.y())
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
LOG(LogError) << "Invalid setCell - position " << x << ", " << y << " out of bounds!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
mGrid[y * mGridSize.x() + x] = entry;
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ComponentListComponent::ComponentEntry* ComponentListComponent::getCell(unsigned int x, unsigned int y)
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
if(x >= (unsigned int)mGridSize.x() || y >= (unsigned int)mGridSize.y())
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
LOG(LogError) << "Invalid getCell - position " << x << ", " << y << " out of bounds!";
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
return mGrid[y * mGridSize.x() + x];
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentListComponent::updateSize()
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
mSize = Eigen::Vector2f(0, 0);
|
|
|
|
for(int x = 0; x < mGridSize.x(); x++)
|
|
|
|
mSize.x() += getColumnWidth(x);
|
|
|
|
for(int y = 0; y < mGridSize.y(); y++)
|
|
|
|
mSize.y() += getRowHeight(y);
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentListComponent::updateComponentOffsets()
|
|
|
|
{
|
|
|
|
for(auto iter = mEntries.begin(); iter != mEntries.end(); iter++)
|
|
|
|
{
|
2013-09-19 23:41:14 +00:00
|
|
|
(*iter)->component->setPosition(getCellOffset((*iter)->pos));
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-21 19:49:33 +00:00
|
|
|
void ComponentListComponent::updateCellSize(ComponentEntry* e, bool updWidth, bool updHeight)
|
|
|
|
{
|
|
|
|
if(!e)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "Tried to updateCellSize NULL ComponentEntry!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int x = e->pos.x();
|
|
|
|
unsigned int y = e->pos.y();
|
|
|
|
|
|
|
|
if(!mColumnWidthForced[x] && updWidth)
|
|
|
|
{
|
|
|
|
//recalc width to widest in column
|
|
|
|
float widest = 0;
|
|
|
|
for(int row = 0; row < mGridSize.y(); row++)
|
|
|
|
{
|
|
|
|
ComponentEntry* check = getCell(x, row);
|
|
|
|
if(check)
|
|
|
|
{
|
|
|
|
if(check->component->getSize().x() > widest)
|
|
|
|
widest = check->component->getSize().x();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mColumnWidths[x] = (unsigned int)widest;
|
|
|
|
}
|
|
|
|
if(!mRowHeightForced[y] && updHeight)
|
|
|
|
{
|
|
|
|
float tallest = 0;
|
|
|
|
for(int col = 0; col < mGridSize.x(); col++)
|
|
|
|
{
|
|
|
|
ComponentEntry* check = getCell(col, y);
|
|
|
|
if(check)
|
|
|
|
{
|
|
|
|
if(check->component->getSize().y() > tallest)
|
|
|
|
tallest = check->component->getSize().y();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mRowHeights[y] = (unsigned int)tallest;
|
|
|
|
}
|
|
|
|
|
|
|
|
updateComponentOffsets();
|
2013-08-21 20:59:11 +00:00
|
|
|
updateSize();
|
2013-08-21 19:49:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentListComponent::updateComponent(GuiComponent* cmp)
|
|
|
|
{
|
|
|
|
for(auto iter = mEntries.begin(); iter != mEntries.end(); iter++)
|
|
|
|
{
|
2013-09-19 23:41:14 +00:00
|
|
|
if((*iter)->component == cmp)
|
2013-08-21 19:49:33 +00:00
|
|
|
{
|
2013-09-19 23:41:14 +00:00
|
|
|
updateCellSize(*iter);
|
2013-08-21 19:49:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
bool ComponentListComponent::input(InputConfig* config, Input input)
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
if(cursorValid() && getCell(mCursor.x(), mCursor.y())->component->input(config, input))
|
2013-06-19 01:12:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if(!input.value)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(config->isMappedTo("down", input))
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
moveCursor(Eigen::Vector2i(0, 1));
|
2013-06-19 01:12:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(config->isMappedTo("up", input))
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
moveCursor(Eigen::Vector2i(0, -1));
|
2013-06-19 01:12:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-08-18 14:16:11 +00:00
|
|
|
if(config->isMappedTo("left", input))
|
|
|
|
{
|
|
|
|
moveCursor(Eigen::Vector2i(-1, 0));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(config->isMappedTo("right", input))
|
|
|
|
{
|
|
|
|
moveCursor(Eigen::Vector2i(1, 0));
|
|
|
|
return true;
|
|
|
|
}
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentListComponent::resetCursor()
|
|
|
|
{
|
2013-09-20 23:55:05 +00:00
|
|
|
auto iter = mEntries.begin();
|
|
|
|
while(iter != mEntries.end())
|
|
|
|
{
|
|
|
|
if((*iter)->canFocus)
|
|
|
|
break;
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(iter == mEntries.end())
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
mCursor = Eigen::Vector2i(-1, -1);
|
2013-06-19 01:12:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-18 14:16:11 +00:00
|
|
|
const Eigen::Vector2i origCursor = mCursor;
|
2013-09-20 23:55:05 +00:00
|
|
|
mCursor << (*iter)->pos[0], (*iter)->pos[1];
|
2013-08-18 14:16:11 +00:00
|
|
|
onCursorMoved(origCursor, mCursor);
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void ComponentListComponent::moveCursor(Eigen::Vector2i dir)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
if(dir.x() != 0 && dir.y() != 0)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
LOG(LogError) << "Invalid cursor move dir!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-18 14:16:11 +00:00
|
|
|
Eigen::Vector2i origCursor = mCursor;
|
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
if(!cursorValid())
|
|
|
|
{
|
|
|
|
resetCursor();
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
if(!cursorValid())
|
2013-08-18 14:16:11 +00:00
|
|
|
{
|
|
|
|
if(mCursor != origCursor)
|
|
|
|
onCursorMoved(origCursor, mCursor);
|
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
return;
|
2013-08-18 14:16:11 +00:00
|
|
|
}
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector2i searchAxis(dir.x() == 0, dir.y() == 0);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
while(mCursor.x() >= 0 && mCursor.y() >= 0 && mCursor.x() < mGridSize.x() && mCursor.y() < mGridSize.y())
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
mCursor = mCursor + dir;
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector2i curDirPos = mCursor;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
//spread out on search axis+
|
2013-07-10 11:29:43 +00:00
|
|
|
while(mCursor.x() < mGridSize.x() && mCursor.y() < mGridSize.y())
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
if(cursorValid() && getCell(mCursor.x(), mCursor.y())->canFocus)
|
2013-08-18 14:16:11 +00:00
|
|
|
{
|
|
|
|
onCursorMoved(origCursor, mCursor);
|
2013-06-19 01:12:30 +00:00
|
|
|
return;
|
2013-08-18 14:16:11 +00:00
|
|
|
}
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
mCursor += searchAxis;
|
|
|
|
}
|
|
|
|
|
|
|
|
//now again on search axis-
|
|
|
|
mCursor = curDirPos;
|
2013-07-10 11:29:43 +00:00
|
|
|
while(mCursor.x() >= 0 && mCursor.y() >= 0)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
if(cursorValid() && getCell(mCursor.x(), mCursor.y())->canFocus)
|
2013-08-18 14:16:11 +00:00
|
|
|
{
|
|
|
|
onCursorMoved(origCursor, mCursor);
|
2013-06-19 01:12:30 +00:00
|
|
|
return;
|
2013-08-18 14:16:11 +00:00
|
|
|
}
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
mCursor -= searchAxis;
|
|
|
|
}
|
2013-08-07 05:41:55 +00:00
|
|
|
|
|
|
|
mCursor = curDirPos;
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//failed to find another focusable element in this direction
|
|
|
|
mCursor = origCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ComponentListComponent::cursorValid()
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
if(mCursor.x() < 0 || mCursor.y() < 0 || mCursor.x() >= mGridSize.x() || mCursor.y() >= mGridSize.y())
|
2013-06-19 01:12:30 +00:00
|
|
|
return false;
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
return getCell(mCursor.x(), mCursor.y()) != NULL;
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ComponentListComponent::update(int deltaTime)
|
|
|
|
{
|
|
|
|
for(auto iter = mEntries.begin(); iter != mEntries.end(); iter++)
|
|
|
|
{
|
2013-09-19 23:41:14 +00:00
|
|
|
switch((*iter)->updateType)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-08-22 20:29:50 +00:00
|
|
|
case UpdateAlways:
|
2013-09-19 23:41:14 +00:00
|
|
|
(*iter)->component->update(deltaTime);
|
2013-08-22 20:29:50 +00:00
|
|
|
break;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
case UpdateFocused:
|
2013-09-19 23:41:14 +00:00
|
|
|
if(cursorValid() && getCell(mCursor.x(), mCursor.y())->component == (*iter)->component)
|
|
|
|
(*iter)->component->update(deltaTime);
|
2013-08-22 20:29:50 +00:00
|
|
|
break;
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void ComponentListComponent::render(const Eigen::Affine3f& parentTrans)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Affine3f trans = parentTrans * getTransform();
|
2013-10-06 02:56:06 +00:00
|
|
|
|
|
|
|
//draw cursor
|
|
|
|
if(cursorValid())
|
|
|
|
{
|
|
|
|
ComponentEntry* entry = getCell(mCursor.x(), mCursor.y());
|
|
|
|
Eigen::Affine3f entryTrans = trans * entry->component->getTransform();
|
|
|
|
Renderer::setMatrix(entryTrans);
|
|
|
|
|
|
|
|
Renderer::drawRect(0, 0, 4, 4, 0xFF0000FF);
|
|
|
|
Renderer::drawRect(0, 0, (int)entry->component->getSize().x(), (int)entry->component->getSize().y(), 0x0000AA22);
|
|
|
|
}
|
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
for(auto iter = mEntries.begin(); iter != mEntries.end(); iter++)
|
|
|
|
{
|
2013-09-19 23:41:14 +00:00
|
|
|
(*iter)->component->render(trans);
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 04:18:30 +00:00
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
//draw cell outlines
|
2013-07-17 04:18:30 +00:00
|
|
|
/*Renderer::setMatrix(trans);
|
|
|
|
Eigen::Vector2i pos(0, 0);
|
|
|
|
for(int x = 0; x < mGridSize.x(); x++)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-17 04:18:30 +00:00
|
|
|
for(int y = 0; y < mGridSize.y(); y++)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-17 04:18:30 +00:00
|
|
|
Renderer::drawRect(pos.x(), pos.y(), getColumnWidth(x), 2, 0x000000AA);
|
|
|
|
Renderer::drawRect(pos.x(), pos.y(), 2, getRowHeight(y), 0x000000AA);
|
|
|
|
Renderer::drawRect(pos.x() + getColumnWidth(x), pos.y(), 2, getRowHeight(y), 0x000000AA);
|
|
|
|
Renderer::drawRect(pos.x(), pos.y() + getRowHeight(y) - 2, getColumnWidth(x), 2, 0x000000AA);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-17 04:18:30 +00:00
|
|
|
pos[1] += getRowHeight(y);
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-07-17 04:18:30 +00:00
|
|
|
pos[1] = 0;
|
|
|
|
pos[0] += getColumnWidth(x);
|
2013-06-19 01:12:30 +00:00
|
|
|
}*/
|
|
|
|
|
2013-10-06 02:56:06 +00:00
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-19 15:36:48 +00:00
|
|
|
void ComponentListComponent::textInput(const char* text)
|
|
|
|
{
|
|
|
|
if(getSelectedComponent() != NULL)
|
|
|
|
getSelectedComponent()->textInput(text);
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void ComponentListComponent::onPositionChanged()
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
updateComponentOffsets();
|
|
|
|
}
|
2013-06-19 21:02:42 +00:00
|
|
|
|
|
|
|
GuiComponent* ComponentListComponent::getSelectedComponent()
|
|
|
|
{
|
|
|
|
if(!cursorValid())
|
|
|
|
return NULL;
|
2013-07-10 11:29:43 +00:00
|
|
|
return getCell(mCursor.x(), mCursor.y())->component;
|
2013-06-19 21:02:42 +00:00
|
|
|
}
|
2013-08-18 14:16:11 +00:00
|
|
|
|
|
|
|
void ComponentListComponent::onCursorMoved(Eigen::Vector2i from, Eigen::Vector2i to)
|
|
|
|
{
|
|
|
|
if(from != Eigen::Vector2i(-1, -1))
|
|
|
|
getCell(from.x(), from.y())->component->onFocusLost();
|
|
|
|
|
|
|
|
if(to != Eigen::Vector2i(-1, -1))
|
|
|
|
getCell(to.x(), to.y())->component->onFocusGained();
|
2014-01-25 23:34:29 +00:00
|
|
|
|
|
|
|
updateHelpPrompts();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> ComponentListComponent::getHelpPrompts()
|
|
|
|
{
|
|
|
|
std::vector<HelpPrompt> prompts;
|
|
|
|
if(cursorValid())
|
|
|
|
prompts = getSelectedComponent()->getHelpPrompts();
|
|
|
|
|
|
|
|
bool canScrollVert = true;
|
|
|
|
bool canScrollHoriz = true;
|
|
|
|
for(auto it = prompts.begin(); it != prompts.end(); it++)
|
|
|
|
{
|
|
|
|
if(it->first == "up/down/left/right")
|
|
|
|
{
|
|
|
|
canScrollHoriz = false;
|
|
|
|
canScrollVert = false;
|
|
|
|
break;
|
|
|
|
}else if(it->first == "up/down")
|
|
|
|
{
|
|
|
|
canScrollVert = false;
|
|
|
|
}else if(it->first == "left/right")
|
|
|
|
{
|
|
|
|
canScrollHoriz = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(canScrollHoriz && canScrollVert)
|
|
|
|
prompts.push_back(HelpPrompt("up/down/left/right", "move cursor"));
|
|
|
|
else if(canScrollHoriz)
|
|
|
|
prompts.push_back(HelpPrompt("left/right", "move cursor"));
|
|
|
|
else if(canScrollVert)
|
|
|
|
prompts.push_back(HelpPrompt("up/down", "move cursor"));
|
|
|
|
|
|
|
|
return prompts;
|
2013-08-18 14:16:11 +00:00
|
|
|
}
|