Sign in Join

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

Mailing lists / fpc-pascal / 2013-01

interactively draw an ellipse

5 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

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

duilio foschi

Hi!

this code

procedure TForm1.DrawBtnClick(Sender: TObject);
{Draw some ellipses on the canvas - random size and color}
var
  i:integer;
  cx,cy:integer;
begin
  with image1, canvas do
  begin
    for i:= 1 to 10 do
    begin
      cx:=random(width);
      cy:=random(height);
      brush.color:=random(256*256*256);
      ellipse(cx,cy,cx+random(100), cy+random(100));
    end;
  end;
end;

will draw 10 ellipses on Image1.

However, I want to do it interactively, like it is done in Photo-Paint.

The ellipse should be contained in a rectangle R whose upper-left corner is given by the original position of the mouse on screen.

And the bottom-right corner of R will be the final position of the mouse.

During dragging, a temporary ellipse should be shown on screen and the mouse will be cross-shaped.

Any idea re how to do it ?

An unexpensive well debugged 3th-party library would be the ideal solution (as I don't plan to work in graphics in the future).

Thank you

Duilio

Reply by email

Mattias Gaertner
to duilio foschi
Show quoted text 23 lines
Hi! this code procedure TForm1.DrawBtnClick(Sender: TObject); {Draw some ellipses on the canvas - random size and color} var i:integer; cx,cy:integer; begin with image1, canvas do begin for i:= 1 to 10 do begin cx:=random(width); cy:=random(height); brush.color:=random(256*256*256); ellipse(cx,cy,cx+random(100), cy+random(100)); end; end; end; will draw 10 ellipses on Image1.

This looks like Lazarus/Delphi code.
This mailing list is about the things that comes with FPC (compiler, RTL, FCL, ...).
Have you searched/asked on Lazarus forum?

Mattias

Reply by email

leledumbo
to duilio foschi: Hi! this code procedure TForm1.DrawBtnClick(Sender: TObject); {Draw some ellipses on the…

Create a backend data structure representing what's on the canvas ATM, then draw them all at OnPaint (clean the canvas first). This way, the temporary object will be kept drawn as it's the same as the final object. You can even modify already drawn object if you want.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/interactively-draw-an-ellipse-tp5712644p5712647.html Sent from the Free Pascal - General mailing list .

Reply by email

Ewald
to duilio foschi: Hi! this code procedure TForm1.DrawBtnClick(Sender: TObject); {Draw some ellipses on the…

Hello,

Quite easy. Abstract concept:
- Take one framebuffer `ImageBuffer`, whose contents is the final image
- Take another framebuffer `InteractionBuffer` whose contents is everything that's interactive
- The InteractionBuffer shall be an overlay of the imagebuffer

So when you want to draw it interactively, you draw the ellipse in InteractionBuffer, and once the user confirms that `yes draw what I see right now`, you simply draw the ellipse in the ImageBuffer and clear the InteractionBuffer. If you want to update the interaction buffer with a new ellipse, you clear it and draw the new ellipse.

As for the third party library: how could you expect for a third party library to give you such lazarus-specific functionality?

Anyway, hope it helps.

Once upon a time, on 01/23/2013 11:27 AM to be precise, duilio foschi said:

Show quoted text 23 lines
Hi! this code [snip] will draw 10 ellipses on Image1. However, I want to do it interactively, like it is done in Photo-Paint. The ellipse should be contained in a rectangle R whose upper-left corner is given by the original position of the mouse on screen. And the bottom-right corner of R will be the final position of the mouse. During dragging, a temporary ellipse should be shown on screen and the mouse will be cross-shaped. Any idea re how to do it ? An unexpensive well debugged 3th-party library would be the ideal solution (as I don't plan to work in graphics in the future).
Ewald

Reply by email