⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvfullcolorcircleform.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: ColorCircleFrm.pas, released on 2004-10-11.

The Initial Developer of the Original Code is Florent Ouchet [ouchet dott florent att laposte dott net]
Portions created by Florent Ouchet are Copyright (C) 2004 Florent Ouchet.
All Rights Reserved.

Contributor(s): -

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvFullColorCircleForm.pas,v 1.8 2005/03/09 07:25:04 marquardt Exp $

unit JvFullColorCircleForm;

{$I jvcl.inc}

interface

uses
  {$IFDEF UNITVERSIONING}
  JclUnitVersioning,
  {$ENDIF UNITVERSIONING}
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  ExtCtrls, StdCtrls, Mask, 
  JvFullColorDialogs, JvFullColorCtrls, JvFullColorSpaces, JvFullColorRotate,
  JvExMask, JvSpin;

type
  TJvFullColorCircleFrm = class(TForm)
    JvColorCircle: TJvFullColorCircle;
    RadioButtonCommonSettings: TRadioButton;
    RadioButtonAxisSettings: TRadioButton;
    PanelAxisSettings: TPanel;
    PanelCommonSettings: TPanel;
    ImageOld: TImage;
    ImageNew: TImage;
    JvFullColorTrackBarCommon: TJvFullColorTrackBar;
    JvFullColorTrackBarBlue: TJvFullColorTrackBar;
    JvFullColorTrackBarGreen: TJvFullColorTrackBar;
    JvFullColorTrackBarRed: TJvFullColorTrackBar;
    SpinEditComAxis0: TJvSpinEdit;
    SpinEditRedAxis0: TJvSpinEdit;
    SpinEditGreenAxis0: TJvSpinEdit;
    SpinEditBlueAxis0: TJvSpinEdit;
    SpinEditComAxis1: TJvSpinEdit;
    SpinEditComAxis2: TJvSpinEdit;
    SpinEditRedAxis1: TJvSpinEdit;
    SpinEditRedAxis2: TJvSpinEdit;
    SpinEditGreenAxis1: TJvSpinEdit;
    SpinEditGreenAxis2: TJvSpinEdit;
    SpinEditBlueAxis1: TJvSpinEdit;
    SpinEditBlueAxis2: TJvSpinEdit;
    LabelOld: TLabel;
    LabelNew: TLabel;
    LabelColorSpace: TLabel;
    LabelAxisSettings: TLabel;
    LabelComAxis0: TLabel;
    LabelComAxis1: TLabel;
    LabelComAxis2: TLabel;
    LabelAxis0: TLabel;
    LabelAxis1: TLabel;
    LabelAxis2: TLabel;
    LabelCommon: TLabel;
    LabelRed: TLabel;
    LabelGreen: TLabel;
    LabelBlue: TLabel;
    PanelGraphics: TPanel;
    ButtonGraphics: TButton;
    ButtonCancel: TButton;
    ButtonOK: TButton;
    ButtonApply: TButton;
    CheckBoxCom0: TCheckBox;
    CheckBoxCom1: TCheckBox;
    CheckBoxCom2: TCheckBox;
    CheckBoxRed0: TCheckBox;
    CheckBoxRed1: TCheckBox;
    CheckBoxRed2: TCheckBox;
    CheckBoxGreen0: TCheckBox;
    CheckBoxGreen1: TCheckBox;
    CheckBoxGreen2: TCheckBox;
    CheckBoxBlue0: TCheckBox;
    CheckBoxBlue1: TCheckBox;
    CheckBoxBlue2: TCheckBox;
    BevelOld: TBevel;
    BevelNew: TBevel;
    JvColorSpaceCombo: TJvFullColorSpaceCombo;
    JvColorAxisConfigCombo: TJvFullColorAxisCombo;
    procedure FormCreate(Sender: TObject);
    procedure ButtonGraphicsClick(Sender: TObject);
    procedure ButtonApplyClick(Sender: TObject);
    procedure JvColorSpaceComboChange(Sender: TObject);
    procedure CheckBoxSettingsClick(Sender: TObject);
    procedure JvColorCircleBlueColorChange(Sender: TObject);
    procedure JvColorCircleColorChange(Sender: TObject);
    procedure JvColorCircleGreenColorChange(Sender: TObject);
    procedure JvColorCircleRedColorChange(Sender: TObject);
    procedure JvColorAxisConfigComboChange(Sender: TObject);
    procedure JvColorCircleColorSpaceChange(Sender: TObject);
    procedure RadioButtonAxisClick(Sender: TObject);
    procedure SpinEditSettingsValueChange(Sender: TObject);
  private
    FExpanded: Boolean;
    FUpdating: Boolean;
    FExpandedWidth: Integer;
    FDelta: TJvColorDelta;
    FOnApply: TNotifyEvent;
    FOptions: TJvFullColorCircleDialogOptions;
    FRedAxis: array [TJvAxisIndex] of Byte;
    FGreenAxis: array [TJvAxisIndex] of Byte;
    FBlueAxis: array [TJvAxisIndex] of Byte;
    FComAxis: array [TJvAxisIndex] of Byte;
    FAxisMin: array [TJvAxisIndex] of Byte;
    FAxisMax: array [TJvAxisIndex] of Byte;
    FSpinEditComAxes: array [TJvAxisIndex] of TJvSpinEdit;
    FSpinEditRedAxes: array [TJvAxisIndex] of TJvSpinEdit;
    FSpinEditGreenAxes: array [TJvAxisIndex] of TJvSpinEdit;
    FSpinEditBlueAxes: array [TJvAxisIndex] of TJvSpinEdit;
    FLabelComAxes: array [TJvAxisIndex] of TLabel;
    FLabelAxes: array [TJvAxisIndex] of TLabel;
    FCheckBoxCom: array [TJvAxisIndex] of TCheckBox;
    FCheckBoxRed: array [TJvAxisIndex] of TCheckBox;
    FCheckBoxGreen: array [TJvAxisIndex] of TCheckBox;
    FCheckBoxBlue: array [TJvAxisIndex] of TCheckBox;
    FFilled: Boolean;
    procedure FillInternalArrays;
  protected
    procedure Loaded; override;
    function GetRedDelta: TJvAxisDelta;
    function GetGreenDelta: TJvAxisDelta;
    function GetBlueDelta: TJvAxisDelta;
    function GetColorID: TJvFullColorSpaceID;
    procedure SetOptions(const Value: TJvFullColorCircleDialogOptions);
    procedure SetRedDelta(const Value: TJvAxisDelta);
    procedure SetGreenDelta(const Value: TJvAxisDelta);
    procedure SetBlueDelta(const Value: TJvAxisDelta);
    procedure SetColorID(const Value: TJvFullColorSpaceID);
    procedure SetDelta(const Value: TJvColorDelta); 
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;

    procedure UpdateDeltaValue;
    procedure CalcDeltaValue(ARotateColor: TJvRotateColor);
    procedure UpdateColorSpace;
    procedure UpdateCheckBoxStates;
    procedure UpdateAxisSettings;
    procedure Expand;
    procedure Collapse;

    property Expanded: Boolean read FExpanded;
    property Options: TJvFullColorCircleDialogOptions read FOptions write SetOptions;
    property RedDelta: TJvAxisDelta read GetRedDelta write SetRedDelta;
    property GreenDelta: TJvAxisDelta read GetGreenDelta write SetGreenDelta;
    property BlueDelta: TJvAxisDelta read GetBlueDelta write SetBlueDelta;
    property ColorID: TJvFullColorSpaceID read GetColorID write SetColorID;
    property Delta: TJvColorDelta read FDelta write SetDelta;
    property OnApply: TNotifyEvent read FOnApply write FOnApply;
  end;

{$IFDEF UNITVERSIONING}
const
  UnitVersioning: TUnitVersionInfo = (
    RCSfile: '$RCSfile: JvFullColorCircleForm.pas,v $';
    Revision: '$Revision: 1.8 $';
    Date: '$Date: 2005/03/09 07:25:04 $';
    LogPath: 'JVCL\run'
    );
{$ENDIF UNITVERSIONING}

implementation

uses
  JvResources,
  TypInfo,
  {$IFDEF COMPILER5}
  JclMath,   // For EnsureRange
  JvJCLUtils,   // for TryStrToInt
  {$ENDIF COMPILER5}
  Math;

{$R *.dfm}

var
  GlobalLoop, GlobalRange: string;

function AxisIndexFromTag(ATag: Integer): TJvAxisIndex;
begin
  Result := TJvAxisIndex(ATag and $03);
end;

//=== { TJvFullColorCircleForm } =============================================

constructor TJvFullColorCircleFrm.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FDelta := TJvColorDelta.Create;
end;

destructor TJvFullColorCircleFrm.Destroy;
begin
  FDelta.Free;
  inherited Destroy;
end;

function TJvFullColorCircleFrm.GetBlueDelta: TJvAxisDelta;
begin
  Result := FDelta.AxisBlue;
end;

function TJvFullColorCircleFrm.GetColorID: TJvFullColorSpaceID;
begin
  Result := FDelta.ColorID;
end;

function TJvFullColorCircleFrm.GetGreenDelta: TJvAxisDelta;
begin
  Result := FDelta.AxisGreen;
end;

function TJvFullColorCircleFrm.GetRedDelta: TJvAxisDelta;
begin
  Result := FDelta.AxisRed;
end;

procedure TJvFullColorCircleFrm.FormCreate(Sender: TObject);
begin
  Options := JvDefaultColorCircleDialogOptions - [coShowSaturation];
  JvColorAxisConfigCombo.Selected := JvColorCircle.AxisConfig;
end;

procedure TJvFullColorCircleFrm.FillInternalArrays;
begin
  if not FFilled then
  begin
    FSpinEditComAxes[axIndex0] := SpinEditComAxis0;
    FSpinEditComAxes[axIndex1] := SpinEditComAxis1;
    FSpinEditComAxes[axIndex2] := SpinEditComAxis2;
    FSpinEditRedAxes[axIndex0] := SpinEditRedAxis0;
    FSpinEditRedAxes[axIndex1] := SpinEditRedAxis1;
    FSpinEditRedAxes[axIndex2] := SpinEditRedAxis2;
    FSpinEditGreenAxes[axIndex0] := SpinEditGreenAxis0;
    FSpinEditGreenAxes[axIndex1] := SpinEditGreenAxis1;
    FSpinEditGreenAxes[axIndex2] := SpinEditGreenAxis2;
    FSpinEditBlueAxes[axIndex0] := SpinEditBlueAxis0;
    FSpinEditBlueAxes[axIndex1] := SpinEditBlueAxis1;
    FSpinEditBlueAxes[axIndex2] := SpinEditBlueAxis2;
    FLabelComAxes[axIndex0] := LabelComAxis0;
    FLabelComAxes[axIndex1] := LabelComAxis1;
    FLabelComAxes[axIndex2] := LabelComAxis2;
    FLabelAxes[axIndex0] := LabelAxis0;
    FLabelAxes[axIndex1] := LabelAxis1;
    FLabelAxes[axIndex2] := LabelAxis2;
    FCheckBoxCom[axIndex0] := CheckBoxCom0;
    FCheckBoxCom[axIndex1] := CheckBoxCom1;
    FCheckBoxCom[axIndex2] := CheckBoxCom2;
    FCheckBoxRed[axIndex0] := CheckBoxRed0;
    FCheckBoxRed[axIndex1] := CheckBoxRed1;
    FCheckBoxRed[axIndex2] := CheckBoxRed2;
    FCheckBoxGreen[axIndex0] := CheckBoxGreen0;
    FCheckBoxGreen[axIndex1] := CheckBoxGreen1;
    FCheckBoxGreen[axIndex2] := CheckBoxGreen2;
    FCheckBoxBlue[axIndex0] := CheckBoxBlue0;
    FCheckBoxBlue[axIndex1] := CheckBoxBlue1;
    FCheckBoxBlue[axIndex2] := CheckBoxBlue2;
    FFilled := True;
  end;
