试试移动 (100分)

  • 主题发起人 主题发起人 hug
  • 开始时间 开始时间
H

hug

Unregistered / Unconfirmed
GUEST, unregistred user!
我在canvas上划出了图形,我想让他跟随鼠标移动,应该怎么做?
一下试我的代码:
procedure TLayoutForm.FlickerFreePaintBox1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
var
MoveDotIndex: integer;
XC, YC, Index: integer;
begin
FFieldsInfo.SetMinMaxDot;
for MoveDotIndex := 0 to High(FFieldsInfo.DotArr) do
if (FX > FFieldsInfo.DotArr[MoveDotIndex].MAxMinPointArr[0].X)
and (FX < FFieldsInfo.DotArr[MoveDotIndex].MAxMinPointArr[1].Y)
and (FY > FFieldsInfo.DotArr[MoveDotIndex].MAxMinPointArr[0].Y)
and (FY < FFieldsInfo.DotArr[MoveDotIndex].MAxMinPointArr[1].Y)
then
begin
for Index := 0 to High(FFieldsInfo.DotArr[MoveDotIndex].FieldPoint) do
begin
FlickerFreePaintBox1.Cursor:=crHandPoint;
if MoveFlag = true then
FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X
:= FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X + X - FX;
FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].Y
:= FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].Y + Y - FY;

end;
FlickerFreePaintBox1.Repaint;
end;
end;
 
请大家帮我改改,问题是X和 y累加的缘故,应该怎么加呢?
 
if MoveFlag = true then begin
FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X
:= FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X + X - FX;
FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].Y
:= FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].Y + Y - FY;
end;
 
谢谢XWHope ,我没有看出您的改动阿?

 
这里是不是错了?
if (FX > FFieldsInfo.DotArr[MoveDotIndex].MAxMinPointArr[0].X)
and (FX < FFieldsInfo.DotArr[MoveDotIndex].MAxMinPointArr[1].Y) //应该是X吧
and (FY > FFieldsInfo.DotArr[MoveDotIndex].MAxMinPointArr[0].Y)
and (FY < FFieldsInfo.DotArr[MoveDotIndex].MAxMinPointArr[1].Y)
 
谢谢yostgxf,对的,那里错了,
FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X
:= FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X + X - FX;
FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].Y
:= FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].Y + Y - FY;
可这里也不对,其中加“+X”是累加的,本来不应该累加的,
到那个位置,就加那个位置的坐标才行,这样连以前的也加上了,
所以不对,应该怎样改才行啊!谢谢大家!!快一点阿!
 
看不懂啊,移动的话还要循环干吗啊?
 
to 来如风,因为我把图形的坐标放在数组里面了,
给每个坐标加上一个值不要循环吗?
 
楼主说的不是很清楚,你是在哪个控件的CANVAS上作画???

FX,FY 分别是什么???

 
你的FX,FY是什么?是不是MouseDown取的X,Y值
如果我理解的对,应该这样改:
FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X
:= FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X - X + FX;//把二个符号转换。

 
明白你的意思了,帮你看看吧
 
不停的在鼠标当前位置画你的图形,并记下坐标,画前先擦除原先画的图形,就可以了
 
我这里只是坐标的转化,画图函数没有在这里,我在一个控件上画的,
相当于PaintBox,
我用划直线的方法把各点连接起来的。
我只希望在MouseMove事件里面给出坐标变换,
 
我也不知道FX,FY是什么意思,

不过感觉不管怎么样首先的确要按 XWHope 的改,
因为不改的话你的if只是对x做变动,y是不受if影响的
 
to yostgxf:您理解得很对,可是把符号改过来也不正确,
和鼠标移动的方向就相反了,
而且也没有解决坐标累加的问题(图形比鼠标移动的快好多)
 
to 如来风, XWHope ,对的,应该那样改,谢谢2位,
但哪里不是主要问题,主要是坐标变换问题!谢谢了
 
to pyh_jerry,谢谢,我就是这样做的,划之前总要有坐标吧?
那就要与以前的坐标相比,就必须近想坐标变换!
 
还有:定义一个变量AA
在MosueDown中
AA:=FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X ;//最后一个值
后面改为:
FFieldsInfo.DotArr[MoveDotIndex].FieldPoint[Index].X := AA- X + FX;

这样应该没问题了。
 
yostgxf,您讲得很有道理,我试一下,不过AA是一个包含所有图形,
所有坐标的数据结构喔!
 
谢谢大家,yostgxf得方法("+"&amp;"-"点到一下)正确,其余的也有很大的帮助,谢谢大家。
方分了
 
后退
顶部