Recent

Author Topic: canvas painting disappear after a form drop on  (Read 7684 times)

ali-libre

  • New Member
  • *
  • Posts: 40
canvas painting disappear after a form drop on
« on: March 01, 2017, 01:10:51 pm »
painting disappear after a new form drop on my form
I don't use window manager and reapaint are exoensive to me.
What can i do?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: canvas painting disappear after a form drop on
« Reply #1 on: March 01, 2017, 01:56:53 pm »
Use the form's OnPaint event to do the drawing?

circular

  • Hero Member
  • *****
  • Posts: 4221
    • Personal webpage
Re: canvas painting disappear after a form drop on
« Reply #2 on: March 01, 2017, 08:51:43 pm »
Otherwise draw in a bitmap and in the OnPaint event just draw the bitmap
Conscience is the debugger of the mind

ali-libre

  • New Member
  • *
  • Posts: 40
Re: canvas painting disappear after a form drop on
« Reply #3 on: March 02, 2017, 12:06:47 pm »
i have a map to see if mouse rally leave form and then back repait
But onmouseleave execute on move on each element on the form!
Is ther any event show really mouse leave the form.

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: canvas painting disappear after a form drop on
« Reply #4 on: March 02, 2017, 01:20:09 pm »
I don't know if I understand what you want...

Anyway.. you can create your own TIMER.

WINDOWS example:
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.Timer1Timer(Sender: TObject);
  2.  Begin
  3.   If Not PtInRect(Self.BoundsRect, Mouse.CursorPos)
  4.   Then Color:= clBlue
  5.   Else Color:= clWhite;
  6.  End;  
  7.  

EDIT: Funny if I use "bsNone" then this is working, but with "bsSizeable" it's not working. If the cursor is at the bottom of the form then the color turns into blue.
« Last Edit: March 02, 2017, 01:32:53 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: canvas painting disappear after a form drop on
« Reply #5 on: March 02, 2017, 03:35:58 pm »
OnMouseLeave (and OnMouseEnter) does not seem to be implemented for TForm. However, that can be remedied without needing a timer. In a new blank Lazarus project set the OnCreate, OnMouseEnter and OnMouseLeave events of Form1 as follows (this deals only with the form client area - to get the full form bounds is more complicated):
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$Mode objfpc}{$H+}
  4. {$AppType console}
  5.  
  6. interface
  7.  
  8. uses
  9.   SysUtils, Forms, Controls, LCLIntf, Classes;
  10.  
  11. type
  12.  
  13.   TForm1 = class(TForm)
  14.     procedure FormCreate(Sender: TObject);
  15.     procedure FormMouseEnter(Sender: TObject);
  16.     procedure FormMouseLeave(Sender: TObject);
  17.   private
  18.     FPriorMouseWithin: Boolean;
  19.     FMouseWithinClient: Boolean;
  20.     FInitialised: Boolean;
  21.     procedure DoMouseLeave;
  22.     procedure DoMouseEnter;
  23.     procedure Form1OnIdle(Sender: TObject; var Done: Boolean);
  24.   public
  25.  
  26.   end;
  27.  
  28. var
  29.   Form1: TForm1;
  30.  
  31. implementation
  32.  
  33. {$R *.lfm}
  34.  
  35. procedure TForm1.FormCreate(Sender: TObject);
  36. begin
  37.   FPriorMouseWithin:=PtInRect(ClientRect, ScreenToClient(Mouse.CursorPos));
  38.   Application.OnIdle:=@Form1OnIdle;
  39. end;
  40.  
  41. procedure TForm1.FormMouseEnter(Sender: TObject);
  42. begin
  43.   WriteLn('FormMouseEnter');
  44. end;
  45.  
  46. procedure TForm1.FormMouseLeave(Sender: TObject);
  47. begin
  48.   WriteLn('FormMouseLeave');
  49. end;
  50.  
  51. procedure TForm1.DoMouseLeave;
  52. begin
  53.   if Assigned(OnMouseLeave) then
  54.     OnMouseLeave(Self);
  55. end;
  56.  
  57. procedure TForm1.DoMouseEnter;
  58. begin
  59.   if Assigned(OnMouseEnter) and FInitialised then
  60.     OnMouseEnter(Self);
  61.   if not FInitialised then
  62.     FInitialised:=True;
  63. end;
  64.  
  65. procedure TForm1.Form1OnIdle(Sender: TObject; var Done: Boolean);
  66. begin
  67.   FMouseWithinClient:=PtInRect(ClientRect, ScreenToClient(Mouse.CursorPos));
  68.   if FPriorMouseWithin and not FMouseWithinClient then begin
  69.     FPriorMouseWithin:=False;
  70.     DoMouseLeave;
  71.   end
  72.   else if not FPriorMouseWithin and FMouseWithinClient then begin
  73.     FPriorMouseWithin:=True;
  74.     DoMouseEnter;
  75.   end;
  76.   Done:=True;
  77. end;
  78.  
  79. end.
