Smooth 2D Noise Viewer
Perlin and Value Noise
CMain.h
Go to the documentation of this file.
1
3
4// MIT License
5//
6// Copyright (c) 2022 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#ifndef __CMAIN_H__
27#define __CMAIN_H__
28
29#include "Includes.h"
30#include "Windows.h"
31#include "WindowsHelpers.h"
32#include "perlin.h"
33
40
41class CMain{
42 private:
43 HWND m_hWnd = nullptr;
44
45 HMENU m_hFileMenu = nullptr;
46 HMENU m_hGenMenu = nullptr;
47 HMENU m_hViewMenu = nullptr;
48 HMENU m_hSetMenu = nullptr;
49 HMENU m_hDistMenu = nullptr;
50 HMENU m_hHashMenu = nullptr;
51 HMENU m_hSplineMenu = nullptr;
52 HMENU m_hOctaveMenu = nullptr;
53
54 eNoise m_eNoise = eNoise::None;
55
56 float m_fOriginX = 0.0f;
57 float m_fOriginY = 0.0f;
58
59 const size_t m_nDefOctaves = 4;
61 const size_t m_nMinOctaves = 1;
62 const size_t m_nMaxOctaves = 8;
63
64 const float m_fDefScale = 64.0f;
66 const float m_fMinScale = 8.0f;
67 const float m_fMaxScale = 512.0f;
68
69 float m_fMin = 0.0f;
70 float m_fMax = 0.0f;
71 float m_fAve = 0.0f;
72
73 ULONG_PTR m_gdiplusToken = 0;
74
75 Gdiplus::Bitmap* m_pBitmap = nullptr;
77
78 bool m_bShowCoords = false;
79 bool m_bShowGrid = false;
80
81 void CreateMenus();
82 void UpdateMenus();
83
84 void SetPixel(UINT, UINT, float);
85 void SetPixel(UINT, UINT, BYTE);
86 void SetPixel(UINT, UINT, Gdiplus::Color);
87
88 void DrawCoords();
89 void DrawGrid();
90
91 void GenerateNoiseBitmap(Gdiplus::PointF, Gdiplus::RectF);
92
93 public:
94 CMain(const HWND hwnd);
95 ~CMain();
96
97 void CreateBitmap(int w, int h);
98 void ClearBitmap(Gdiplus::Color);
99
100 void Randomize();
101
103 void GenerateNoiseBitmap();
104
106 void SetSpline(eSpline);
107 void SetHash(eHash);
108
109 void ToggleViewCoords();
110 void ToggleViewGrid();
111
112 void Jump();
113 void Jump(float x, float y);
114 const bool Origin(float x, float y) const;
115
116 void IncreaseOctaves();
117 void DecreaseOctaves();
118 void IncreaseScale();
119 void DecreaseScale();
120 void IncreaseTableSize();
121 void DecreaseTableSize();
122 void Reset();
123
124 void OnPaint();
125
126 Gdiplus::Bitmap* GetBitmap() const;
127 const std::wstring GetFileName() const;
128 const std::wstring GetNoiseDescription() const;
129}; //CMain
130
131#endif //__CMAIN_H__
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.
Interface for some helpful Windows-specific functions.
The main class.
Definition: CMain.h:41
void ClearBitmap(Gdiplus::Color)
Clear bitmap to color.
Definition: CMain.cpp:184
CPerlinNoise2D * m_pPerlin
Pointer to Perlin noise generator.
Definition: CMain.h:76
HMENU m_hGenMenu
Handle to the Generate menu.
Definition: CMain.h:46
const std::wstring GetNoiseDescription() const
Get noise description.
Definition: CMain.cpp:598
void CreateMenus()
Create menus.
Definition: CMain.cpp:112
HMENU m_hSplineMenu
Handle to the Spline menu.
Definition: CMain.h:51
float m_fScale
Scale.
Definition: CMain.h:65
void DecreaseScale()
Decrease scale.
Definition: CMain.cpp:520
HMENU m_hDistMenu
Handle to the Distribution menu.
Definition: CMain.h:49
void GenerateNoiseBitmap()
Generate bitmap again with saved parameters.
Definition: CMain.cpp:391
void DrawGrid()
Draw grid to bitmap.
Definition: CMain.cpp:344
eNoise m_eNoise
Noise type.
Definition: CMain.h:54
bool m_bShowCoords
Show coordinates flag.
Definition: CMain.h:78
const float m_fMaxScale
Minimum scale.
Definition: CMain.h:67
const std::wstring GetFileName() const
Get noise file name.
Definition: CMain.cpp:559
const size_t m_nMaxOctaves
Maximum number of octaves of noise.
Definition: CMain.h:62
HMENU m_hFileMenu
Handle to the File menu.
Definition: CMain.h:45
void CreateBitmap(int w, int h)
Create bitmap.
Definition: CMain.cpp:175
void Randomize()
Randomize PRNG.
Definition: CMain.cpp:406
float m_fMax
Largest noise value in generated noise.
Definition: CMain.h:70
void Reset()
Reset number of octaves, scale, table size.
Definition: CMain.cpp:542
void UpdateMenus()
Update menus.
Definition: CMain.cpp:131
~CMain()
Destructor.
Definition: CMain.cpp:51
void DrawCoords()
Draw coordinates to bitmap.
Definition: CMain.cpp:297
bool SetDistribution(eDistribution)
Set probability distribution.
Definition: CMain.cpp:417
HMENU m_hHashMenu
Handle to the Hash menu.
Definition: CMain.h:50
void DecreaseTableSize()
Decrease table size.
Definition: CMain.cpp:534
float m_fAve
Average noise value in generated noise.
Definition: CMain.h:71
float m_fOriginX
X-coordinate of top.
Definition: CMain.h:56
CMain(const HWND hwnd)
Constructor.
Definition: CMain.cpp:43
void ToggleViewCoords()
Toggle View Coordinates flag.
Definition: CMain.cpp:449
float m_fOriginY
Y-coordinate of left.
Definition: CMain.h:57
const size_t m_nMinOctaves
Minimum number of octaves of noise.
Definition: CMain.h:61
void IncreaseTableSize()
Increase table size.
Definition: CMain.cpp:527
const size_t m_nDefOctaves
Default number of octaves of noise.
Definition: CMain.h:59
ULONG_PTR m_gdiplusToken
GDI+ token.
Definition: CMain.h:73
Gdiplus::Bitmap * GetBitmap() const
Get pointer to bitmap.
Definition: CMain.cpp:695
const float m_fMinScale
Minimum scale.
Definition: CMain.h:66
void SetHash(eHash)
Set hash function.
Definition: CMain.cpp:440
void DecreaseOctaves()
Decrease number of octaves.
Definition: CMain.cpp:504
void Jump()
Change origin coordinates.
Definition: CMain.cpp:467
HMENU m_hViewMenu
Handle to the View menu.
Definition: CMain.h:47
bool m_bShowGrid
Show grid flag.
Definition: CMain.h:79
void ToggleViewGrid()
Toggle View Grid flag.
Definition: CMain.cpp:458
HMENU m_hSetMenu
Handle to the Settings menu.
Definition: CMain.h:48
void SetSpline(eSpline)
Set spline function.
Definition: CMain.cpp:431
void IncreaseOctaves()
Increase number of octaves.
Definition: CMain.cpp:496
const bool Origin(float x, float y) const
Check origin coordinates.
Definition: CMain.cpp:489
Gdiplus::Bitmap * m_pBitmap
Pointer to a bitmap image.
Definition: CMain.h:75
void OnPaint()
Paint the client area of the window.
Definition: CMain.cpp:67
size_t m_nOctaves
Number of octaves of noise.
Definition: CMain.h:60
const float m_fDefScale
Default scale.
Definition: CMain.h:64
void SetPixel(UINT, UINT, float)
Set pixel grayscale from float.
Definition: CMain.cpp:196
void IncreaseScale()
Increase scale.
Definition: CMain.cpp:512
HWND m_hWnd
Window handle.
Definition: CMain.h:43
float m_fMin
Smallest noise value in generated noise.
Definition: CMain.h:69
HMENU m_hOctaveMenu
Handle to the Octave menu.
Definition: CMain.h:52
2D Perlin and Value noise generator.
Definition: perlin.h:48
Interface for the Perlin and Value noise generators.