From: <enl...@li...> - 2001-04-08 16:54:39
|
Enlightenment CVS committal Author : monkeyiq Project : misc Module : gevas Dir : misc/gevas/src Modified Files: Makefile.am gevas.c gevas.h gevas_sprite.c gevas_sprite.h gevasimage.c gevasimage.h Added Files: gevas_util.c gevas_util.h Log Message: Updates for sprite animation. Now loads metadata much better. =================================================================== RCS file: /cvsroot/enlightenment/misc/gevas/src/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- Makefile.am 2001/04/07 16:53:08 1.10 +++ Makefile.am 2001/04/08 16:54:38 1.11 @@ -43,7 +43,8 @@ gevasevh_selectable.h \ gevasevh_group_selector.h \ gevas_obj_collection.h \ -gevas_sprite.h +gevas_sprite.h \ +gevas_util.h libgevas_la_SOURCES = \ @@ -64,7 +65,9 @@ gevasevh_selectable.c \ gevasevh_group_selector.c \ gevas_obj_collection.c \ -gevas_sprite.c +gevas_sprite.c \ +gevas_util.c + libgevas_la_LIBADD = $(LIBS_ALL) @GTK_LIBS@ libgevas_la_LDFLAGS = -version-info 1:0:1 =================================================================== RCS file: /cvsroot/enlightenment/misc/gevas/src/gevas.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -3 -r1.22 -r1.23 --- gevas.c 2001/04/05 02:38:32 1.22 +++ gevas.c 2001/04/08 16:54:38 1.23 @@ -1432,3 +1432,106 @@ } } + +static void +add_string_to_list( GtkgEvas * ev, const char* p, GList **li ) +{ + g_return_if_fail(ev != NULL); + g_return_if_fail(p != NULL); + g_return_if_fail(GTK_IS_GEVAS(ev)); + + if(!strlen(p)) + return; + + *li = g_list_append(*li, g_strdup(p)); +} + +static void +remove_string_from_list( GtkgEvas * ev, const char* p, GList **li ) +{ + GList *t = 0; + + g_return_if_fail(ev != NULL); + g_return_if_fail(p != NULL); + g_return_if_fail(GTK_IS_GEVAS(ev)); + + if(!strlen(p)) + return; + + if(t = g_list_find(*li, (gpointer)p)) + { + g_free(t->data); + *li = g_list_remove_link(*li, t); + } +} + + + +void gevas_add_metadata_prefix( GtkgEvas * ev, const char* p ) +{ + g_return_if_fail(ev != NULL); + g_return_if_fail(p != NULL); + g_return_if_fail(GTK_IS_GEVAS(ev)); + + if(!strlen(p)) + return; + + add_string_to_list( ev, p, &ev->metadata_prefix_list ); +} + +void gevas_remove_metadata_prefix ( GtkgEvas * ev, const char* p ) +{ + GList *li = 0; + + g_return_if_fail(ev != NULL); + g_return_if_fail(p != NULL); + g_return_if_fail(GTK_IS_GEVAS(ev)); + + if(!strlen(p)) + return; + + remove_string_from_list( ev, p, &ev->metadata_prefix_list ); + +} + + + + + +void gevas_add_image_prefix( GtkgEvas * ev, const char* p ) +{ + g_return_if_fail(ev != NULL); + g_return_if_fail(p != NULL); + g_return_if_fail(GTK_IS_GEVAS(ev)); + if(!strlen(p)) + return; + add_string_to_list( ev, p, &ev->image_prefix_list ); +} + +void gevas_remove_image_prefix ( GtkgEvas * ev, const char* p ) +{ + g_return_if_fail(ev != NULL); + g_return_if_fail(p != NULL); + g_return_if_fail(GTK_IS_GEVAS(ev)); + if(!strlen(p)) + return; + remove_string_from_list( ev, p, &ev->image_prefix_list ); +} + + + +GList* gevas_get_metadata_prefix_list( GtkgEvas *ev ) +{ + g_return_if_fail(ev != NULL); + g_return_if_fail(GTK_IS_GEVAS(ev)); + return ev->metadata_prefix_list; +} + + +GList* gevas_get_image_prefix_list ( GtkgEvas *ev ) +{ + g_return_if_fail(ev != NULL); + g_return_if_fail(GTK_IS_GEVAS(ev)); + return ev->image_prefix_list; +} + =================================================================== RCS file: /cvsroot/enlightenment/misc/gevas/src/gevas.h,v retrieving revision 1.16 retrieving revision 1.17 diff -u -3 -r1.16 -r1.17 --- gevas.h 2001/04/05 00:55:28 1.16 +++ gevas.h 2001/04/08 16:54:38 1.17 @@ -140,6 +140,12 @@ GtkWidget* scrolledwindow; GtkViewport* scrolledwindow_viewport; + + // Place to find metadata + GList* metadata_prefix_list; + + // Place to find images + GList* image_prefix_list; }; @@ -167,6 +173,12 @@ void gevas_add_fontpath(GtkgEvas * ev, const gchar * path); void gevas_remove_fontpath(GtkgEvas * ev, const gchar * path); + void gevas_add_metadata_prefix( GtkgEvas * ev, const char* p ); + void gevas_remove_metadata_prefix ( GtkgEvas * ev, const char* p ); + + void gevas_add_image_prefix( GtkgEvas * ev, const char* p ); + void gevas_remove_image_prefix ( GtkgEvas * ev, const char* p ); + /** protected **/ @@ -196,6 +208,11 @@ /** protected access only **/ + + GList* gevas_get_metadata_prefix_list( GtkgEvas *ev ); + GList* gevas_get_image_prefix_list ( GtkgEvas *ev ); + + void __gevas_mouse_in(void *_data, Evas _e, Evas_Object _o, int _b, int _x, int _y); void __gevas_mouse_out(void *_data, Evas _e, Evas_Object _o, int _b, int _x, =================================================================== RCS file: /cvsroot/enlightenment/misc/gevas/src/gevas_sprite.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- gevas_sprite.c 2001/04/07 16:40:27 1.3 +++ gevas_sprite.c 2001/04/08 16:54:38 1.4 @@ -31,6 +31,7 @@ #include <gevas_obj_collection.h> #include <gevas_sprite.h> #include <gevasimage.h> +#include <gevas_util.h> #include <gtk/gtkmarshal.h> #include <gtk/gtksignal.h> @@ -210,38 +211,42 @@ } -void gevas_sprite_push_metadata_prefix( GtkgEvasSprite* ev, const char* p ) +static void +setup_attribs( GtkgEvasSprite* ev, GHashTable* hash_args ) { - g_return_if_fail(ev != NULL); - g_return_if_fail(p != NULL); - g_return_if_fail(GTK_IS_GEVAS_SPRITE(ev)); + gint n=0; + gint x=0; + gint y=0; - if(!strlen(p)) - return; + g_return_if_fail(ev != NULL); + g_return_if_fail(GTK_IS_GEVAS_SPRITE(ev)); + g_return_if_fail(GTK_IS_GEVAS_OBJ_COLLECTION(ev->col)); - ev->metadata_prefix_list = g_list_append(ev->metadata_prefix_list, - g_strdup(p)); - + n = url_args_lookup_int(hash_args, "default_frame_delay", 0 ); + if(n) + gevas_sprite_set_default_frame_delay( ev, n ); + + x = url_args_lookup_int(hash_args, "x", 0 ); + y = url_args_lookup_int(hash_args, "y", 0 ); + if( x && y ) + gevas_sprite_move( ev, x, y ); + + x = url_args_lookup_int(hash_args, "rx", 0 ); + y = url_args_lookup_int(hash_args, "ry", 0 ); + if( x && y ) + gevas_sprite_move_relative( ev, x, y ); + + n = url_args_lookup_int(hash_args, "visible", 0 ); + if(n) + gevas_sprite_set_visible( ev, n ); + + n = url_args_lookup_int(hash_args, "play_forever", 0 ); + if(n) + gevas_sprite_play_forever( ev ); } -void gevas_sprite_pop_metadata_prefix ( GtkgEvasSprite* ev, const char* p ) -{ - GList *li = 0; - - g_return_if_fail(ev != NULL); - g_return_if_fail(p != NULL); - g_return_if_fail(GTK_IS_GEVAS_SPRITE(ev)); - if(!strlen(p)) - return; - if(li = g_list_find(ev->metadata_prefix_list, (gpointer)p)) - { - g_free(li->data); - ev->metadata_prefix_list = - g_list_remove_link(ev->metadata_prefix_list, li); - } -} static void load_from_metadata( @@ -256,8 +261,11 @@ char* edb_prefix = 0; char* p = 0; E_DB_File* edb = 0; - gboolean failed=1; - + gboolean loaded=1; + GHashTable* hash_args = 0; + char* strbuf1 = 0; + + g_return_if_fail(ev != NULL); g_return_if_fail(fully_qualified_prefix!= NULL); g_return_if_fail(GTK_IS_GEVAS_SPRITE(ev)); @@ -267,41 +275,33 @@ return; } - - full_buffer = g_strconcat( fully_qualified_prefix, "/", ev->metadata_load_postfix,0 ); - filen = full_buffer; + printf("SPRITE load_from_metadata() fully_qualified_prefix: %s\n", + fully_qualified_prefix); - p="edb://"; - if( !g_strncasecmp(filen, p, strlen(p))) + printf("SPRITE load_from_metadata() ev->metadata_load_postfix:%s\n", + ev->metadata_load_postfix); + + + if( strlen( fully_qualified_prefix )) { - filen+=strlen(p); + full_buffer = g_strconcat( fully_qualified_prefix, + "/", ev->metadata_load_postfix,0 ); } - - for(p=filen; *p; p++ ) + else { - if( *p == '?' ) - { - *p = '\0'; - p++; - for(; *p; p++ ) - { - if( *p == '=' ) - { - edb_prefix = ++p; - break; - } - } - - } - if( *p == '&' ) - { - *p = '\0'; - break; - } - + full_buffer = g_strdup(ev->metadata_load_postfix); } - + + printf("full_buffer:%s\n",full_buffer ); + filen = strbuf1 = url_file_name_part_new( full_buffer ); + hash_args = url_args_to_hash( full_buffer ); + + g_free(full_buffer); + + filen = gevas_trim_prefix("file:",filen); + edb_prefix = url_args_lookup_str(hash_args, "prefix", "" ); + printf("load_from_metadata() filen :%s\n",filen); printf("load_from_metadata() edb_prefix :%s\n",edb_prefix); @@ -310,27 +310,26 @@ if( edb ) { - gint idx = 0; - gint count = 0; - char *t; + gint idx = 0; + gint count = 0; + char* t = 0; + int rc = 0; + gint n = 0; printf("load_from_metadata() loaded edb\n"); - while( strlen(edb_prefix) && edb_prefix[ strlen(edb_prefix)-1 ] == '/' ) - { - edb_prefix[ strlen(edb_prefix)-1 ] = '\0'; - } + t = g_strconcat( edb_prefix, "/Count",0 ); + rc = e_db_int_get(edb, t, &count); + g_free(t); - t = g_strconcat( edb_prefix, "/Count",0 ); - if(1 == e_db_int_get(edb, t, &count)) + if( rc == 1 ) { - g_free(t); printf("load_from_metadata() count:%d\n",count); - for( idx = 0; idx < count ; idx++ ) + for( idx = 0; loaded && idx < count ; idx++ ) { GtkgEvasImage* o = gevasimage_new(); char* image_name = 0; @@ -342,30 +341,35 @@ printf("load_from_metadata() image_name:%s\n",image_name); - - if( !image_name ) + if(!(o = gevasimage_new_from_metadata( ev->gevas, image_name ))) { - break; + loaded=0; } - - p="file://"; - if( !g_strncasecmp(image_name, p, strlen(p))) + else { - char* f = image_name + strlen(p); - - gevasobj_set_gevas(o, ev->gevas); - printf("load_from_metadata() f:%s\n",f); - gevasimage_set_image_name(o, f); gevas_obj_collection_add( ev->col, GTK_GEVASOBJ(o) ); } g_free(image_name); - } - if(!failed || !(idx < count)) + if(loaded && !(idx < count)) { + char* p = edb_prefix; + GHashTable* def_hash_args = g_hash_table_new( g_str_hash, g_str_equal ); + ev->metadata_load_loaded = 1; + + edb_to_hash_int( edb, def_hash_args, "default_frame_delay", p, 0 ); + edb_to_hash_int( edb, def_hash_args, "x", p, 0 ); + edb_to_hash_int( edb, def_hash_args, "y", p, 0 ); + edb_to_hash_int( edb, def_hash_args, "visible", p, 0 ); + edb_to_hash_int( edb, def_hash_args, "play_forever", p, 0 ); + + setup_attribs( ev, def_hash_args ); + setup_attribs( ev, hash_args ); + + hash_str_str_clean( def_hash_args ); } e_db_close(edb); } @@ -373,25 +377,38 @@ } - g_free(full_buffer); + hash_str_str_clean( hash_args ); + g_free(strbuf1); } -gboolean gevas_sprite_load_from_metadata( GtkgEvasSprite* ev, const char* loc ) +gboolean +gevas_sprite_load_from_metadata( GtkgEvasSprite* ev, const char* loc ) { + char* no_prefix = ""; g_return_val_if_fail(ev != NULL,0); g_return_val_if_fail(loc!= NULL,0); g_return_val_if_fail(GTK_IS_GEVAS_SPRITE(ev),0); g_return_val_if_fail(GTK_IS_GEVAS_OBJ_COLLECTION(ev->col),0); + g_return_val_if_fail(GTK_IS_GEVAS(ev->gevas),0); + ev->metadata_load_loaded = 0; ev->metadata_load_postfix = loc; - load_from_metadata((gpointer)loc,ev); - g_list_foreach(ev->metadata_prefix_list, load_from_metadata, ev); + printf("SPRITE gevas_sprite_load_from_metadata() loc:%s\n", loc ); + + if( gevas_get_metadata_prefix_list(ev->gevas)) + { + g_list_foreach( gevas_get_metadata_prefix_list(ev->gevas), + load_from_metadata, ev); + } + load_from_metadata((gpointer)no_prefix,ev); + + return ev->metadata_load_loaded; } gint @@ -646,9 +663,10 @@ g_return_if_fail(GTK_IS_GEVAS_OBJ_COLLECTION(ev->col)); printf("gevas_sprite_play()\n"); - + clock_sprite(ev); restart_timer(ev); + } void gevas_sprite_play_n( GtkgEvasSprite* ev, gint n ) @@ -769,7 +787,6 @@ ev->gevas = 0; ev->col = 0; ev->playing_backwards = 0; - ev->metadata_prefix_list = 0; ev->frame_delay_ms_base = 0; ev->frame_delay_ms = 0; } @@ -786,7 +803,8 @@ ev->gevas = _gevas; ev->col = gevas_obj_collection_new(ev->gevas); gevas_sprite_set_default_frame_delay( ev, 40 ); - + gevas_sprite_move( ev, 0, 0 ); + return GTK_GEVAS_SPRITE(ev); } @@ -851,5 +869,19 @@ break; } +} + + +GtkgEvasSprite* +gevas_sprite_new_from_metadata( GtkgEvas* gevas, const char* loc ) +{ + GtkgEvasSprite* sprite = gevas_sprite_new( gevas ); + if(gevas_sprite_load_from_metadata( + sprite, + loc)) + { + return sprite; + } + return 0; } =================================================================== RCS file: /cvsroot/enlightenment/misc/gevas/src/gevas_sprite.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- gevas_sprite.h 2001/04/07 16:40:27 1.4 +++ gevas_sprite.h 2001/04/08 16:54:38 1.5 @@ -69,7 +69,6 @@ gint current_frame; gboolean playing_backwards; - GList* metadata_prefix_list; // These are both temp data used in gevas_sprite_load_from_metadata // gboolean metadata_load_loaded; @@ -91,6 +90,7 @@ guint gevas_sprite_get_type(void); GtkgEvasSprite* gevas_sprite_new( GtkgEvas* _gevas ); + GtkgEvasSprite* gevas_sprite_new_from_metadata( GtkgEvas* gevas, const char* loc ); @@ -117,8 +117,6 @@ gboolean gevas_sprite_contains( GtkgEvasSprite* ev, GtkgEvasSprite_T o ); gboolean gevas_sprite_contains_all( GtkgEvasSprite* ev, GtkgEvasSprite*s); - void gevas_sprite_push_metadata_prefix( GtkgEvasSprite* ev, const char* p ); - void gevas_sprite_pop_metadata_prefix ( GtkgEvasSprite* ev, const char* p ); gboolean gevas_sprite_load_from_metadata( GtkgEvasSprite* ev, const char* loc ); gint gevas_sprite_get_current_frame( GtkgEvasSprite* ev ); =================================================================== RCS file: /cvsroot/enlightenment/misc/gevas/src/gevasimage.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- gevasimage.c 2001/04/05 02:38:32 1.5 +++ gevasimage.c 2001/04/08 16:54:38 1.6 @@ -35,6 +35,14 @@ */ #include "config.h" + +#include <gevasimage.h> +#include <gevas_util.h> + + +#include <Edb.h> + + /* Always disable NLS, since we have no config.h; * a real app would not do this of course. */ @@ -59,7 +67,6 @@ #endif /* ENABLE_NLS */ -#include "gevasimage.h" enum { ARG_0, /* Skip 0, an invalid argument ID */ @@ -203,12 +210,19 @@ Evas_Object o; gstr = GTK_VALUE_STRING(*arg); + + // Trim off leading double slash + while( *gstr && *(gstr+1) && *gstr=='/' && *(gstr+1)=='/') + gstr++; + + printf("ARG_IMAGENAME: %s\n",gstr); + _gevasobj_ensure_obj_free(object); e = _gevas_evas(object); - o = evas_add_image_from_file(EVAS(ev), gstr); + ev->image_filename = g_strdup(gstr); + o = evas_add_image_from_file(EVAS(ev), ev->image_filename); _gevas_set_obj(object, o); - ev->image_filename = g_strdup(gstr); } break; @@ -238,3 +252,151 @@ break; } } + + +static void +setup_attribs( GtkgEvasImage* ev, GHashTable* hash_args ) +{ + gint n=0; + gint x=0; + gint y=0; + + g_return_if_fail(ev != NULL); + g_return_if_fail(GTK_IS_GEVASIMAGE(ev)); + + x = url_args_lookup_int(hash_args, "x", 0 ); + y = url_args_lookup_int(hash_args, "y", 0 ); + if( x && y ) + gevasobj_move( ev, x, y ); + + x = url_args_lookup_int(hash_args, "rx", 0 ); + y = url_args_lookup_int(hash_args, "ry", 0 ); + if( x && y ) + gevasobj_move_relative( ev, x, y ); + + n = url_args_lookup_int(hash_args, "layer", 0 ); + if(n) + gevasobj_set_layer( ev, n ); + + x = url_args_lookup_int(hash_args, "resize_x", 0 ); + y = url_args_lookup_int(hash_args, "resize_y", 0 ); + if( x && y ) + gevasobj_resize( ev, x, y ); + + n = url_args_lookup_int(hash_args, "fill_size", 0 ); + if(n) + { + int w,h; + gevasimage_get_image_size(GTK_GEVASOBJ(ev), &w, &h); + gevasimage_set_image_fill(GTK_GEVASOBJ(ev), 0,0,w,h); + } + + + + n = url_args_lookup_int(hash_args, "visible", 0 ); + if(n) + gevasobj_set_visible( ev, n ); + +} + + + +static void +load_from_metadata( + gpointer data, + gpointer user_data + ) +{ + const char* fully_qualified_prefix = data; + GtkgEvasImage* ev = user_data; + char* full_buffer; + char* filen; + char* edb_prefix = 0; + char* p = 0; + GHashTable* hash_args = 0; + E_DB_File* edb = 0; + gboolean failed=1; + + g_return_if_fail(ev != NULL); + g_return_if_fail(fully_qualified_prefix!= NULL); + g_return_if_fail(GTK_IS_GEVASIMAGE(ev)); + + if( ev->metadata_load_loaded ) + { + return; + } + + + if( strlen( fully_qualified_prefix )) + { + full_buffer = g_strconcat( fully_qualified_prefix, + "/", ev->metadata_load_postfix,0 ); + } + else + { + full_buffer = g_strdup(ev->metadata_load_postfix); + } + + + + filen = p = url_file_name_part_new( full_buffer ); + hash_args = url_args_to_hash( full_buffer ); + g_free(full_buffer); + filen = gevas_trim_prefix("file:",filen); + + printf("image load_from_metadata() filen1 :%s\n",filen); + + gevasimage_set_image_name(ev, filen); + ev->metadata_load_loaded = 1; + setup_attribs( ev, hash_args ); + + hash_str_str_clean( hash_args ); + g_free(p); + +} + + +gboolean +gevasimage_load_from_metadata( GtkgEvasObj * object, const char* loc ) +{ + GtkgEvasImage *ev; + char* no_prefix = ""; + + g_return_val_if_fail(object != NULL,0); + g_return_val_if_fail(GTK_IS_GEVASIMAGE(object),0); + g_return_val_if_fail(GTK_IS_GEVAS(gevasobj_get_gevas(GTK_OBJECT(object))),0); + + ev = GTK_GEVASIMAGE(object); + + ev->metadata_load_loaded = 0; + ev->metadata_load_postfix = loc; + + load_from_metadata((gpointer)no_prefix,ev); + + if( gevas_get_image_prefix_list(gevasobj_get_gevas(GTK_OBJECT(ev)))) + { + g_list_foreach( gevas_get_image_prefix_list(gevasobj_get_gevas(GTK_OBJECT(ev))), + load_from_metadata, ev); + } + + return ev->metadata_load_loaded; +} + +GtkgEvasImage *gevasimage_new_from_metadata( GtkgEvas* gevas, const char* loc ) +{ + GtkgEvasImage* o = gevasimage_new(); + gboolean b = 1; + + if(!loc || !strlen(loc)) + return 0; + + gevasobj_set_gevas(o, gevas); + b = gevasimage_load_from_metadata(o, loc ); + if(!b) + { + gtk_object_unref( GTK_OBJECT(o) ); + return 0; + } + return o; +} + =================================================================== RCS file: /cvsroot/enlightenment/misc/gevas/src/gevasimage.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- gevasimage.h 2001/03/27 03:43:14 1.3 +++ gevasimage.h 2001/04/08 16:54:38 1.4 @@ -59,6 +59,10 @@ GtkgEvasObj gobj; gchar* image_filename; + + // These are both temp data used in _load_from_metadata + gboolean metadata_load_loaded; + const char * metadata_load_postfix; }; @@ -80,9 +84,11 @@ guint gevasimage_get_type(void); GtkgEvasImage *gevasimage_new(void); + GtkgEvasImage *gevasimage_new_from_metadata( GtkgEvas* gevas, const char* loc ); + gboolean gevasimage_load_from_metadata( GtkgEvasObj * object, const char* loc ); - void gevasimage_set_image_fill(GtkgEvasObj * object, double x, double y, + void gevasimage_set_image_fill(GtkgEvasObj * object, double x, double y, double w, double h); void gevasimage_set_image_border(GtkgEvasObj * object, int l, int r, int t, int b); |