Page 1 of 1

ResizeGadget simple

Posted: Mon Jul 08, 2013 9:22 pm
by minimy
A ResizeGadget quite humble but it works. Hope this helps.
I tried it on x86 and x64 and it works.

Code: Select all


; Example ResizeGadget por Toni2013
;{
CompilerIf Not #PB_Compiler_IsIncludeFile
    ;- Window Constants
    Enumeration
      #Window_0
    EndEnumeration
    
    ;- Gadget Constants
    Enumeration
      #Button_0
      #ListIcon_0
    EndEnumeration
CompilerEndIf
;}

Structure Ventana
  Window.l
  Gadget.l
  Largo.w
  Alto.w
  Estado.i
  Cleft.i
  Cup.i
  CRight.i
  CDown.i
EndStructure
Global NewList Ventana.Ventana()

Procedure AutoResizeSet(Window.l, Gadget.l, Left.i, Up.i, Right.i, Down.i)
  AddElement(Ventana())
  Ventana()\Window = Window
  Ventana()\Gadget = Gadget
  Ventana()\Estado = 0
  Ventana()\Largo  = WindowWidth(Window)
  Ventana()\Alto   = WindowHeight(Window)
  Ventana()\Cleft = Left
  Ventana()\CUp = Up
  Ventana()\CRight = Right
  Ventana()\CDown = Down
EndProcedure


Procedure AutoResize(WindowID)
ForEach Ventana()
If WindowID=Ventana()\Window
  Left=GadgetX(Ventana()\Gadget)
  Up=GadgetY(Ventana()\Gadget)
  La=GadgetWidth(Ventana()\Gadget)
  Al=GadgetHeight(Ventana()\Gadget)
  
  SepLeft=Ventana()\Largo-GadgetX(Ventana()\Gadget)
  SepUp=Ventana()\Alto-GadgetY(Ventana()\Gadget)
  SepRig=Ventana()\Largo-(GadgetX(Ventana()\Gadget)+La)
  SepDow=Ventana()\Alto-(GadgetY(Ventana()\Gadget)+Al)

  If Ventana()\CLeft=0
  Left=WindowWidth(Ventana()\Window)-SepLeft
  EndIf
  If Ventana()\CUp=0
  Up=WindowHeight(Ventana()\Window)-SepUp
  EndIf
  If Ventana()\CRight=1
  La=WindowWidth(Ventana()\Window)-(Left+SepRig)
  EndIf
  If Ventana()\CDown=1
  Al=WindowHeight(Ventana()\Window)-(Up+SepDow)
  EndIf
  
  ResizeGadget(Ventana()\Gadget,Left,Up,La,Al)
  Ventana()\Largo=WindowWidth(Ventana()\Window)
  Ventana()\Alto =WindowHeight(Ventana()\Window)
EndIf  
Next
EndProcedure

CompilerIf Not #PB_Compiler_IsIncludeFile
    Procedure Open_Window_0()
      If OpenWindow(#Window_0, 220, 0, 600, 300, "AutoResize",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
          ButtonGadget(#Button_0, 50, 5, 500, 30, "Wiki wiki")
          ListIconGadget(#ListIcon_0, 55, 55, 530, 230, "Column0", 100)
          AutoResizeSet(#Window_0,#Button_0,1,1,0,0)
          AutoResizeSet(#Window_0,#ListIcon_0,1,1,1,1)
          SetWindowColor(#window_0,0)
      EndIf
    EndProcedure
    
    
    Open_Window_0()
    
    Repeat 
      
      Event = WaitWindowEvent()
      WindowID = EventWindow() 
      GadgetID = EventGadget() 
      EventType = EventType() 
      
      If Event = #PB_Event_Gadget
        If GadgetID = #Button_0
        ElseIf GadgetID = #ListIcon_0
        EndIf
      EndIf
    
      If Event = #PB_Event_SizeWindow
        AutoResize(WindowID)
      EndIf
    
    Until Event = #PB_Event_CloseWindow ; End of the event loop
    
    End
CompilerEndIf


Re: ResizeGadget simple

Posted: Mon Jul 08, 2013 9:47 pm
by davido
Nice! :D

Thanks for sharing.

Re: ResizeGadget simple

Posted: Mon Jul 08, 2013 10:22 pm
by jassing
I always like simple elegant solutions -- but for me, x86 pb 5.20, b5 - the button does not resize, at all. (I didn't debug it)

Re: ResizeGadget simple

Posted: Tue Jul 09, 2013 11:16 am
by captain_skank
Nice code.

Jassing you need to set the bounding of the bottom and right edge

Code: Select all

AutoResizeSet(#Window_0,#Button_0,1,1,1,0)
sets the right edeg to resize but not the bottom edge - at lest i think that's how it works :)

Re: ResizeGadget simple

Posted: Tue Jul 09, 2013 3:54 pm
by jassing
Yuppers! thanks .

Re: ResizeGadget simple

Posted: Tue Jul 16, 2013 1:33 pm
by mk-soft
Very nice :D

Re: ResizeGadget simple

Posted: Tue Jul 16, 2013 10:21 pm
by USCode
ResizeGadgets: http://www.purebasic.fr/english/viewtop ... lit=resize
Originally written in 2004! I think it still works ... :wink:

Re: ResizeGadget simple

Posted: Tue Jul 16, 2013 10:30 pm
by fsw
It does so... perfectly :!:

Re: ResizeGadget simple

Posted: Sun Aug 25, 2013 8:24 pm
by minimy
:shock: Sorry i dont see the code from 2004, But congratulations to the autor!! :D
I only pretended to help, but do not think that is very compatible PB code from 2004 now. :?:
Lot thanks to all friends!! :wink:

Re: ResizeGadget simple

Posted: Mon Aug 26, 2013 4:52 am
by USCode
minimy wrote::shock: Sorry i dont see the code from 2004, But congratulations to the autor!! :D
I only pretended to help, but do not think that is very compatible PB code from 2004 now. :?:
Lot thanks to all friends!! :wink:
I brought it up to date awhile back. Did you try it?

Re: ResizeGadget simple

Posted: Mon Aug 26, 2013 5:26 pm
by minimy
I have not tried, try to learn doing it myself. Well, I must confess :oops: that I sometimes use PureResize that goes very well.
Even if I used some code from the forum for 2003 or 2004 and have some things diferntes, Windows position title and other things. I've really learned a lot in this forum as there are great programmers, (take the opportunity to thank you all for the contributions :D ) and many people willing to learn and share.
I see you are an expert programmer. 797 posts!. Many posts ... 8)
Humbly just trying to cooperate.
USCode Greetings!

Re: ResizeGadget simple

Posted: Wed Aug 28, 2013 11:19 pm
by USCode
minimy wrote:I have not tried, try to learn doing it myself. Well, I must confess :oops: that I sometimes use PureResize that goes very well.
Even if I used some code from the forum for 2003 or 2004 and have some things diferntes, Windows position title and other things. I've really learned a lot in this forum as there are great programmers, (take the opportunity to thank you all for the contributions :D ) and many people willing to learn and share.
I see you are an expert programmer. 797 posts!. Many posts ... 8)
Humbly just trying to cooperate.
USCode Greetings!
Nah, I'm a rank amateur compared to a lot of guys here.
I've just BEEN here a long time and like you, have learned a lot from the real gurus.
It's an excellent forum and is gratifying to share.

Re: ResizeGadget simple

Posted: Thu Aug 29, 2013 8:28 pm
by minimy
Yes sir, that's the spirit in which computer programming began. Learn and share .. when ZXSpectrum ruled the planet. (then died and arrived CBMAmiga and AtariST, If Darwin hear me ..). :D

Greetings friends!