Freebasic -GTK - Graphics

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
Posts: 18
Joined: Jun 19, 2023 8:30

Freebasic -GTK - Graphics

Post by Wawavoun »


I am in the way to start (at least try) coding some applications with FreeBASIC.

I need something cross platform Windows - Linux so after tests with FLTK and GTK I think I will use GTK3 with Glade + GladeToBac as ui builder.

Installing that under linux was easy but not so easy into Windows.
After some search and reading (msys2, etc...) finally I got Glade - GladeToBac - Freebasic working on both system and can compile and run simple things.

Now the question :
In the apps I need to draw some geometrical figures (lines, triangles, circles...) into a "canvas". I also need the functions for scaling this canvas and made pan and zoom (usually called world coordinates, screen coordinates etc...).
I found in the GTK documentation the "GtkDrawigArea". Is that what I sould use ? Or is there some better widget to do that ?

And where can I find tutorial, documentation and even samples in FreeBASIC language of what I try to do ? It seems I also need to learn some things about Cairo but it is unclear what I have to do with GTK (create the area) and with Cairo (draw into the area)...

Thanks and regards.
Posts: 107
Joined: Jan 17, 2021 7:27

Re: Freebasic -GTK - Graphics

Post by Avata »

you can try make code with "VisualFBEditor - IDE for FreeBasic" viewtopic.php?t=27284
VisualFBEditor based on the library MyFbFramework which is an open source library. A lot of programmers work with it with GTK3 in Linux
Posts: 18
Joined: Jun 19, 2023 8:30

Re: Freebasic -GTK - Graphics

Post by Wawavoun »

I give a try under Windows and look well !
I have to do some test under Linux now.

I have not mention than the graphical part can become very heavy with fe more than 10000 triangles to draw as fast as possible and then make zoom, pan etc on this image.

Cairo and GTK are fast in this kind of operation so in the same time I try to continue my test on the tool chain FB + GTK + Cairo and still search for tutos or examples about that.
Posts: 3
Joined: Feb 09, 2012 10:22

Re: Freebasic -GTK - Graphics

Post by Wawa »

VisualFBEditor works not smoothly under Linux (I use 22.04 LTS Kubuntu).

I can compile and run but the IDE show lot of what look like bugs.

Selection case stay empty (but the selection seems to act)
No way to resize controls with the mouse into a form
If change control size by hand in the properties its not take in account after compile... and so on !
Posts: 18
Joined: Jun 19, 2023 8:30

Re: Freebasic -GTK - Graphics

Post by Wawavoun »


I need some help usin GTK3 + Cairo into FreeBasic.

I have found an example of cade where Cairo draw into a "screen" opened with ScreenRes...
'' Example showing cairo being used to draw into the FB graphics window
#LIBPATH "c:\msys64\mingw64\lib"
#include once "cairo/"

Const SCREEN_W = 400
Const SCREEN_H = 300

ScreenRes SCREEN_W, SCREEN_H, 32

'' Create a cairo drawing context, using the FB screen as surface.
Var surface = cairo_image_surface_create_for_data(ScreenPtr(), CAIRO_FORMAT_ARGB32, SCREEN_W, SCREEN_H, SCREEN_W * SizeOf(ULong))

Var c = cairo_create(surface)


'' Draw the entire context white.
cairo_set_source_rgba(c, 1, 1, 1, 1)

'' Draw a red line
cairo_set_line_width(c, 1)
cairo_set_source_rgba(c, 1, 0, 0, 1)
cairo_move_to(c, 0, 0)
cairo_line_to(c, SCREEN_W - 1, SCREEN_H - 1)



'' Clean up the cairo context
How should I modify this code to draw the same thing into a GtkDrawingArea (or may be another Gtk widget but not a screen) ?
I belive I should change something into the "surface" declaration... I try "DrArea" instead of ScreenPtr() but I got a warning at compile and nothing is displayed..

Thanks and regards.
Xusinboy Bekchanov
Posts: 802
Joined: Jul 26, 2018 18:28

Re: Freebasic -GTK - Graphics

Post by Xusinboy Bekchanov »

Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°

Re: Freebasic -GTK - Graphics

Post by TJF »

The most advanced drawing widget for GTK is GooCanvas (based on Cairo). Ie the library GooData is based on that widget.

Post Reply