gEvas: the GTK+2 to Evas Bridge
At its core, gEvas provides five things: it tells Evas when to repaint itself, assists in gluing Evas events and glib2 signals together, handles Edje timer calls to support animation, helps Evas play nice with GTK+2 widgets and codes to assist in Evas usage. Because Evas also is being targeted at embedded systems, some handy code is left out of the core Evas to make it lean. Because gEvas is desktop-targeted, it adds some handy functionality for desktop applications.
The following code creates a gEvas canvas inside a scrollable area and attaches it to a GTK+2 window. As not every scrollable gEvas will want to allow the middle button to drag the canvas position—as in The GIMP—you have to set this up outside of gevas_new_gtkscrolledwindow():
GtkWidget* window = 0;
GtkWidget* scw = 0;
GtkWidget* gevas = 0;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gevas_new_gtkscrolledwindow(
(GtkgEvas**)(&gevas), &scw );
gtk_container_add(GTK_CONTAINER(window), scw);
gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(scw),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gevas_set_middleb_scrolls(GTK_GEVAS(gevas), 1,
gtk_scrolled_window_get_hadjustment(
GTK_SCROLLED_WINDOW(scw)),
gtk_scrolled_window_get_vadjustment(
GTK_SCROLLED_WINDOW(scw)));
The gEvas API for creating objects takes a leaf from standard GTK+ coding, having some methods attached to a general GtkgEvasObj class. Other special classes, such as GtkgEvasImage, are derived from GtkgEvasObj. Unfortunately, this also brings the usual cast-heavy style of ANSI C GTK+ programming.
The following creates an image showing your PNG file at its original width and height. We then move the image and raise its layer in the canvas:
GtkgEvasImage* gi;
GtkgEvasObj* go;
gi = gevasimage_new_from_metadata(
GTK_GEVAS(gevas), "/my/path/foo.png" );
go = GTK_GEVASOBJ( gi );
int x = 100, y = 50;
gevasobj_move( go, x, y );
gevasobj_set_layer( go, 1 );
I created a simple client showing how to connect Evas events from the canvas to some GTK+2 widgets outside the gEvas widget. Look in the demo directory of the gEvas package for signalconnect.c. For a more-advanced example, take a look at the testgevas client for the use of both raw Evas callbacks and Evas-triggered callbacks that are marshaled to glib signals. Signalconnect is shown in Figure 3.

