GooCanvas: header for advanced GTK drawing widget

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
TJF
Posts: 3581
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

GooCanvas: header for advanced GTK drawing widget

Postby TJF » Sep 21, 2011 13:16

Image

A new FB header is available for the library libgoocanvas. GooCanvas is a canvas widget for GTK+ that uses the cairo 2D library for drawing. Some features
  • Optional model/view split.
  • Uses interfaces for items and views.
  • Basic items - rect/ellipse/polyline/text/image/grid/group.
  • Path item, using SVG path specification strings.
  • Table item for layout of other items (similar to the GtkTable widget). (This also supports items whose requested height changes according to their allocated width, such as text items.)
  • Embedded GTK+ widgets.
  • Layers/stacking order with raise/lower functions.
  • Cascading styles - line width/style/dashes, colors, fill patterns.
  • Affine transformations for all items - rotations/scales/skews.
  • Event handling - button/motion events, "pointer-events" property like SVG.
  • Grabs - support for pointer and keyboard grabs.
  • Keyboard focus traversal.
  • Accessibility (item title and description properties and hierarchy stuff).
  • Printing (output to a given cairo_t).
  • Scrolling.
  • Zooming.
  • Static items that don't move as the canvas is scrolled or zoomed.
  • Item visibility setting - on/off/above zoom threshold.
  • Simple animation.
  • Scalable - support for thousands of items over a large canvas area.
  • Support for different units - pixels/points/inches/millimeters.

For details and binary download see original website.

Download FB part: goovanvas2.0.0 (GTK widget)

The archiv contains the new FB header and some FB examples, translated from C code from the original tarball.

Have fun, share your results!

Hint:
To use this header you'll need a GTK installation that includes Cairo (since 2.16, recomended: 2.22) and the GTK-2.22.0_TJF.bi header from GladeToBac3.0.2.zip (ot later - some improvements have been done in gobject).

Edit: Hint added. Links added.
Last edited by TJF on Sep 22, 2011 6:51, edited 2 times in total.
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

Do you have binaries for WIN?

Postby vladimir777 » Sep 22, 2011 0:33

Do you have binaries for WIN?
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

Postby vladimir777 » Sep 22, 2011 1:50

I have libgoocanvas-3.dll
in c:\opt\goocanvas\lib
----------------------------------

Code: Select all

#IF DEFINED(__FB_WIN32__)
#LIBPATH "C:\opt\GTK-2.22.1\lib" ' your paths here
#LIBPATH "C:\opt\goocanvas\lib"
#ENDIF

#INCLUDE "gtk/goocanvas-2.0.0.bi"
'#INCLUDE "gtk/GTK-2.22.0_TJF.bi"     DO I NEED THIS



#DEFINE NULL 0


And I got this ERRORS:

Code: Select all

goo.bas(43) warning 3(1): Passing different pointer types, at parameter 1 of G_TYPE_CHECK_INSTANCE_CAST()
goo.bas(43) error 1: Argument count mismatch, found 'GooCanvas' in 'goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000)'
goo.bas(43) warning 3(1): Passing different pointer types, at parameter 1 of GOO_CANVAS_SET_BOUNDS()
goo.bas(47) warning 3(1): Passing different pointer types, at parameter 1 of G_TYPE_CHECK_INSTANCE_CAST()
goo.bas(47) error 1: Argument count mismatch, found 'GooCanvas' in 'VAR root = goo_canvas_get_root_item (GOO_CANVAS (canvas))'
goo.bas(47) warning 3(1): Passing different pointer types, at parameter 1 of GOO_CANVAS_GET_ROOT_ITEM()

TJF
Posts: 3581
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Sep 22, 2011 6:37

vladimir777 wrote:I have libgoocanvas-3.dll
in c:\opt\goocanvas\lib

  • The linker needs libgoocavas.dll.a in c:\opt\goocanvas\lib (regarding your #LIBPATH).
  • When executing the runtime loader needs libgoocanvas-3.dll in any folder of your PATH environment variable.
  • fbc needs goocanvas-2.0.0.bi in ...\FreeBasic\inc\gtk (this seems to work allready).

vladimir777 wrote:And I got this ERRORS:

Sorry for that.

I forgot to add a hint while fighting with the tags at the german site. Now the hint is added at the end of the first post here (use an updated GTK-2.22.0_TJF.bi file from the GladeToBac3.0.2.zip archiv).
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

Postby vladimir777 » Sep 22, 2011 15:31

And I dont have
libgoocavas.dll.a
I've got just DLL when I download goocanvas binaries
TJF
Posts: 3581
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Sep 22, 2011 16:35

vladimir777 wrote:And I dont have
libgoocavas.dll.a

Is this your first download?
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

It works

Postby vladimir777 » Sep 22, 2011 17:02

All examples works but demo-focus.bas
There I've got this error
demo-focus.o fake undefined reference to gtk_widget_set_can_focus ...
---------------------------------------------------------
I like your arrowhead example. Like you editing arrows maybe it is posible to place any component eg Button, Label, etc which would be good for creating FORMEDITOR.

I know that QT canvas now replaced with QGraphicsView can do that.
-----------------------------------------------------------------
It is really nice TJF, but I have no time to experiment more now

PANIC, boss is comming :)
TJF
Posts: 3581
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: It works

Postby TJF » Sep 22, 2011 17:14

vladimir777 wrote:All examples works ...

Fine! (These are not my samples, I just translated them from C source.)

vladimir777 wrote:but demo-focus.bas
There I've got this error
demo-focus.o fake undefined reference to gtk_widget_set_can_focus ...

