Results 1 to 6 of 6

Thread: How to retrieve thumb position of canvas?

  1. #1

    How to retrieve thumb position of canvas?

    When I create a large canvas, set it to virtual mode, and use the scroll bars to move around it, how do I receive events (like %WM_HSCROLL) for those scroll bars? I'd like to update other controls in my main window as the user drags the canvas around under the viewport.

    I have set my canvas up to use a callback, and in that callback I'm looking for %WM_HSCROLL and %WM_VSCROLL but I never see them come through.

    Thanks-

    *Brian

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,311
    Blog Entries
    2
    Rep Power
    10
    Mmmm, not sure you can actually trap that event.

    Canvass callback handle only 4 events:
    %STN_CLICKED
    Sent when the user clicks a mouse button on the graphic control (unless the image control has been disabled).
    %STN_DBLCLK
    Sent when the user double-clicks on a graphic control (unless the control has been disabled).
    %STN_DISABLE
    Sent when a graphic control has been disabled.
    %STN_ENABLE
    Sent when a graphic control has been enabled.


    http://www.thinbasic.com/public/prod...add_canvas.htm

    I have to study if it is possible and how.
    Maybe subclassing the control.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  3. #3
    That's OK - I've found a workaround for now. I simply read the position of the viewport from within a timer, which gives me the position the user has moved the thumb to.

    *Brian

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,311
    Blog Entries
    2
    Rep Power
    10
    Ah, OK, using Canvas_GetView, right?

    In any case I will see what I can do.
    Not all functionalities are developed in thinBasic but very often we develop new features when someone is interested.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

  5. #5
    Eros- yes, that is exactly correct. This system works pretty well actually.

    If I could ask for the moon, it would be very helpful to be able to control the width of the thumb on the canvas. For example, with extremely wide canvases, the horizontal scroll thumb becomes very narrow, making it harder to grab with a mouse (especially if you have gloves on, or are using a touchscreen PC). If we had control over that width, it would be kinda nice.

    Absolutely not a critical thing though. Very low priority request.

    Thanks!

    *Brian

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    51
    Posts
    8,311
    Blog Entries
    2
    Rep Power
    10
    Not sure I will be able to remove automatic scrollbar or resize it. Will check.

    A quick and dirty possible solution: add a new scrollbar bigger than the automatic one and use both to scroll our virtual window.

    Uses "UI"
    
    Dim x,y As Double
    
    Begin ControlID
      %ID_Canvas
      %ID_hScroll
    End ControlID
    
    Function TBMain() As Long
      Local hDlg As DWord '---Used to store window handle of main dialog
       
      hDlg = Dialog_New Pixels, 0, "very wide graphics ", -1, -1, 1200, 775,
      %WS_DLGFRAME | 
      %DS_CENTER | 
      %WS_CAPTION | 
      %WS_SYSMENU | 
      %WS_OVERLAPPEDWINDOW
       
      Dialog Show Modal hDlg, Call cbDialog
    End Function
    
    CallBack Function cbDialog() As Long
      STATIC lPos, lMin, lMax, lStep, lPage AS LONG
      static vVirtualWidth as Long
    
      Select Case CBMSG
        Case %WM_INITDIALOG
          Control Add Canvas, CBHNDL, %ID_Canvas, "", 50, 10,1000, 400, %WS_BORDER | %WS_CHILD | %WS_VISIBLE
          Canvas_Attach(CBHNDL, %ID_Canvas, %FALSE)
          vVirtualWidth = 100000
          Canvas_SetVirtual(100000, 380)
          Canvas_SetView(0,0) 
          Canvas_Width(2)
          Canvas_Clear %BLACK 
    
    
          '---Add a scrollbar big enough to be used with fingers
          Control add SCROLLBAR CBHNDL, %ID_hScroll, "", 50, 430,1000, 100
          lStep = 2
          lPage = 10
          lMax  = 110 'set maximum to intended max + page size to allow page scroll to max
          lMin  = 1
          lPos  = 1
          SCROLLBAR_SETPAGESIZE CBHNDL, %ID_hScroll, lPage
          SCROLLBAR_SETRANGE CBHNDL, %ID_hScroll, lMin, lMax
          SCROLLBAR_SETPOS CBHNDL, %ID_hScroll, lPos
          
          '---Draw something till 2000
          For x = 0 To 2000 Step 0.1
            y = Sin(x)*20* Rndf(1, 2)*Cos(x/3)^2
            Canvas_Width(2)
            Canvas_Line( (x*10, y +100), (x*10, y +100) , Rgb(255, 255, 0) )
            Canvas_Redraw
          Next
          
        CASE %WM_HSCROLL
            'Process messages and perform calculations to change thumb position
            SELECT CASE LOWRD(CBWPARAM)
                CASE %SB_LINELEFT
                  lPos -= lStep
                CASE %SB_LINERIGHT
                  lPos += lStep
                CASE %SB_PAGELEFT
                  lPos -= lPage
                CASE %SB_PAGERIGHT
                  lPos += lPage
                CASE %SB_TOP
                  lPos = lMin
                CASE %SB_BOTTOM
                  lPos = lMax
                CASE %SB_THUMBTRACK
                  lPos = HI(WORD, CBWPARAM)
                  lPos -= mod(lPos, lStep)
                CASE ELSE
                  EXIT FUNCTION
            END SELECT
            
            'test limits, position thumb and update label showing position
            IF lPos > (lMax - lPage) THEN lPos = (lMax - lPage)
            IF lPos < lMin THEN lPos = lMin
            SCROLLBAR_SETPOS CBHNDL, %ID_hScroll, lPos
    
            Canvas_SetView(vVirtualWidth / 100 * lpos, 0)
    
      End Select
    
    End Function
    
    Click image for larger version. 

Name:	Capture.PNG 
Views:	25 
Size:	17.3 KB 
ID:	9822
    Last edited by ErosOlmi; 13-02-2018 at 22:27.
    www.thinbasic.com | www.thinbasic.com/community/ | psch.thinbasic.com
    Win10Pro 64bit - 8GB Ram - Intel i7 M620 2.67GHz - NVIDIA Quadro FX1800M 1GB

Similar Threads

  1. Replies: 3
    Last Post: 26-06-2017, 19:35
  2. Replies: 6
    Last Post: 16-06-2010, 06:40
  3. Replies: 8
    Last Post: 14-01-2010, 04:56
  4. Window position
    By ErosOlmi in forum thinAir General
    Replies: 3
    Last Post: 31-10-2005, 09:52

Posting Permissions

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