1
0
Files
aarre
applications
bindings
components
ZVDateTimeCtrls
aboutcomponent
acs
beepfp
callite
chelper
cmdline
cmdlinecfg
colorpalette
cryptini
csvdocument
epiktimer
flashfiler
fpsound
fpspreadsheet
fractions
freetypepascal
geckoport
gradcontrols
iosdesigner
iphonelazext
jujiboutils
jvcllaz
kcontrols
lazautoupdate
lazbarcodes
lclextensions
longtimer
manualdock
mbColorLib
examples
BAxisColorPicker.dcr
BAxisColorPicker.pas
BColorPicker.dcr
BColorPicker.pas
CColorPicker.dcr
CColorPicker.pas
CIEAColorPicker.dcr
CIEAColorPicker.pas
CIEBColorPicker.dcr
CIEBColorPicker.pas
CIELColorPicker.dcr
CIELColorPicker.pas
GAxisColorPicker.dcr
GAxisColorPicker.pas
GColorPicker.dcr
GColorPicker.pas
HColorPicker.dcr
HColorPicker.pas
HRingPicker.dcr
HRingPicker.pas
HSColorPicker.dcr
HSColorPicker.pas
HSLColorPicker.dcr
HSLColorPicker.pas
HSLRingPicker.dcr
HSLRingPicker.pas
HSVColorPicker.dcr
HSVColorPicker.pas
HTMLColors.pas
HexaColorPicker.dcr
HexaColorPicker.pas
KColorPicker.dcr
KColorPicker.pas
LColorPicker.dcr
LColorPicker.pas
MColorPicker.dcr
MColorPicker.pas
OfficeMoreColorsDialog.dfm
OfficeMoreColorsDialog.lfm
OfficeMoreColorsDialog.pas
PalUtils.pas
PickCursor.res
RAxisColorPicker.dcr
RAxisColorPicker.pas
RColorPicker.dcr
RColorPicker.pas
RGBCIEUtils.pas
RGBCMYKUtils.pas
RGBHSLUtils.pas
RGBHSVUtils.pas
Readme.rtf
SColorPicker.dcr
SColorPicker.pas
SLColorPicker.dcr
SLColorPicker.pas
SLHColorPicker.dcr
SLHColorPicker.pas
Scanlines.pas
ScreenWin.dfm
ScreenWin.lfm
ScreenWin.pas
SelPropUtils.pas
VColorPicker.dcr
VColorPicker.pas
XPLibIntegration.txt
YColorPicker.dcr
YColorPicker.pas
clean.bat
clear history.bat
mbBasicPicker.pas
mbColorLibD10.dpk
mbColorLibD5.dpk
mbColorLibD7.dpk
mbColorLibD9.dpk
mbColorList.dcr
mbColorList.pas
mbColorPalette.dcr
mbColorPalette.pas
mbColorPickerControl.pas
mbColorPreview.dcr
mbColorPreview.pas
mbColorTree.dcr
mbColorTree.pas
mbDeskPickerButton.dcr
mbDeskPickerButton.pas
mbOfficeColorDialog.dcr
mbOfficeColorDialog.pas
mbReg.lrs
mbReg.pas
mbTrackBarPicker.pas
mbcolorliblaz.lpk
mbutils.pas
mxs.inc
mplayer
multithreadprocs
nvidia-widgets
onguard
orpheus
playsoundpackage
poweredby
powerpdf
rgbgraphics
richmemo
richview
rtfview
rx
scrolltext
smnetgradient
spktoolbar
svn
tdi
thtmlport
tparadoxdataset
tvplanit
virtualtreeview
virtualtreeview-new
xdev_toolkit
zlibar
examples
lclbindings
wst
lazarus-ccr/components/mbColorLib/GAxisColorPicker.pas

383 lines
8.1 KiB
ObjectPascal
Raw Normal View History

unit GAxisColorPicker;
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
interface
uses
{$IFDEF FPC}
LCLType, LCLIntf, LMessages,
{$ELSE}
Windows, Messages,
{$ENDIF}
SysUtils, Classes, Controls, Graphics, Math, Forms,
HTMLColors, mbColorPickerControl;
type
TGAxisColorPicker = class(TmbColorPickerControl)
private
FR, FG, FB: integer;
dx, dy, mxx, myy: integer;
procedure SetRValue(r: integer);
procedure SetGValue(g: integer);
procedure SetBValue(b: integer);
protected
procedure CorrectCoords(var x, y: integer);
procedure CreateWnd; override;
procedure DrawMarker(x, y: integer);
function GetGradientColor2D(x, y: Integer): TColor; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
(*
procedure CNKeyDown(var Message: {$IFDEF FPC}TLMKeyDown{$ELSE}TWMKeyDown{$ENDIF});
message CN_KEYDOWN;
*)
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure Paint; override;
procedure Resize; override;
procedure SetSelectedColor(c: TColor); override;
public
constructor Create(AOwner: TComponent); override;
published
property SelectedColor default clLime;
property RValue: integer read FR write SetRValue default 0;
property GValue: integer read FG write SetGValue default 255;
property BValue: integer read FB write SetBValue default 0;
property MarkerStyle default msCircle;
property OnChange;
end;
implementation
uses
mbUtils;
{TGAxisColorPicker}
constructor TGAxisColorPicker.Create(AOwner: TComponent);
begin
inherited;
FGradientWidth := 256;
FGradientHeight := 256;
{$IFDEF DELPHI}
Width := 256;
Height := 256;
{$ELSE}
SetInitialBounds(0, 0, 256, 256);
{$ENDIF}
HintFormat := 'R: %r B: %b'#13'Hex: %hex';
FG := 255;
FB := 0;
FR := 0;
FSelected := clLime;
FManual := false;
dx := 0;
dy := 0;
mxx := 0;
myy := 0;
MarkerStyle := msCircle;
end;
procedure TGAxisColorPicker.CorrectCoords(var x, y: integer);
begin
Clamp(x, 0, Width-1);
Clamp(y, 0, Height-1);
end;
procedure TGAxisColorPicker.CreateWnd;
begin
inherited;
CreateGradient;
end;
function TGAxisColorPicker.GetGradientColor2D(x, y: Integer): TColor;
begin
Result := RGB(FBufferBmp.Height - 1 - y, FG, x);
end;
procedure TGAxisColorPicker.DrawMarker(x, y: integer);
var
c: TColor;
begin
CorrectCoords(x, y);
FR := GetRValue(FSelected);
FG := GetGValue(FSelected);
FB := GetBValue(FSelected);
dx := x;
dy := y;
if Focused or (csDesigning in ComponentState) then
c := clBlack
else
c := clWhite;
InternalDrawMarker(x, y, c);
end;
procedure TGAxisColorPicker.SetSelectedColor(c: TColor);
begin
if WebSafe then c := GetWebSafe(c);
FR := GetRValue(c);
FG := GetGValue(c);
FB := GetBValue(c);
FSelected := c;
FManual := false;
myy := Round((255 - FR) * Height / 255);
mxx := Round(FB * Width / 255);
Invalidate;
if Assigned(FOnChange) then
FOnChange(Self);
end;
procedure TGAxisColorPicker.Paint;
begin
Canvas.StretchDraw(ClientRect, FBufferBmp);
CorrectCoords(mxx, myy);
DrawMarker(mxx, myy);
end;
procedure TGAxisColorPicker.Resize;
begin
FManual := false;
myy := Round((255 - FR) * Height / 255);
mxx := Round(FB * Width / 255);
inherited;
end;
procedure TGAxisColorPicker.KeyDown(var Key: Word; Shift: TShiftState);
var
eraseKey: Boolean;
delta: Integer;
begin
eraseKey := true;
if (ssCtrl in Shift) then delta := 10 else delta := 1;
case Key of
VK_LEFT:
begin
mxx := dx - delta;
myy := dy;
if mxx < 0 then mxx := 0;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
if Assigned(FOnChange) then
FOnChange(Self);
end;
VK_RIGHT:
begin
mxx := dx + delta;
myy := dy;
if mxx >= Width then mxx := Width - 1;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
if Assigned(FOnChange) then
FOnChange(Self);
end;
VK_UP:
begin
mxx := dx;
myy := dy - delta;
if myy < 0 then myy := 0;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
if Assigned(FOnChange) then
FOnChange(Self);
end;
VK_DOWN:
begin
mxx := dx;
myy := dy + delta;
if myy >= Height then myy := Height - 1;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
if Assigned(FOnChange) then
FOnChange(Self);
end;
else
eraseKey := false;
end;
if eraseKey then Key := 0;
inherited;
end;
procedure TGAxisColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
R: TRect;
begin
inherited;
mxx := x;
myy := y;
if Button = mbLeft then
begin
{$IFDEF DELPHI}
R := ClientRect;
R.TopLeft := ClientToScreen(R.TopLeft);
R.BottomRight := ClientToScreen(R.BottomRight);
ClipCursor(@R);
{$ENDIF}
FSelected := GetColorAtPoint(x, y);
FManual := true;
Invalidate;
end;
SetFocus;
end;
procedure TGAxisColorPicker.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;
if ssLeft in Shift then
begin
{$IFDEF DELPHI}
ClipCursor(nil);
{$ENDIF}
mxx := X;
myy := Y;
FSelected := GetColorAtPoint(X, Y);
FManual := true;
Invalidate;
if Assigned(FOnChange) then
FOnChange(Self);
end;
end;
procedure TGAxisColorPicker.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited;
if ssLeft in Shift then
begin
mxx := X;
myy := Y;
FSelected := GetColorAtPoint(X, Y);
FManual := true;
Invalidate;
if Assigned(FOnChange) then
FOnChange(Self);
end;
end;
(*
procedure TGAxisColorPicker.CNKeyDown(
var Message: {$IFDEF FPC}TLMKeyDown{$ELSE}TWMKeyDown{$ENDIF});
var
Shift: TShiftState;
FInherited: boolean;
begin
FInherited := false;
Shift := KeyDataToShiftState(Message.KeyData);
if not (ssCtrl in Shift) then
case Message.CharCode of
VK_LEFT:
begin
mxx := dx - 1;
myy := dy;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
end;
VK_RIGHT:
begin
mxx := dx + 1;
myy := dy;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
end;
VK_UP:
begin
mxx := dx;
myy := dy - 1;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
end;
VK_DOWN:
begin
mxx := dx;
myy := dy + 1;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
end;
else
begin
FInherited := true;
inherited;
end;
end
else
case Message.CharCode of
VK_LEFT:
begin
mxx := dx - 10;
myy := dy;
Refresh;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
end;
VK_RIGHT:
begin
mxx := dx + 10;
myy := dy;
Refresh;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
end;
VK_UP:
begin
mxx := dx;
myy := dy - 10;
Refresh;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
end;
VK_DOWN:
begin
mxx := dx;
myy := dy + 10;
Refresh;
FSelected := GetColorAtPoint(mxx, myy);
FManual := true;
Invalidate;
end;
else
begin
FInherited := true;
inherited;
end;
end;
if not FInherited then
if Assigned(OnKeyDown) then
OnKeyDown(Self, Message.CharCode, Shift);
end;
*)
procedure TGAxisColorPicker.SetRValue(r: integer);
begin
Clamp(r, 0, 255);
FR := r;
SetSelectedColor(RGB(FR, FG, FB));
end;
procedure TGAxisColorPicker.SetGValue(g: integer);
begin
Clamp(g, 0, 255);
FG := g;
SetSelectedColor(RGB(FR, FG, FB));
end;
procedure TGAxisColorPicker.SetBValue(b: integer);
begin
Clamp(b, 0, 255);
FB := b;
SetSelectedColor(RGB(FR, FG, FB));
end;
end.