* * *

Author Topic: How is made event management?  (Read 921 times)

Borneq

  • Full Member
  • ***
  • Posts: 127
How is made event management?
« on: August 10, 2017, 11:45:11 pm »
How is WinApi wrapped?
With each window HWND is associated window procedure (callback)?
This procedure can handle WM_PAINT messages; between BeginPaint-EndPaint controls can draw self.
But how user application have access to Canvas from any event? OnCreate, OnClick, OnMouseMove etc. How they can draw on Canvas?
« Last Edit: August 10, 2017, 11:51:10 pm by Borneq »

RAW

  • Hero Member
  • *****
  • Posts: 577
Re: How is made event management?
« Reply #1 on: August 11, 2017, 05:46:39 am »
Don't know if I understand this...  :)

OnPaint
Repaint
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8 FPC 3.0.4 // 1.7 FPC 3.1.1

Borneq

  • Full Member
  • ***
  • Posts: 127
Re: How is made event management?
« Reply #2 on: August 11, 2017, 07:28:08 am »
Is page: http://wiki.lazarus.freepascal.org/LCL_Internals but nothing about Paint

RAW

  • Hero Member
  • *****
  • Posts: 577
Re: How is made event management?
« Reply #3 on: August 11, 2017, 08:35:44 am »
I thought you just want to paint something like this...  :D
No harm meant...
Code: Pascal  [Select]
  1. Procedure TForm1.FormCreate(Sender: TObject);
  2.  Begin
  3.   DoubleBuffered:= True; // Classic Theme
  4.   Height        := 400;
  5.   Width         := 500;
  6.   Position      := poDesktopCenter;
  7.  End;
  8.  
  9.  
  10. Procedure TForm1.FormPaint(Sender: TObject);
  11.  Begin
  12.   If booColor
  13.   Then
  14.    Begin
  15.     Canvas.Brush.Color:= clBlue;
  16.     Canvas.Brush.Style:= bsSolid;
  17.     Canvas.Ellipse(0, 0, 150, 300);
  18.    End
  19.   Else
  20.    Begin
  21.     Canvas.Brush.Color:= clYellow;
  22.     Canvas.Brush.Style:= bsSolid;
  23.     Canvas.Ellipse(0, 0, 150, 300);
  24.    End;
  25.  End;
  26.  
  27.  
  28. Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  29.                                Shift : TShiftState; X, Y: Integer);
  30.  Begin
  31.   If Button = mbRight
  32.   Then
  33.    Begin
  34.     booColor:= True;
  35.     Repaint;
  36.    End;
  37.  
  38.   If Button = mbLeft
  39.   Then
  40.    Begin
  41.     booColor:= False;
  42.     Repaint;
  43.    End;
  44.  End;


Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8 FPC 3.0.4 // 1.7 FPC 3.1.1

Borneq

  • Full Member
  • ***
  • Posts: 127
Re: How is made event management?
« Reply #4 on: August 11, 2017, 09:41:45 am »
Problem is not drawing on FormPaint but direct drawing:
Code: Pascal  [Select]
  1.     Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  2.                                    Shift : TShiftState; X, Y: Integer);
  3.     Begin
  4.        Canvas.Brush.Color:= clBlue;
  5.        Canvas.Brush.Style:= bsSolid;
  6.        Canvas.Ellipse(0, 0, 150, 300);
  7.     End;
  8.  

RAW

  • Hero Member
  • *****
  • Posts: 577
Re: How is made event management?
« Reply #5 on: August 11, 2017, 10:15:54 am »
Try this...  :D
Code: Pascal  [Select]
  1. UNIT Unit1;
  2. {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes,  SysUtils, Forms,
  7.   Controls, Graphics, LCLType,
  8.   ExtCtrls;
  9.  
  10.  TYPE
  11.   TForm1 = Class(TForm)
  12.  
  13.    Procedure FormCreate  (Sender: TObject);
  14.    Procedure FormKeyDown (Sender: TObject; Var Key: Word; Shift: TShiftState);
  15.  
  16.     PRIVATE
  17.      IMG: TImage;
  18.   End;
  19.  
  20.  VAR
  21.   Form1: TForm1;
  22.  
  23. Implementation
  24. {$R *.LFM}
  25.  
  26.  
  27. Procedure TForm1.FormCreate(Sender: TObject);
  28.  Begin
  29.   DoubleBuffered:= True;
  30.  
  31.   IMG       := TImage.Create(Self);
  32.   IMG.Align := alClient;
  33.   IMG.Parent:= Self;
  34.   IMG.Show;
  35.  End;
  36.  
  37.  
  38. Procedure TForm1.FormKeyDown(Sender: TObject; Var Key: Word;
  39.                              Shift : TShiftState);
  40.   Var
  41.    BMP: TBitmap;
  42.  Begin
  43.   If Key = VK_RETURN
  44.   Then
  45.    Begin
  46.     BMP:= TBitmap.Create;
  47.      Try
  48.       BMP.Height:= Self.ClientHeight;
  49.       BMP.Width := Self.ClientWidth Div 2;
  50.  
  51.       BMP.Canvas.Brush.Color:= clRed;
  52.       BMP.Canvas.Brush.Style:= bsSolid;
  53.       BMP.Canvas.FillRect(BMP.Canvas.ClipRect);
  54.  
  55.       IMG.Picture.Bitmap.Assign(BMP);
  56.      Finally
  57.       BMP.Free;
  58.      End;
  59.    End;
  60.  End;
  61.  
  62. END.

Just kidding ... there is no other event for drawing...   
Use >> OnPaint << ...
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8 FPC 3.0.4 // 1.7 FPC 3.1.1

RAW

  • Hero Member
  • *****
  • Posts: 577
Re: How is made event management?
« Reply #6 on: August 11, 2017, 10:39:15 am »
If you don't like OnPaint then this is definitely for you ...   :)

Try this..
OnClick-Drawing...  :)
Code: Pascal  [Select]
  1. Unit Unit1;
  2. {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes,  SysUtils, Forms,
  7.   Controls, Graphics, ExtCtrls,
  8.   StdCtrls;
  9.  
  10.  TYPE
  11.   TForm1 = Class(TForm)
  12.  
  13.    Procedure FormCreate (Sender: TObject);
  14.    Procedure FormResize (Sender: TObject);
  15.    Procedure FormClick  (Sender: TObject);
  16.    Procedure ShowVAT;
  17.  
  18.     PRIVATE
  19.      PanVAT: TPanel;
  20.   End;
  21.  
  22.  VAR
  23.   Form1: TForm1;
  24.  
  25. Implementation
  26. {$R *.LFM}
  27.  
  28.  
  29. Procedure TForm1.ShowVAT;
  30.   Var
  31.    LabLeft  : TLabel;
  32.    iFontSize: Integer;
  33.  
  34.    IMG: TImage;
  35.    BMP: TBitmap;
  36.  Begin
  37.   PanVAT               := TPanel.Create(Self);
  38.   PanVAT.BorderStyle   := bsSingle;
  39.   PanVAT.BevelOuter    := bvRaised;
  40.   PanVAT.Color         := clBlack;
  41.   PanVAT.BorderWidth   := 0;
  42.   PanVAT.Caption       := '';
  43.   PanVAT.DoubleBuffered:= True;
  44.   PanVAT.SetBounds     (Self.ClientWidth Div 2,
  45.                         0,
  46.                         Self.ClientWidth Div 2,
  47.                         Self.ClientHeight);
  48.   PanVAT.Parent        := Self;
  49.  
  50.  
  51.   LabLeft             := TLabel.Create(PanVAT);
  52.   LabLeft.Transparent := True;
  53.   LabLeft.AutoSize    := True;
  54.   LabLeft.Font.Color  := clLime;
  55.   LabLeft.Font.Name   := 'Lucida Console';
  56.   LabLeft.Font.Quality:= fqAntialiased;
  57.   LabLeft.Font.Size   := PanVAT.ClientWidth Div 30;
  58.   LabLeft.Font.Style  := [fsBold];
  59.   LabLeft.Align       := alLeft;
  60.   LabLeft.Alignment   := taRightJustify;
  61.   LabLeft.Caption     := 'Current Period' +sLineBreak+
  62.                          'Return Due'     +sLineBreak+
  63.                                            sLineBreak+
  64.                                            sLineBreak+
  65.                          'Period Shown'   +sLineBreak+
  66.                          'Output VAT'     +sLineBreak+
  67.                          'Input VAT'      +sLineBreak+
  68.                          'VAT Due'        +sLineBreak+
  69.                          'Sales'          +sLineBreak+
  70.                          'Purchases'      +sLineBreak+
  71.                          'Adjustment VAT' +sLineBreak+
  72.                          'Adjustment Goods';
  73.   LabLeft.Parent      := PanVAT;
  74.  
  75.  
  76.   iFontSize:= LabLeft.Font.Size;
  77.  
  78.   BMP:= TBitmap.Create;
  79.    Try
  80.     BMP.Height            := iFontSize;
  81.     BMP.Width             := PanVAT.ClientWidth;
  82.     BMP.Canvas.Brush.Color:= clLime;
  83.     BMP.Canvas.Brush.Style:= bsSolid;
  84.     BMP.Canvas.FillRect      (BMP.Canvas.ClipRect);
  85.  
  86.     IMG:= TImage.Create(PanVAT);
  87.     IMG.Picture.Assign(BMP);
  88.     IMG.SetBounds(0,
  89.                   Trunc(iFontSize*3.5),
  90.                   BMP.Width,
  91.                   BMP.Height);
  92.     IMG.Parent:= PanVAT;
  93.    Finally
  94.     BMP.Free;
  95.    End;
  96.  End;
  97.  
  98.  
  99. Procedure TForm1.FormClick(Sender: TObject);
  100.  Begin
  101.   If Not Assigned(PanVAT)
  102.   Then ShowVAT
  103.   Else
  104.    Begin
  105.     PanVAT.Free;
  106.     PanVAT:= Nil;
  107.    End;
  108.  End;
  109.  
  110.  
  111. Procedure TForm1.FormResize(Sender: TObject);
  112.  Begin
  113.   If Assigned(PanVAT)
  114.   Then
  115.    Begin
  116.     PanVAT.Free;
  117.     ShowVAT;
  118.    End;
  119.  End;
  120.  
  121.  
  122. Procedure TForm1.FormCreate(Sender: TObject);
  123.  Begin
  124.   DoubleBuffered:= True;
  125.  
  126.   Constraints.MinHeight:= 200;
  127.   Constraints.MinWidth := 300;
  128.  End;
  129.  
  130. END.
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8 FPC 3.0.4 // 1.7 FPC 3.1.1

RAW

  • Hero Member
  • *****
  • Posts: 577
Re: How is made event management?
« Reply #7 on: August 12, 2017, 01:44:02 pm »
Quote
Problem is not drawing on FormPaint but direct drawing:
Obviously I'm not smart enough...

This is what you want... isn't it ???
EDIT: If you really want to paint like MSPaint or GIMP, then you can use the TPaintbox or better BGRABitmap (semitransparent pixel) or FreePascal only or Graphics32 or VampyreImagingLIB or AGGPAS....
And probably better a fast timer and not OnMouseMove...  :D
Code: Pascal  [Select]
  1. UNIT Unit1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, SysUtils, Forms, Controls, Graphics;
  7.  
  8.  TYPE
  9.   TForm1 = Class(TForm)
  10.  
  11.    Procedure FormMouseUp   (Sender: TObject; Button: TMouseButton;
  12.                             Shift : TShiftState; X, Y: Integer);
  13.    Procedure FormMouseMove (Sender: TObject; Shift: TShiftState;
  14.                             X, Y: Integer);
  15.    Procedure FormMouseDown (Sender: TObject; Button: TMouseButton;
  16.                             Shift : TShiftState; X, Y: Integer);
  17.     PRIVATE
  18.      booDrawing: Boolean;
  19.   End;
  20.  
  21.  VAR
  22.   Form1: TForm1;
  23.  
  24. Implementation
  25.  {$R *.LFM}
  26.  
  27.  
  28. Procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState;
  29.                                X, Y: Integer);
  30.  Begin
  31.   If booDrawing
  32.   Then
  33.    Begin
  34.     Canvas.Brush.Color:= clBlue;
  35.     Canvas.Rectangle  (X, Y-10, X+10, Y);
  36.    End;
  37.  End;
  38.  
  39.  
  40. Procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  41.                              Shift : TShiftState; X, Y: Integer);
  42.  Begin
  43.   booDrawing:= False;
  44.  End;
  45.  
  46.  
  47. Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  48.                                Shift : TShiftState; X, Y: Integer);
  49.  Begin
  50.   If Button = mbLeft
  51.   Then booDrawing:= True;
  52.  
  53.   If Button = mbRight
  54.   Then Repaint;
  55.  End;
  56.  
  57. END.
