Wang Tiling
A Simple Wang Tiling Generator
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CMain Class Reference

The main class. More...

#include <CMain.h>

Public Member Functions

 CMain (const HWND hwnd)
 Constructor. More...
 
 ~CMain ()
 Destructor. More...
 
HRESULT LoadTileSet (const UINT idm, const UINT n)
 Load tileset. More...
 
void Generate ()
 Generate a Wang tiling. More...
 
void Draw ()
 Draw the Wang tiling. More...
 
void OnPaint ()
 Paint the client area of the window. More...
 
Gdiplus::Bitmap * GetBitmap ()
 Get pointer to bitmap. More...
 

Private Member Functions

void CreateMenus ()
 Create menus. More...
 

Private Attributes

HWND m_hWnd = nullptr
 Window handle. More...
 
HMENU m_hTilesetMenu = nullptr
 Handle to the Generate menu. More...
 
ULONG_PTR m_gdiplusToken = 0
 GDI+ token. More...
 
Gdiplus::Bitmap * m_pBitmap = nullptr
 Pointer to a bitmap image. More...
 
CWangTilerm_pWangTiler
 Pointer to the Wang tiler. More...
 
Gdiplus::Bitmap ** m_pTile = nullptr
 The tile pointer array. More...
 
UINT m_nNumTiles = 0
 Number of tiles in tileset. More...
 

Detailed Description

The interface between I/O from Windows (input from the drop-down menus, output to the client area of the window), the Wang tiler, and the GDI+ graphics interface.

Definition at line 39 of file CMain.h.

Constructor & Destructor Documentation

◆ CMain()

CMain::CMain ( const HWND  hwnd)

Initialize GDI+, create the menus, load the initial tile set, generate a Wang tiling, then draw it to the bitmap. If the default tileset is not found, then do a fatal app exit.

Parameters
hwndWindow handle.

Definition at line 39 of file CMain.cpp.

◆ ~CMain()

CMain::~CMain ( )

Delete GDI+ objects, then shut down GDI+.

Definition at line 55 of file CMain.cpp.

Member Function Documentation

◆ CreateMenus()

void CMain::CreateMenus ( )
private

Add menus to the menu bar and store the Tileset menu handle, which will be needed later to set checkmarks.

Definition at line 159 of file CMain.cpp.

◆ Draw()

void CMain::Draw ( )

Draw the Wang tiling stored in the array m_pTile to the bitmap m_pBitmap using the tiles stored in array m_pTile. If m_pBitmap is nullptr, then a new bitmap of the appropriate size is created.

Definition at line 117 of file CMain.cpp.

◆ Generate()

void CMain::Generate ( )

Definition at line 247 of file CMain.cpp.

◆ GetBitmap()

Gdiplus::Bitmap * CMain::GetBitmap ( )

Reader function for the bitmap pointer m_pBitmap which, it is assumed, contains a bitmap Wang tiling.

Returns
The bitmap pointer m_pBitmap.

Definition at line 255 of file CMain.cpp.

◆ LoadTileSet()

HRESULT CMain::LoadTileSet ( const UINT  idm,
const UINT  n 
)

Load a tileset into m_pTile and set the checkmarks on the Tileset menu. Assumes that m_hTilesetMenu contains a handle to the Tileset menu and that the tile images are in separate numbered png files in a hard-coded subfolder of the tiles folder.

Parameters
idmA menu identifier for the required tileset.
nNumber of tiles in the tileset.
Returns
S_OK if the tileset loaded correctly, E_FAIL otherwise.

Definition at line 182 of file CMain.cpp.

◆ OnPaint()

void CMain::OnPaint ( )

Draw the bitmap m_pBitmap to the window client area, scaled down if necessary. This function should only be called in response to a WM_PAINT message.

Definition at line 77 of file CMain.cpp.

Member Data Documentation

◆ m_gdiplusToken

ULONG_PTR CMain::m_gdiplusToken = 0
private

Definition at line 44 of file CMain.h.

◆ m_hTilesetMenu

HMENU CMain::m_hTilesetMenu = nullptr
private

Definition at line 42 of file CMain.h.

◆ m_hWnd

HWND CMain::m_hWnd = nullptr
private

Definition at line 41 of file CMain.h.

◆ m_nNumTiles

UINT CMain::m_nNumTiles = 0
private

Definition at line 50 of file CMain.h.

◆ m_pBitmap

Gdiplus::Bitmap* CMain::m_pBitmap = nullptr
private

Definition at line 46 of file CMain.h.

◆ m_pTile

Gdiplus::Bitmap** CMain::m_pTile = nullptr
private

Definition at line 49 of file CMain.h.

◆ m_pWangTiler

CWangTiler* CMain::m_pWangTiler
private

Definition at line 48 of file CMain.h.