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

202
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
@@ -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
@@ -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
@@ -582,10 +582,10 @@ Module OSM
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) Procedure UpdateLocation(*Location.Location)
SetGadgetText(#String_0,StrD(*Location\Latitude)) SetGadgetText(#String_0,StrD(*Location\Latitude))
SetGadgetText(#String_1,StrD(*Location\Longitude)) SetGadgetText(#String_1,StrD(*Location\Longitude))
ProcedureReturn 0 ProcedureReturn 0
EndProcedure 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 ResizeAll()
LoadFont(0, "Wingdings", 12) ResizeGadget(#Map,10,10,WindowWidth(#Window_0)-198,WindowHeight(#Window_0)-59)
LoadFont(1, "Arial", 12, #PB_Font_Bold) 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
OSM::OSMGadget(#Map, 10, 10, 512, 512) ;- Main
If OpenWindow(#Window_0, 260, 225, 700, 571, "OpenStreetMap", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered | #PB_Window_SizeGadget )
TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ") OSM::InitOSM()
ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Button_0, FontID(0)) LoadFont(0, "Wingdings", 12)
ButtonGadget(#Button_1, 610, 100, 30, 30, Chr($E8)) : SetGadgetFont(#Button_1, FontID(0)) LoadFont(1, "Arial", 12, #PB_Font_Bold)
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 OSM::OSMGadget(#Map, 10, 10, 512, 512)
Define pfValue.d
OSM::SetLocation(49.04599, 2.03347, 17)
OSM::SetCallBackLocation(@UpdateLocation())
Repeat TextGadget(#Text_1, 530, 50, 60, 15, "Movements : ")
Event = WaitWindowEvent() ButtonGadget(#Button_0, 550, 100, 30, 30, Chr($E7)) : SetGadgetFont(#Button_0, FontID(0))
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")
OSM::Event(Event) Define Event.i, Gadget.i, Quit.b = #False
Select Event Define pfValue.d
Case #PB_Event_CloseWindow : Quit = 1 OSM::SetLocation(49.04599, 2.03347, 17)
Case #PB_Event_Gadget ;{ OSM::SetCallBackLocation(@UpdateLocation())
Gadget = EventGadget()
Select Gadget Repeat
Case #Button_4 Event = WaitWindowEvent()
OSM::SetZoom(1)
Case #Button_5 OSM::Event(Event)
OSM::SetZoom( - 1) Select Event
Case #Gdt_LoadGpx Case #PB_Event_CloseWindow : Quit = 1
OSM::LoadGpxFile(OpenFileRequester("Choisissez un fichier à charger", "", "*.gpx", 0)) Case #PB_Event_Gadget ;{
EndSelect Gadget = EventGadget()
EndSelect Select Gadget
Until Quit = #True Case #Button_4
EndIf 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