-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormDeleteFrames.pas
156 lines (140 loc) · 4.64 KB
/
FormDeleteFrames.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
155
156
unit FormDeleteFrames;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Spin, ExtCtrls, SHP_File, Math, Undo_Redo, SHP_Frame, XPMan;
type
TFrmDeleteFrames = class(TForm)
Label1: TLabel;
spFrom: TSpinEdit;
spTo: TSpinEdit;
Label2: TLabel;
Bevel1: TBevel;
BtOK: TButton;
BtCancel: TButton;
CbShadow: TCheckBox;
BtToOne: TButton;
BtToEnd: TButton;
XPManifest: TXPManifest;
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure BtCancelClick(Sender: TObject);
procedure BtOKClick(Sender: TObject);
procedure CbShadowClick(Sender: TObject);
procedure BtToOneClick(Sender: TObject);
procedure BtToEndClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure spFromClick(Sender: TObject);
procedure spToClick(Sender: TObject);
private
{ Private declarations }
PLastFocus : ^TSpinEdit;
public
{ Public declarations }
end;
implementation
uses FormMain;
{$R *.dfm}
procedure TFrmDeleteFrames.BtCancelClick(Sender: TObject);
begin
close;
end;
procedure TFrmDeleteFrames.BtOKClick(Sender: TObject);
var
MaxFrames,FromValue,ToValue : Integer;
begin
// We start with a check up to see if the values are valid:
FromValue := spFrom.Value;
ToValue := spTo.Value;
spFrom.Value := Min(FromValue,ToValue);
spTo.Value := Max(FromValue,ToValue);
MaxFrames := spTo.Value - spFrom.Value + 1;
// Check if it goes with shadows or not.
if CbShadow.Checked then
begin
if (MaxFrames*2) > FrmMain.ActiveData^.SHP.Header.NumImages then
begin
ShowMessage('Error: An SHP must have one or more frames.');
exit;
end;
AddToUndoRemovedFrames(FrmMain.ActiveData^.UndoList,FrmMain.ActiveData^.SHP,spFrom.Value,(FrmMain.ActiveData^.SHP.Header.NumImages div 2) + spFrom.Value,MaxFrames);
// Now exclude original content from ActiveData
MoveSeveralFrameImagesDown(FrmMain.ActiveData^.SHP,(FrmMain.ActiveData^.SHP.Header.NumImages div 2) + spFrom.Value,MaxFrames);
MoveSeveralFrameImagesDown(FrmMain.ActiveData^.SHP,spFrom.Value,MaxFrames);
end
else
begin
if MaxFrames > FrmMain.ActiveData^.SHP.Header.NumImages then
begin
ShowMessage('Error: An SHP must have one or more frames.');
exit;
end;
AddToUndoRemovedFrames(FrmMain.ActiveData^.UndoList,FrmMain.ActiveData^.SHP,spFrom.Value,MaxFrames);
// Now exclude original content from ActiveData
MoveSeveralFrameImagesDown(FrmMain.ActiveData^.SHP,spFrom.Value,MaxFrames);
end;
if FrmMain.ActiveForm^.Frame > FrmMain.ActiveData^.SHP.Header.NumImages then
FrmMain.ActiveForm^.Frame := FrmMain.ActiveData^.SHP.Header.NumImages;
FrmMain.ActiveForm^.SetShadowMode(FrmMain.ActiveForm^.ShadowMode); // Fakes a shadow change so frame lengths are set
FrmMain.UndoUpdate(FrmMain.ActiveData^.UndoList);
close;
end;
procedure TFrmDeleteFrames.CbShadowClick(Sender: TObject);
begin
if CbShadow.Checked then
begin
spFrom.MaxValue := FrmMain.ActiveData^.SHP.Header.NumImages div 2;
spTo.MaxValue := FrmMain.ActiveData^.SHP.Header.NumImages div 2;
end
else
begin
spFrom.MaxValue := FrmMain.ActiveData^.SHP.Header.NumImages;
spTo.MaxValue := FrmMain.ActiveData^.SHP.Header.NumImages;
end;
if spFrom.Value > spFrom.MaxValue then
spFrom.Value := spFrom.MaxValue;
if spTo.Value > spTo.MaxValue then
spTo.Value := spTo.MaxValue;
end;
procedure TFrmDeleteFrames.BtToOneClick(Sender: TObject);
begin
PLastFocus^.Value := PLastFocus^.MinValue;
end;
procedure TFrmDeleteFrames.BtToEndClick(Sender: TObject);
begin
PLastFocus^.Value := PLastFocus^.MaxValue;
end;
procedure TFrmDeleteFrames.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_RETURN then
begin
BtOkClick(Sender);
end
else if Key = VK_ESCAPE then
begin
BtCancelClick(Sender);
end;
end;
procedure TFrmDeleteFrames.FormShow(Sender: TObject);
begin
// Setting up the default values on the spin edits
spFrom.Value := FrmMain.ActiveForm^.Frame;
spTo.Value := FrmMain.ActiveForm^.Frame;
spFrom.Increment := 1;
spTo.Increment := 1;
spFrom.MinValue := 1;
spFrom.MaxValue := FrmMain.ActiveData^.SHP.Header.NumImages;
spTo.MinValue := 1;
spTo.MaxValue := FrmMain.ActiveData^.SHP.Header.NumImages;
PLastFocus := @spFrom;
// Set focus on From
spFrom.SetFocus;
end;
procedure TFrmDeleteFrames.spFromClick(Sender: TObject);
begin
PLastFocus := @spFrom;
end;
procedure TFrmDeleteFrames.spToClick(Sender: TObject);
begin
PLastFocus := @spTo;
end;
end.