Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TImage.Canvas Polygon

Posted on 1998-12-18
2
Medium Priority
?
671 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 120 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

610 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