[Gambas-user] Using gb.Cairo
John Dovey
dovey.john at gmail.com
Mon May 17 22:25:02 CEST 2021
I applied another one, slightly different from the first I asked. I figured
others might like to see:
Dim hImg As New Image(PictureBox1.W, PictureBox1.H)
Dim h As Integer = 60
Cairo.Begin(hImg)
Cairo.Source = Cairo.SolidPattern(224, 224, 224, 0) ' Background. Pattern
is RGB
Cairo.Paint()
Cairo.Font.Name = "Serif"
Cairo.Font.Slant = Cairo.FontSlantItalic
Cairo.Font.Weight = Cairo.FontWeightBold
Cairo.Font.Size = h
Cairo.Source = Cairo.SolidPattern(0, 0, 0)
Cairo.MoveTo(40, 60)
Cairo.Text("El Gato de Fuego")
Cairo.Fill
Cairo.Source = Cairo.SolidPattern(0.5, 0.5, 0.2)
Cairo.MoveTo(43, 63)
Cairo.Text("El Gato de Fuego")
Cairo.Fill()
Cairo.End()
PictureBox1.Picture = hImg.Picture
-- End Code --
I'm not too sure about the "floating point" parameters. I can't quite
figure that out. How do I translate for example RGB 102,102,0 (Green) (RGB
Color Tables <https://www.rapidtables.com/web/color/RGB_Color.html>) to
the required floating point? I got the green I wanted from just trial and
error.
On Mon, 17 May 2021 at 14:34, Tobias Boege <tobs at taboege.de> wrote:
> On Mon, 17 May 2021, John Dovey wrote:
> > Hi,
> > I am quite keen to use the Cairo component. I am having no luck though
> even
> > starting.
> > The docs tell me that
> > "Before starting drawing anything, you must call the Begin
> > <http://gambaswiki.org/wiki/comp/gb.cairo/cairo/begin> method by
> passing it
> > the Image <http://gambaswiki.org/wiki/comp/gb.image.effect/image> where
> you
> > want to draw."
> >
> > I figured the simplest way to do this would be to create a Picturebox on
> a
> > form, and pass that to Cairo.Begin. That didn't work.
> > A hint on how to do this would help tremendously.
> >
>
> A PictureBox is a control which displays a Picture. You cannot draw on
> a PictureBox directly. You have to draw with Cairo on a Picture object
> and then display the result in a PictureBox (actually, you draw on an
> Image object, which is slightly different from a Picture). Alternatively,
> you can draw on a DrawingArea, but not with the Cairo component, only
> with the (GUI toolkit-specific) Paint class whose interface is very
> similar to Cairo...
>
> If that was too confusing, don't worry. I have also attached a project
> which implements most(!) of your C code in Gambas. I think once you have
> figured out how to start drawing, the translation is straightforward.
>
> The only thing I could not copy is the cairo_pattern_set_extend()
> setting, so the result looks different (the gradient is not repeating).
> There is only one mention of this function in the gb.cairo source code
> and that is limited to Cairo.ImagePattern(). Apparently you cannot
> apply an Extend to a LinearGradient currently.
>
> This is probably an oversight and you should file a feature request
> at http://gambaswiki.org/bugtracker
>
> Best,
> Tobias
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210517/b4b532e4/attachment.htm>
More information about the User
mailing list