У меня есть изображение .bmp с макетом комикса.В настоящее время мой код работает как это. Если я щелкну правой кнопкой мыши и удерживаю нажатой кнопку мыши, я могу нарисовать рамку вокруг одного из фреймов на странице комикса. Когда я отпущу кнопку, он увеличит масштаб этого кадра. Но это мгновенно. И я хотел бы, чтобы
Таким образом, вместо того, чтобы идти и устанавливать значения PicRect в "END VALUE"
PicRect.Left
PicRect.right
PicRect.top
PicRect.bottom
, как показано в коде ниже, мне нужен способ медленного ge t там, какой-то цикл while, который устанавливает эти значения понемногу, пока не дойдет до «конечного значения». Но я не уверен на 100% в том, как работает эта математика. Ни одна из моих попыток цикла while не делает ничего, кроме слишком большого увеличения. Это процедура.
procedure TZImage.MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
var coef:Double;
t:integer;
begin
if FMouse=mNone then Exit;
if x>ShowRect.Right then x:=ShowRect.Right;
if y>ShowRect.Bottom then y:=ShowRect.Bottom;
if FMouse=mZoom then begin //calculate new PicRect
t:=startx;
startx:=Min(startx,x);
x:=Max(t,x);
t:=starty;
starty:=Min(starty,y);
y:=Max(t,y);
FMouse:=mNone;
MouseCapture:=False;
//enable the following if you want to zoom-out by dragging in the opposite direction}
{ if Startx>x then begin
DblClick;
Exit;
end;}
if Abs(x-startx)<5 then Exit;
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
begin
while (x - startx > y - starty) do
begin
y := y + 100;
starty := starty - 100;
end;
end;
//This is were it sets the zoom info. This is were
//I have to change to slowly get the PICRECT.Left/right/top/bottom
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;
if FMouse=mDrag then begin
FMouse:=mNone;
Canvas.Pen.Mode:=pmCopy;
Screen.Cursor:=crDefault;
end;
Invalidate;
end;
Я считаю, что это можно сделать в приведенном выше коде. но также хотел добавить это, если это поможет.
type
TZImage = class(TGraphicControl)
private
FBitmap : TBitmap;
PicRect : TRect;
ShowRect : TRect;
FShowBorder : boolean;
FBorderWidth : integer;
FForceRepaint : boolean;
FMouse : (mNone, mDrag, mZoom);
FProportional : boolean;
FDblClkEnable : boolean;
startx, starty,
oldx, oldy : integer;
спасибо за любую помощь в том, чтобы заставить это работать.