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

📄 teeedigrad.pas

📁 第三方控件:PaintGrid.pas 网格型仪表控件源文件 Mymeter.pas 圆型仪表控件源文件 Project1是这两个控件的使用范例。 该
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{**********************************************}
{  TChartGradient Editor Dialog                }
{  Copyright (c) 1999-2005 by David Berneda    }
{**********************************************}
unit TeeEdiGrad;
{$I TeeDefs.inc}

interface

uses {$IFNDEF LINUX}
     Windows, Messages,
     {$ENDIF}
     SysUtils, Classes,
     {$IFDEF CLX}
     QGraphics, QControls, QForms, QDialogs, QStdCtrls, QExtCtrls, QComCtrls,
     {$ELSE}
     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
     {$ENDIF}
     {$IFDEF LINUX}
     Types,
     {$ENDIF} 
     {$IFDEF D10}
     Types,
     {$ENDIF}
     {$IFDEF LCL}
     Buttons,
     {$ENDIF}
     TeeProcs, TeePenDlg, TeCanvas, TeeGalleryPanel;

type
  TPreviewGradient=class(TCustomTeePanelExtended)
  protected
    Procedure InternalDraw(Const UserRectangle:TRect); override;
  end;

  TTeeGradientEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Label4: TLabel;
    SBBalance: TScrollBar;
    LabelBalance: TLabel;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    LRadialX: TLabel;
    LRadialY: TLabel;
    TrackBar1: TTrackBar;
    TrackBar2: TTrackBar;
    BSwap: TButton;
    BStart: TButtonColor;
    BEnd: TButtonColor;
    BMid: TButtonColor;
    CBMid: TCheckBox;
    Panel1: TPanel;
    BOk: TButton;
    BCancel: TButton;
    Panel2: TPanel;
    CBVisible: TCheckBox;
    Label1: TLabel;
    CBDirection: TComboFlat;
    TabSheet3: TTabSheet;
    Gallery: TListBox;
    Panel3: TPanel;
    Panel4: TPanel;
    Panel5: TPanel;
    Panel6: TPanel;
    Panel7: TPanel;
    TabSheet4: TTabSheet;
    Directions: TChartGalleryPanel;
    procedure CBVisibleClick(Sender: TObject);
    procedure CBDirectionChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure BCancelClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BSwapClick(Sender: TObject);
    procedure CBMidClick(Sender: TObject);
    procedure BMidClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TrackBar1Change(Sender: TObject);
    procedure TrackBar2Change(Sender: TObject);
    procedure SBBalanceChange(Sender: TObject);
    procedure BStartClick(Sender: TObject);
    procedure BEndClick(Sender: TObject);
    procedure GalleryClick(Sender: TObject);
    procedure DirectionsChangeChart(Sender: TObject);
  private
    { Private declarations }
    Backup : TCustomTeeGradient;
    IModified  : Boolean;
    IOnlyStart : Boolean;
    SettingProps : Boolean;
    Preview : TPreviewGradient;

    procedure CheckDirection;
    procedure CheckVisible;
    Function IsRectGradient:Boolean;
    procedure SetDirectionGradients;
  protected
    procedure RefreshControls; virtual;
    procedure SetPreview; virtual;
  public
    { Public declarations }
    TheGradient : TCustomTeeGradient;

    Constructor CreateCustom(AOwner:TComponent; AGradient:TCustomTeeGradient);
    class procedure DefaultGradient(Gradient:TCustomTeeGradient;
                                    IsRectGradient:Boolean; Index:Integer);
    Procedure RefreshGradient(AGradient:TCustomTeeGradient); virtual;
  end;

  TButtonGradient=class(TTeeButton) // 7.05
  private
    Function GetGradient:TCustomTeeGradient;
  protected
    procedure DrawSymbol(ACanvas:TTeeCanvas); override;
  public
    OnlyStart : Boolean;

    procedure Click; override;
    procedure LinkGradient(const Value:TCustomTeeGradient);

    property Gradient:TCustomTeeGradient read GetGradient write LinkGradient;
  end;

Function EditTeeGradient(AOwner:TComponent; AGradient:TCustomTeeGradient):Boolean; overload;
Function EditTeeGradient(AOwner:TComponent; AGradient:TCustomTeeGradient;
                         OnlyStart:Boolean; HideVisible:Boolean=False):Boolean; overload;

Const TeeMaxSampleGradient=16;

implementation

{$IFNDEF CLX}
{$IFNDEF LCL}
{$R *.DFM}
{$ENDIF}
{$ELSE}
{$R *.xfm}
{$ENDIF}

uses {$IFDEF CLR}
     Variants,
     {$ENDIF}
     TeeConst, Math;

Function EditTeeGradient( AOwner:TComponent;
                          AGradient:TCustomTeeGradient):Boolean;
