mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-24 18:22:25 -05:00
Testing purposes only
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@295 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
parent
1879c42602
commit
3e2a64cc7e
@ -1,103 +1,116 @@
|
||||
object ColourHistoryForm: TColourHistoryForm
|
||||
Left = 420
|
||||
Height = 250
|
||||
Top = 318
|
||||
Width = 490
|
||||
ActiveControl = SelectionName
|
||||
Caption = 'Colour Picker History'
|
||||
ClientHeight = 250
|
||||
ClientWidth = 490
|
||||
Constraints.MinHeight = 200
|
||||
Constraints.MinWidth = 490
|
||||
OnHide = UnSetCHShowMenu
|
||||
OnShow = SetCHShowMenu
|
||||
LCLVersion = '0.9.29'
|
||||
object ColourList: TListView
|
||||
Left = 16
|
||||
Height = 176
|
||||
Top = 16
|
||||
Width = 329
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
Columns = <>
|
||||
ItemIndex = -1
|
||||
TabOrder = 0
|
||||
OnSelectItem = ChangeViewData
|
||||
end
|
||||
object DeleteButton: TButton
|
||||
Left = 16
|
||||
Height = 25
|
||||
Top = 208
|
||||
Width = 128
|
||||
Anchors = [akLeft, akBottom]
|
||||
Caption = 'Delete'
|
||||
OnClick = DeleteSelected
|
||||
TabOrder = 1
|
||||
end
|
||||
object SelectionName: TEdit
|
||||
Left = 361
|
||||
Height = 27
|
||||
Top = 16
|
||||
Width = 112
|
||||
Anchors = [akTop, akRight]
|
||||
OnChange = ChangeName
|
||||
OnKeyPress = SelectionNameKeyPress
|
||||
TabOrder = 2
|
||||
Text = 'Name'
|
||||
end
|
||||
object PickNewColourButton: TButton
|
||||
Left = 217
|
||||
Height = 25
|
||||
Top = 208
|
||||
Width = 128
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'Pick New Colour'
|
||||
TabOrder = 3
|
||||
end
|
||||
object ColourValue: TEdit
|
||||
Left = 361
|
||||
Height = 27
|
||||
Top = 56
|
||||
Width = 112
|
||||
Anchors = [akTop, akRight]
|
||||
ReadOnly = True
|
||||
TabOrder = 4
|
||||
Text = 'ColourValue'
|
||||
end
|
||||
object CoordValue: TLabel
|
||||
Left = 361
|
||||
Height = 18
|
||||
Top = 96
|
||||
Width = 112
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'CoordValue'
|
||||
Constraints.MinWidth = 112
|
||||
ParentColor = False
|
||||
end
|
||||
object ColourImage: TImage
|
||||
Left = 152
|
||||
Height = 24
|
||||
Top = 209
|
||||
Width = 57
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
end
|
||||
object OkButton: TButton
|
||||
Left = 393
|
||||
Height = 24
|
||||
Top = 209
|
||||
Width = 80
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'Ok'
|
||||
OnClick = OkButtonClick
|
||||
TabOrder = 5
|
||||
end
|
||||
object CH_RGB_Label: TLabel
|
||||
Left = 361
|
||||
Height = 18
|
||||
Top = 128
|
||||
Width = 112
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'RGBValues'
|
||||
Constraints.MinWidth = 112
|
||||
ParentColor = False
|
||||
end
|
||||
end
|
||||
object ColourHistoryForm: TColourHistoryForm
|
||||
Left = 420
|
||||
Height = 250
|
||||
Top = 318
|
||||
Width = 490
|
||||
ActiveControl = SelectionName
|
||||
Caption = 'Colour Picker History'
|
||||
ClientHeight = 250
|
||||
ClientWidth = 490
|
||||
Constraints.MinHeight = 200
|
||||
Constraints.MinWidth = 490
|
||||
OnCreate = FormCreate
|
||||
OnHide = UnSetCHShowMenu
|
||||
OnShow = SetCHShowMenu
|
||||
LCLVersion = '0.9.29'
|
||||
object ColourList: TListView
|
||||
Left = 16
|
||||
Height = 176
|
||||
Top = 16
|
||||
Width = 329
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
Columns = <
|
||||
item
|
||||
Caption = 'Colour'
|
||||
MaxWidth = 50
|
||||
MinWidth = 50
|
||||
Width = 10
|
||||
end
|
||||
item
|
||||
Caption = 'Woot'
|
||||
Width = 10
|
||||
end>
|
||||
ItemIndex = -1
|
||||
TabOrder = 0
|
||||
ViewStyle = vsReport
|
||||
OnAdvancedCustomDrawSubItem = ColourListAdvancedCustomDrawSubItem
|
||||
OnSelectItem = ChangeViewData
|
||||
end
|
||||
object DeleteButton: TButton
|
||||
Left = 16
|
||||
Height = 25
|
||||
Top = 208
|
||||
Width = 128
|
||||
Anchors = [akLeft, akBottom]
|
||||
Caption = 'Delete'
|
||||
OnClick = DeleteSelected
|
||||
TabOrder = 1
|
||||
end
|
||||
object SelectionName: TEdit
|
||||
Left = 361
|
||||
Height = 21
|
||||
Top = 16
|
||||
Width = 112
|
||||
Anchors = [akTop, akRight]
|
||||
OnChange = ChangeName
|
||||
OnKeyPress = SelectionNameKeyPress
|
||||
TabOrder = 2
|
||||
Text = 'Name'
|
||||
end
|
||||
object PickNewColourButton: TButton
|
||||
Left = 217
|
||||
Height = 25
|
||||
Top = 208
|
||||
Width = 128
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'Pick New Colour'
|
||||
TabOrder = 3
|
||||
end
|
||||
object ColourValue: TEdit
|
||||
Left = 361
|
||||
Height = 21
|
||||
Top = 56
|
||||
Width = 112
|
||||
Anchors = [akTop, akRight]
|
||||
ReadOnly = True
|
||||
TabOrder = 4
|
||||
Text = 'ColourValue'
|
||||
end
|
||||
object CoordValue: TLabel
|
||||
Left = 361
|
||||
Height = 14
|
||||
Top = 96
|
||||
Width = 112
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'CoordValue'
|
||||
Constraints.MinWidth = 112
|
||||
ParentColor = False
|
||||
end
|
||||
object ColourImage: TImage
|
||||
Left = 152
|
||||
Height = 24
|
||||
Top = 209
|
||||
Width = 57
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
end
|
||||
object OkButton: TButton
|
||||
Left = 393
|
||||
Height = 24
|
||||
Top = 209
|
||||
Width = 80
|
||||
Anchors = [akRight, akBottom]
|
||||
Caption = 'Ok'
|
||||
OnClick = OkButtonClick
|
||||
TabOrder = 5
|
||||
end
|
||||
object CH_RGB_Label: TLabel
|
||||
Left = 361
|
||||
Height = 14
|
||||
Top = 128
|
||||
Width = 112
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'RGBValues'
|
||||
Constraints.MinWidth = 112
|
||||
ParentColor = False
|
||||
end
|
||||
end
|
||||
|
@ -1,33 +1,36 @@
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TColourHistoryForm','FORMDATA',[
|
||||
'TPF0'#18'TColourHistoryForm'#17'ColourHistoryForm'#4'Left'#3#164#1#6'Height'
|
||||
+#3#250#0#3'Top'#3'>'#1#5'Width'#3#234#1#13'ActiveControl'#7#13'SelectionName'
|
||||
+#7'Caption'#6#21'Colour Picker History'#12'ClientHeight'#3#250#0#11'ClientWi'
|
||||
+'dth'#3#234#1#21'Constraints.MinHeight'#3#200#0#20'Constraints.MinWidth'#3
|
||||
+#234#1#6'OnHide'#7#15'UnSetCHShowMenu'#6'OnShow'#7#13'SetCHShowMenu'#10'LCLV'
|
||||
+'ersion'#6#6'0.9.29'#0#9'TListView'#10'ColourList'#4'Left'#2#16#6'Height'#3
|
||||
+#176#0#3'Top'#2#16#5'Width'#3'I'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRigh'
|
||||
+'t'#8'akBottom'#0#7'Columns'#14#0#9'ItemIndex'#2#255#8'TabOrder'#2#0#12'OnSe'
|
||||
+'lectItem'#7#14'ChangeViewData'#0#0#7'TButton'#12'DeleteButton'#4'Left'#2#16
|
||||
+#6'Height'#2#25#3'Top'#3#208#0#5'Width'#3#128#0#7'Anchors'#11#6'akLeft'#8'ak'
|
||||
+'Bottom'#0#7'Caption'#6#6'Delete'#7'OnClick'#7#14'DeleteSelected'#8'TabOrder'
|
||||
+#2#1#0#0#5'TEdit'#13'SelectionName'#4'Left'#3'i'#1#6'Height'#2#27#3'Top'#2#16
|
||||
+#5'Width'#2'p'#7'Anchors'#11#5'akTop'#7'akRight'#0#8'OnChange'#7#10'ChangeNa'
|
||||
+'me'#10'OnKeyPress'#7#21'SelectionNameKeyPress'#8'TabOrder'#2#2#4'Text'#6#4
|
||||
+'Name'#0#0#7'TButton'#19'PickNewColourButton'#4'Left'#3#217#0#6'Height'#2#25
|
||||
+#3'Top'#3#208#0#5'Width'#3#128#0#7'Anchors'#11#7'akRight'#8'akBottom'#0#7'Ca'
|
||||
+'ption'#6#15'Pick New Colour'#8'TabOrder'#2#3#0#0#5'TEdit'#11'ColourValue'#4
|
||||
+'Left'#3'i'#1#6'Height'#2#27#3'Top'#2'8'#5'Width'#2'p'#7'Anchors'#11#5'akTop'
|
||||
+#7'akRight'#0#8'ReadOnly'#9#8'TabOrder'#2#4#4'Text'#6#11'ColourValue'#0#0#6
|
||||
+'TLabel'#10'CoordValue'#4'Left'#3'i'#1#6'Height'#2#18#3'Top'#2'`'#5'Width'#2
|
||||
+'p'#7'Anchors'#11#5'akTop'#7'akRight'#0#7'Caption'#6#10'CoordValue'#20'Const'
|
||||
+'raints.MinWidth'#2'p'#11'ParentColor'#8#0#0#6'TImage'#11'ColourImage'#4'Lef'
|
||||
+'t'#3#152#0#6'Height'#2#24#3'Top'#3#209#0#5'Width'#2'9'#7'Anchors'#11#6'akLe'
|
||||
+'ft'#7'akRight'#8'akBottom'#0#0#0#7'TButton'#8'OkButton'#4'Left'#3#137#1#6'H'
|
||||
+'eight'#2#24#3'Top'#3#209#0#5'Width'#2'P'#7'Anchors'#11#7'akRight'#8'akBotto'
|
||||
+'m'#0#7'Caption'#6#2'Ok'#7'OnClick'#7#13'OkButtonClick'#8'TabOrder'#2#5#0#0#6
|
||||
+'TLabel'#12'CH_RGB_Label'#4'Left'#3'i'#1#6'Height'#2#18#3'Top'#3#128#0#5'Wid'
|
||||
+'th'#2'p'#7'Anchors'#11#5'akTop'#7'akRight'#0#7'Caption'#6#9'RGBValues'#20'C'
|
||||
+'onstraints.MinWidth'#2'p'#11'ParentColor'#8#0#0#0
|
||||
]);
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TColourHistoryForm','FORMDATA',[
|
||||
'TPF0'#18'TColourHistoryForm'#17'ColourHistoryForm'#4'Left'#3#164#1#6'Height'
|
||||
+#3#250#0#3'Top'#3'>'#1#5'Width'#3#234#1#13'ActiveControl'#7#13'SelectionName'
|
||||
+#7'Caption'#6#21'Colour Picker History'#12'ClientHeight'#3#250#0#11'ClientWi'
|
||||
+'dth'#3#234#1#21'Constraints.MinHeight'#3#200#0#20'Constraints.MinWidth'#3
|
||||
+#234#1#8'OnCreate'#7#10'FormCreate'#6'OnHide'#7#15'UnSetCHShowMenu'#6'OnShow'
|
||||
+#7#13'SetCHShowMenu'#10'LCLVersion'#6#6'0.9.29'#0#9'TListView'#10'ColourList'
|
||||
+#4'Left'#2#16#6'Height'#3#176#0#3'Top'#2#16#5'Width'#3'I'#1#7'Anchors'#11#5
|
||||
+'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#7'Columns'#14#1#7'Caption'#6#6'Co'
|
||||
+'lour'#8'MaxWidth'#2'2'#8'MinWidth'#2'2'#5'Width'#2#10#0#1#7'Caption'#6#4'Wo'
|
||||
+'ot'#5'Width'#2#10#0#0#9'ItemIndex'#2#255#8'TabOrder'#2#0#9'ViewStyle'#7#8'v'
|
||||
+'sReport'#27'OnAdvancedCustomDrawSubItem'#7'#ColourListAdvancedCustomDrawSub'
|
||||
+'Item'#12'OnSelectItem'#7#14'ChangeViewData'#0#0#7'TButton'#12'DeleteButton'
|
||||
+#4'Left'#2#16#6'Height'#2#25#3'Top'#3#208#0#5'Width'#3#128#0#7'Anchors'#11#6
|
||||
+'akLeft'#8'akBottom'#0#7'Caption'#6#6'Delete'#7'OnClick'#7#14'DeleteSelected'
|
||||
+#8'TabOrder'#2#1#0#0#5'TEdit'#13'SelectionName'#4'Left'#3'i'#1#6'Height'#2#21
|
||||
+#3'Top'#2#16#5'Width'#2'p'#7'Anchors'#11#5'akTop'#7'akRight'#0#8'OnChange'#7
|
||||
+#10'ChangeName'#10'OnKeyPress'#7#21'SelectionNameKeyPress'#8'TabOrder'#2#2#4
|
||||
+'Text'#6#4'Name'#0#0#7'TButton'#19'PickNewColourButton'#4'Left'#3#217#0#6'He'
|
||||
+'ight'#2#25#3'Top'#3#208#0#5'Width'#3#128#0#7'Anchors'#11#7'akRight'#8'akBot'
|
||||
+'tom'#0#7'Caption'#6#15'Pick New Colour'#8'TabOrder'#2#3#0#0#5'TEdit'#11'Col'
|
||||
+'ourValue'#4'Left'#3'i'#1#6'Height'#2#21#3'Top'#2'8'#5'Width'#2'p'#7'Anchors'
|
||||
+#11#5'akTop'#7'akRight'#0#8'ReadOnly'#9#8'TabOrder'#2#4#4'Text'#6#11'ColourV'
|
||||
+'alue'#0#0#6'TLabel'#10'CoordValue'#4'Left'#3'i'#1#6'Height'#2#14#3'Top'#2'`'
|
||||
+#5'Width'#2'p'#7'Anchors'#11#5'akTop'#7'akRight'#0#7'Caption'#6#10'CoordValu'
|
||||
+'e'#20'Constraints.MinWidth'#2'p'#11'ParentColor'#8#0#0#6'TImage'#11'ColourI'
|
||||
+'mage'#4'Left'#3#152#0#6'Height'#2#24#3'Top'#3#209#0#5'Width'#2'9'#7'Anchors'
|
||||
+#11#6'akLeft'#7'akRight'#8'akBottom'#0#0#0#7'TButton'#8'OkButton'#4'Left'#3
|
||||
+#137#1#6'Height'#2#24#3'Top'#3#209#0#5'Width'#2'P'#7'Anchors'#11#7'akRight'#8
|
||||
+'akBottom'#0#7'Caption'#6#2'Ok'#7'OnClick'#7#13'OkButtonClick'#8'TabOrder'#2
|
||||
+#5#0#0#6'TLabel'#12'CH_RGB_Label'#4'Left'#3'i'#1#6'Height'#2#14#3'Top'#3#128
|
||||
+#0#5'Width'#2'p'#7'Anchors'#11#5'akTop'#7'akRight'#0#7'Caption'#6#9'RGBValue'
|
||||
+'s'#20'Constraints.MinWidth'#2'p'#11'ParentColor'#8#0#0#0
|
||||
]);
|
||||
|
@ -1,206 +1,226 @@
|
||||
unit colourhistory;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
ComCtrls, StdCtrls, ExtCtrls;
|
||||
|
||||
type
|
||||
TColourPickerObject = class(TObject)
|
||||
constructor Create(C: Integer; P: TPoint; N: String);
|
||||
destructor Destroy; override;
|
||||
|
||||
public
|
||||
Colour: Integer;
|
||||
Pos: TPoint;
|
||||
Name: String;
|
||||
end;
|
||||
|
||||
{ TColourHistoryForm }
|
||||
|
||||
TColourHistoryForm = class(TForm)
|
||||
CH_RGB_Label: TLabel;
|
||||
OkButton: TButton;
|
||||
ColourValue: TEdit;
|
||||
CoordValue: TLabel;
|
||||
ColourImage: TImage;
|
||||
PickNewColourButton: TButton;
|
||||
DeleteButton: TButton;
|
||||
ColourList: TListView;
|
||||
SelectionName: TEdit;
|
||||
procedure ChangeName(Sender: TObject);
|
||||
procedure ChangeViewData(Sender: TObject; Item: TListItem; Selected: Boolean
|
||||
);
|
||||
procedure DeleteSelected(Sender: TObject);
|
||||
procedure AddColObj(c: TColourPickerObject; autoName: Boolean);
|
||||
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure OkButtonClick(Sender: TObject);
|
||||
procedure SelectionNameKeyPress(Sender: TObject; var Key: char);
|
||||
procedure SetCHShowMenu(Sender: TObject);
|
||||
procedure UnSetCHShowMenu(Sender: TObject);
|
||||
private
|
||||
Colour_Count: Integer;
|
||||
{ private declarations }
|
||||
protected
|
||||
procedure AddColObj(c: TColourPickerObject);
|
||||
public
|
||||
IndexSelected: Integer;
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
|
||||
|
||||
var
|
||||
ColourHistoryForm: TColourHistoryForm;
|
||||
|
||||
implementation
|
||||
uses
|
||||
colour_conv, TestUnit;
|
||||
|
||||
constructor TColourPickerObject.Create(C: Integer; P: TPoint; N: String);
|
||||
begin
|
||||
inherited Create;
|
||||
Self.Colour := C;
|
||||
Self.Pos := P;
|
||||
Self.Name:= N;
|
||||
end;
|
||||
|
||||
destructor TColourPickerObject.Destroy;
|
||||
begin
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TColourHistoryForm }
|
||||
|
||||
procedure TColourHistoryForm.AddColObj(c: TColourPickerObject; autoName: Boolean);
|
||||
begin
|
||||
if autoName then
|
||||
begin
|
||||
Inc(Colour_Count);
|
||||
// TODO: Proper name
|
||||
c.Name := IntToStr(c.Colour) + ' (' + IntToStr(Colour_Count) + ')';
|
||||
end;
|
||||
Self.AddColObj(c);
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.AddColObj(c: TColourPickerObject);
|
||||
|
||||
var
|
||||
it: TListItem;
|
||||
begin
|
||||
it := ColourList.Items.Add;
|
||||
it.Data := c;
|
||||
it.Caption:= c.Name;
|
||||
ColourList.Selected := it;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.DeleteSelected(Sender: TObject);
|
||||
|
||||
begin
|
||||
if (Assigned(ColourList.Selected)) then
|
||||
begin
|
||||
TColourPickerObject(ColourList.Selected.Data).Free;
|
||||
ColourList.Selected.Delete;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.ChangeViewData(Sender: TObject; Item: TListItem;
|
||||
Selected: Boolean);
|
||||
var
|
||||
r,g,b:integer;
|
||||
begin
|
||||
if not Assigned(Item) then
|
||||
exit;
|
||||
if not Item.Selected then
|
||||
exit;
|
||||
|
||||
{ This only occurs when we have manually added an item with the Form Editor }
|
||||
if not Assigned(Item.Data) then
|
||||
exit;
|
||||
|
||||
colour_conv.ColorToRGB(TColourPickerObject(Item.Data).Colour, r, g, b);
|
||||
|
||||
{ Change Form Text / Values }
|
||||
ColourValue.Caption := IntToStr(TColourPickerObject(Item.Data).Colour);
|
||||
CoordValue.Caption := 'Coords: ' + IntToStr(TColourPickerObject(Item.Data).Pos.X) +
|
||||
', ' + IntToStr(TColourPickerObject(Item.Data).Pos.Y);
|
||||
SelectionName.Text := TColourPickerObject(Item.Data).Name;
|
||||
|
||||
CH_RGB_Label.Caption:=Format('RGB:%d,%d,%d', [r,g,b]);
|
||||
|
||||
{ Draw the Image }
|
||||
ColourImage.Canvas.Brush.Color := TColourPickerObject(Item.Data).Colour;
|
||||
ColourImage.Canvas.Rectangle(0,0,ColourImage.Width, ColourImage.Height);
|
||||
|
||||
if Self.Visible then
|
||||
begin
|
||||
try
|
||||
SelectionName.SetFocus;
|
||||
finally
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.ChangeName(Sender: TObject);
|
||||
begin
|
||||
if not Assigned(ColourList.Selected) then
|
||||
begin
|
||||
WriteLn('We double clicked but have nothing Selected?');
|
||||
exit;
|
||||
end;
|
||||
ColourList.Selected.Caption := SelectionName.Text;
|
||||
TColourPickerObject(ColourList.Selected.Data).Name := SelectionName.Text;
|
||||
end;
|
||||
|
||||
constructor TColourHistoryForm.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
|
||||
Colour_Count := 0;
|
||||
PickNewColourButton.OnClick:= @Form1.ButtonPickClick;
|
||||
end;
|
||||
|
||||
destructor TColourHistoryForm.Destroy;
|
||||
begin
|
||||
PickNewColourButton.OnClick := nil;
|
||||
Colour_Count := 0;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.OkButtonClick(Sender: TObject);
|
||||
begin
|
||||
Self.close;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.SelectionNameKeyPress(Sender: TObject;
|
||||
var Key: char);
|
||||
begin
|
||||
if key = #13 then
|
||||
begin
|
||||
key := #0;
|
||||
Self.close;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.SetCHShowMenu(Sender: TObject);
|
||||
begin
|
||||
Form1.MenuItemColourHistory.Checked := True;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.UnSetCHShowMenu(Sender: TObject);
|
||||
begin
|
||||
Form1.MenuItemColourHistory.Checked := False;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I colourhistory.lrs}
|
||||
|
||||
end.
|
||||
|
||||
unit colourhistory;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
ComCtrls, StdCtrls, ExtCtrls;
|
||||
|
||||
type
|
||||
TColourPickerObject = class(TObject)
|
||||
constructor Create(C: Integer; P: TPoint; N: String);
|
||||
destructor Destroy; override;
|
||||
|
||||
public
|
||||
Colour: Integer;
|
||||
Pos: TPoint;
|
||||
Name: String;
|
||||
end;
|
||||
|
||||
{ TColourHistoryForm }
|
||||
|
||||
TColourHistoryForm = class(TForm)
|
||||
CH_RGB_Label: TLabel;
|
||||
OkButton: TButton;
|
||||
ColourValue: TEdit;
|
||||
CoordValue: TLabel;
|
||||
ColourImage: TImage;
|
||||
PickNewColourButton: TButton;
|
||||
DeleteButton: TButton;
|
||||
ColourList: TListView;
|
||||
SelectionName: TEdit;
|
||||
procedure ChangeName(Sender: TObject);
|
||||
procedure ChangeViewData(Sender: TObject; Item: TListItem; Selected: Boolean
|
||||
);
|
||||
procedure ColourListAdvancedCustomDrawSubItem(Sender: TCustomListView;
|
||||
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
|
||||
Stage: TCustomDrawStage; var DefaultDraw: Boolean);
|
||||
procedure DeleteSelected(Sender: TObject);
|
||||
procedure AddColObj(c: TColourPickerObject; autoName: Boolean);
|
||||
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure OkButtonClick(Sender: TObject);
|
||||
procedure SelectionNameKeyPress(Sender: TObject; var Key: char);
|
||||
procedure SetCHShowMenu(Sender: TObject);
|
||||
procedure UnSetCHShowMenu(Sender: TObject);
|
||||
private
|
||||
Colour_Count: Integer;
|
||||
{ private declarations }
|
||||
protected
|
||||
procedure AddColObj(c: TColourPickerObject);
|
||||
public
|
||||
IndexSelected: Integer;
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
|
||||
|
||||
var
|
||||
ColourHistoryForm: TColourHistoryForm;
|
||||
|
||||
implementation
|
||||
uses
|
||||
colour_conv, TestUnit;
|
||||
|
||||
constructor TColourPickerObject.Create(C: Integer; P: TPoint; N: String);
|
||||
begin
|
||||
inherited Create;
|
||||
Self.Colour := C;
|
||||
Self.Pos := P;
|
||||
Self.Name:= N;
|
||||
end;
|
||||
|
||||
destructor TColourPickerObject.Destroy;
|
||||
begin
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TColourHistoryForm }
|
||||
|
||||
procedure TColourHistoryForm.AddColObj(c: TColourPickerObject; autoName: Boolean);
|
||||
begin
|
||||
if autoName then
|
||||
begin
|
||||
Inc(Colour_Count);
|
||||
// TODO: Proper name
|
||||
c.Name := IntToStr(c.Colour) + ' (' + IntToStr(Colour_Count) + ')';
|
||||
end;
|
||||
Self.AddColObj(c);
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.AddColObj(c: TColourPickerObject);
|
||||
|
||||
var
|
||||
it: TListItem;
|
||||
begin
|
||||
it := ColourList.Items.Add;
|
||||
it.Data := c;
|
||||
it.Caption:= c.Name;
|
||||
ColourList.Selected := it;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.DeleteSelected(Sender: TObject);
|
||||
|
||||
begin
|
||||
if (Assigned(ColourList.Selected)) then
|
||||
begin
|
||||
TColourPickerObject(ColourList.Selected.Data).Free;
|
||||
ColourList.Selected.Delete;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.ChangeViewData(Sender: TObject; Item: TListItem;
|
||||
Selected: Boolean);
|
||||
var
|
||||
r,g,b:integer;
|
||||
begin
|
||||
if not Assigned(Item) then
|
||||
exit;
|
||||
if not Item.Selected then
|
||||
exit;
|
||||
|
||||
{ This only occurs when we have manually added an item with the Form Editor }
|
||||
if not Assigned(Item.Data) then
|
||||
exit;
|
||||
|
||||
colour_conv.ColorToRGB(TColourPickerObject(Item.Data).Colour, r, g, b);
|
||||
|
||||
{ Change Form Text / Values }
|
||||
ColourValue.Caption := IntToStr(TColourPickerObject(Item.Data).Colour);
|
||||
CoordValue.Caption := 'Coords: ' + IntToStr(TColourPickerObject(Item.Data).Pos.X) +
|
||||
', ' + IntToStr(TColourPickerObject(Item.Data).Pos.Y);
|
||||
SelectionName.Text := TColourPickerObject(Item.Data).Name;
|
||||
|
||||
CH_RGB_Label.Caption:=Format('RGB:%d,%d,%d', [r,g,b]);
|
||||
|
||||
{ Draw the Image }
|
||||
ColourImage.Canvas.Brush.Color := TColourPickerObject(Item.Data).Colour;
|
||||
ColourImage.Canvas.Rectangle(0,0,ColourImage.Width, ColourImage.Height);
|
||||
|
||||
if Self.Visible then
|
||||
begin
|
||||
try
|
||||
SelectionName.SetFocus;
|
||||
finally
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.ColourListAdvancedCustomDrawSubItem(
|
||||
Sender: TCustomListView; Item: TListItem; SubItem: Integer;
|
||||
State: TCustomDrawState; Stage: TCustomDrawStage; var DefaultDraw: Boolean);
|
||||
begin
|
||||
if SubItem = 0 then
|
||||
ColourList.Canvas.Brush.Color := clWhite
|
||||
else
|
||||
ColourList.Canvas.Brush.Color := TColourPickerObject(Item.Data).Colour;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.ChangeName(Sender: TObject);
|
||||
begin
|
||||
if not Assigned(ColourList.Selected) then
|
||||
begin
|
||||
WriteLn('We double clicked but have nothing Selected?');
|
||||
exit;
|
||||
end;
|
||||
ColourList.Selected.Caption := SelectionName.Text;
|
||||
TColourPickerObject(ColourList.Selected.Data).Name := SelectionName.Text;
|
||||
end;
|
||||
|
||||
constructor TColourHistoryForm.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
|
||||
Colour_Count := 0;
|
||||
PickNewColourButton.OnClick:= @Form1.ButtonPickClick;
|
||||
end;
|
||||
|
||||
destructor TColourHistoryForm.Destroy;
|
||||
begin
|
||||
PickNewColourButton.OnClick := nil;
|
||||
Colour_Count := 0;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
ColourList.Column[0].Width:= 100;
|
||||
ColourList.Column[1].Width:= 500;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.OkButtonClick(Sender: TObject);
|
||||
begin
|
||||
Self.close;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.SelectionNameKeyPress(Sender: TObject;
|
||||
var Key: char);
|
||||
begin
|
||||
if key = #13 then
|
||||
begin
|
||||
key := #0;
|
||||
Self.close;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.SetCHShowMenu(Sender: TObject);
|
||||
begin
|
||||
Form1.MenuItemColourHistory.Checked := True;
|
||||
end;
|
||||
|
||||
procedure TColourHistoryForm.UnSetCHShowMenu(Sender: TObject);
|
||||
begin
|
||||
Form1.MenuItemColourHistory.Checked := False;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I colourhistory.lrs}
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user