Wang Tiling
A Simple Wang Tiling Generator
Main.cpp
Go to the documentation of this file.
1
3
4// MIT License
5//
6// Copyright (c) 2020 Ian Parberry
7//
8// Permission is hereby granted, free of charge, to any person obtaining a copy
9// of this software and associated documentation files (the "Software"), to
10// deal in the Software without restriction, including without limitation the
11// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12// sell copies of the Software, and to permit persons to whom the Software is
13// furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice shall be included in
16// all copies or substantial portions of the Software.
17//
18// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24// IN THE SOFTWARE.
25
26#include "Includes.h"
27
28#include "CMain.h"
29
30static CMain* g_pMain = nullptr;
31
40
41LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
42 UINT nMenuId = 0; //menu identifier for menu command messages
43 static bool bResizing = false;
44
45 switch(message){
46 case WM_CREATE: //window has been created
47 g_pMain = new CMain(hWnd); //create the main class
48 return 0;
49
50 case WM_DESTROY: //window has been removed from the screen
51 delete g_pMain; //delete the main class
52 PostQuitMessage(0); //ready to shut down
53 return 0;
54
55 case WM_PAINT: //window needs to be redrawn
57 return 0;
58
59 case WM_COMMAND: //user has selected a command from the menu
60 nMenuId = LOWORD(wParam); //menu id
61
62 switch(nMenuId){
63
66 g_pMain->Draw();
67 InvalidateRect(hWnd, nullptr, FALSE);
68 break;
69
70 case IDM_FILE_SAVE: //save bitmap to image file
72 break;
73
74 case IDM_FILE_QUIT: //so long, farewell, auf weidersehn, goodbye!
75 SendMessage(hWnd, WM_CLOSE, 0, 0);
76 break;
77
80 case IDM_TILESET_MUD:
82 g_pMain->LoadTileSet(nMenuId, 8); //load tile set
83 g_pMain->Draw(); //draw with current tiling
84 InvalidateRect(hWnd, nullptr, FALSE); //show in window
85 break;
86
87 case IDM_HELP_HELP:
88 ShellExecute(0, 0,
89 "https://ian-parberry.github.io/wangtiler/html/",
90 0, 0, SW_SHOW);
91 break;
92
93 case IDM_HELP_ABOUT:
94 MessageBox(nullptr,
95 "Copyright © Ian Parberry, 2022.\nSource code available under the MIT License from https://github.com/Ian-Parberry/wangtiler.",
96 "About", MB_ICONINFORMATION | MB_OK);
97 break;
98 } //switch
99
100 return 0; //all is good
101
102 default:
103 return DefWindowProc(hWnd, message, wParam, lParam); //not my message
104 } //switch
105} //WndProc
106
115
116int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpStr, int nShow){
117 UNREFERENCED_PARAMETER(hPrev); //nope
118 UNREFERENCED_PARAMETER(lpStr); //nope nope
119
120 InitWindow(hInst, nShow, WndProc); //create and show a window
121
122 MSG msg; //current message
123
124 while(GetMessage(&msg, nullptr, 0, 0)){ //message pump
125 TranslateMessage(&msg);
126 DispatchMessage(&msg);
127 } //while
128
129 return (int)msg.wParam;
130} //wWinMain
Interface for the main class CMain.
Useful includes.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Window procedure.
Definition: Main.cpp:41
static CMain * g_pMain
Pointer to the main class.
Definition: Main.cpp:30
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpStr, int nShow)
Winmain.
Definition: Main.cpp:116
HRESULT SaveBitmap(HWND hwnd, Gdiplus::Bitmap *pBitmap)
Save bitmap to file.
void InitWindow(HINSTANCE hInst, INT nShow, WNDPROC WndProc)
Initialize window.
#define IDM_TILESET_FLOWER
Menu id for flower tileset.
#define IDM_FILE_SAVE
Menu id for Save.
#define IDM_TILESET_GRASS
Menu id for grass tileset.
#define IDM_FILE_QUIT
Menu id for Quit.
#define IDM_FILE_GENERATE
Menu id for Generate.
#define IDM_HELP_HELP
Menu id for display help.
#define IDM_TILESET_MUD
Menu id for dirt tileset.
#define IDM_HELP_ABOUT
Menu id for display About info.
#define IDM_TILESET_DEFAULT
Menu id for default tileset.
The main class.
Definition: CMain.h:39
HRESULT LoadTileSet(const UINT idm, const UINT n)
Load tileset.
Definition: CMain.cpp:182
void Draw()
Draw the Wang tiling.
Definition: CMain.cpp:117
void Generate()
Generate a Wang tiling.
Definition: CMain.cpp:247
Gdiplus::Bitmap * GetBitmap()
Get pointer to bitmap.
Definition: CMain.cpp:255
void OnPaint()
Paint the client area of the window.
Definition: CMain.cpp:77