« Last Edit: March 02, 2017, 03:37:44 pm by howardpc »

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: canvas painting disappear after a form drop on
« Reply #6 on: March 02, 2017, 05:07:32 pm »
Quote
...does not seem to be implemented for TForm.
On Windows 7 it's working fine (OnMouseLeave and OnMouseEnter), but if I move very fast then it fails. And yes only ClientArea is handled.

EDIT: ClientRect is working fine in combination with "bsSizeable"...
Code: Pascal  [Select][+][-]
  1. Procedure TForm1.Timer1Timer(Sender: TObject);
  2.  Begin
  3.   If Not PtInRect(ClientRect, ScreenToClient(Mouse.CursorPos))
  4.   Then Color:= clBlue
  5.   Else Color:= clWhite;
  6.  End;
  7.  

Maybe it's just my CustomClassicTheme setting.  :)
« Last Edit: March 02, 2017, 05:24:10 pm by RAW »
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: canvas painting disappear after a form drop on
« Reply #7 on: March 02, 2017, 06:38:55 pm »
On Windows 7 it's working fine (OnMouseLeave and OnMouseEnter), but if I move very fast then it fails.

Since very rapid mouse movements will send message(s) before an OnIdle event occurs to interpret it/them using this rather naive code.

ali-libre

  • New Member
  • *
  • Posts: 40
Re: canvas painting disappear after a form drop on
« Reply #8 on: March 02, 2017, 08:19:49 pm »
sadly : both not worked.
but i used on activated event and everything work fine...!
but how a window manager make it unchangable ?
whie program run in a window manager nothing been cleared but non-gui?
can i activate such thing in my project or manually active this on simple x-org?
« Last Edit: March 02, 2017, 10:56:09 pm by ali-libre »

ali-libre

  • New Member
  • *
  • Posts: 40
Re: canvas painting disappear after a form drop on
« Reply #9 on: March 02, 2017, 11:07:39 pm »
can the element's pixel's be over write linke bake texture on 3D software?
« Last Edit: March 03, 2017, 12:41:54 am by ali-libre »

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: canvas painting disappear after a form drop on
« Reply #10 on: March 03, 2017, 12:30:33 pm »
painting disappear after a new form drop on my form
I don't use window manager and reapaint are exoensive to me.
What can i do?
Have a TImage on form to hold all the canvas drawings. Draw on a image1.Picture.Bitmap.Canvas, but before that you need to ensure there is a canvas as large as the image, so
Code: Pascal  [Select][+][-]
  1. onFormCreate:
  2.  
  3. image1.Align:=alClient; // stretch to form boundaries
  4. image1.Picture.Bitmap.Width:=ClientWidth;
  5. image1.Picture.Bitmap.Height:=ClientHeight;
TImage's pixels never disappear when other form passes over, you don't need to repaint.

ali-libre

  • New Member
  • *
  • Posts: 40
Re: canvas painting disappear after a form drop on
« Reply #11 on: March 03, 2017, 10:38:51 pm »
good idea but what about performance?
is it fast as simple component?

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: canvas painting disappear after a form drop on
« Reply #12 on: March 03, 2017, 11:30:01 pm »
Speed of (re)drawing is not something you can reliably predict theoretically.
If speed is of the essence, you would have to implement the two different solutions (each coded optimally), and time their performance on your system to see if there were any significant difference between them. In any case, a few milliseconds display differential is not noticeable to the human eye. It's not like we're talking OS boot-up time, or C++ project compilation time.

ali-libre

  • New Member
  • *
  • Posts: 40
Re: canvas painting disappear after a form drop on
« Reply #13 on: March 11, 2017, 11:20:32 pm »
no.
i tested timage tonight an found timage not produced for fast painting
i can fast draw on simple object but not timage
i'm currently using tpaintbox.
or timage have an option for fast drawing?
or i must back to redraw?

lainz

  • Hero Member
  • *****
  • Posts: 4473
    • https://lainz.github.io/
Re: canvas painting disappear after a form drop on
« Reply #14 on: March 11, 2017, 11:25:22 pm »
I agree better use TPaintBox.

But as already said only repaint as needed not redraw the content too often.

If you need speed at repaint better use OpenGL.

 

TinyPortal © 2005-2018