Figure 3. Connecting Evas and GTK+ signals. The dinosaur image can be dragged around either directly or by moving the slider bar.
Connecting to Evas events is handled by way of the GtkgEvasEvHClass subclasses. The below fragment causes evh to marshal Evas' mouse up/down events into glib signals, which then are connected to reporting functions. Also, when the user moves the raptor image, raptor_moved() is called by way of a glib2 signal to update various GTK+2 widgets with the current coordinates of the image:
static gint raptor_moved(
GtkgEvasObj* o,
Evas_Coord* x, Evas_Coord* y,
gpointer user_data )
{
gtk_progress_bar_set_fraction( x_coord_tracker,
(1.0 * (*x)) / CANVAS_WIDTH );
gtk_range_set_value(
GTK_RANGE(y_coord_tracker), *y );
return GEVASOBJ_SIG_OK;
}
static gboolean
gtk_mouse_down_cb(GtkObject * object,
GtkObject * gevasobj, gint _b, gint _x, gint _y,
gpointer data)
{
char buffer[1024];
snprintf(buffer,1000,"mouse_down b:%d x:%d y:%d",
_b, _x, _y);
gtk_label_set_text( e_logo_label, buffer );
return FALSE;
}
...
gi = gevasimage_new();
go = GTK_GEVASOBJ( gi );
gevasimage_set_image_name( gi, "raptor.png" );
...
/** Let the user drag the raptor around **/
GtkObject *evh = gevasevh_drag_new();
gevasobj_add_evhandler( GTK_GEVASOBJ( gi ), evh );
gtk_signal_connect( go, "move_absolute",
GTK_SIGNAL_FUNC( raptor_moved ), go );
gi = gevasimage_new();
go = GTK_GEVASOBJ( gi );
gevasimage_set_image_name( gi, "e_logo.png" );
...
evh = gevasevh_to_gtk_signal_new();
gevasobj_add_evhandler( GTK_GEVASOBJ( gi ), evh );
gtk_signal_connect(GTK_OBJECT(evh), "mouse_down",
GTK_SIGNAL_FUNC(gtk_mouse_down_cb), NULL);
gtk_signal_connect(GTK_OBJECT(evh), "mouse_up",
GTK_SIGNAL_FUNC(gtk_mouse_up_cb), NULL);
The following are some more functional event handlers that can be attached:
/* Standard GTK+ popup menu creation + handling */
static gboolean
gtk_popup_activate_cb(GtkObject * object,
GtkObject * gevasobj, gint _b, gint _x, gint _y,
gpointer data)
{
static GtkMenu *menu = 0;
...
}
GtkgEvasObj* go = ...;
GtkObject* evh = 0;
/* Make the object throb when mouse is over it */
GtkgEvasEvHThrob* evht = gevasevh_throb_new( go );
/* Allow the user to drag the object around */
evh = gevasevh_drag_new();
gevasobj_add_evhandler( go, evh );
/* Make a popup menu appear on right mouse click */
evh = gevasevh_popup_new();
gevasobj_add_evhandler( go, evh );
gtk_signal_connect(GTK_OBJECT(evh),"popup_activate",
GTK_SIGNAL_FUNC(gtk_popup_activate_cb), NULL);
Handling a selection in the canvas is a little trickier than the above event handlers. This is so because more than one object is involved in the selection process. You create a selector event handler object of class GtkgEvasEvHGroupSelector that attaches to the object you want as the background unselectable object. You can think of this object as where the rubber-band rectangle is drawn to indicate which objects should become selected. The rubber band always is drawn at a higher layer than the selectable objects. Each selectable object on the canvas then has a GtkgEvasEvHSelectable object attached to it that communicates with the GtkgEvasEvHGroupSelector object:
GtkWidget* gevas = ...;
GtkObject* evh_selector = 0;
GtkgEvasImage* gevas_image;
gevas_image = gevasimage_new();
gevasobj_set_gevas(gevas_image, gevas);
gevasimage_set_image_name(gevas_image,".../bg.png");
/* Make this a group_selector */
evh_selector = gevasevh_group_selector_new();
gevasevh_group_selector_set_object(
(GtkgEvasEvHGroupSelector*)evh_selector,
GTK_GEVASOBJ(gevas_image));
GtkgEvasObj* go = ...;
make_selectable( gevas, go, evh_selector );
...
/* lets make this object also selectable */
void make_selectable( GtkgEvasObj* object,
GtkObject* evhsel )
{
GtkgEvasObj* ct = 0;
GtkObject* evh = gevasevh_selectable_new( evhsel );
gevasevh_selectable_set_confine(
GTK_GEVASEVH_SELECTABLE(evh), 1 );
gevasobj_add_evhandler(object, evh);
gevasevh_selectable_set_normal_gevasobj(
GTK_GEVASEVH_SELECTABLE(evh), object);
ct = (GtkgEvasObj*)gevasgrad_new(
gevasobj_get_gevas( GTK_OBJECT(object)));
gevasobj_set_color( ct, 255, 200, 255, 200);
gevasgrad_add_color(ct, 120, 150, 170, 45, 8);
gevasgrad_add_color(ct, 200, 170, 90, 150, 16);
gevasgrad_set_angle(ct, 150);
gevasobj_resize( ct, 200,100);
gevasobj_set_layer(ct, 9999);
gevasevh_selectable_set_selected_gevasobj(evh,ct);
}
You then can easily test if objects are selected or get a collection object to perform operations on all objects selected:
GtkgEvasEvHGroupSelector* ev = ...; GtkgEvasEvHSelectable* o = ...; GtkgEvasObjCollection* col = 0; gboolean yn = gevasevh_group_selector_isinsel(ev,o); col = gevasevh_group_selector_get_collection( ev ); gevas_obj_collection_move_relative( col, 100, 200 );
In addition, some objects, such as geTransAlphaWipe, were created to perform image transitions before Edje existed. Although Edje is the way of the future, the alphawipe code allows you to perform a common simple transition without involving Edje. This is used in gevasanim to create a sprite-like object that transitions between its frames using alpha blending.
The xxx_from_metadata() functions in gEvas allow you to set up location, image filename, visibility and other attributes for a new object using a single string. Both the from_metadata() and the transition code duplicate functionality now also available in Edje:
sprite = gevas_sprite_new( GTK_GEVAS(gevas) );
for( i=1; i<frame_count; ++i )
{
gchar* md = g_strdup_printf(
"cell%ld.png?x=120&y=120&visible=0&fill_size=1"
,i);
gi = gevasimage_new_from_metadata( GTK_GEVAS(gevas), md );
g_free( md );
gevas_sprite_add( sprite, GTK_GEVASOBJ( gi ) );
}
gevas_sprite_set_default_frame_delay( sprite,2000 );
gevas_sprite_play_forever( sprite );
/* frame transitions */
geTransAlphaWipe* trans = 0;
trans = gevastrans_alphawipe_new();
for( i=0; i<frame_count; ++i )
gevas_sprite_set_transition_function(
sprite, i, trans );
For the grand finale, I put an Edje object onto the gEvas canvas. The client I created to demonstrate for this article is demo/gevasedje in the gEvas distribution. The interesting parts are shown below. The Edje itself has an Enlightenment logo that spins around and one that throbs under mouse clicks:
/* init engines */ ecore_init(); edje_init(); gtk_init(&argc, &argv); ... gevas = ...; /* allow edje to update the canvas as well */ gevas_setup_ecore( (GtkgEvas*)gevas ); /* place an edje object */ GtkgEvasEdje* gedje = gevasedje_new_with_canvas( gevas ); /* eet files can contain many edje objects */ gevasedje_set_file( gedje, "e_logo.eet", "test" ); go = GTK_GEVASOBJ(gedje); gevasobj_move( go, 300, 300 ); gevasobj_resize( go, 370, 350 ); gevasobj_set_layer( go, 10 ); gevasobj_show( go );
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- RSS Feeds
- Dynamic DNS—an Object Lesson in Problem Solving
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Designing Electronics with Linux
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- A Topic for Discussion - Open Source Feature-Richness?
- Drupal Is a Framework: Why Everyone Needs to Understand This
- Validate an E-Mail Address with PHP, the Right Way
- What's the tweeting protocol?
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




9 hours 53 min ago
14 hours 20 min ago
17 hours 55 min ago
18 hours 28 min ago
20 hours 51 min ago
20 hours 55 min ago
20 hours 56 min ago
1 day 1 hour ago
1 day 3 hours ago
1 day 8 hours ago