32#pragma region Constructors and destructors
47 FatalAppExit(0,
"One or more default tileset images are missing.");
66#pragma endregion Constructors and destructors
71#pragma region Drawing functions
79 HDC hdc = BeginPaint(
m_hWnd, &ps);
80 Gdiplus::Graphics graphics(hdc);
84 const int nBitmapWidth =
m_pBitmap->GetWidth();
85 const int nBitmapHeight =
m_pBitmap->GetHeight();
90 GetClientRect(
m_hWnd, &rectClient);
91 const int nClientWidth = rectClient.right - rectClient.left;
92 const int nClientHeight = rectClient.bottom - rectClient.top;
96 const int nDestSide = min(nClientWidth, nClientHeight);
98 const int width = min(nDestSide, nBitmapWidth);
99 const int height = min(nDestSide, nBitmapHeight);
101 const int x = max(0, nClientWidth - width)/2;
102 const int y = max(0, nClientHeight - height)/2;
104 Gdiplus::Rect rectDest(x, y, width, height);
118 const UINT nTileWidth =
m_pTile[0]->GetWidth();
119 const UINT nTileHeight =
m_pTile[0]->GetHeight();
131 r.Width = nTileWidth;
132 r.Height = nTileHeight;
135 graphics.SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
137 for(
size_t i=0; i<nGridHeight; i++){
138 for(
size_t j=0; j<nGridWidth; j++){
139 const size_t index = (*m_pWangTiler)(i, j);
140 graphics.DrawImage(
m_pTile[index], r);
149#pragma endregion Drawing functions
154#pragma region Menu functions
160 HMENU hMenubar = CreateMenu();
166 SetMenu(
m_hWnd, hMenubar);
169#pragma endregion Menu functions
185 std::wstring filename;
186 Gdiplus::Bitmap** temp =
new Gdiplus::Bitmap*[n];
193 m_pTile =
new Gdiplus::Bitmap*[n];
194 for(UINT i=0; i<n; i++)
200 for(i=0; i<n && !error; i++){
201 filename = L
"tiles\\";
210 filename += std::wstring(L
"\\") + std::to_wstring(i) + L
".png";
212 temp[i] = Gdiplus::Bitmap::FromFile(filename.c_str());
213 error = temp[i]->GetLastStatus() != Gdiplus::Ok;
219 std::wstring s = L
"Error loading file " + filename;
220 MessageBoxW(
m_hWnd, s.c_str(), L
"Error", MB_ICONERROR | MB_OK);
222 for(UINT j=0; j<i; j++)
227 for(UINT j=0; j<n; j++){
242 return error? E_FAIL: S_OK;
Interface for the main class CMain.
HMENU CreateTilesetMenu(HMENU hParent)
Create Tileset menu.
void CreateFileMenu(HMENU hParent)
Create File menu.
ULONG_PTR InitGDIPlus()
Initialize GDI+.
void CreateHelpMenu(HMENU hParent)
Create Help menu.
Interface for some helpful Windows-specific functions.
#define IDM_TILESET_FLOWER
Menu id for flower tileset.
#define IDM_TILESET_GRASS
Menu id for grass tileset.
#define IDM_TILESET_MUD
Menu id for dirt tileset.
#define IDM_TILESET_DEFAULT
Menu id for default tileset.
HRESULT LoadTileSet(const UINT idm, const UINT n)
Load tileset.
CWangTiler * m_pWangTiler
Pointer to the Wang tiler.
void CreateMenus()
Create menus.
UINT m_nNumTiles
Number of tiles in tileset.
Gdiplus::Bitmap ** m_pTile
The tile pointer array.
void Draw()
Draw the Wang tiling.
void Generate()
Generate a Wang tiling.
CMain(const HWND hwnd)
Constructor.
ULONG_PTR m_gdiplusToken
GDI+ token.
Gdiplus::Bitmap * GetBitmap()
Get pointer to bitmap.
HMENU m_hTilesetMenu
Handle to the Generate menu.
Gdiplus::Bitmap * m_pBitmap
Pointer to a bitmap image.
void OnPaint()
Paint the client area of the window.
HWND m_hWnd
Window handle.
void Generate()
Generate tiling.
const size_t GetHeight() const
Get height in tiles.
const size_t GetWidth() const
Get width in tiles.