not updated ?? lazarus / 39-Graphics ---------------------------------------------------------------------- Flaze07 · 2017-07-04 23:35 hi I tried to make a code where a rectangle will be where my mouse is clicked but it is not working... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure FormPaint(Sender: TObject);  private    { private declarations }    type        Direction = (none, up, down, left, right);    const     Rect_Width = 10;     Rect_Height = 10;    var    Rect_x : integer ;  Rect_y : integer ;    dir : Direction;  public    { public declarations }  end;  var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  Rect_x := 0;  Rect_y := 0;  dir := none;end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  if (button = mbLeft) then  begin  Rect_x := X;    Rect_y := Y;  end;end;   procedure TForm1.FormPaint(Sender: TObject);var  bmp : TBGRABitmap;begin  bmp := TBGRABitmap.Create(300, 300, BGRABlack);  bmp.FillRect(Rect_x, Rect_y, Rect_x + Rect_Width, Rect_y + Rect_Height, BGRA(0, 100, 0));  bmp.draw(Canvas, 0, 0, true);  bmp.free;end; end. ---------------------------------------------------------------------- Flaze07 · 2017-07-04 23:47 this works but I don't think this is the right way Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type   { TForm1 }   TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure FormPaint(Sender: TObject);    procedure PaintDraw;  private    { private declarations }    type        Direction = (none, up, down, left, right);    const     Rect_Width = 10;     Rect_Height = 10;    var    Rect_x : integer ;    Rect_y : integer ;    dir : Direction;  public    { public declarations }  end;  var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin  Rect_x := 0;  Rect_y := 0;  dir := none;end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  if (button = mbLeft) then  begin    Rect_x := X;    Rect_y := Y;  end;  PaintDraw;end; procedure TForm1.PaintDraw;var  bmp : TBGRABitmap;begin  bmp := TBGRABitmap.Create(300, 300, BGRABlack);  bmp.FillRect(Rect_x, Rect_y, Rect_x + Rect_Width, Rect_y + Rect_Height, BGRA(0, 100, 0));  bmp.draw(Canvas, 0, 0, true);  bmp.free;end; procedure TForm1.FormPaint(Sender: TObject);begin  PaintDraw;end; end. ---------------------------------------------------------------------- Almir.Bispo · 2017-07-05 00:05 All that you need is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1;  {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;  type   { TForm1 }   TForm1 = class(TForm)    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);  private    { private declarations }  public    { public declarations }  end;  var  Form1: TForm1;  implementation {$R *.lfm} { TForm1 }//Just need it !procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,  Y: Integer);begin  form1.Canvas.Brush.Color:=clred;  form1.canvas.Rectangle(x,y-50,x+50,y);end; end. ---------------------------------------------------------------------- RAW · 2017-07-05 00:07 Works fine for me ...  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;                             Shift : TShiftState; X, Y: Integer); Begin  If Button = mbLeft  Then   Begin    Rect_x:= X;    Rect_y:= Y;    Repaint;   End; End; EDIT: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i UNIT Unit1; {$MODE OBJFPC}{$H+} Interface USES  Classes, SysUtils, Forms, Controls,  BGRABitmap, BGRABitmapTypes;  TYPE  TForm1 = Class(TForm)    Procedure FormCreate    (Sender: TObject);   Procedure FormMouseDown (Sender: TObject; Button: TMouseButton;                            Shift : TShiftState; X, Y: Integer);   Procedure FormPaint     (Sender: TObject);     PRIVATE     TYPE      Direction = (None, Up, Down, Left, Right);      CONST      Rect_Width  = 10;      Rect_Height = 10;      VAR      Rect_x: Integer ;      Rect_y: Integer ;      Dir : Direction;  End;  VAR  Form1: TForm1; Implementation {$R *.LFM}  Procedure TForm1.FormCreate(Sender: TObject); Begin  Rect_x:= 0;  Rect_y:= 0;  Dir   := none;   DoubleBuffered:= True; // classic theme :-) End;  Procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;                               Shift : TShiftState; X, Y: Integer); Begin  If Button = mbLeft  Then   Begin  Rect_x:= X;    Rect_y:= Y;    Repaint;   End; End;  Procedure TForm1.FormPaint(Sender: TObject);  Var   BMP: TBGRABitmap; Begin  BMP:= TBGRABitmap.Create(ClientWidth, ClientHeight, BGRABlack);   Try    BMP.FillRect(Rect_x, Rect_y, Rect_x+Rect_Width, Rect_y+Rect_Height,                 BGRA(255, 192, 0), dmSet);    BMP.Draw(Canvas, 0, 0, True);   Finally    BMP.Free;   End; End; END. ---------------------------------------------------------------------- Flaze07 · 2017-07-05 03:30 ah, I didn't know there's such thing as repaint thank you ---------------------------------------------------------------------- Flaze07 · 2017-07-05 03:31 Almir, I only want one rectangle and not drawing ---------------------------------------------------------------------- Handoko · 2017-07-05 04:14 Hi Flaze07. I saw you use BGRABitmap. I guess you will be interested to see this 16 tutorials: http://wiki.freepascal.org/BGRABitmap_tutorial ---------------------------------------------------------------------- Flaze07 · 2017-07-05 05:33 yeah, I have seen them...not all of them tho I got the basic idea from there