> ...problem always return NULL for creating canvas
Attached is a simple example which works for me.
Mike
/* Example of a simple click button using Evas. This illustrates many of the
basic techniques
and function calls used for Evas objects. The button can be any image in any
file format. By
having both a highlighted and normal version, the image can be made to
change its appearance
when the mouse cursor is positioned on it. Clicking the image closes the
program.
Author: Mike Hughes
Revised: 07/26/2009 */
#include <Evas.h>
#include <Ecore.h>
#include <Ecore_Evas.h>
#include <Ecore_File.h>
#include <stdlib.h>
#include <stdio.h>
/* Defines the size of the window in pixels */
const WIDTH = 400;
const HEIGHT = 300;
Ecore_Evas *EcoreCanvas; /* Pointer to the Ecore_Evas structure representing
the window */
Evas *EvasCanvas; /* Pointer to the Evas structure representing the
graphic canvas */
Evas_Object *Background; /* Pointer to the Evas structure representing the
background rectangle */
Evas_Object *Image; /* Pointer to the Evas structure representing the
button image */
Evas_Object *Caption; /* Pointer to the Evas structure representing the
text caption of the button */
int ImageWidth, ImageHeight; /* Size of the image, taken from the file
(pixels) */
int ImageX, ImageY; /* Position of the button image (pixels) */
int TextWidth, TextHeight; /* Size of the text object which will depend on
its content */
int TextX, TextY; /* Initial position of the text object (not used,
required by function call) */
/* Callback function which is called by Evas when the user clicks on either the
button image or the
text caption. In this case, it calls the function which closes out the main
event loop which
will terminate the program. The parameters of a callback function are:
Data - The pointer passed to the "callback_add" function. This is used to
associate a data
structure with the visible object and can be used for any purpose.
These are often
state variables used to keep track of where you are in a sequence
of events.
e - The Evas canvas containing the object. You might have multiple
canvases generating callbacks.
obj - The object generating the callback. You may have multiple objects
calling the same function.
event_info - A structure containing information about the event. This
varies with the type of event.
The structures for different events are defined in Evas.h. */
void OnClick(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
/* Terminate the event processing loop. This will cause the
ecore_main_loop_begin() function to
return and lead to termination of the program. The loop will also
terminate if the process
receives a SIGTERM, ie if you click on the "X" button of the window. */
ecore_main_loop_quit();
}
/* Callback function which is called when the user moves the mouse cursor on to
either
the image object or the text caption. It changes the image to the
highlighted version. */
void MouseOn(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
evas_object_image_file_set(Image, "button_hilited.png", "");
}
/* Callback function which is called when the user moves the mouse cursor off
of either the image
object or the text caption object. This replaces the image with the
non-highlighted version. */
void MouseOff(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
evas_object_image_file_set(Image, "button_active.png", "");
}
/************** Main routine ****************/
int main(void)
{
/* Initialize the Enlightenment Foundation Libraries */
if ((ecore_init() == 0)
|| (ecore_evas_init() == 0)
|| (evas_init() == 0))
{
printf("Could not init EFL\n");
return 1;
}
/* Use the Ecore_Evas library to open a new window and initialize an Evas
canvas. This specific function
uses the X Window backend to produce the graphics. Other "engines" are
available, such as one which
drives the video directly if it implements the Open GL standard. */
EcoreCanvas = ecore_evas_software_x11_new("", 0, 0, 0, WIDTH, HEIGHT);
if (EcoreCanvas == NULL)
{
printf("Could not open Window\n");
return 1;
}
/* Give the window a title and make it visible */
ecore_evas_title_set(EcoreCanvas, "Evas Button Example");
ecore_evas_show(EcoreCanvas);
/* Get a pointer to the Evas canvas */
EvasCanvas = ecore_evas_get(EcoreCanvas);
/* Create a basic rectangle object to fill the window background. An image
could be used. */
Background = evas_object_rectangle_add(EvasCanvas);
evas_object_resize(Background, WIDTH, HEIGHT);
/* The parameters for color set are "Red", Green", "Blue" and "Alpha" which
is opaqueness. Setting
the colors 255,255,255 makes it full white; 0,0,0 makes full black. This
setting is a light
gray. Setting "Alpha" to 255 prevents anythng behind the area from
showing through. */
evas_object_color_set(Background, 244, 243, 242, 255);
evas_object_show(Background);
/* Create an Image object for the button. Any kind of image in any common
file format will work.
Use GIMP or other tools to create the image. You usually want an image of
this type to have a
a transparent background so a format which supports that feature, such as
PNG, is a good idea.
PNG produces bigger files than JPEG but JPEG does not support
transparency. JPEG works well
for large background images. */
Image = evas_object_image_add(EvasCanvas);
evas_object_image_file_set(Image, "button_active.png", "");
/* Set the size and fill mode - It appears that the generic object must be
resized,
positioned and the fill mode set before it can be shown. It cannot
default this from the
file, so you have to get the dimension of the Image in the file using the
evas_object_image_size_get() function if you want to keep the original
size in the file. You
can, of course, make it any size you want. Evas will be happy to scale it
for you. */
evas_object_image_size_get(Image, &ImageWidth, &ImageHeight);
evas_object_resize(Image, ImageWidth, ImageHeight);
evas_object_image_fill_set(Image, 0, 0, ImageWidth, ImageHeight);
/* Evas supports layers which are not necessary and may or may not be useful
*/
evas_object_layer_set(Image, 2);
/* Center it on the window */
ImageX = WIDTH/2 - ImageWidth/2;
ImageY = HEIGHT/2 - ImageHeight/2;
evas_object_move(Image, ImageX, ImageY);
evas_object_show(Image);
/* Superimpose a text label on it */
Caption = evas_object_text_add(EvasCanvas);
/* Set the font name and size */
evas_object_text_font_set(Caption, "liberation", 12);
/* Set the text for the caption */
evas_object_text_text_set(Caption, "Close");
/* Use white text if the image is dark */
evas_object_color_set(Caption, 255, 255, 255, 160);
evas_object_layer_set(Caption, 3);
/* Get the size of the text and center it on the button. The size will
depend on the content. */
evas_object_geometry_get(Caption, &TextX, &TextY, &TextWidth, &TextHeight);
evas_object_move(Caption,ImageX + (ImageWidth/2 - TextWidth/2),
ImageY + (ImageHeight/2 - TextHeight/2));
evas_object_show(Caption);
/* Add callbacks for mouse events on both the image and text objects. The
function named as the
third parameter will be called when the event specified by the constant in
the second parameter
occurs. These constants are defined in "Evas.h". The same functions will
be called for either
object. There is a problem in that a "MOUSE_OUT" event will occur on the
image when you move
the cursor onto the caption. If you want to keep the highlighted mode in
the image, you have
to set it back when the mouse cursor moves to the caption. It happens too
fast to see.
The last parameter can be a pointer to any kind of data structure and this
pointer will be passed
to the callback function as one of its parameters when it is called. You
can use this data for
any purpose. It would normally serve as state variables for keeping track
of what is going on
when a sequence of events is expected. You can assign it NULL if you are
not using it. */
evas_object_event_callback_add(Image, EVAS_CALLBACK_MOUSE_DOWN, OnClick,
NULL);
evas_object_event_callback_add(Image, EVAS_CALLBACK_MOUSE_IN, MouseOn, NULL);
evas_object_event_callback_add(Image, EVAS_CALLBACK_MOUSE_OUT, MouseOff,
NULL);
evas_object_event_callback_add(Caption, EVAS_CALLBACK_MOUSE_DOWN, OnClick,
NULL);
evas_object_event_callback_add(Caption, EVAS_CALLBACK_MOUSE_IN, MouseOn,
NULL);
evas_object_event_callback_add(Caption, EVAS_CALLBACK_MOUSE_OUT, MouseOff,
NULL);
/* Start the main event loop. This does not return until the
ecore_main_loop_quit()
function is invoked by the button click callback routine or the program
gets a
SIGTERM signal, such as by clicking the "X" button on the window border. */
ecore_main_loop_begin();
/* when the main event loop exits, delete the objects and shut down the
libraries. It probably is
not necessary to do this when you are closing the process out but it is
good practice. If you
are opening and closing things while the program continues to run, failing
to delete things no
longer needed will create a memory leak. The structures representing the
objects are allocated
on the heap and need to be freed up when closed. */
evas_object_del(Caption);
evas_object_del(Image);
evas_object_del(Background);
ecore_evas_free(EcoreCanvas);
evas_shutdown();
ecore_evas_shutdown();
ecore_shutdown();
}
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel