Results 1 to 3 of 3

Thread: Yet another question, Scroll bars

  1. #1

    Yet another question, Scroll bars

    Hi all,

    Is it possible to put some scroll bars on a Canvas / TBGL window (or do I have to create a separate form for it ?).
    I need to look into a very wide BMP at pixel level (math related)

    Thanks in advance ,

    Rob

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

    the easiest way to achieve this is to use concept of viewports. You can nest dialog into dialog this way.

    So you will have one main dialog, and one secondary, while the secondary will contain just the CANVAS/TBGL surface.

    There are some examples in SampleScripts, but I crafted a simpler one here for you:
    Uses "UI"
    
    ' -- ID numbers of controls
    Begin ControlID
      %Main_Viewport
    End ControlID    
    
    Begin Const
      %MAIN_WIDTH   = 320
      %MAIN_HEIGHT  = 240
    End Const
    
    ' -- Create dialog here
    Function TBMain()
      Local hDlg As DWord
      Local hViewport As DWord
      
      Dialog New Pixels, 0, "Minimalistic viewport demo",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
                    %WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg
      
      ' -- Place controls here
      hViewport = Control Add VIEWPORT, hDlg, %Main_Viewport, "", 10, 10, %MAIN_WIDTH-20, %MAIN_HEIGHT-20
      Dialog_WithCanvas(hViewport)
     
      Dialog Show Modal hDlg, Call cbDialog
    
    End Function
    
    ' -- Callback for main dialog
    CallBack Function cbDialog()
    
      ' -- Test for messages
      Select Case CBMSG
    
        Case %WM_INITDIALOG
        ' -- Put code to be executed after dialog creation here
    
        Case %WM_COMMAND
        ' -- You can handle controls here
    
        Case %WM_CLOSE
        ' -- Put code to be executed before dialog end here
    
      End Select
    
    End Function
     
    Begin ControlID
      %Viewport_Canvas
    End ControlID    
     
    '----------------------------------------------------------------------------
    
    Function Dialog_WithCanvas(hViewPort As DWord)
    
      Local hDlg    As Long
    
      Dialog New Pixels, hViewPort, "", 0, 0, 500, 500, %WS_CHILD Or %WS_CLIPCHILDREN To hDlg
    
      Control Add Canvas , hDlg, %Viewport_Canvas, "", 0, 0, 500, 500
      Canvas_Attach(hDlg, %Viewport_Canvas, TRUE)
        Canvas_Clear(%BLACK)
        Canvas_Line((0,0), (500, 500), %GREEN)
        Canvas_Line((500,0), (0, 500), %GREEN)
      Canvas_Redraw
      
      Dialog Show Modeless hDlg, Call cbCanvasDialog
    
      ViewPort_SetChild(hViewPort, hDlg, FALSE )
      
      Function = hDlg
    End Function
    
    ' -- Callback for canvas dialog
    CallBack Function cbCanvasDialog()
    
      ' -- Test for messages
      Select Case CBMSG
    
        Case %WM_INITDIALOG
        ' -- Put code to be executed after dialog creation here
    
        Case %WM_COMMAND
        ' -- You can handle controls here
    
        Case %WM_CLOSE
        ' -- Put code to be executed before dialog end here
    
      End Select
    
    End Function
    
    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

  3. #3
    Thanks alot , Petr .... perfect !

Similar Threads

  1. Question of the day ;)
    By Petr Schreiber in forum thinBasic General
    Replies: 8
    Last Post: 23-08-2010, 19:58
  2. C to TB question
    By Michael Clease in forum Other languages
    Replies: 2
    Last Post: 03-06-2010, 12:11
  3. gdi question
    By Lionheart008 in forum UI (User Interface)
    Replies: 6
    Last Post: 07-12-2009, 19:31
  4. UDT question
    By sandyrepope in forum thinBasic General
    Replies: 3
    Last Post: 18-02-2008, 22:33
  5. m15 question
    By kryton9 in forum M15 file format
    Replies: 4
    Last Post: 20-06-2007, 20:18

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
  •