Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2002-10

TCanvas.Ellipse

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Tony Maro
to Andrew Johnson: On Mon, 7 Oct 2002 23:11:31 -0500 perfect sense.. not so perfect routine. I thought I had…

I don't know how to do patches, so here's an updated Ellipse routine for GTK that properly draws the ellipse in all of my tests. This goes in gtkwinapi.inc

function TgtkObject.Ellipse(DC: HDC;
  x1,y1,x2,y2: Integer): Boolean;
var
  x,y,width,height: integer;
  DCOrigin: TPoint;
begin
  Result := IsValidDC(DC);
  if Result
  then with TDeviceContext(DC) do
  begin
    if GC = nil
    then begin
      WriteLn('WARNING: [TgtkObject.Ellipse] Uninitialized GC');
      Result := False;
    end
    else begin
      x := x1; // added by Tony
      y := y1; // added by Tony
      //x:=(x1+x2) shr 1;  // removed by Tony
      //y:=(y1+y2) shr 1;  // removed by Tony
      width:=(x2-x1) shl 1;
      if width<0 then width:=-width;
      width:=width shr 1;  // Changed by Tony
      height:=(y2-y1) shl 1;  // changed by Tony
      if height<0 then height:=-height;
      height:=height shr 1;
      // first draw interior in brush color
      SelectGDKBrushProps(DC);
      DCOrigin:=GetDCOffset(TDeviceContext(DC));
      gdk_draw_arc(Drawable, GC, 1, x+DCOrigin.X, y+DCOrigin.Y, Width,
Height,
                   0, 360 shl 6);
      // Draw outline
      SelectGDKPenProps(DC);
      If not IsValidGDIObject(hPen(CurrentPen)) then
        exit;//cowardly refuse to continue
      If CurrentPen^.IsNullPen then begin
        Result := True;//not an error
        Exit;//Skip out.
      end;
      gdk_draw_arc(Drawable, GC, 0, x+DCOrigin.X, y+DCOrigin.Y, Width,
Height,
                   0, 360 shl 6);
      Result := True;
    end;
  end;
end;

Reply by email

Andrew Johnson
Show quoted text 11 lines
How is TCanvas.Ellipse supposed to function? I would have assumed top, left width, height are the params. In fact I think that's the way it functioned in Delphi. Unfortunately that draws an ellipse in the lower right corner of that bounding box. To get one to draw properly at 0,0 with a width of 100 and a height of 100 I had to use: .Ellipse(-100,-100,100,100);// places center at 50,50 with a radius of 50 Does that make any sense?

perfect sense.. not so perfect routine. I thought I had that fixed a while back.. but it was only in the non-gtk version.

I looked at the code and scratched my head.. The code for ellipse makes no sense from my standpoint. Before calling the actual routine it does -

      x:=(x1+x2) shr 1;
      y:=(y1+y2) shr 1;
      width:=(x2-x1);
      if width<0 then width:=-width;
      width:=width shr 1;
      height:=(y2-y1);
      if height<0 then height:=-height;
      height:=height shr 1;

and uses the X, Y, Width and height values. I have no idea why it does this.. So I would suggest you try instead to do

Chord(0,0,200,200, 0, 360*16);

I think that should work for you.

Just remember currently Chord takes X, Y, Width, Height, Angle1*16, Angle2*16

Why? Again I do not know. But thus far I have left it alone.

Andrew

_________________________________________________________________ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx

Reply by email

Tony Maro

How is TCanvas.Ellipse supposed to function? I would have assumed top, left width, height are the params. In fact I think that's the way it functioned in Delphi.

Unfortunately that draws an ellipse in the lower right corner of that bounding box. To get one to draw properly at 0,0 with a width of 100 and a height of 100 I had to use:

.Ellipse(-100,-100,100,100);// places center at 50,50 with a radius of 50

Does that make any sense?

-Tony

Reply by email