[Gambas-user] Using gb.Cairo

John Dovey dovey.john at gmail.com
Tue May 18 04:03:14 CEST 2021


I have a further question:

I have this code:

-- Begin Code --
  Dim hImg As New Image(frmMain.W, frmMain.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()
  'frmMain.Picture = hImg.Picture

  'Cairo.Begin(hImg)
  h = 20 ' Font Size
  Cairo.Font.Name = "Serif"
  Cairo.Font.Slant = Cairo.FontSlantItalic
  Cairo.Font.Weight = Cairo.FontWeightBold
  Cairo.Font.Size = h

  Cairo.Source = Cairo.SolidPattern(224, 224, 224, 0)
  Cairo.Source = Cairo.SolidPattern(0, 0, 0)
  Cairo.MoveTo(40, 90)
  Cairo.DrawText("New Generation FTN Network")

  Cairo.Rectangle(30, 100, 700, 300)
  Cairo.Fill

  Cairo.Source = Cairo.SolidPattern(0.4, 0, 0)
  Cairo.Rectangle(25, 95, 695, 295)
  Cairo.Fill
  Cairo.End
  frmMain.Picture = hImg.Picture

--- End Code --

As you can see, I'm writing directly to the form (frmMain.Picture).
It's working very well. What I find odd though (and I'm sure it's because I
don't truly understand what I'm doing) is that when I run the program the
form displays perfectly, just the way I expect it to. When I enlarge the
form by dragging on any of the borders, it seems the picture has been
"tiled". I don't see a tiled property for the form picture, so I'm assuming
I'm making the mistake in the Cairo code?

[image: Screenshot 2021-05-17 205613.png]

On Mon, 17 May 2021 at 16:22, Tobias Boege <tobs at taboege.de> wrote:

> On Mon, 17 May 2021, John Dovey wrote:
> > 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.
>
> See http://gambaswiki.org/wiki/comp/gb.cairo/cairo/solidpattern:
>
>   The color components are floating point numbers in the range 0 to 1.
>   If the values passed in are outside that range, they will be clamped.
>
> RGB color component c between 0 and 255 maps to float f via
>
>   f = c / 255
>   c = f * 255
>
> Thus (102, 102, 0) in 256-based RGB notation is (102/255, 102/255, 0/255)
> or just (0.4, 0.4, 0.0) in float notation.
>
> 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/91eff33e/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screenshot 2021-05-17 205613.png
Type: image/png
Size: 42938 bytes
Desc: not available
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20210517/91eff33e/attachment-0001.png>


More information about the User mailing list