MathgeomGLS
346 строк · 8.3 Кб
1unit fStyle;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.SysUtils,
9System.UITypes,
10System.Variants,
11System.Classes,
12Vcl.Graphics,
13Vcl.Controls,
14Vcl.Forms,
15Vcl.Dialogs,
16Vcl.StdCtrls,
17Vcl.Buttons,
18
19uGlobal;
20
21type
22TStyleNameForm = class(TForm)
23BitBtn1: TBitBtn;
24StyleListBox: TListBox;
25EditName: TEdit;
26procedure FormShow(Sender: TObject);
27procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
28procedure EditKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
29procedure EditKeyPress(Sender: TObject; var Key: Char);
30procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
31procedure StyleListBoxDblClick(Sender: TObject);
32private
33StyleAltered: Boolean;
34procedure SaveToFile;
35public
36Selecting: Boolean;
37
38end;
39
40var
41StyleNameForm: TStyleNameForm;
42
43//====================================================================
44implementation
45//====================================================================
46
47uses
48fPlot1D,
49fFuncts,
50fNumeric;
51
52{$R *.dfm}
53
54procedure TStyleNameForm.FormShow(Sender: TObject);
55procedure ReadStyles;
56var
57F: File of TPlotStyle;
58s: TPlotStyle;
59so: TPlotStyleObject;
60
61begin
62AssignFile(F, StyleFName);
63Reset(F);
64while not Eof(F) do
65begin
66Read(F, s);
67so := TPlotStyleObject.Create(s);
68StyleListBox.Items.AddObject(String(s.StyleName), so);
69end;
70CloseFile(F);
71end;
72
73begin
74if Selecting then
75begin
76StyleListBox.Enabled := true;
77StyleListBox.ItemIndex := -1;
78EditName.Visible := false;
79Caption := ' Select a style';
80BitBtn1.Hint := 'OK to apply selected style.';
81StyleListBox.Hint := 'Press Del to delete an item.';
82Hint := 'Press escape to deselect style.'
83end
84else
85begin
86StyleListBox.Enabled := false;
87EditName.Visible := true;
88Caption := ' Save a style as...';
89BitBtn1.Hint := 'OK to add the current graph style.';
90StyleListBox.Hint := '';
91Hint := '';
92end;
93StyleAltered := false;
94
95if FileExists(StyleFName) then ReadStyles;
96StyleListBox.ItemIndex := -1;
97
98with Layout do
99begin
100if Left = 0 then
101begin
102Left := (Screen.Width - Width) div 2;
103Top := (Screen.Height - Height) div 2;
104end
105else
106begin
107Left := StyleLeft;
108Top := StyleTop;
109end;
110end;
111end;
112
113procedure TStyleNameForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
114procedure ApplyStyle;
115var
116s: TPlotStyle;
117so: TPlotStyleObject;
118i: integer;
119
120begin
121if StyleListbox.ItemIndex = -1 then exit;
122so := TPlotStyleObject(StyleListBox.Items.Objects[StyleListBox.ItemIndex]);
123s := so.Style;
124with GraphData do
125begin
126AreaAlpha := s.AreaAlpha;
127FontName := String(s.FontName);
128FontStyle := s.FontStyle;
129FontSize := s.FontSize;
130AxisWidth := s.AxisWidth;
131xMinorGrad := s.xMinorGrad;
132yMinorGrad := s.yMinorGrad;
133xMajorGrad := s.xMajorGrad;
134yMajorGrad := s.yMajorGrad;
135MinorWidth := s.MinorWidth;
136MajorWidth := s.MajorWidth;
137CoordWidth := s.CoordWidth;
138dydxWidth := s.dydxWidth;
139d2ydx2Width := s.d2ydx2Width;
140IntegCount := s.IntegCount;
141ydxWidth := s.ydxWidth;
142
143BackColor := s.BackColor;
144GridColor := s.GridColor;
145xAxisColor := s.xAxisColor;
146yAxisColor := s.yAxisColor;
147CoordColor := s.CoordColor;
148dydxColor := s.dydxColor;
149d2ydx2Color := s.d2ydx2Color;
150ydxColor := s.ydxColor;
151PosAreaColor := s.PosAreaColor;
152NegAreaColor := s.NegAreaColor;
153Grid := s.Grid;
154with FunctionsForm.CheckListBox do
155begin
156for i := 0 to Count -1 do
157with TPlotDataObject(Items.Objects[i]).Data do
158begin
159PlotWidth := s.Pens[i mod 12].PenWidth;
160PlotColor := s.Pens[i mod 12].PenColor;
161end;
162end;
163
164with NumericForm.CheckListBox do
165begin
166for i := 0 to Count -1 do
167with TNumericObject(Items.Objects[i]).Data do
168begin
169PlotWidth := s.NumLines[i mod 12].PenWidth;
170PlotColor := s.NumLines[i mod 12].PenColor;
171PointSize := s.NumPoints[i mod 12].PenWidth;
172PointColor := s.NumPoints[i mod 12].PenColor;
173end;
174end;
175end;
176MainForm.GLViewer.Buffer.BackgroundColor := GraphData.BackColor;
177end; { ApplyStyle }
178
179function UniqueName(s: string): Boolean;
180var
181i: integer;
182Found: Boolean;
183
184begin
185i := 0;
186Found := false;
187while not Found and (i < StyleListBox.Items.Count) do
188begin
189Found := LowerCase(s) = LowerCase(StyleListBox.Items[i]);
190Inc(i);
191end;
192Result := not Found;
193end; { UniqueName }
194
195procedure AddToList;
196var
197s: TPlotStyle;
198so: TPlotStyleObject;
199i: integer;
200
201begin
202with GraphData do
203begin
204s.AreaAlpha := AreaAlpha;
205s.FontName := ShortString(FontName);
206s.StyleName := ShortString(EditName.Text);
207s.FontStyle := FontStyle;
208s.FontSize := FontSize;
209s.AxisWidth := AxisWidth;
210s.xMinorGrad := xMinorGrad;
211s.yMinorGrad := yMinorGrad;
212s.xMajorGrad := xMajorGrad;
213s.yMajorGrad := yMajorGrad;
214s.MinorWidth := MinorWidth;
215s.MajorWidth := MajorWidth;
216s.CoordWidth := CoordWidth;
217s.dydxWidth := dydxWidth;
218s.d2ydx2Width := d2ydx2Width;
219s.IntegCount := IntegCount;
220s.ydxWidth := ydxWidth;
221
222s.BackColor := BackColor;
223s.GridColor := GridColor;
224s.xAxisColor := xAxisColor;
225s.yAxisColor := yAxisColor;
226s.CoordColor := CoordColor;
227s.dydxColor := dydxColor;
228s.d2ydx2Color := d2ydx2Color;
229s.ydxColor := ydxColor;
230s.PosAreaColor := PosAreaColor;
231s.NegAreaColor := NegAreaColor;
232
233s.Grid := Grid;
234
235for i := 0 to 11 do
236begin
237s.Pens[i].PenWidth := 1;
238s.Pens[i].PenColor := clBlack;
239end;
240
241with FunctionsForm.CheckListBox do
242begin
243for i := 0 to Count -1 do
244with TPlotDataObject(Items.Objects[i]).Data do
245begin
246s.Pens[i mod 12].PenWidth := PlotWidth;
247s.Pens[i mod 12].PenColor := PlotColor;
248end;
249end;
250
251with NumericForm.CheckListBox do
252begin
253for i := 0 to Count -1 do
254with TNumericObject(Items.Objects[i]).Data do
255begin
256s.NumLines[i mod 12].PenWidth := PlotWidth;
257s.NumLines[i mod 12].PenColor := PlotColor;
258s.NumPoints[i mod 12].PenWidth := PointSize;
259s.NumPoints[i mod 12].PenColor := PointColor;
260end;
261end;
262end;
263so := TPlotStyleObject.Create(s);
264StyleListBox.Items.AddObject(EditName.Text, so);
265SaveToFile;
266end; { AddToList }
267
268var
269i: integer;
270
271begin
272if Selecting then ApplyStyle
273else if StyleAltered then
274begin
275EditName.Text := Trim(EditName.Text);
276if EditName.Text <> '' then
277begin
278if UniqueName(EditName.Text) then AddToList
279else
280begin
281MessageDlg('The Style Name entered is not unique.', mtError, [mbOK], 0);
282CanClose := false;
283end;
284end;
285end;
286if CanClose then
287begin
288for i := 0 to StyleListBox.Items.Count -1
289do StyleListBox.Items.Objects[i].Free;
290StyleListBox.Clear;
291end;
292with Layout do
293begin
294StyleLeft := Left;
295StyleTop := Top;
296end;
297end;
298
299procedure TStyleNameForm.EditKeyDown(Sender: TObject; var Key: Word;
300Shift: TShiftState);
301begin
302if Key = VK_DELETE then StyleAltered := true;
303end;
304
305procedure TStyleNameForm.EditKeyPress(Sender: TObject; var Key: Char);
306begin
307StyleAltered := true;
308end;
309
310procedure TStyleNameForm.FormKeyDown(Sender: TObject; var Key: Word;
311Shift: TShiftState);
312begin
313if Key = VK_ESCAPE then StyleListBox.ItemIndex := -1;
314if (Key = VK_DELETE) and (StyleListBox.Items.Count > 0) then
315begin
316StyleListBox.DeleteSelected;
317SaveToFile;
318end;
319end;
320
321procedure TStyleNameForm.SaveToFile;
322
323var
324F: File of TPlotStyle;
325s: TPlotStyle;
326so: TPlotStyleObject;
327i: integer;
328
329begin
330AssignFile(F, StyleFName);
331Rewrite(F);
332for i := 0 to StyleListBox.Count -1 do
333begin
334so := TPlotStyleObject(StyleListBox.Items.Objects[i]);
335s := so.Style;
336write(F, s);
337end;
338CloseFile(F);
339end;
340
341procedure TStyleNameForm.StyleListBoxDblClick(Sender: TObject);
342begin
343Close;
344end;
345
346end.
347