Relative mousewheel zoom
Centered on the mouse...
This commit is contained in:
61
PBMap.pb
61
PBMap.pb
@@ -27,7 +27,7 @@ DeclareModule PBMap
|
||||
;-Show debug infos
|
||||
Global Verbose = #False
|
||||
;-Proxy ON/OFF
|
||||
Global Proxy = #False
|
||||
Global Proxy = #True
|
||||
Declare InitPBMap()
|
||||
Declare SetMapServer(ServerURL.s="http://tile.openstreetmap.org/",TileSize.l=256,ZoomMin.l=0,ZoomMax.l=18)
|
||||
Declare MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
|
||||
@@ -310,10 +310,10 @@ Module PBMap
|
||||
|
||||
Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
|
||||
If Gadget = #PB_Any
|
||||
PBMap\Gadget = CanvasGadget(PBMap\Gadget, X, Y, Width, Height)
|
||||
PBMap\Gadget = CanvasGadget(PBMap\Gadget, X, Y, Width, Height, #PB_Canvas_Keyboard) ;#PB_Canvas_Keyboard has to be set for mousewheel to work on windows
|
||||
Else
|
||||
PBMap\Gadget = Gadget
|
||||
CanvasGadget(PBMap\Gadget, X, Y, Width, Height)
|
||||
CanvasGadget(PBMap\Gadget, X, Y, Width, Height, #PB_Canvas_Keyboard)
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
@@ -855,7 +855,7 @@ Module PBMap
|
||||
|
||||
Procedure Event(Event.l)
|
||||
Protected Gadget.i
|
||||
Protected MouseX.i, MouseY.i
|
||||
Protected MouseX.i, MouseY.i, OldPx.d, OldPy.d, OldMx.d, OldMy.d
|
||||
Protected Marker.Position
|
||||
Protected *Drawing.DrawingParameters
|
||||
If IsGadget(PBMap\Gadget) And GadgetType(PBMap\Gadget) = #PB_GadgetType_Canvas
|
||||
@@ -866,7 +866,37 @@ Module PBMap
|
||||
Case PBMap\Gadget
|
||||
Select EventType()
|
||||
Case #PB_EventType_MouseWheel
|
||||
SetZoom(GetGadgetAttribute(PBMap\Gadget,#PB_Canvas_WheelDelta),#PB_Relative)
|
||||
;Absolute zoom (centered on the center of the map)
|
||||
; SetZoom(GetGadgetAttribute(PBMap\Gadget,#PB_Canvas_WheelDelta),#PB_Relative)
|
||||
;Relative zoom (centered on the center of the mouse)
|
||||
OldPx = PBMap\Position\x : OldPy = PBMap\Position\y
|
||||
OldMx = OldPx + GadgetWidth(PBMap\Gadget) / 2 - GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||
OldMy = OldPy + GadgetHeight(PBMap\Gadget) / 2 - GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
||||
PBMap\Zoom = PBMap\Zoom + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_WheelDelta)
|
||||
If PBMap\Zoom > PBMap\ZoomMax : PBMap\Zoom = PBMap\ZoomMax : EndIf
|
||||
If PBMap\Zoom < PBMap\ZoomMin : PBMap\Zoom = PBMap\ZoomMin : EndIf
|
||||
;-*** Fill parameters and signal the drawing thread
|
||||
LockMutex(PBMap\Drawing\Mutex)
|
||||
LatLon2XY(@PBMap\TargetLocation, @PBMap\Drawing)
|
||||
;Convert X, Y in tile.decimal into real pixels
|
||||
PBMap\Position\x = PBMap\Drawing\Position\x * PBMap\TileSize
|
||||
PBMap\Position\y = PBMap\Drawing\Position\y * PBMap\TileSize
|
||||
MouseX = PBMap\Position\x + GadgetWidth(PBMap\Gadget) / 2 - GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||
MouseY = PBMap\Position\y + GadgetHeight(PBMap\Gadget) / 2 - GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
||||
PBMap\Position\x = (OldPx * MouseX) / OldMx
|
||||
PBMap\Position\y = (OldPy * MouseY) / OldMy
|
||||
;PBMap tile position in tile.decimal
|
||||
PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize
|
||||
PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize
|
||||
PBMap\Drawing\PassNb = 1
|
||||
XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation)
|
||||
UnlockMutex(PBMap\Drawing\Mutex)
|
||||
;Start drawing
|
||||
SignalSemaphore(PBMap\Drawing\Semaphore)
|
||||
;If CallBackLocation send Location to function
|
||||
If PBMap\CallBackLocation > 0
|
||||
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
|
||||
EndIf
|
||||
Case #PB_EventType_LeftButtonDown
|
||||
;Check if we select a marker
|
||||
MouseX = PBMap\Position\x - GadgetWidth(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||
@@ -906,15 +936,16 @@ Module PBMap
|
||||
PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize
|
||||
PBMap\Drawing\PassNb = 1
|
||||
XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation)
|
||||
;If CallBackLocation send Location to function
|
||||
If PBMap\CallBackLocation > 0
|
||||
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
|
||||
EndIf
|
||||
|
||||
UnlockMutex(PBMap\Drawing\Mutex)
|
||||
EndIf
|
||||
;Start drawing
|
||||
SignalSemaphore(PBMap\Drawing\Semaphore)
|
||||
;- ***
|
||||
;If CallBackLocation send Location to function
|
||||
If PBMap\CallBackLocation > 0
|
||||
CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation)
|
||||
EndIf
|
||||
PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||
PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
||||
EndIf
|
||||
@@ -931,12 +962,7 @@ Module PBMap
|
||||
XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation)
|
||||
UnlockMutex(PBMap\Drawing\Mutex)
|
||||
EndIf
|
||||
Case #PB_EventType_MouseWheel
|
||||
MouseX = PBMap\Position\x - GadgetWidth(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
|
||||
MouseY = PBMap\Position\y - GadgetHeight(PBMap\Gadget) / 2 + GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
|
||||
PBMap\Position\x
|
||||
Pow(2, PBMap::GetZoom() + 8)
|
||||
GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_WheelDelta)
|
||||
|
||||
EndSelect
|
||||
EndSelect
|
||||
EndSelect
|
||||
@@ -1088,8 +1114,9 @@ CompilerIf #PB_Compiler_IsMainFile
|
||||
CompilerEndIf
|
||||
|
||||
; IDE Options = PureBasic 5.42 LTS (Windows - x86)
|
||||
; CursorPosition = 1088
|
||||
; FirstLine = 1031
|
||||
; CursorPosition = 869
|
||||
; FirstLine = 858
|
||||
; Folding = ---------
|
||||
; EnableUnicode
|
||||
; EnableThread
|
||||
; EnableXP
|
Reference in New Issue
Block a user