Smooth 2D Noise Viewer
Perlin and Value Noise
WindowsHelpers.h
Go to the documentation of this file.
1
6
7// MIT License
8//
9// Copyright (c) 2022 Ian Parberry
10//
11// Permission is hereby granted, free of charge, to any person obtaining a copy
12// of this software and associated documentation files (the "Software"), to
13// deal in the Software without restriction, including without limitation the
14// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
15// sell copies of the Software, and to permit persons to whom the Software is
16// furnished to do so, subject to the following conditions:
17//
18// The above copyright notice and this permission notice shall be included in
19// all copies or substantial portions of the Software.
20//
21// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27// IN THE SOFTWARE.
28
29#ifndef __WINDOWSHELPERS_H__
30#define __WINDOWSHELPERS_H__
31
32#include "Includes.h"
33#include "Defines.h"
34
36// Menu IDs
37
38#pragma region Menu IDs
39
40#define IDM_FILE_SAVE 1
41#define IDM_FILE_PROPS 2
42#define IDM_FILE_QUIT 3
43
44#define IDM_GENERATE_PERLINNOISE 4
45#define IDM_GENERATE_VALUENOISE 5
46#define IDM_GENERATE_RANDOMIZE 6
47#define IDM_GENERATE_JUMP 7
48#define IDM_GENERATE_RESETORIGIN 8
49
50#define IDM_VIEW_COORDS 9
51#define IDM_VIEW_GRID 10
52
53#define IDM_DISTRIBUTION_UNIFORM 11
54#define IDM_DISTRIBUTION_COSINE 12
55#define IDM_DISTRIBUTION_NORMAL 13
56#define IDM_DISTRIBUTION_EXPONENTIAL 14
57#define IDM_DISTRIBUTION_MIDPOINT 15
58#define IDM_DISTRIBUTION_MAXIMAL 16
59
60#define IDM_HASH_PERM 17
61#define IDM_HASH_LCON 18
62#define IDM_HASH_STD 19
63
64#define IDM_SPLINE_NONE 20
65#define IDM_SPLINE_CUBIC 21
66#define IDM_SPLINE_QUINTIC 22
67
68#define IDM_SETTINGS_OCTAVE_UP 23
69#define IDM_SETTINGS_OCTAVE_DN 24
70#define IDM_SETTINGS_SCALE_UP 25
71#define IDM_SETTINGS_SCALE_DN 26
72#define IDM_SETTINGS_TSIZE_UP 27
73#define IDM_SETTINGS_TSIZE_DN 28
74#define IDM_SETTINGS_RESET 29
75
76#define IDM_HELP_HELP 30
77#define IDM_HELP_ABOUT 31
78
79#pragma endregion Menu IDs
80
82// Helper functions
83
84#pragma region Helper functions
85
86//initialization functions
87
88ULONG_PTR InitGDIPlus();
89
90//others
91
92HRESULT SaveBitmap(HWND, const std::wstring&, Gdiplus::Bitmap*);
93
94#pragma endregion Helper functions
95
97// Menu functions
98
99#pragma region Menu functions
100
101HMENU CreateFileMenu(HMENU);
102HMENU CreateGenerateMenu(HMENU);
103HMENU CreateViewMenu(HMENU);
104HMENU CreateDistributionMenu(HMENU);
105HMENU CreateHashMenu(HMENU);
106HMENU CreateSplineMenu(HMENU);
107HMENU CreateSettingsMenu(HMENU);
108void CreateHelpMenu(HMENU);
109
110void UpdateMenuItemGray(HMENU, UINT, eNoise, bool);
111void UpdateMenuItemCheck(HMENU, UINT, bool);
112
113void UpdateFileMenu(HMENU, eNoise);
114void UpdateGenerateMenu(HMENU, eNoise);
115void UpdateViewMenu(HMENU, eNoise);
116
118void UpdateHashMenu(HMENU, eNoise, eHash);
119void UpdateSplineMenu(HMENU, eNoise, eSpline);
120void UpdateSettingsMenu(HMENU, eNoise);
121
135
136template<typename t>
137void UpdateMenuItem(HMENU hMenu, UINT up, UINT dn, eNoise noise,
138 t n, t nMin, t nMax)
139{
140 if(noise == eNoise::None){ //all gray
141 EnableMenuItem(hMenu, up, MF_GRAYED);
142 EnableMenuItem(hMenu, dn, MF_GRAYED);
143 } //if
144
145 else{ //grayed if out of range
146 EnableMenuItem(hMenu, up, (n < nMax)? MF_ENABLED: MF_GRAYED);
147 EnableMenuItem(hMenu, dn, (n > nMin)? MF_ENABLED: MF_GRAYED);
148 } //else
149} //UpdateMenuItem
150
151#pragma endregion Menu functions
152
153#endif //__WINDOWSHELPERS_H__
Useful defines, constants, and types.
eDistribution
Distribution.
Definition: Defines.h:54
eSpline
Spline type.
Definition: Defines.h:62
eHash
Hash function type.
Definition: Defines.h:46
eNoise
Perlin noise type.
Definition: Defines.h:38
Useful includes.
HMENU CreateFileMenu(HMENU)
Create File menu.
HMENU CreateHashMenu(HMENU)
Create Hash menu.
HMENU CreateViewMenu(HMENU)
Create View menu.
void UpdateSettingsMenu(HMENU, eNoise)
Update Settings menu.
void UpdateFileMenu(HMENU, eNoise)
Update File menu.
HMENU CreateGenerateMenu(HMENU)
Create Generate menu.
void UpdateGenerateMenu(HMENU, eNoise)
Update Generate menu.
void CreateHelpMenu(HMENU)
Create Help menu.
HMENU CreateSettingsMenu(HMENU)
Create Settings menu.
void UpdateMenuItemGray(HMENU, UINT, eNoise, bool)
Update menu item bool.
void UpdateSplineMenu(HMENU, eNoise, eSpline)
Update Spline menu.
void UpdateHashMenu(HMENU, eNoise, eHash)
Update Hash menu.
ULONG_PTR InitGDIPlus()
Initialize GDI+.
void UpdateMenuItem(HMENU hMenu, UINT up, UINT dn, eNoise noise, t n, t nMin, t nMax)
Update a numeric menu item.
HMENU CreateDistributionMenu(HMENU)
Create Distribution menu.
void UpdateViewMenu(HMENU, eNoise)
Update View menu.
HMENU CreateSplineMenu(HMENU)
Create Spline menu.
void UpdateMenuItemCheck(HMENU, UINT, bool)
Update menu item check.
void UpdateDistributionMenu(HMENU, eNoise, eDistribution)
Update Distribution menu.
HRESULT SaveBitmap(HWND, const std::wstring &, Gdiplus::Bitmap *)
Save bitmap to file.