2013-06-19 01:12:30 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../GuiComponent.h"
|
|
|
|
|
2014-03-01 00:52:32 +00:00
|
|
|
// Used to arrange a bunch of components in a spreadsheet-esque grid.
|
|
|
|
class ComponentGrid : public GuiComponent
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-03-01 00:52:32 +00:00
|
|
|
ComponentGrid(Window* window, Eigen::Vector2i gridDimensions);
|
|
|
|
virtual ~ComponentGrid();
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
enum UpdateBehavior
|
|
|
|
{
|
|
|
|
UpdateAlways, UpdateFocused
|
|
|
|
};
|
|
|
|
|
|
|
|
enum AlignmentType
|
|
|
|
{
|
|
|
|
AlignLeft, AlignRight, AlignCenter
|
|
|
|
};
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
//DO NOT USE NEGATIVE NUMBERS FOR POSITION OR SIZE.
|
2013-08-18 14:16:11 +00:00
|
|
|
void setEntry(Eigen::Vector2i pos, Eigen::Vector2i size, GuiComponent* component, bool canFocus, AlignmentType align,
|
|
|
|
Eigen::Matrix<bool, 1, 2> autoFit = Eigen::Matrix<bool, 1, 2>(true, true), UpdateBehavior updateType = UpdateAlways);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
void removeEntriesIn(Eigen::Vector2i pos, Eigen::Vector2i size);
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void onPositionChanged() override;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-08-19 15:36:48 +00:00
|
|
|
void textInput(const char* text) override;
|
2013-06-19 01:12:30 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
void update(int deltaTime) override;
|
2013-07-10 11:29:43 +00:00
|
|
|
void render(const Eigen::Affine3f& parentTrans) override;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-08-21 19:49:33 +00:00
|
|
|
void forceColumnWidth(int col, unsigned int size);
|
|
|
|
void forceRowHeight(int row, unsigned int size);
|
|
|
|
|
|
|
|
void updateComponent(GuiComponent* cmp);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
void resetCursor();
|
|
|
|
bool cursorValid();
|
|
|
|
|
2013-06-19 21:02:42 +00:00
|
|
|
GuiComponent* getSelectedComponent();
|
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
void moveCursor(Eigen::Vector2i dir);
|
|
|
|
|
2014-01-25 23:34:29 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
private:
|
|
|
|
class ComponentEntry
|
|
|
|
{
|
|
|
|
public:
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector2i pos;
|
|
|
|
Eigen::Vector2i dim;
|
2013-06-19 01:12:30 +00:00
|
|
|
GuiComponent* component;
|
|
|
|
UpdateBehavior updateType;
|
|
|
|
AlignmentType alignment;
|
|
|
|
bool canFocus;
|
|
|
|
|
|
|
|
ComponentEntry() : component(NULL), updateType(UpdateAlways), canFocus(true), alignment(AlignCenter) {};
|
2013-07-10 11:29:43 +00:00
|
|
|
ComponentEntry(Eigen::Vector2i p, Eigen::Vector2i d, GuiComponent* comp, UpdateBehavior update, bool focus, AlignmentType align) : pos(p), dim(d), component(comp), updateType(update), canFocus(focus), alignment(align) {};
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
operator bool() const
|
|
|
|
{
|
|
|
|
return component != NULL;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
//Offset we render components by (for scrolling). [unimplemented]
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector2f mComponentOffset;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector2i mGridSize;
|
2013-06-19 01:12:30 +00:00
|
|
|
ComponentEntry** mGrid;
|
2013-09-19 23:41:14 +00:00
|
|
|
std::vector<ComponentEntry*> mEntries;
|
2013-07-10 11:29:43 +00:00
|
|
|
void makeCells(Eigen::Vector2i size);
|
2013-06-19 01:12:30 +00:00
|
|
|
void setCell(unsigned int x, unsigned int y, ComponentEntry* entry);
|
|
|
|
ComponentEntry* getCell(unsigned int x, unsigned int y);
|
|
|
|
|
|
|
|
unsigned int getColumnWidth(int col);
|
|
|
|
unsigned int getRowHeight(int row);
|
|
|
|
|
|
|
|
unsigned int* mColumnWidths;
|
|
|
|
unsigned int* mRowHeights;
|
2013-08-21 19:49:33 +00:00
|
|
|
bool* mColumnWidthForced;
|
|
|
|
bool* mRowHeightForced;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector3f getCellOffset(Eigen::Vector2i gridPos);
|
2013-06-19 01:12:30 +00:00
|
|
|
void updateSize();
|
|
|
|
|
2013-08-18 14:16:11 +00:00
|
|
|
void onCursorMoved(Eigen::Vector2i from, Eigen::Vector2i to);
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector2i mCursor;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
void updateComponentOffsets();
|
2013-08-21 19:49:33 +00:00
|
|
|
void updateCellSize(ComponentEntry* e, bool updWidth = true, bool updHeight = true);
|
2013-06-19 01:12:30 +00:00
|
|
|
};
|