Page 1 of 1

Can't (un)HideGadget()[SOLVED]

Posted: Sun Jun 03, 2012 2:26 pm
by rule
I'm playing about with HideGadget(), but it wont work the way I want. I need it for a project with moving textboxes.

Code: Select all

;{- Enumerations / DataSections
;:PureFORM:Init:Start:
; PureFORM V1.99 ~ 3-6-2012 14:53:08
;{ Windows
Global Window_0
;}
;{ Gadgets
Global String_0
Global String_1
Global Button_2
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;:PureFORM:Init:End:
;}
;:PureFORM:Windows:Start:
;:PureFORM:Window_0_1:Start:
Procedure OpenWindow_Window_0()
  Window_0 = OpenWindow(#PB_Any, 450, 200, 528, 155, "Window_0", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_SizeGadget)
  If Window_0
    String_0 = StringGadget(#PB_Any, 130, 45, 80, 20, "Gadget_0", #PB_String_ReadOnly)
    String_1 = StringGadget(#PB_Any, 225, 45, 80, 20, "Gadget_1", #PB_String_ReadOnly)
    Button_2 = ButtonGadget(#PB_Any, 320, 35, 85, 35, "Go")
    ;
    HideGadget(String_0,1)
    HideGadget(String_1,1)
    ;:PureFORM:Window_0_1:End:
    ; Your code here ...

    ;
    ;:PureFORM:Window_0_2:Start:
  EndIf
EndProcedure
;:PureFORM:Window_0_2:End:
;:PureFORM:Windows:End:
;
;:PureFORM:Gadgets:Start:
;
;:PureFORM:Gadget_2_1:Start:
Procedure Button_2_OnEvent(EventType.l)
  HideGadget(String_0,0)
  Delay(500)
  HideGadget(String_0,1)
  HideGadget(String_1,0)
  Delay(500)
  HideGadget(String_1,1)
  ;:PureFORM:Gadget_2_1:End:
  ; Your code here ...

  ;
  ;:PureFORM:Gadget_2_2:Start:
EndProcedure
;:PureFORM:Gadget_2_2:End:
;:PureFORM:Gadgets:End:

OpenWindow_Window_0()
;:PureFORM:Main:Start:
;:PureFORM:Main:End:

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  ;:PureFORM:Loop:Start:
  Select Event
    ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = String_0
      ElseIf EventGadget = String_1
      ElseIf EventGadget = Button_2
        Button_2_OnEvent(EventType)
      EndIf
    ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = Window_0
        CloseWindow(Window_0)
        Window_0 = 0
        Break
      EndIf
  EndSelect
  ;:PureFORM:Loop:End:
ForEver
;
;}
;:PureFORM:AfterLoop:Start:
;:PureFORM:AfterLoop:End:
Am I doing wrong?

TIA,
Roel.

Re: Can't (un)HideGadget()

Posted: Sun Jun 03, 2012 3:08 pm
by eJan
You have hidden gadgets already, simply comment lines 25 and 26 and it should work.

Code: Select all

;     HideGadget(String_0,1)
;     HideGadget(String_1,1)

Re: Can't (un)HideGadget()

Posted: Sun Jun 03, 2012 3:24 pm
by rule
Thank you for your reply,

But the boxes should come up and vanish with a delay of 500ms. But now they all are hidden and stay that way.

Re: Can't (un)HideGadget()

Posted: Sun Jun 03, 2012 3:33 pm
by Demivec
rule wrote:Thank you for your reply,

But the boxes should come up and vanish with a delay of 500ms. But now they all are hidden and stay that way.
Try this for your event loop instead:

Code: Select all

Define isFirstTime = #True
Repeat
  event = WaitWindowEvent()
  ;:PureFORM:Loop:Start:
  Select event
      ; ///////////////////
    Case #PB_Event_Timer
      If EventTimer() = 0 And EventWindow() = Window_0
        If isFirstTime = #True
          HideGadget(String_0,1)
          HideGadget(String_1,0)
          isFirstTime = #False
        Else
          HideGadget(String_1,1)
          RemoveWindowTimer(Window_0, 0)
          isFirstTime = #True
        EndIf 
      EndIf 
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      eventType = EventType()
      If EventGadget = String_0
      ElseIf EventGadget = String_1
      ElseIf EventGadget = Button_2
        ;Button_2_OnEvent(eventType)
        HideGadget(String_0, 0)
        AddWindowTimer(Window_0, 0, 500)
      EndIf
      ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = Window_0
        CloseWindow(Window_0)
        Window_0 = 0
        Break
      EndIf
  EndSelect
  ;:PureFORM:Loop:End:
ForEver
According to my understanding, events that repaint the gadgets are only processed when no other events are present, and all such events are processed together. In the event loop of your example the hiding and unhiding of the gadgets was done without checking for window events in-between. That meant that only the last action, the re-hiding of the gadgets, was registered in the event loop.

Re: Can't (un)HideGadget()

Posted: Sun Jun 03, 2012 3:37 pm
by infratec
Hi,

the reason why your first try fails is:
HiddenGadget() applies only in a working eventloop.
You stop inside the loop show it, wait and hide it again.
Since the eventloop is stopped, you see nothing.

To demonstarte it working:

Code: Select all

Procedure Button_2_OnEvent(EventType.l)
  HideGadget(String_0,0)
  i = 0
  Repeat
    Delay(1)
    WindowEvent()
    i + 1
  Until i = 500
  
  HideGadget(String_0,1)
  HideGadget(String_1,0)
  i = 0
  Repeat
    Delay(1)
    WindowEvent()
    i + 1
  Until i = 500
  HideGadget(String_1,1)
  ;:PureFORM:Gadget_2_1:End:
  ; Your code here ...

  ;
  ;:PureFORM:Gadget_2_2:Start:
EndProcedure
But that is not a good idea.
It is only to show you the problem.

Bernd

Re: Can't (un)HideGadget()

Posted: Sun Jun 03, 2012 3:43 pm
by Zebuddi123
mnemonic`s make life easier :)

I had missed the fact both gadgets were hidden already so easy to do as we scan as opposed to reading the code :oops:

so make it simpler for your self use mnemonic`s ie

Code: Select all

#hide=1     ;make it easier to follow
#show=0	  ;make it easier to follow

;{- Enumerations / DataSections
;:PureFORM:Init:Start:
; PureFORM V1.99 ~ 3-6-2012 14:53:08
;{ Windows
Global Window_0
;}
;{ Gadgets
Global String_0
Global String_1
Global Button_2
;}
Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;:PureFORM:Init:End:
;}
;:PureFORM:Windows:Start:
;:PureFORM:Window_0_1:Start:
Procedure OpenWindow_Window_0()
  Window_0 = OpenWindow(#PB_Any, 450, 200, 528, 155, "Window_0", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_SizeGadget)
  If Window_0
    String_0 = StringGadget(#PB_Any, 130, 45, 80, 20, "Gadget_0", #PB_String_ReadOnly)
    String_1 = StringGadget(#PB_Any, 225, 45, 80, 20, "Gadget_1", #PB_String_ReadOnly)
    Button_2 = ButtonGadget(#PB_Any, 320, 35, 85, 35, "Go")
    ;
;     HideGadget(String_0,#hide) ;not needed but were hidden
;     HideGadget(String_1,#hide) ;not needed but were hidden

    ;:PureFORM:Window_0_1:End:
    ; Your code here ...

    ;
    ;:PureFORM:Window_0_2:Start:
  EndIf
EndProcedure
;:PureFORM:Window_0_2:End:
;:PureFORM:Windows:End:
;
;:PureFORM:Gadgets:Start:
;
;:PureFORM:Gadget_2_1:Start:
Procedure Button_2_OnEvent(EventType.l)
  HideGadget(String_0,#show)
  Delay(500)
  HideGadget(String_0,#hide)
  HideGadget(String_1,#show)
  Delay(500)
  HideGadget(String_1,#hide)
  ;:PureFORM:Gadget_2_1:End:
  ; Your code here ...

  ;
  ;:PureFORM:Gadget_2_2:Start:
EndProcedure
;:PureFORM:Gadget_2_2:End:
;:PureFORM:Gadgets:End:

OpenWindow_Window_0()
;:PureFORM:Main:Start:
;:PureFORM:Main:End:

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  ;:PureFORM:Loop:Start:
  Select Event
    ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      If EventGadget = String_0
      ElseIf EventGadget = String_1
      ElseIf EventGadget = Button_2
        Button_2_OnEvent(EventType)
      EndIf
    ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = Window_0
        CloseWindow(Window_0)
        Window_0 = 0
        Break
      EndIf
  EndSelect
  ;:PureFORM:Loop:End:
ForEver
;
;}
;:PureFORM:AfterLoop:Start:
;:PureFORM:AfterLoop:End:
Zebuddi. :D

Re: Can't (un)HideGadget()

Posted: Sun Jun 03, 2012 3:59 pm
by rule
@All,

Worked!
Thank you very much, I've learned allot from you.

Greets from holland,
Roel.