Smooth 2D Noise Viewer
Perlin and Value Noise
Macros | Functions
WindowsHelpers.h File Reference

Interface for some helpful Windows-specific functions. More...

#include "Includes.h"
#include "Defines.h"

Go to the source code of this file.

Macros

#define IDM_FILE_SAVE   1
 Menu id for Save. More...
 
#define IDM_FILE_PROPS   2
 Menu id for Properties. More...
 
#define IDM_FILE_QUIT   3
 Menu id for Quit. More...
 
#define IDM_GENERATE_PERLINNOISE   4
 Menu id for Perlin Noise. More...
 
#define IDM_GENERATE_VALUENOISE   5
 Menu id for Value Noise. More...
 
#define IDM_GENERATE_RANDOMIZE   6
 Menu id for regenerate Noise. More...
 
#define IDM_GENERATE_JUMP   7
 Menu id for jump. More...
 
#define IDM_GENERATE_RESETORIGIN   8
 Menu id for reset origin. More...
 
#define IDM_VIEW_COORDS   9
 Menu id for view coordinates. More...
 
#define IDM_VIEW_GRID   10
 Menu id for view grid. More...
 
#define IDM_DISTRIBUTION_UNIFORM   11
 Menu id for uniform distribution. More...
 
#define IDM_DISTRIBUTION_COSINE   12
 Menu id for cosine distribution. More...
 
#define IDM_DISTRIBUTION_NORMAL   13
 Menu id for normal distribution. More...
 
#define IDM_DISTRIBUTION_EXPONENTIAL   14
 Menu id for exponential distribution. More...
 
#define IDM_DISTRIBUTION_MIDPOINT   15
 Menu id for midpoint displacement. More...
 
#define IDM_DISTRIBUTION_MAXIMAL   16
 Menu id for midpoint displacement. More...
 
#define IDM_HASH_PERM   17
 Menu id for permutation hash. More...
 
#define IDM_HASH_LCON   18
 Menu id for linear congruential hash. More...
 
#define IDM_HASH_STD   19
 Menu id for std::hash. More...
 
#define IDM_SPLINE_NONE   20
 Menu id for cubic spline. More...
 
#define IDM_SPLINE_CUBIC   21
 Menu id for no spline. More...
 
#define IDM_SPLINE_QUINTIC   22
 Menu id for quintic spline. More...
 
#define IDM_SETTINGS_OCTAVE_UP   23
 Menu id for octave up. More...
 
#define IDM_SETTINGS_OCTAVE_DN   24
 Menu id for octave down. More...
 
#define IDM_SETTINGS_SCALE_UP   25
 Menu id for scale up. More...
 
#define IDM_SETTINGS_SCALE_DN   26
 Menu id for scale down. More...
 
#define IDM_SETTINGS_TSIZE_UP   27
 Menu id for table size up. More...
 
#define IDM_SETTINGS_TSIZE_DN   28
 Menu id for table size down. More...
 
#define IDM_SETTINGS_RESET   29
 Menu id for reset settings. More...
 
#define IDM_HELP_HELP   30
 Menu id for display help. More...
 
#define IDM_HELP_ABOUT   31
 Menu id for display About info. More...
 

Functions

ULONG_PTR InitGDIPlus ()
 Initialize GDI+. More...
 
HRESULT SaveBitmap (HWND, const std::wstring &, Gdiplus::Bitmap *)
 Save bitmap to file. More...
 
HMENU CreateFileMenu (HMENU)
 Create File menu. More...
 
HMENU CreateGenerateMenu (HMENU)
 Create Generate menu. More...
 
HMENU CreateViewMenu (HMENU)
 Create View menu. More...
 
HMENU CreateDistributionMenu (HMENU)
 Create Distribution menu. More...
 
HMENU CreateHashMenu (HMENU)
 Create Hash menu. More...
 
HMENU CreateSplineMenu (HMENU)
 Create Spline menu. More...
 
HMENU CreateSettingsMenu (HMENU)
 Create Settings menu. More...
 
void CreateHelpMenu (HMENU)
 Create Help menu. More...
 
void UpdateMenuItemGray (HMENU, UINT, eNoise, bool)
 Update menu item bool. More...
 
void UpdateMenuItemCheck (HMENU, UINT, bool)
 Update menu item check. More...
 
void UpdateFileMenu (HMENU, eNoise)
 Update File menu. More...
 
void UpdateGenerateMenu (HMENU, eNoise)
 Update Generate menu. More...
 
void UpdateViewMenu (HMENU, eNoise)
 Update View menu. More...
 
void UpdateDistributionMenu (HMENU, eNoise, eDistribution)
 Update Distribution menu. More...
 
void UpdateHashMenu (HMENU, eNoise, eHash)
 Update Hash menu. More...
 
void UpdateSplineMenu (HMENU, eNoise, eSpline)
 Update Spline menu. More...
 
void UpdateSettingsMenu (HMENU, eNoise)
 Update Settings menu. More...
 
template<typename t >
void UpdateMenuItem (HMENU hMenu, UINT up, UINT dn, eNoise noise, t n, t nMin, t nMax)
 Update a numeric menu item. More...
 

Detailed Description

These platform-dependent functions are hidden away so that the faint-of-heart don't have to see them if they're offended by them.

Definition in file WindowsHelpers.h.

Macro Definition Documentation

◆ IDM_DISTRIBUTION_COSINE

#define IDM_DISTRIBUTION_COSINE   12

Definition at line 54 of file WindowsHelpers.h.

◆ IDM_DISTRIBUTION_EXPONENTIAL

#define IDM_DISTRIBUTION_EXPONENTIAL   14

Definition at line 56 of file WindowsHelpers.h.

◆ IDM_DISTRIBUTION_MAXIMAL

#define IDM_DISTRIBUTION_MAXIMAL   16

Definition at line 58 of file WindowsHelpers.h.

◆ IDM_DISTRIBUTION_MIDPOINT

#define IDM_DISTRIBUTION_MIDPOINT   15

Definition at line 57 of file WindowsHelpers.h.

◆ IDM_DISTRIBUTION_NORMAL

#define IDM_DISTRIBUTION_NORMAL   13

Definition at line 55 of file WindowsHelpers.h.

◆ IDM_DISTRIBUTION_UNIFORM

#define IDM_DISTRIBUTION_UNIFORM   11

Definition at line 53 of file WindowsHelpers.h.

◆ IDM_FILE_PROPS

#define IDM_FILE_PROPS   2

Definition at line 41 of file WindowsHelpers.h.

◆ IDM_FILE_QUIT

#define IDM_FILE_QUIT   3

Definition at line 42 of file WindowsHelpers.h.

◆ IDM_FILE_SAVE

#define IDM_FILE_SAVE   1

Definition at line 40 of file WindowsHelpers.h.

◆ IDM_GENERATE_JUMP

#define IDM_GENERATE_JUMP   7

Definition at line 47 of file WindowsHelpers.h.

◆ IDM_GENERATE_PERLINNOISE

#define IDM_GENERATE_PERLINNOISE   4

Definition at line 44 of file WindowsHelpers.h.

◆ IDM_GENERATE_RANDOMIZE

#define IDM_GENERATE_RANDOMIZE   6

Definition at line 46 of file WindowsHelpers.h.

◆ IDM_GENERATE_RESETORIGIN

#define IDM_GENERATE_RESETORIGIN   8

Definition at line 48 of file WindowsHelpers.h.

◆ IDM_GENERATE_VALUENOISE

#define IDM_GENERATE_VALUENOISE   5

Definition at line 45 of file WindowsHelpers.h.

◆ IDM_HASH_LCON

#define IDM_HASH_LCON   18

Definition at line 61 of file WindowsHelpers.h.

◆ IDM_HASH_PERM

#define IDM_HASH_PERM   17

Definition at line 60 of file WindowsHelpers.h.

◆ IDM_HASH_STD

#define IDM_HASH_STD   19

Definition at line 62 of file WindowsHelpers.h.

◆ IDM_HELP_ABOUT

#define IDM_HELP_ABOUT   31

Definition at line 77 of file WindowsHelpers.h.

◆ IDM_HELP_HELP

#define IDM_HELP_HELP   30

Definition at line 76 of file WindowsHelpers.h.

◆ IDM_SETTINGS_OCTAVE_DN

#define IDM_SETTINGS_OCTAVE_DN   24

Definition at line 69 of file WindowsHelpers.h.

◆ IDM_SETTINGS_OCTAVE_UP

#define IDM_SETTINGS_OCTAVE_UP   23

Definition at line 68 of file WindowsHelpers.h.

◆ IDM_SETTINGS_RESET

#define IDM_SETTINGS_RESET   29

Definition at line 74 of file WindowsHelpers.h.

◆ IDM_SETTINGS_SCALE_DN

#define IDM_SETTINGS_SCALE_DN   26

Definition at line 71 of file WindowsHelpers.h.

◆ IDM_SETTINGS_SCALE_UP

#define IDM_SETTINGS_SCALE_UP   25

Definition at line 70 of file WindowsHelpers.h.

◆ IDM_SETTINGS_TSIZE_DN

#define IDM_SETTINGS_TSIZE_DN   28

Definition at line 73 of file WindowsHelpers.h.

◆ IDM_SETTINGS_TSIZE_UP

#define IDM_SETTINGS_TSIZE_UP   27

Definition at line 72 of file WindowsHelpers.h.

◆ IDM_SPLINE_CUBIC

#define IDM_SPLINE_CUBIC   21

Definition at line 65 of file WindowsHelpers.h.

◆ IDM_SPLINE_NONE

#define IDM_SPLINE_NONE   20

Definition at line 64 of file WindowsHelpers.h.

◆ IDM_SPLINE_QUINTIC

#define IDM_SPLINE_QUINTIC   22

Definition at line 66 of file WindowsHelpers.h.

◆ IDM_VIEW_COORDS

#define IDM_VIEW_COORDS   9

Definition at line 50 of file WindowsHelpers.h.

◆ IDM_VIEW_GRID

#define IDM_VIEW_GRID   10

Definition at line 51 of file WindowsHelpers.h.

Function Documentation

◆ CreateDistributionMenu()

HMENU CreateDistributionMenu ( HMENU  hMenubar)

Create the Distribution menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Distribution menu.

Definition at line 192 of file WindowsHelpers.cpp.

◆ CreateFileMenu()

HMENU CreateFileMenu ( HMENU  hMenubar)

Create the File menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to File menu.

Definition at line 144 of file WindowsHelpers.cpp.

◆ CreateGenerateMenu()

HMENU CreateGenerateMenu ( HMENU  hMenubar)

Create the Generate menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Generate menu.

Definition at line 159 of file WindowsHelpers.cpp.

◆ CreateHashMenu()

HMENU CreateHashMenu ( HMENU  hMenubar)

Create the Hash menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Hash menu.

Definition at line 210 of file WindowsHelpers.cpp.

◆ CreateHelpMenu()

void CreateHelpMenu ( HMENU  hMenubar)

Create the Help menu.

Parameters
hMenubarHandle to menu bar.

Definition at line 263 of file WindowsHelpers.cpp.

◆ CreateSettingsMenu()

HMENU CreateSettingsMenu ( HMENU  hMenubar)

Create the Settings menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Settings menu.

Definition at line 240 of file WindowsHelpers.cpp.

◆ CreateSplineMenu()

HMENU CreateSplineMenu ( HMENU  hMenubar)

Create the Spline menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Spline menu.

Definition at line 225 of file WindowsHelpers.cpp.

◆ CreateViewMenu()

HMENU CreateViewMenu ( HMENU  hMenubar)

Create the View menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to View menu.

Definition at line 178 of file WindowsHelpers.cpp.

◆ InitGDIPlus()

ULONG_PTR InitGDIPlus ( )

Initialize GDI+ and get a GDI+ token.

Returns
A GDI+ token.

Definition at line 43 of file WindowsHelpers.cpp.

◆ SaveBitmap()

HRESULT SaveBitmap ( HWND  hwnd,
const std::wstring &  wstrName,
Gdiplus::Bitmap *  pBitmap 
)

Display a Save dialog box for png files and save a bitmap to the file name that the user selects. Only files with a .png extension are allowed. The default file name is "ImageN.png", where N is the number of images saved so far in the current instance of this program. This prevents any collisions with files already saved by this instance. If there is a collision with a file from a previous instance, then the user is prompted to overwrite or rename it in the normal fashion.

Parameters
hwndWindow handle.
wstrNameFile name without extension.
pBitmapPointer to a bitmap.
Returns
S_OK for success, E_FAIL for failure.

Definition at line 97 of file WindowsHelpers.cpp.

◆ UpdateDistributionMenu()

void UpdateDistributionMenu ( HMENU  hMenu,
eNoise  noise,
eDistribution  distr 
)

Gray out and set the checkmarks in the Distribution menu according to the current noise and distribution types.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.
distrDistribution enumerated type.

Definition at line 356 of file WindowsHelpers.cpp.

◆ UpdateFileMenu()

void UpdateFileMenu ( HMENU  hMenu,
eNoise  noise 
)

Gray out the Properties and Save menu entries in the File menu if there is no noise present, and ungray them otherwise.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.

Definition at line 283 of file WindowsHelpers.cpp.

◆ UpdateGenerateMenu()

void UpdateGenerateMenu ( HMENU  hMenu,
eNoise  noise 
)

Gray out and set the checkmarks in the Generate menu according to the current noise properties. Check or uncheck the menu entries for pixel, Perlin, and Value noise depending on the current noise type. Gray out the Randomize menu entry if there is no noise generated, and ungray it otherwise.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.

Definition at line 303 of file WindowsHelpers.cpp.

◆ UpdateHashMenu()

void UpdateHashMenu ( HMENU  hMenu,
eNoise  noise,
eHash  h 
)

Gray out and set the checkmarks in the Hash menu according to the current noise and hash function types.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.
hHash function enumerated type.

Definition at line 395 of file WindowsHelpers.cpp.

◆ UpdateMenuItem()

template<typename t >
void UpdateMenuItem ( HMENU  hMenu,
UINT  up,
UINT  dn,
eNoise  noise,
n,
nMin,
nMax 
)

Update a menu item that has an up and a down, with maximum and minimum values. Gray out the up item if the number is greater than the maximum allowed, and gray out the down item if the number is less than the minimum allowed. Gray out both if the noise type is eNoise::None.

Parameters
hMenuMenu handle.
upUp menu item id.
dnDown menu item id.
noiseNoise enumerated type.
nA number.
nMinMinimum value.
nMaxMaximum value.

Definition at line 137 of file WindowsHelpers.h.

◆ UpdateMenuItemCheck()

void UpdateMenuItemCheck ( HMENU  hMenu,
UINT  item,
bool  bCheck 
)

Update the check mark on a menu item.

Parameters
hMenuMenu handle.
itemMenu item id.
bCheckTrue if entry is to be checked.

Definition at line 346 of file WindowsHelpers.cpp.

◆ UpdateMenuItemGray()

void UpdateMenuItemGray ( HMENU  hMenu,
UINT  item,
eNoise  noise,
bool  bGray 
)

Gray or ungray a menu item depending on noise type and a boolean value.

Parameters
hMenuMenu handle.
itemMenu item id.
noiseNoise enumerated type.
bGrayTrue if entry is to be grayed out.

Definition at line 336 of file WindowsHelpers.cpp.

◆ UpdateSettingsMenu()

void UpdateSettingsMenu ( HMENU  hMenu,
eNoise  noise 
)

Gray out entries in the Settings menu if they are not appropriate for the current noise type and parameters.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.

Definition at line 454 of file WindowsHelpers.cpp.

◆ UpdateSplineMenu()

void UpdateSplineMenu ( HMENU  hMenu,
eNoise  noise,
eSpline  spline 
)

Gray out and set the checkmarks in the Spline menu according to the current noise and spline types.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.
splineSpline enumerated type.

Definition at line 425 of file WindowsHelpers.cpp.

◆ UpdateViewMenu()

void UpdateViewMenu ( HMENU  hMenu,
eNoise  noise 
)

Gray out entries in the View menu according to the current noise properties.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.

Definition at line 323 of file WindowsHelpers.cpp.