On 18/09/2014 17:41, Giuliano Colla wrote:

Canvas.RadalPie on GTK2 and Windows works only clockwise, but provides a
very poor image (more like a portion of an octagon that a portion of a
circle).
Counterclockwise it generates the image of my previous e-mail.

On Windows here, Pie (RadialPie) works counterclockwise well, using the following code example. I'm sure if you added anitaliasing to improve the rendering quality this would be welcomed.

Howard

== code ==

unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics;

type

  { TForm1 }

  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
  end;

  TPieRec = record
    percentage: integer; // give pie segments as percentag of whole pie
    color: TColor;
  end;

  TPieArray = array of TPieRec;

  procedure DrawPie(aCanvas: TCanvas; aCircleRect: TRect; pa: TPieArray);

var
  Form1: TForm1;

implementation

procedure DrawPie(aCanvas: TCanvas; aCircleRect: TRect; pa: TPieArray);
var
  angles: array of integer;
  lastAngle: integer = 0;
  i: Integer;
begin
  SetLength(angles, Length(pa));
  for i:=0 to High(pa) do begin
    angles[i]:=trunc(pa[i].percentage * 57.60);
    aCanvas.Brush.Color:=pa[i].color;
aCanvas.RadialPie(aCircleRect.Left, aCircleRect.Top, aCircleRect.Right, aCircleRect.Bottom,
                      lastAngle, angles[i]);
    Inc(lastAngle, angles[i]);
  end;
end;

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  example: TPieArray;
  circleRect: TRect;
begin
  circleRect:=Rect(10,10,110,110);
  SetLength(example, 4);
  example[0].percentage:=30; example[0].color:=clBlue;
  example[1].percentage:=10; example[1].color:=clRed;
  example[2].percentage:=20; example[2].color:=clYellow;
  example[3].percentage:=40; example[3].color:=clMoneyGreen;
  DrawPie(Canvas, circleRect, example);
end;

end.



--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to