begin
  result:=EditTeeGradient(AOwner,AGradient,False,False);
end;

Function EditTeeGradient( AOwner:TComponent;
                          AGradient:TCustomTeeGradient;
                          OnlyStart:Boolean;
                          HideVisible:Boolean=False):Boolean;
begin
  With TeeCreateForm(TTeeGradientEditor,AOwner) as TTeeGradientEditor do
  try
    Tag:={$IFDEF CLR}Variant{$ELSE}Integer{$ENDIF}(AGradient);
    IOnlyStart:=OnlyStart;

    if IOnlyStart then
    begin
      BEnd.Visible:=False;
      BSwap.Visible:=False;
    end;

    CBVisible.Visible:=not HideVisible;
    result:=ShowModal=mrOk;
  finally
    Free;
  end;
end;

Constructor TTeeGradientEditor.CreateCustom(AOwner:TComponent; AGradient:TCustomTeeGradient);
Begin
  inherited Create(AOwner);
  TheGradient:=AGradient;
  Tag:={$IFDEF CLR}Variant{$ELSE}Integer{$ENDIF}(TheGradient);
  Panel1.Visible:=False;
  BOk.Visible:=False;
  BCancel.Visible:=False;
  Height:=Height-BOk.Height;
end;

procedure TTeeGradientEditor.CheckVisible;
Begin
  EnableControls(IOnlyStart or TheGradient.Visible,
                 [CBDirection,BStart,CBMid,BMid,BEnd,BSwap,Gallery]);
end;

procedure TTeeGradientEditor.CheckDirection;
var tmp : Boolean;
begin
  With TheGradient do
  begin
    tmp:=(Direction=gdFromCenter) or
         (Direction=gdRadial) or
         (Direction=gdFromTopLeft) or
         (Direction=gdFromBottomLeft);
    EnableControls(IOnlyStart or Visible and (not tmp),[CBMid,BMid]);
    EnableControls(Direction=gdRadial,[Label2,Label3,TrackBar1,TrackBar2]);
  end;
end;

procedure TTeeGradientEditor.CBVisibleClick(Sender: TObject);
begin
  IModified:=True;
  TheGradient.Visible:=CBVisible.Checked;
  CheckVisible;
end;

procedure TTeeGradientEditor.CBDirectionChange(Sender: TObject);
begin
  IModified:=True;
  TheGradient.Direction:=TGradientDirection(CBDirection.ItemIndex);
  CheckDirection;

  if not IsRectGradient then Gallery.ItemIndex:=-1;

  SetPreview;

  Directions.SelectChart(Directions[CBDirection.ItemIndex]);
end;

Procedure TTeeGradientEditor.RefreshGradient(AGradient:TCustomTeeGradient);
begin
  SettingProps:=True;
  Tag:={$IFDEF CLR}Variant{$ELSE}Integer{$ENDIF}(AGradient);

  TheGradient:=AGradient;

  if Assigned(TheGradient) then
  begin
    Backup.Free;
    Backup:=TChartGradient.Create(nil);
    Backup.Assign(TheGradient);

    BStart.LinkProperty(TheGradient,'StartColor');
    BMid.LinkProperty(TheGradient,'MidColor');
    BEnd.LinkProperty(TheGradient,'EndColor');

    RefreshControls;

    CheckVisible;
    CheckDirection;
    SetPreview;
  end;

  Directions.SelectChart(Directions[Ord(TheGradient.Direction)]);

  SettingProps:=False;
end;

procedure TTeeGradientEditor.RefreshControls;
begin
  With TheGradient do
  begin
    SBBalance.Position:=Balance;
    CBVisible.Checked:=Visible;
    CBDirection.ItemIndex:=Ord(Direction);
    CBMid.Checked:=MidColor=clNone;
    TrackBar1.Position:=RadialX;
    LRadialX.Caption:=IntToStr(RadialX);
    TrackBar2.Position:=RadialY;
    LRadialY.Caption:=IntToStr(RadialY);
  end;

  BStart.Invalidate;
  BMid.Invalidate;
  BEnd.Invalidate;

  SetDirectionGradients;
end;

procedure TTeeGradientEditor.SetDirectionGradients;
var t : Integer;
begin
  for t:=0 to Directions.Charts.Count-1 do
  with Directions[t].BackWall.Gradient do
  begin
    StartColor:=TheGradient.StartColor;
    MidColor:=TheGradient.MidColor;
    EndColor:=TheGradient.EndColor;
  end;
end;

procedure TTeeGradientEditor.FormShow(Sender: TObject);
begin
  if Assigned(TheGradient) then
     RefreshGradient(TheGradient)
  else
     RefreshGradient(TCustomTeeGradient({$IFDEF CLR}TObject{$ENDIF}(Tag)));

  IModified:=False;
  TeeTranslateControl(Self);
end;

⌨️ 快捷键说明

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