From 9643a6ba1c2a6376a6a5fd9cda2c1830e8e06cb7 Mon Sep 17 00:00:00 2001 From: djes Date: Thu, 4 Aug 2016 10:35:44 +0200 Subject: [PATCH 1/5] Lil commit to update from thyphoon --- PBMap.pb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/PBMap.pb b/PBMap.pb index 18247e1..fd458a1 100644 --- a/PBMap.pb +++ b/PBMap.pb @@ -908,7 +908,13 @@ Module PBMap MyDebug("PBMap\Drawing\Position\x " + Str(PBMap\Drawing\Position\x) + " ; PBMap\Drawing\Position\y " + Str(PBMap\Drawing\Position\y) ) XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation) UnlockMutex(PBMap\Drawing\Mutex) - EndIf + 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 @@ -1039,10 +1045,10 @@ CompilerIf #PB_Compiler_IsMainFile Case #Button_5 PBMap::SetZoom( - 1) Case #Gdt_LoadGpx - PBMap::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) - PBMap::ZoomToArea() ; <-To center the view, and to viex all the track + PBMap::LoadGpxFile(OpenFileRequester("Choose a file to load", "", "*.gpx", 0)) + PBMap::ZoomToArea() ; <-To center the view, and zoom on the tracks Case #Gdt_AddMarker - PBMap:: AddMarker(ValD(GetGadgetText(#String_0)),ValD(GetGadgetText(#String_1)),RGBA(Random(255),Random(255),Random(255),255)) + PBMap:: AddMarker(ValD(GetGadgetText(#String_0)), ValD(GetGadgetText(#String_1)), RGBA(Random(255), Random(255), Random(255),255)) EndSelect Case #PB_Event_SizeWindow ResizeAll() @@ -1054,7 +1060,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 11 +; CursorPosition = 914 +; FirstLine = 880 ; Folding = -------- ; EnableUnicode ; EnableThread From 7901b35dedb26787cd89f587ff0b786dbb02ec27 Mon Sep 17 00:00:00 2001 From: djes Date: Thu, 4 Aug 2016 17:51:05 +0200 Subject: [PATCH 2/5] Relative mousewheel zoom Centered on the mouse... --- PBMap.pb | 81 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/PBMap.pb b/PBMap.pb index 9089b7f..f37ba11 100644 --- a/PBMap.pb +++ b/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) @@ -121,25 +121,25 @@ Module PBMap Font.i ; Font to uses when write on the map TargetLocation.Location ; Latitude and Longitude from focus point Drawing.DrawingParameters ; Drawing parameters based on focus point - ; + ; CallBackLocation.i ; @Procedure(latitude.d,lontitude.d) CallBackMainPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib) - ; + ; Position.PixelPosition ; Actual focus point coords in pixels (global) MoveStartingPoint.PixelPosition ; Start mouse position coords when dragging the map - ; + ; ServerURL.s ; Web URL ex: http://tile.openstreetmap.org/ ZoomMin.i ; Min Zoom supported by server ZoomMax.i ; Max Zoom supported by server Zoom.i ; Current zoom TileSize.i ; Tile size downloaded on the server ex : 256 - ; + ; HDDCachePath.S ; Path where to load and save tiles downloaded from server MemCache.TileMemCach ; Images in memory cache - ; + ; Moving.i Dirty.i ; To signal that drawing need a refresh - ; + ; MainDrawingThread.i List TilesThreads.TileThread() ; @@ -263,7 +263,7 @@ Module PBMap ClosePreferences() EndIf curl_global_init(#CURL_GLOBAL_WIN32); - ;- Main drawing thread launching + ;- Main drawing thread launching PBMap\MainDrawingThread = CreateThread(@DrawingThread(), @PBMap\Drawing) If PBMap\MainDrawingThread = 0 Error("MapGadget : can't create main drawing thread.") @@ -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 @@ -371,7 +371,7 @@ Module PBMap x2 = (PBMap\TargetLocation\Longitude+180)*(mapWidth/360) ; convert from degrees To radians latRad = PBMap\TargetLocation\Latitude*#PI/180; - ; get y value + ; get y value mercN = Log(Tan((#PI/4)+(latRad/2))) y2 = (mapHeight/2)-(mapWidth*mercN/(2*#PI)); *Pixel\x=GadgetWidth(PBMap\Gadget)/2 - (x2-x1) @@ -852,10 +852,10 @@ Module PBMap ProcedureReturn Value EndProcedure - + 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 @@ -1025,7 +1051,7 @@ CompilerIf #PB_Compiler_IsMainFile LoadFont(0, "Wingdings", 12) LoadFont(1, "Arial", 12, #PB_Font_Bold) - + TextGadget(#Text_1, 530, 50, 60, 15, "Movements") ButtonGadget(#Gdt_Left, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Gdt_Left, FontID(0)) ButtonGadget(#Gdt_Right, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Gdt_Right, FontID(0)) @@ -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 \ No newline at end of file From 2a25fd6e9fdc9c624854cdb5586bbae3c956d3a9 Mon Sep 17 00:00:00 2001 From: djes Date: Thu, 4 Aug 2016 17:52:17 +0200 Subject: [PATCH 3/5] proxy off... --- PBMap.pb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PBMap.pb b/PBMap.pb index f37ba11..62e1205 100644 --- a/PBMap.pb +++ b/PBMap.pb @@ -27,7 +27,7 @@ DeclareModule PBMap ;-Show debug infos Global Verbose = #False ;-Proxy ON/OFF - Global Proxy = #True + Global Proxy = #False 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) @@ -1114,8 +1114,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 869 -; FirstLine = 858 +; CursorPosition = 28 +; FirstLine = 19 ; Folding = --------- ; EnableUnicode ; EnableThread From 51524d0a33097d44f5c250b036ac566237c96602 Mon Sep 17 00:00:00 2001 From: djes Date: Fri, 5 Aug 2016 11:20:08 +0200 Subject: [PATCH 4/5] WheelMouse zoom and minors modifications in prefs and code cleaning --- PBMap.pb | 173 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 77 deletions(-) diff --git a/PBMap.pb b/PBMap.pb index 62e1205..f6f955a 100644 --- a/PBMap.pb +++ b/PBMap.pb @@ -26,7 +26,6 @@ UsePNGImageEncoder() DeclareModule PBMap ;-Show debug infos Global Verbose = #False - ;-Proxy ON/OFF Global Proxy = #False Declare InitPBMap() Declare SetMapServer(ServerURL.s="http://tile.openstreetmap.org/",TileSize.l=256,ZoomMin.l=0,ZoomMax.l=18) @@ -115,6 +114,10 @@ Module PBMap CallBackPointer.i ; @Procedure(X.i, Y.i) to DrawPointer (you must use VectorDrawing lib) EndStructure + Structure Option + WheelMouseRelative.i + EndStructure + ;-PBMap Structure Structure PBMap Gadget.i ; Canvas Gadget Id @@ -137,15 +140,17 @@ Module PBMap HDDCachePath.S ; Path where to load and save tiles downloaded from server MemCache.TileMemCach ; Images in memory cache ; - Moving.i + Moving.i ; Dirty.i ; To signal that drawing need a refresh ; - MainDrawingThread.i - List TilesThreads.TileThread() - ; + MainDrawingThread.i ; + List TilesThreads.TileThread() ; + ; List track.Location() ; To display a GPX track List Marker.Marker() ; To diplay marker - EditMarkerIndex.l + EditMarkerIndex.l ; + ; + Options.option ; EndStructure Global PBMap.PBMap, Null.i @@ -163,7 +168,7 @@ Module PBMap EndIf EndProcedure - ;- *** CURL specific *** + ;- *** CURL specific ; (program has To be compiled in console format for curl debug infos) IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl @@ -239,31 +244,34 @@ Module PBMap PBMap\Drawing\Semaphore = CreateSemaphore() PBMap\EditMarkerIndex = -1 ;<- You must initialize with No Marker selected PBMap\Font = LoadFont(#PB_Any, "Arial", 20, #PB_Font_Bold) - ;- Proxy details + ;-Options + PBMap\Options\WheelMouseRelative = #True + ;-Preferences ;Use this to create and customize your preferences file for the first time - ; Result = CreatePreferences(GetHomeDirectory() + "PBMap.prefs") - ; If Proxy - ; PreferenceGroup("PROXY") - ; WritePreferenceString("ProxyURL", "myproxy.fr") - ; WritePreferenceString("ProxyPort", "myproxyport") - ; WritePreferenceString("ProxyUser", "myproxyname") - ; EndIf - ; If Result - ; ClosePreferences() - ; EndIf - Result = OpenPreferences(GetHomeDirectory() + "PBMap.prefs") + ; CreatePreferences(GetHomeDirectory() + "PBMap.prefs") + ; ;Or this to modify + ; ;OpenPreferences(GetHomeDirectory() + "PBMap.prefs") + ; ;Or this + ; ;RunProgram("notepad.exe", GetHomeDirectory() + "PBMap.prefs", GetHomeDirectory()) + ; PreferenceGroup("PROXY") + ; WritePreferenceInteger("Proxy", #True) + ; WritePreferenceString("ProxyURL", "myproxy.fr") + ; WritePreferenceString("ProxyPort", "myproxyport") + ; WritePreferenceString("ProxyUser", "myproxyname") + ; WritePreferenceString("ProxyPass", "myproxypass") ;TODO !Warning! !not encoded! + ; ClosePreferences() + OpenPreferences(GetHomeDirectory() + "PBMap.prefs") + PreferenceGroup("PROXY") + Proxy = ReadPreferenceInteger("Proxy", #False) If Proxy - PreferenceGroup("PROXY") Global ProxyURL$ = ReadPreferenceString("ProxyURL", "") ;InputRequester("ProxyServer", "Do you use a Proxy Server? Then enter the full url:", "") Global ProxyPort$ = ReadPreferenceString("ProxyPort", "") ;InputRequester("ProxyPort" , "Do you use a specific port? Then enter it", "") Global ProxyUser$ = ReadPreferenceString("ProxyUser", "") ;InputRequester("ProxyUser" , "Do you use a user name? Then enter it", "") - Global ProxyPassword$ = InputRequester("ProxyPass", "Do you use a password ? Then enter it", "") + Global ProxyPassword$ = InputRequester("ProxyPass", "Do you use a password ? Then enter it", "") ;TODO EndIf - If Result - ClosePreferences() - EndIf - curl_global_init(#CURL_GLOBAL_WIN32); - ;- Main drawing thread launching + ClosePreferences() + curl_global_init(#CURL_GLOBAL_WIN32) + ;- Main drawing thread launching PBMap\MainDrawingThread = CreateThread(@DrawingThread(), @PBMap\Drawing) If PBMap\MainDrawingThread = 0 Error("MapGadget : can't create main drawing thread.") @@ -573,18 +581,18 @@ Module PBMap Next EndProcedure - Procedure Pointer(x.i, y.i, color.l = #Red) - color=RGBA(255, 0, 0, 255) + Procedure Pointer(x.i, y.i, color.l = 0) VectorSourceColor(color) MovePathCursor(x, y) - AddPathLine(-8,-16,#PB_Path_Relative) - AddPathCircle(8,0,8,180,0,#PB_Path_Relative) - AddPathLine(-8,16,#PB_Path_Relative) + AddPathLine(-8, -16, #PB_Path_Relative) + AddPathCircle(8, 0, 8, 180, 0, #PB_Path_Relative) + AddPathLine(-8, 16, #PB_Path_Relative) ;FillPath(#PB_Path_Preserve) ;ClipPath(#PB_Path_Preserve) - AddPathCircle(0,-16,5,0,360,#PB_Path_Relative) + AddPathCircle(0, -16, 5, 0, 360, #PB_Path_Relative) VectorSourceColor(color) - FillPath(#PB_Path_Preserve):VectorSourceColor(RGBA(0, 0, 0, 255)):StrokePath(1) + FillPath(#PB_Path_Preserve):VectorSourceColor(color);RGBA(0, 0, 0, 255)) + StrokePath(1) EndProcedure Procedure TrackPointer(x.i, y.i,dist.l) @@ -627,7 +635,7 @@ Module PBMap StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) ;Draw Distance ForEach PBMap\track() - ;-Test Distance + ;Distance test If ListIndex(PBMap\track())=0 Location\Latitude=PBMap\track()\Latitude Location\Longitude=PBMap\track()\Longitude @@ -707,7 +715,7 @@ Module PBMap If PBMap\CallBackMainPointer > 0 CallFunctionFast(PBMap\CallBackMainPointer, Drawing\CenterX, Drawing\CenterY) Else - Pointer(Drawing\CenterX, Drawing\CenterY, #Red) + Pointer(Drawing\CenterX, Drawing\CenterY, RGBA($FF, 0, 0, $FF)) EndIf StopVectorDrawing() ;Redraw @@ -818,7 +826,43 @@ Module PBMap If PBMap\CallBackLocation > 0 CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation) EndIf - EndProcedure + EndProcedure + + ;Zoom on x, y position relative to the canvas gadget + Procedure SetZoomOnPosition(x, y, zoom) + Protected MouseX.d, MouseY.d + Protected OldPx.d, OldPy.d, OldMx.d, OldMy.d + ;Fast and dirty code + OldPx = PBMap\Position\x : OldPy = PBMap\Position\y + OldMx = OldPx + GadgetWidth(PBMap\Gadget) / 2 - x + OldMy = OldPy + GadgetHeight(PBMap\Gadget) / 2 - y + PBMap\Zoom = PBMap\Zoom + zoom + If PBMap\Zoom > PBMap\ZoomMax : PBMap\Zoom = PBMap\ZoomMax : EndIf + If PBMap\Zoom < PBMap\ZoomMin : PBMap\Zoom = PBMap\ZoomMin : EndIf + ;Centered Zoom + 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 - x + MouseY = PBMap\Position\y + GadgetHeight(PBMap\Gadget) / 2 - y + ;Cross-multiply to get the new center + 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 + EndProcedure Procedure SetCallBackLocation(CallBackLocation.i) PBMap\CallBackLocation = CallBackLocation @@ -855,9 +899,8 @@ Module PBMap Procedure Event(Event.l) Protected Gadget.i - Protected MouseX.i, MouseY.i, OldPx.d, OldPy.d, OldMx.d, OldMy.d + Protected MouseX.i, MouseY.i Protected Marker.Position - Protected *Drawing.DrawingParameters If IsGadget(PBMap\Gadget) And GadgetType(PBMap\Gadget) = #PB_GadgetType_Canvas Select Event Case #PB_Event_Gadget ;{ @@ -866,37 +909,13 @@ Module PBMap Case PBMap\Gadget Select EventType() Case #PB_EventType_MouseWheel - ;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 + If PBMap\Options\WheelMouseRelative + ;Relative zoom (centered on the mouse) + SetZoomOnPosition(GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX), GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY), GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_WheelDelta)) + Else + ;Absolute zoom (centered on the center of the map) + SetZoom(GetGadgetAttribute(PBMap\Gadget,#PB_Canvas_WheelDelta), #PB_Relative) + 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) @@ -914,11 +933,12 @@ Module PBMap PBMap\MoveStartingPoint\x = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) PBMap\MoveStartingPoint\y = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) Case #PB_EventType_MouseMove + ;If a move has been initiated by a left click If PBMap\MoveStartingPoint\x <> - 1 MouseX = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseX) - PBMap\MoveStartingPoint\x MouseY = GetGadgetAttribute(PBMap\Gadget, #PB_Canvas_MouseY) - PBMap\MoveStartingPoint\y PBMap\Moving = #True - ;move Marker + ;If it's marker move If PBMap\EditMarkerIndex > -1 SelectElement(PBMap\Marker(), PBMap\EditMarkerIndex) LatLon2XY(@PBMap\Marker()\Location, @Marker) @@ -929,19 +949,17 @@ Module PBMap ;New move values PBMap\Position\x - MouseX PBMap\Position\y - MouseY - ;-*** Fill parameters and signal the drawing thread + ;Fill parameters and signal the drawing thread LockMutex(PBMap\Drawing\Mutex) ;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) EndIf ;Start drawing SignalSemaphore(PBMap\Drawing\Semaphore) - ;- *** ;If CallBackLocation send Location to function If PBMap\CallBackLocation > 0 CallFunctionFast(PBMap\CallBackLocation, @PBMap\TargetLocation) @@ -952,9 +970,11 @@ Module PBMap Case #PB_EventType_LeftButtonUp PBMap\Moving = #False PBMap\MoveStartingPoint\x = - 1 + ;Stop marker move If PBMap\EditMarkerIndex > -1 PBMap\EditMarkerIndex = -1 - Else ;Move Map + Else + ;Stop map move LockMutex(PBMap\Drawing\Mutex) PBMap\Drawing\Position\x = PBMap\Position\x / PBMap\TileSize PBMap\Drawing\Position\y = PBMap\Position\y / PBMap\TileSize @@ -962,7 +982,6 @@ Module PBMap XY2LatLon(@PBMap\Drawing, @PBMap\TargetLocation) UnlockMutex(PBMap\Drawing\Mutex) EndIf - EndSelect EndSelect EndSelect @@ -1114,8 +1133,8 @@ CompilerIf #PB_Compiler_IsMainFile CompilerEndIf ; IDE Options = PureBasic 5.42 LTS (Windows - x86) -; CursorPosition = 28 -; FirstLine = 19 +; CursorPosition = 1120 +; FirstLine = 1077 ; Folding = --------- ; EnableUnicode ; EnableThread From 648231a5b2012c725301b5a5906fca486ac5fe64 Mon Sep 17 00:00:00 2001 From: djes Date: Fri, 5 Aug 2016 11:34:15 +0200 Subject: [PATCH 5/5] Update README.md --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4070e5b..39cd9e3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # PBMap -Purebasic opensource tiled map software -Created to develop and test our tiles applications for PureBasic +Purebasic open source tiled map software. +Created to develop and test tiles applications in PureBasic. + +This code is free ! + +Officials forums topics here : +http://www.purebasic.fr/english/viewtopic.php?f=27&t=66320 (english) +http://www.purebasic.fr/french/viewtopic.php?f=3&t=16160 (french) + +Contributors : +Thyphoon +djes +Progi1984