📄 teegdiplus.pas
字号:
EndAngle:=ArcTan2(YC-Y4,X4-XC);
if EndAngle<0 then
EndAngle:=EndAngle+2.0*Pi;
EndAngle:=EndAngle*HalfDivPi;
end;
procedure TGDIPlusCanvas.Arc(const Left, Top, Right, Bottom, StartX, StartY, EndX, EndY: Integer);
var StartAngle : Single;
EndAngle : Single;
begin
if Pen.Style<>psClear then
begin
CalcArcAngles(Left,Top,Right,Bottom,StartX,StartY,EndX,EndY,StartAngle,EndAngle);
FGraphics.DrawArc(GPen,Left,Top,Right-Left,Bottom-Top,StartAngle,EndAngle-StartAngle);
end;
end;
procedure TGDIPlusCanvas.Ellipse(X1, Y1, X2, Y2: Integer);
begin
if Brush.Style<>bsClear then
FGraphics.FillEllipse(GBrush,X1,Y1,X2-X1,Y2-Y1);
if Pen.Style<>psClear then
FGraphics.DrawEllipse(GPen,X1,Y1,X2-X1,Y2-Y1);
end;
procedure TGDIPlusCanvas.FillRect(const Rect: TRect);
begin
if Brush.Style<>bsClear then
FGraphics.FillRectangle(GBrush,MakeRect(Rect));
end;
Procedure TGDIPlusCanvas.Line(X0,Y0,X1,Y1:Integer);
begin
FGraphics.DrawLine(GPen,X0,Y0,X1,Y1);
end;
procedure TGDIPlusCanvas.LineTo(X,Y:Integer);
begin
FGraphics.DrawLine(GPen,FX,FY,X,Y);
end;
procedure TGDIPlusCanvas.LineTo3D(X,Y,Z:Integer);
begin
Calc3DPos(x,y,z);
LineTo(x,y);
end;
procedure TGDIPlusCanvas.MoveTo(X,Y:Integer);
begin
FX:=X;
FY:=Y;
end;
procedure TGDIPlusCanvas.MoveTo3D(X,Y,Z:Integer);
begin
Calc3DPos(x,y,z);
FX:=X;
FY:=Y;
FZ:=Z;
end;
procedure TGDIPlusCanvas.Rectangle(X0,Y0,X1,Y1:Integer);
begin
Dec(X1);
Dec(Y1);
if Brush.Style<>bsClear then
FGraphics.FillRectangle(GBrush,X0,Y0,X1-X0,Y1-Y0);
if Pen.Style<>psClear then
FGraphics.DrawRectangle(GPen,X0,Y0,X1-X0,Y1-Y0);
end;
procedure TGDIPlusCanvas.RoundRect(X1,Y1,X2,Y2,X3,Y3:Integer);
var dx,dy,
offX,offY : Integer;
tmp : TGPGraphicsPath;
begin
dx := (x2 - x1);
dy := (y2 - y1);
offX := X3 div 2;
X3 := offX * 2;
offY := Y3 div 2;
Y3 := offY * 2;
if (X3> Abs(dx)) or (Y3 > Abs(dy)) then
Ellipse(x1, y1, x2, y2)
else
begin
tmp:=TGPGraphicsPath.Create;
try
tmp.AddLine(x1+offX, y1, x2-offX, y1);
tmp.AddArc(x2-X3, y1, x3, Y3, 270, 90);
tmp.AddLine(x2, y1+offY, x2, y2-offY);
tmp.AddArc(x2-X3, y2-Y3, x3, y3, 0, 90);
tmp.AddLine(x2-offX, y2, x1+offX, y2);
tmp.AddArc(x1, y2-Y3, X3, y3, 90, 90);
tmp.AddLine(x1, y2-offY, x1, y1+offY);
tmp.AddArc(x1, y1, X3, Y3, 180, 90);
if Brush.Style<>bsClear then
FGraphics.FillPath(GBrush,tmp);
if Pen.Style<>psClear then
FGraphics.DrawPath(GPen,tmp);
finally
tmp.Free;
end;
end;
end;
function MakePoints(const Points:Array of TPoint):PGPPoint;
begin
result:=@Points[0];
end;
Procedure TGDIPlusCanvas.Polygon(const Points:Array of TPoint);
begin
if Brush.Style<>bsClear then
FGraphics.FillPolygon(GBrush,MakePoints(Points),Length(Points));
if Pen.Style<>psClear then
FGraphics.DrawPolygon(GPen,MakePoints(Points),Length(Points));
end;
{$IFDEF D5}
Procedure TGDIPlusCanvas.Polyline(const Points:Array of TPoint);
begin
if Pen.Style<>psClear then
FGraphics.DrawLines(GPen,MakePoints(Points),Length(Points));
end;
{$ENDIF}
Procedure TGDIPlusCanvas.TextOut(X,Y:Integer; const Text:String);
function GFont:TGPFont;
var tmpFontStyle : TFontStyle;
begin
FGPFont.Free;
tmpFontStyle:=0;
if fsBold in Font.Style then
if fsItalic in Font.Style then
tmpFontStyle:=FontStyleBoldItalic
else
tmpFontStyle:=FontStyleBold;
if fsUnderline in Font.Style then
tmpFontStyle:=tmpFontStyle or FontStyleUnderline;
if fsStrikeOut in Font.Style then
tmpFontStyle:=tmpFontStyle or FontStyleStrikeout;
FGPFont:=TGPFont.Create(Font.Name,Font.Size,tmpFontStyle);
result:=FGPFont;
end;
function GFontBrush:TGPBrush;
begin
result:=TGPSolidBrush.Create(GDIPColor(Font.Color));
end;
var Origin : TGPPointF;
tmp : Integer;
begin
tmp:=TextAlign;
if tmp>=TA_BOTTOM then
begin
Dec(Y,TextHeight(Text));
Dec(tmp,TA_BOTTOM);
end;
if tmp=TA_RIGHT then
Dec(X,TextWidth(Text))
else
if tmp=TA_CENTER then
Dec(X,TextWidth(Text) div 2);
Origin.X:=X-2;
Origin.Y:=Y;
FGraphics.DrawString(Text,Length(Text),GFont,Origin,GFontBrush);
end;
Procedure TGDIPlusCanvas.HorizLine3D(Left,Right,Y,Z:Integer);
var tmpY : Integer;
begin
tmpY:=Y;
Calc3DPos(Left,tmpY,Z);
Calc3DPos(Right,Y,Z);
FGraphics.DrawLine(GPen,Left,tmpY,Right,Y);
end;
Procedure TGDIPlusCanvas.LineWithZ(X0,Y0,X1,Y1,Z:Integer);
begin
Calc3DPos(X0,Y0,Z);
Calc3DPos(X1,Y1,Z);
FGraphics.DrawLine(GPen,X0,Y0,X1,Y1);
end;
procedure TGDIPlusCanvas.UnClipRectangle;
begin
FGraphics.SetClip(MakeRect(Bounds));
inherited;
end;
Procedure TGDIPlusCanvas.VertLine3D(X,Top,Bottom,Z:Integer);
var tmpX : Integer;
begin
tmpX:=X;
Calc3DPos(tmpX,Top,Z);
Calc3DPos(X,Bottom,Z);
FGraphics.DrawLine(GPen,tmpX,Top,X,Bottom);
end;
Procedure TGDIPlusCanvas.ZLine3D(X,Y,Z0,Z1:Integer);
var tmpX : Integer;
tmpY : Integer;
begin
tmpX:=X;
tmpY:=Y;
Calc3DPos(tmpX,tmpY,Z0);
Calc3DPos(X,Y,Z1);
FGraphics.DrawLine(GPen,tmpX,tmpY,X,Y);
end;
procedure TGDIPlusCanvas.SetPixel(X, Y: Integer; Value: TColor);
begin
FGraphics.DrawLine(GPen,X,Y,X,Y);
end;
procedure TGDIPlusCanvas.SetPixel3D(X, Y, Z: Integer; Value: TColor);
begin
Calc3DPos(x,y,z);
SetPixel(x,y,Value);
end;
procedure TGDIPlusCanvas.SetAnti(const Value: Boolean);
begin
if FAnti<>Value then
begin
FAnti:=Value;
View3DOptions.Repaint;
end;
end;
procedure TGDIPlusCanvas.SetAntiText(const Value: Boolean);
begin
if FAntiText<>Value then
begin
FAntiText:=Value;
View3DOptions.Repaint;
end;
end;
procedure TGDIPlusCanvas.Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
var StartAngle : Single;
EndAngle : Single;
begin
CalcArcAngles(X1,Y1,X2,Y2,X3,Y3,X4,Y4,StartAngle,EndAngle);
if Brush.Style<>bsClear then
FGraphics.FillPie(GBrush,X1,Y1,X2,Y2,StartAngle,EndAngle-StartAngle);
if Pen.Style<>psClear then
FGraphics.DrawPie(GPen,X1,Y1,X2,Y2,StartAngle,EndAngle-StartAngle);
end;
procedure TGDIPlusCanvas.Donut( XCenter,YCenter,XRadius,YRadius:Integer;
Const StartAngle,EndAngle,HolePercent:Double);
var tmpXRadius,
tmpYRadius : Double;
P : TGPGraphicsPath;
procedure ArcTo(const X1,Y1,X2,Y2,X3,Y3,X4,Y4:Integer;
const ClockWise:Boolean=False);
var StartAngle : Single;
EndAngle : Single;
begin
// if ClockWise then
// SetArcDirection(tmpDC,AD_CLOCKWISE);
CalcArcAngles(X1,Y1,X2,Y2,X3,Y3,X4,Y4,StartAngle,EndAngle);
P.AddArc(X1,Y1,X2-X1,Y2-Y1,StartAngle,EndAngle-StartAngle);
// if ClockWise then
// SetArcDirection(tmpDC,AD_COUNTERCLOCKWISE);
end;
Procedure CalcPoint(const Angle:Double; out x,y:Integer);
var tmpSin : Extended;
tmpCos : Extended;
begin
SinCos(Angle,tmpSin,tmpCos);
x:=XCenter+Round(XRadius*tmpCos);
y:=YCenter-Round(YRadius*tmpSin);
end;
Procedure CalcPoint2(const Angle:Double; out x,y:Integer);
var tmpSin : Extended;
tmpCos : Extended;
begin
SinCos(Angle,tmpSin,tmpCos);
x:=XCenter+Round(tmpXRadius*tmpCos);
y:=YCenter-Round(tmpYRadius*tmpSin);
end;
var x3,y3,
x4,y4 : Integer;
begin
tmpXRadius:=HolePercent*XRadius*0.01;
tmpYRadius:=HolePercent*YRadius*0.01;
CalcPoint(StartAngle,x3,y3);
CalcPoint(EndAngle,x4,y4);
MoveTo(x3,y3);
P:=TGPGraphicsPath.Create;
try
ArcTo(XCenter-XRadius,YCenter-YRadius,XCenter+XRadius,YCenter+YRadius,x3,y3,x4,y4);
CalcPoint2(StartAngle,x3,y3);
CalcPoint2(EndAngle,x4,y4);
if (x4<>x3) or (y4<>y3) then
ArcTo(XCenter-Round(tmpXRadius),YCenter-Round(tmpYRadius),
XCenter+Round(tmpXRadius),YCenter+Round(tmpYRadius),
x4,y4,x3,y3,True);
if Brush.Style<>bsClear then
FGraphics.FillPath(GBrush,P);
if Pen.Style<>psClear then
FGraphics.DrawPath(GPen,P);
finally
P.Free;
end;
end;
{$IFDEF CLR}
{ ChartPenHelper }
procedure ChartPenHelper.SetTransp(const Value: TTeeTransparency);
begin
if FTransp<>Value then
begin
FTransp:=Value;
Changed(Self);
end;
end;
{$ENDIF}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -