[Gambas-user] I need help to start drawing with Gambas

Tobias Boege taboege at ...626...
Sun Jul 30 22:51:23 CEST 2017


On Sun, 30 Jul 2017, Fernando Cabral wrote:
> Perhaps some of you have a little time available to point me the direction
> for this littledelineate project of mine.
> 
> I like to play with sundials. Basically, it consists in calculating some
> lines and angles and then drawing them on the ground, marble, concrete,
> etc. Things are conceptually very easy. I have line lengths and angles. I
> can use either or both to delineate the sundial face.
> 
> I would guess I will have to resort to cairo or chart, but I don't know
> where to start from. I'd appreciate a few hints.
> 

It doesn't have to be gb.cairo. You can use the Paint class of gb.qt4 if
you use gb.qt4 anyway. The interfaces of both drawing classes are very
similar either way. Use gb.cairo if you want to export your drawings to
PDF or Postscript and Paint for everything else (it allows you to draw
into windows of your Gambas process, to a printer, to svg or bitmap images).

Something that may be confusing when you first encounter it is the path-
based drawing that is used in Cairo and Paint. Most methods of the Paint
class don't paint anything but create and manipulate paths (it memorises
movements on the drawing surface). To create a drawing you have to call
Stroke() or Fill() on the path, to realise the memorised movement on the
paper, so to speak, e.g.

  Paint.Ellipse(0, 0, 10, 10)

will give you a circle of diameter 10 centered around the origin -- and by
that I mean a circle *path*. If you want a normal circle, you have to call
Stroke() afterwards. If you want a solid disc, call Fill() on the path.

To get you started, you can find the ancient AnalogWatch example on the
software farm, which draws an analog wall clock. If you're proficient
with trigonometry you can concentrate on the Paint bits of the source
code. There is also a chapter on Cairo in the German Gambas-Buch [1]
(with example projects) and many more in the Paint chapter [2].

And, as always, look into the source code of Gambas itself. Lots of
graphical controls written in Gambas (gb.form and gb.gui.base) draw
themselves with Paint. You can find examples of arbitrarily high
complexity (gb.form.terminal and the GridView from gb.gui.base come
to mind). There are also plenty of easier examples, like the Spinner
class in gb.form.

Regards,
Tobi

[1] https://gambas-buch.de/dw/doku.php?id=k25:k25.1:start
[2] https://gambas-buch.de/dw/doku.php?id=k23:k23.3:start

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list