ResizeGadget simple

Share your advanced PureBasic knowledge/code with the community.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 634
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

ResizeGadget simple

Post 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

If translation=Error: reply="Sorry, Im Spanish": Endif
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: ResizeGadget simple

Post by davido »

Nice! :D

Thanks for sharing.
DE AA EB
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: ResizeGadget simple

Post 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)
User avatar
captain_skank
Enthusiast
Enthusiast
Posts: 641
Joined: Fri Oct 06, 2006 3:57 pm
Location: England

Re: ResizeGadget simple

Post 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 :)
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: ResizeGadget simple

Post by jassing »

Yuppers! thanks .
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ResizeGadget simple

Post by mk-soft »

Very nice :D
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
USCode
Addict
Addict
Posts: 924
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: ResizeGadget simple

Post by USCode »

ResizeGadgets: http://www.purebasic.fr/english/viewtop ... lit=resize
Originally written in 2004! I think it still works ... :wink:
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: ResizeGadget simple

Post by fsw »

It does so... perfectly :!:

I am to provide the public with beneficial shocks.
Alfred Hitshock
User avatar
minimy
Enthusiast
Enthusiast
Posts: 634
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: ResizeGadget simple

Post 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:
If translation=Error: reply="Sorry, Im Spanish": Endif
USCode
Addict
Addict
Posts: 924
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: ResizeGadget simple

Post 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?
User avatar
minimy
Enthusiast
Enthusiast
Posts: 634
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: ResizeGadget simple

Post 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!
If translation=Error: reply="Sorry, Im Spanish": Endif
USCode
Addict
Addict
Posts: 924
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: ResizeGadget simple

Post 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.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 634
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: ResizeGadget simple

Post 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!
If translation=Error: reply="Sorry, Im Spanish": Endif
Post Reply