interactively draw an ellipse

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

interactively draw an ellipse

duilio foschi-2
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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: interactively draw an ellipse

Mattias Gaertner
On Wed, 23 Jan 2013 11:27:31 +0100
duilio foschi <[hidden email]> wrote:

> 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
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: interactively draw an ellipse

Johann Glaser
In reply to this post by duilio foschi-2
Hi!

Please do your homework yourself.

Bye
  Hansi


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: interactively draw an ellipse

leledumbo
Administrator
In reply to this post by duilio foschi-2
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.
Reply | Threaded
Open this post in threaded view
|

Re: interactively draw an ellipse

Ewald-2
In reply to this post by duilio foschi-2
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:

> 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

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal