You've already forked lazarus-ccr
jvcllaz: Fix high-dpi awareness of TJvGammaPanel.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7157 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1,21 +1,27 @@
|
||||
object DemoForm: TDemoForm
|
||||
Left = 340
|
||||
Height = 393
|
||||
Top = 128
|
||||
Width = 431
|
||||
Left = 440
|
||||
Height = 265
|
||||
Top = 205
|
||||
Width = 334
|
||||
AutoSize = True
|
||||
Caption = 'JvGammaPanel demo'
|
||||
ClientHeight = 393
|
||||
ClientWidth = 431
|
||||
ClientHeight = 265
|
||||
ClientWidth = 334
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '2.1.0.0'
|
||||
object JvGammaPanel1: TJvGammaPanel
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
AnchorSideBottom.Control = Owner
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 8
|
||||
Height = 249
|
||||
Top = 8
|
||||
Anchors = [akTop, akLeft, akBottom]
|
||||
BorderSpacing.Left = 8
|
||||
BorderSpacing.Top = 8
|
||||
BorderSpacing.Bottom = 8
|
||||
ForegroundColor = clWhite
|
||||
BackgroundColor = clBlack
|
||||
OnChangeColor = JvGammaPanel1ChangeColor
|
||||
end
|
||||
object DemoLabel: TLabel
|
||||
@ -25,7 +31,7 @@ object DemoForm: TDemoForm
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 105
|
||||
Height = 45
|
||||
Top = 111
|
||||
Top = 110
|
||||
Width = 214
|
||||
BorderSpacing.Left = 32
|
||||
BorderSpacing.Right = 16
|
||||
@ -34,4 +40,38 @@ object DemoForm: TDemoForm
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object FgColorBtn: TColorButton
|
||||
AnchorSideLeft.Control = DemoLabel
|
||||
AnchorSideTop.Control = JvGammaPanel1
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 105
|
||||
Height = 25
|
||||
Top = 8
|
||||
Width = 207
|
||||
BorderWidth = 2
|
||||
ButtonColorAutoSize = False
|
||||
ButtonColorSize = 16
|
||||
ButtonColor = clBlack
|
||||
Caption = 'Foreground color'
|
||||
OnColorChanged = FgColorBtnColorChanged
|
||||
end
|
||||
object BgColorBtn: TColorButton
|
||||
AnchorSideLeft.Control = DemoLabel
|
||||
AnchorSideTop.Control = FgColorBtn
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = FgColorBtn
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 105
|
||||
Height = 25
|
||||
Top = 37
|
||||
Width = 207
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 4
|
||||
BorderWidth = 2
|
||||
ButtonColorAutoSize = False
|
||||
ButtonColorSize = 16
|
||||
ButtonColor = clBlack
|
||||
Caption = 'Background color'
|
||||
OnColorChanged = BgColorBtnColorChanged
|
||||
end
|
||||
end
|
||||
|
@ -13,10 +13,14 @@ type
|
||||
{ TDemoForm }
|
||||
|
||||
TDemoForm = class(TForm)
|
||||
FgColorBtn: TColorButton;
|
||||
BgColorBtn: TColorButton;
|
||||
JvGammaPanel1: TJvGammaPanel;
|
||||
DemoLabel: TLabel;
|
||||
procedure JvGammaPanel1ChangeColor(Sender: TObject; Foreground,
|
||||
Background: TColor);
|
||||
procedure BgColorBtnColorChanged(Sender: TObject);
|
||||
procedure FgColorBtnColorChanged(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure JvGammaPanel1ChangeColor(Sender: TObject; FgColor, BgColor: TColor);
|
||||
private
|
||||
|
||||
public
|
||||
@ -32,11 +36,29 @@ implementation
|
||||
|
||||
{ TDemoForm }
|
||||
|
||||
procedure TDemoForm.JvGammaPanel1ChangeColor(Sender: TObject; Foreground,
|
||||
Background: TColor);
|
||||
procedure TDemoForm.BgColorBtnColorChanged(Sender: TObject);
|
||||
begin
|
||||
DemoLabel.Color := Background;
|
||||
DemoLabel.Font.Color := Foreground;
|
||||
JvGammaPanel1.BackgroundColor := BgColorBtn.ButtonColor;
|
||||
end;
|
||||
|
||||
procedure TDemoForm.FgColorBtnColorChanged(Sender: TObject);
|
||||
begin
|
||||
JvGammaPanel1.ForegroundColor := FgColorBtn.ButtonColor;
|
||||
end;
|
||||
|
||||
procedure TDemoForm.FormCreate(Sender: TObject);
|
||||
begin
|
||||
FgColorBtn.ButtonColor := JvGammaPanel1.ForegroundColor;
|
||||
BgColorBtn.ButtonColor := JvGammaPanel1.BackgroundColor;
|
||||
|
||||
DemoLabel.Color := JvGammaPanel1.BackgroundColor;
|
||||
Demolabel.Font.Color := JvGammaPanel1.ForegroundColor;
|
||||
end;
|
||||
|
||||
procedure TDemoForm.JvGammaPanel1ChangeColor(Sender: TObject; FgColor, BgColor: TColor);
|
||||
begin
|
||||
DemoLabel.Color := BgColor;
|
||||
DemoLabel.Font.Color := FgColor;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -942,8 +942,8 @@ resourcestring
|
||||
RsGreenFormat = 'G : %3D';
|
||||
RsBlueFormat = 'B : %3D';
|
||||
|
||||
RsHint1 = 'Background Color';
|
||||
RsHint2 = 'Foreground Color';
|
||||
RsHintBg = 'Background Color';
|
||||
RsHintFg = 'Foreground Color';
|
||||
RsXCaption = 'X';
|
||||
RsLabelHint = 'Exchange colors';
|
||||
|
||||
|
@ -29,63 +29,61 @@ Known Issues:
|
||||
|
||||
unit JvGammaPanel;
|
||||
|
||||
//{$I jvcl.inc}
|
||||
{$MODE OBJFPC}{$H+}
|
||||
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Types, SysUtils, Classes,
|
||||
//Windows, Messages,
|
||||
Graphics, Controls, Dialogs,
|
||||
ExtCtrls, StdCtrls,
|
||||
Types, SysUtils, Classes, Graphics, Controls, Dialogs, ExtCtrls, StdCtrls,
|
||||
JvTypes;
|
||||
// JvTypes, JvComponent;
|
||||
|
||||
|
||||
type
|
||||
TJvGammaPanel = class(TWinControl) //TJvWinControl)
|
||||
TJvGammaPanel = class(TWinControl)
|
||||
private
|
||||
FForegroundColor: TColor;
|
||||
FBackgroundColor: TColor;
|
||||
LastCol: TColor;
|
||||
FPanel1: TPanel;
|
||||
FPanel2: TPanel;
|
||||
FPanel3: TPanel;
|
||||
FPanel4: TPanel;
|
||||
FGamma: TImage;
|
||||
FForegroundColorImg: TShape;
|
||||
FBackgroundColorImg: TShape;
|
||||
FChosen: TShape;
|
||||
FXLabel: TLabel;
|
||||
FRLabel: TLabel;
|
||||
FGLabel: TLabel;
|
||||
FBLabel: TLabel;
|
||||
FXLabel: TLabel;
|
||||
FGamma: TImage;
|
||||
FChoosed: TImage;
|
||||
FForegroundColorImg: TImage;
|
||||
FBackgroundColorImg: TImage;
|
||||
FLastColor: TColor;
|
||||
FOnChangeColor: TJvChangeColorEvent;
|
||||
procedure ChangeColor(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
procedure BgColorClick(Sender: TObject);
|
||||
procedure ChangeColor(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
procedure ColorSeek(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
||||
procedure Exchange(Sender: TObject);
|
||||
procedure SetForegroundColor(const Value: TColor);
|
||||
procedure SetBackgroundColor(const Value: TColor);
|
||||
procedure Color1Click(Sender: TObject);
|
||||
procedure Color2Click(Sender: TObject);
|
||||
procedure FgColorClick(Sender: TObject);
|
||||
function GetBackgroundColor: TColor;
|
||||
function GetForegroundColor: TColor;
|
||||
function IsHeightStored: Boolean;
|
||||
function IsWidthStored: Boolean;
|
||||
procedure SetBackgroundColor(const AValue: TColor);
|
||||
procedure SetForegroundColor(const AValue: TColor);
|
||||
protected
|
||||
procedure BoundsChanged; override;
|
||||
procedure DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
||||
const AXProportion, AYProportion: Double); override;
|
||||
procedure DoChangeColor(AForegroundColor, ABackgroundColor: TColor); virtual;
|
||||
procedure Resize; override;
|
||||
public
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
published
|
||||
property Align;
|
||||
property AutoSize;
|
||||
property Anchors;
|
||||
property BorderSpacing;
|
||||
property Height default 250;
|
||||
property Width default 65;
|
||||
property ForegroundColor: TColor read FForegroundColor write SetForegroundColor default clBlack;
|
||||
property BackgroundColor: TColor read FBackgroundColor write SetBackgroundColor default clWhite;
|
||||
property Height stored IsHeightStored;
|
||||
property Width stored IsWidthStored;
|
||||
property ForegroundColor: TColor read GetForegroundColor write SetForegroundColor default clBlack;
|
||||
property BackgroundColor: TColor read GetBackgroundColor write SetBackgroundColor default clWhite;
|
||||
property OnChangeColor: TJvChangeColorEvent read FOnChangeColor write FOnChangeColor;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
@ -94,122 +92,69 @@ uses
|
||||
|
||||
{$R ../../resource/jvgammapanel.res}
|
||||
|
||||
const
|
||||
DEFAULT_WIDTH = 65;
|
||||
DEFAULT_HEIGHT = 250;
|
||||
|
||||
MARGIN_1 = 5;
|
||||
MARGIN_2 = 2;
|
||||
IMG_SIZE = 30;
|
||||
|
||||
constructor TJvGammaPanel.Create(AOwner: TComponent);
|
||||
var
|
||||
p5: Integer;
|
||||
begin
|
||||
inherited Create(AOwner);
|
||||
Width := 65;
|
||||
Height := 250;
|
||||
FForegroundColor := clBlack;
|
||||
FBackgroundColor := clWhite;
|
||||
Width := DEFAULT_WIDTH; // Scaling of outer dimensions is done automatically
|
||||
Height := DEFAULT_HEIGHT;
|
||||
|
||||
FPanel1 := TPanel.Create(Self);
|
||||
with FPanel1 do
|
||||
begin
|
||||
Parent := Self;
|
||||
// Width := 65;
|
||||
// Height := 250;
|
||||
Align := alClient;
|
||||
BevelInner := bvLowered;
|
||||
BevelOuter := bvRaised;
|
||||
Visible := True;
|
||||
end;
|
||||
|
||||
FPanel2 := TPanel.Create(FPanel1);
|
||||
with FPanel2 do
|
||||
begin
|
||||
Parent := FPanel1;
|
||||
Left := 5;
|
||||
Top := 5;
|
||||
Width := 55;
|
||||
Height := 105;
|
||||
Align := alClient;
|
||||
BorderSpacing.Around := Scale96ToFont(MARGIN_1); // Scale inner dimensions manually
|
||||
BevelInner := bvLowered;
|
||||
BevelOuter := bvRaised;
|
||||
Visible := True;
|
||||
end;
|
||||
|
||||
FPanel3 := TPanel.Create(FPanel1);
|
||||
with FPanel3 do
|
||||
begin
|
||||
Parent := FPanel1;
|
||||
Left := 5;
|
||||
Top := 115;
|
||||
Width := 55;
|
||||
Height := 50;
|
||||
Align := alBottom;
|
||||
BorderSpacing.Left := Scale96ToFont(MARGIN_1);
|
||||
BorderSpacing.Right := Scale96ToFont(MARGIN_1);
|
||||
Height := Scale96ToFont(3*IMG_SIZE div 2 + 2 * MARGIN_2);
|
||||
BevelInner := bvLowered;
|
||||
BevelOuter := bvRaised;
|
||||
Visible := True;
|
||||
end;
|
||||
|
||||
FPanel4 := TPanel.Create(FPanel1);
|
||||
with FPanel4 do
|
||||
begin
|
||||
Parent := FPanel1;
|
||||
Left := 5;
|
||||
Top := 170;
|
||||
Width := 55;
|
||||
Height := 75;
|
||||
Align := alBottom;
|
||||
BorderSpacing.Around := Scale96ToFont(MARGIN_1);
|
||||
BevelInner := bvLowered;
|
||||
BevelOuter := bvRaised;
|
||||
Visible := True;
|
||||
end;
|
||||
|
||||
FRLabel := TLabel.Create(FPanel4);
|
||||
with FRLabel do
|
||||
begin
|
||||
Top := 2;
|
||||
Left := 5;
|
||||
AutoSize := True;
|
||||
{
|
||||
Font.Size := 8;
|
||||
Font.Name := 'Arial';
|
||||
}
|
||||
Caption := RsDefaultR;
|
||||
Transparent := True;
|
||||
Parent := FPanel4;
|
||||
end;
|
||||
|
||||
FGLabel := TLabel.Create(FPanel4);
|
||||
with FGLabel do
|
||||
begin
|
||||
Top := 14;
|
||||
Left := 5;
|
||||
AutoSize := True;
|
||||
{
|
||||
Font.Name := 'Arial';
|
||||
Font.Size := 8;
|
||||
}
|
||||
Caption := RsDefaultG;
|
||||
Transparent := True;
|
||||
Parent := FPanel4;
|
||||
end;
|
||||
|
||||
FBLabel := TLabel.Create(FPanel4);
|
||||
with FBLabel do
|
||||
begin
|
||||
Top := 26;
|
||||
Left := 5;
|
||||
{
|
||||
Font.Size := 8;
|
||||
Font.Name := 'arial';
|
||||
}
|
||||
AutoSize := True;
|
||||
Caption := RsDefaultB;
|
||||
Transparent := True;
|
||||
Parent := FPanel4;
|
||||
AutoSize := true;
|
||||
Top := self.Height; // Force to be at very bottom
|
||||
end;
|
||||
|
||||
FGamma := TImage.Create(FPanel2);
|
||||
with FGamma do
|
||||
begin
|
||||
Parent := FPanel2;
|
||||
Stretch := False;
|
||||
Center := True;
|
||||
AutoSize := True;
|
||||
Picture.Bitmap.PixelFormat := pf24bit;
|
||||
Width := 55;
|
||||
Height := 105;
|
||||
Align := alClient;
|
||||
Stretch := true;
|
||||
OnMouseDown := @ChangeColor;
|
||||
OnMouseMove := @ColorSeek;
|
||||
Align := alClient;
|
||||
@ -217,112 +162,93 @@ begin
|
||||
Cursor := crCross;
|
||||
end;
|
||||
|
||||
FChoosed := TImage.Create(FPanel4);
|
||||
with FChoosed do
|
||||
begin
|
||||
Top := 40;
|
||||
Left := 12;
|
||||
Width := 30;
|
||||
Height := 30;
|
||||
Parent := FPanel4;
|
||||
Visible := True;
|
||||
Stretch := False;
|
||||
Align := alNone;
|
||||
// Picture.Bitmap := TBitmap.Create;
|
||||
Picture.Bitmap.Width := Width;
|
||||
Picture.Bitmap.Height := Height;
|
||||
Canvas.Brush.Color := clBlack;
|
||||
Canvas.Brush.Style := bsSolid;
|
||||
Canvas.FillRect(Rect(0, 0, Width, Height));
|
||||
end;
|
||||
|
||||
FForegroundColorImg := TImage.Create(FPanel3);
|
||||
with FForegroundColorImg do
|
||||
begin
|
||||
Left := 5;
|
||||
Top := 5;
|
||||
Width := 25;
|
||||
Height := 25;
|
||||
// Picture.Bitmap := TBitmap.Create;
|
||||
Picture.Bitmap.Width := FChoosed.Width;
|
||||
Picture.Bitmap.Height := FChoosed.Height;
|
||||
Canvas.Brush.Color := clBlack;
|
||||
Canvas.Brush.Style := bsSolid;
|
||||
Canvas.FillRect(Rect(0, 0, FChoosed.Width, FChoosed.Height));
|
||||
Hint := RsHint2;
|
||||
ShowHint := True;
|
||||
OnClick := @Color1Click;
|
||||
Parent := FPanel3;
|
||||
Visible := True;
|
||||
end;
|
||||
|
||||
FBackgroundColorImg := TImage.Create(FPanel3);
|
||||
FBackgroundColorImg := TShape.Create(FPanel3);
|
||||
with FBackgroundColorImg do
|
||||
begin
|
||||
Left := 25;
|
||||
Top := 20;
|
||||
Height := 25;
|
||||
Width := 25;
|
||||
// Picture.Bitmap := TBitmap.Create;
|
||||
Picture.Bitmap.Width := FChoosed.Width;
|
||||
Picture.Bitmap.Height := FChoosed.Height;
|
||||
Canvas.Brush.Color := clWhite;
|
||||
Canvas.Brush.Style := bsSolid;
|
||||
Canvas.FillRect(Rect(0, 0, FChoosed.Width, FChoosed.Height));
|
||||
Hint := RsHint1;
|
||||
ShowHint := True;
|
||||
OnClick := @Color2Click;
|
||||
Parent := FPanel3;
|
||||
Visible := True;
|
||||
Height := Scale96ToFont(IMG_SIZE);
|
||||
Width := Height;
|
||||
Top := Scale96ToFont(MARGIN_2) + Height div 2;
|
||||
Left := Scale96ToFont(MARGIN_2) + Width div 2;
|
||||
Brush.Color := clBlack;
|
||||
Hint := RsHintBg;
|
||||
ShowHint := True;
|
||||
OnClick := @BgColorClick;
|
||||
end;
|
||||
|
||||
FForegroundColorImg := TShape.Create(FPanel3);
|
||||
with FForegroundColorImg do
|
||||
begin
|
||||
Parent := FPanel3;
|
||||
Height := Scale96ToFont(IMG_SIZE);
|
||||
Width := Height;
|
||||
Left := Scale96ToFont(MARGIN_2);
|
||||
Top := Scale96ToFont(MARGIN_2);
|
||||
Brush.Color := clWhite;
|
||||
Hint := RsHintFg;
|
||||
ShowHint := True;
|
||||
OnClick := @FgColorClick;
|
||||
end;
|
||||
|
||||
FXLabel := TLabel.Create(FPanel3);
|
||||
with FXLabel do
|
||||
begin
|
||||
Left := 7;
|
||||
Top := 32;
|
||||
Parent := FPanel3;
|
||||
BorderSpacing.Left := Scale96ToFont(MARGIN_1);
|
||||
BorderSpacing.Bottom := 0;
|
||||
Alignment := taCenter;
|
||||
AutoSize := True;
|
||||
Caption := RsXCaption;
|
||||
Hint := RsLabelHint;
|
||||
OnClick := @Exchange;
|
||||
ShowHint := True;
|
||||
Visible := True;
|
||||
Parent := FPanel3;
|
||||
end;
|
||||
|
||||
FRLabel := TLabel.Create(FPanel4);
|
||||
with FRLabel do
|
||||
begin
|
||||
Parent := FPanel4;
|
||||
Align := alTop;
|
||||
BorderSpacing.Left := Scale96ToFont(2);
|
||||
Caption := RsDefaultR;
|
||||
Transparent := True;
|
||||
end;
|
||||
|
||||
FGLabel := TLabel.Create(FPanel4);
|
||||
with FGLabel do
|
||||
begin
|
||||
Parent := FPanel4;
|
||||
Align := alTop;
|
||||
Top := FRLabel.Top + FRLabel.Height;
|
||||
BorderSpacing.Left := FRLabel.BorderSpacing.Left;
|
||||
Caption := RsDefaultG;
|
||||
Transparent := True;
|
||||
end;
|
||||
|
||||
FBLabel := TLabel.Create(FPanel4);
|
||||
with FBLabel do
|
||||
begin
|
||||
Parent := FPanel4;
|
||||
Align := alTop;
|
||||
Top := FGLabel.Top + FGLabel.Height;
|
||||
BorderSpacing.Left := FRLabel.BorderSpacing.Left;
|
||||
Caption := RsDefaultB;
|
||||
Transparent := True;
|
||||
end;
|
||||
|
||||
FChosen := TShape.Create(FPanel4);
|
||||
with FChosen do
|
||||
begin
|
||||
Parent := FPanel4;
|
||||
Align := alTop;
|
||||
Top := FBLabel.Top + FBLabel.Height;
|
||||
Height := FBLabel.Height * 2;
|
||||
BorderSpacing.Around := Scale96ToFont(MARGIN_1);
|
||||
Brush.Color := clBlack;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.ChangeColor(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
||||
begin
|
||||
if Button = mbLeft then
|
||||
begin
|
||||
FForegroundColor := LastCol;
|
||||
FForegroundColorImg.Canvas.Brush.Color := FForegroundColor;
|
||||
FForegroundColorImg.Canvas.Brush.Style := bsSolid;
|
||||
FForegroundColorImg.Canvas.FillRect(Rect(0, 0, FChoosed.Width, FChoosed.Height));
|
||||
DoChangeColor(FForegroundColor, FBackgroundColor);
|
||||
end
|
||||
else
|
||||
if Button = mbRight then
|
||||
begin
|
||||
FBackgroundColor := LastCol;
|
||||
FBackgroundColorImg.Canvas.Brush.Color := FBackgroundColor;
|
||||
FBackgroundColorImg.Canvas.Brush.Style := bsSolid;
|
||||
FBackgroundColorImg.Canvas.FillRect(Rect(0, 0, FChoosed.Width, FChoosed.Height));
|
||||
DoChangeColor(FForegroundColor, FBackgroundColor);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.Color1Click(Sender: TObject);
|
||||
begin
|
||||
with TColorDialog.Create(Self) do
|
||||
begin
|
||||
if Execute then
|
||||
SetForegroundColor(Color);
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.Color2Click(Sender: TObject);
|
||||
procedure TJvGammaPanel.BgColorClick(Sender: TObject);
|
||||
begin
|
||||
with TColorDialog.Create(Self) do
|
||||
begin
|
||||
@ -332,69 +258,68 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.ColorSeek(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
||||
procedure TJvGammaPanel.ChangeColor(Sender: TObject; Button: TMouseButton;
|
||||
Shift: TShiftState; X, Y: Integer);
|
||||
begin
|
||||
if Button = mbLeft then
|
||||
begin
|
||||
FForegroundColorImg.Brush.Color := FLastColor;
|
||||
DoChangeColor(FLastColor, FBackgroundColorImg.Brush.Color);
|
||||
end else
|
||||
if Button = mbRight then
|
||||
begin
|
||||
FBackgroundColorImg.Brush.Color := FLastColor;
|
||||
DoChangeColor(FForegroundColorImg.Brush.Color, FLastColor);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.ColorSeek(Sender: TObject; Shift: TShiftState;
|
||||
X, Y: Integer);
|
||||
var
|
||||
Col: TColor;
|
||||
col: TColor;
|
||||
xbmp, ybmp: Integer;
|
||||
begin
|
||||
if not PtInRect(Bounds(0, 0, FGamma.Picture.Width, FGamma.Picture.Height), Point(X,Y)) then
|
||||
Exit; // asn for Linux/X11
|
||||
Col := FGamma.Picture.Bitmap.Canvas.Pixels[X, Y];
|
||||
LastCol := Col;
|
||||
FRLabel.Caption := Format(RsRedFormat, [GetRValue(Col)]);
|
||||
FGLabel.Caption := Format(RsGreenFormat, [GetGValue(Col)]);
|
||||
FBLabel.Caption := Format(RsBlueFormat, [GetBValue(Col)]);
|
||||
FChoosed.Canvas.Brush.Color := Col;
|
||||
FChoosed.Canvas.Brush.Style := bsSolid;
|
||||
FChoosed.Canvas.FillRect(Rect(0, 0, FChoosed.Width, FChoosed.Height));
|
||||
if not PtInRect(Bounds(0, 0, FGamma.Width, FGamma.Height), Point(X,Y)) then
|
||||
Exit;
|
||||
|
||||
xbmp := round(X * FGamma.Picture.Bitmap.Width / FGamma.Width);
|
||||
ybmp := round(Y * FGamma.Picture.Bitmap.Height / FGamma.Height);
|
||||
col := FGamma.Picture.Bitmap.Canvas.Pixels[xbmp, ybmp];
|
||||
FLastColor := col;
|
||||
FRLabel.Caption := Format(RsRedFormat, [GetRValue(col)]);
|
||||
FGLabel.Caption := Format(RsGreenFormat, [GetGValue(col)]);
|
||||
FBLabel.Caption := Format(RsBlueFormat, [GetBValue(col)]);
|
||||
FChosen.Brush.Color := col;
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.Exchange(Sender: TObject);
|
||||
var
|
||||
Col: TColor;
|
||||
procedure TJvGammaPanel.DoAutoAdjustLayout(const AMode: TLayoutAdjustmentPolicy;
|
||||
const AXProportion, AYProportion: Double);
|
||||
begin
|
||||
// exchange colors
|
||||
Col := FForegroundColor;
|
||||
FForegroundColor := FBackgroundColor;
|
||||
FBackgroundColor := Col;
|
||||
inherited;
|
||||
|
||||
FForegroundColorImg.Canvas.Brush.Color := FForegroundColor;
|
||||
FForegroundColorImg.Canvas.Brush.Style := bsSolid;
|
||||
FForegroundColorImg.Canvas.FillRect(Rect(0, 0, FChoosed.Width, FChoosed.Height));
|
||||
FPanel2.BorderSpacing.Around := round(MARGIN_1 * AXProportion);
|
||||
FPanel3.BorderSpacing.Left := round(MARGIN_1 * AXProportion);
|
||||
FPanel3.BorderSpacing.Right := round(MARGIN_1 * AXProportion);
|
||||
FPanel3.Height := round((IMG_SIZE * 3 div 2 + 2 * MARGIN_2) * AYProportion);
|
||||
|
||||
FBackgroundColorImg.Canvas.Brush.Color := FBackgroundColor;
|
||||
FBackgroundColorImg.Canvas.Brush.Style := bsSolid;
|
||||
FBackgroundColorImg.Canvas.FillRect(Rect(0, 0, FChoosed.Width, FChoosed.Height));
|
||||
FPanel4.BorderSpacing.Around := round(MARGIN_1 * AXProportion);
|
||||
|
||||
if Assigned(FOnChangeColor) then
|
||||
FOnChangeColor(Self, FForegroundColor, FBackgroundColor);
|
||||
end;
|
||||
FBackgroundColorImg.Height := round(IMG_SIZE * AYProportion);
|
||||
FBackgroundColorImg.Width := round(IMG_SIZE * AXProportion);
|
||||
FBackgroundColorImg.Top := round((MARGIN_2 + IMG_SIZE div 2) * AYProportion);
|
||||
FBackgroundColorImg.Left := round((MARGIN_2 + IMG_SIZE div 2) * AXProportion);
|
||||
|
||||
procedure TJvGammaPanel.SetForegroundColor(const Value: TColor);
|
||||
begin
|
||||
FForegroundColor := Value;
|
||||
FForegroundColorImg.Canvas.Brush.Color := FForegroundColor;
|
||||
FForegroundColorImg.Canvas.Brush.Style := bsSolid;
|
||||
FForegroundColorImg.Canvas.FillRect(Rect(0, 0, FChoosed.Width, FChoosed.Height));
|
||||
if Assigned(FOnChangeColor) then
|
||||
FOnChangeColor(Self, FForegroundColor, FBackgroundColor);
|
||||
end;
|
||||
FForegroundColorImg.Height := round(IMG_SIZE * AYProportion);
|
||||
FBackgroundColorImg.Width := round(IMG_SIZE * AXProportion);
|
||||
FBackgroundColorImg.Left := round(MARGIN_2 * AXProportion);
|
||||
FBackgroundColorImg.Top := round(MARGIN_2 * AYProportion);
|
||||
|
||||
procedure TJvGammaPanel.SetBackgroundColor(const Value: TColor);
|
||||
begin
|
||||
FBackgroundColor := Value;
|
||||
FBackgroundColorImg.Canvas.Brush.Color := FBackgroundColor;
|
||||
FBackgroundColorImg.Canvas.Brush.Style := bsSolid;
|
||||
FBackgroundColorImg.Canvas.FillRect(Rect(0, 0, FChoosed.Width, FChoosed.Height));
|
||||
if Assigned(FOnChangeColor) then
|
||||
FOnChangeColor(Self, FForegroundColor, FBackgroundColor);
|
||||
end;
|
||||
FXLabel.BorderSpacing.Left := round(MARGIN_1 * AXProportion);
|
||||
|
||||
procedure TJvGammaPanel.BoundsChanged;
|
||||
begin
|
||||
Width := 65;
|
||||
Height := 250;
|
||||
if Assigned(FForegroundColorImg) then
|
||||
FForegroundColorImg.BringToFront;
|
||||
FRLabel.BorderSpacing.Left := round(MARGIN_2 * AXProportion);
|
||||
FGLabel.BorderSpacing.Left := round(MARGIN_2 * AXProportion);
|
||||
FBLabel.BorderSpacing.Left := round(MARGIN_2 * AXProportion);
|
||||
FChosen.BorderSpacing.Left := round(MARGIN_1 * AXProportion);
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.DoChangeColor(AForegroundColor, ABackgroundColor: TColor);
|
||||
@ -403,5 +328,100 @@ begin
|
||||
FOnChangeColor(Self, AForegroundColor, ABackgroundColor);
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.Exchange(Sender: TObject);
|
||||
var
|
||||
col: TColor;
|
||||
savedOnChangeColor: TJvChangeColorEvent;
|
||||
begin
|
||||
savedOnChangeColor := FOnChangeColor;
|
||||
FOnChangeColor := nil;
|
||||
|
||||
// exchange colors
|
||||
col := GetForegroundColor;
|
||||
SetForegroundColor(GetBackgroundColor);
|
||||
SetBackgroundColor(col);
|
||||
|
||||
FOnChangeColor := savedOnChangeColor;
|
||||
DoChangeColor(GetForegroundColor, GetBackgroundColor);
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.FgColorClick(Sender: TObject);
|
||||
begin
|
||||
with TColorDialog.Create(Self) do
|
||||
begin
|
||||
if Execute then
|
||||
SetForegroundColor(Color);
|
||||
Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TJvGammaPanel.GetBackgroundColor: TColor;
|
||||
begin
|
||||
Result := FBackgroundColorImg.Brush.Color;
|
||||
end;
|
||||
|
||||
function TJvGammaPanel.GetForegroundColor: TColor;
|
||||
begin
|
||||
Result := FForegroundColorImg.Brush.Color;
|
||||
end;
|
||||
|
||||
function TJvGammaPanel.IsHeightStored: Boolean;
|
||||
begin
|
||||
Result := Height <> Scale96ToFont(DEFAULT_HEIGHT);
|
||||
end;
|
||||
|
||||
function TJvGammaPanel.IsWidthStored: Boolean;
|
||||
begin
|
||||
Result := Width <> Scale96ToFont(DEFAULT_WIDTH);
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.Resize;
|
||||
var
|
||||
imgSize: Integer;
|
||||
p: Integer;
|
||||
m: Integer;
|
||||
hx: Integer;
|
||||
begin
|
||||
inherited;
|
||||
if FPanel3 = nil then
|
||||
exit;
|
||||
|
||||
m := Scale96ToFont(MARGIN_1);
|
||||
if FPanel3.Width > FPanel3.Height then begin
|
||||
imgSize := (FPanel3.ClientHeight - 2*m) div 3 * 2;
|
||||
p := (FPanel3.ClientWidth - imgSize*3 div 2) div 2;
|
||||
FBackgroundColorImg.SetBounds(
|
||||
p + imgSize*3 div 2 - imgSize, FPanel3.ClientHeight - imgSize - m, imgSize, imgSize);
|
||||
FForegroundColorImg.SetBounds(p, m, imgSize, imgSize);
|
||||
FXLabel.Left := FForegroundColorImg.Left;
|
||||
FXLabel.AnchorSideBottom.Control := FPanel3;
|
||||
FXLabel.AnchorSideBottom.Side := asrBottom;
|
||||
FXLabel.Anchors := [akLeft, akBottom];
|
||||
FXLabel.BorderSpacing.Bottom := 0;
|
||||
end else begin
|
||||
imgSize := (FPanel3.ClientWidth - 2*m) div 3 * 2;
|
||||
p := (FPanel3.ClientHeight - imgSize*3 div 2) div 2;
|
||||
FBackgroundColorImg.SetBounds(
|
||||
FPanel3.ClientWidth - imgSize - m, p + imgSize*3 div 2 - imgSize, imgSize, imgSize);
|
||||
FForegroundColorImg.SetBounds(
|
||||
m, p, imgSize, imgSize);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.SetBackgroundColor(const AValue: TColor);
|
||||
begin
|
||||
if GetBackgroundColor = AValue then
|
||||
exit;
|
||||
FBackgroundColorImg.Brush.Color := AValue;
|
||||
DoChangeColor(GetForegroundColor, AValue);
|
||||
end;
|
||||
|
||||
procedure TJvGammaPanel.SetForegroundColor(const AValue: TColor);
|
||||
begin
|
||||
if GetForegroundColor = AValue then
|
||||
exit;
|
||||
FForegroundColorImg.Brush.Color := AValue;
|
||||
DoChangeColor(AValue, GetBackgroundColor);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Reference in New Issue
Block a user