stmm-games-doc  0.32.0
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
stmg::ActionsBoxWidget Class Reference

Action grid box. More...

Inheritance diagram for stmg::ActionsBoxWidget:
Inheritance graph
[legend]

Classes

struct  BoxCell
 
struct  Init
 
struct  LocalInit
 

Public Types

enum  ACTION_TYPE { ACTION_NONE = 0, ACTION_KEY_ACTION = 1, ACTION_INTERRUPT = 2, ACTION_EVENT_MSG = 3 }
 

Public Member Functions

int32_t getTotColumns () const noexcept
 The grid's number of columns. More...
 
int32_t getTotRows () const noexcept
 The grid's number of rows. More...
 
int32_t getSumOfAllColumnParts () const noexcept
 The sum of all column parts. More...
 
int32_t getSumOfAllRowParts () const noexcept
 The sum of all row parts. More...
 
int32_t getColumnPart (int32_t nCol) const noexcept
 The column weight of the width of the box. More...
 
int32_t getRowPart (int32_t nRow) const noexcept
 The row weight of the height of the box. More...
 
void handleXYInput (const shared_ptr< stmi::Event > &refXYEvent, int32_t nTeam, int32_t nMate, int32_t nCol, int32_t nRow) noexcept
 Execute action. More...
 
 ActionsBoxWidget (Init &&oInit) noexcept
 Constructor. More...
 
void dump (int32_t nIndentSpaces, bool bHeader) const noexcept override
 Writes object contents to std::cout. More...
 
- Public Member Functions inherited from stmg::BoxWidget
bool isVertical (int32_t nLayoutConfig) const noexcept
 Whether the children are stacked vertically. More...
 
bool hasInvertedChildren (int32_t nLayoutConfig) const noexcept
 Whether the children should be boxed in reverse order for the layout config. More...
 
 BoxWidget (Init &&oInit) noexcept
 Constructor. More...
 
void dump (int32_t nIndentSpaces, bool bHeader) const noexcept override
 Writes object contents to std::cout. More...
 
- Public Member Functions inherited from stmg::ContainerWidget
const std::vector< shared_ptr< GameWidget > > & getChildren () const noexcept
 The children widgets of the container. More...
 
virtual ~ContainerWidget () noexcept
 
- Public Member Functions inherited from stmg::GameWidget
virtual ~GameWidget () noexcept=default
 
int32_t getViewWidgetNameIdx () const noexcept
 The type (name) that might be used to choose a ThemeWidget. More...
 
const std::string & getName () const noexcept
 The name of the widget. More...
 
int32_t getTeam () const noexcept
 The team the widget is assigned to. More...
 
int32_t getMate () const noexcept
 The mate the widget is assigned to. More...
 
WidgetAxisFit getWidgetHorizAxisFit (int32_t nLayoutConfig) const noexcept
 Widget alignment and expansion for the x axis. More...
 
WidgetAxisFit getWidgetVertAxisFit (int32_t nLayoutConfig) const noexcept
 Widget alignment and expansion for the y axis. More...
 
bool isAssignedToHuman () const noexcept
 Tells whether the widget is assigned to a human. More...
 
ContainerWidgetgetContainer () const noexcept
 The container to which this widget was added to. More...
 
void dump (int32_t nIndentSpaces) const noexcept
 Writes object contents to std::cout (header included). More...
 
void dump () const noexcept
 Writes object contents to std::cout (header included). More...
 

Protected Member Functions

void reInit (Init &&oInit) noexcept
 Reinitialization. More...
 
- Protected Member Functions inherited from stmg::BoxWidget
void reInit (Init &&oInit) noexcept
 Reinitialization. More...
 
- Protected Member Functions inherited from stmg::ContainerWidget
 ContainerWidget (Init &&oData) noexcept
 Constructor. More...
 
void reInit (Init &&oData) noexcept
 Reinitialization. More...
 
- Protected Member Functions inherited from stmg::GameWidget
 GameWidget (Init &&oData) noexcept
 Constructor. More...
 
void reInit (Init &&oData) noexcept
 Reinitialization. More...
 
Layoutlayout () noexcept
 The layout the widget belongs to. More...
 
const Layoutlayout () const noexcept
 The layout the widget belongs to. More...
 
GameProxygame () noexcept
 The game the widget belongs to. More...
 
const GameProxygame () const noexcept
 The game the widget belongs to. More...
 
virtual void onAddedToLayout () noexcept
 Signals widget was added to layout. More...
 
virtual void onAddedToGame () noexcept
 Signals widget was added to game. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from stmg::ContainerWidget
static bool getChildExpand (const std::vector< shared_ptr< GameWidget > > &aChildWidgets, int32_t nLayoutConfig, bool bHoriz) noexcept
 Tells whether any of a vector of game widgets expands. More...
 
static bool getChildFill (const std::vector< shared_ptr< GameWidget > > &aChildWidgets, int32_t nLayoutConfig, bool bHoriz) noexcept
 Tells whether any of a vector of game widgets fills. More...
 

Detailed Description

Action grid box.

This is a BoxWidget extension that allows to define an action grid. An action can be assigned to each cell of the grid. An action can either be a key action, a msg to send to an event or an interrupt. The action is triggered when for example a pointer device clicks in the cell area.

Note that the action grid is completely independent of the placement and size of the box's children.

LocalInit::m_aColumns contains positive numbers that partition the width of the box widget. A column claims the portion of the box equivalent to the value divided by the sum of all the values in the vector. LocalInit::m_aRows contains positive numbers that partition the height of the box widget. A row claims the portion of the box equivalent to the value divided by the sum of all the values in the vector. If a LocalInit::m_aActionCells value is empty, no key action is triggered.

Example: for a Tetris like game the grid has 2 columns and 3 rows, LocalInit could be filled with m_aColumns = {7, 7}, m_aRows = {20, 140, 40}, m_aActionCells = {interrupt "PAUSE", interrupt "ABORT_ASK", key action "Drop", key action "Rotate", key action "Left", key action "Right"}. Meaning: the box rectangle is partitioned in 6 cells with the two columns claiming 50% each and the rows claiming 10%, 70% and 20% respectively.

Member Enumeration Documentation

◆ ACTION_TYPE

Enumerator
ACTION_NONE 

No action.

ACTION_KEY_ACTION 

Execute a key action.

ACTION_INTERRUPT 

Execute an interrupt.

Ex: PAUSE.

ACTION_EVENT_MSG 

Trigger an event with a message.

Constructor & Destructor Documentation

◆ ActionsBoxWidget()

stmg::ActionsBoxWidget::ActionsBoxWidget ( Init &&  oInit)
inlineexplicitnoexcept

Constructor.

The target widget with given name must exist in the layout when the layout is created and must not be a ContainerWidget (subclass).

The team and mate of the target widget are the same as this widget.

Parameters
oInitThe initialization data.

Member Function Documentation

◆ dump()

void stmg::ActionsBoxWidget::dump ( int32_t  nIndentSpaces,
bool  bHeader 
) const
overridevirtualnoexcept

Writes object contents to std::cout.

Should only do it in debug mode. The function is also exposed in release mode because it is virtual.

If bHeader is true this function should also output the type of the object and its address.

Parameters
nIndentSpacesNumber of spaces put in front of each output line.
bHeaderWhether the header of the object should be displayed.

Reimplemented from stmg::ContainerWidget.

◆ getColumnPart()

int32_t stmg::ActionsBoxWidget::getColumnPart ( int32_t  nCol) const
inlinenoexcept

The column weight of the width of the box.

Parameters
nColThe column.
Returns
The column part. Is >= 1.

◆ getRowPart()

int32_t stmg::ActionsBoxWidget::getRowPart ( int32_t  nRow) const
inlinenoexcept

The row weight of the height of the box.

Parameters
nRowThe row.
Returns
The row part. Is >= 1.

◆ getSumOfAllColumnParts()

int32_t stmg::ActionsBoxWidget::getSumOfAllColumnParts ( ) const
inlinenoexcept

The sum of all column parts.

Returns
The sum of all column parts. Is >= 1.

◆ getSumOfAllRowParts()

int32_t stmg::ActionsBoxWidget::getSumOfAllRowParts ( ) const
inlinenoexcept

The sum of all row parts.

Returns
The sum of all row parts. Is >= 1.

◆ getTotColumns()

int32_t stmg::ActionsBoxWidget::getTotColumns ( ) const
inlinenoexcept

The grid's number of columns.

Returns
The number of columns. Is >= 1.

◆ getTotRows()

int32_t stmg::ActionsBoxWidget::getTotRows ( ) const
inlinenoexcept

The grid's number of rows.

Returns
The number of rows. Is >= 1.

◆ handleXYInput()

void stmg::ActionsBoxWidget::handleXYInput ( const shared_ptr< stmi::Event > &  refXYEvent,
int32_t  nTeam,
int32_t  nMate,
int32_t  nCol,
int32_t  nRow 
)
noexcept

Execute action.

If type of cell is ACTION_KEY_ACTION, a KeyActionEvent is created out of a stmi::XYEvent for a player.

Parameters
refXYEventThe event generated in the view. Cannot be null.
nTeamThe team of the player. Must be >=-1.
nMateThe mate number of the player. Must be >=-1. If team is -1 must be -1 too.
nColThe column. Must be >= 0 and < getTotColumns().
nRowThe row. Must be >= 0 and < getTotRows().

◆ reInit()

void stmg::ActionsBoxWidget::reInit ( Init &&  oInit)
inlineprotectednoexcept

Reinitialization.

See ActionsBoxWidget::ActionsBoxWidget(Init&& oInit).

Parameters
oInitThe initialization data.