-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathunit6.pas
More file actions
167 lines (146 loc) · 5.1 KB
/
unit6.pas
File metadata and controls
167 lines (146 loc) · 5.1 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
(******************************************************************************)
(* *)
(* Author : Uwe Schächterle (Corpsman) *)
(* *)
(* This file is part of PixelEditor *)
(* *)
(* See the file license.md, located under: *)
(* https://github.com/PascalCorpsman/Software_Licenses/blob/main/license.md *)
(* for details about the license. *)
(* *)
(* It is not allowed to change or remove this text from any *)
(* source file of the project. *)
(* *)
(******************************************************************************)
Unit Unit6;
{$MODE ObjFPC}{$H+}
Interface
Uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons,
Spin, upixeleditor_types;
Type
{ TForm6 }
TForm6 = Class(TForm)
Button1: TButton;
Button2: TButton;
CheckBox1: TCheckBox;
ComboBox1: TComboBox;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
SpinEdit3: TSpinEdit;
SpinEdit4: TSpinEdit;
SpinEdit5: TFloatSpinEdit;
SpinEdit6: TFloatSpinEdit;
Procedure FormCreate(Sender: TObject);
Procedure SpinEdit1KeyDown(Sender: TObject; Var Key: Word;
Shift: TShiftState);
Procedure SpinEdit3Change(Sender: TObject);
Procedure SpinEdit4Change(Sender: TObject);
Procedure SpinEdit5Change(Sender: TObject);
Procedure SpinEdit6Change(Sender: TObject);
private
Block: Boolean;
public
Procedure InitWith(aWidth, aHeight: Integer; Global: Boolean);
Function GetScaleMode(): TScaleMode;
End;
Var
Form6: TForm6;
Implementation
{$R *.lfm}
Uses math, LCLType;
{ TForm6 }
Procedure TForm6.FormCreate(Sender: TObject);
Begin
caption := 'Resize / Scale';
End;
Procedure TForm6.SpinEdit1KeyDown(Sender: TObject; Var Key: Word;
Shift: TShiftState);
Begin
If key = VK_RETURN Then button2.Click;
If key = VK_ESCAPE Then Button1.Click;
End;
Procedure TForm6.SpinEdit3Change(Sender: TObject);
Begin
// Change on New Width
If block Then exit;
block := true;
SpinEdit5.Value := SpinEdit3.Value * 100 / SpinEdit1.Value;
If CheckBox1.Checked Then Begin
SpinEdit4.Value := round(SpinEdit3.Value * SpinEdit2.Value / max(1, SpinEdit1.Value));
SpinEdit6.Value := SpinEdit4.Value * 100 / max(1, SpinEdit2.Value);
End;
block := false;
End;
Procedure TForm6.SpinEdit4Change(Sender: TObject);
Begin
// Change on New Height
If block Then exit;
block := true;
SpinEdit6.Value := SpinEdit4.Value * 100 / SpinEdit2.Value;
If CheckBox1.Checked Then Begin
SpinEdit3.Value := round(SpinEdit4.Value * SpinEdit1.Value / max(1, SpinEdit2.Value));
SpinEdit5.Value := SpinEdit3.Value * 100 / max(1, SpinEdit1.Value);
End;
block := false;
End;
Procedure TForm6.SpinEdit5Change(Sender: TObject);
Begin
// Change on New Width Percent
If block Then exit;
block := true;
SpinEdit3.Value := (SpinEdit1.Value * SpinEdit5.Value) / 100;
If CheckBox1.Checked Then Begin
SpinEdit4.Value := round(SpinEdit3.Value * SpinEdit2.Value / max(1, SpinEdit1.Value));
SpinEdit6.Value := SpinEdit4.Value * 100 / max(1, SpinEdit2.Value);
End;
block := false;
End;
Procedure TForm6.SpinEdit6Change(Sender: TObject);
Begin
// Change on New Height Percent
If block Then exit;
block := true;
SpinEdit4.Value := (SpinEdit2.Value * SpinEdit6.Value) / 100;
If CheckBox1.Checked Then Begin
SpinEdit3.Value := round(SpinEdit4.Value * SpinEdit1.Value / max(1, SpinEdit2.Value));
SpinEdit5.Value := SpinEdit3.Value * 100 / max(1, SpinEdit1.Value);
End;
block := false;
End;
Procedure TForm6.InitWith(aWidth, aHeight: Integer; Global: Boolean);
Begin
CheckBox1.Checked := false; // Damit man die Werte in Ruhe setzen kann
SpinEdit1.Value := aWidth;
SpinEdit3.Value := aWidth;
SpinEdit5.Value := 100;
SpinEdit2.Value := aHeight;
SpinEdit4.Value := aHeight;
SpinEdit6.Value := 100;
ComboBox1.ItemIndex := 1 - ord(Global);
CheckBox1.Checked := true;
If Global Then Begin
SpeedButton1.Down := true;
End
Else Begin
SpeedButton2.Down := true;
End;
End;
Function TForm6.GetScaleMode(): TScaleMode;
Begin
result := smResize;
If SpeedButton2.Down Then result := smScale;
If SpeedButton3.Down Then result := smSmoothScale;
End;
End.