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):
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.
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