Add resize to Window Exemple

You can resize Window with Exemple and all gadget change his position
function window size.
This commit is contained in:
2016-07-23 20:53:35 +02:00
parent bdf8b2a66f
commit 6c77fecb1a

218
osm.pb
View File

@@ -114,7 +114,7 @@ Module OSM
Global OSM.OSM, Null.i Global OSM.OSM, Null.i
;- *** CURL specific *** ;- *** CURL specific ***
Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s Global *ReceiveHTTPToMemoryBuffer, ReceiveHTTPToMemoryBufferPtr.i, ReceivedData.s
IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl IncludeFile "libcurl.pbi" ; https://github.com/deseven/pbsamples/tree/master/crossplatform/libcurl
@@ -213,7 +213,7 @@ Module OSM
EndProcedure EndProcedure
;- *** ;- ***
Procedure InitOSM() Procedure InitOSM()
Protected Result.i Protected Result.i
@@ -236,17 +236,17 @@ Module OSM
Global Proxy = #True Global Proxy = #True
;- => Use this to customise your preferences ;- => Use this to customise your preferences
; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs") ; Result = CreatePreferences(GetHomeDirectory() + "OSM.prefs")
; If Proxy ; If Proxy
; PreferenceGroup("PROXY") ; PreferenceGroup("PROXY")
; WritePreferenceString("ProxyURL", "myproxy.fr") ; WritePreferenceString("ProxyURL", "myproxy.fr")
; WritePreferenceString("ProxyPort", "myproxyport") ; WritePreferenceString("ProxyPort", "myproxyport")
; WritePreferenceString("ProxyUser", "myproxyname") ; WritePreferenceString("ProxyUser", "myproxyname")
; EndIf ; EndIf
; If Result ; If Result
; ClosePreferences() ; ClosePreferences()
; EndIf ; EndIf
Result = OpenPreferences(GetHomeDirectory() + "OSM.prefs") Result = OpenPreferences(GetHomeDirectory() + "OSM.prefs")
If Proxy If Proxy
@@ -489,10 +489,10 @@ Module OSM
If OSM\EmergencyQuit = 0 ;Quit before drawing If OSM\EmergencyQuit = 0 ;Quit before drawing
StartVectorDrawing(CanvasVectorOutput(OSM\Gadget)) StartVectorDrawing(CanvasVectorOutput(OSM\Gadget))
If IsImage(*Tile\nImage) 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 Else
Debug "Image missing" Debug "Image missing"
OSM\Dirty = #True ;Signal that this image is missing so we should have to redraw OSM\Dirty = #True ;Signal that this image is missing so we should have to redraw
@@ -541,7 +541,7 @@ Module OSM
\nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY) \nImage = GetTileFromMem(\OSMZoom, \OSMTileX, \OSMTileY)
If \nImage = -1 If \nImage = -1
\GetImageThread = CreateThread(@GetImageThread(), *NewTile) \GetImageThread = CreateThread(@GetImageThread(), *NewTile)
OSM\TilesThreads()\GetImageThread = \GetImageThread OSM\TilesThreads()\GetImageThread = \GetImageThread
EndIf EndIf
Debug " Creating get image thread nb " + Str(\GetImageThread) Debug " Creating get image thread nb " + Str(\GetImageThread)
@@ -565,10 +565,10 @@ Module OSM
EndProcedure EndProcedure
Procedure DrawTrack() Procedure DrawTrack()
Protected Pixel.Pixel Protected Pixel.Pixel
Protected Location.Location Protected Location.Location
If ListSize(OSM\track())>0 If ListSize(OSM\track())>0
ForEach OSM\track() ForEach OSM\track()
If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0 If @OSM\TargetLocation\Latitude<>0 And @OSM\TargetLocation\Longitude<>0
@@ -578,14 +578,14 @@ Module OSM
Else Else
AddPathLine(Pixel\X,Pixel\Y) AddPathLine(Pixel\X,Pixel\Y)
EndIf EndIf
EndIf EndIf
Next Next
VectorSourceColor(RGBA(0, 255, 0, 150)) VectorSourceColor(RGBA(0, 255, 0, 150))
StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner) StrokePath(10, #PB_Path_RoundEnd|#PB_Path_RoundCorner)
EndIf EndIf
EndProcedure EndProcedure
Procedure Pointer(x.l,y.l,color.l=#Red) Procedure Pointer(x.l,y.l,color.l=#Red)
@@ -749,89 +749,109 @@ Module OSM
EndModule EndModule
;Demonstration ;-Exemple
CompilerIf #PB_Compiler_IsMainFile CompilerIf #PB_Compiler_IsMainFile
Enumeration Enumeration
#Window_0 #Window_0
#Map #Map
#Button_0 #Button_0
#Button_1 #Button_1
#Button_2 #Button_2
#Button_3 #Button_3
#Button_4 #Button_4
#Button_5 #Button_5
#Combo_0 #Combo_0
#Text_0 #Text_0
#Text_1 #Text_1
#Text_2 #Text_2
#Text_3 #Text_3
#Text_4 #Text_4
#String_0 #String_0
#String_1 #String_1
#Gdt_LoadGpx #Gdt_LoadGpx
EndEnumeration EndEnumeration
Structure Location Structure Location
Longitude.d Longitude.d
Latitude.d Latitude.d
EndStructure EndStructure
Procedure UpdateLocation(*Location.Location)
SetGadgetText(#String_0,StrD(*Location\Latitude))
SetGadgetText(#String_1,StrD(*Location\Longitude))
ProcedureReturn 0
EndProcedure
;- Main
If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
OSM::InitOSM() Procedure UpdateLocation(*Location.Location)
LoadFont(0, "Wingdings", 12) SetGadgetText(#String_0,StrD(*Location\Latitude))
LoadFont(1, "Arial", 12, #PB_Font_Bold) SetGadgetText(#String_1,StrD(*Location\Longitude))
ProcedureReturn 0
EndProcedure
OSM::OSMGadget(#Map, 10, 10, 512, 512) Procedure ResizeAll()
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(#Button_0,WindowWidth(#Window_0)-150,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Button_1,WindowWidth(#Window_0)-90,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Button_2,WindowWidth(#Window_0)-110,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Button_3,WindowWidth(#Window_0)-110,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Text_2,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Button_4,WindowWidth(#Window_0)-150,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Button_5,WindowWidth(#Window_0)-100,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Text_3,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#String_0,WindowWidth(#Window_0)-100,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#String_1,WindowWidth(#Window_0)-100,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Text_4,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
ResizeGadget(#Gdt_LoadGpx,WindowWidth(#Window_0)-170,#PB_Ignore,#PB_Ignore,#PB_Ignore)
EndProcedure
TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ") ;- Main
ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Button_0, FontID(0)) If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget )
ButtonGadget(#Button_1, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Button_1, FontID(0))
ButtonGadget(#Button_2, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Button_2, FontID(0))
ButtonGadget(#Button_3, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Button_3, FontID(0))
TextGadget(#Text_2, 530, 160, 60, 15, "Zoom : ")
ButtonGadget(#Button_4, 550, 180, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1))
ButtonGadget(#Button_5, 600, 180, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1))
TextGadget(#Text_3, 530, 230, 60, 15, "Latitude : ")
StringGadget(#String_0, 600, 230, 90, 20, "")
TextGadget(#Text_4, 530, 250, 60, 15, "Longitude : ")
StringGadget(#String_1, 600, 250, 90, 20, "")
ButtonGadget(#Gdt_LoadGpx, 530, 280, 150, 30, "Load GPX")
Define Event.i, Gadget.i, Quit.b = #False
Define pfValue.d
OSM::SetLocation(49.04599, 2.03347, 17)
OSM::SetCallBackLocation(@UpdateLocation())
Repeat
Event = WaitWindowEvent()
OSM::Event(Event) OSM::InitOSM()
Select Event LoadFont(0, "Wingdings", 12)
Case #PB_Event_CloseWindow : Quit = 1 LoadFont(1, "Arial", 12, #PB_Font_Bold)
Case #PB_Event_Gadget ;{
Gadget = EventGadget() OSM::OSMGadget(#Map, 10, 10, 512, 512)
Select Gadget
Case #Button_4 TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ")
OSM::SetZoom(1) ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Button_0, FontID(0))
Case #Button_5 ButtonGadget(#Button_1, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Button_1, FontID(0))
OSM::SetZoom( - 1) ButtonGadget(#Button_2, 580, 070, 30, 30, Chr($E9)) : SetGadgetFont(#Button_2, FontID(0))
Case #Gdt_LoadGpx ButtonGadget(#Button_3, 580, 130, 30, 30, Chr($EA)) : SetGadgetFont(#Button_3, FontID(0))
OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) TextGadget(#Text_2, 530, 160, 60, 15, "Zoom : ")
EndSelect ButtonGadget(#Button_4, 550, 180, 50, 30, " + ") : SetGadgetFont(#Button_4, FontID(1))
EndSelect ButtonGadget(#Button_5, 600, 180, 50, 30, " - ") : SetGadgetFont(#Button_5, FontID(1))
Until Quit = #True TextGadget(#Text_3, 530, 230, 60, 15, "Latitude : ")
EndIf StringGadget(#String_0, 600, 230, 90, 20, "")
TextGadget(#Text_4, 530, 250, 60, 15, "Longitude : ")
StringGadget(#String_1, 600, 250, 90, 20, "")
ButtonGadget(#Gdt_LoadGpx, 530, 280, 150, 30, "Load GPX")
Define Event.i, Gadget.i, Quit.b = #False
Define pfValue.d
OSM::SetLocation(49.04599, 2.03347, 17)
OSM::SetCallBackLocation(@UpdateLocation())
Repeat
Event = WaitWindowEvent()
OSM::Event(Event)
Select Event
Case #PB_Event_CloseWindow : Quit = 1
Case #PB_Event_Gadget ;{
Gadget = EventGadget()
Select Gadget
Case #Button_4
OSM::SetZoom(1)
Case #Button_5
OSM::SetZoom( - 1)
Case #Gdt_LoadGpx
OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0))
EndSelect
Case #PB_Event_SizeWindow
ResizeAll()
EndSelect
Until Quit = #True
EndIf
CompilerEndIf CompilerEndIf
; IDE Options = PureBasic 5.42 LTS (Windows - x86) ; IDE Options = PureBasic 5.42 LTS (Windows - x86)
; CursorPosition = 726 ; CursorPosition = 749
; FirstLine = 683 ; FirstLine = 713
; Folding = ----- ; Folding = -----
; EnableUnicode ; EnableUnicode
; EnableThread ; EnableThread