Page 1 of 1

How Do you Remove Buttons?

Posted: Tue Oct 25, 2011 10:00 pm
by Swos2009
I have made GUI window with 4 Buttons.

IF I click on new Game then I would like have new Screen which mean I need to remove the buttons but the questions I would like to ask is How?

Re: How Do you Remove Buttons?

Posted: Tue Oct 25, 2011 10:10 pm
by Shield
Use FreeGadget().

Re: How Do you Remove Buttons?

Posted: Tue Oct 25, 2011 10:35 pm
by Swos2009
Thanks Shied

I got another questions...

What code should I do if I click on Button then new Screen come on...

for example

IF ButtonGadget()=true
FREEGADGET()
Make Tab Screen
Endif

Re: How Do you Remove Buttons?

Posted: Tue Oct 25, 2011 11:28 pm
by ts-soft
Use Container for your Screens:

Code: Select all

Enumeration ; gadgets
  #con_SF
  #btn_SF_1
  #btn_SF_2
  #btn_SF_3
  #con_SS
  #btn_SS_1
EndEnumeration

OpenWindow(0, #PB_Ignore, #PB_Ignore, 340, 100, "")

ContainerGadget(#con_SF, 0, 0, WindowWidth(0), WindowHeight(0))
ButtonGadget(#btn_SF_1, 10, 10, 150, 30, "First on Screen First")
ButtonGadget(#btn_SF_2, 170, 10, 150, 30, "Secont on Screen First")
ButtonGadget(#btn_SF_3, 100, 60, 150,30, "Next Screen")
CloseGadgetList()
ContainerGadget(#con_SS, 0, 0, WindowWidth(0), WindowHeight(0))
ButtonGadget(#btn_SS_1, 60, 30, 200, 30, "Go Back to Screen First")
CloseGadgetList()
HideGadget(#con_SS, #True)
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #btn_SF_1 : Debug "First on Screen First"
        Case #btn_SF_2 : Debug "Second on Screen First"
        Case #btn_SF_3 : HideGadget(#con_SF, #True) : HideGadget(#con_SS, #False)
        Case #btn_SS_1 : HideGadget(#con_SS, #True) : HideGadget(#con_SF, #False)
      EndSelect
  EndSelect
ForEver

Re: How Do you Remove Buttons?

Posted: Wed Oct 26, 2011 12:00 am
by Swos2009
Thanks ts-soft

That good to learn from and I do love Select case as it is so simple :)

Re: How Do you Remove Buttons?

Posted: Wed Oct 26, 2011 12:12 am
by Swos2009
This is what I have done so far

Code: Select all

Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Button_0
  #Button_1
  #Button_2
  #Button_3
  #Text_0
EndEnumeration

;- Fonts
Global FontID1
FontID1 = LoadFont(1, "@Meiryo UI", 28)

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 627, 148, 600, 300, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_TitleBar )
    If createGadgetlist(WindowID(#Window_0))
      ButtonGadget(#Button_0, 190, 70, 190, 40, "NEW GAME")
      ButtonGadget(#Button_1, 190, 120, 190, 40, "LOAD GAME")
      ButtonGadget(#Button_2, 190, 170, 190, 40, "OPTIONS")
      ButtonGadget(#Button_3, 190, 220, 190, 40, "EXIT")
  
      SetGadgetFont(#Text_0, FontID1)
      
    EndIf
  EndIf
EndProcedure

Repeat
  Select WaitWindowEvent()   ; << WHY Error?
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_0: HideGadget(#Button_1, #True) : HideGadget(#Button_2, #False): HideGadget(#Button_3, #True)
      EndSelect
  EndSelect
ForEver

Re: How Do you Remove Buttons?

Posted: Wed Oct 26, 2011 8:06 am
by Kiffi
Swos2009 wrote:

Code: Select all

  Select WaitWindowEvent()   ; << WHY Error?
Without calling Open_Window_0() you have no window.
Without having a window, WaitWindowEvent() will
throw an error.

Greetings ... Kiffi

Re: How Do you Remove Buttons?

Posted: Wed Oct 26, 2011 6:59 pm
by Swos2009
Should I do this?

Code: Select all

Repeat
  Select #Window_0
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_0: HideGadget(#Button_1, #True) : HideGadget(#Button_2, #False): HideGadget(#Button_3, #True)
      EndSelect
  EndSelect
ForEver
:?:

Re: How Do you Remove Buttons?

Posted: Wed Oct 26, 2011 7:02 pm
by Kiffi

Code: Select all

Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Button_0
  #Button_1
  #Button_2
  #Button_3
  #Text_0
EndEnumeration

;- Fonts
Global FontID1
FontID1 = LoadFont(1, "@Meiryo UI", 28)

Procedure Open_Window_0()
  
  If OpenWindow(#Window_0, 627, 148, 600, 300, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_TitleBar )
    
    ButtonGadget(#Button_0, 190, 70, 190, 40, "NEW GAME")
    ButtonGadget(#Button_1, 190, 120, 190, 40, "LOAD GAME")
    ButtonGadget(#Button_2, 190, 170, 190, 40, "OPTIONS")
    ButtonGadget(#Button_3, 190, 220, 190, 40, "EXIT")
    
    SetGadgetFont(#Text_0, FontID1)
    
  EndIf
  
EndProcedure

Open_Window_0() ; <<< paste this 

Repeat
  Select WaitWindowEvent()   ; << no error anymore
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_0: HideGadget(#Button_1, #True) : HideGadget(#Button_2, #False): HideGadget(#Button_3, #True)
      EndSelect
  EndSelect
ForEver
Greetings ... Kiffi

Re: How Do you Remove Buttons?

Posted: Wed Oct 26, 2011 8:40 pm
by Swos2009
Thanks Kiffi and now I understand how it work :)