-
[VB6] Cairo BRUSH
I present the class I have named cCairoBrush.
It is not entirely complete, in fact initially I had thought of not posting it in CodeBank, but then I changed my mind because it seemed good enough and interesting enough.
What is it about?
The class is for drawing fairly advanced strokes.
Cairo in RC6 is very complete and implements for example these types of "strokes":
https://www.vbforums.com/images/ieimages/2023/12/15.jpg
https://www.vbforums.com/images/ieimages/2023/12/16.jpg
https://www.vbforums.com/images/ieimages/2023/12/17.jpg
I found myself in need of a tool to draw something more advanced than this last image. I built the class cCairoBrush.
In the first stage it more or less replicated Cairo's cc.Polygon.
https://www.vbforums.com/images/ieimages/2023/12/18.jpg
The curve is defined by a sequence of points (Addable via BRUSH.Addpoint)
This was achieved by automatically computing the control points between the nodal points by bringing this code into VB6:
"Draw a Smooth Curve through a Set of 2D Points with Bezier Primitives."
Sucessively I made each dot/knot have in its own color, and from one dot to another there was a gentle transition of color.
https://www.vbforums.com/images/ieimages/2023/12/19.jpg
In addition to the color transition there can also be opacity transition (alpha) defined at each nodal point.
https://www.vbforums.com/images/ieimages/2023/12/20.jpg
Then I added another property to each node that I called Radius , maybe half width would be more correct.
https://www.vbforums.com/images/ieimages/2023/12/21.jpg
https://www.vbforums.com/images/ieimages/2023/12/22.jpg
Finally I added another property, which is the outer (boundary) opacity. (Called BorderAlpha)
https://www.vbforums.com/images/ieimages/2023/12/23.jpg
However, this still does not work very well , in fact you can see a darker curve centrally (a spine) that is not very pleasing.
The code was written quite hastily, so perhaps it is a bit convoluted but I think it may be of interest.
For example in these videos you can see my use of it:
https://www.youtube.com/watch?v=oEgaflI6s9I
https://www.youtube.com/watch?v=bI4OkqPSIm4
Final Notes:
- To draw such "complex" curves, I have intensively used the cCairoPattern classes as explained in this example:
https://www.vbforums.com/showthread....=1#post5540317
https://www.vbforums.com/images/ieimages/2021/10/31.png
You can see on the left how it is possible to draw a patch with four curves and four corners of different colors.
When there is no BorderAlpha (BorderAlpha =1) each curve between two nodal points is drawn with 1 of these patches.
When BorderAlpha is present (BorderAlpha <>1), each curve between two nodal points takes 2 Pieces, one on one side and one on the other.
The code ( and subsequent updates of mine) is on GitHub
DOWNLOAD here: https://github.com/miorsoft/VB6-cCairoBrush
Aesthetic improvements to the final result and/or speedup of execution made by others will be appreciated.