SetXY Modul zur Unterstützung beim Erstellen einer Gui
Verfasst: 01.05.2018 10:40
Die Prozedur SetXY hilft beim Plazieren von Gadgets mit Hilfe von Flags.
Diese ist für PBler gedacht, welche den FormDesigner nicht nutzen wollen
oder keine Lust haben mit der DialogLib von PB zu arbeiten, wie z.B. ich.
Anweisungen wie x = 10: y = 20 und weiter y + 30 etc werden fast überflüssig.
Und ja ich weiss, die DialogLib kann das sehr viel besser !!! aber viel Lernaufwand.
SetWidth() + SetHeight() haben noch Optimierungsbedarf. z.B. Panel im Panel
aber das sind für mich seltene Fälle die man umgehen kann.
Modul abspeichern als z.B. SetXYf.pb
Diese ist für PBler gedacht, welche den FormDesigner nicht nutzen wollen
oder keine Lust haben mit der DialogLib von PB zu arbeiten, wie z.B. ich.
Anweisungen wie x = 10: y = 20 und weiter y + 30 etc werden fast überflüssig.
Und ja ich weiss, die DialogLib kann das sehr viel besser !!! aber viel Lernaufwand.
SetWidth() + SetHeight() haben noch Optimierungsbedarf. z.B. Panel im Panel
aber das sind für mich seltene Fälle die man umgehen kann.
Modul abspeichern als z.B. SetXYf.pb
Code: Alles auswählen
DeclareModule SetXY
;HJBremer PB 5.60 x64 April 2018 V.2.10 - alle Betriebssysteme
Enumeration 1 ;für SetXY() muß bei 1 beginnen !
#Up
#Down
#Left
#Right
#Top
#TopLeft
#TopRight
#TopCenter
#Bottom
#BottomLeft
#BottomRight
#BottomCenter
#BottomCenterLeft
#BottomCenterRight
#GadgetOutside ;nur für flag2, siehe Procedure SetXY()
EndEnumeration
Declare.i SetXY(gadgetnr, parent, flag, abstand=10, flag2=0, abstand2=10)
Declare.i SetWidth(gadget, bisgadget, flag, abstand=10)
Declare.i SetHeight(gadget, bisgadget, flag, abstand=10)
Declare.i SetWindowSize(window, gadget, flag, abstand=10)
EndDeclareModule
Module SetXY
EnableExplicit
;auf Wunsch eines Unix-Nutzers
CompilerIf Not Defined(rect, #PB_Structure)
Structure rect
top.i
left.i
right.i
bottom.i
EndStructure
CompilerEndIf
Procedure.i SetWindowSize(window, gadget, flag, abstand=10)
;Fenster vergrößern/verkleinern wenn nötig, nur nach unten oder rechts, kann größer Screen werden
;Hinweis: Fenster kann ein Window oder Container/Panel/FrameGadget sein.
;Hinweis: Fenster verändern, wenn Gadget nach demselben ausgerichtet wurde, ergibt Mist. siehe 1.Demo
Protected windowx, windowbr
Protected windowy, windowhh
Protected ybottom, xright, diff, newvalue
If IsWindow(window)
windowx = WindowX(window): windowbr = WindowWidth(window)
windowy = WindowY(window): windowhh = WindowHeight(window)
Else
windowx = GadgetX(window): windowbr = GadgetWidth(window)
windowy = GadgetY(window): windowhh = GadgetHeight(window)
EndIf
Select flag
Case #Right
xright = GadgetX(gadget) + GadgetWidth(gadget) + abstand
diff = xright - windowbr
newvalue = windowbr + diff
ResizeWindow(window, windowx - diff/2, #PB_Ignore, newvalue, #PB_Ignore)
Case #Bottom
ybottom = GadgetY(gadget) + GadgetHeight(gadget) + abstand
diff = ybottom - windowhh
newvalue = windowhh + diff
ResizeWindow(window, #PB_Ignore, windowy - diff/2, #PB_Ignore, newvalue)
EndSelect
ProcedureReturn newvalue
EndProcedure
Procedure.i SetHeight(gadget, bisgadget, flag, abstand=10)
Protected hh
If IsGadget(bisgadget)
If flag = #Top
hh = GadgetY(bisgadget) - GadgetY(gadget)
ElseIf flag = #Bottom
hh = GadgetY(bisgadget) - GadgetY(gadget) + GadgetHeight(bisgadget)
EndIf
ResizeGadget(gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, hh - abstand)
ElseIf IsWindow(bisgadget)
If flag = #Bottom
hh = WindowHeight(bisgadget) - GadgetY(gadget)
EndIf
ResizeGadget(gadget, #PB_Ignore, #PB_Ignore, #PB_Ignore, hh - abstand)
EndIf
ProcedureReturn hh
EndProcedure
Procedure.i SetWidth(gadget, bisgadget, flag, abstand=10)
Protected br
If IsGadget(bisgadget)
If flag = #Left
br = GadgetX(bisgadget) - GadgetX(gadget)
ElseIf flag = #Right
br = GadgetX(bisgadget) - GadgetX(gadget) + GadgetWidth(bisgadget)
EndIf
ResizeGadget(gadget, #PB_Ignore, #PB_Ignore, br - abstand, #PB_Ignore)
ElseIf IsWindow(bisgadget)
If flag = #Right
br = WindowWidth(bisgadget) - GadgetX(gadget)
EndIf
ResizeGadget(gadget, #PB_Ignore, #PB_Ignore, br - abstand, #PB_Ignore)
EndIf
ProcedureReturn br
EndProcedure
Procedure.i SetXY(gadgetnr, parent, flag, abstand=10, flag2=0, abstand2=10)
;ermittelt x + y für Gadget
;flag2 = #GadgetOutside wird gesetzt wenn Parent ein Container/Panel ist
; und ein Gadget ausserhalb vom Container/Panel plaziert werden soll.
Protected parenttype.s, gadgettyp, p.rect, x, y
If IsGadget(gadgetnr) = 0
Debug "Gadget existiert nicht. Nr." + gadgetnr
ProcedureReturn
EndIf
;Parent auswerten
If IsGadget(parent)
gadgettyp = GadgetType(parent)
If flag2 = #GadgetOutside: gadgettyp = #PB_GadgetType_Unknown: EndIf
Select gadgettyp
Case #PB_GadgetType_Container ;minus + plus Werte sind geschätzt
parenttype = "Container"
p\top = 1
p\left = 1
p\right = GadgetWidth(parent) - 3
p\bottom = GadgetHeight(parent) - 4
Case #PB_GadgetType_Panel
parenttype = "Panel"
p\right = GadgetWidth(parent) - 5
p\bottom = GadgetHeight(parent) - 25
Case #PB_GadgetType_Frame
parenttype = "Frame"
p\top = GadgetY(parent) + 3
p\left = GadgetX(parent) + 2
p\right = GadgetWidth(parent) + 7
p\bottom = GadgetHeight(parent) + 8
Default
parenttype = "Gadget"
p\top = GadgetY(parent)
p\left = GadgetX(parent)
p\right = GadgetX(parent) + GadgetWidth(parent)
p\bottom = GadgetY(parent) + GadgetHeight(parent)
EndSelect
ElseIf IsWindow(parent)
parenttype = "Window"
p\right = WindowWidth(parent)
p\bottom = WindowHeight(parent)
Else
Debug "Parent Gadget/Window existiert nicht. Nr." + parent
ProcedureReturn
EndIf
;Auswertung
Select parenttype
Case "Gadget"
Select flag
Case #Left:
x = p\left - abstand - GadgetWidth(gadgetnr)
y = p\top
Case #Right:
x = p\right + abstand
y = p\top
Case #TopLeft, #Top
x = p\left
y = p\top - abstand - GadgetHeight(gadgetnr)
Case #TopRight
x = p\right - GadgetWidth(gadgetnr)
y = p\top - abstand - GadgetHeight(gadgetnr)
Case #TopCenter
x = p\Left + (GadgetWidth(parent) / 2) - (GadgetWidth(gadgetnr) / 2)
y = p\top - abstand - GadgetHeight(gadgetnr)
Case #BottomLeft, #Bottom
x = p\left
y = p\bottom + abstand
Case #BottomRight
x = p\right - GadgetWidth(gadgetnr)
y = p\bottom + abstand
Case #BottomCenter
x = p\Left + (GadgetWidth(parent) / 2) - (GadgetWidth(gadgetnr) / 2)
y = p\bottom + abstand
Case #BottomCenterLeft
x = p\Left + (GadgetWidth(parent) / 2) - GadgetWidth(gadgetnr)
y = p\bottom + abstand
Case #BottomCenterRight
x = p\Left + (GadgetWidth(parent) / 2)
y = p\bottom + abstand
Default: Debug "unbekanntes Flag für ParentGadget - Gadgetnr." + gadgetnr
EndSelect
Case "Window", "Container", "Panel", "Frame" ;Gadgets sollen innerhalb sein
Select flag
Case #TopLeft, #Top
x = p\left + abstand
y = p\top + abstand
Case #TopRight
x = p\right - abstand - GadgetWidth(gadgetnr)
y = p\top + abstand
Case #TopCenter
x = (p\right / 2) - (GadgetWidth(gadgetnr) / 2)
y = p\top + abstand
Case #BottomLeft, #Bottom
x = p\left + abstand
y = p\bottom - abstand - GadgetHeight(gadgetnr)
Case #BottomRight
x = p\right - abstand - GadgetWidth(gadgetnr)
y = p\bottom - abstand - GadgetHeight(gadgetnr)
Case #BottomCenter
x = (p\right / 2) - (GadgetWidth(gadgetnr) / 2)
y = p\bottom - abstand - GadgetHeight(gadgetnr)
Case #BottomCenterLeft
x = (p\right / 2) - GadgetWidth(gadgetnr)
y = p\bottom - abstand - GadgetHeight(gadgetnr)
Case #BottomCenterRight
x = p\right / 2
y = p\bottom - abstand - GadgetHeight(gadgetnr)
Default: Debug "unbekanntes Flag für ParentWindow etc - Gadgetnr." + gadgetnr
EndSelect
EndSelect
;Schiebeflag
Select flag2
Case 0
Case #Left: x - abstand2
Case #Right: x + abstand2
Case #Up: y - abstand2
Case #Down: y + abstand2
Case #GadgetOutside: ;damit Default nicht zutrifft
Default: Debug "unbekanntes flag2"
EndSelect
ResizeGadget(gadgetnr, x, y, #PB_Ignore, #PB_Ignore)
EndProcedure
EndModule