end;

procedure TJvFullColorCircleFrm.Loaded;
begin
  inherited Loaded;
  FExpandedWidth := Width;
end;

procedure TJvFullColorCircleFrm.Collapse;
begin
  Width := PanelGraphics.Left - 1;
  PanelGraphics.Visible := False;
  ButtonGraphics.Caption := RsCollapsedCaption;
  FExpanded := False;
end;

procedure TJvFullColorCircleFrm.Expand;
begin
  Width := FExpandedWidth;
  PanelGraphics.Visible := True;
  ButtonGraphics.Caption := RsExpandedCaption;
  FExpanded := True;
end;

procedure TJvFullColorCircleFrm.SetOptions(const Value: TJvFullColorCircleDialogOptions);
var
  I: TJvAxisIndex;
  EnabledA, EnabledB: Boolean;
  LVisible: Boolean;

  procedure UpdateCheckBox(ACheckBox: TCheckBox);
  begin
    ACheckBox.Visible := EnabledA;
    ACheckBox.Checked := EnabledB;
  end;

begin
  FOptions := Value;
  FillInternalArrays;

  if coFullOpen in Options then
    Expand
  else
    Collapse;

  ButtonGraphics.Enabled := not (coPreventExpand in Options);

  ButtonApply.Visible := (coShowApply in Options);

  if coShowHelp in Options then
    BorderIcons := BorderIcons + [biHelp]
  else
    BorderIcons := BorderIcons - [biHelp];

  EnabledA := coAllowSpaceChange in Options;
  LabelColorSpace.Enabled := EnabledA;
  JvColorSpaceCombo.Enabled := EnabledA;

  LVisible := coShowOldPreview in Options;
  ImageOld.Visible := LVisible;
  LabelOld.Visible := LVisible;

  LVisible := coShowNewPreview in Options;
  ImageNew.Visible := LVisible;
  LabelNew.Visible := LVisible;

  EnabledA := coShowSaturation in Options;
  EnabledB := coDefaultRange in Options;

  for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do
  begin
    UpdateCheckBox(FCheckBoxCom[I]);
    UpdateCheckBox(FCheckBoxRed[I]);
    UpdateCheckBox(FCheckBoxGreen[I]);
    UpdateCheckBox(FCheckBoxBlue[I]);
  end;

  if RadioButtonCommonSettings.Enabled and RadioButtonAxisSettings.Enabled then
    RadioButtonAxisSettings.Checked := True;

  UpdateAxisSettings;
  UpdateCheckBoxStates;
  UpdateColorSpace;
end;

procedure TJvFullColorCircleFrm.UpdateColorSpace;
var
  I: TJvAxisIndex;
  LCaption: string;
  LColor: TJvFullColor;
