- Added reading and writing of RandomHuePresets (refs #66)

This commit is contained in:
Andreas Schneider 2011-03-12 23:46:57 +01:00
parent fd4155a45b
commit 2a9598452b
1 changed files with 41 additions and 2 deletions

View File

@ -21,7 +21,7 @@
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2009 Andreas Schneider * Portions Copyright 2011 Andreas Schneider
*) *)
unit UfrmHueSettings; unit UfrmHueSettings;
@ -31,7 +31,8 @@ interface
uses uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls, Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, Buttons, VirtualTrees, UfrmToolWindow, UHue; ExtCtrls, Buttons, UfrmToolWindow, UHue,
XMLRead, XMLWrite, DOM;
type type
@ -62,6 +63,12 @@ type
procedure lbRandomDragDrop(Sender, Source: TObject; X, Y: Integer); procedure lbRandomDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure lbRandomDragOver(Sender, Source: TObject; X, Y: Integer; procedure lbRandomDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean); State: TDragState; var Accept: Boolean);
private
FConfigDir: String;
FRandomHuePresetsFile: String;
FRandomHuePresetsDoc: TXMLDocument;
procedure LoadRandomPresets;
procedure SaveRandomPresets;
public public
function GetHue: Word; function GetHue: Word;
public public
@ -137,6 +144,10 @@ begin
lbHue.Items.AddObject(Format('$%x (%s)', [i, hue.Name]), hue); lbHue.Items.AddObject(Format('$%x (%s)', [i, hue.Name]), hue);
end; end;
lbHue.ItemIndex := 0; lbHue.ItemIndex := 0;
FConfigDir := GetAppConfigDir(False);
ForceDirectories(FConfigDir);
FRandomHuePresetsFile := FConfigDir + 'RandomHuePresets.xml';
end; end;
procedure TfrmHueSettings.lbHueDrawItem(Control: TWinControl; Index: Integer; procedure TfrmHueSettings.lbHueDrawItem(Control: TWinControl; Index: Integer;
@ -169,6 +180,34 @@ begin
if Source = lbHue then Accept := True; if Source = lbHue then Accept := True;
end; end;
procedure TfrmHueSettings.LoadRandomPresets;
var
presetElement, hueElement: TDOMElement;
begin
FreeAndNil(FRandomHuePresetsDoc);
cbRandomPreset.Items.Clear;
if FileExists(FRandomHuePresetsFile) then
begin
ReadXMLFile(FRandomHuePresetsDoc, FRandomHuePresetsFile);
presetElement := TDOMElement(FRandomHuePresetsDoc.DocumentElement.FirstChild);
while presetElement <> nil do
begin
if presetElement.NodeName = 'HuePreset' then
cbRandomPreset.Items.Add(presetElement.AttribStrings['Name']);
presetElement := TDOMElement(presetElement.NextSibling);
end;
end else
begin
FRandomHuePresetsDoc := TXMLDocument.Create;
FRandomHuePresetsDoc.AppendChild(FRandomHuePresetsDoc.CreateElement('RandomHuePresets'));
end;
end;
procedure TfrmHueSettings.SaveRandomPresets;
begin
WriteXMLFile(FRandomHuePresetsDoc, FRandomHuePresetsFile);
end;
function TfrmHueSettings.GetHue: Word; function TfrmHueSettings.GetHue: Word;
begin begin
if cbRandom.Checked and (lbRandom.Items.Count > 0) then if cbRandom.Checked and (lbRandom.Items.Count > 0) then