Recent

Author Topic: few basic things  (Read 4358 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 397
few basic things
« on: January 09, 2012, 09:39:45 am »
1. what is the diff between Timage and TPaintBox ?
2. Id I do some line drawing on Timage canvas following this example:
http://123codegenerator.blogspot.com/2010/04/click-and-drag-mouse-to-draw-line-using.html
Each form resize or scroll (as timage is inside scrollbox) erases all lines. How to handle that ?
3. Following example from above link, scrolling image inside scroll box, proc:
Code: [Select]
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;

  Shift: TShiftState; X, Y: Integer);

begin

 Drawing := true;

 StartX := x;
 //...
The coordinates are not picked up correctly any more after scroll.

How to handle that ?
lazarus 3.2-fpc-3.2.2-win32/win64

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: few basic things
« Reply #1 on: January 09, 2012, 11:58:33 am »
1. TPaintBox is propably more optimal for doing drawing.

2. TImage has sort of 2 picture layers. First the TPicture base which is loaded from file, and then the canvas. Whenever you resize the component, TPicture is drawn on the canvas. If you don't want want your drawings to get erased, you need to draw them directly into the TPicture, not to canvas.

3. FormMouseDown() is executed normally ONLY when you click the TForm. Do you have event assigned to TImage.onMousedown? As for coordinates when clicking TImage, they are always relative to top left position of the component. If its scrolled, you can find the difference from TScrollBox properties maybe.
« Last Edit: January 09, 2012, 12:04:14 pm by User137 »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: few basic things
« Reply #2 on: January 09, 2012, 12:09:23 pm »
1. what is the diff between Timage and TPaintBox ?

TImage draws an image, so you can draw to this buffer image at any time and it will be shown to the screen when required. TImage is not made for fast changing graphics, but if your graphics change slowly it should be fine.

TPaintBox is just a pre-made TCustomControl, so you cannot draw to it outside the OnPaint event.

In general read: http://wiki.lazarus.freepascal.org/Developing_with_Graphics

Quote
2. Id I do some line drawing on Timage canvas following this example:
http://123codegenerator.blogspot.com/2010/04/click-and-drag-mouse-to-draw-line-using.html
Each form resize or scroll (as timage is inside scrollbox) erases all lines. How to handle that ?

As very often with Delphi, the code you posted is Windows only. Never draw to a visual control outside the OnPaint event.

Instead you have multiple possible solutions:

1> Draw to a TBitmap instead. In the OnPaint draw this TBitmap to the form Canvas. Call Invalidate when you modified the bitmap to request a form redraw.

2> Use a TImage which does the same as option 1 internally

3> A more complex one. Use fpvectorial for example to handle the list of all lines and other vectors of the image and then use fpvectorial too to render them

All of those will also be safe in case of resize

Quote
3. Following example from above link, scrolling image inside scroll box, proc:
Code: [Select]
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 Drawing := true;
 StartX := x;
 //...
The coordinates are not picked up correctly any more after scroll.
How to handle that ?

How exactly are they not correct?

You could also try Mouse.CursorPos + ScreenToClient()

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 397
Re: few basic things
« Reply #3 on: January 09, 2012, 04:14:58 pm »
Here is whole thing  - attached
1.
Quote
    The coordinates are not picked up correctly any more after scroll.
    How to handle that ?

    How exactly are they not correct?

Load any image bigger than window, scroll a bit and try

2. if I go and replace (in code)

Code: [Select]
with image2 do
with:

Code: [Select]
with image2.Picture.Bitmap do

then problems with wrong coordinates & disappearing on form resize ... disappears, but the thing draws whole bunch of things that I don't know where they come from.

Need simple thing: load image & draw line with mouse & save the thing.

If anyone can shed some light on that. Will manage to do things from that point on.
 
« Last Edit: January 09, 2012, 04:16:49 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

 

TinyPortal © 2005-2018