Code: Alles auswählen
;
; by Danilo, 2005/10/26
;
Structure ML
hWnd.l
EventProc.l
oldCallback.l
ButtonDown.l
oldPt.POINT
EndStructure
NewList MoverList.ML()
Procedure MoverCallback(hWnd,Msg,wParam,lParam)
ForEach MoverList()
If MoverList()\hWnd = hWnd
Select Msg
Case #WM_LBUTTONDOWN
SetCapture_(hWnd)
MoverList()\ButtonDown = 1
GetCursorPos_(pt.POINT)
MoverList()\oldPT\X = pt\X
MoverList()\oldPT\Y = pt\Y
;ProcedureReturn 1
Case #WM_LBUTTONUP
ReleaseCapture_()
MoverList()\ButtonDown = 0
;ProcedureReturn 1
Case #WM_MOUSEMOVE
If MoverList()\ButtonDown
GetCursorPos_(pt.POINT)
CallFunctionFast(MoverList()\EventProc,pt\X-MoverList()\oldPt\X,pt\Y-MoverList()\oldPt\Y)
MoverList()\oldPt\X = pt\X
MoverList()\oldPt\Y = pt\Y
EndIf
ProcedureReturn 1
EndSelect
ProcedureReturn CallWindowProc_(MoverList()\oldCallback,hWnd,Msg,wParam,lParam)
EndIf
Next
EndProcedure
Procedure MouseMover(hWnd, EventProc)
AddElement(MoverList())
MoverList()\hWnd = hWnd
MoverList()\EventProc = EventProc
MoverList()\oldCallback = SetWindowLong_(hWnd,#GWL_WNDPROC,@MoverCallback())
EndProcedure
;=========================================
; MOUSE MOVER DEMO
;=========================================
Procedure Mover1(x,y)
Static CameraX, CameraY
CameraX + x
CameraY + y
SetGadgetText(11,"CameraPos: "+Str(CameraX)+","+Str(CameraY))
EndProcedure
Procedure Mover2(x,y)
Static RotateX, RotateY
RotateX + x
RotateY + y
SetGadgetText(12,"Rotate: "+Str(RotateX)+","+Str(RotateY))
EndProcedure
Procedure Mover3(x,y)
Static MoveX, MoveY
MoveX + x
MoveY + y
SetGadgetText(13,"Move: "+Str(MoveX)+","+Str(MoveY))
EndProcedure
Procedure Mover4(x,y)
Static Gray.f, Value
Gray + x * 2.5
If Gray > 255: Gray = 255: EndIf
If Gray < -255: Gray = -255: EndIf
UseImage(1)
hDC = StartDrawing(ImageOutput())
If hDC
If Gray>=0
Circle(40,40,35,RGB(Gray,Gray,Gray))
Else
Circle(40,40,35,RGB(Abs(Gray),Abs(Gray),0))
EndIf
StopDrawing()
EndIf
SetGadgetState(4,ImageID())
EndProcedure
Procedure Mover5(x,y)
Static Value
Value + ((x+y)/2)
If Value > 999: Value = 999: EndIf
If Value < 0 : Value = 0 : EndIf
UseImage(2)
If StartDrawing(ImageOutput())
Box(0,0,80,18,RGB($00,$00,$FF))
BackColor($00,$00,$FF)
DrawText(Str(Value))
StopDrawing()
EndIf
SetGadgetState(5,ImageID())
EndProcedure
If CreateImage(1,80,80)
hDC = StartDrawing(ImageOutput())
If hDC
Box(0,0,80,80,GetSysColor_(#COLOR_BTNFACE))
rect.RECT
rect\top = 0 : rect\left = 0
rect\bottom = 80 : rect\right = 80
DrawEdge_(hDC,rect,#EDGE_SUNKEN,#BF_RECT)
Circle(40,40,35,0)
StopDrawing()
EndIf
EndIf
If CreateImage(2,80,16)
If StartDrawing(ImageOutput())
Box(0,0,80,18,RGB($00,$00,$FF))
BackColor($00,$00,$FF)
DrawText("0")
StopDrawing()
EndIf
EndIf
OpenWindow(0,0,0,740,500,#PB_Window_SystemMenu|#PB_Window_ScreenCentered,"Mover")
CreateGadgetList(WindowID())
MouseMover(ContainerGadget(1,0,0,640,480,#PB_Container_Single),@Mover1())
CloseGadgetList()
MouseMover(ButtonGadget(2,650,10,80,30,"Rotate"),@Mover2())
MouseMover(ButtonGadget(3,650,50,80,30,"Move"),@Mover3())
MouseMover(ImageGadget( 4,650,90,80,80,UseImage(1)),@Mover4())
MouseMover(ImageGadget( 5,650,180,80,16,UseImage(2)),@Mover5())
TextGadget(11,010,481,150,20,"CameraPos: 0,0")
TextGadget(12,170,481,150,20,"Rotate: 0,0")
TextGadget(13,330,481,150,20,"Move: 0,0")
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
die per MausMove Werte erhöhen. Eine Lautstärkeanzeige
und -regelung ist damit schnell gemacht (mal als Beispiel).