- Added saving and loading of hue presets (refs #66)

This commit is contained in:
Andreas Schneider 2011-03-16 19:42:55 +01:00
parent 2a9598452b
commit 8bebb92300
4 changed files with 98 additions and 4 deletions

View File

@ -21,7 +21,7 @@
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2010 Andreas Schneider * Portions Copyright 2011 Andreas Schneider
*) *)
program CentrED; program CentrED;

View File

@ -277,6 +277,7 @@ inherited frmHueSettings: TfrmHueSettings
3BFF000000000000000000000000000000000000000000000000 3BFF000000000000000000000000000000000000000000000000
} }
NumGlyphs = 0 NumGlyphs = 0
OnClick = btnRandomPresetSaveClick
ShowCaption = False ShowCaption = False
ShowHint = True ShowHint = True
ParentShowHint = False ParentShowHint = False
@ -329,6 +330,7 @@ inherited frmHueSettings: TfrmHueSettings
4FFFC5894BFFC4763BFF00000000000000000000000000000000 4FFFC5894BFFC4763BFF00000000000000000000000000000000
} }
NumGlyphs = 0 NumGlyphs = 0
OnClick = btnRandomPresetDeleteClick
ShowCaption = False ShowCaption = False
ShowHint = True ShowHint = True
ParentShowHint = False ParentShowHint = False
@ -347,6 +349,7 @@ inherited frmHueSettings: TfrmHueSettings
BorderSpacing.Right = 4 BorderSpacing.Right = 4
BorderSpacing.Bottom = 4 BorderSpacing.Bottom = 4
ItemHeight = 15 ItemHeight = 15
OnChange = cbRandomPresetChange
Sorted = True Sorted = True
Style = csDropDownList Style = csDropDownList
TabOrder = 0 TabOrder = 0

View File

@ -54,7 +54,10 @@ type
procedure btnAddRandomClick(Sender: TObject); procedure btnAddRandomClick(Sender: TObject);
procedure btnClearRandomClick(Sender: TObject); procedure btnClearRandomClick(Sender: TObject);
procedure btnDeleteRandomClick(Sender: TObject); procedure btnDeleteRandomClick(Sender: TObject);
procedure btnRandomPresetDeleteClick(Sender: TObject);
procedure btnRandomPresetSaveClick(Sender: TObject);
procedure cbRandomChange(Sender: TObject); procedure cbRandomChange(Sender: TObject);
procedure cbRandomPresetChange(Sender: TObject);
procedure edHueEditingDone(Sender: TObject); procedure edHueEditingDone(Sender: TObject);
procedure FormCreate(Sender: TObject); procedure FormCreate(Sender: TObject);
procedure lbHueDrawItem(Control: TWinControl; Index: Integer; ARect: TRect; procedure lbHueDrawItem(Control: TWinControl; Index: Integer; ARect: TRect;
@ -67,6 +70,7 @@ type
FConfigDir: String; FConfigDir: String;
FRandomHuePresetsFile: String; FRandomHuePresetsFile: String;
FRandomHuePresetsDoc: TXMLDocument; FRandomHuePresetsDoc: TXMLDocument;
function FindRandomPreset(AName: String): TDOMElement;
procedure LoadRandomPresets; procedure LoadRandomPresets;
procedure SaveRandomPresets; procedure SaveRandomPresets;
public public
@ -109,12 +113,85 @@ begin
lbRandom.Items.EndUpdate; lbRandom.Items.EndUpdate;
end; end;
procedure TfrmHueSettings.btnRandomPresetDeleteClick(Sender: TObject);
var
preset: TDOMElement;
begin
if cbRandomPreset.ItemIndex > -1 then
begin
preset := TDOMElement(cbRandomPreset.Items.Objects[cbRandomPreset.ItemIndex]);
FRandomHuePresetsDoc.DocumentElement.RemoveChild(preset);
cbRandomPreset.Items.Delete(cbRandomPreset.ItemIndex);
cbRandomPreset.ItemIndex := -1;
end;
end;
procedure TfrmHueSettings.btnRandomPresetSaveClick(Sender: TObject);
var
presetName: string;
i: Integer;
preset, hue: TDOMElement;
children: TDOMNodeList;
begin
presetName := cbRandomPreset.Text;
if InputQuery('Save Preset', 'Enter the name of the preset:', presetName) then
begin
preset := FindRandomPreset(presetName);
if preset = nil then
begin
preset := FRandomHuePresetsDoc.CreateElement('Preset');
preset.AttribStrings['Name'] := presetName;
FRandomHuePresetsDoc.DocumentElement.AppendChild(preset);
cbRandomPreset.Items.AddObject(presetName, preset);
end else
begin
children := preset.GetChildNodes;
for i := children.Count - 1 downto 0 do
preset.RemoveChild(children[i]);
end;
for i := 0 to lbRandom.Items.Count - 1 do
begin
hue := FRandomHuePresetsDoc.CreateElement('Hue');
hue.AttribStrings['ID'] := IntToStr(PtrInt(lbRandom.Items.Objects[i]));
preset.AppendChild(hue);
end;
cbRandomPreset.ItemIndex := cbRandomPreset.Items.IndexOfObject(preset);
SaveRandomPresets;
end;
end;
procedure TfrmHueSettings.cbRandomChange(Sender: TObject); procedure TfrmHueSettings.cbRandomChange(Sender: TObject);
begin begin
lbHue.MultiSelect := cbRandom.Checked; lbHue.MultiSelect := cbRandom.Checked;
gbRandom.Visible := cbRandom.Checked; gbRandom.Visible := cbRandom.Checked;
end; end;
procedure TfrmHueSettings.cbRandomPresetChange(Sender: TObject);
var
preset, hue: TDOMElement;
id: PtrInt;
begin
lbRandom.Clear;
if cbRandomPreset.ItemIndex > -1 then
begin
preset := TDOMElement(cbRandomPreset.Items.Objects[cbRandomPreset.ItemIndex]);
hue := TDOMElement(preset.FirstChild);
while hue <> nil do
begin
if hue.NodeName = 'Hue' then
begin
id := StrToInt(hue.AttribStrings['ID']);
lbRandom.Items.AddObject(lbHue.Items.Strings[id], TObject(id));
end;
hue := TDOMElement(hue.NextSibling);
end;
end;
end;
procedure TfrmHueSettings.btnClearRandomClick(Sender: TObject); procedure TfrmHueSettings.btnClearRandomClick(Sender: TObject);
begin begin
lbRandom.Items.Clear; lbRandom.Items.Clear;
@ -122,7 +199,7 @@ end;
procedure TfrmHueSettings.btnAddRandomClick(Sender: TObject); procedure TfrmHueSettings.btnAddRandomClick(Sender: TObject);
var var
i: Integer; i: PtrInt;
begin begin
lbRandom.Items.BeginUpdate; lbRandom.Items.BeginUpdate;
for i := 0 to lbHue.Count - 1 do for i := 0 to lbHue.Count - 1 do
@ -148,6 +225,8 @@ begin
FConfigDir := GetAppConfigDir(False); FConfigDir := GetAppConfigDir(False);
ForceDirectories(FConfigDir); ForceDirectories(FConfigDir);
FRandomHuePresetsFile := FConfigDir + 'RandomHuePresets.xml'; FRandomHuePresetsFile := FConfigDir + 'RandomHuePresets.xml';
LoadRandomPresets;
end; end;
procedure TfrmHueSettings.lbHueDrawItem(Control: TWinControl; Index: Integer; procedure TfrmHueSettings.lbHueDrawItem(Control: TWinControl; Index: Integer;
@ -180,6 +259,18 @@ begin
if Source = lbHue then Accept := True; if Source = lbHue then Accept := True;
end; end;
function TfrmHueSettings.FindRandomPreset(AName: String): TDOMElement;
begin
Result := TDOMElement(FRandomHuePresetsDoc.DocumentElement.FirstChild);
while Result <> nil do
begin
if SameText(Result.AttribStrings['Name'], AName) then
Break;
Result := TDOMElement(Result.NextSibling);
end;
end;
procedure TfrmHueSettings.LoadRandomPresets; procedure TfrmHueSettings.LoadRandomPresets;
var var
presetElement, hueElement: TDOMElement; presetElement, hueElement: TDOMElement;
@ -193,7 +284,7 @@ begin
while presetElement <> nil do while presetElement <> nil do
begin begin
if presetElement.NodeName = 'HuePreset' then if presetElement.NodeName = 'HuePreset' then
cbRandomPreset.Items.Add(presetElement.AttribStrings['Name']); cbRandomPreset.Items.AddObject(presetElement.AttribStrings['Name'], presetElement);
presetElement := TDOMElement(presetElement.NextSibling); presetElement := TDOMElement(presetElement.NextSibling);
end; end;
end else end else

View File

@ -21,7 +21,7 @@
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2009 Andreas Schneider * Portions Copyright 2011 Andreas Schneider
*) *)
unit UfrmMain; unit UfrmMain;