📄 jvqfullcolorctrls.pas
字号:
end;
end;
procedure TJvFullColorComponent.DrawFrame(X, Y: Integer);
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(Rect(0, 0, Width, Y));
Canvas.FillRect(Rect(0, Y + FBuffer.Height, Width, Height));
Canvas.FillRect(Rect(0, Y, X, Y + FBuffer.Height));
Canvas.FillRect(Rect(X + FBuffer.Width, Y, Width, Y + FBuffer.Height));
end;
procedure TJvFullColorComponent.SetFullColor(const Value: TJvFullColor);
var
NewColorID: TJvFullColorSpaceID;
OldColorID: TJvFullColorSpaceID;
OldColor: TJvFullColor;
begin
if Value <> FullColor then
begin
OldColor := FFullColor;
NewColorID := ColorSpaceManager.GetColorSpaceID(Value);
if (NewColorID = csDEF) then
raise EJvFullColorError.CreateFmt(Rs_EUnsupportedColorSpace, [NewColorID]);
OldColorID := ColorSpaceManager.GetColorSpaceID(OldColor);
FFullColor := Value;
if OldColorID <> ColorSpaceManager.GetColorSpaceID(FFullColor) then
ColorSpaceChange;
if Assigned(FOnColorChange) then
FOnColorChange(Self);
end;
end;
procedure TJvFullColorComponent.MouseColor(Shift: TShiftState; X, Y: Integer);
begin
if Assigned(FOnMouseColor) then
FOnMouseColor(Self, X, Y);
end;
procedure TJvFullColorComponent.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
SetFocus;
try
if AutoMouse and (Shift * [ssLeft, ssMiddle, ssRight] <> []) then
MouseColor(Shift, X, Y);
inherited MouseDown(Button, Shift, X, Y);
finally
SetCapture(Handle);
end;
end;
procedure TJvFullColorComponent.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
if AutoMouse and (Shift * [ssLeft, ssMiddle, ssRight] <> []) then
MouseColor(Shift, X, Y);
inherited MouseMove(Shift, X, Y);
end;
procedure TJvFullColorComponent.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
try
inherited MouseUp(Button, Shift, X, Y);
finally
ReleaseCapture;
end;
end;
procedure TJvFullColorComponent.SetAxisConfig(const Value: TJvFullColorAxisConfig);
begin
if FAxisConfig <> Value then
begin
FAxisConfig := Value;
AxisConfigChange;
end;
end;
procedure TJvFullColorComponent.ColorSpaceChange;
begin
CalcSize;
if Assigned(FOnColorSpaceChange) then
FOnColorSpaceChange(Self);
end;
function TJvFullColorComponent.GetColorSpace: TJvColorSpace;
begin
with ColorSpaceManager do
Result := ColorSpace[GetColorSpaceID(FullColor)];
end;
procedure TJvFullColorComponent.AxisConfigChange;
begin
CalcSize;
if Assigned(FOnAxisConfigChange) then
FOnAxisConfigChange(Self);
end;
procedure TJvFullColorComponent.SetWantDrawBuffer(Value: Boolean);
begin
FWantDrawBuffer := Value;
if (Value) and (Width <> 0) and (Height <> 0) then
Invalidate;
end;
procedure TJvFullColorComponent.WMGetDlgCode(var Msg: TWMGetDlgCode);
begin
inherited;
Msg.Result := DLGC_WANTARROWS;
end;
procedure TJvFullColorComponent.DoEnter;
begin
inherited DoEnter;
Invalidate;
end;
procedure TJvFullColorComponent.DoExit;
begin
inherited DoExit;
Invalidate;
end;
procedure TJvFullColorComponent.KeyMove(KeyCode: TJvKeyCode; MoveCount: Integer);
begin
Invalidate;
end;
procedure TJvFullColorComponent.KeyDown(var Key: Word; Shift: TShiftState);
begin
case Key of
VK_LEFT:
KeyMove(kcLeft, 1);
VK_RIGHT:
KeyMove(kcRight, 1);
VK_UP:
KeyMove(kcUp, 1);
VK_DOWN:
KeyMove(kcDown, 1);
end;
end;
procedure TJvFullColorComponent.CMColorChanged(var Msg: TMessage);
begin
inherited;
WantDrawBuffer := True;
end;
procedure TJvFullColorComponent.CMSysColorChange(var Msg: TMessage);
begin
inherited;
WantDrawBuffer := True;
end;
//=== { TColor2D } ===========================================================
constructor TJvFullColorComponent2D.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FValueZ := 0;
FValueZAuto := True;
ColorSpaceChange;
end;
procedure TJvFullColorComponent2D.AxisConfigChange;
begin
UpdateDefaultValueZ;
inherited AxisConfigChange;
end;
procedure TJvFullColorComponent2D.ColorSpaceChange;
begin
UpdateDefaultValueZ;
inherited ColorSpaceChange;
end;
procedure TJvFullColorComponent2D.TrackBarAxisConfigChange(Sender: TObject);
begin
if not FAxisConfigChanging then
begin
FAxisConfigChanging := True;
AxisConfig := (Sender as TJvFullColorTrackBar).AxisConfig;
FAxisConfigChanging := False;
end;
end;
procedure TJvFullColorComponent2D.TrackBarColorChange(Sender: TObject);
begin
if FColorChanging then
Exit;
FColorChanging := True;
FullColor := (Sender as TJvFullColorTrackBar).FullColor;
FColorChanging := False;
if Assigned(FOnColorChange) then
FOnColorChange(Self);
end;
function TJvFullColorComponent2D.IsValueZStored: Boolean;
begin
Result := not ValueZAuto;
end;
procedure TJvFullColorComponent2D.SetValueZ(const Value: Byte);
begin
FValueZAuto := False;
FValueZ := Value;
WantDrawBuffer := True;
end;
procedure TJvFullColorComponent2D.SetValueZAuto(const Value: Boolean);
begin
FValueZAuto := Value;
if Value then
UpdateDefaultValueZ;
WantDrawBuffer := True;
end;
procedure TJvFullColorComponent2D.UpdateDefaultValueZ;
begin
if ValueZAuto then
FValueZ := ColorSpace.AxisDefault[GetIndexAxisZ(AxisConfig)];
end;
//=== { TJvColorPanel } ======================================================
constructor TJvFullColorPanel.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FCrossSize := 5;
FCrossCenter := 1;
FReverseAxisX := False;
FReverseAxisY := False;
FPen := TPen.Create;
FPen.OnChange := PenChange;
FColorChanging := False;
end;
destructor TJvFullColorPanel.Destroy;
begin
ColorTrackBar := nil;
FPen.Free;
inherited Destroy;
end;
procedure TJvFullColorPanel.CalcSize;
begin
FBuffer.Width := Max(Width - 2 * FCrossSize,0);
FBuffer.Height := Max(Height - 2 * FCrossSize,0);
inherited CalcSize;
end;
procedure TJvFullColorPanel.DrawBuffer;
var
AxisX, AxisY: TJvAxisIndex;
IndexX, IndexY: Integer;
MinX, MaxX, MinY, MaxY: Integer;
RangeX, RangeY: Integer;
TempColor: TJvFullColor;
Line: PJvFullColorArray;
begin
if (FBuffer.Width = 0) or (FBuffer.Height = 0) or (Width = 0) or (Height = 0) then
Exit;
AxisX := GetIndexAxisX(AxisConfig);
AxisY := GetIndexAxisY(AxisConfig);
with ColorSpace do
begin
MinX := AxisMin[AxisX];
MaxX := AxisMax[AxisX];
RangeX := MaxX - MinX;
MinY := AxisMin[AxisY];
MaxY := AxisMax[AxisY];
RangeY := MaxY - MinY;
TempColor := SetAxisValue(fclRGBBlack, GetIndexAxisZ(AxisConfig), ValueZ);
with FBuffer do
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(Rect(0, 0, Width-1, Height-1));
for IndexY := 0 to Height-1 do
begin
Line := ScanLine[IndexY];
if ReverseAxisY then
TempColor := SetAxisValue(TempColor, AxisY, MaxY - (RangeY * IndexY) div (Height - 1))
else
TempColor := SetAxisValue(TempColor, AxisY, (RangeY * IndexY) div (Height - 1) + MinY);
for IndexX := 0 to Width-1 do
begin
if ReverseAxisX then
TempColor := SetAxisValue(TempColor, AxisX, MaxX - (RangeX * IndexX) div (Width - 1))
else
TempColor := SetAxisValue(TempColor, AxisX, (RangeX * IndexX) div (Width - 1) + MinX);
// (outchy) don't remove, Bitmap colors are stocked as (MSB) 00RRGGBB (LSB)
// Delphi TColor is (MSB) 00BBGGRR (LSB)
Line[IndexX] := RGBToBGR(ConvertToColor(TempColor));
end;
end;
end;
end;
inherited DrawBuffer;
end;
function TJvFullColorPanel.GetCursorPosition: TPoint;
var
AxisX, AxisY: TJvAxisIndex;
MinAxis, MaxAxis: Integer;
begin
if (FBuffer.Width = 0) or (FBuffer.Height = 0) or (Width = 0) or (Height = 0) then
begin
Result.X := 0;
Result.Y := 0;
end
else
with ColorSpaceManager, ColorSpace[GetColorSpaceID(FullColor)], Result do
begin
AxisX := GetIndexAxisX(AxisConfig);
MinAxis := AxisMin[AxisX];
MaxAxis := AxisMax[AxisX];
X := GetAxisValue(FullColor, AxisX);
if ReverseAxisX then
X := MaxAxis - X
else
X := X - MinAxis;
X := ((X * (FBuffer.Width - 1)) div (MaxAxis-MinAxis)) + CrossSize;
AxisY := GetIndexAxisY(AxisConfig);
MinAxis := AxisMin[AxisY];
MaxAxis := AxisMax[AxisY];
Y := GetAxisValue(FullColor, AxisY);
if ReverseAxisY then
Y := MaxAxis - Y
else
Y := Y - MinAxis;
Y := ((Y * (FBuffer.Height - 1)) div (MaxAxis-MinAxis)) + CrossSize;
end;
end;
procedure TJvFullColorPanel.InvalidateCursor;
var
ARect: TRect;
begin
with GetCursorPosition do
begin
ARect.Left := X - 1 - CrossSize - CrossStyle.Width;
ARect.Right := X + 1 + CrossSize + CrossStyle.Width;
ARect.Top := Y - 1 - CrossSize - CrossStyle.Width;
ARect.Bottom := Y + 1 + CrossSize + CrossStyle.Width;
end;
QWindows.InvalidateRect(Handle, @ARect, False);
end;
procedure TJvFullColorPanel.Paint;
begin
inherited Paint;
with Canvas do
begin
Brush.Color := Color;
DrawFrame(CrossSize, CrossSize);
Draw(CrossSize, CrossSize, FBuffer);
Pen := CrossStyle;
with GetCursorPosition do
begin
MoveTo(X - CrossSize, Y);
LineTo(X - CrossCenter, Y);
MoveTo(X + CrossCenter, Y);
LineTo(X + CrossSize, Y);
MoveTo(X, Y - CrossSize);
LineTo(X, Y - CrossCenter);
MoveTo(X, Y + CrossCenter);
LineTo(X, Y + CrossSize);
end;
end;
DrawFocus;
end;
procedure TJvFullColorPanel.PenChange(Sender: TObject);
begin
Invalidate;
end;
procedure TJvFullColorPanel.SetCrossCenter(Value: Integer);
begin
if Value >= CrossSize then
Value := CrossSize - 1;
if FCrossCenter <> Value then
begin
FCrossCenter := Value;
Invalidate;
end;
end;
procedure TJvFullColorPanel.SetCrossSize(Value: Integer);
begin
if Value < 1 then
Value := 1;
if FCrossCenter >= Value then
FCrossCenter := Value - 1;
if FCrossSize <> Value then
begin
FCrossSize := Value;
CalcSize;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -