I have an .bmp image with a comic book layout. Currently my code works like this. If I right click and hold down mouse button i can draw a marquee type box around one of the
I've got a few suggestions; I'm not sure that they'll be sufficient to solve your problem, but I hope it helps you get there.
First, your while
loops are doing a fair amount of funny fiddling:
if (x - startx < y - starty) then
begin
while (x - startx < y - starty) do
begin
x := x + 100;
startx := startx - 100;
end;
end
else if (x - startx > y - starty) then
/* similar code */
Note that x - start == y - starty
case is being completely overlooked. I don't know if this matters.
Second, this could probably be re-written without a loop. I'm guessing here, it'd take a little testing to see if this is correct, but this feels like the right path:
foo := (x - startx) - (y - starty)
if (foo > 200 || foo < -200)
bar = foo / 200 # I assume integer truncation
x += bar * 100
startx += bar * 100
I'm not entirely sure why you're trying to get (x-startx) - (y-starty)
to within 200 of each other; there may be something better still.
This section of code is a little confusing:
if (PicRect.Right=PicRect.Left)
then
coef := 100000
else
coef:=ShowRect.Right/(PicRect.Right-PicRect.Left);
PicRect.Left:=Round(PicRect.Left+startx/coef);
PicRect.Right:=PicRect.Left+Round((x-startx)/coef);
if (PicRect.Bottom=PicRect.Top)
then
coef := 100000
else
coef:=ShowRect.Bottom/(PicRect.Bottom-PicRect.Top);
PicRect.Top:=Round(PicRect.Top+starty/coef);
PicRect.Bottom:=PicRect.Top+Round((y-starty)/coef);
end;
Is coef
supposed to be overwritten from the earlier? Or, should you instead calculate a coefx
and coefy
and then pick the (larger? smaller? closer to 100000?) value to serve for both the .Left
, .Right
, .Top
, and .Bottom
calculations? I have to think that this code, as it stands, is more likely to lead to awkward stretching of your content in a way that will likely annoy users and authors both.
Now, to address the real reason why you're here, animating the zoom -- you'll probably need to drastically change something. I feel like your while
loops were probably intended to do the zooming, but they come after the coef
calculations, so I assumed they were meant for something else. But, once you do figure out where exactly to place the loop to calculate different coef
values over a range from "no zoom" to "final zoom", you'll also need to add calls to repaint the display -- or, depending upon your environment, maybe need to add some callback code fired by a timer every 50 ms or something to repaint with updated coef
values.