31#include <guichan/actionlistener.hpp>
32#include <guichan/graphics.hpp>
33#include <guichan/key.hpp>
41 void action(
const gcn::ActionEvent& actionEvent)
override;
59 widget->addActionListener(
this);
60 widget->_setParent(table);
68 mWidget->removeActionListener(
this);
76 mTable->distributeActionEvent();
83 mBackgroundColor(background)
88 addMouseListener(
this);
134 for (
int i = 0; i < columns_nr; i++)
245 for (
int row = 0; row < rows; ++row)
246 for (
int column = 0; column < columns; ++column)
267 backgroundColor.a = guiAlpha;
269 graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
273 highlightColor.a = guiAlpha;
284 if (max_rows_nr < rows_nr)
285 rows_nr = max_rows_nr;
289 int first_column = 0;
294 int y_offset = first_row * height;
296 for (
int r = first_row; r < first_row + rows_nr; ++r)
300 for (
int c = first_column; c <= last_column; ++c)
306 gcn::Rectangle bounds(x_offset, y_offset, width, height);
310 bounds.height = widget->getHeight();
311 bounds.width = widget->getWidth();
314 widget->setDimension(bounds);
320 graphics->fillRectangle(gcn::Rectangle(0, y_offset,
321 getWidth(), height));
326 graphics->fillRectangle(gcn::Rectangle(x_offset, y_offset,
343 gcn::Rectangle bounds =
mTopWidget->getDimension();
352 gcn::Widget::moveToTop(widget);
358 gcn::Widget::moveToBottom(widget);
365 return gcn::Rectangle(0, 0, getWidth(), getHeight());
371 gcn::Key key = keyEvent.getKey();
375 distributeActionEvent();
378 else if (key.getValue() ==
Key::UP)
404 else if (key.getValue() ==
Key::END)
415 if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
420 if (row > -1 && column > -1 &&
421 row < mModel->getRows() && column < mModel->getColumns())
427 distributeActionEvent();
440 mouseEvent.consume();
450 mouseEvent.consume();
456 if (mouseEvent.getButton() != gcn::MouseEvent::LEFT)
460 const int x = std::max(0, mouseEvent.getX());
461 const int y = std::max(0, mouseEvent.getY());
490 if (row > -1 && column > -1)
493 if (w->isFocusable())
533 gcn::Widget::_setFocusHandler(focusHandler);
543 w->_setFocusHandler(focusHandler);
void setColor(const gcn::Color &color) override
void action(const gcn::ActionEvent &actionEvent) override
GuiTableActionListener(GuiTable *table, gcn::Widget *widget, int row, int column)
~GuiTableActionListener() override
A table, with rows and columns made out of sub-widgets.
void installActionListeners()
Installs all action listeners on inner widgets.
void mouseWheelMovedUp(gcn::MouseEvent &mouseEvent) override
void setSelectedRow(int selected)
void mousePressed(gcn::MouseEvent &mouseEvent) override
void setSelectedColumn(int selected)
gcn::Widget * mTopWidget
If someone moves a fresh widget to the top, we must display it.
void setModel(TableModel *m)
Sets the table model.
int getSelectedColumn() const
void modelUpdated(bool) override
Must be invoked by the TableModel whenever a global change is about to occur or has occurred (e....
int getSelectedRow() const
int getRowForY(int y) const
friend class GuiTableActionListener
int getColumnWidth(int i) const
TableModel * getModel() const
Retrieves the active table model.
gcn::Rectangle getChildrenArea() override
void moveToBottom(gcn::Widget *child) override
std::vector< GuiTableActionListener * > mActionListeners
Vector for compactness; used as a list in practice.
void mouseDragged(gcn::MouseEvent &mouseEvent) override
void mouseWheelMovedDown(gcn::MouseEvent &mouseEvent) override
GuiTable(TableModel *initialModel=nullptr, gcn::Color background=0xffffff, bool opacity=true)
void keyPressed(gcn::KeyEvent &keyEvent) override
void recomputeDimensions()
void setSelected(int row, int column)
void setLinewiseSelection(bool linewise)
Toggle whether to use linewise selection mode, in which the table selects an entire line at a time,...
void uninstallActionListeners()
Frees all action listeners on inner widgets.
void _setFocusHandler(gcn::FocusHandler *focusHandler) override
void draw(gcn::Graphics *graphics) override
gcn::Widget * getWidgetAt(int x, int y) override
void moveToTop(gcn::Widget *child) override
int getColumnForX(int x) const
Theme * getTheme() const
The global GUI theme.
A model for a regular table of widgets.
virtual int getRows() const =0
Determines the number of rows (lines) in the table.
virtual int getRowHeight() const =0
Determines the height for each row.
void removeListener(TableModelListener *listener)
virtual int getColumns() const =0
Determines the number of columns in each row.
virtual gcn::Widget * getElementAt(int row, int column) const =0
Retrieves the widget stored at the specified location within the table.
virtual int getColumnWidth(int index) const =0
Determines the width of each individual column.
void installListener(TableModelListener *listener)
int getGuiAlpha() const
Get the current GUI alpha value.
static const gcn::Color & getThemeColor(int type)
Gets the color associated with the type in the default palette (0).
void delete_all(Container &c)