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

📄 teetext3d.pas

📁 BCB第三方组件
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{**********************************************}
{   TeeChart - 3D text tool                    }
{   Copyright (c) 2006-2007 by David Berneda   }
{**********************************************}
unit TeeText3D;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows, Messages,
  {$ENDIF}
  SysUtils, Classes,
  {$IFDEF CLX}
  Qt, QGraphics, QControls, QForms, QDialogs, QComCtrls, QStdCtrls,
  {$ELSE}
  Graphics, Controls, Forms, Dialogs, ComCtrls, StdCtrls,
  {$ENDIF}
  TeCanvas, TeeProcs, TeEngine, Chart, TeeEdiFont, TeeBrushDlg;

type
  TText3DTool=class(TTeeCustomTool)
  private
    FAngle     : Double;
    FFont      : TTeeFont;
    FPosition  : TFloatXYZ;
    FRotation  : TFloatXYZ;
    FText      : String;

    procedure Changed(Sender:TObject);
    procedure DestroyPolygons;
    procedure SetAngle(const Value:Double);
    procedure SetFont(const Value:TTeeFont);
    procedure SetPosition(const Value:TFloatXYZ);
    procedure SetRotation(const Value:TFloatXYZ);
    procedure SetText(const Value:String);
  protected
    Procedure ChartEvent(AEvent:TChartToolEvent); override;
    class Function GetEditorClass:String; override;
  public
    Interior     : Array of Boolean;
    PolygonCount : Integer;
    Polygons     : Array of TPointArray;

    Constructor Create(AOwner:TComponent); override;
    Destructor Destroy; override;

    procedure Assign(Source:TPersistent); override;
    class Function Description:String; override;
    class Function LongDescription:String; override;
  published
    property Active;
    property Angle:Double read FAngle write SetAngle;
    property Brush;
    property Font:TTeeFont read FFont write SetFont;
    property Pen;
    property Position:TFloatXYZ read FPosition write SetPosition;
    property Rotation:TFloatXYZ read FRotation write SetRotation;
    property Text:String read FText write SetText;
  end;

  TText3DEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabFont: TTabSheet;
    Label1: TLabel;
    MemoText: TMemo;
    TabSheet3: TTabSheet;
    Label4: TLabel;
    Label5: TLabel;
    ECustLeft: TEdit;
    UDLeft: TUpDown;
    ECustTop: TEdit;
    UDTop: TUpDown;
    Button1: TButton;
    Label2: TLabel;
    Edit1: TEdit;
    UDZ: TUpDown;
    Button2: TButton;
    TabSheet2: TTabSheet;
    Label3: TLabel;
    TBRotation: TTrackBar;
    LRotation: TLabel;
    Label6: TLabel;
    TBElevation: TTrackBar;
    LElevation: TLabel;
    Label7: TLabel;
    TBTilt: TTrackBar;
    LTilt: TLabel;
    procedure ECustLeftChange(Sender: TObject);
    procedure ECustTopChange(Sender: TObject);
    procedure MemoTextChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure TBRotationChange(Sender: TObject);
    procedure TBElevationChange(Sender: TObject);
    procedure TBTiltChange(Sender: TObject);
  private
    { Private declarations }
    Tool : TText3DTool;
  public
    { Public declarations }
  end;

implementation

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

uses
  {$IFDEF CLR}
  System.Runtime.InteropServices,  // Marshal
  {$ENDIF}
  TeeStringsEditor, TeeProCo;

Constructor TText3DTool.Create(AOwner:TComponent);
begin
  inherited;

  FFont:=TTeeFont.Create(CanvasChanged);
  FFont.Size:=24;

  FFont.OutLine.Color:=clWhite;
  FFont.OutLine.Show;

  Brush.Color:=clWhite;
  Brush.BackColor:=Font.Color;

  FPosition:=TFloatXYZ.Create;
  FPosition.X:=50;
  FPosition.Y:=50;
  FPosition.OnChange:=Changed;

  FRotation:=TFloatXYZ.Create;
  FRotation.OnChange:=Changed;
end;

Destructor TText3DTool.Destroy;
begin
  DestroyPolygons;
  FFont.Free;
  FRotation.Free;
  FPosition.Free;
  inherited;
end;

procedure TText3DTool.Changed(Sender:TObject);
begin
  Repaint;
end;

procedure TText3DTool.DestroyPolygons;
var t : Integer;
begin
  Interior:=nil;

  for t:=0 to PolygonCount-1 do
      Polygons[t]:=nil;

  Polygons:=nil;
  PolygonCount:=0;
end;

type
  {$IFNDEF CLR}
  TPArray=packed Array[0..0] of TPoint;
  PTP=^TPArray;
  TBArray=packed Array[0..0] of Byte;
  PTB=^TBArray;
  {$ENDIF}

  TTeeCanvas3DAccess=class(TTeeCanvas3D);
  TChartAccess=class(TCustomChart);

Procedure TText3DTool.ChartEvent(AEvent:TChartToolEvent);

  procedure DrawPolygons;

    procedure DoDrawPolygons(AColor,ABack:TColor);
    var t : Integer;
        tt : Integer;
        Clipped  : Boolean;
        PP       : TPointArray;
        tmpZ     : Integer;
    begin
      PP:=nil;

      tmpZ:=Round(FPosition.Z);

      for t:=0 to PolygonCount-1 do
      begin
        if Interior[t] then
        begin
          if FFont.OutLine.Visible then
          begin
            ParentChart.Canvas.Brush.Style:=bsClear;
            ParentChart.Canvas.PolygonWithZ(Polygons[t],tmpZ);
            ParentChart.Canvas.AssignBrush(Brush,ABack,AColor);
          end;
        end
        else
        begin
          Clipped:=False;

          for tt:=0 to PolygonCount-1 do
          if tt<>t then
             if PolygonInPolygon(Polygons[tt],Polygons[t]) then
             begin
               PP:=ParentChart.Canvas.Calc3DPoints(Polygons[tt],tmpZ);
               try
                 ParentChart.Canvas.ClipPolygon(PP,Length(PP),True);
               finally
                 PP:=nil;
               end;

               Clipped:=True;
             end;

          if Assigned(FFont.Picture) and Assigned(FFont.Picture.Graphic) then
          begin
            PP:=ParentChart.Canvas.Calc3DPoints(Polygons[t],tmpZ);
            try
              ParentChart.Canvas.ClipPolygon(PP,Length(PP),False);
              ParentChart.Canvas.StretchDraw(PolygonBounds(PP),FFont.Picture.Filtered);
              Clipped:=True;

              if FFont.OutLine.Visible then
              begin
                ParentChart.Canvas.UnClipRectangle;
                ParentChart.Canvas.Brush.Style:=bsClear;
                ParentChart.Canvas.Polygon(PP);
                ParentChart.Canvas.AssignBrush(Brush,AColor,ABack);
              end;

            finally
              PP:=nil;
            end;
          end
          else
          if FFont.Gradient.Visible then
          begin
            FFont.Gradient.Draw(ParentChart.Canvas,Polygons[t],tmpZ,ParentChart.View3D);

            if FFont.OutLine.Visible then
            begin
              ParentChart.Canvas.Brush.Style:=bsClear;

              PP:=ParentChart.Canvas.Calc3DPoints(Polygons[t],tmpZ);
              try
                ParentChart.Canvas.Polygon(PP);
              finally
                PP:=nil;
              end;

              ParentChart.Canvas.AssignBrush(Brush,AColor,ABack);
            end;
          end
          else
          begin
            {
            if Smooth.Active then
               ParentChart.Canvas.PolygonWithZ(Smooth.Calculate(Polygons[t]),ZPos)
            else
            }
               ParentChart.Canvas.PolygonWithZ(Polygons[t],tmpZ);
          end;

          if Clipped then
             ParentChart.Canvas.UnClipRectangle;
        end;
      end;
    end;

  var t : Integer;
      tt : Integer;
      AShadow  : TTeeShadow;
      tmpColor : TColor;

      OldR,
      OldE : Double;
      OldT : Integer;
      tmpRotate : Boolean;
  begin
    // Apply rotation
    tmpRotate:= (Rotation.X<>0) or (Rotation.Y<>0) or (Rotation.Z<>0);

    if tmpRotate then
    begin
      with ParentChart.Canvas.View3DOptions do
      begin
        oldR:=RotationFloat;
        oldE:=ElevationFloat;
        oldT:=Tilt;

        RotationFloat:=oldR+Self.Rotation.X;
        ElevationFloat:=oldE+Self.Rotation.Y;
        Tilt:=oldT+Round(Self.Rotation.Z);
      end;

      if ParentChart.Canvas is TTeeCanvas3D then
      begin
        TTeeCanvas3DAccess(ParentChart.Canvas).CalcTrigValues;
        TTeeCanvas3DAccess(ParentChart.Canvas).CalcPerspective(ParentChart.ChartRect);
      end;

      // Restore previous rotation
      with ParentChart.Canvas.View3DOptions do
      begin
        RotationFloat:=oldR;
        ElevationFloat:=oldE;
        Tilt:=oldT;
      end;
    end;

    ParentChart.Canvas.AssignBrush(Brush);

    SetLength(Interior,PolygonCount);

    for t:=0 to PolygonCount-1 do
    begin
      Interior[t]:=False;

      for tt:=0 to PolygonCount-1 do
      if tt<>t then
         if PolygonInPolygon(Polygons[t],Polygons[tt]) then
         begin
           Interior[t]:=True;
           break;
         end;
    end;

    AShadow:=FFont.Shadow;

    if AShadow.Visible and (AShadow.Size<>0) then
    begin
      if ParentChart.Canvas is TTeeCanvas3D then
      begin
        Inc(TTeeCanvas3DAccess(ParentChart.Canvas).XCenterOffset,AShadow.HorizSize);
        Inc(TTeeCanvas3DAccess(ParentChart.Canvas).YCenterOffset,AShadow.VertSize);
      end;

      ParentChart.Canvas.AssignBrush(Brush,AShadow.Color,AShadow.Color);
      ParentChart.Canvas.AssignVisiblePenColor(FFont.OutLine,AShadow.Color);

      tmpColor:=AShadow.Color;

      DoDrawPolygons(tmpColor,tmpColor);

      ParentChart.Canvas.AssignBrush(Brush);

⌨️ 快捷键说明

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