From: <enl...@li...> - 2005-10-02 21:59:03
|
Enlightenment CVS committal Author : moom16 Project : e17 Module : proto Dir : e17/proto/etk/src/lib Modified Files: etk_image.c etk_image.h Log Message: * You can now load images from an edje file with etk_image_new_from_edje and etk_image_set_from_edje =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_image.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- etk_image.c 1 Oct 2005 16:29:45 -0000 1.1 +++ etk_image.c 2 Oct 2005 15:40:28 -0000 1.2 @@ -1,5 +1,7 @@ /** @file etk_image.c */ #include "etk_image.h" +#include <Evas.h> +#include <Edje.h> #include <stdlib.h> #include <string.h> #include "etk_signal.h" @@ -14,7 +16,10 @@ enum _Etk_Image_Property_Id { ETK_IMAGE_FILE_PROPERTY, - ETK_IMAGE_KEEP_ASPECT_PROPERTY + ETK_IMAGE_EDJE_FILE_PROPERTY, + ETK_IMAGE_EDJE_GROUP_PROPERTY, + ETK_IMAGE_KEEP_ASPECT_PROPERTY, + ETK_IMAGE_USE_EDJE_PROPERTY }; static void _etk_image_constructor(Etk_Image *image); @@ -24,6 +29,7 @@ static void _etk_image_realize_cb(Etk_Object *object, void *data); static void _etk_image_move_resize(Etk_Widget *widget, int x, int y, int w, int h); static void _etk_image_size_request(Etk_Widget *widget, Etk_Size *size_requisition); +static void _etk_image_load(Etk_Image *image); /************************** * @@ -43,8 +49,11 @@ { image_type = etk_type_new("Etk_Image", ETK_WIDGET_TYPE, sizeof(Etk_Image), ETK_CONSTRUCTOR(_etk_image_constructor), ETK_DESTRUCTOR(_etk_image_destructor), NULL); - etk_type_property_add(image_type, "file", ETK_IMAGE_FILE_PROPERTY, ETK_PROPERTY_STRING, ETK_PROPERTY_READABLE_WRITABLE, etk_property_value_string(NULL)); - etk_type_property_add(image_type, "keep_aspect", ETK_IMAGE_KEEP_ASPECT_PROPERTY, ETK_PROPERTY_BOOL, ETK_PROPERTY_READABLE_WRITABLE, etk_property_value_bool(TRUE)); + etk_type_property_add(image_type, "image_file", ETK_IMAGE_FILE_PROPERTY, ETK_PROPERTY_STRING, ETK_PROPERTY_READABLE_WRITABLE, etk_property_value_string(NULL)); + etk_type_property_add(image_type, "edje_file", ETK_IMAGE_EDJE_FILE_PROPERTY, ETK_PROPERTY_STRING, ETK_PROPERTY_READABLE_WRITABLE, etk_property_value_string(NULL)); + etk_type_property_add(image_type, "edje_group", ETK_IMAGE_EDJE_GROUP_PROPERTY, ETK_PROPERTY_STRING, ETK_PROPERTY_READABLE_WRITABLE, etk_property_value_string(NULL)); + etk_type_property_add(image_type, "keep_aspect", ETK_IMAGE_KEEP_ASPECT_PROPERTY, ETK_PROPERTY_BOOL, ETK_PROPERTY_READABLE_WRITABLE, etk_property_value_bool(TRUE)); + etk_type_property_add(image_type, "use_edje", ETK_IMAGE_USE_EDJE_PROPERTY, ETK_PROPERTY_BOOL, ETK_PROPERTY_READABLE, etk_property_value_bool(FALSE)); image_type->property_set = _etk_image_property_set; image_type->property_get = _etk_image_property_get; @@ -69,7 +78,18 @@ */ Etk_Widget *etk_image_new_from_file(const char *filename) { - return etk_widget_new(ETK_IMAGE_TYPE, "file", filename, NULL); + return etk_widget_new(ETK_IMAGE_TYPE, "image_file", filename, NULL); +} + +/** + * @brief Creates a new image and loads the image from an edje file + * @param edje_filename the name of the edje file to load + * @param edje_group the name of the edje group to load + * @return Returns the new image widget + */ +Etk_Widget *etk_image_new_from_edje(const char *edje_filename, const char *edje_group) +{ + return etk_widget_new(ETK_IMAGE_TYPE, "edje_file", edje_filename, "edje_group", edje_group, NULL); } /** @@ -91,42 +111,28 @@ else image->filename = NULL; free(old_filename); + etk_object_notify(ETK_OBJECT(image), "image_file"); - if (image->image_object && !image->filename) + if (image->edje_group) { - etk_widget_member_object_del(widget, image->image_object); - evas_object_del(image->image_object); - image->image_object = NULL; + free(image->edje_group); + image->edje_group = NULL; + etk_object_notify(ETK_OBJECT(image), "edje_group"); } - else if (image->filename) + if (image->edje_filename) { - int error_code; - - if (!image->image_object) - { - Evas *evas; + free(image->edje_filename); + image->edje_filename = NULL; + etk_object_notify(ETK_OBJECT(image), "edje_file"); + } - if (!(evas = etk_widget_toplevel_evas_get(widget))) - { - etk_object_notify(ETK_OBJECT(image), "file"); - etk_widget_resize_queue(widget); - return; - } - image->image_object = evas_object_image_add(evas); - etk_widget_member_object_add(widget, image->image_object); - } - evas_object_image_file_set(image->image_object, image->filename, NULL); - if ((error_code = evas_object_image_load_error_get(image->image_object))) - { - ETK_WARNING("Unable to load image from file \"%s\", error %d", filename, error_code); - etk_widget_member_object_del(widget, image->image_object); - evas_object_del(image->image_object); - image->image_object = NULL; - } + if (image->use_edje) + { + image->use_edje = FALSE; + etk_object_notify(ETK_OBJECT(image), "use_edje"); } - etk_widget_resize_queue(widget); - etk_object_notify(ETK_OBJECT(image), "file"); + _etk_image_load(image); } /** @@ -134,7 +140,7 @@ * @param image an image * @return Returns the name of the file use for the image (NULL on failure) */ -const char *etk_image_get_file(Etk_Image *image) +const char *etk_image_file_get(Etk_Image *image) { if (!image) return NULL; @@ -142,6 +148,75 @@ } /** + * @brief Loads the image from an edje file + * @param image an image + * @param edje_filename the name of the edje file to load + * @param edje_group the name of the edje group to load + */ +void etk_image_set_from_edje(Etk_Image *image, const char *edje_filename, const char *edje_group) +{ + Etk_Widget *widget; + char *previous_filename, *previous_group; + + if (!(widget = ETK_WIDGET(image))) + return; + + previous_filename = image->edje_filename; + if (edje_filename) + image->edje_filename = strdup(edje_filename); + else + image->edje_filename = NULL; + free(previous_filename); + etk_object_notify(ETK_OBJECT(image), "edje_file"); + + previous_group = image->edje_group; + if (edje_group) + image->edje_group = strdup(edje_group); + else + image->edje_group = NULL; + free(previous_group); + etk_object_notify(ETK_OBJECT(image), "edje_group"); + + if (image->filename) + { + free(image->filename); + image->filename = NULL; + etk_object_notify(ETK_OBJECT(image), "image_file"); + } + + if (!image->use_edje) + { + image->use_edje = TRUE; + etk_object_notify(ETK_OBJECT(image), "use_edje"); + } + + _etk_image_load(image); +} + +/** + * @brief Gets the filename and the group of the edje object used for the image + * @param image an image + * @param edje_filename the location to store the filename of the edje object + * @param edje_group the location to store the filename of the edje group + */ +void etk_image_edje_file_get(Etk_Image *image, char **edje_filename, char **edje_group) +{ + if (!image) + { + if (edje_filename) + *edje_filename = NULL; + if (edje_group) + *edje_group = NULL; + return; + } + + if (edje_filename) + *edje_filename = image->edje_filename; + if (edje_group) + *edje_group = image->edje_group; +} + +/** * @brief Sets if the image should keep its aspect ratio when it's resized * @param image an image * @param keep_aspect if keep_aspect == TRUE, the image will keep its aspect ratio when it's resized @@ -185,7 +260,10 @@ image->image_object = NULL; image->filename = NULL; + image->edje_filename = NULL; + image->edje_group = NULL; image->keep_aspect = TRUE; + image->use_edje = FALSE; widget->size_request = _etk_image_size_request; widget->move_resize = _etk_image_move_resize; @@ -200,6 +278,8 @@ return; free(image->filename); + free(image->edje_filename); + free(image->edje_group); } /* Sets the property whose id is "property_id" to the value "value" */ @@ -215,6 +295,12 @@ case ETK_IMAGE_FILE_PROPERTY: etk_image_set_from_file(image, etk_property_value_string_get(value)); break; + case ETK_IMAGE_EDJE_FILE_PROPERTY: + etk_image_set_from_edje(image, etk_property_value_string_get(value), image->edje_group); + break; + case ETK_IMAGE_EDJE_GROUP_PROPERTY: + etk_image_set_from_edje(image, image->edje_filename, etk_property_value_string_get(value)); + break; case ETK_IMAGE_KEEP_ASPECT_PROPERTY: etk_image_keep_aspect_set(image, etk_property_value_bool_get(value)); break; @@ -236,9 +322,18 @@ case ETK_IMAGE_FILE_PROPERTY: etk_property_value_string_set(value, image->filename); break; + case ETK_IMAGE_EDJE_FILE_PROPERTY: + etk_property_value_string_set(value, image->edje_filename); + break; + case ETK_IMAGE_EDJE_GROUP_PROPERTY: + etk_property_value_string_set(value, image->edje_group); + break; case ETK_IMAGE_KEEP_ASPECT_PROPERTY: etk_property_value_bool_set(value, image->keep_aspect); break; + case ETK_IMAGE_USE_EDJE_PROPERTY: + etk_property_value_bool_set(value, image->use_edje); + break; default: break; } @@ -252,9 +347,15 @@ if (!(image = ETK_IMAGE(widget)) || !size_requisition) return; - if (image->image_object) - evas_object_image_size_get(image->image_object, &size_requisition->w, &size_requisition->h); + { + if (image->use_edje) + { + /* TODO: */ + } + else + evas_object_image_size_get(image->image_object, &size_requisition->w, &size_requisition->h); + } else { size_requisition->w = 0; @@ -270,7 +371,10 @@ if (!(image = ETK_IMAGE(widget))) return; - if (image->image_object) + if (!image->image_object) + return; + + if (!image->use_edje) { if (image->keep_aspect) { @@ -295,10 +399,10 @@ } } - evas_object_move(image->image_object, x, y); - evas_object_resize(image->image_object, w, h); evas_object_image_fill_set(image->image_object, 0, 0, w, h); } + evas_object_move(image->image_object, x, y); + evas_object_resize(image->image_object, w, h); } /************************** @@ -316,7 +420,69 @@ if (!(image = ETK_IMAGE(object)) || !(evas = etk_widget_toplevel_evas_get(ETK_WIDGET(image)))) return; - etk_image_set_from_file(image, image->filename); + _etk_image_load(image); +} + +/************************** + * + * Private functions + * + **************************/ + +/* Load the image from the image or the edje file */ +static void _etk_image_load(Etk_Image *image) +{ + Etk_Widget *widget; + + if (!(widget = ETK_WIDGET(image))) + return; + + if (image->image_object) + { + etk_widget_member_object_del(widget, image->image_object); + evas_object_del(image->image_object); + image->image_object = NULL; + } + if (image->filename) + { + int error_code; + Evas *evas; + + if ((evas = etk_widget_toplevel_evas_get(widget))) + { + image->image_object = evas_object_image_add(evas); + evas_object_image_file_set(image->image_object, image->filename, NULL); + if ((error_code = evas_object_image_load_error_get(image->image_object))) + { + ETK_WARNING("Unable to load image from file \"%s\", error %d", image->filename, error_code); + evas_object_del(image->image_object); + image->image_object = NULL; + } + else + etk_widget_member_object_add(widget, image->image_object); + } + } + else if (image->edje_filename && image->edje_group) + { + int error_code; + Evas *evas; + + if ((evas = etk_widget_toplevel_evas_get(widget))) + { + image->image_object = edje_object_add(evas); + edje_object_file_set(image->image_object, image->edje_filename, image->edje_group); + if ((error_code = edje_object_load_error_get(image->image_object))) + { + ETK_WARNING("Unable to load image from edje file \"%s\"/\"%s\", error %d", image->edje_filename, image->edje_group, error_code); + evas_object_del(image->image_object); + image->image_object = NULL; + } + else + etk_widget_member_object_add(widget, image->image_object); + } + } + + etk_widget_resize_queue(widget); } /** @} */ =================================================================== RCS file: /cvsroot/enlightenment/e17/proto/etk/src/lib/etk_image.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- etk_image.h 1 Oct 2005 16:29:45 -0000 1.1 +++ etk_image.h 2 Oct 2005 15:40:28 -0000 1.2 @@ -29,15 +29,22 @@ Evas_Object *image_object; char *filename; + char *edje_group; + char *edje_filename; Etk_Bool keep_aspect; + Etk_Bool use_edje; }; Etk_Type *etk_image_type_get(); Etk_Widget *etk_image_new(); Etk_Widget *etk_image_new_from_file(const char *filename); +Etk_Widget *etk_image_new_from_edje(const char *edje_filename, const char *edje_group); void etk_image_set_from_file(Etk_Image *image, const char *filename); -const char *etk_image_get_file(Etk_Image *image); +const char *etk_image_file_get(Etk_Image *image); + +void etk_image_set_from_edje(Etk_Image *image, const char *edje_filename, const char *edje_group); +void etk_image_edje_file_get(Etk_Image *image, char **edje_filename, char **edje_group); void etk_image_keep_aspect_set(Etk_Image *image, Etk_Bool keep_aspect); Etk_Bool etk_image_keep_aspect_get(Etk_Image *image); |