Example of a Simple Gambas App with Cairo Bindings

The advantages of Gambas as an IDE for Linux are numerous. This is a fantastic work with over 400 containerized applets, conveniently selectable by menu, all nicely arranged and ready for extention in BASIC programming language. The simplicity of the environment deserves attention, just the overwhelming relief of not having to play the callbacks and GTK+ windows games is enormous. You put down a control/widget/component, it actually stays where you put it (listen up Java, GTK+, python). You can play the Gnome windows placement game, but you actually don't have to! Woot!! And for those fools who like to reinvent the wheel, and think real programmers should take an axe into the forest and build their own wheel, "here's your wheel"! The environment now even comes with several compiler and packaging options to encapsulate your gems. You can save 4-5 hours on a simple app just not worrying about data type conversions.

Is it fleshed out and professional? No. The absence of an Edit menu is absolutely maddening. Storing all the files as hidden files instead of text, maddening. It is where Gimp was maybe ten years ago. And that's really crazy but not bad for a giant blue shrimp :-). (By the way, Gimp still needs a nanny to remove the amateur stuff and actually put the app together in a coherent whole, hey bazaar guys...)

So here is a simple app to use Cairo bindings. I found the basics on a French web site. Cairo is a graphics package uniquely suited for certain engineering applications like printed circuit boards and it exposes a series of primitives (you know, those things like lines and circles that are needed for graphics but are often described as being too trivial for the professional amateur, hence left for the unprofessional amateur to work out in their second or third lifetimes.) Cairo permits transparency, rounded line joinings, dithering, and a variety of nifty capabilities. Like SDL and other such bindings, the usual problem is establishing the canvas and managing all the hundreds of environment variables. It isn't clear to me how much of this has been solved by Gambas, but wrapping the Cairo graphics in a drawing layer has taken most of the grief out of this, including the callback issue. Having written some C++ and python programs with Cairo, I am impressed.

Gambas class file
 Private q As Integer

Public Sub _new()

Public Sub Form_Open()

Public Sub Button1_Click()
q = q + 1
Button1.text = "C-Systems\n Reactor Test:" & q
If q = 5 Then Button1.text = "you really need \nto floss more son\n Reactor Test:" & q
If q = 6 Then Button1.text = "but I meant to\n tell you Lyman!\n Reactor Test:" & q
If q = 9 Then
   Button1.text = "your retirement has\n already been arranged"

Public Sub rumrun()
Dim i As Float
Dim x As Float
Dim y As Float
Dim Tut As Image
Tut = New Image(300, 300, Color.blue)
If q = 9 Then
   Cairo.Source = Cairo.ColorPattern(Color.Red)
   Cairo.linewidth = 2
   'Cairo.MoveTo(100, 100)
   For i = 0 To 100 Step 0.1
      x = 100 * Sin(i) * Exp(- i / 100) + 150
      y = 100 * Cos(i) * Exp(- i / 100) + 150
      Cairo.Lineto(x, y)
   Cairo.moveto(130.0, 150)
   Cairo.Lineto(170.0, 150)
   Cairo.moveto(150.0, 130)
   Cairo.Lineto(150.0, 170)
   'Cairo.Fill() 'Ici je trace le contour ET je remplis  (thanks French guys)
Draw.Image(Tut, 0, 0)

Public Sub DrawingArea1_Draw()
Here is a picture of the app running. I may include the brz file later, or not, after all just a code example. But if you have downloaded gambas and the cairo C++ stuff, all you need to run the code above is to check the gb image, gb gui, and cairo modules under "project preferences". I had some trouble downloading gambas in fedora17 the package kit pipeline had jammed from doubling up on dependencies from other programs. I wasn't paying attention so I'm not sure it was Gambas. The package kit fix options from the command line cleared the pipe (fix, remove doubles, cleanup).

Microsoft, I meant to tell you...
Last modified July 29, 2012