Results 1 to 4 of 4

Thread: [RESOLVED] The function equivalent to DrawFocusRect API ? (vbRichClient5)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Resolved [RESOLVED] The function equivalent to DrawFocusRect API ? (vbRichClient5)

    I need to draw Focus-Rect with CairoContext. I looked at the source code of vbWidgets and found the code snippet related to dotted-rectangle:

    cThemeWin7:
    Code:
        '...
        '...
    
        Case thmTypeDottedRectangle
            CC.SetLineWidth 1 / ZoomFac
            x = CLng(x * ZoomFac) / ZoomFac '- 0.05 '+ 0.05
            y = CLng(y * ZoomFac) / ZoomFac '+ 0.05
            Offs = 0.50005 / ZoomFac
            Size = 1.50005 / ZoomFac
            Radius = (Int(Radius * ZoomFac)) / ZoomFac '- 0.3
            dx = CLng((dx + 0.1) * ZoomFac) / ZoomFac - 0.1
            dy = CLng((dy + 0.1) * ZoomFac) / ZoomFac
            CC.RoundedRect x, y, dx, dy, Radius, True
              CC.SetDashes 0.85 / ZoomFac, Offs, Size
              CC.SetSourceColor vbBlack, Alpha * 0.7
            CC.Stroke
            
            CC.RoundedRect x, y, dx, dy, Radius, True
              CC.SetSourceColor vbWhite, Alpha * 0.6
              CC.SetDashes 1.75 / ZoomFac, Offs, Size
            CC.Stroke
    I'd like to know if there is a function equivalent to the DrawFocusRect API in RC5 that can draw the dotted rectangle very simply and quickly. Thanks
    Last edited by dreammanor; Jan 22nd, 2019 at 07:12 AM.

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: The function equivalent to DrawFocusRect API ? (vbRichClient5)

    IMO you need to experiment a bit more on your own...
    (the RC5 will not "explode" or something, when you try out some different arguments on some of the CC.methods)

    Here is the basic-setup for a fast "Drawing-Test on a CairoContext" (usually named CC in Drawing-Routines).
    (you might want to save that as a VB6-template, to have it loaded directly as a Project, including the RC5-reference):

    Code:
    Option Explicit
    
    Private Sub Form_Resize()
      ScaleMode = vbPixels 'ensure Pixel-Scalemode on the TestForm
      DrawOn Cairo.CreateSurface(ScaleWidth, ScaleHeight).CreateContext
    End Sub
    
    Private Sub DrawOn(CC As cCairoContext)
      CC.Paint 1, Cairo.CreateSolidPatternLng(vbWhite) 'set the Srf-BG-Color
      
      'place your CC-test-drawing-commands here...
      
      Set Picture = CC.Surface.Picture 'set the Srf-content as the Form-Pic
    End Sub
    That's it already, to be able to start experimenting...

    As for your question - I'd start with putting out a Rectangle first...
    Code:
    Private Sub Form_Resize()
      ScaleMode = vbPixels 'ensure Pixel-Scalemode on the TestForm
      DrawOn Cairo.CreateSurface(ScaleWidth, ScaleHeight).CreateContext
    End Sub
    
    Private Sub DrawOn(CC As cCairoContext)
      CC.Paint 1, Cairo.CreateSolidPatternLng(&H888888) 'set the Srf-BG-Color
    
      CC.SetLineWidth 1
      CC.Rectangle 30, 30, 155, 25, True
      CC.Stroke False, Cairo.CreateSolidPatternLng(vbGreen)
    
      Set Picture = CC.Surface.Picture 'set the Srf-content as the Form-Pic
    End Sub
    Now to the "dotted stroking"...
    As you can see in the Theme-Implementation - the call you obviously need is: CC.SetDashes Offset, PenDownInterval, PenUpInterval
    So let's give it a try - adding it to the previous test-code:

    Code:
    Private Sub Form_Resize()
      ScaleMode = vbPixels 'ensure Pixel-Scalemode on the TestForm
      DrawOn Cairo.CreateSurface(ScaleWidth, ScaleHeight).CreateContext
    End Sub
    
    Private Sub DrawOn(CC As cCairoContext)
      CC.Paint 1, Cairo.CreateSolidPatternLng(&H888888) 'set the Srf-BG-Color
    
      CC.SetLineWidth 1
      CC.Rectangle 30, 30, 155, 25, True
      CC.SetDashes 0.5, 1, 1
      CC.Stroke False, Cairo.CreateSolidPatternLng(vbGreen)
    
      Set Picture = CC.Surface.Picture 'set the Srf-content as the Form-Pic
    End Sub
    This is what's now rendered on the Form :

    (Pen goes "down for one Pixel" and then "up for one Pixel" - the background then "coming through" in the "pen-up-interval")

    Now, if you want to ensure, that the DottedLine has good visibility on dark - as well as light backgrounds, you might want to
    stroke also the "in-between pixels" where the Pen was currently "going up" - and that's where we need a second call - and where the Offset-Param comes in:

    Code:
    Private Sub Form_Resize()
      ScaleMode = vbPixels 'ensure Pixel-Scalemode on the TestForm
      DrawOn Cairo.CreateSurface(ScaleWidth, ScaleHeight).CreateContext
    End Sub
    
    Private Sub DrawOn(CC As cCairoContext)
      CC.Paint 1, Cairo.CreateSolidPatternLng(&H888888) 'set the Srf-BG-Color
      
      CC.ScaleDrawings 2, 2 'zoom the output by factor 2, to better see "the Pixels"
      
      CC.SetLineWidth 1
      CC.Rectangle 30, 30, 155, 25, True
      
      CC.SetDashes 0.5, 1, 1
      CC.Stroke True, Cairo.CreateSolidPatternLng(vbGreen) 'the True-Param leaves the Rect-Path on the stack
      
      CC.SetDashes 1.5, 1, 1 'we use a different Offset here, to "get into the Pen-Up-Spaces" of the previous call
      CC.Stroke False, Cairo.CreateSolidPatternLng(vbRed) 'False signifies, that the Rect-Path is no longer needed
     
      Set Picture = CC.Surface.Picture 'set the Srf-content as the Form-Pic
    End Sub
    Here again, what's now rendered on the Form (I've scaled the Drawings by factor 2, to make the Pixels better-recognizable color-wise):


    HTH

    Olaf

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: The function equivalent to DrawFocusRect API ? (vbRichClient5)

    Hi Olaf, your example shows very clearly how to draw dotted rectangles with Cairo, it's so simple and efficient, it's exactly what I need. Extremely grateful.

    One more thing, I haven't understood the meaning of 0.85 and 1.75 in the thmTypeDottedRectangle.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: [RESOLVED] The function equivalent to DrawFocusRect API ? (vbRichClient5)

    I found a problem. The min line width of CC.LineTo is 2 instead of 1, which means I can't use CC.LineTo to draw a line with a line-width of 1. Did I miss something?

    Code:
    Private Sub DrawOn_4(CC As cCairoContext)
        CC.Paint 1, Cairo.CreateSolidPatternLng(vbWhite)
        
        Dim x, y
        Dim dx: dx = 100
        Dim dy: dy = 100
                            
        CC.SetLineWidth 1
        
        '--- Draw Line1 ----------------------------------------------
        x = 50: y = 50
        CC.MoveTo x, y
        CC.LineTo x + dx, y
        CC.Stroke , Cairo.CreateSolidPatternLng(vbBlue)
        
        '--- Draw Line2 ----------------------------------------------
        x = 50: y = 100             '--- Line2
        CC.DrawLine x, y, x + dx, y, True, 1, vbRed
        
        Set Picture = CC.Surface.Picture
        
    End Sub
    Attached Images Attached Images  

Posting Permissions

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



Click Here to Expand Forum to Full Width