Tags标签 网战地图
当前位置: 主页 > 编程语言 > Delphi教程 >

再学GDI+[29]: TGPPen - 自定义复合画笔 - SetCompoundArray

2012-05-05 20:43 [Delphi教程] 来源于:
导读:本例效果图: 代码文件: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtr

本例效果图:

代码文件:unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls, ExtCtrls;
type
 TForm1 = class(TForm)
  LabeledEdit1: TLabeledEdit;
  RadioGroup1: TRadioGroup;
  procedure FormCreate(Sender: TObject);
  procedure FormPaint(Sender: TObject);
  procedure RadioGroup1Click(Sender: TObject);
  procedure LabeledEdit1Change(Sender: TObject);
 end;
var
 Form1: TForm1;
implementation
{$R *.dfm}
uses GDIPOBJ, GDIPAPI;
var
 arr1: array[0..5] of Single; {用于均分线复合画笔; 数组大小没有限制, 可用动态数 组}
 arr2: array[0..3] of Single; {用于粗细线复合画笔; 数组大小没有限制, 可用动态数 组}
procedure TForm1.FormCreate(Sender: TObject);
begin
 {均分线复合画笔; 6 个元素决定 3 条子线; 数组元素为百分比, 应在 0-1 之间}
 arr1[0] := 0.00; {第一线起点}
 arr1[1] := 0.10; {第一线终点}
 arr1[2] := 0.45; {第二线起点}
 arr1[3] := 0.55; {第二线终点}
 arr1[4] := 0.90; {第三线起点}
 arr1[5] := 1.00; {第三线终点}
 {粗细线复合画笔; 4 个元素决定 2 条子线; }
 arr2[0] := 0.00; {第一线起点}
 arr2[1] := 0.50; {第一线终点}
 arr2[2] := 0.90; {第二线起点}
 arr2[3] := 1.00; {第二线终点}
 LabeledEdit1.EditLabel.Caption := '笔宽';
 LabeledEdit1.Text := '10';
 RadioGroup1.Caption := '线型';
 RadioGroup1.Items.CommaText := '单实线,均分线,粗细线';
 RadioGroup1.ItemIndex := 0;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
 g: TGPGraphics;
 p: TGPPen;
 r: TRect;
begin
 g := TGPGraphics.Create(Canvas.Handle);
 g.Clear($FFFFFFFF);
 p := TGPPen.Create(aclCoral);
 p.SetWidth(StrToFloatDef(LabeledEdit1.Text, 10));
 case RadioGroup1.ItemIndex of
  1: p.SetCompoundArray(@arr1, Length(arr1));
  2: p.SetCompoundArray(@arr2, Length(arr2));
 end;
 g.DrawLine(p, 0, 0, ClientWidth, ClientHeight);
 r := ClientRect;
 g.DrawEllipse(p, MakeRect(r));
 InflateRect(r, -ClientWidth p 4, -ClientHeight p 4);
 g.DrawLine(p, 0, 0, ClientWidth, ClientHeight);
 g.DrawRectangle(p, MakeRect(r));
 p.Free;
 g.Free;
end;
procedure TForm1.LabeledEdit1Change(Sender: TObject);
begin
 Repaint;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
 Repaint;
end;
end.

(编辑:)

本文标签:
网友评论

栏目列表

推荐文章