Solved

TImage.Canvas Polygon

Posted on 1998-12-18
2
663 Views
Last Modified: 2010-05-19
Hi, how do I draw a user defined polygon ? The user clicks
with the mouse on some points. Then a polygon should be drawn. How do I add the points to the polygon and how do I create an array for them ? Source ?
0
Comment
Question by:ItsMe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 30 total points
ID: 1351761
Hi ItsMe,

This is a way :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls;

const
  MaxPoints = 10;

type
  TForm1 = class(TForm)
    PaintBox1: TPaintBox;
    StorePoly: TButton;
    DrawPoly: TButton;
    Memo1: TMemo;
    procedure StorePolyClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DrawPolyClick(Sender: TObject);
    procedure PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
    StoringMode : Boolean;
    PolygonArray : Array[0..MaxPoints-1] of TPoint;
    PointNumber : 0..MaxPoints-1;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.StorePolyClick(Sender: TObject);
begin
 {clear canvas}
 with paintbox1.canvas do begin
  Brush.Color := clWhite;
  FillRect(clipRect);
 end;
 memo1.lines.clear;
{clear polygonarray}
 FillChar(PolygonArray,SizeOf(PolygonArray),0);
 PointNumber := 0;
{start storing polygon  }
 storingMode := true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 StoringMode := false;
end;

procedure TForm1.DrawPolyClick(Sender: TObject);
begin
 {draw the polygon}
 storingMode := false;
 memo1.Lines.Add('Now drawing Polygon');
 with paintbox1.canvas do begin
  Brush.Color := clBlack;
  Polygon(Slice(PolygonArray,PointNumber));
 end;
end;

procedure TForm1.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 {Store X,Y value in grid}
 if StoringMode then begin
  if PointNumber < MaxPoints then begin
   PolygonArray[PointNumber].X := X;
   PolygonArray[PointNumber].Y := Y;
   Inc(PointNumber);
   {show point}
   PaintBox1.Canvas.Pixels[X,Y] := clRed;
   {put point in memo}
   memo1.Lines.Add('Pointnr. : '+IntToStr(PointNumber)+
                   ' at position [X:'+IntToStr(X)+', Y:'+IntToStr(Y)+']');
  end
   else showmessage('sorry polygon points are limited to: '+IntToStr(MaxPoints));
  end
   else showmessage('please press StorePoly button to start defining the polygon');
end;

end.

Regards, Zif.
0
 

Author Comment

by:ItsMe
ID: 1351762
Adjusted points to 30
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question