Drawing pointer better handled + thyphoon code cleaning
This commit is contained in:
223
osm.pb
223
osm.pb
@@ -41,10 +41,19 @@ Module OSM
|
|||||||
Latitude.d
|
Latitude.d
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
;- Tile Structure
|
Structure Position
|
||||||
Structure Tile
|
|
||||||
x.d
|
x.d
|
||||||
y.d
|
y.d
|
||||||
|
EndStructure
|
||||||
|
|
||||||
|
Structure PixelPosition
|
||||||
|
x.i
|
||||||
|
y.i
|
||||||
|
EndStructure
|
||||||
|
|
||||||
|
;- Tile Structure
|
||||||
|
Structure Tile
|
||||||
|
Position.Position
|
||||||
OSMTileX.i
|
OSMTileX.i
|
||||||
OSMTileY.i
|
OSMTileY.i
|
||||||
OSMZoom.i
|
OSMZoom.i
|
||||||
@@ -53,12 +62,17 @@ Module OSM
|
|||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure DrawingParameters
|
Structure DrawingParameters
|
||||||
x.d
|
Position.Position
|
||||||
y.d
|
Canvas.i
|
||||||
OSMTileX.i
|
OSMTileX.i
|
||||||
OSMTileY.i
|
OSMTileY.i
|
||||||
OSMZoom.i
|
OSMZoom.i
|
||||||
Mutex.i
|
Mutex.i
|
||||||
|
TargetLocation.Location
|
||||||
|
CenterX.i
|
||||||
|
CenterY.i
|
||||||
|
DeltaX.i
|
||||||
|
DeltaY.i
|
||||||
Semaphore.i
|
Semaphore.i
|
||||||
Dirty.i
|
Dirty.i
|
||||||
PassNB.i
|
PassNB.i
|
||||||
@@ -70,11 +84,6 @@ Module OSM
|
|||||||
*Tile.Tile
|
*Tile.Tile
|
||||||
EndStructure
|
EndStructure
|
||||||
|
|
||||||
Structure Pixel
|
|
||||||
x.i
|
|
||||||
y.i
|
|
||||||
EndStructure
|
|
||||||
|
|
||||||
Structure ImgMemCach
|
Structure ImgMemCach
|
||||||
nImage.i
|
nImage.i
|
||||||
Usage.i
|
Usage.i
|
||||||
@@ -99,8 +108,8 @@ Module OSM
|
|||||||
|
|
||||||
CallBackLocation.i ; @Procedure(latitude.d,lontitude.d)
|
CallBackLocation.i ; @Procedure(latitude.d,lontitude.d)
|
||||||
|
|
||||||
Position.Pixel ; Actual focus Point coords in pixels
|
Position.PixelPosition ; Actual focus point coords in pixels (global)
|
||||||
MoveStartingPoint.Pixel ; Start mouse position coords when dragging the map
|
MoveStartingPoint.PixelPosition ; Start mouse position coords when dragging the map
|
||||||
|
|
||||||
ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/
|
ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/
|
||||||
ZoomMin.i ; Min Zoom supported by server
|
ZoomMin.i ; Min Zoom supported by server
|
||||||
@@ -283,6 +292,12 @@ Module OSM
|
|||||||
(Bool((a) >= (b)) * (a) + Bool((b) > (a)) * (b))
|
(Bool((a) >= (b)) * (a) + Bool((b) > (a)) * (b))
|
||||||
EndMacro
|
EndMacro
|
||||||
|
|
||||||
|
Procedure.d Distance(x1.d, y1.d, x2.d, y2.d)
|
||||||
|
Protected Result.d
|
||||||
|
Result = Sqr( (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))
|
||||||
|
ProcedureReturn Result
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
|
Procedure MapGadget(Gadget.i, X.i, Y.i, Width.i, Height.i)
|
||||||
If Gadget = #PB_Any
|
If Gadget = #PB_Any
|
||||||
OSM\Gadget = CanvasGadget(OSM\Gadget, X, Y, Width, Height)
|
OSM\Gadget = CanvasGadget(OSM\Gadget, X, Y, Width, Height)
|
||||||
@@ -293,27 +308,29 @@ Module OSM
|
|||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
;*** Converts coords to tile.decimal
|
;*** Converts coords to tile.decimal
|
||||||
Procedure LatLon2XY(*Location.Location, *Tile.Tile)
|
;Warning, structures used in parameters are not tested
|
||||||
|
Procedure LatLon2XY(*Location.Location, *Coords.Position)
|
||||||
Protected n.d = Pow(2.0, OSM\Zoom)
|
Protected n.d = Pow(2.0, OSM\Zoom)
|
||||||
Protected LatRad.d = Radian(*Location\Latitude)
|
Protected LatRad.d = Radian(*Location\Latitude)
|
||||||
*Tile\x = n * ( (*Location\Longitude + 180.0) / 360.0)
|
*Coords\x = n * ( (*Location\Longitude + 180.0) / 360.0)
|
||||||
*Tile\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0
|
*Coords\y = n * ( 1.0 - Log(Tan(LatRad) + 1.0/Cos(LatRad)) / #PI ) / 2.0
|
||||||
; Debug "Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude)
|
; Debug "Latitude : " + StrD(*Location\Latitude) + " ; Longitude : " + StrD(*Location\Longitude)
|
||||||
; Debug "Tile X : " + Str(*Tile\x) + " ; Tile Y : " + Str(*Tile\y)
|
; Debug "Coords X : " + Str(*Coords\x) + " ; Y : " + Str(*Coords\y)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
;*** Converts tile.decimal to coords
|
;*** Converts tile.decimal to coords
|
||||||
Procedure XY2LatLon(*Tile.Tile, *Location.Location)
|
;Warning, structures used in parameters are not tested
|
||||||
|
Procedure XY2LatLon(*Coords.Position, *Location.Location)
|
||||||
Protected n.d = Pow(2.0, OSM\Zoom)
|
Protected n.d = Pow(2.0, OSM\Zoom)
|
||||||
Protected LatitudeRad.d
|
Protected LatitudeRad.d
|
||||||
*Location\Longitude = *Tile\x / n * 360.0 - 180.0
|
*Location\Longitude = *Coords\x / n * 360.0 - 180.0
|
||||||
LatitudeRad = ATan(SinH(#PI * (1.0 - 2.0 * *Tile\y / n)))
|
LatitudeRad = ATan(SinH(#PI * (1.0 - 2.0 * *Coords\y / n)))
|
||||||
*Location\Latitude = Degree(LatitudeRad)
|
*Location\Latitude = Degree(LatitudeRad)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
; HaversineAlgorithm
|
; HaversineAlgorithm
|
||||||
; http://andrew.hedges.name/experiments/haversine/
|
; http://andrew.hedges.name/experiments/haversine/
|
||||||
Procedure.d HaversineInKM(*posA.Location,*posB.Location)
|
Procedure.d HaversineInKM(*posA.Location, *posB.Location)
|
||||||
Protected eQuatorialEarthRadius.d = 6378.1370;6372.795477598;
|
Protected eQuatorialEarthRadius.d = 6378.1370;6372.795477598;
|
||||||
Protected dlong.d = (*posB\Longitude - *posA\Longitude);
|
Protected dlong.d = (*posB\Longitude - *posA\Longitude);
|
||||||
Protected dlat.d = (*posB\Latitude - *posA\Latitude) ;
|
Protected dlat.d = (*posB\Latitude - *posA\Latitude) ;
|
||||||
@@ -325,17 +342,15 @@ Module OSM
|
|||||||
ProcedureReturn distance ;
|
ProcedureReturn distance ;
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.d HaversineInM(*posA.Location,*posB.Location)
|
Procedure.d HaversineInM(*posA.Location, *posB.Location)
|
||||||
ProcedureReturn (1000 * HaversineInKM(@*posA,@*posB));
|
ProcedureReturn (1000 * HaversineInKM(@*posA,@*posB));
|
||||||
EndProcedure
|
EndProcedure
|
||||||
Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.Pixel) ; TODO to Optimize
|
|
||||||
|
Procedure GetPixelCoordFromLocation(*Location.Location, *Pixel.PixelPosition) ; TODO to Optimize
|
||||||
Protected mapWidth.l = Pow(2,OSM\Zoom+8)
|
Protected mapWidth.l = Pow(2,OSM\Zoom+8)
|
||||||
Protected mapHeight.l = Pow(2,OSM\Zoom+8)
|
Protected mapHeight.l = Pow(2,OSM\Zoom+8)
|
||||||
Protected x1.l,y1.l
|
Protected x1.l,y1.l
|
||||||
|
|
||||||
Protected deltaX = OSM\Position\x - Int(OSM\Drawing\x) * OSM\TileSize ;Get the position into the tile
|
|
||||||
Protected deltaY = OSM\Position\y - Int(OSM\Drawing\y) * OSM\TileSize
|
|
||||||
|
|
||||||
; get x value
|
; get x value
|
||||||
x1 = (*Location\Longitude+180)*(mapWidth/360)
|
x1 = (*Location\Longitude+180)*(mapWidth/360)
|
||||||
; convert from degrees To radians
|
; convert from degrees To radians
|
||||||
@@ -353,8 +368,8 @@ Module OSM
|
|||||||
mercN = Log(Tan((#PI/4)+(latRad/2))) ;
|
mercN = Log(Tan((#PI/4)+(latRad/2))) ;
|
||||||
y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI));
|
y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI));
|
||||||
|
|
||||||
*Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1) - deltaX
|
*Pixel\x=GadgetWidth(OSM\Gadget)/2 - (x2-x1)
|
||||||
*Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1) - deltaY
|
*Pixel\y=GadgetHeight(OSM\Gadget)/2 - (y2-y1)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure LoadGpxFile(file.s)
|
Procedure LoadGpxFile(file.s)
|
||||||
@@ -489,21 +504,16 @@ Module OSM
|
|||||||
|
|
||||||
Procedure DrawTile(*Tile.Tile)
|
Procedure DrawTile(*Tile.Tile)
|
||||||
|
|
||||||
Protected x = *Tile\x
|
Protected x = *Tile\Position\x
|
||||||
Protected y = *Tile\y
|
Protected y = *Tile\Position\y
|
||||||
|
|
||||||
; Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX)
|
; Debug " Drawing tile nb " + " X : " + Str(*Tile\OSMTileX) + " Y : " + Str(*Tile\OSMTileX)
|
||||||
; Debug " at coords " + Str(x) + "," + Str(y)
|
; Debug " at coords " + Str(x) + "," + Str(y)
|
||||||
|
|
||||||
If IsImage(*Tile\nImage)
|
|
||||||
MovePathCursor(x, y)
|
MovePathCursor(x, y)
|
||||||
DrawVectorImage(ImageID(*Tile\nImage))
|
DrawVectorImage(ImageID(*Tile\nImage))
|
||||||
MovePathCursor(x, y)
|
MovePathCursor(x, y)
|
||||||
DrawVectorText(Str(x) + ", " + Str(y))
|
DrawVectorText(Str(x) + ", " + Str(y))
|
||||||
Else
|
|
||||||
; Debug "Image missing"
|
|
||||||
OSM\Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -511,18 +521,11 @@ Module OSM
|
|||||||
|
|
||||||
Protected x.i, y.i
|
Protected x.i, y.i
|
||||||
|
|
||||||
Protected tx = Int(*Drawing\x) ;Don't forget the Int() !
|
Protected tx = Int(*Drawing\Position\x) ;Don't forget the Int() !
|
||||||
Protected ty = Int(*Drawing\y)
|
Protected ty = Int(*Drawing\Position\y)
|
||||||
|
|
||||||
Protected CenterX = GadgetWidth(OSM\Gadget) / 2
|
Protected nx = *Drawing\CenterX / OSM\TileSize ;How many tiles around the point
|
||||||
Protected CenterY = GadgetHeight(OSM\Gadget) / 2
|
Protected ny = *Drawing\CenterY / OSM\TileSize
|
||||||
|
|
||||||
Protected nx = CenterX / OSM\TileSize ;How many tiles around the point
|
|
||||||
Protected ny = CenterY / OSM\TileSize
|
|
||||||
|
|
||||||
;Pixel shift, aka position in the tile
|
|
||||||
Protected DeltaX = *Drawing\x * OSM\TileSize - (tx * OSM\TileSize)
|
|
||||||
Protected DeltaY = *Drawing\y * OSM\TileSize - (ty * OSM\TileSize)
|
|
||||||
|
|
||||||
; Debug "Drawing tiles"
|
; Debug "Drawing tiles"
|
||||||
|
|
||||||
@@ -543,8 +546,8 @@ Module OSM
|
|||||||
OSM\TilesThreads()\Tile = *NewTile
|
OSM\TilesThreads()\Tile = *NewTile
|
||||||
|
|
||||||
;New tile parameters
|
;New tile parameters
|
||||||
\x = CenterX + x * OSM\TileSize - DeltaX
|
\Position\x = *Drawing\CenterX + x * OSM\TileSize - *Drawing\DeltaX
|
||||||
\y = CenterY + y * OSM\TileSize - DeltaY
|
\Position\y = *Drawing\CenterY + y * OSM\TileSize - *Drawing\DeltaY
|
||||||
\OSMTileX = tx + x
|
\OSMTileX = tx + x
|
||||||
\OSMTileY = ty + y
|
\OSMTileY = ty + y
|
||||||
\OSMZoom = OSM\Zoom
|
\OSMZoom = OSM\Zoom
|
||||||
@@ -558,7 +561,12 @@ Module OSM
|
|||||||
; Debug " Creating get image thread nb " + Str(\GetImageThread)
|
; Debug " Creating get image thread nb " + Str(\GetImageThread)
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
If IsImage(\nImage)
|
||||||
DrawTile(*NewTile)
|
DrawTile(*NewTile)
|
||||||
|
Else
|
||||||
|
; Debug "Image missing"
|
||||||
|
*Drawing\Dirty = #True ;Signals that this image is missing so we should have to redraw
|
||||||
|
EndIf
|
||||||
|
|
||||||
EndWith
|
EndWith
|
||||||
|
|
||||||
@@ -598,11 +606,9 @@ Module OSM
|
|||||||
|
|
||||||
Procedure DrawTrack(*Drawing.DrawingParameters)
|
Procedure DrawTrack(*Drawing.DrawingParameters)
|
||||||
|
|
||||||
Protected Pixel.Pixel
|
Protected Pixel.PixelPosition
|
||||||
Protected Location.Location
|
Protected Location.Location
|
||||||
|
|
||||||
Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * OSM\TileSize)
|
|
||||||
Protected DeltaY = *Drawing\y * OSM\TileSize - (Int(*Drawing\y) * OSM\TileSize)
|
|
||||||
Protected km.f, memKm.i
|
Protected km.f, memKm.i
|
||||||
|
|
||||||
If ListSize(OSM\track())>0
|
If ListSize(OSM\track())>0
|
||||||
@@ -618,12 +624,12 @@ Module OSM
|
|||||||
Location\Latitude=OSM\track()\Latitude
|
Location\Latitude=OSM\track()\Latitude
|
||||||
Location\Longitude=OSM\track()\Longitude
|
Location\Longitude=OSM\track()\Longitude
|
||||||
EndIf
|
EndIf
|
||||||
If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0
|
If *Drawing\TargetLocation\Latitude<>0 And *Drawing\TargetLocation\Longitude<>0
|
||||||
GetPixelCoordFromLocation(@OSM\track(),@Pixel)
|
GetPixelCoordFromLocation(@OSM\track(),@Pixel)
|
||||||
If ListIndex(OSM\track())=0
|
If ListIndex(OSM\track())=0
|
||||||
MovePathCursor(Pixel\X + DeltaX, Pixel\Y + DeltaY)
|
MovePathCursor(Pixel\X, Pixel\Y)
|
||||||
Else
|
Else
|
||||||
AddPathLine(Pixel\X + DeltaX, Pixel\Y + DeltaY)
|
AddPathLine(Pixel\X, Pixel\Y)
|
||||||
If Int(km)<>memKm
|
If Int(km)<>memKm
|
||||||
memKm=Int(km)
|
memKm=Int(km)
|
||||||
If OSM\Zoom>10
|
If OSM\Zoom>10
|
||||||
@@ -647,7 +653,6 @@ Module OSM
|
|||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
|
||||||
; Add a Marker To the Map
|
; Add a Marker To the Map
|
||||||
Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1)
|
Procedure AddMarker(Latitude.d,Longitude.d,color.l=-1, CallBackPointer.i = -1)
|
||||||
AddElement(OSM\Marker())
|
AddElement(OSM\Marker())
|
||||||
@@ -659,60 +664,72 @@ Module OSM
|
|||||||
|
|
||||||
; Draw all markers on the screen !
|
; Draw all markers on the screen !
|
||||||
Procedure DrawMarker(*Drawing.DrawingParameters)
|
Procedure DrawMarker(*Drawing.DrawingParameters)
|
||||||
Protected Pixel.Pixel
|
Protected Pixel.PixelPosition
|
||||||
|
|
||||||
Protected DeltaX = *Drawing\x * OSM\TileSize - (Int(*Drawing\x) * 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 > 0 And Pixel\Y > 0 And Pixel\X < GadgetWidth(OSM\Gadget) And Pixel\Y < GadgetHeight(OSM\Gadget) ; Only if visible ^_^
|
||||||
If OSM\Marker()\CallBackPointer > 0
|
If OSM\Marker()\CallBackPointer > 0
|
||||||
CallFunctionFast(OSM\Marker()\CallBackPointer, Pixel\X + DeltaX, Pixel\Y + DeltaY)
|
CallFunctionFast(OSM\Marker()\CallBackPointer, Pixel\X, Pixel\Y)
|
||||||
Else
|
Else
|
||||||
Pointer(Pixel\X + DeltaX, Pixel\Y + DeltaY, OSM\Marker()\color)
|
Pointer(Pixel\X, Pixel\Y, OSM\Marker()\color)
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
Next
|
Next
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure DrawingThread(*Drawing.DrawingParameters)
|
Procedure DrawingThread(*SharedDrawing.DrawingParameters)
|
||||||
|
|
||||||
|
Protected Drawing.DrawingParameters
|
||||||
|
Protected Px.d, Py.d
|
||||||
|
|
||||||
Repeat
|
Repeat
|
||||||
|
|
||||||
WaitSemaphore(*Drawing\Semaphore)
|
WaitSemaphore(*SharedDrawing\Semaphore)
|
||||||
|
|
||||||
; Debug "--------- Main drawing thread ------------"
|
; Debug "--------- Main drawing thread ------------"
|
||||||
|
|
||||||
Protected CenterX = GadgetWidth(OSM\Gadget) / 2
|
;Creates a copy of the structure to work with, and precalculus some values
|
||||||
Protected CenterY = GadgetHeight(OSM\Gadget) / 2
|
LockMutex(*SharedDrawing\Mutex)
|
||||||
|
CopyStructure(*SharedDrawing, @Drawing, DrawingParameters)
|
||||||
|
UnlockMutex(*SharedDrawing\Mutex)
|
||||||
|
|
||||||
*Drawing\Dirty = #False
|
Drawing\CenterX = GadgetWidth(OSM\Gadget) / 2
|
||||||
|
Drawing\CenterY = GadgetHeight(OSM\Gadget) / 2
|
||||||
|
;Pixel shift, aka position in the tile
|
||||||
|
Px = Drawing\Position\x : Py = Drawing\Position\y
|
||||||
|
Drawing\DeltaX = Px * OSM\TileSize - (Int(Px) * OSM\TileSize) ;Don't forget the Int() !
|
||||||
|
Drawing\DeltaY = Py * OSM\TileSize - (Int(Py) * OSM\TileSize)
|
||||||
|
Drawing\TargetLocation\Latitude = OSM\TargetLocation\Latitude
|
||||||
|
Drawing\TargetLocation\Longitude = OSM\TargetLocation\Longitude
|
||||||
|
|
||||||
|
Drawing\Dirty = #False
|
||||||
|
|
||||||
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
|
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
|
||||||
DrawTiles(*Drawing)
|
DrawTiles(@Drawing)
|
||||||
DrawTrack(*Drawing)
|
DrawTrack(@Drawing)
|
||||||
DrawMarker(*Drawing)
|
DrawMarker(@Drawing)
|
||||||
Pointer(CenterX, CenterY, #Red)
|
Pointer(Drawing\CenterX, Drawing\CenterY, #Red)
|
||||||
StopVectorDrawing()
|
StopVectorDrawing()
|
||||||
|
|
||||||
;- Redraw
|
;- Redraw
|
||||||
;If something was not correctly drawn, redraw after a while
|
;If something was not correctly drawn, redraw after a while
|
||||||
LockMutex(OSM\Drawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore)
|
LockMutex(*SharedDrawing\Mutex) ;Be sure that we're not modifying while moving (seems not useful, but it is, especially to clean the semaphore)
|
||||||
If *Drawing\Dirty
|
If Drawing\Dirty
|
||||||
; Debug "Something was dirty ! We try again to redraw"
|
; Debug "Something was dirty ! We try again to redraw"
|
||||||
;Delay(250)
|
;Delay(250)
|
||||||
*Drawing\PassNb + 1
|
Drawing\PassNb + 1
|
||||||
SignalSemaphore(*Drawing\Semaphore)
|
SignalSemaphore(*SharedDrawing\Semaphore)
|
||||||
Else
|
Else
|
||||||
;Clean the semaphore to avoid multiple unuseful redraws
|
;Clean the semaphore to avoid multiple unuseful redraws
|
||||||
Repeat : Until TrySemaphore(*Drawing\Semaphore) = 0
|
Repeat : Until TrySemaphore(*SharedDrawing\Semaphore) = 0
|
||||||
EndIf
|
EndIf
|
||||||
UnlockMutex(OSM\Drawing\Mutex)
|
UnlockMutex(*SharedDrawing\Mutex)
|
||||||
|
|
||||||
Until *Drawing\End
|
Until Drawing\End
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
@@ -728,8 +745,8 @@ Module OSM
|
|||||||
|
|
||||||
LatLon2XY(@OSM\TargetLocation, @OSM\Drawing)
|
LatLon2XY(@OSM\TargetLocation, @OSM\Drawing)
|
||||||
;Convert X, Y in tile.decimal into real pixels
|
;Convert X, Y in tile.decimal into real pixels
|
||||||
OSM\Position\X = OSM\Drawing\x * OSM\TileSize
|
OSM\Position\x = OSM\Drawing\Position\x * OSM\TileSize
|
||||||
OSM\Position\Y = OSM\Drawing\y * OSM\TileSize
|
OSM\Position\y = OSM\Drawing\Position\y * OSM\TileSize
|
||||||
OSM\Drawing\PassNb = 1
|
OSM\Drawing\PassNb = 1
|
||||||
;Start drawing
|
;Start drawing
|
||||||
SignalSemaphore(OSM\Drawing\Semaphore)
|
SignalSemaphore(OSM\Drawing\Semaphore)
|
||||||
@@ -800,8 +817,8 @@ Module OSM
|
|||||||
|
|
||||||
LatLon2XY(@OSM\TargetLocation, @OSM\Drawing)
|
LatLon2XY(@OSM\TargetLocation, @OSM\Drawing)
|
||||||
;Convert X, Y in tile.decimal into real pixels
|
;Convert X, Y in tile.decimal into real pixels
|
||||||
OSM\Position\X = OSM\Drawing\x * OSM\TileSize
|
OSM\Position\X = OSM\Drawing\Position\x * OSM\TileSize
|
||||||
OSM\Position\Y = OSM\Drawing\y * OSM\TileSize
|
OSM\Position\Y = OSM\Drawing\Position\y * OSM\TileSize
|
||||||
;*** Creates a drawing thread and fill parameters
|
;*** Creates a drawing thread and fill parameters
|
||||||
OSM\Drawing\PassNb = 1
|
OSM\Drawing\PassNb = 1
|
||||||
;Start drawing
|
;Start drawing
|
||||||
@@ -818,8 +835,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 Marker.Position
|
||||||
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
|
||||||
@@ -831,14 +847,13 @@ Module OSM
|
|||||||
Select EventType()
|
Select EventType()
|
||||||
Case #PB_EventType_LeftButtonDown
|
Case #PB_EventType_LeftButtonDown
|
||||||
;Check if we select a marker
|
;Check if we select a marker
|
||||||
Protected Pixel.Pixel
|
MouseX = OSM\Position\x - GadgetWidth(OSM\Gadget) / 2 + GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseX)
|
||||||
|
MouseY = OSM\Position\y - GadgetHeight(OSM\Gadget) / 2 + GetGadgetAttribute(OSM\Gadget, #PB_Canvas_MouseY)
|
||||||
ForEach OSM\Marker()
|
ForEach OSM\Marker()
|
||||||
GetPixelCoordFromLocation(@OSM\Marker()\Location, @Pixel)
|
LatLon2XY(@OSM\Marker()\Location, @Marker)
|
||||||
;LockMutex(OSM\Drawing\Mutex)
|
Marker\x * OSM\TileSize
|
||||||
DeltaX = OSM\Drawing\x * OSM\TileSize - (Int(OSM\Drawing\x) * OSM\TileSize)
|
Marker\y * OSM\TileSize
|
||||||
DeltaY = OSM\Drawing\y * OSM\TileSize - (Int(OSM\Drawing\y) * OSM\TileSize)
|
If Distance(Marker\x, Marker\y, MouseX, MouseY) < 8
|
||||||
;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())
|
OSM\EditMarkerIndex = ListIndex(OSM\Marker())
|
||||||
Break
|
Break
|
||||||
EndIf
|
EndIf
|
||||||
@@ -855,30 +870,26 @@ Module OSM
|
|||||||
If OSM\EditMarkerIndex > -1
|
If OSM\EditMarkerIndex > -1
|
||||||
SelectElement(OSM\Marker(), OSM\EditMarkerIndex)
|
SelectElement(OSM\Marker(), OSM\EditMarkerIndex)
|
||||||
Protected Tile.Tile
|
Protected Tile.Tile
|
||||||
LatLon2XY(@OSM\Marker()\Location, @Tile)
|
LatLon2XY(@OSM\Marker()\Location, @Marker)
|
||||||
; Debug MouseX
|
Marker\x + MouseX / OSM\TileSize
|
||||||
Tile\x + MouseX / OSM\TileSize
|
Marker\y + MouseY / OSM\TileSize
|
||||||
Tile\y + MouseY / OSM\TileSize
|
XY2LatLon(@Marker, @OSM\Marker()\Location)
|
||||||
XY2LatLon(@Tile, @OSM\Marker()\Location)
|
|
||||||
Else
|
Else
|
||||||
;New move values
|
;New move values
|
||||||
OSM\Position\x - MouseX
|
OSM\Position\x - MouseX
|
||||||
OSM\Position\y - MouseY
|
OSM\Position\y - MouseY
|
||||||
;-*** Fill parameters and signal the drawing thread
|
;-*** Fill parameters and signal the drawing thread
|
||||||
;OSM tile position in tile.decimal
|
|
||||||
LockMutex(OSM\Drawing\Mutex)
|
LockMutex(OSM\Drawing\Mutex)
|
||||||
OSM\Drawing\x = OSM\Position\x / OSM\TileSize
|
;OSM tile position in tile.decimal
|
||||||
OSM\Drawing\y = OSM\Position\y / OSM\TileSize
|
OSM\Drawing\Position\x = OSM\Position\x / OSM\TileSize
|
||||||
|
OSM\Drawing\Position\y = OSM\Position\y / OSM\TileSize
|
||||||
OSM\Drawing\PassNb = 1
|
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)
|
XY2LatLon(@OSM\Drawing, @OSM\TargetLocation)
|
||||||
;EndIf
|
|
||||||
;If CallBackLocation send Location to function
|
;If CallBackLocation send Location to function
|
||||||
If OSM\CallBackLocation > 0
|
If OSM\CallBackLocation > 0
|
||||||
CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation)
|
CallFunctionFast(OSM\CallBackLocation, @OSM\TargetLocation)
|
||||||
EndIf
|
EndIf
|
||||||
|
UnlockMutex(OSM\Drawing\Mutex)
|
||||||
EndIf
|
EndIf
|
||||||
;Start drawing
|
;Start drawing
|
||||||
SignalSemaphore(OSM\Drawing\Semaphore)
|
SignalSemaphore(OSM\Drawing\Semaphore)
|
||||||
@@ -892,10 +903,12 @@ Module OSM
|
|||||||
If OSM\EditMarkerIndex > -1
|
If OSM\EditMarkerIndex > -1
|
||||||
OSM\EditMarkerIndex = -1
|
OSM\EditMarkerIndex = -1
|
||||||
Else ;Move Map
|
Else ;Move Map
|
||||||
OSM\Drawing\x = OSM\Position\x / OSM\TileSize
|
LockMutex(OSM\Drawing\Mutex)
|
||||||
OSM\Drawing\y = OSM\Position\y / OSM\TileSize
|
OSM\Drawing\Position\x = OSM\Position\x / OSM\TileSize
|
||||||
|
OSM\Drawing\Position\y = OSM\Position\y / OSM\TileSize
|
||||||
; Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y)
|
; Debug "OSM\Position\x " + Str(OSM\Position\x) + " ; OSM\Position\y " + Str(OSM\Position\y)
|
||||||
XY2LatLon(@OSM\Drawing, @OSM\TargetLocation)
|
XY2LatLon(@OSM\Drawing, @OSM\TargetLocation)
|
||||||
|
UnlockMutex(OSM\Drawing\Mutex)
|
||||||
;Draw()
|
;Draw()
|
||||||
; Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y)
|
; Debug "OSM\Drawing\x " + StrD(OSM\Drawing\x) + " ; OSM\Drawing\y " + StrD(OSM\Drawing\y)
|
||||||
;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude))
|
;SetGadgetText(#String_1, StrD(OSM\TargetLocation\Latitude))
|
||||||
@@ -1042,8 +1055,8 @@ CompilerIf #PB_Compiler_IsMainFile
|
|||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
|
|
||||||
; IDE Options = PureBasic 5.42 LTS (Windows - x64)
|
; IDE Options = PureBasic 5.42 LTS (Windows - x64)
|
||||||
; CursorPosition = 605
|
; CursorPosition = 697
|
||||||
; FirstLine = 598
|
; FirstLine = 683
|
||||||
; Folding = -------
|
; Folding = -------
|
||||||
; EnableUnicode
|
; EnableUnicode
|
||||||
; EnableThread
|
; EnableThread
|
||||||
|
Reference in New Issue
Block a user