43LRESULT CALLBACK
WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
45 static bool bResizing =
false;
65 nMenuId = LOWORD(wParam);
77 L
"Properties", MB_ICONINFORMATION | MB_OK);
81 SendMessage(hWnd, WM_CLOSE, 0, 0);
88 InvalidateRect(hWnd,
nullptr, FALSE);
93 InvalidateRect(hWnd,
nullptr, FALSE);
98 InvalidateRect(hWnd,
nullptr, FALSE);
103 InvalidateRect(hWnd,
nullptr, FALSE);
108 InvalidateRect(hWnd,
nullptr, FALSE);
115 InvalidateRect(hWnd,
nullptr, FALSE);
120 InvalidateRect(hWnd,
nullptr, FALSE);
127 InvalidateRect(hWnd,
nullptr, FALSE);
132 InvalidateRect(hWnd,
nullptr, FALSE);
137 InvalidateRect(hWnd,
nullptr, FALSE);
142 InvalidateRect(hWnd,
nullptr, FALSE);
147 InvalidateRect(hWnd,
nullptr, FALSE);
152 InvalidateRect(hWnd,
nullptr, FALSE);
159 InvalidateRect(hWnd,
nullptr, FALSE);
164 InvalidateRect(hWnd,
nullptr, FALSE);
169 InvalidateRect(hWnd,
nullptr, FALSE);
176 InvalidateRect(hWnd,
nullptr, FALSE);
181 InvalidateRect(hWnd,
nullptr, FALSE);
186 InvalidateRect(hWnd,
nullptr, FALSE);
193 InvalidateRect(hWnd,
nullptr, FALSE);
198 InvalidateRect(hWnd,
nullptr, FALSE);
203 InvalidateRect(hWnd,
nullptr, FALSE);
208 InvalidateRect(hWnd,
nullptr, FALSE);
213 InvalidateRect(hWnd,
nullptr, FALSE);
218 InvalidateRect(hWnd,
nullptr, FALSE);
223 InvalidateRect(hWnd,
nullptr, FALSE);
230 L
"https://ian-parberry.github.io/smooth2dnoiseviewer/html/",
236 L
"Copyright © Ian Parberry, 2022.\nSource code available under the MIT License from https://github.com/Ian-Parberry/smooth2dnoiseviewer.",
237 L
"About", MB_ICONINFORMATION | MB_OK);
244 return DefWindowProc(hWnd, message, wParam, lParam);
254 const LPCWSTR appname = L
"2D Noise Generator";
256 WNDCLASSEX wndClass = {0};
258 wndClass.cbSize =
sizeof(WNDCLASSEX);
259 wndClass.style = CS_HREDRAW | CS_VREDRAW;
260 wndClass.lpfnWndProc =
WndProc;
261 wndClass.cbClsExtra = 0;
262 wndClass.cbWndExtra = 0;
263 wndClass.hInstance = hInst;
264 wndClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
265 wndClass.hCursor = LoadCursor(
nullptr, IDC_ARROW);
266 wndClass.hbrBackground =
nullptr;
267 wndClass.lpszMenuName =
nullptr;
268 wndClass.lpszClassName = appname;
270 RegisterClassEx(&wndClass);
272 const DWORD dwStyle = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
273 const DWORD dwStyleEx = WS_EX_APPWINDOW | WS_EX_DLGMODALFRAME;
277 r.bottom =
g_nHeight + GetSystemMetrics(SM_CYMENU);
278 AdjustWindowRectEx(&r, dwStyle, FALSE, dwStyleEx);
280 const HWND hwnd = CreateWindowEx(dwStyleEx, appname, appname, dwStyle,
281 CW_USEDEFAULT, CW_USEDEFAULT, r.right - r.left, r.bottom - r.top,
282 nullptr,
nullptr, hInst,
nullptr);
284 ShowWindow(hwnd, nShow);
297int WINAPI
wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpStr,
int nShow){
298 UNREFERENCED_PARAMETER(hPrev);
299 UNREFERENCED_PARAMETER(lpStr);
305 while(GetMessage(&msg,
nullptr, 0, 0)){
306 TranslateMessage(&msg);
307 DispatchMessage(&msg);
310 return (
int)msg.wParam;
Interface for the main class CMain.
static const int g_nHeight
Client area height in pixels.
static const int g_nWidth
Client area width in pixels.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Window procedure.
static CMain * g_pMain
Pointer to the main class.
void InitWindow(HINSTANCE hInst, INT nShow, WNDPROC WndProc)
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR lpStr, int nShow)
Winmain.
HRESULT SaveBitmap(HWND hwnd, const std::wstring &wstrName, Gdiplus::Bitmap *pBitmap)
Save bitmap to file.
#define IDM_SETTINGS_TSIZE_UP
Menu id for table size up.
#define IDM_VIEW_GRID
Menu id for view grid.
#define IDM_GENERATE_VALUENOISE
Menu id for Value Noise.
#define IDM_DISTRIBUTION_EXPONENTIAL
Menu id for exponential distribution.
#define IDM_DISTRIBUTION_UNIFORM
Menu id for uniform distribution.
#define IDM_HASH_LCON
Menu id for linear congruential hash.
#define IDM_DISTRIBUTION_NORMAL
Menu id for normal distribution.
#define IDM_GENERATE_PERLINNOISE
Menu id for Perlin Noise.
#define IDM_FILE_SAVE
Menu id for Save.
#define IDM_SPLINE_QUINTIC
Menu id for quintic spline.
#define IDM_SPLINE_NONE
Menu id for cubic spline.
#define IDM_HASH_STD
Menu id for std::hash.
#define IDM_SETTINGS_SCALE_UP
Menu id for scale up.
#define IDM_SETTINGS_SCALE_DN
Menu id for scale down.
#define IDM_GENERATE_JUMP
Menu id for jump.
#define IDM_FILE_QUIT
Menu id for Quit.
#define IDM_HASH_PERM
Menu id for permutation hash.
#define IDM_SETTINGS_RESET
Menu id for reset settings.
#define IDM_HELP_HELP
Menu id for display help.
#define IDM_SETTINGS_TSIZE_DN
Menu id for table size down.
#define IDM_SETTINGS_OCTAVE_UP
Menu id for octave up.
#define IDM_SPLINE_CUBIC
Menu id for no spline.
#define IDM_SETTINGS_OCTAVE_DN
Menu id for octave down.
#define IDM_DISTRIBUTION_COSINE
Menu id for cosine distribution.
#define IDM_GENERATE_RANDOMIZE
Menu id for regenerate Noise.
#define IDM_DISTRIBUTION_MAXIMAL
Menu id for midpoint displacement.
#define IDM_DISTRIBUTION_MIDPOINT
Menu id for midpoint displacement.
#define IDM_HELP_ABOUT
Menu id for display About info.
#define IDM_VIEW_COORDS
Menu id for view coordinates.
#define IDM_GENERATE_RESETORIGIN
Menu id for reset origin.
#define IDM_FILE_PROPS
Menu id for Properties.
const std::wstring GetNoiseDescription() const
Get noise description.
void DecreaseScale()
Decrease scale.
const std::wstring GetFileName() const
Get noise file name.
void CreateBitmap(int w, int h)
Create bitmap.
void Randomize()
Randomize PRNG.
void Reset()
Reset number of octaves, scale, table size.
bool SetDistribution(eDistribution)
Set probability distribution.
void DecreaseTableSize()
Decrease table size.
void GenerateNoiseBitmap(Gdiplus::PointF, Gdiplus::RectF)
Generate bitmap rectangle.
void ToggleViewCoords()
Toggle View Coordinates flag.
void IncreaseTableSize()
Increase table size.
Gdiplus::Bitmap * GetBitmap() const
Get pointer to bitmap.
void SetHash(eHash)
Set hash function.
void DecreaseOctaves()
Decrease number of octaves.
void Jump()
Change origin coordinates.
void ToggleViewGrid()
Toggle View Grid flag.
void SetSpline(eSpline)
Set spline function.
void IncreaseOctaves()
Increase number of octaves.
void OnPaint()
Paint the client area of the window.
void IncreaseScale()
Increase scale.