Added marker move by thyphoon

This commit is contained in:
djes
2016-07-28 21:39:37 +02:00
parent 3cca540852
commit 489e9651b6

128
osm.pb
View File

@@ -29,7 +29,7 @@ DeclareModule OSM
Declare ZoomToArea() Declare ZoomToArea()
Declare SetCallBackLocation(*CallBackLocation) Declare SetCallBackLocation(*CallBackLocation)
Declare LoadGpxFile(file.s); Declare LoadGpxFile(file.s);
Declare AddMarker(Latitude.d,Longitude.d,color.l=-1) Declare AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1)
EndDeclareModule EndDeclareModule
Module OSM Module OSM
@@ -85,8 +85,9 @@ Module OSM
EndStructure EndStructure
Structure Marker Structure Marker
Location.Location Location.Location ; Latitude and Longitude from Marker
color.l color.l ; Color Marker
CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (You must use VectorDrawing lib)
EndStructure EndStructure
;-OSM Structure ;-OSM Structure
@@ -236,8 +237,8 @@ Module OSM
OSM\Dirty = #False OSM\Dirty = #False
OSM\Drawing\Mutex = CreateMutex() OSM\Drawing\Mutex = CreateMutex()
OSM\Drawing\Semaphore = CreateSemaphore() OSM\Drawing\Semaphore = CreateSemaphore()
OSM\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected
;- Proxy details ;- Proxy details
Global Proxy = #False Global Proxy = #False
@@ -599,11 +600,12 @@ Module OSM
; Add a Marker To the Map ; Add a Marker To the Map
Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1) Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1)
AddElement(OSM\Marker()) AddElement(OSM\Marker())
OSM\Marker()\Location\Latitude=Latitude OSM\Marker()\Location\Latitude=Latitude
OSM\Marker()\Location\Longitude=Longitude OSM\Marker()\Location\Longitude=Longitude
OSM\Marker()\color=color OSM\Marker()\color=color
OSM\Marker()\CallBackPointer = CallBackPointer
EndProcedure EndProcedure
; Draw all markers on the screen ! ; Draw all markers on the screen !
@@ -614,10 +616,14 @@ Module OSM
Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize) Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize)
ForEach OSM\Marker() ForEach OSM\Marker()
If OSM\Marker()\Location\Latitude<>0 And OSM\Marker()\Location\Longitude<>0 If OSM\Marker()\Location\Latitude <> 0 And OSM\Marker()\Location\Longitude <> 0
GetPixelCoordFromLocation(OSM\Marker()\Location,@Pixel) GetPixelCoordFromLocation(OSM\Marker()\Location, @Pixel)
If Pixel\X+ DeltaX>0 And Pixel\Y+ DeltaY>0 And Pixel\X+ DeltaX<GadgetWidth(OSM\Gadget) And Pixel\Y<GadgetHeight(OSM\Gadget) ; Only if visible ^_^ If Pixel\X + DeltaX > 0 And Pixel\Y + DeltaY > 0 And Pixel\X + DeltaX < GadgetWidth(OSM\Gadget) And Pixel\Y < GadgetHeight(OSM\Gadget) ; Only if visible ^_^
Pointer(Pixel\X+ DeltaX,Pixel\Y+ DeltaY,OSM\Marker()\color) If OSM\Marker()\CallBackPointer > 0
CallFunctionFast(OSM\Marker()\CallBackPointer, Pixel\X + DeltaX, Pixel\Y + DeltaY)
Else
Pointer(Pixel\X + DeltaX, Pixel\Y + DeltaY, OSM\Marker()\color)
EndIf
EndIf EndIf
EndIf EndIf
Next Next
@@ -771,6 +777,7 @@ Module OSM
Protected Gadget.i Protected Gadget.i
Protected MouseX.i, MouseY.i Protected MouseX.i, MouseY.i
Protected OldX.i, OldY.i Protected OldX.i, OldY.i
Protected DeltaX.d, DeltaY.d
Protected *Drawing.DrawingParameters Protected *Drawing.DrawingParameters
If IsGadget(OSM\Gadget) And GadgetType(OSM\Gadget) = #PB_GadgetType_Canvas If IsGadget(OSM\Gadget) And GadgetType(OSM\Gadget) = #PB_GadgetType_Canvas
@@ -781,6 +788,19 @@ Module OSM
Case OSM\Gadget Case OSM\Gadget
Select EventType() Select EventType()
Case #PB_EventType_LeftButtonDown Case #PB_EventType_LeftButtonDown
;Check if we select a marker
Protected Pixel.Pixel
ForEach OSM\Marker()
GetPixelCoordFromLocation(@OSM\Marker()\Location, @Pixel)
;LockMutex(OSM\Drawing\Mutex)
DeltaX = OSM\Drawing\x * OSM\TileSize - (Int(OSM\Drawing\x) * OSM\TileSize)
DeltaY = OSM\Drawing\y * OSM\TileSize - (Int(OSM\Drawing\y) * OSM\TileSize)
;UnlockMutex(OSM\Drawing\Mutex)
If Pixel\X + DeltaX > GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - 4 And Pixel\X + DeltaX < GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) + 4 And Pixel\Y + DeltaY > GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - 4 And Pixel\Y + DeltaY < GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) + 4
OSM\EditMarkerIndex = ListIndex(OSM\Marker())
Break
EndIf
Next
;Mem cursor Coord ;Mem cursor Coord
OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX)
OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY)
@@ -789,44 +809,56 @@ Module OSM
MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x MouseX = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) - OSM\MoveStartingPoint\x
MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y MouseY = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) - OSM\MoveStartingPoint\y
OSM\Moving = #True OSM\Moving = #True
;Old move values ;move Marker
OldX = OSM\Position\x If OSM\EditMarkerIndex > -1
OldY = OSM\Position\y SelectElement(OSM\Marker(), OSM\EditMarkerIndex)
;New move values Protected Tile.Tile
OSM\Position\x - MouseX LatLon2XY(@OSM\Marker()\Location, @Tile)
OSM\Position\y - MouseY Debug MouseX
;-*** Fill parameters and signal the drawing thread Tile\x + MouseX / OSM\TileSize
;OSM tile position in tile.decimal Tile\y + MouseY / OSM\TileSize
LockMutex(OSM\Drawing\Mutex) XY2LatLon(@Tile, @OSM\Marker()\Location)
OSM\Drawing\x = OSM\Position\x / OSM\TileSize Else
OSM\Drawing\y = OSM\Position\y / OSM\TileSize ;New move values
OSM\Drawing\PassNb = 1 OSM\Position\x - MouseX
UnlockMutex(OSM\Drawing\Mutex) OSM\Position\y - MouseY
;Moved to a new tile ? ;-*** Fill parameters and signal the drawing thread
;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize)) ;OSM tile position in tile.decimal
XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) LockMutex(OSM\Drawing\Mutex)
;EndIf OSM\Drawing\x = OSM\Position\x / OSM\TileSize
OSM\Drawing\y = OSM\Position\y / OSM\TileSize
OSM\Drawing\PassNb = 1
UnlockMutex(OSM\Drawing\Mutex)
;Moved to a new tile ?
;If (Int(OSM\Position\x / OSM\TileSize)) <> (Int(OldX / OSM\TileSize)) Or (Int(OSM\Position\y / OSM\TileSize)) <> (Int(OldY / OSM\TileSize))
XY2LatLon(@OSM\Drawing, @OSM\TargetLocation)
;EndIf
;If CallBackLocation send Location to function
If OSM\CallBackLocation > 0
CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation)
EndIf
EndIf
;Start drawing ;Start drawing
SignalSemaphore(OSM\Drawing\Semaphore) SignalSemaphore(OSM\Drawing\Semaphore)
;- *** ;- ***
OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX) OSM\MoveStartingPoint\x = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX)
OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY) OSM\MoveStartingPoint\y = GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY)
;If CallBackLocation send Location to function
If OSM\CallBackLocation>0
CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation)
EndIf
EndIf EndIf
Case #PB_EventType_LeftButtonUp Case #PB_EventType_LeftButtonUp
OSM\Moving = #False OSM\Moving = #False
OSM\MoveStartingPoint\x = - 1 OSM\MoveStartingPoint\x = - 1
OSM\Drawing\x = OSM\Position\x / OSM\TileSize If OSM\EditMarkerIndex > -1
OSM\Drawing\y = OSM\Position\y / OSM\TileSize OSM\EditMarkerIndex = -1
Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y) Else ;Move Map
XY2LatLon(@OSM\Drawing, @OSM\TargetLocation) OSM\Drawing\x = OSM\Position\x / OSM\TileSize
;Draw() OSM\Drawing\y = OSM\Position\y / OSM\TileSize
Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y) Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y)
;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude)) XY2LatLon(@OSM\Drawing, @OSM\TargetLocation)
;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude)) ;Draw()
Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y)
;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude))
;SetGadgetText(#String_0, StrD(OSM\TargetLocation\Longitude))
EndIf
EndSelect EndSelect
EndSelect EndSelect
EndSelect EndSelect
@@ -874,6 +906,18 @@ CompilerIf #PB_Compiler_IsMainFile
ProcedureReturn 0 ProcedureReturn 0
EndProcedure EndProcedure
Procedure MyPointer(x.i, y.i)
Protected color.l
color=RGBA(0, 255, 0, 255)
VectorSourceColor(color)
MovePathCursor(x, y)
AddPathLine(-16,-32,#PB_Path_Relative)
AddPathCircle(16,0,16,180,0,#PB_Path_Relative)
AddPathLine(-16,32,#PB_Path_Relative)
VectorSourceColor(color)
FillPath(#PB_Path_Preserve):VectorSourceColor(RGBA(0, 0, 0, 255)):StrokePath(1)
EndProcedure
Procedure ResizeAll() Procedure ResizeAll()
ResizeGadget(#Map,10,10,WindowWidth(#Window_0)-198,WindowHeight(#Window_0)-59) ResizeGadget(#Map,10,10,WindowWidth(#Window_0)-198,WindowHeight(#Window_0)-59)
ResizeGadget(#Text_1,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore) ResizeGadget(#Text_1,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
@@ -918,6 +962,8 @@ CompilerIf #PB_Compiler_IsMainFile
Define pfValue.d Define pfValue.d
OSM::SetLocation(49.04599, 2.03347, 17) OSM::SetLocation(49.04599, 2.03347, 17)
OSM::SetCallBackLocation(@UpdateLocation()) OSM::SetCallBackLocation(@UpdateLocation())
OSM::AddMarker(49.0446828398,2.0349812508,-1,@MyPointer())
Repeat Repeat
Event = WaitWindowEvent() Event = WaitWindowEvent()
@@ -954,8 +1000,8 @@ CompilerIf #PB_Compiler_IsMainFile
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Windows - x64) ; IDE Options = PureBasic 5.42 LTS (Windows - x64)
; CursorPosition = 723 ; CursorPosition = 850
; FirstLine = 671 ; FirstLine = 771
; Folding = ------ ; Folding = ------
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread