Edje smart object是如何定义的?

 

Edje_private.h:

typedef struct _Edje_Smart_Api Edje_Smart_Api;

 

struct _Edje_Smart_Api

{

   Evas_Smart_Class base;

   int version;

   Eina_Bool (*file_set)(Evas_Object *obj, const char *file, const char *group);

};

 

/* Basic macro to init the Edje Smart API */

#define EDJE_SMART_API_INIT(smart_class_init) {smart_class_init, EDJE_SMART_API_VERSION, NULL}

 

#define EDJE_SMART_API_INIT_NULL EDJE_SMART_API_INIT(EVAS_SMART_CLASS_INIT_NULL)

#define EDJE_SMART_API_INIT_VERSION EDJE_SMART_API_INIT(EVAS_SMART_CLASS_INIT_VERSION)

#define EDJE_SMART_API_INIT_NAME_VERSION(name) EDJE_SMART_API_INIT(EVAS_SMART_CLASS_INIT_NAME_VERSION(name))

 

edje_smart.c中开始进行定义,这里的API是私有的,公共的,将来为所有的edje object服务:

static Edje_Smart_Api _edje_smart_class = EDJE_SMART_API_INIT_NAME_VERSION("edje");

//很简单的一句话,定义这样一个结构变量

 

展开它:

Static Edje_Smart_Api _edje_smart_class =

{

{

edje, // evas smart class name

EVAS_SMART_CLASS_VERSION, //1

NULL, // add 函数初始化

NULL, // del

NULL, // move

NULL, // resize

NULL, // show

NULL, // hide

NULL, // color_set

NULL, // clip_set

NULL, // clip_unset

NULL, // calculate

NULL, // member_add

NULL, // member_del

NULL, // parent

NULL, // callbacks

NULL, // interfaces

NULL, // data

},

 

EDJE_SMART_API_VERSION, //

NULL // file_set

};

 

 

然后定义一个smart:

static Evas_Smart *_edje_smart = NULL;

这个smart 会用到上面定义的一系列的私有APIs

 

 

然后定义一个链表:这个链表很重要,在程序中定义的object, 以及EDC中自定义的所有object, 都会挂到这个链表上面。

Eina_List *_edje_edjes = NULL;

 

 

当在一个进程中,第一次调用下面这个函数时,会把前面的全局API给填充一下:

EAPI Evas_Object *

edje_object_add(Evas *evas)

{

   if (!_edje_smart)

     {

         _edje_object_smart_set(&_edje_smart_class); //edje自己的一组API给填充进去 (参考A

         _edje_smart = evas_smart_class_new((Evas_Smart_Class *)&_edje_smart_class); //分配一块内存给_edje_smart, 同时把上面的一组API绑定给这个_edje_smart

     }

   return evas_object_smart_add(evas, _edje_smart); //evas舞台上面,创建一个新的evas smart object, 同时给这个smart object赋予一定的edje自己提供的,定制的API

}

 

A: 填充好后的全局_edje_smart_class这组函数是:

_edje_smart_class =

{

{

edje, // evas smart class name

EVAS_SMART_CLASS_VERSION, //1

_edje_smart_add, // add 函数初始化

_edje_smart_del, // del

_edje_smart_move, // move

_edje_smart_resize, // resize

_edje_smart_show, // show

_edje_smart_hide, // hide

_edje_smart_color_set, // color_set

_edje_smart_clip_set, // clip_set

_edje_smart_clip_unset, // clip_unset

_edje_smart_calculate, // calculate

NULL, // member_add

NULL, // member_del

NULL, // parent

NULL, // callbacks

NULL, // interfaces

NULL, // data

},

 

EDJE_SMART_API_VERSION, //

_edje_smart_file_set// file_set

};

 

 

EAPI Evas_Object *

evas_object_smart_add(Evas *e, Evas_Smart *s)

{

   Evas_Object *obj;

 

   MAGIC_CHECK(e, Evas, MAGIC_EVAS);

   return NULL;

   MAGIC_CHECK_END();

   MAGIC_CHECK(s, Evas_Smart, MAGIC_SMART);

   return NULL;

   MAGIC_CHECK_END();

 

   obj = evas_object_new(e); //evas上面创建一个object,

   if (!obj) return NULL;

   obj->smart.smart = s;  //这个object就有灵性了: 绑定用户定制的API集,这里是edjeAPI集合

   obj->type = s->smart_class->name;  //edje

   evas_object_smart_init(obj); //初始化一些数据,同时给这个object再绑定一些evas_object所提供的基础API集合:参考B

   evas_object_inject(obj, e); // 把这个smart object放到Evaslayer上面

 

   evas_object_smart_use(s);

 

   if (s->smart_class->add) s->smart_class->add(obj); //调用edje提供的API集合中的add函数:_edje_smart_add 参考C:

 

   return obj;

}

 

 

B:

static const Evas_Object_Func object_func =

{

   /* methods (compulsory) */

   evas_object_smart_free,

     evas_object_smart_render,

     evas_object_smart_render_pre,

     evas_object_smart_render_post,

     evas_object_smart_id_get,

     evas_object_smart_visual_id_get,

     evas_object_smart_engine_data_get,

     /* these are optional. NULL = nothing */

     NULL,

     NULL,

     NULL,

     NULL,

     NULL,

     NULL,

     NULL,

     NULL,

     NULL,

     NULL,

     NULL,

     NULL,

     NULL

};

 

C:

static void

_edje_smart_add(Evas_Object *obj)

{

   Edje *ed;

 

   ed = evas_object_smart_data_get(obj);

   if (!ed)

     {

         const Evas_Smart *smart;

         const Evas_Smart_Class *sc;

 

         ed = calloc(1, sizeof(Edje));

         if (!ed) return;

 

         smart = evas_object_smart_smart_get(obj);

         sc = evas_smart_class_get(smart);

         ed->api = (const Edje_Smart_Api *)sc;

 

         evas_object_smart_data_set(obj, ed);

     }

 

   ed->evas = evas_object_evas_get(obj);

   ed->clipper = evas_object_rectangle_add(ed->evas);

   evas_object_static_clip_set(ed->clipper, 1);

   evas_object_smart_member_add(ed->clipper, obj);

   evas_object_color_set(ed->clipper, 255, 255, 255, 255);

   evas_object_move(ed->clipper, -10000, -10000);

   evas_object_resize(ed->clipper, 20000, 20000);

   evas_object_pass_events_set(ed->clipper, 1);

   ed->have_objects = 1;

   ed->references = 1;

 

   evas_object_geometry_get(obj, &(ed->x), &(ed->y), &(ed->w), &(ed->h));

   ed->obj = obj;

   _edje_edjes = eina_list_append(_edje_edjes, obj); //evas smart object: edje放到一个全局链表中保持;

/*

     {

         Eina_List *l;

         const void *data;

 

         printf("--- EDJE DUMP [%i]/n", eina_list_count(_edje_edjes));

         EINA_LIST_FOREACH(_edge_edges, l, data)

           {

              ed = _edje_fetch(data);

              printf("EDJE: %80s | %80s/n", ed->path, ed->part);

           }

         printf("--- EDJE DUMP [%i]/n", eina_list_count(_edje_edjes));

     }

 */

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值