Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: New UI ... CallBacks options

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    New UI ... CallBacks options

    Something you will get into next thinBasic beta (1.9.8.0)
    • DIALOGS can be samed using Name clause during DIALOG NEW ...
    • If named option is used, you can use dialog name to create events dialog callbacks function that will be automatically called when such an event is fired
    • automatic dialog callbacks must be named with the dialog name + underscore + event
    • so far I've created the following events: *_OnInit, *_OnSize, *_OnMove, *_OnTimer, *_OnCommand, *_OnCallback (can be used to create automatic callback to dialogs)


    During this development I discovered it would be very useful to have variables defined with a DIALOG scope, that is variable accessible from any dialog callback of the same dialog. This in order to avoid global variables and keep things all together. I'm thinking about it and how to implement.

    Suggestions/ideas are welcome.

    Ciao
    Eros

    Example:
      uses "UI"
      Uses "console"
           
      Begin ControlID       
        %IDC_TIMER      
        %IDC_LABEL      
        %IDC_Start      
        %IDC_Stop       
      End ControlID
       
      %TIMER_DELAY    = 10     ' Timer delay (in milliseconds, not very accurate below about 100)
    
    
      Global TimerValue As Double       '---Will be used to calculate timer values
    
    
      '------------------------------------------------------------------------------
      ' Main function
      '------------------------------------------------------------------------------
      FUNCTION TBMain() as long
        LOCAL hDlg AS DWORD
                
        Dialog New Name "TimerDialog", 0 , "Timer Example using CallBacks functions", -1, -1, 240, 40, %WS_OVERLAPPEDWINDOW  To hDlg
    
    
        CONTROL ADD BUTTON, hDlg, %IDC_Start, "Start" ,  10, 10, 50, 20
        CONTROL ADD LABEL , hDlg, %IDC_LABEL, ""      ,  90, 10, 55, 20, %WS_CHILD OR %WS_VISIBLE OR %WS_BORDER OR %SS_CENTERIMAGE OR %SS_CENTER
        CONTROL ADD BUTTON, hDlg, %IDC_Stop , "Stop"  , 180, 10, 50, 20
       
        Dialog Show Modal hDlg 'Call MainDialog_OnCallBack        
        
      END FUNCTION
    
    
     
      '------------------------------------------------------------------------------
      ' OnCallBack
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnCallBack() As Long
        PrintL Timer, Function_Name, CBMSG             
      End Function
    
    
    
    
      '------------------------------------------------------------------------------
      ' OnCommand
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnCommand() As Long
        Select Case CBCTL
    
    
          '---Check which control as fired the event
          Case %IDC_Start
            '---If start, than enable/disable relevant buttons and activate the timer
            Control Disable CBHNDL, %IDC_Start
            Control Enable CBHNDL, %IDC_Stop
    
    
            TimerValue = 0              '---Set the time counter to zero
            Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
    
    
          Case %IDC_Stop
            '---If sstop, than enable/disable relevant buttons and destroy the timer
            Control Disable CBHNDL, %IDC_Stop
            Control Enable CBHNDL, %IDC_Start
            Dialog Kill Timer CBHNDL, %IDC_TIMER
    
    
        End Select
      End Function
      
      '------------------------------------------------------------------------------
      ' OnInit
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnInit() As Long
        Control Disable CBHNDL, %IDC_Stop
      End Function
    
    
      '------------------------------------------------------------------------------
      ' OnTimer
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnTimer() As Long
        '---This event is fired by any timer created on the dialog. We have to check which one
      
          '---CBWPARAM contains the ID of the timer that fired %WM_TIMER event
          '---More than one timer can be active sumultaneously
          Select Case CBWPARAM
            Case %IDC_TIMER
              '---Increment and set the test value...
              TimerValue += 0.01
              Control Set Text CBHNDL, %IDC_LABEL, Format$(TimerValue, "#0.00")
          End Select
      End Function
        
      '------------------------------------------------------------------------------
      ' OnSize
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnSize() As Long
        PrintL Timer, "Sizing", CBWPARAM, CBLPARAM
      End Function
      
      '------------------------------------------------------------------------------
      ' OnMove
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnMove() As Long
        PrintL Timer, "Moving", CBWPARAM, CBLPARAM
      End Function
    
    PS: this post fired OOP discussion (that I really appreaciated) in this post: http://www.thinbasic.com/community/s...ad.php?t=12194
    I just wanted to point out that here I'm not discussing OOP but just another approach to Dialog Events CallBacks handling, at least for the more often used events.

    Last edited by ErosOlmi; 26-08-2013 at 21:00.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    "Private scope" without oop nor globals? Append some pointer to Dialog where to find a datapointer and store data in heap...
    Last edited by ReneMiner; 26-08-2013 at 21:20.
    I think there are missing some Forum-sections as beta-testing and support

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    I'm thinking about that:
    • STATIC variables created inside a CALLBACK of a Window will be defined inside a Window scope and not FUNCTION scope like it is now
    • all such variables will be available to all CALLBACKs of the same Window using the Window Handle as discriminant.


    Not an usual way of doing things ...
    ... but something unique.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Eros,

    If I may, I would propose to call them slightly differentely than STATICs, to avoid confusion. Maybe SHARED or something similar?
    To support encapsulation, what about wild idea of DIALOG FUNCTION:
    MainWindow("Ciao")
    
    DIALOG FUNCTION MainWindow( aParam AS STRING ) ' -- Any number/kind of parameters
      
      DIALOG NEW ... TO hDlg
      
      CONTROL ADD ...
    
      DIALOG SHARED myData AS STRING = "They passed" + aParam ' -- Such a variable would be shared with callback functions
    
      DIALOG SHOW MODAL hDlg
    END FUNCTION
    
    CALLBACK FUNCTION MainWindow_OnTimer()
    
      PrintL myData ' -- Can be read here, because it is "shared", would print "They passed Ciao" in this case
    
    END FUNCTION
    
    or alternatively, instead of DIALOG FUNCTION, we could have specific block for sharing:
    DIALOG SHARED hDlg ' -- For which dialog we share this?
      x AS LONG
      s AS STRING
      ...
    END SHARED
    
    "Private scope" without oop nor globals? Append some pointer to Dialog where to find a datapointer and store data in heap...
    Rene - you can do this even now, via DIALOG SET/GET USER.


    Petr
    Last edited by Petr Schreiber; 26-08-2013 at 22:14.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    I like SHARED idea.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    Quote Originally Posted by Petr Schreiber View Post
    ...
    Rene - you can do this even now, via DIALOG SET/GET USER.


    Petr
    Of course- but there are "only" 4 user-slots and I think they should stay available to the user. I just would hide the "shared" data in heap. As long as the dialog-handle is known the related heap will be easy to find or access. I think it probably will never need to change size nor its pointer - and just changing values inside through some local overlay won't matter as long as the size stays as it is. This needs no additional variables - and it could hide a whole udt, array or a book of the bible.

    But anyway - I can't await to get my fingers onto these new functionalities - try out, test and surprise you once more
    Last edited by ReneMiner; 27-08-2013 at 11:27.
    I think there are missing some Forum-sections as beta-testing and support

  7. #7
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    Not to trash your thread - check this - it's not real oop but ensures a private scope through heap - could be a way straight through between - tB goes it's own way...
    I think there are missing some Forum-sections as beta-testing and support

  8. #8
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    no one cares what sb is made up of... - as long as you don't read the linked thread your comment is just... another useless comment.
    Last edited by ReneMiner; 03-09-2013 at 20:46.
    I think there are missing some Forum-sections as beta-testing and support

  9. #9
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Eros,

    the highlevel devil in my head still talks and I must repost his prophecy: What about adding some more easy to read event parameters overlays?

    Take for example OnSize handler - wouldn't it be nice to be able to access OnSize_Width, OnSize_Height pseudovariables instead of Win32ish CBWPARAM, CBLPARAM?


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  10. #10
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Petr,

    you are asking too much but ... who knows

    In the meantime the following is what will be present in next update. Do you see anything ... new?

      uses "UI"  Uses "console"
           
      Begin ControlID       
        %IDC_TIMER      
        %IDC_LABEL      
        %IDC_Start      
        %IDC_Stop       
      End ControlID
       
      %TIMER_DELAY    = 10          '---Timer delay (in milliseconds, not very accurate below about 100)
    
    
      Global TimerValue As Double   '---Will be used to calculate timer values
    
    
      '------------------------------------------------------------------------------
      ' Main function
      '------------------------------------------------------------------------------
      FUNCTION TBMain() as long
        LOCAL hDlg AS DWORD
                
        Dialog New Name "TimerDialog", 0 , "Timer Example using CallBacks functions", -1, -1, 240, 40, %WS_OVERLAPPEDWINDOW  To hDlg
    
    
        Control Add Button, Name "cmdStart", hDlg, %IDC_Start, "Start" ,  10, 10, 50, 20
        Control Add Label ,                  hDlg, %IDC_LABEL, ""      ,  90, 10, 55, 20, %WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %SS_CENTERIMAGE Or %SS_CENTER
        Control Add Button, Name "cmdStop" , hDlg, %IDC_Stop , "Stop"  , 180, 10, 50, 20
       
        Dialog Show Modal hDlg 'Call MainDialog_OnCallBack        
        
      END FUNCTION
    
    
     
      '------------------------------------------------------------------------------
      ' TimerDialog OnCallBack
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnCallBack() As Long
        'PrintL Timer, Function_Name, CBMSG             
      End Function
    
    
    
    
      '------------------------------------------------------------------------------
      ' TimerDialog OnCommand
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnCommand() As Long
    '    Select Case CBCTL
    '
    '      '---Check which control as fired the event
    '      Case %IDC_Start
    '        '---If start, than enable/disable relevant buttons and activate the timer
    '        Control Disable CBHNDL, %IDC_Start
    '        Control Enable CBHNDL, %IDC_Stop
    '
    '        TimerValue = 0              '---Set the time counter to zero
    '        Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
    '
    '      Case %IDC_Stop
    '        '---If sstop, than enable/disable relevant buttons and destroy the timer
    '        Control Disable CBHNDL, %IDC_Stop
    '        Control Enable CBHNDL, %IDC_Start
    '        Dialog Kill Timer CBHNDL, %IDC_TIMER
    '
    '    End Select
      End Function
      
      '------------------------------------------------------------------------------
      ' TimerDialog OnInit
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnLoad() As Long
        Control Disable CBHNDL, %IDC_Stop
      End Function
    
    
      '------------------------------------------------------------------------------
      ' TimerDialog OnTimer
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnTimer() As Long
        '---This event is fired by any timer created on the dialog. We have to check which one
      
          '---CBWPARAM contains the ID of the timer that fired %WM_TIMER event
          '---More than one timer can be active sumultaneously
          Select Case CBWPARAM
            Case %IDC_TIMER
              '---Increment and set the test value...
              TimerValue += 0.01
              Control Set Text CBHNDL, %IDC_LABEL, Format$(TimerValue, "#0.00")
          End Select
      End Function
        
      '------------------------------------------------------------------------------
      ' TimerDialog OnSize
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnSize() As Long
        PrintL Timer, "Sizing", CBWPARAM, CBLPARAM
      End Function
      
      '------------------------------------------------------------------------------
      ' TimerDialog OnMove
      '------------------------------------------------------------------------------
      CallBack Function TimerDialog_OnMove() As Long
        PrintL Timer, "Moving", CBWPARAM, CBLPARAM
      End Function
    
    
      '------------------------------------------------------------------------------
      ' cmdStart OnClick
      '------------------------------------------------------------------------------
      CallBack Function cmdStart_OnClick() As Long
        PrintL Timer, "cmdStart_OnClick"
    
    
        '---If start, than enable/disable relevant buttons and activate the timer
        Control Disable CBHNDL, %IDC_Start
        Control Enable CBHNDL, %IDC_Stop
      
        TimerValue = 0              '---Set the time counter to zero
        Dialog Set Timer CBHNDL, %IDC_TIMER, %TIMER_DELAY
    
    
      End Function
    
    
      '------------------------------------------------------------------------------
      ' cmdStop OnClick
      '------------------------------------------------------------------------------
      CallBack Function cmdStop_OnClick() As Long
        PrintL Timer, "cmdStop_OnClick"
    
    
        '---If sstop, than enable/disable relevant buttons and destroy the timer
        Control Disable CBHNDL, %IDC_Stop
        Control Enable CBHNDL, %IDC_Start
        Dialog Kill Timer CBHNDL, %IDC_TIMER
    
    
      End Function
    
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Page 1 of 2 12 LastLast

Similar Threads

  1. OOP ideas
    By ErosOlmi in forum Suggestions/Ideas discussions
    Replies: 13
    Last Post: 26-08-2013, 20:26
  2. New karma options
    By ErosOlmi in forum General
    Replies: 2
    Last Post: 13-09-2006, 19:35
  3. New Options Management
    By RobertoBianchi in forum thinAir General
    Replies: 3
    Last Post: 24-02-2006, 13:48

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •