15Slide
GTKSlide::TileGrid Class Reference

A Gtk::Grid graphical representation of a Grid15::Grid. More...

#include <TileGrid.h>

Inherits Grid.

Public Member Functions

 TileGrid (Gtk::Window &parent, std::shared_ptr< Grid15::Grid > &newGridPtr, std::shared_ptr< SaveManager > &saveManagerPtr)
 Creates and populates the GTKSlide main window. More...
 
void lableTiles ()
 Lables the Gtk::Button tiles based on gridPtr tile values. More...
 
void sensitizeTiles ()
 Sensitizes or desensitizes Gtk::Button the tiles based on if moving them would be valid, based on gridPtr tile values. More...
 
void updateTiles ()
 Both lables and sensitizes (depending on GTKSlide::SENSITIZE_VALID_MOVES_ONLY) the tiles at one. More...
 

Protected Member Functions

void on_tile_clicked (std::uint8_t coordinates)
 
void displayWonDialog ()
 Creates and displays a "won" dialog if the game is won. More...
 
std::pair< std::uint8_t, std::uint8_t > singleToTwoD (std::uint8_t coordinates)
 A helper function to convert a single number from 0 to 15 to an x and y coordinate from 0 to 3. More...
 
std::uint8_t twoDToSingle (std::uint8_t y, std::uint8_t x)
 A helper function to convert an x and y coordinate from 0 to 3 to a single number from 0 to 15. More...
 

Protected Attributes

Gtk::Window * parentPtr {}
 A pointer to the parent window to call various dialogs set_transient_for() More...
 
std::shared_ptr< Grid15::GridgridPtr {}
 A pointer to the grid to use. More...
 
std::unique_ptr< Gtk::Button[]> gridButtons {new Gtk::Button [16]}
 The array of buttons which represent tiles. More...
 
std::shared_ptr< SaveManagersaveManager {}
 A pointer to a SaveManager for managing autosaving. More...
 

Detailed Description

A Gtk::Grid graphical representation of a Grid15::Grid.

Author
John Jekel
Date
2018-2018

Constructor & Destructor Documentation

◆ TileGrid()

GTKSlide::TileGrid::TileGrid ( Gtk::Window &  parent,
std::shared_ptr< Grid15::Grid > &  newGridPtr,
std::shared_ptr< SaveManager > &  saveManagerPtr 
)

Creates and populates the GTKSlide main window.

Parameters
parentThe parent window to call various dialogs set_transient_for()
newGridPtrThe Grid15::Grid to use
saveManagerPtrA pointer to a SaveManager for managing autosaving
Exceptions
std::invalid_argumentIf the Grid15::Grid given is invalid

Member Function Documentation

◆ displayWonDialog()

void GTKSlide::TileGrid::displayWonDialog ( )
protected

Creates and displays a "won" dialog if the game is won.

◆ lableTiles()

void GTKSlide::TileGrid::lableTiles ( )

Lables the Gtk::Button tiles based on gridPtr tile values.

◆ on_tile_clicked()

void GTKSlide::TileGrid::on_tile_clicked ( std::uint8_t  coordinates)
protected

The signal handler if a tile is clicked

Parameters
coordinatesA 1 dimentional array position that will be converted to 2D for use

◆ sensitizeTiles()

void GTKSlide::TileGrid::sensitizeTiles ( )

Sensitizes or desensitizes Gtk::Button the tiles based on if moving them would be valid, based on gridPtr tile values.

◆ singleToTwoD()

std::pair< std::uint8_t, std::uint8_t > GTKSlide::TileGrid::singleToTwoD ( std::uint8_t  coordinates)
protected

A helper function to convert a single number from 0 to 15 to an x and y coordinate from 0 to 3.

Used along with TileGrid::twoDToSingle to convert the other way

Parameters
coordinatesThe merged coordinates
Returns
A std::pair with first = y coordinate and second = x coordinate

◆ twoDToSingle()

std::uint8_t GTKSlide::TileGrid::twoDToSingle ( std::uint8_t  y,
std::uint8_t  x 
)
protected

A helper function to convert an x and y coordinate from 0 to 3 to a single number from 0 to 15.

Used to access the single dimentional array of Gtk::Buttons like a 2D one

Parameters
yThe y coordinate (rows)
xThe x coordinate (colums)
Returns
The merged coordinates

◆ updateTiles()

void GTKSlide::TileGrid::updateTiles ( )

Both lables and sensitizes (depending on GTKSlide::SENSITIZE_VALID_MOVES_ONLY) the tiles at one.

Member Data Documentation

◆ gridButtons

std::unique_ptr<Gtk::Button[]> GTKSlide::TileGrid::gridButtons {new Gtk::Button [16]}
protected

The array of buttons which represent tiles.

◆ gridPtr

std::shared_ptr<Grid15::Grid> GTKSlide::TileGrid::gridPtr {}
protected

A pointer to the grid to use.

◆ parentPtr

Gtk::Window* GTKSlide::TileGrid::parentPtr {}
protected

A pointer to the parent window to call various dialogs set_transient_for()

◆ saveManager

std::shared_ptr<SaveManager> GTKSlide::TileGrid::saveManager {}
protected

A pointer to a SaveManager for managing autosaving.


The documentation for this class was generated from the following files: