Solved

TImage.Canvas Polygon

Posted on 1998-12-18
2
653 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
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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 108
Print Graphic and Text to Epson TM-T88v 12 259
Dev Express grid collapse 2 45
Firemonkey BASS_Init into a thread 17 8
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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