29#include <shobjidl_core.h>
38#pragma region Initialization
44 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
45 ULONG_PTR gdiplusToken;
46 Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput,
nullptr);
50#pragma endregion Initialization
55#pragma region Save functions
67 Gdiplus::ImageCodecInfo* pCodecInfo =
nullptr;
68 if(FAILED(Gdiplus::GetImageEncodersSize(&num, &n)))
return E_FAIL;
69 if(n == 0)
return E_FAIL;
71 pCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(n));
72 if(pCodecInfo ==
nullptr)
return E_FAIL;
73 if(FAILED(GetImageEncoders(num, n, pCodecInfo)))
return E_FAIL;
75 for(UINT j=0; j<num && hr!=S_OK; j++)
76 if(wcscmp(pCodecInfo[j].MimeType, format) == 0){
77 *pClsid = pCodecInfo[j].Clsid;
97HRESULT
SaveBitmap(HWND hwnd,
const std::wstring& wstrName,
98 Gdiplus::Bitmap* pBitmap)
100 COMDLG_FILTERSPEC filetypes[] = {
101 {L
"PNG Files", L
"*.png"}
104 std::wstring wstrFileName;
105 CComPtr<IFileSaveDialog> pDlg;
106 CComPtr<IShellItem> pItem;
107 LPWSTR pwsz =
nullptr;
111 if(FAILED(pDlg.CoCreateInstance(__uuidof(FileSaveDialog))))
return E_FAIL;
113 pDlg->SetFileTypes(_countof(filetypes), filetypes);
114 pDlg->SetTitle(L
"Save Image");
115 pDlg->SetFileName(wstrName.c_str());
116 pDlg->SetDefaultExtension(L
"png");
118 if(FAILED(pDlg->Show(hwnd)))
return E_FAIL;
119 if(FAILED(pDlg->GetResult(&pItem)))
return E_FAIL;
120 if(FAILED(pItem->GetDisplayName(SIGDN_FILESYSPATH, &pwsz)))
return E_FAIL;
125 if(FAILED(
GetEncoderClsid((WCHAR*)L
"image/png", &clsid)))
return E_FAIL;
126 pBitmap->Save(pwsz, &clsid,
nullptr);
133#pragma endregion Save functions
138#pragma region Create menu functions
145 HMENU hMenu = CreateMenu();
151 AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L
"&File");
160 HMENU hMenu = CreateMenu();
164 AppendMenuW(hMenu, MF_SEPARATOR, 0,
nullptr);
167 AppendMenuW(hMenu, MF_SEPARATOR, 0,
nullptr);
170 AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L
"&Generate");
179 HMENU hMenu = CreateMenu();
184 AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L
"&View");
193 HMENU hMenu = CreateMenu();
202 AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L
"&Distribution");
211 HMENU hMenu = CreateMenu();
213 AppendMenuW(hMenu, MF_STRING,
IDM_HASH_PERM, L
"Permutation");
214 AppendMenuW(hMenu, MF_STRING,
IDM_HASH_LCON, L
"Linear congruential");
215 AppendMenuW(hMenu, MF_STRING,
IDM_HASH_STD, L
"Std::hash");
217 AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L
"&Hash");
226 HMENU hMenu = CreateMenu();
232 AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L
"&Spline");
241 HMENU hMenu = CreateMenu();
244 L
"Increase number of octaves");
246 L
"Decrease number of octaves");
247 AppendMenuW(hMenu, MF_SEPARATOR, 0,
nullptr);
250 AppendMenuW(hMenu, MF_SEPARATOR, 0,
nullptr);
253 AppendMenuW(hMenu, MF_SEPARATOR, 0,
nullptr);
256 AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L
"&Settings");
264 HMENU hMenu = CreateMenu();
266 AppendMenuW(hMenu, MF_STRING,
IDM_HELP_HELP, L
"Display help...");
268 AppendMenuW(hMenubar, MF_POPUP, (UINT_PTR)hMenu, L
"&Help");
271#pragma endregion Create menu functions
276#pragma region Update menu functions
284 if(noise == eNoise::None){
305 (noise == eNoise::Perlin)? MF_CHECKED: MF_UNCHECKED);
307 (noise == eNoise::Value)? MF_CHECKED: MF_UNCHECKED);
310 (noise == eNoise::None)? MF_GRAYED: MF_ENABLED);
312 (noise == eNoise::None)? MF_GRAYED: MF_ENABLED);
315 (noise == eNoise::None)? MF_GRAYED: MF_ENABLED);
325 (noise == eNoise::None)? MF_GRAYED: MF_ENABLED);
327 (noise == eNoise::None)? MF_GRAYED: MF_ENABLED);
337 EnableMenuItem(hMenu, item,
338 (noise == eNoise::None || bGray)? MF_GRAYED: MF_ENABLED);
347 CheckMenuItem(hMenu, item, bCheck? MF_CHECKED: MF_UNCHECKED);
357 if(noise == eNoise::None){
376 distr == eDistribution::Uniform? MF_CHECKED: MF_UNCHECKED);
378 distr == eDistribution::Maximal? MF_CHECKED: MF_UNCHECKED);
380 distr == eDistribution::Cosine? MF_CHECKED: MF_UNCHECKED);
382 distr == eDistribution::Normal? MF_CHECKED: MF_UNCHECKED);
384 distr == eDistribution::Exponential? MF_CHECKED: MF_UNCHECKED);
386 distr == eDistribution::Midpoint? MF_CHECKED: MF_UNCHECKED);
412 (h == eHash::Permutation)? MF_CHECKED: MF_UNCHECKED);
414 (h == eHash::LinearCongruential)? MF_CHECKED: MF_UNCHECKED);
416 (h == eHash::Std)? MF_CHECKED: MF_UNCHECKED);
442 (spline == eSpline::None)? MF_CHECKED: MF_UNCHECKED);
444 (spline == eSpline::Cubic)? MF_CHECKED: MF_UNCHECKED);
446 (spline == eSpline::Quintic)? MF_CHECKED: MF_UNCHECKED);
455 if(noise == eNoise::None){
eDistribution
Distribution.
HMENU CreateViewMenu(HMENU hMenubar)
Create View menu.
void UpdateGenerateMenu(HMENU hMenu, eNoise noise)
Update Generate menu.
HMENU CreateSplineMenu(HMENU hMenubar)
Create Spline menu.
HMENU CreateHashMenu(HMENU hMenubar)
Create Hash menu.
void UpdateHashMenu(HMENU hMenu, eNoise noise, eHash h)
Update Hash menu.
void UpdateViewMenu(HMENU hMenu, eNoise noise)
Update View menu.
HMENU CreateDistributionMenu(HMENU hMenubar)
Create Distribution menu.
void UpdateSettingsMenu(HMENU hMenu, eNoise noise)
Update Settings menu.
HMENU CreateSettingsMenu(HMENU hMenubar)
Create Settings menu.
void UpdateSplineMenu(HMENU hMenu, eNoise noise, eSpline spline)
Update Spline menu.
HRESULT SaveBitmap(HWND hwnd, const std::wstring &wstrName, Gdiplus::Bitmap *pBitmap)
Save bitmap to file.
HRESULT GetEncoderClsid(const WCHAR *format, CLSID *pClsid)
void UpdateMenuItemGray(HMENU hMenu, UINT item, eNoise noise, bool bGray)
Update menu item bool.
ULONG_PTR InitGDIPlus()
Initialize GDI+.
void UpdateFileMenu(HMENU hMenu, eNoise noise)
Update File menu.
HMENU CreateFileMenu(HMENU hMenubar)
Create File menu.
void UpdateDistributionMenu(HMENU hMenu, eNoise noise, eDistribution distr)
Update Distribution menu.
void UpdateMenuItemCheck(HMENU hMenu, UINT item, bool bCheck)
Update menu item check.
void CreateHelpMenu(HMENU hMenubar)
Create Help menu.
HMENU CreateGenerateMenu(HMENU hMenubar)
Create Generate menu.
Interface for some helpful Windows-specific functions.
#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.