tecanvas.pas
来自「Delphi TeeChartPro.6.01的源代码」· PAS 代码 · 共 2,088 行 · 第 1/5 页
PAS
2,088 行
TTeeButton = class(TButton)
private
{$IFNDEF CLX}
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
{$ENDIF}
protected
Instance : TObject;
Info : PPropInfo;
Procedure DrawSymbol(ACanvas:TTeeCanvas); virtual; abstract;
{$IFNDEF CLX}
procedure PaintWindow(DC: HDC); override;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
{$ELSE}
procedure Painting(Sender: QObjectH; EventRegion: QRegionH); override;
{$ENDIF}
public
Procedure LinkProperty(AInstance:TObject; Const PropName:String);
published
{ Published declarations }
property Height default 25;
property Width default 75;
end;
TButtonColor = class(TTeeButton)
private
Function GetTeeColor : TColor;
protected
procedure DrawSymbol(ACanvas:TTeeCanvas); override;
public
GetColorProc : TButtonGetColorProc;
procedure Click; override;
property SymbolColor:TColor read GetTeeColor;
end;
TComboFlat=class(TComboBox)
private
{$IFNDEF CLX}
Inside: Boolean;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure CMFocusChanged(var Message: TCMFocusChanged); message CM_FOCUSCHANGED;
{$ENDIF}
public
Constructor Create(AOwner:TComponent); override;
published
property Style default csDropDownList;
property Height default 21;
property ItemHeight default 13;
end;
{$IFNDEF D5}
procedure FreeAndNil(var Obj);
{$ENDIF}
var IsWindowsNT:Boolean=False;
GetDefaultFontSize:Integer=0;
GetDefaultFontName:String='';
{$IFDEF LINUX}
Function GetRValue(Color:Integer):Byte;
Function GetGValue(Color:Integer):Byte;
Function GetBValue(Color:Integer):Byte;
Function RGB(r,g,b:Integer):TColor;
{$ENDIF}
{$IFDEF CLX}
Function TeeCreatePenSmallDots(AColor:TColor):QPenH;
{$ELSE}
Function TeeCreatePenSmallDots(AColor:TColor):HPen;
{$ENDIF}
Procedure TeeSetTeePen(FPen:TPen; APen:TChartPen; AColor:TColor);
// Converts ABitmap pixels into Gray Scale (levels of gray)
Procedure TeeGrayScale(ABitmap:TBitmap; Inverted:Boolean; AMethod:Integer); { 5.02 }
Function TeePoint(aX,aY:Integer):TPoint; { compatibility with D6 CLX }
function PointInRect(Const Rect:TRect; x,y:Integer):Boolean; { compatibility with D6 CLX }
function TeeRect(Left,Top,Right,Bottom:Integer):TRect; { compatibility with D6 CLX }
Function OrientRectangle(Const R:TRect):TRect;
// Default color depth
Const TeePixelFormat={$IFDEF CLX}pf32Bit{$ELSE}pf24Bit{$ENDIF};
{$IFDEF CLX}
type
TRGBTriple=packed record
rgbtBlue : Byte;
rgbtGreen : Byte;
rgbtRed : Byte;
rgbtAlpha : Byte; // Linux ?
end;
{$ENDIF}
Function RGBValue(Color:TColor):TRGBTriple;
{ Show the TColorDialog, return new color if changed }
Function EditColor(AOwner:TComponent; AColor:TColor):TColor;
{ Show the TColorDialog, return True if color changed }
Function EditColorDialog(AOwner:TComponent; var AColor:TColor):Boolean;
// Returns point "ATo" minus ADist pixels from AFrom point.
Function PointAtDistance(AFrom,ATo:TPoint; ADist:Integer):TPoint;
// Returns True when 3 first points in P are "face-viewing".
Function TeeCull(const P:TFourPoints):Boolean; overload;
Function TeeCull(const P0,P1,P2:TPoint):Boolean; overload;
// Returns Sqrt( Sqr(x)+Sqr(y) )
Function TeeDistance(x,y:Integer):Double;
{ Used at EditColor function, for the Color Editor dialog }
var TeeCustomEditColors:TStrings=nil;
{$IFNDEF CLX}
TeeFontAntiAlias:Integer=ANTIALIASED_QUALITY;
{$ENDIF}
implementation
Uses {$IFDEF CLX}
QForms, QDialogs,
{$ELSE}
Forms, Dialogs,
{$ENDIF}
Math,
{$IFNDEF CLX}
{$IFDEF D6}
Types,
{$ENDIF}
{$ENDIF}
TeeConst;
type PPoints = ^TPoints;
TPoints = Array[0..0] of TPoint;
{$IFNDEF CLX}
var WasOldRegion : Boolean=False;
OldRegion : HRgn=0;
{$ENDIF}
Function TeeCull(const P:TFourPoints):Boolean;
begin
result:=TeeCull(P[0],P[1],P[2]);
end;
Function TeeCull(const P0,P1,P2:TPoint):Boolean;
begin
result:=( ((P0.x-P1.x) * (P2.y-P1.y)) -
((P2.x-P1.x) * (P0.y-P1.y))
) < 0;
end;
Function TeePoint(aX,aY:Integer):TPoint;
begin
with result do
begin
X:=aX;
Y:=aY;
end;
end;
function PointInRect(Const Rect:TRect; x,y:Integer):Boolean;
begin
result:=(x>=Rect.Left) and (y>=Rect.Top) and (x<Rect.Right) and (y<Rect.Bottom);
end;
function TeeRect(Left,Top,Right,Bottom:Integer):TRect;
begin
result.Left :=Left;
result.Top :=Top;
result.Bottom:=Bottom;
result.Right :=Right;
end;
// Makes sure the R rectangle Left is smaller than Right and
// Top is smaller than Bottom. Returns corrected rectangle.
Function OrientRectangle(Const R:TRect):TRect;
begin
result:=R;
with result do
begin
if Left>Right then SwapInteger(Left,Right);
if Top>Bottom then SwapInteger(Top,Bottom);
end;
end;
Function Point3D(x,y,z:Integer):TPoint3D;
begin
result.x:=x;
result.y:=y;
result.z:=z;
end;
Procedure RectSize(Const R:TRect; Var RectWidth,RectHeight:Integer);
begin
With R do
begin
RectWidth :=Right-Left;
RectHeight:=Bottom-Top;
end;
end;
Procedure RectCenter(Const R:TRect; Var X,Y:Integer);
begin
With R do
begin
X:=(Left+Right) div 2;
Y:=(Top+Bottom) div 2;
end;
end;
{ TChartPen }
Constructor TChartPen.Create(OnChangeEvent:TNotifyEvent);
begin
inherited Create;
FVisible:=True;
DefaultVisible:=True;
DefaultEnd:=esRound;
OnChange:=OnChangeEvent;
{$IFDEF CLX}
ReleaseHandle;
Width:=1;
{$ENDIF}
end;
Procedure TChartPen.Assign(Source:TPersistent);
begin
if Source is TChartPen then
begin
FVisible :=TChartPen(Source).Visible;
FSmallDots:=TChartPen(Source).SmallDots;
FEndStyle :=TChartPen(Source).EndStyle; { 5.01 }
end;
{$IFDEF CLX}
if not Assigned(Handle) then ReleaseHandle;
{$ENDIF}
inherited;
end;
Function TChartPen.IsEndStored:Boolean;
begin
result:=FEndStyle<>DefaultEnd;
end;
Function TChartPen.IsVisibleStored:Boolean;
begin
result:=FVisible<>DefaultVisible;
end;
procedure TChartPen.SetEndStyle(const Value: TPenEndStyle);
begin
if FEndStyle<>Value then
begin
FEndStyle:=Value;
Changed;
end;
end;
Procedure TChartPen.SetSmallDots(Value:Boolean);
begin
if FSmallDots<>Value then
begin
FSmallDots:=Value;
Changed;
end;
end;
Procedure TChartPen.SetVisible(Value:Boolean);
Begin
if FVisible<>Value then
begin
FVisible:=Value;
Changed;
end;
end;
{ TChartHiddenPen }
Constructor TChartHiddenPen.Create(OnChangeEvent:TNotifyEvent);
Begin
inherited;
FVisible:=False;
DefaultVisible:=False;
end;
{ TDottedGrayPen }
Constructor TDottedGrayPen.Create(OnChangeEvent:TNotifyEvent);
Begin
inherited;
Color:=clGray;
Style:=psDot;
end;
{ TDarkGrayPen }
Constructor TDarkGrayPen.Create(OnChangeEvent:TNotifyEvent);
Begin
inherited;
Color:=clDkGray;
end;
{ TChartAxisPen }
Constructor TChartAxisPen.Create(OnChangeEvent:TNotifyEvent);
Begin
inherited;
Width:=2;
end;
{ TChartBrush }
Constructor TChartBrush.Create(OnChangeEvent:TNotifyEvent);
Begin
inherited Create;
Color:=clDefault;
OnChange:=OnChangeEvent;
end;
Destructor TChartBrush.Destroy;
begin
FImage.Free;
inherited;
end;
Procedure TChartBrush.Assign(Source:TPersistent);
begin
if Source is TChartBrush then
Image.Assign(TChartBrush(Source).FImage);
inherited;
end;
procedure TChartBrush.SetImage(Value: TPicture);
begin
if Assigned(Value) then Image.Assign(Value)
else FreeAndNil(FImage);
end;
Function TChartBrush.GetImage:TPicture;
begin
if not Assigned(FImage) then
begin
FImage:=TPicture.Create;
FImage.OnChange:=OnChange;
end;
result:=FImage;
end;
{ TView3DOptions }
Constructor TView3DOptions.Create(AParent:TWinControl);
begin
inherited Create;
FParent :=AParent;
FOrthogonal :=True;
FOrthoAngle :=45;
FZoom :=100; { % }
FZoomText :=True;
FRotation :=345;
FElevation :=345;
FPerspective :=TeeDefaultPerspective; { % }
end;
Procedure TView3DOptions.Repaint;
begin
FParent.Invalidate;
end;
Procedure TView3DOptions.SetIntegerProperty(Var Variable:Integer; Value:Integer);
begin
if Variable<>Value then
begin
Variable:=Value;
Repaint;
end;
end;
Procedure TView3DOptions.SetBooleanProperty(Var Variable:Boolean; Value:Boolean);
begin
if Variable<>Value then
begin
Variable:=Value;
Repaint;
end;
end;
Procedure TView3DOptions.SetElevation(Value:Integer);
begin
SetIntegerProperty(FElevation,Value);
end;
Procedure TView3DOptions.SetPerspective(Value:Integer);
begin
SetIntegerProperty(FPerspective,Value);
end;
Procedure TView3DOptions.SetRotation(Value:Integer);
begin
SetIntegerProperty(FRotation,Value);
end;
Procedure TView3DOptions.SetTilt(Value:Integer);
begin
SetIntegerProperty(FTilt,Value);
end;
Procedure TView3DOptions.SetHorizOffset(Value:Integer);
begin
if FHorizOffset<>Value then
begin
FHorizOffset:=Value;
Repaint;
if Assigned(FOnScrolled) then FOnScrolled(True);
end;
end;
Procedure TView3DOptions.SetVertOffset(Value:Integer);
begin
if FVertOffset<>Value then
begin
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?