begin
  if FUpdating then
    Exit;
  FillInternalArrays;

  FUpdating := True;

  with JvColorSpaceCombo.SelectedSpace do
  begin
    SetColorID(ID);
    JvColorAxisConfigCombo.ColorID := ID;

    for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do
    begin
      LCaption := AxisName[I];
      FLabelComAxes[I].Caption := LCaption;
      FLabelAxes[I].Caption := LCaption;

      FAxisMax[I] := AxisMax[I];
      FAxisMin[I] := AxisMin[I];
      FSpinEditComAxes[I].MaxValue := FAxisMax[I];
      FSpinEditComAxes[I].MinValue := -FAxisMax[I];
      FSpinEditRedAxes[I].MaxValue := FAxisMax[I];
      FSpinEditRedAxes[I].MinValue := -FAxisMax[I];
      FSpinEditGreenAxes[I].MaxValue := FAxisMax[I];
      FSpinEditGreenAxes[I].MinValue := -FAxisMax[I];
      FSpinEditBlueAxes[I].MaxValue := FAxisMax[I];
      FSpinEditBlueAxes[I].MinValue := -FAxisMax[I];

      LColor := ConvertFromColor(clRed);
      FRedAxis[I] := GetAxisValue(LColor, I);

      LColor := ConvertFromColor(clLime);
      FGreenAxis[I] := GetAxisValue(LColor, I);

      LColor := ConvertFromColor(clBlue);
      FBlueAxis[I] := GetAxisValue(LColor, I);

      LColor := ConvertFromColor(clDkGray);
      FComAxis[I] := GetAxisValue(LColor, I);
    end;

    JvColorCircle.ConvertToID(ID shl 24);

    FUpdating := False;
  end;
  CalcDeltaValue(rcRed);
  CalcDeltaValue(rcGreen);
  CalcDeltaValue(rcBlue);
end;

procedure TJvFullColorCircleFrm.UpdateDeltaValue;
var
  I: TJvAxisIndex;
  ComAxis: array [TJvAxisIndex] of Integer;
  LColorID: TJvFullColorSpaceID;
  ARedColor, AGreenColor, ABlueColor, ACommonColor: TJvFullColor;

  function CheckRange(Value: Integer; AMin: Byte; AMax: Byte): Byte;
  begin
    while Value < AMin do
      Inc(Value, AMax - AMin + 1);
    while Value > AMax do
      Dec(Value, AMax - AMin + 1);
    Result := Value;
  end;

begin
  if FUpdating then
    Exit;
  FillInternalArrays;

  FUpdating := True;

  for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do
  begin
    ComAxis[I] := (RedDelta[I].Value + GreenDelta[I].Value + BlueDelta[I].Value) div 3;
    FSpinEditRedAxes[I].Value := RedDelta[I].Value;
    FSpinEditGreenAxes[I].Value := GreenDelta[I].Value;
    FSpinEditBlueAxes[I].Value := BlueDelta[I].Value;
    FSpinEditComAxes[I].Value := ComAxis[I];
  end;

  LColorID := JvColorSpaceCombo.ColorSpaceID;

  ACommonColor := LColorID shl 24;
  ARedColor := LColorID shl 24;
  AGreenColor := LColorID shl 24;
  ABlueColor := LColorID shl 24;
  for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do
  begin
    ARedColor := ARedColor or
      (CheckRange(RedDelta[I].Value + FRedAxis[I], FAxisMin[I], FAxisMax[I]) shl (Ord(I)*8));
    AGreenColor := AGreenColor or
      (CheckRange(GreenDelta[I].Value + FGreenAxis[I], FAxisMin[I], FAxisMax[I]) shl (Ord(I)*8));
    ABlueColor := ABlueColor or
      (CheckRange(BlueDelta[I].Value + FBlueAxis[I], FAxisMin[I], FAxisMax[I]) shl (Ord(I)*8));
    ACommonColor := ACommonColor or
      (CheckRange(ComAxis[I] + FComAxis[I], FAxisMin[I], FAxisMax[I]) shl (Ord(I)*8));
  end;

  JvColorCircle.FullColor := ACommonColor;
  JvColorCircle.RedColor := ARedColor;
  JvColorCircle.GreenColor := AGreenColor;
  JvColorCircle.BlueColor := ABlueColor;

  FUpdating := False;
end;

procedure TJvFullColorCircleFrm.RadioButtonAxisClick(Sender: TObject);
begin
  UpdateAxisSettings;
end;

procedure TJvFullColorCircleFrm.UpdateAxisSettings;
var
  I: TJvAxisIndex;
  LColor: TColor;
  EnabledA, EnabledB: Boolean;
begin
  FillInternalArrays;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -