Lindenmayer System
A Simple L-system Image Generator Featuring Turtle Graphics
CMain.h
Go to the documentation of this file.
1 
4 // MIT License
5 //
6 // Copyright (c) 2020 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 #pragma once
27 
28 #include "Includes.h"
29 #include "Types.h"
30 
31 #include "WindowsHelpers.h"
32 #include "Lsystem.h"
33 
39 
40 class CMain{
41  private:
42  HWND m_hWnd = nullptr;
43  HMENU m_hFileMenu = nullptr;
44  HMENU m_hLSMenu = nullptr;
45  HMENU m_hViewMenu = nullptr;
46 
47  ULONG_PTR m_gdiplusToken = 0;
48 
49  Gdiplus::Bitmap* m_pBitmap = nullptr;
50 
52 
54  bool m_bThickLines = false;
55  bool m_bShowRules = true;
56 
57  Gdiplus::FontFamily* m_pFontFamily = nullptr;
58  Gdiplus::Font* m_pFont = nullptr;
59 
60  void SetRules();
61 
62  void Draw(const TurtleDesc& d);
63  void DrawRules(Gdiplus::Graphics& graphics, Gdiplus::PointF p);
64 
65  void CreateMenus();
66  void SetLSystemMenuChecks();
68 
69  int GetRuleStrWidth(Gdiplus::Graphics& graphics);
70 
71  public:
72  CMain(const HWND hwnd);
73  ~CMain();
74 
75  void Draw();
76  void Generate();
77 
78  void OnPaint();
79  void SetType(UINT t);
80  Gdiplus::Bitmap* GetBitmap();
81 
82  const bool IsStochastic() const;
83  void ToggleShowRules();
84  void ToggleLineThickness();
85 }; //CMain
void SetLSystemMenuChecks()
Set L-system menu checkmarks.
Definition: CMain.cpp:341
UINT m_nType
Current L-system type.
Definition: CMain.h:53
ULONG_PTR m_gdiplusToken
GDI+ token.
Definition: CMain.h:47
Useful types and structures.
Turtle graphics descriptor.
Definition: Types.h:41
int GetRuleStrWidth(Gdiplus::Graphics &graphics)
Get rule string width.
Definition: CMain.cpp:509
Gdiplus::Font * m_pFont
Font.
Definition: CMain.h:58
~CMain()
Destructor.
Definition: CMain.cpp:72
Gdiplus::Bitmap * m_pBitmap
Pointer to a bitmap image.
Definition: CMain.h:49
Useful includes.
void CreateMenus()
Create menus.
Definition: CMain.cpp:285
Gdiplus::Bitmap * GetBitmap()
Get pointer to bitmap.
Definition: CMain.cpp:489
Interface for some helpful Windows-specific functions.
A stochastic bracketed context-free L-system.
Definition: Lsystem.h:70
Interface for LProduction and LSystem.
void EnableGenerateMenuEntry()
Enable Generate in File menu.
Definition: CMain.cpp:351
void Generate()
Generate L-system string.
Definition: CMain.cpp:467
void ToggleShowRules()
Toggle the show rules flag.
Definition: CMain.cpp:453
HMENU m_hViewMenu
Handle to the View menu.
Definition: CMain.h:45
CMain(const HWND hwnd)
Constructor.
Definition: CMain.cpp:41
const bool IsStochastic() const
Is a stochastic L-system.
Definition: CMain.cpp:496
void SetRules()
Create the L-system rules.
Definition: CMain.cpp:369
LSystem m_cLSystem
The L-system.
Definition: CMain.h:51
HMENU m_hFileMenu
Handle to the File menu.
Definition: CMain.h:43
bool m_bShowRules
Whether to show the rules.
Definition: CMain.h:55
bool m_bThickLines
Line thickness flag.
Definition: CMain.h:54
The main class.
Definition: CMain.h:40
HMENU m_hLSMenu
Handle to the L-System menu.
Definition: CMain.h:44
#define IDM_LSYS_PLANT_A
Menu id for Fig. 1.24a.
void ToggleLineThickness()
Toggle the line thickness flag.
Definition: CMain.cpp:443
void OnPaint()
Paint the client area.
Definition: CMain.cpp:90
void DrawRules(Gdiplus::Graphics &graphics, Gdiplus::PointF p)
Draw rules.
Definition: CMain.cpp:141
Gdiplus::FontFamily * m_pFontFamily
Font family.
Definition: CMain.h:57
void SetType(UINT t)
Set type.
Definition: CMain.cpp:428
void Draw()
Draw turtle graphics.
Definition: CMain.cpp:254
HWND m_hWnd
Window handle.
Definition: CMain.h:42