Снова столкнулся с задачей перемещения картинки с помощью мыши. Старый код, который взял как пример, мне не подошел
Global iw,ih
Global ipx=0
Global ipy=0
Global mpx,mpy
Procedure drawcan(xx,yy)
StartDrawing(CanvasOutput(0))
Box(0,0,640,480,0)
DrawImage(ImageID(0),xx,yy)
StopDrawing()
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, "Move/Drag Canvas Image", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 640, 480)
LoadImage(0,"pic.bmp")
iw=ImageWidth(0)
ih=ImageHeight(0)
ipx=0
ipy=0
Drag = #False
drawcan(0,0)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
Select EventType()
Case #PB_EventType_LeftButtonDown
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
If x >= ipx And x < ipx + iw
If y >= ipy And y < ipy + ih
mpx=x
mpy=y
Drag = #True
EndIf
EndIf
Case #PB_EventType_LeftButtonUp
Drag = #False
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
ipx=ipx-(mpx-x)
ipy=ipy-(mpy-y)
Case #PB_EventType_MouseMove
If Drag = #True
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
drawcan( ipx-(mpx-x),ipy-(mpy-y) )
EndIf
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Global ipx=0
Global ipy=0
Global mpx,mpy
Procedure drawcan(xx,yy)
StartDrawing(CanvasOutput(0))
Box(0,0,640,480,0)
DrawImage(ImageID(0),xx,yy)
StopDrawing()
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, "Move/Drag Canvas Image", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 0, 0, 640, 480)
LoadImage(0,"pic.bmp")
iw=ImageWidth(0)
ih=ImageHeight(0)
ipx=0
ipy=0
Drag = #False
drawcan(0,0)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = 0
Select EventType()
Case #PB_EventType_LeftButtonDown
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
If x >= ipx And x < ipx + iw
If y >= ipy And y < ipy + ih
mpx=x
mpy=y
Drag = #True
EndIf
EndIf
Case #PB_EventType_LeftButtonUp
Drag = #False
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
ipx=ipx-(mpx-x)
ipy=ipy-(mpy-y)
Case #PB_EventType_MouseMove
If Drag = #True
x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
drawcan( ipx-(mpx-x),ipy-(mpy-y) )
EndIf
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
Комментарии
Отправить комментарий