Gadgets use without API's ... ???

Just starting out? Need help? Post your questions and find answers here.
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Gadgets use without API's ... ???

Post by Joris »

Hi,

I got this very simplified setup completely working but only with the use of API's.
The position of all Gadgets should not become changed (as images are according placed on the canvas).
Most of the names are simplified too.

I like to know how to do it without API's, yet some things then go wrong or don't work :
* If the button RED is pushed the other gadgets in the container gets hidden and also colored red as the window below ?
* The buttons START and STOP don't work ?

I can change the setup with the use of two Canvas Gadgets, but that will be quit a work in the existing full source.
So if possible I'd like to keep it as is but only change some contanier and/or open/close gadgetlist's.

Thanks

Code: Select all

;**************************************************************************
;{
;**************************************************************************
;{
EnableExplicit
Global.i Event
;**************************************************************************
Global.i wnd_000, pnl_001, btn_002, btn_003, btn_006, txt_007, btn_008, txt_009 
Global.i btn_010, txt_011, trb_012, btn_013, btn_014, btn_015, txt_016, txt_017, trb_018, scb_019 
Global.i scb_020, opt_021, opt_022, cnv_023, cnt_024, txt_025, txt_026, txt_027, txt_028, trb_029 
Global.i btn_030, txt_031, txt_032, btn_033 
;**************************************************************************
;}
;**************************************************************************
;**************************************************************************
Procedure Build_Window_1(x = 0, y = 0, width = 730, height = 660)
  wnd_000 = OpenWindow(#PB_Any, 140,  10, 400, 395, "gadget_000")
  
  pnl_001 = PanelGadget(#PB_Any,   2,   2, 395, 390)
  btn_002 = ButtonGadget(#PB_Any, 200,   0,  90,  20, "START")
  btn_003 = ButtonGadget(#PB_Any, 300,   0,  90,  20, "STOP")

  ;OpenGadgetList(pnl_001)
  AddGadgetItem(pnl_001, -1, "Defaults")
  btn_006 = ButtonGadget(#PB_Any,   6,   2,  80,  17, "gadget_006")
  txt_007 = TextGadget(#PB_Any,  90,   2,  40,  17, "gadget_007", #PB_Text_Border)

  scb_020 = ScrollBarGadget(#PB_Any, 111, 332,  35,  18,   1, 100,   5)
  opt_021 = OptionGadget(#PB_Any, 242, 324,  80,  18, "gadget_021")
  opt_022 = OptionGadget(#PB_Any, 242, 340,  80,  18, "gadget_022")

  cnv_023 = CanvasGadget(#PB_Any,  10,  22, 370, 300, #PB_Canvas_Keyboard | #PB_Canvas_Container)

  cnt_024 = ContainerGadget(#PB_Any,   0, 235, 790,  20)
  txt_025 = TextGadget(#PB_Any,  90,   2,  40,  17, "gadget_025", #PB_Text_Border)
  trb_029 = TrackBarGadget(#PB_Any, 272,   2, 100,  18,   1, 100, #PB_TrackBar_Ticks)
  btn_030 = ButtonGadget(#PB_Any,   6,   2,  80,  17, "gadget_030")
  btn_033 = ButtonGadget(#PB_Any, 230,   2,  40,  17, "RED")

  CloseGadgetList()
  
EndProcedure
;**************************************************************************
;**************************************************************************
Procedure EventLoop()
  Build_Window_1()
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        If EventType()=#PB_EventType_LeftClick
          Select EventGadget()
            Case btn_033 : : SetWindowColor(wnd_000, $FF)  
            Default :Debug EventGadget()
          EndSelect
        EndIf
      Case #PB_Event_Menu
      Case #PB_Event_CloseWindow
        CloseWindow(#PB_All)
        End
    EndSelect
  ForEver
EndProcedure
EventLoop()
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
infratec
Always Here
Always Here
Posts: 6883
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Gadgets use without API's ... ???

Post by infratec »

You overlap gadgets. This is not handled by PB.
The Sart and Stop button overlaps with the PanelGadget.

The rest seams to be a bug in PB.
Bugfix:

Code: Select all

;**************************************************************************
;{
;**************************************************************************
;{
EnableExplicit
Global.i Event
;**************************************************************************
Global.i wnd_000, pnl_001, btn_002, btn_003, btn_006, txt_007, btn_008, txt_009
Global.i btn_010, txt_011, trb_012, btn_013, btn_014, btn_015, txt_016, txt_017, trb_018, scb_019
Global.i scb_020, opt_021, opt_022, cnv_023, cnt_024, txt_025, txt_026, txt_027, txt_028, trb_029
Global.i btn_030, txt_031, txt_032, btn_033
;**************************************************************************
;}
;**************************************************************************
;**************************************************************************
Procedure Build_Window_1(x = 0, y = 0, width = 730, height = 660)
  wnd_000 = OpenWindow(#PB_Any, 140,  10, 400, 415, "gadget_000")
  
  btn_002 = ButtonGadget(#PB_Any, 200,   2,  90,  20, "START")
  btn_003 = ButtonGadget(#PB_Any, 300,   2,  90,  20, "STOP")
  
  pnl_001 = PanelGadget(#PB_Any,   2,   22, 395, 390)
  
  ;OpenGadgetList(pnl_001)
  AddGadgetItem(pnl_001, -1, "Defaults")
  btn_006 = ButtonGadget(#PB_Any,   6,   2,  80,  17, "gadget_006")
  txt_007 = TextGadget(#PB_Any,  90,   2,  40,  17, "gadget_007", #PB_Text_Border)
  
  scb_020 = ScrollBarGadget(#PB_Any, 111, 332,  35,  18,   1, 100,   5)
  opt_021 = OptionGadget(#PB_Any, 242, 324,  80,  18, "gadget_021")
  opt_022 = OptionGadget(#PB_Any, 242, 340,  80,  18, "gadget_022")
  
  cnv_023 = CanvasGadget(#PB_Any,  10,  22, 370, 300, #PB_Canvas_Keyboard | #PB_Canvas_Container|#PB_Canvas_Border)
  
  cnt_024 = ContainerGadget(#PB_Any,   0, 235, 790,  20)
  txt_025 = TextGadget(#PB_Any,  90,   2,  40,  17, "gadget_025", #PB_Text_Border)
  trb_029 = TrackBarGadget(#PB_Any, 272,   2, 100,  18,   1, 100, #PB_TrackBar_Ticks)
  btn_030 = ButtonGadget(#PB_Any,   6,   2,  80,  17, "gadget_030")
  btn_033 = ButtonGadget(#PB_Any, 230,   2,  40,  17, "RED")
  CloseGadgetList()
  CloseGadgetList()
  
  
EndProcedure
;**************************************************************************
;**************************************************************************
Procedure EventLoop()
  Build_Window_1()
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case btn_002
            Debug "Start"
          Case btn_003
            Debug "Stop"
          Case btn_033
            SetWindowColor(wnd_000, $FF)
            ResizeGadget(cnt_024, #PB_Ignore, #PB_Ignore, #PB_Ignore, #PB_Ignore)
            SetGadgetColor(cnt_024, #PB_Gadget_BackColor, $F0F0F0)
          Default
            Debug EventGadget()
        EndSelect
      Case #PB_Event_Menu
      Case #PB_Event_CloseWindow
        CloseWindow(wnd_000)
        Break
    EndSelect
  ForEver
EndProcedure

EventLoop()
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Gadgets use without API's ... ???

Post by RASHAD »

All what you need now :
1- Create procedure to keep the positions of the the new windows right on when moving or resizing
2- Calculate the right x,y,width,height (I just did it by sense only :)

Code: Select all

;**************************************************************************
;{
;**************************************************************************
;{
EnableExplicit
Global.i Event
;**************************************************************************
Global.i wnd_000,wnd_001,wnd_002, pnl_001, btn_002, btn_003, btn_006, txt_007, btn_008, txt_009
Global.i btn_010, txt_011, trb_012, btn_013, btn_014, btn_015, txt_016, txt_017, trb_018, scb_019
Global.i scb_020, opt_021, opt_022, cnv_023, cnt_024, txt_025, txt_026, txt_027, txt_028, trb_029
Global.i btn_030, txt_031, txt_032, btn_033
;**************************************************************************
;}
;**************************************************************************
;**************************************************************************
Procedure moveCB()
  ResizeWindow(wnd_001,WindowX(wnd_000)+200, WindowY(wnd_000)+ 32, 200, 20)
  ResizeWindow(wnd_002,WindowX(wnd_000)+5, WindowY(wnd_000)+ 350, 395, 20)
EndProcedure

Procedure Build_Window_1(x = 0, y = 0, width = 730, height = 660)
  wnd_000 = OpenWindow(#PB_Any, 140,  10, 400, 395, "gadget_000")
 
  pnl_001 = PanelGadget(#PB_Any,   2,   2, 395, 390)
 
  wnd_001 = OpenWindow(#PB_Any, WindowX(wnd_000)+200, WindowY(wnd_000)+ 32, 200, 20, "",#PB_Window_BorderLess,WindowID(wnd_000))
  UseGadgetList(WindowID(wnd_001))
 
  btn_002 = ButtonGadget(#PB_Any, 0,   0,  90,  20, "START")
  btn_003 = ButtonGadget(#PB_Any, 100,   0,  90,  20, "STOP")
 
  UseGadgetList(WindowID(wnd_000))
  ;OpenGadgetList(pnl_001)
  AddGadgetItem(pnl_001, -1, "Defaults")
  btn_006 = ButtonGadget(#PB_Any,   6,   2,  80,  17, "gadget_006")
  txt_007 = TextGadget(#PB_Any,  90,   2,  40,  17, "gadget_007", #PB_Text_Border)

  scb_020 = ScrollBarGadget(#PB_Any, 111, 332,  35,  18,   1, 100,   5)
  opt_021 = OptionGadget(#PB_Any, 242, 324,  80,  18, "gadget_021")
  opt_022 = OptionGadget(#PB_Any, 242, 340,  80,  18, "gadget_022")

  cnv_023 = CanvasGadget(#PB_Any,  10,  22, 370, 300, #PB_Canvas_Keyboard | #PB_Canvas_Container)
 
  wnd_002 = OpenWindow(#PB_Any, WindowX(wnd_000)+5, WindowY(wnd_000)+ 350, 395, 20, "",#PB_Window_BorderLess,WindowID(wnd_000))
  ;cnt_024 = ContainerGadget(#PB_Any,   0, 0, 395,  20)
  txt_025 = TextGadget(#PB_Any,  90,   2,  40,  17, "gadget_025", #PB_Text_Border)
  trb_029 = TrackBarGadget(#PB_Any, 272,   2, 100,  18,   1, 100, #PB_TrackBar_Ticks)
  btn_030 = ButtonGadget(#PB_Any,   6,   2,  80,  17, "gadget_030")
  btn_033 = ButtonGadget(#PB_Any, 230,   2,  40,  17, "RED")

  ;CloseGadgetList()
 
EndProcedure
;**************************************************************************
;**************************************************************************
Procedure EventLoop()
  Build_Window_1()
  BindEvent(#PB_Event_MoveWindow,@moveCB())
  SetActiveWindow(wnd_000)
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        If EventType()=#PB_EventType_LeftClick
          Select EventGadget()
            Case btn_033 : : SetWindowColor(wnd_000, $FF):SetActiveWindow(wnd_000)
            Default :Debug EventGadget()
            SetActiveWindow(wnd_000)
          EndSelect
        EndIf
      Case #PB_Event_Menu
      Case #PB_Event_CloseWindow
        CloseWindow(#PB_All)
        End
    EndSelect
  ForEver
EndProcedure
EventLoop()
Egypt my love
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Gadgets use without API's ... ???

Post by Joris »

Strange solution Rashad, but still thanks.
Infratec, you too.

I found another strange thing about that color-overlapping : it happens only once ...
Push the RED button, thengo to the next panal-tab and come back... it seems oke thenb (no twice color-overlapping) ???

Code: Select all

;**************************************************************************
;{
;**************************************************************************
;{
EnableExplicit
Global.i Event
;**************************************************************************
Global.i wnd_000, pnl_001, btn_002, btn_003, btn_006, txt_007, btn_008, txt_009
Global.i btn_010, txt_011, trb_012, btn_013, btn_014, btn_015, txt_016, txt_017, trb_018, scb_019
Global.i scb_020, opt_021, opt_022, cnv_023, cnt_024, txt_025, txt_026, txt_027, txt_028, trb_029
Global.i btn_030, txt_031, txt_032, btn_033
;**************************************************************************
;}
;**************************************************************************
;**************************************************************************
Procedure Build_Window_1(x = 0, y = 0, width = 730, height = 660)
  wnd_000 = OpenWindow(#PB_Any, 140,  10, 400, 395, "gadget_000")
 
  pnl_001 = PanelGadget(#PB_Any,   2,   2, 395, 390)
  btn_002 = ButtonGadget(#PB_Any, 200,   0,  90,  20, "START")
  btn_003 = ButtonGadget(#PB_Any, 300,   0,  90,  20, "STOP")

  ;OpenGadgetList(pnl_001)
  AddGadgetItem(pnl_001, -1, "Defaults")
  btn_006 = ButtonGadget(#PB_Any,   6,   2,  80,  17, "gadget_006")
  txt_007 = TextGadget(#PB_Any,  90,   2,  40,  17, "gadget_007", #PB_Text_Border)

  scb_020 = ScrollBarGadget(#PB_Any, 111, 332,  35,  18,   1, 100,   5)
  opt_021 = OptionGadget(#PB_Any, 242, 324,  80,  18, "gadget_021")
  opt_022 = OptionGadget(#PB_Any, 242, 340,  80,  18, "gadget_022")

  cnv_023 = CanvasGadget(#PB_Any,  10,  22, 370, 300, #PB_Canvas_Keyboard | #PB_Canvas_Container)

  cnt_024 = ContainerGadget(#PB_Any,   0, 235, 790,  20)
  txt_025 = TextGadget(#PB_Any,  90,   2,  40,  17, "gadget_025", #PB_Text_Border)
  trb_029 = TrackBarGadget(#PB_Any, 272,   2, 100,  18,   1, 100, #PB_TrackBar_Ticks)
  btn_030 = ButtonGadget(#PB_Any,   6,   2,  80,  17, "gadget_030")
  btn_033 = ButtonGadget(#PB_Any, 230,   2,  40,  17, "RED")

  CloseGadgetList()
  OpenGadgetList(pnl_001)
  AddGadgetItem(pnl_001, -1, "Just second")
  CloseGadgetList()
EndProcedure
;**************************************************************************
;**************************************************************************
Procedure EventLoop()
  Build_Window_1()
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        If EventType()=#PB_EventType_LeftClick
          Select EventGadget()
            Case btn_033 :  SetWindowColor(wnd_000, $FF) 
            ;SetWindowColor(wnd_000, Random($FFFFFF))       ;<= this keeps on going wrong

           ;a simple solution resize (based on Rashad's idea)
           ;ResizeGadget(cnt_024,#PB_Ignore, #PB_Ignore, 780,#PB_Ignore)
           ;ResizeGadget(cnt_024,#PB_Ignore, #PB_Ignore, 790,#PB_Ignore)

            Default :Debug EventGadget()
          EndSelect
        EndIf
      Case #PB_Event_Menu
      Case #PB_Event_CloseWindow
        CloseWindow(#PB_All)
        End
    EndSelect
  ForEver
EndProcedure
EventLoop()
Last edited by Joris on Tue Sep 08, 2020 8:59 am, edited 1 time in total.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Gadgets use without API's ... ???

Post by RASHAD »

Hi Joris
This is what infratec mentioned
Refresh the container needed

Code: Select all

         Select EventGadget()
            Case btn_033 :HideGadget(cnt_024,1) :SetWindowColor(wnd_000, $FF) :HideGadget(cnt_024,0)
            Default :Debug EventGadget()
Egypt my love
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Gadgets use without API's ... ???

Post by Joris »

Ha, yes, Rashad that's maybe a little bit better then my Resize.
(The OS-redraw process needs to get started, isn't it ?)

Thanks.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

Re: Gadgets use without API's ... ???

Post by RASHAD »

Yes
PanelGadget() and ContainerGadget() almost share the same characteristics
Both are containers to other gadgets
Both deals with the same API (from Windows point of view)
Egypt my love
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Gadgets use without API's ... ???

Post by Joris »

Ok.

This solution seems the best one (according the redraw process) :
SetGadgetColor(cnt_024, #PB_Gadget_BackColor, #PB_Default)
After the SetWindowColor(wnd_000, $FF)

See you.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply