MathgeomGLS
346 строк · 8.3 Кб
1unit faStyle;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
19Graf.Global1d;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);32private33StyleAltered: Boolean;34procedure SaveToFile;35public36Selecting: Boolean;37
38end;39
40var
41StyleNameForm: TStyleNameForm;42
43//====================================================================
44implementation
45//====================================================================
46
47uses
48faGraf1D,49faFunc1d,50faNumeric;51
52{$R *.dfm}
53
54procedure TStyleNameForm.FormShow(Sender: TObject);55procedure ReadStyles;56var57F: File of TPlotStyle;58s: TPlotStyle;59so: TPlotStyleObject;60
61begin62AssignFile(F, StyleFName);63Reset(F);64while not Eof(F) do65begin66Read(F, s);67so := TPlotStyleObject.Create(s);68StyleListBox.Items.AddObject(String(s.StyleName), so);69end;70CloseFile(F);71end;72
73begin
74if Selecting then75begin76StyleListBox.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.'83end84else85begin86StyleListBox.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 do99begin100if Left = 0 then101begin102Left := (Screen.Width - Width) div 2;103Top := (Screen.Height - Height) div 2;104end105else106begin107Left := StyleLeft;108Top := StyleTop;109end;110end;111end;112
113procedure TStyleNameForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);114procedure ApplyStyle;115var116s: TPlotStyle;117so: TPlotStyleObject;118i: integer;119
120begin121if StyleListbox.ItemIndex = -1 then exit;122so := TPlotStyleObject(StyleListBox.Items.Objects[StyleListBox.ItemIndex]);123s := so.Style;124with GraphData do125begin126AreaAlpha := 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 do155begin156for i := 0 to Count -1 do157with TPlotDataObject(Items.Objects[i]).Data do158begin159PlotWidth := s.Pens[i mod 12].PenWidth;160PlotColor := s.Pens[i mod 12].PenColor;161end;162end;163
164with NumericForm.CheckListBox do165begin166for i := 0 to Count -1 do167with TNumericObject(Items.Objects[i]).Data do168begin169PlotWidth := 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;180var181i: integer;182Found: Boolean;183
184begin185i := 0;186Found := false;187while not Found and (i < StyleListBox.Items.Count) do188begin189Found := LowerCase(s) = LowerCase(StyleListBox.Items[i]);190Inc(i);191end;192Result := not Found;193end; { UniqueName }194
195procedure AddToList;196var197s: TPlotStyle;198so: TPlotStyleObject;199i: integer;200
201begin202with GraphData do203begin204s.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 do236begin237s.Pens[i].PenWidth := 1;238s.Pens[i].PenColor := clBlack;239end;240
241with FunctionsForm.CheckListBox do242begin243for i := 0 to Count -1 do244with TPlotDataObject(Items.Objects[i]).Data do245begin246s.Pens[i mod 12].PenWidth := PlotWidth;247s.Pens[i mod 12].PenColor := PlotColor;248end;249end;250
251with NumericForm.CheckListBox do252begin253for i := 0 to Count -1 do254with TNumericObject(Items.Objects[i]).Data do255begin256s.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 ApplyStyle273else if StyleAltered then274begin275EditName.Text := Trim(EditName.Text);276if EditName.Text <> '' then277begin278if UniqueName(EditName.Text) then AddToList279else280begin281MessageDlg('The Style Name entered is not unique.', mtError, [mbOK], 0);282CanClose := false;283end;284end;285end;286if CanClose then287begin288for i := 0 to StyleListBox.Items.Count -1289do StyleListBox.Items.Objects[i].Free;290StyleListBox.Clear;291end;292with Layout do293begin294StyleLeft := 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) then315begin316StyleListBox.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 do333begin334so := 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