« Last Edit: August 12, 2017, 01:52:41 pm by RAW »
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8 FPC 3.0.4 // 1.7 FPC 3.1.1

RAW

  • Hero Member
  • *****
  • Posts: 577
Re: How is made event management?
« Reply #8 on: August 12, 2017, 02:45:37 pm »
Paint on a form like MSPaint... almost... this is funny...  :D :D :D :D :D :D

Code: Pascal  [Select]
  1. UNIT Unit1;
  2.  {$MODE OBJFPC}{$H+}{$J-}
  3.  
  4. Interface
  5.  USES
  6.   Classes, SysUtils, Forms, Controls, Graphics, ExtCtrls;
  7.  
  8.  TYPE
  9.   TForm1 = Class(TForm)
  10.  
  11.    Timer1: TTimer;
  12.  
  13.    Procedure FormCreate    (Sender: TObject);
  14.    Procedure FormMouseDown (Sender: TObject; Button: TMouseButton;
  15.                             Shift : TShiftState; X, Y: Integer);
  16.    Procedure FormMouseUp   (Sender: TObject; Button: TMouseButton;
  17.                             Shift : TShiftState; X, Y: Integer);
  18.    Procedure Timer1Timer   (Sender: TObject);
  19.  
  20.     PRIVATE
  21.      booPainting: Boolean;
  22.   End;
  23.  
  24.  VAR
  25.   Form1: TForm1;
  26.  
  27. Implementation
  28.  {$R *.LFM}
  29.  
  30.  
  31. Procedure TForm1.FormCreate(Sender: TObject);
  32.  Begin
  33.   Canvas.Pen.Style:= psSolid;
  34.   Canvas.Pen.Color:= clBlue;
  35.   Canvas.Pen.Width:= 10;
  36.  End;
  37.  
  38.  
  39. Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  40.                                Shift : TShiftState; X, Y: Integer);
  41.  Begin
  42.   If Button = mbLeft
  43.   Then booPainting:= True;
  44.  
  45.   If Button = mbRight
  46.   Then Repaint;
  47.  End;
  48.  
  49.  
  50. Procedure TForm1.Timer1Timer(Sender: TObject);
  51.   Var
  52.    p: TPoint;
  53.  Begin
  54.   If booPainting
  55.   Then
  56.    Begin
  57.     p:= ScreenToClient(Mouse.CursorPos);
  58.     Canvas.LineTo(p.x, p.y);
  59.    End;
  60.  End;
  61.  
  62.  
  63. Procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  64.                              Shift : TShiftState; X, Y: Integer);
  65.  Begin
  66.   booPainting:= False;
  67.  End;
  68.  
  69. END.
« Last Edit: August 12, 2017, 03:08:16 pm by RAW »
Windows 7 Pro (x64 Sp1) And Windows XP Pro (x86 Sp3) - LAZARUS 1.8 FPC 3.0.4 // 1.7 FPC 3.1.1

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus