ColorPicker

From Vectorlab
Jump to: navigation, search

This is an example of how to use the Color Picker. Instead of the standard example, this one contains a function that you can immediately copy and paste to use in your own projects.

By Gerard Jonker

procedure test;
var h:handle;
bool : boolean;
IndexedColor : integer;
r,g,b : longint;

function DialogColorPicker(var IndColor : integer):boolean;
VAR
dialog1  :INTEGER;
PROCEDURE Dialog_Handler(VAR item :LONGINT; data :LONGINT);
BEGIN {dialog procedure}
	CASE item OF
		SetupDialogC:
			BEGIN
			SetColorChoice(dialog1, 4, IndColor);
			END;
		1:
			BEGIN
			GetColorChoice(dialog1, 4, IndColor);
			END;
		END; {Case}
END; {dialog procedure}
BEGIN {main part of the Function}
dialog1 := CreateLayout('Color Dialog', FALSE, 'OK', 'Cancel');
CreateColorPopup(dialog1, 4, 24);
SetFirstLayoutItem(dialog1, 4);
DialogColorPicker := RunLayoutDialog(dialog1, Dialog_Handler) = 1;  {OK = 1 -> True}
END; {main part of the Function}


begin
h:=fsactlayer; {Foreachobjectinlayer is a better way to get a handle}
if h <> nil then 
	begin
	getFillBack(h,r,g,b); {get current color of object}
	RGBToColorIndexN(r, g, b, IndexedColor, TRUE); 
	if DialogColorPicker(IndexedColor) then {display dialog showing current color}
		begin
		ColorIndexToRGBN(IndexedColor,r,g,b,TRUE);
		SetFillBack(h,r,g,b);	 {apply chosen color}
		end;
	end;
end;
RUN(test);