- EnableExplicit
- ;############################################################################################################################
- ; Redimensionnement automatique des gadgets - pf shadoko - 2016
- ;
- ; fonctionnement:
- ; les instructions: OpenWindow, ButtonGadget, TextGadget, ... , CloseGadgetList
- ; doivent etre utilisées avec le suffixe 'R'
- ; les 2 parametres suplementaires : rx et ry correspondent au type de redimensionnement:
- ; rx/ry = 0 : pas de modification
- ; rx/ry = 1 : modification de la position x/y
- ; rx/ry = 2 : modification de la largeur/hauteur
- ; rx/ry = 3 : positionnement proportionnel
- ; (rx/ry = 4 : positionnement proportionnel d'un coté)
- ; (rx/ry = 5 : positionnement proportionnel de l'autre coté)
- ;
- ;############################################################################################################################
- Structure GadgetInfo
- g.i ;gadgetID
- Map Glist.s() ;liste des gadgets contenus (pour les containers)
- x.w: y.w ;position d'origine
- dx.w: dy.w ;dimension d'origine
- rx.b : ry.b ;type de redimensionnement
- EndStructure
- Global Dim GadgetCont.s(256), GadgetConti
- Global NewMap GadgetList.GadgetInfo()
- Procedure Redimensioner(c, nx, ny, ndx, ndy, t.s="G")
- Protected.w ox1,oy1, ox2,oy2, x1,y1, x2,y2
- Protected gi.GadgetInfo, o.GadgetInfo, adx,ady, r.f,d.w
- Macro RedimensionerD(t, v1, V2, oV1, oV2, adV, ndV)
- d = ndV - adV
- r = ndV / adV
- Select t
- Case 0: v1 = oV1: V2 = oV2
- Case 1: v1 = oV1 + d: V2 = oV2 + d
- Case 2: v1 = oV1: V2 = oV2 + d
- Case 3: v1 = oV1 * r: V2 = oV2 * r
- Case 4: v1 = oV1: V2 = oV2 * r
- Case 5: v1 = oV1 * r: V2 = oV2 + d
- EndSelect
- EndMacro
- gi=GadgetList(t STR(c))
- adx = gi\dx
- ady = gi\dy
- ForEach gi\Glist():o=GadgetList(gi\Glist())
- If (o\rx OR o\ry)
- ox1 = o\x: ox2 = ox1 + o\dx: RedimensionerD (o\rx, x1, x2, ox1, ox2, adx, ndx)
- oy1 = o\y: oy2 = oy1 + o\dy: RedimensionerD (o\ry, y1, y2, oy1, oy2, ady, ndy)
- Redimensioner (o\g, x1, y1, x2 - x1, y2 - y1)
- EndIf
- Next
- If t="G":ResizeGadget(c,nx, ny, ndx, ndy):EndIf
- EndProcedure
- Procedure GadgetInfo(na,n,x.w,y.w,dx.w,dy.w,rx.b,ry.b,iscontainer=0)
- Protected gi.GadgetInfo, tg.s
- With gi
- If n=-1:\g=na:Else:\g=n:EndIf
- \x=x: \dx=dx: \rx=rx
- \y=y: \dy=dy: \ry=ry
- If iscontainer=-1
- tg="W" STR(\g):GadgetConti=0
- Else
- tg="G" STR(\g):GadgetList(GadgetCont(GadgetConti))\Glist(tg)=tg
- EndIf
- GadgetList(tg)=gi
- If iscontainer:GadgetConti+1:GadgetCont(GadgetConti)=tg :EndIf
- ProcedureReturn \g
- EndWith
- EndProcedure
- ;--------------------------------- gadgets
- Procedure ButtonGadgetR(n,x,y,dx,dy,txt.s,f=0,rx=0,ry=0)
- Protected na=ButtonGadget(n,x,y,dx,dy,txt,f)
- ProcedureReturn GadgetInfo(na,n,x,y,dx,dy,rx,ry)
- EndProcedure
- Procedure TextGadgetR(n,x,y,dx,dy,txt.s,f=0,rx=0,ry=0)
- Protected na=TextGadget(n,x,y,dx,dy,txt,f)
- ProcedureReturn GadgetInfo(na,n,x,y,dx,dy,rx,ry)
- EndProcedure
- Procedure CheckBoxGadgetR(n,x,y,dx,dy,txt.s,f=0,rx=0,ry=0)
- Protected na=CheckBoxGadget(n,x,y,dx,dy,txt,f)
- ProcedureReturn GadgetInfo(na,n,x,y,dx,dy,rx,ry)
- EndProcedure
- Procedure StringGadgetR(n,x,y,dx,dy,txt.s,f=0,rx=0,ry=0)
- Protected na=StringGadget(n,x,y,dx,dy,txt,f)
- ProcedureReturn GadgetInfo(na,n,x,y,dx,dy,rx,ry)
- EndProcedure
- Procedure EditorGadgetR(n,x,y,dx,dy,f=0,rx=0,ry=0)
- Protected na=EditorGadget(n,x,y,dx,dy,f)
- ProcedureReturn GadgetInfo(na,n,x,y,dx,dy,rx,ry)
- EndProcedure
- Procedure ButtonImageGadgetR(n,x,y,dx,dy,imageID,f=0,rx=0,ry=0)
- Protected na=ButtonImageGadget(n,x,y,dx,dy,imageID,f)
- ProcedureReturn GadgetInfo(na,n,x,y,dx,dy,rx,ry)
- EndProcedure
- ;--------------------------------- containers
- Procedure ContainerGadgetR(n,x,y,dx,dy,f=0,rx=0,ry=0)
- Protected na=ContainerGadget(n,x,y,dx,dy,f)
- ProcedureReturn GadgetInfo(na,n,x,y,dx,dy,rx,ry,1)
- EndProcedure
- Procedure PanelGadgetR(n,x,y,dx,dy,rx=0,ry=0)
- Protected na=PanelGadget(n,x,y,dx,dy)
- ProcedureReturn GadgetInfo(na,n,x,y,dx,dy,rx,ry,1)
- EndProcedure
- Procedure ScrollAreaGadgetR(n,x,y,dx,dy,scrolldx,scrolldy,scrollstep,f=0,rx=0,ry=0)
- Protected na=ScrollAreaGadget(n,x,y,dx,dy,scrolldx,scrolldy,scrollstep,f)
- ProcedureReturn GadgetInfo(na,n,x,y,dx,dy,rx,ry,1)
- EndProcedure
- ;--------------------------------- window
- Procedure WindowResizeEvent()
- Protected n=EventWindow()
- Redimensioner(n,0,0,WindowWidth(n), WindowHeight(n),"W")
- EndProcedure
- Procedure OpenWindowR(n,x,y,dx,dy,txt.s,f=#PB_Window_SystemMenu,pid=0)
- Protected na=OpenWindow(n,x,y,dx,dy,txt,f,pid)
- Protected nw=GadgetInfo(na,n,x,y,dx,dy,2,2,-1)
- BindEvent(#PB_Event_SizeWindow,@WindowResizeEvent(), nw)
- ProcedureReturn nw
- EndProcedure
- ;---------------------------------
- Procedure CloseGadgetListR()
- CloseGadgetList()
- GadgetConti-1
- EndProcedure
- ;############################################################################################################################
- ; Exemple
- ;############################################################################################################################
- CreateImage(0,200,60):StartDrawing(ImageOutput(0)):Define i:For i=0 To 200:Circle(100,30,200-i,(i+50)*$010101):Next:StopDrawing()
- OpenWindowR(0, 0, 0, 512, 200, "Resize gadget",#PB_Window_ScreenCentered | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget)
- TextGadgetR(1, 10, 10, 200, 50, "Redimentionnez la fenetre, les gadgets seront automatiquement redimentionnés",#PB_Text_Center)
- ButtonImageGadgetR(3, 10, 70, 200, 60, ImageID(0),0,0,0)
- EditorGadgetR(2, 10, 140, 200, 20, 0,0,2):SetGadgetText(2,"Editor")
- ButtonGadgetR(4, 10, 170, 490, 20, "Button / toggle", #PB_Button_Toggle,2,1)
- TextGadgetr(5,220,10,190,20,"Text",#PB_Text_Center,2,0):SetGadgetColor(5, #PB_Gadget_BackColor, $00FFFF)
- ContainerGadgetR(6, 220, 30, 190, 100,#PB_Container_Single,2,2):SetGadgetColor(6, #PB_Gadget_BackColor, $cccccc)
- EditorGadgetR(7, 10, 10, 170, 50, 0,2,2):SetGadgetText(7,"Editor")
- ButtonGadgetR(8, 10, 70, 80, 20, "Button",0,4,1)
- ButtonGadgetR(9, 100, 70, 80, 20, "Button",0,5,1)
- CloseGadgetListR()
- StringGadgetR(10, 220, 140, 190, 20, "String",0,2,1)
- ButtonGadgetR(11, 420, 10, 80, 80, "Bouton",0,1,2)
- CheckBoxGadgetR(12, 420, 90, 200, 20, "CheckBox",0,1,1)
- CheckBoxGadgetR(13, 420, 110, 200, 20, "CheckBox",0,1,1)
- CheckBoxGadgetR(14, 420, 130, 200, 20, "CheckBox",0,1,1)
- CheckBoxGadgetR(15, 420, 150, 200, 20, "CheckBox",0,1,1)
- ResizeWindow(0, #PB_Ignore , #PB_Ignore ,512,400):
- Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow