In article <397d2...@nap-ns1.netconnect.net.au>,
"Paul" <holdf...@netconnect.com.au> wrote:
Quote
> (With Delphi 3) I've loaded a bitmap into TImage. The bitmap (actually
it is
> a real map!)has a scale line on it somewhere representing a certain
> distance. I need to do three things:
> 1. Click mouse at two points on the scale line to record x pixels
> 2. Click a "draw" button (for example) to draw a grid over the entire
> bitmap, the length of the sides of its squares being the number of
pixels
> previously recorded. I assume I can use the LineTo method of TCanvas
to draw
> the first side of a grid square, then an algorythm of some sort to
construct
> the rest of the grid. Now I'm lost.
> 3. Use mouse to position grid over map before setting its position
with a
> button or right click etc.
> The gridded (is there a better word) bitmap can then be saved/printed.
> I have absolutely no idea how to proceed and any advice would be most
> welcome.
First you probably need some sort of global state variable
to keep track of what the next click on the grid "means". Like
type TNextClickMeans = (ncmFirstX, ncmSecondX, ncmGridPoint);
var nextClickMeans: TNextClickMeans;
firstX, secondX: integer;
gridPoint: TPoint;
Before starting all this you say
nextClickMeans:= ncmFirstX;
Now the image's OnMouseDown handler inspects the value of
nextClickMeans to decide what to do, something like
procedure whatever.MouseDown(...);
begin
case nextClickMeans of
ncmFirstX:
begin
firstX:= X;
nextClickMeans:= ncmSecondX;
end;
ncmSecondX:
begin
secondX:= X;
nextClickMeans:= ncmGridPoint;
end;
end;
ncmmGridPoint:
begin
gridPoint:= Point(X,Y);
nextClickMeans:= whatever seems appropriate;
DrawTheGrid;
end;
end;
Now the DrawTheGrid method does something like this:
procedure DrawTheGrid;
var j, delta, XMin, YMin, XNum, YNum: integer;
begin
delta:= abs(firstX - secondX);
XMin:= GridPoint.X - (1 + GridPoint.X div delta)*delta;
YMin:= GridPoint.Y - (1 + GridPoint.Y div delta)*delta;
XNum:= 2 + image.Width div delta;
YNum:= 2 + image.Height div delta;
for j:= 0 to XNum do
begin
image.Canvas.MoveTo(XMin + j*delta, 0);
image.Canvas.LineTo(XMin + j*delta, image.Height;
end;
for j:=0 to YNum do
begin
image.Canvas.MoveTo(0, YMin + j*delta);
image.Canvas.LineTo(image.Width, YMin + j*delta);
end;
end;
end;
That's off the top of the head, may need a little
tweaking. (Off the top of the head I suspect that it
draws all the lines you want, possibly also drawing
one or two invisible off-screen lines. Except for
typos.)
Sent via Deja.com http://www.deja.com/
Before you buy.