The linker cannot find the 'gtk_widget_set_can_focus' function. (I dont understand it -- this one is in GTK2 and GTK3 ?!?)
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

PATHDEMO EXAMPLE

Postby vladimir777 » Sep 22, 2011 18:02

Code: Select all


#IF DEFINED(__FB_WIN32__)
#LIBPATH "C:\opt\GTK-2.22.1\lib" ' your paths here
#LIBPATH "C:\opt\goocanvas\lib"
#ENDIF

#INCLUDE "gtk/goocanvas-2.0.0.bi"
'#INCLUDE "gtk/GTK-2.22.0_TJF.bi"

#DEFINE NULL 0

gtk_init (@__FB_ARGC__, @__FB_ARGV__)

VAR win = gtk_window_new (GTK_WINDOW_TOPLEVEL)
gtk_window_set_default_size (GTK_WINDOW (win), 640, 600)
gtk_widget_show (win)
g_signal_connect (win, "delete_event", G_CALLBACK(@gtk_main_quit), NULL)

VAR scrolled_win = gtk_scrolled_window_new (NULL, NULL)
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN)
gtk_widget_show (scrolled_win)
gtk_container_add (GTK_CONTAINER (win), scrolled_win)

VAR canvas = goo_canvas_new ()
gtk_widget_set_size_request (canvas, 600, 550)
goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000)
gtk_widget_show (canvas)
gtk_container_add (GTK_CONTAINER (scrolled_win), canvas)

VAR root = goo_canvas_get_root_item (GOO_CANVAS (canvas))

VAR path_item1 = goo_canvas_path_new (root, "M20,100 C20,50 100,50 100,100", "stroke-color", "blue", NULL)
VAR path_item2 = goo_canvas_path_new (root, "M 200 500 L 40 40", "stroke-color", "red", NULL)
VAR path_item3 = goo_canvas_path_new (root, "M200,500 h-150 a150,150 0 1,0 150,-150 z", "fill-color", "green", "stroke-color", "blue", "line-width", 1.0, NULL)
VAR path_item4 = goo_canvas_path_new (root, "M100,200 C100,100 250,100 250,200 S400,300 400,200",  "stroke-color", "green", "line-width", 5.0, NULL)

gtk_main ()
END 0

/'
M (absolute)
m (relative)   
Parameters:  (x y)+   
moves to the given (x, y) coordinates to start a new subpath
=================================================================================
Z or z   none   closes the current subpath
=================================================================================
L (absolute)
l (relative)   
Parameters: (x y)+   
draws a line to the given (x, y) coordinates
=================================================================================
H (absolute)
h (relative)   
Parameters: x+   
draws a horizontal line to the given x coordinates
=================================================================================
V (absolute)
v (relative)   
Parameters: y+   
draws a vertical line to the given y coordinates
=================================================================================
C (absolute)
c (relative)   
Parameters:  (x1 y1 x2 y2 x y)+   
draws a cubic Bézier curve to the given (x,y) coordinates, uses the given
(x1,y1) coordinates as the first control point, the (x2,y2) coordinates as the second control point
=================================================================================
S (absolute)
s (relative)   
Parameters:  (x2 y2 x y)+   
short hand of the C/c command: the reflection relative to the current
point of the second control point of the previous command is used as the first control point.
=================================================================================
Q (absolute)
q (relative)   
Parameters: (x1 y1 x y)+   
draws a quadratic cubic Bézier curve to the given (x,y) coordinates,
uses the given (x1,y1) coordinates as the control point.
=================================================================================
T (absolute)
t (relative)   
Parameters: (x y)+   
short hand of the Q/q command: the reflection relative to the current point of the control
point of the previous command is used as the control point.
=================================================================================
A (absolute)
a (relative)   
Parameters: (rx ry x-axis-rotation large-arc-flag sweep-flag x y)+   
draws an elliptical arc to (x, y): the size and rotation of the ellipse are defined by two
radii (rx, ry) and the x-axis-rotation; the center (cx, cy) of the ellipse is also determined by the
large-arc-flag and sweep-flag constraint.

'/
AGS
Posts: 1284
Joined: Sep 25, 2007 0:26
Location: the Netherlands

Postby AGS » Sep 22, 2011 21:33

Nice one, TJF. GooCanvas looks good.
TJF
Posts: 3581
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Sep 23, 2011 5:24

AGS wrote:Nice one, TJF. GooCanvas looks good.

Thank you!

Unfortunatelly I couldn't make it work with GTK3 yet.
TJF
Posts: 3581
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Sep 23, 2011 14:57

I added another example at Tips and Tricks.

This library is fun!
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

Postby vladimir777 » Sep 23, 2011 15:57

TJF
Posts: 3581
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Postby TJF » Sep 23, 2011 17:21


I did know SciGraphica, but I didn't know that they published their library (since May 2011).

The library is outdated. They deal with old GTK versions (2.18 ATM) and they have old features in their lib (like GtkCList). Their Sheet widget is a simple ListView. Most of their buttons are available in GTK allready. Of course, they have some nice graphs. But the main downside is: they do not use Cairo.
vladimir777
Posts: 94
Joined: Aug 19, 2011 18:28

Postby vladimir777 » Sep 23, 2011 17:49

There is a confusion (at least for me as beginer in GTK) with versions.

I start with version 2, then I switched to 3, and now because of goocanvas I am back to version 2.

I am not using GTK in any real project now, just learning
and I will use both for now.
I discover that GTK is powerful

and by the way TJF why I can not flip axes so zero is in lower left corner

For maps LONG-LAT, and UTM projections

I can recalculate coordinates but is it the only way??

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest