Using the Canvas

Display a Rectangle

This chapter will introduce you into using CCC for creating custom widgets by using the canvas and the delivered primitives.

Display a Rectangle

Create a rectangle:

CcItem* rectangle = cc_rectangle_new ();

Specify the position (0,0) and size (100x100) of the rectangle:

cc_rectangle_set_position (CC_RECTANGLE (rectangle),
                           0.0, 0.0,
			   100.0, 100.0);

Fill the rectangle with red color:

cc_rectangle_set_brush_content (CC_RECTANGLE (rectangle),
				cc_brush_color_new (cc_color_new_rgb (1.0, 0.0, 0.0)));

Create a GtkWindow and a CcViewWidget :

GtkWidget* view = cc_view_widget_new ();
GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
/* put the view into the window */
gtk_container_add (GTK_CONTAINER (window), view);

Tell the view widget to display the rectangle:

cc_view_set_root (CC_VIEW (view), rectangle);

And now run the main loop:

gtk_main ();

Congratulations.