Board index » delphi » Canvas and other Graphics Stuff

Canvas and other Graphics Stuff

Hi..
I'm trying to draw something on a PaintBox.Canvas base on coordinate
received from another form

But something not working properly and nothing is being displayed..
hope that someone can help me.
Heres the code

----------------------------------------------------

unit uBuildingRoom;

interface

uses
  Windows,  Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, Mask, DBCtrls,DrawUtil, dsWinVesta, Encrypt,
GlobalVar,
  NbiUtils, RoomUtil, rsWinVesta, WV_Utils;

type
  TfrmBldRoom = class(TForm)
    Panel1: TPanel;
    Panel3: TPanel;
    Panel5: TPanel;
    Label1: TLabel;
    Panel6: TPanel;
    Panel4: TPanel;
    Panel2: TPanel;
    Label2: TLabel;
    Label3: TLabel;
    Button1: TButton;
    Button2: TButton;
    Label4: TLabel;
    Label5: TLabel;
    DBEdit1: TDBEdit;
    DBEdit2: TDBEdit;
    DBEdit3: TDBEdit;
    Image1: TImage;
    ComboBox1: TComboBox;
    Label6: TLabel;
    paintRoom: TPaintBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
  private
    { Dclarations prives}
  public
    { Dclarations publiques}
    Room : TRoom;
    Procedure Build_A_Room;
  end;

var
  frmBldRoom: TfrmBldRoom;

implementation

{$R *.DFM}

{ TfrmBldRoom }

procedure TfrmBldRoom.Build_A_Room;
Var
  Bmp : TBitmap;
  ClientMaxWidth : Integer;
  ClientMaxHeigth: Integer;
  RoomWidth      : Integer;
  RoomHeigth     : Integer;
  X_ExpandCoef   : Double;
  Y_ExpandCoef   : Double;
  ExpandCoef     : Integer;
  AdjWidth       : Integer;
  AdjHeigth      : Integer;

begin
  Bmp := TBitmap.Create;

  Bmp.Canvas.Pen.Mode  := pmBlack;
  Bmp.Canvas.Pen.Style := psSolid;
  Bmp.Canvas.Pen.Width := 5;

  Bmp.Canvas.Brush.Color := clWhite;
  Bmp.Canvas.Brush.Style := bsSolid;

  ClientMaxWidth  := paintRoom.Width;
  ClientMaxHeigth := paintRoom.Height;

  RoomWidth  := Room.rRect.Right - Room.rRect.Left;
  RoomHeigth := Room.rRect.Bottom - Room.rRect.Top;

  X_ExpandCoef := ClientMaxWidth / RoomWidth;
  Y_ExpandCoef := ClientMaxheigth / RoomHeigth;

  If X_ExpandCoef > Y_ExpandCoef Then
    ExpandCoef := Round(Y_ExpandCoef) - 1
  Else
    ExpandCoef := Round(X_ExpandCoef) - 1;

  AdjWidth  := Round((ClientMaxWidth - (RoomWidth * ExpandCoef)) / 2);
  AdjHeigth := Round((ClientMaxHeigth - (RoomHeigth * ExpandCoef)) / 2);

  Room.rRect.TopLeft := Point(AdjWidth,AdjHeigth);
  Room.rRect.BottomRight := Point(AdjWidth + (RoomWidth *
ExpandCoef),AdjHeigth + (RoomHeigth * ExpandCoef));

  Bmp.Canvas.MoveTo(Room.rRect.Left,Room.rRect.Top);

  Bmp.Canvas.LineTo(Room.rRect.Right,Room.rRect.Top);
  Bmp.Canvas.LineTo(Room.rRect.Right,Room.rRect.Bottom);
  Bmp.Canvas.LineTo(Room.rRect.Left,Room.rRect.Bottom);
  Bmp.Canvas.LineTo(Room.rRect.Left,Room.rRect.Top);

  paintRoom.Canvas.Draw(0,0,Bmp);

  bmp.free;
end;

procedure TfrmBldRoom.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

procedure TfrmBldRoom.FormDestroy(Sender: TObject);
begin
   frmBldRoom := nil;
end;

end.

-------------------------------------------
the paintRoom is a TPaintBox component
the Room i a TRoom (user define) that holds a TRect classes which containt
the basic representation of what to
displaThe code seem to be working OK, but nothing is being drawn..

someone knows why??

thanks mike

 

Re:Canvas and other Graphics Stuff


Deplhi help:
Unlike TImage, which displays an image that is stored in a bitmap, icon, or
metafile, TPaintBox requires an application to draw the image directly on a
canvas.

Use TImage instead.

Vyacheslav.

Quote
Michel Hudon wrote:
> Hi..
> I'm trying to draw something on a PaintBox.Canvas base on coordinate
> received from another form

> But something not working properly and nothing is being displayed..
> hope that someone can help me.
> Heres the code

> ----------------------------------------------------

> unit uBuildingRoom;

> interface

> uses
>   Windows,  Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
>   ExtCtrls, StdCtrls, Mask, DBCtrls,DrawUtil, dsWinVesta, Encrypt,
> GlobalVar,
>   NbiUtils, RoomUtil, rsWinVesta, WV_Utils;

> type
>   TfrmBldRoom = class(TForm)
>     Panel1: TPanel;
>     Panel3: TPanel;
>     Panel5: TPanel;
>     Label1: TLabel;
>     Panel6: TPanel;
>     Panel4: TPanel;
>     Panel2: TPanel;
>     Label2: TLabel;
>     Label3: TLabel;
>     Button1: TButton;
>     Button2: TButton;
>     Label4: TLabel;
>     Label5: TLabel;
>     DBEdit1: TDBEdit;
>     DBEdit2: TDBEdit;
>     DBEdit3: TDBEdit;
>     Image1: TImage;
>     ComboBox1: TComboBox;
>     Label6: TLabel;
>     paintRoom: TPaintBox;
>     procedure FormClose(Sender: TObject; var Action: TCloseAction);
>     procedure FormDestroy(Sender: TObject);
>   private
>     { Dclarations prives}
>   public
>     { Dclarations publiques}
>     Room : TRoom;
>     Procedure Build_A_Room;
>   end;

> var
>   frmBldRoom: TfrmBldRoom;

> implementation

> {$R *.DFM}

> { TfrmBldRoom }

> procedure TfrmBldRoom.Build_A_Room;
> Var
>   Bmp : TBitmap;
>   ClientMaxWidth : Integer;
>   ClientMaxHeigth: Integer;
>   RoomWidth      : Integer;
>   RoomHeigth     : Integer;
>   X_ExpandCoef   : Double;
>   Y_ExpandCoef   : Double;
>   ExpandCoef     : Integer;
>   AdjWidth       : Integer;
>   AdjHeigth      : Integer;

> begin
>   Bmp := TBitmap.Create;

>   Bmp.Canvas.Pen.Mode  := pmBlack;
>   Bmp.Canvas.Pen.Style := psSolid;
>   Bmp.Canvas.Pen.Width := 5;

>   Bmp.Canvas.Brush.Color := clWhite;
>   Bmp.Canvas.Brush.Style := bsSolid;

>   ClientMaxWidth  := paintRoom.Width;
>   ClientMaxHeigth := paintRoom.Height;

>   RoomWidth  := Room.rRect.Right - Room.rRect.Left;
>   RoomHeigth := Room.rRect.Bottom - Room.rRect.Top;

>   X_ExpandCoef := ClientMaxWidth / RoomWidth;
>   Y_ExpandCoef := ClientMaxheigth / RoomHeigth;

>   If X_ExpandCoef > Y_ExpandCoef Then
>     ExpandCoef := Round(Y_ExpandCoef) - 1
>   Else
>     ExpandCoef := Round(X_ExpandCoef) - 1;

>   AdjWidth  := Round((ClientMaxWidth - (RoomWidth * ExpandCoef)) / 2);
>   AdjHeigth := Round((ClientMaxHeigth - (RoomHeigth * ExpandCoef)) / 2);

>   Room.rRect.TopLeft := Point(AdjWidth,AdjHeigth);
>   Room.rRect.BottomRight := Point(AdjWidth + (RoomWidth *
> ExpandCoef),AdjHeigth + (RoomHeigth * ExpandCoef));

>   Bmp.Canvas.MoveTo(Room.rRect.Left,Room.rRect.Top);

>   Bmp.Canvas.LineTo(Room.rRect.Right,Room.rRect.Top);
>   Bmp.Canvas.LineTo(Room.rRect.Right,Room.rRect.Bottom);
>   Bmp.Canvas.LineTo(Room.rRect.Left,Room.rRect.Bottom);
>   Bmp.Canvas.LineTo(Room.rRect.Left,Room.rRect.Top);

>   paintRoom.Canvas.Draw(0,0,Bmp);

>   bmp.free;
> end;

> procedure TfrmBldRoom.FormClose(Sender: TObject; var Action: TCloseAction);
> begin
>   Action := caFree;
> end;

> procedure TfrmBldRoom.FormDestroy(Sender: TObject);
> begin
>    frmBldRoom := nil;
> end;

> end.

> -------------------------------------------
> the paintRoom is a TPaintBox component
> the Room i a TRoom (user define) that holds a TRect classes which containt
> the basic representation of what to
> displaThe code seem to be working OK, but nothing is being drawn..

> someone knows why??

> thanks mike

Re:Canvas and other Graphics Stuff


Actually, this is EXACTLY what i wish to do.
Let me explain..

2 Forms
On the first form is a TPaintBox in which i load a bitmap
then i draw rectangle box over the bitmap to simulate a " focus" and a
"selection" over some part of the bitmap
the rectangle are save in a Paradox database with the Top,Left,Bottom,Right
point of each rect.

This part WORKS PERFECTLY

When i dblclick on one on the "selected" rectangle, the Second form open,
which also contains a TPaintbox
NO bitmap is being loaded in this TPaintBox.
Instead, i get the X1,Y1,X2,Y2 coor from the "specified rectangle" and
strech the dimension to almost fix in the TPaintBox while respecting the
proportion

Soo, since there is NO bitmap available for the second form TPaintBox, i
have to MANUALLY draw everything
the dimension streching works fine, but nothing seem to be displayed in the
PaintBox.

Hope someone can help.

Thanks

Mike

Vyacheslav Bufetov <vvbufe...@mail.ru> a crit dans le message :
3993B69E.57527...@mail.ru...

Quote

> Deplhi help:
> Unlike TImage, which displays an image that is stored in a bitmap, icon,
or
> metafile, TPaintBox requires an application to draw the image directly on
a
> canvas.

> Use TImage instead.

> Vyacheslav.

> Michel Hudon wrote:

> > Hi..
> > I'm trying to draw something on a PaintBox.Canvas base on coordinate
> > received from another form

> > But something not working properly and nothing is being displayed..
> > hope that someone can help me.
> > Heres the code

> > ----------------------------------------------------

> > unit uBuildingRoom;

> > interface

> > uses
> >   Windows,  Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
> >   ExtCtrls, StdCtrls, Mask, DBCtrls,DrawUtil, dsWinVesta, Encrypt,
> > GlobalVar,
> >   NbiUtils, RoomUtil, rsWinVesta, WV_Utils;

> > type
> >   TfrmBldRoom = class(TForm)
> >     Panel1: TPanel;
> >     Panel3: TPanel;
> >     Panel5: TPanel;
> >     Label1: TLabel;
> >     Panel6: TPanel;
> >     Panel4: TPanel;
> >     Panel2: TPanel;
> >     Label2: TLabel;
> >     Label3: TLabel;
> >     Button1: TButton;
> >     Button2: TButton;
> >     Label4: TLabel;
> >     Label5: TLabel;
> >     DBEdit1: TDBEdit;
> >     DBEdit2: TDBEdit;
> >     DBEdit3: TDBEdit;
> >     Image1: TImage;
> >     ComboBox1: TComboBox;
> >     Label6: TLabel;
> >     paintRoom: TPaintBox;
> >     procedure FormClose(Sender: TObject; var Action: TCloseAction);
> >     procedure FormDestroy(Sender: TObject);
> >   private
> >     { Dclarations prives}
> >   public
> >     { Dclarations publiques}
> >     Room : TRoom;
> >     Procedure Build_A_Room;
> >   end;

> > var
> >   frmBldRoom: TfrmBldRoom;

> > implementation

> > {$R *.DFM}

> > { TfrmBldRoom }

> > procedure TfrmBldRoom.Build_A_Room;
> > Var
> >   Bmp : TBitmap;
> >   ClientMaxWidth : Integer;
> >   ClientMaxHeigth: Integer;
> >   RoomWidth      : Integer;
> >   RoomHeigth     : Integer;
> >   X_ExpandCoef   : Double;
> >   Y_ExpandCoef   : Double;
> >   ExpandCoef     : Integer;
> >   AdjWidth       : Integer;
> >   AdjHeigth      : Integer;

> > begin
> >   Bmp := TBitmap.Create;

> >   Bmp.Canvas.Pen.Mode  := pmBlack;
> >   Bmp.Canvas.Pen.Style := psSolid;
> >   Bmp.Canvas.Pen.Width := 5;

> >   Bmp.Canvas.Brush.Color := clWhite;
> >   Bmp.Canvas.Brush.Style := bsSolid;

> >   ClientMaxWidth  := paintRoom.Width;
> >   ClientMaxHeigth := paintRoom.Height;

> >   RoomWidth  := Room.rRect.Right - Room.rRect.Left;
> >   RoomHeigth := Room.rRect.Bottom - Room.rRect.Top;

> >   X_ExpandCoef := ClientMaxWidth / RoomWidth;
> >   Y_ExpandCoef := ClientMaxheigth / RoomHeigth;

> >   If X_ExpandCoef > Y_ExpandCoef Then
> >     ExpandCoef := Round(Y_ExpandCoef) - 1
> >   Else
> >     ExpandCoef := Round(X_ExpandCoef) - 1;

> >   AdjWidth  := Round((ClientMaxWidth - (RoomWidth * ExpandCoef)) / 2);
> >   AdjHeigth := Round((ClientMaxHeigth - (RoomHeigth * ExpandCoef)) / 2);

> >   Room.rRect.TopLeft := Point(AdjWidth,AdjHeigth);
> >   Room.rRect.BottomRight := Point(AdjWidth + (RoomWidth *
> > ExpandCoef),AdjHeigth + (RoomHeigth * ExpandCoef));

> >   Bmp.Canvas.MoveTo(Room.rRect.Left,Room.rRect.Top);

> >   Bmp.Canvas.LineTo(Room.rRect.Right,Room.rRect.Top);
> >   Bmp.Canvas.LineTo(Room.rRect.Right,Room.rRect.Bottom);
> >   Bmp.Canvas.LineTo(Room.rRect.Left,Room.rRect.Bottom);
> >   Bmp.Canvas.LineTo(Room.rRect.Left,Room.rRect.Top);

> >   paintRoom.Canvas.Draw(0,0,Bmp);

> >   bmp.free;
> > end;

> > procedure TfrmBldRoom.FormClose(Sender: TObject; var Action:
TCloseAction);
> > begin
> >   Action := caFree;
> > end;

> > procedure TfrmBldRoom.FormDestroy(Sender: TObject);
> > begin
> >    frmBldRoom := nil;
> > end;

> > end.

> > -------------------------------------------
> > the paintRoom is a TPaintBox component
> > the Room i a TRoom (user define) that holds a TRect classes which
containt
> > the basic representation of what to
> > displaThe code seem to be working OK, but nothing is being drawn..

> > someone knows why??

> > thanks mike

Other Threads