-
Notifications
You must be signed in to change notification settings - Fork 5
/
frm_newterrain.pas
154 lines (135 loc) · 3.96 KB
/
frm_newterrain.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//------------------------------------------------------------------------------
//
// DD_TERRAIN: Terrain Generator
// Copyright (C) 2020-2021 by Jim Valavanis
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
// DESCRIPTION:
// New Terrain Form
//
//------------------------------------------------------------------------------
// E-Mail: [email protected]
// Site : https://sourceforge.net/projects/DD-TERRAIN/
//------------------------------------------------------------------------------
unit frm_newterrain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TNewForm = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
TextureSizeRadioGroup: TRadioGroup;
HeightmapSizeRadioGroup: TRadioGroup;
OKButton: TButton;
CancelButton: TButton;
Label1: TLabel;
Label2: TLabel;
procedure TextureSizeRadioGroupClick(Sender: TObject);
procedure HeightmapSizeRadioGroupClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
private
{ Private declarations }
procedure UpdateControls;
public
{ Public declarations }
function TextureSize: integer;
procedure SetTextureSize(const tsize: integer);
function HeightmapSize: integer;
procedure SetHeightmapSize(const hsize: integer);
end;
function GetNewTerrainSize(var tsize, hsize: integer): boolean;
implementation
{$R *.dfm}
uses
ter_class;
function GetNewTerrainSize(var tsize, hsize: integer): boolean;
var
f: TNewForm;
begin
Result := False;
f := TNewForm.Create(nil);
try
f.SetTextureSize(tsize);
f.SetHeightmapSize(hsize);
f.ShowModal;
if f.ModalResult = mrOK then
begin
tsize := f.TextureSize;
hsize := f.HeightmapSize;
Result := True;
end;
finally
f.Free;
end;
end;
procedure TNewForm.UpdateControls;
begin
Label1.Caption := Format('Mesh quad size: %d', [TextureSize div (HeightmapSize - 1)]);
Label2.Caption := Format('Resulting mesh triangles: %d', [2 * sqr(HeightmapSize - 1)]);
end;
function TNewForm.TextureSize: integer;
begin
if TextureSizeRadioGroup.ItemIndex >= 0 then
begin
Result := StrToInt(TextureSizeRadioGroup.Items[TextureSizeRadioGroup.ItemIndex]);
Exit;
end;
Result := 1024;
end;
procedure TNewForm.SetTextureSize(const tsize: integer);
var
sz: integer;
begin
sz := ter_validatetexturesize(tsize);
TextureSizeRadioGroup.ItemIndex := TextureSizeRadioGroup.Items.IndexOf(IntToStr(sz));
end;
function TNewForm.HeightmapSize: integer;
begin
if HeightmapSizeRadioGroup.ItemIndex >= 0 then
begin
Result := StrToInt(HeightmapSizeRadioGroup.Items[HeightmapSizeRadioGroup.ItemIndex]);
Exit;
end;
Result := 17;
end;
procedure TNewForm.SetHeightmapSize(const hsize: integer);
var
sz: integer;
begin
sz := ter_validateheightmapsize(hsize);
HeightmapSizeRadioGroup.ItemIndex := HeightmapSizeRadioGroup.Items.IndexOf(IntToStr(sz));
end;
procedure TNewForm.TextureSizeRadioGroupClick(Sender: TObject);
begin
UpdateControls;
end;
procedure TNewForm.HeightmapSizeRadioGroupClick(Sender: TObject);
begin
UpdateControls;
end;
procedure TNewForm.FormCreate(Sender: TObject);
begin
UpdateControls;
end;
procedure TNewForm.FormShow(Sender: TObject);
begin
UpdateControls;
end;
end.