SetZoomOnPosition bugfixed and double clic fast go

This commit is contained in:
djes
2016-09-09 12:33:46 +02:00
parent 5aba6510b5
commit c698760d7d

View File

@@ -107,7 +107,6 @@ Module PBMap
DeltaX.i DeltaX.i
DeltaY.i DeltaY.i
Dirty.i Dirty.i
PassNB.i
End.i End.i
EndStructure EndStructure
@@ -1025,7 +1024,6 @@ Module PBMap
;Convert X, Y in tile.decimal into real pixels ;Convert X, Y in tile.decimal into real pixels
PBMap\PixelCoordinates\x = PBMap\Drawing\TileCoordinates\x * PBMap\TileSize PBMap\PixelCoordinates\x = PBMap\Drawing\TileCoordinates\x * PBMap\TileSize
PBMap\PixelCoordinates\y = PBMap\Drawing\TileCoordinates\y * PBMap\TileSize PBMap\PixelCoordinates\y = PBMap\Drawing\TileCoordinates\y * PBMap\TileSize
PBMap\Drawing\PassNb = 1
PBMap\Redraw = #True PBMap\Redraw = #True
;Drawing() ;Drawing()
If PBMap\CallBackLocation > 0 If PBMap\CallBackLocation > 0
@@ -1111,31 +1109,45 @@ Module PBMap
EndProcedure EndProcedure
;Zoom on x, y position relative to the canvas gadget ;Zoom on x, y position relative to the canvas gadget
;TODO
Procedure SetZoomOnPosition(x, y, zoom) Procedure SetZoomOnPosition(x, y, zoom)
Protected MouseX.d, MouseY.d Protected MouseX.d, MouseY.d
Protected OldPx.d, OldPy.d, OldMx.d, OldMy.d, Px.d, Py.d Protected OldPx.d, OldPy.d, OldMx.d, OldMy.d, Px.d, Py.d
Protected CenterX = GadgetWidth(PBMap\Gadget) / 2, CenterY = GadgetHeight(PBMap\Gadget) / 2 Protected CenterX = GadgetWidth(PBMap\Gadget) / 2
Protected MapWidth = Pow(2.0, PBMap\Zoom) * PBMap\TileSize Protected CenterY = GadgetHeight(PBMap\Gadget) / 2
LatLon2Pixel(@PBMap\GeographicCoordinates, @PBMap\PixelCoordinates, PBMap\Zoom) x - CenterX
OldPx = PBMap\PixelCoordinates\x : OldPy = PBMap\PixelCoordinates\y y - CenterY
OldMx = OldPx + CenterX - x
OldMy = OldPy + CenterY - y
;*** First : Zoom ;*** First : Zoom
PBMap\Zoom = PBMap\Zoom + zoom PBMap\Zoom + zoom
If PBMap\Zoom > PBMap\ZoomMax : PBMap\Zoom = PBMap\ZoomMax : EndIf If PBMap\Zoom > PBMap\ZoomMax : PBMap\Zoom = PBMap\ZoomMax : EndIf
If PBMap\Zoom < PBMap\ZoomMin : PBMap\Zoom = PBMap\ZoomMin : EndIf If PBMap\Zoom < PBMap\ZoomMin : PBMap\Zoom = PBMap\ZoomMin : EndIf
LatLon2Pixel(@PBMap\GeographicCoordinates, @PBMap\PixelCoordinates, PBMap\Zoom) LatLon2Pixel(@PBMap\GeographicCoordinates, @PBMap\PixelCoordinates, PBMap\Zoom)
;*** If Zoom = 1
Debug OldMx - OldPx PBMap\PixelCoordinates\x + x
MouseX = PBMap\PixelCoordinates\X + CenterX - x PBMap\PixelCoordinates\y + y
MouseY = PBMap\PixelCoordinates\Y + CenterY - y ElseIf zoom = -1
;Cross-multiply to get the new view center PBMap\PixelCoordinates\x - x/2
PBMap\PixelCoordinates\x = (OldPx * MouseX) / OldMx PBMap\PixelCoordinates\y - y/2
PBMap\PixelCoordinates\y = (OldPy * MouseY) / OldMy EndIf
Pixel2LatLon(@PBMap\PixelCoordinates, @PBMap\GeographicCoordinates, PBMap\Zoom)
;Start drawing
PBMap\Redraw = #True
;If CallBackLocation send Location to function
If PBMap\CallBackLocation > 0
CallFunctionFast(PBMap\CallBackLocation, @PBMap\GeographicCoordinates)
EndIf
EndProcedure
;Go to x, y position relative to the canvas gadget
Procedure GotoPixelRel(x, y)
Protected CenterX = GadgetWidth(PBMap\Gadget) / 2
Protected CenterY = GadgetHeight(PBMap\Gadget) / 2
x - CenterX
y - CenterY
LatLon2Pixel(@PBMap\GeographicCoordinates, @PBMap\PixelCoordinates, PBMap\Zoom)
PBMap\PixelCoordinates\x + x
PBMap\PixelCoordinates\y + y
Pixel2LatLon(@PBMap\PixelCoordinates, @PBMap\GeographicCoordinates, PBMap\Zoom) Pixel2LatLon(@PBMap\PixelCoordinates, @PBMap\GeographicCoordinates, PBMap\Zoom)
;Start drawing ;Start drawing
PBMap\Drawing\PassNb = 1
PBMap\Redraw = #True PBMap\Redraw = #True
;If CallBackLocation send Location to function ;If CallBackLocation send Location to function
If PBMap\CallBackLocation > 0 If PBMap\CallBackLocation > 0
@@ -1164,6 +1176,8 @@ Module PBMap
Protected MarkerCoords.Coordinates, *Tile.Tile, MapWidth = Pow(2, PBMap\Zoom) * PBMap\TileSize Protected MarkerCoords.Coordinates, *Tile.Tile, MapWidth = Pow(2, PBMap\Zoom) * PBMap\TileSize
PBMap\Moving = #False PBMap\Moving = #False
Select EventType() Select EventType()
Case #PB_EventType_LeftDoubleClick
GotoPixelRel(GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX), GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY))
Case #PB_EventType_MouseWheel Case #PB_EventType_MouseWheel
If PBMap\Options\WheelMouseRelative If PBMap\Options\WheelMouseRelative
;Relative zoom (centered on the mouse) ;Relative zoom (centered on the mouse)
@@ -1217,7 +1231,6 @@ Module PBMap
CallFunctionFast(PBMap\CallBackLocation, @PBMap\GeographicCoordinates) CallFunctionFast(PBMap\CallBackLocation, @PBMap\GeographicCoordinates)
EndIf EndIf
EndIf EndIf
PBMap\Drawing\PassNb = 1
PBMap\Redraw = #True PBMap\Redraw = #True
PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX)
PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY)
@@ -1416,8 +1429,7 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.50 (Windows - x64) ; IDE Options = PureBasic 5.50 (Windows - x64)
; CursorPosition = 1129 ; CursorPosition = 8
; FirstLine = 1115
; Folding = ----------- ; Folding = -----------
; EnableThread ; EnableThread
; EnableXP ; EnableXP