Seite 1 von 1
[Gelöst] Dialog library - Image über XML Beschreibung laden
Verfasst: 30.01.2018 00:22
von MeRobot
Hallo,
ich benutze die Dialog Library um GUIs über XML zu erstellen. Das klappt zum Beispiel für Buttons, Checkboxes etc. ganz gut.
Code: Alles auswählen
<button name="btExample" text="Example" onevent="On_btExample_Event()"/>
Ist es möglich auf die gleiche Art und Weise Images einzufügen und zwar so, dass das anzuzeigende Bild gleich geladen wird? Oder kann ich das Image nur als Platzhalter einfügen und muss selber zur Laufzeit mit LoadImage und SetGadgetState für dieses Image arbeiten? Leider finde ich in der Doku nichts zum Thema.
Danke und Grüße
Re: Dialog library - Image über XML Beschreibung laden
Verfasst: 30.01.2018 01:50
von Kiffi
das geht indirekt, indem Du OpenXMLDialog() mit einem Macro überschreibst:
Code: Alles auswählen
EnableExplicit
Procedure ProcessGadgets(Dialog, Window, XmlNode)
Protected Name.s
Protected ImgSrc.s
Protected Img
Protected ChildNode = ChildXMLNode(XmlNode)
While ChildNode <> 0
If ExamineXMLAttributes(ChildNode)
Name = ""
ImgSrc = ""
While NextXMLAttribute(ChildNode)
Select LCase(XMLAttributeName(ChildNode))
Case "name"
Name = XMLAttributeValue(ChildNode)
Case "src"
If Name
ImgSrc = XMLAttributeValue(ChildNode)
If FileSize(ImgSrc) > -1
Img = LoadImage(#PB_Any, ImgSrc)
If Img
SetGadgetState(DialogGadget(Dialog, Name), ImageID(Img))
FreeImage(Img)
EndIf
EndIf
EndIf
EndSelect
Wend
EndIf
If XMLChildCount(ChildNode)
ProcessGadgets(Dialog, Window, ChildNode)
EndIf
ChildNode = NextXMLNode(ChildNode)
Wend
EndProcedure
Procedure OpenXMLDialog2(Dialog, Xml, Name.s, x, y, Width, Height, ParentID)
Protected Result = OpenXMLDialog(Dialog, Xml, Name.s, x, y, Width, Height, ParentID)
If Result
ProcessGadgets(Dialog, DialogWindow(Dialog), MainXMLNode(Xml))
EndIf
ProcedureReturn Result
EndProcedure
Macro OpenXMLDialog(Dialog, Xml, Name, x=0, y=0, Width=0, Height=0, ParentID=0)
OpenXMLDialog2(Dialog, Xml, Name, x, y, Width, Height, ParentID)
EndMacro
; ###############
; # Example:
; ###############
Define XML.s = "<window id='#PB_Any' name='test' text='Dialog example' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered'>" +
" <image id='image1' name='image1' src='" + #PB_Compiler_Home + "/examples/sources/Data/Geebee2.bmp' />" +
"</window>"
#Dialog = 0
#Xml = 0
If ParseXML(#Xml, XML) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
RefreshDialog(#Dialog) ; important!
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
EndIf
Grüße ... Peter
Re: Dialog library - Image über XML Beschreibung laden
Verfasst: 31.01.2018 10:09
von MeRobot
Hallo Kiffi,
das hilft mir weiter. Ich würde das Ganze als "elegantes selber erledigen" bezeichnen
Vielen Dank für deine Unterstützung!