📄 teeflexcanvas.pas
字号:
begin
result:=FBackColor;
end;
function TFlexCanvas.GetBackMode: TCanvasBackMode;
begin
result:=FBackMode;
end;
function TFlexCanvas.GetMonochrome: Boolean;
begin
result:=False;
end;
function TFlexCanvas.GetTextAlign: TCanvasTextAlign;
begin
result:=FTextAlign;
end;
function TFlexCanvas.FlexGradient(Gradient:TCustomTeeGradient):String;
begin
with Gradient do
if Visible then
result:=FlexGradient(StartColor,EndColor,Direction,Balance)
else
result:='';
end;
function TFlexCanvas.FlexGradient(StartColor,EndColor: TColor;
Direction: TGradientDirection; Balance: Integer):String;
function GradientDirection:String;
begin
case Direction of
gdLeftRight: result:='LeftRight';
gdTopBottom: result:='TopBottom';
gdBottomTop: result:='BottomTop';
gdRightLeft: result:='RightLeft';
end;
end;
var tmpType : String;
begin
if Direction=gdRadial then
tmpType:='Radial'
else
tmpType:='Linear';
result:='gradientType="'+tmpType+'" '+
'gradientDir="'+GradientDirection+'" '+
'startColor='+FlexColor(StartColor)+' '+
'endColor='+FlexColor(EndColor)+' ';
end;
procedure TFlexCanvas.GradientFill(const Rect: TRect; StartColor,
EndColor: TColor; Direction: TGradientDirection; Balance: Integer);
begin
AddTag('tee:Rectangle',FlexPosition(Rect.Left,Rect.Top)+' '+
FlexSize(Rect)+' '+
FlexGradient(StartColor,EndColor,Direction,Balance)+FlexAlpha);
end;
function TFlexCanvas.InitWindow(DestCanvas: TCanvas;
A3DOptions: TView3DOptions; ABackColor: TColor; Is3D: Boolean;
const UserRect: TRect): TRect;
begin
result:=inherited InitWindow(DestCanvas,A3DOptions,ABackColor,Is3D,UserRect);
IAddedInitApp:=False;
AddItem('<?xml version="1.0"?>');
AddItem('<!-- Generated by TeeChart Pro Version '+TeeChartVersion+' -->');
AddItem('<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"');
AddItem(' xmlns:tee="com.steema.graphics.*"');
// Add(' '+FlexSize(UserRect));
AddItem('>');
IApplication:=FStrings.Count;
AddItem('');
AddItem(' <mx:Script>');
AddItem(' <![CDATA[');
AddItem(' ]]>');
IScript:=FStrings.Count;
AddItem(' </mx:Script>');
AddItem(' <mx:Canvas '+FlexSize(UserRect)+'>'); // FlexSprite ??
end;
procedure TFlexCanvas.LineTo(X, Y: Integer);
function Pos0:String;
begin
result:='x0="'+IntToStr(FX)+'" y0="'+IntToStr(FY)+'"';
end;
function Pos1:String;
begin
result:='x1="'+IntToStr(x)+'" y1="'+IntToStr(y)+'"';
end;
function DashLenGap:String;
var len, gap : Integer;
begin
len:=4;
gap:=4;
if ISmallDots then
begin
len:=1;
gap:=1;
end
else
case Pen.Style of
psDash: begin end;
psDot: begin len:=2; gap:=2; end;
psDashDot: begin len:=4; gap:=2; end;
psDashDotDot: begin len:=4; gap:=3; end;
end;
result:=' len="'+IntToStr(len)+'" gap="'+IntToStr(gap)+'"';
end;
begin
if (not ISmallDots) and (Pen.Style=psSolid) then
AddTag('tee:Line',Pos0+' '+Pos1+FlexAlpha+PenColor+PenWidth)
else
AddTag('tee:DashLine',Pos0+' '+Pos1+FlexAlpha+PenColor+PenWidth+DashLenGap);
end;
procedure TFlexCanvas.MoveTo(X, Y: Integer);
begin
FX:=X;
FY:=Y;
end;
procedure TFlexCanvas.Pie(X1, Y1, X2, Y2, X3, Y3, X4, Y4: Integer);
var StartAngle : Single;
EndAngle : Single;
XC : Integer;
YC : Integer;
begin
//TODO: Replace with a single call to a custom <tee:Pie...> class
XC:=(X1+X2) div 2;
YC:=(Y1+Y2) div 2;
CalcArcAngles(XC,YC,
X3,Y3,X4,Y4,StartAngle,EndAngle);
Line(XC,YC,X3,Y3);
AddTag('tee:Arc',
'x0="'+IntToStr(X1)+'" y0="'+IntToStr(Y1)+'" '+
'x1="'+IntToStr(X2)+'" y1="'+IntToStr(Y2)+'" '+
'startAngle="'+FlexFloatToStr(StartAngle)+
'" endAngle="'+FlexFloatToStr(EndAngle)+'" '+
FlexAlpha+PenColor+PenWidth);
Line(X4,Y4,XC,YC);
end;
function TFlexCanvas.FlexPoints(const Points: Array of TPoint):String;
function PointToString(const P:TPoint):String;
begin
result:=IntToStr(P.X)+','+IntToStr(P.Y);
end;
var t : Integer;
begin
result:='points="[';
if Length(Points)>0 then
begin
result:=result+PointToString(Points[0]);
for t:=1 to Length(Points)-1 do
result:=result+','+PointToString(Points[t]);
end;
result:=result+']"';
end;
procedure TFlexCanvas.BeginEntity(const Entity:String);
begin
IPath.Add(Entity);
IIdent:=IIdent+' ';
end;
procedure TFlexCanvas.EndEntity;
begin
IPath.Delete(IPath.Count-1);
Delete(IIdent,1,1);
end;
procedure TFlexCanvas.AddTag(const ATag,AText:String);
function CurrentID:String;
var t : Integer;
begin
if IPath.Count=0 then
result:=View3DOptions.Parent.Name+'_'
else
result:=IPath[0];
for t:=1 to IPath.Count-1 do
result:=result+'_'+IPath[t];
end;
function TheID:String;
var tmp : Integer;
tmpID : String;
begin
tmpID:=CurrentID;
tmp:=0;
result:=tmpID;
while IItems.IndexOf(result)<>-1 do
begin
Inc(tmp);
result:=tmpID+'_'+IntToStr(tmp);
end;
IItems.Add(result);
result:=' id="'+result+'"';
end;
begin
AddItem(IIdent+'<'+ATag+TheID+' '+AText+'/>');
end;
procedure TFlexCanvas.Polygon(const Points: array of TPoint);
begin
AddTag('tee:Polygon',FlexPoints(Points)+' '+
FlexAlpha+BrushColor+PenColor+PenWidth);
end;
Procedure TFlexCanvas.PolygonGradient(const Points: Array of TPoint;
Gradient:TCustomTeeGradient);
begin
AddTag('tee:Polygon',FlexPoints(Points)+' '+
FlexAlpha+PenColor+PenWidth+' '+FlexGradient(Gradient));
end;
procedure TFlexCanvas.Polyline(const Points:{$IFDEF D5}Array of TPoint{$ELSE}TPointArray{$ENDIF});
begin
AddTag('tee:Polyline',FlexPoints(Points)+' '+
FlexAlpha+PenColor+PenWidth);
end;
function TFlexCanvas.FlexFloatToStr(const Value:Double):String;
var Old : {$IFDEF CLR}String{$ELSE}Char{$ENDIF};
begin
Old:=DecimalSeparator;
DecimalSeparator:='.';
try
result:=FloatToStr(Value);
finally
DecimalSeparator:=Old;
end;
end;
function TFlexCanvas.FlexAlpha:String;
begin
if ITransp=0 then
result:=''
else
result:=' alpha="'+FlexFloatToStr(1-(ITransp/100))+'" ';
end;
function TFlexCanvas.PenWidth:String;
begin
if Pen.Width=1 then
result:=''
else
result:=' strokeWidth="'+IntToStr(Pen.Width)+'"';
end;
function TFlexCanvas.BrushColor:String;
begin
if Brush.Style=bsClear then
result:=' brushColor=""'
else
result:=' brushColor='+FlexColor(Brush.Color);
end;
procedure TFlexCanvas.Rectangle(X0, Y0, X1, Y1: Integer);
begin
AddTag('tee:Rectangle',FlexPosition(X0,Y0)+' '+
FlexSize(X1-X0,Y1-Y0)+FlexAlpha+PenColor+BrushColor+PenWidth);
end;
function TFlexCanvas.FlexFont(AFont:TFont):String;
function FontStyle:String;
begin
if fsItalic in Font.Style then
result:=' fontStyle="italic" '
else
result:=''; // normal
end;
function FontWeight:String;
begin
if fsBold in Font.Style then
result:=' fontWeight="bold" '
else
result:=''; // normal
end;
function TextDecoration:String;
begin
if fsUnderline in Font.Style then
result:=' textDecoration="underline" '
else
result:=''; // none
end;
begin
result:=FontStyle+
FontWeight+
' fontSize="'+FlexFloatToStr(Font.Size*1.2)+'" '+
TextDecoration+
' fontFamily="'+Font.Name+'" '+
' color='+FlexColor(Font.Color)+' ';
end;
procedure TFlexCanvas.RotateLabel(x, y: Integer; const St: String;
RotDegree: Double);
function TextRotation:String;
begin
if RotDegree=0 then
result:=''
else
result:=FlexFloatToStr(RotDegree); // embedded fonts only?
end;
begin
if TextAlign=TA_RIGHT then
Dec(x,TextWidth(St))
else
if TextAlign=TA_CENTER then
Dec(x,TextWidth(St) div 2);
AddTag('mx:Label','text="'+St+'" '+FlexPosition(x,y)+
FlexFont(Font)+' textAlign="left"');
end;
procedure TFlexCanvas.RoundRect(X1, Y1, X2, Y2, X3, Y3: Integer);
function RXY:String;
begin
result:='rx="'+IntToStr(x3)+'" ry="'+IntToStr(y3)+'"';
end;
begin
AddTag('tee:RoundRect',FlexPosition(X1,Y1)+' '+FlexSize(X2-X1,Y2-Y1)+' '+RXY+
FlexAlpha+PenColor+BrushColor+PenWidth);
end;
procedure TFlexCanvas.SetBackColor(Color: TColor);
begin
FBackColor:=Color;
end;
procedure TFlexCanvas.SetBackMode(Mode: TCanvasBackMode);
begin
FBackMode:=Mode;
end;
procedure TFlexCanvas.SetMonochrome(Value: Boolean);
begin // empty
end;
procedure TFlexCanvas.SetPixel(X, Y: Integer; Value: TColor);
begin
//TODO
end;
procedure TFlexCanvas.SetPixel3D(X, Y, Z: Integer; Value: TColor);
begin
Calc3DPos(x,y,z);
SetPixel(x,y,Value);
end;
procedure TFlexCanvas.SetTextAlign(Align: TCanvasTextAlign);
begin
FTextAlign:=Align;
end;
procedure TFlexCanvas.ShowImage(DestCanvas, DefaultCanvas: TCanvas;
const UserRect: TRect);
begin
AddItem(' </mx:Canvas>');
AddItem('</mx:Application>');
Pen.OnChange:=nil;
end;
procedure TFlexCanvas.StretchDraw(const Rect: TRect; Graphic: TGraphic);
function ImageSource:String;
begin
if EmbeddImages then
result:='@Embed('''+ImageFileName(Graphic)+''')'
else
result:=ImageFileName(Graphic);
end;
begin
if Assigned(Graphic) then
begin
AddTag('mx:Image',FlexPosition(Rect.Left,Rect.Top)+' '+
' scaleX="'+FloatToStr((Rect.Right-Rect.Left)/Graphic.Width)+'" '+
' scaleY="'+FloatToStr((Rect.Bottom-Rect.Top)/Graphic.Height)+'" '+
' source="'+ImageSource+'"');
end;
end;
procedure TFlexCanvas.TextOut(X, Y: Integer; const Text: String);
begin
RotateLabel(x,y,Text,0);
end;
procedure TFlexCanvas.TextOut3D(X, Y, Z: Integer; const Text: String);
begin
Calc3DPos(X,Y,Z);
TextOut(X,Y,Text);
end;
procedure TFlexCanvas.UnClipRectangle;
begin
//TODO
inherited;
end;
procedure TFlexCanvas.AddItem(const S: String);
begin
FStrings.Add(S);
end;
procedure TFlexCanvas.AddLink(x,y:Integer; const Text, URL, Hint: String);
begin
AddTag('mx:LinkButton','label="'+Text+'" '+FlexPosition(x,y)+
' toolTip="'+Hint+'" '+
FlexFont(Font)+
'click="navigateToURL(new URLRequest('''+URL+'''), '''+Hint+''')"');
end;
procedure TFlexCanvas.AddToolTip(const Entity,ToolTip:String);
begin
if not IAddedInitApp then
begin
FStrings.Insert(IApplication-1,' creationComplete = "initApp()"');
FStrings.Insert(IScript,' }');
FStrings.Insert(IScript,' public function initApp():void {');
IAddedInitApp:=True;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -