语言

Menu
Sites
Language
How to show cairo drawing in naviframe

I have been trying to create a view for showing graph using cairo. This view is supposed to get created when a button is clicked. So I added the following code

in a function and called it from the button's callback function.

Eina_Bool view_history_create(void *data)
{
    Evas_Object *nf = (Evas_Object *)data;
    // nf is pointer to parent naviframe container

    appdata_s *ad = {0,};

    dlog_print(DLOG_ERROR, LOG_TAG, "Creating evas_object_image.");
    ad->img = evas_object_image_filled_add(evas_object_evas_get(nf));

    dlog_print(DLOG_ERROR, LOG_TAG, "Showing image.");
    evas_object_show(ad->img);

    dlog_print(DLOG_ERROR, LOG_TAG, "Calling evas_object_geometry_get...");
    evas_object_geometry_get(nf, NULL, NULL, &ad->width, &ad->height);

    dlog_print(DLOG_ERROR, LOG_TAG, "Calling cairo_image_surface_create...");
    ad->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ad->width, ad->height);

    dlog_print(DLOG_ERROR, LOG_TAG, "Calling cairo_create...");
    ad->cairo = cairo_create(ad->surface);

    dlog_print(DLOG_ERROR, LOG_TAG, "Calling cairo_drawing...");
    cairo_drawing(ad);

    dlog_print(DLOG_ERROR, LOG_TAG, "Calling elm_naviframe_item_push...");
    elm_naviframe_item_push(nf, "History", NULL, NULL, ad->img, NULL);

    dlog_print(DLOG_ERROR, LOG_TAG, "Returning...");
    return EINA_TRUE;
}

With the log, I found that the app crashes after calling the function evas_object_image_filled_add. So, I want to know what am I doing wrong here? What can I do to fix this?

编辑者为: Asiful Nobel 27 7月, 2016
查看选择的答案

响应

4 回复
Mark as answer
Eugene Kurzberg

Hello, I'm not sure what is wrong with your function, however you should see this sample applicaiton for an example of using cairo with EFL.

Asiful Nobel

Thanks, I followed your advice and was able to work out what I needed to do. It seems that evas_object_image_filled_add does not work as I thought it did. I had to instead use evas_object_image_add function and manually set image size and fill size using evas_object_image_size_set, evas_object_image_fill_set functions.

Finally, I was able to work out the solution from your answer. So, I am selecting it as answer.

Mehedi Alamgir

Hi Asiful

The following line of your code is the reason of program crash

appdata_s *ad = {0,};

You wrote "ad->img", but currently above "ad" pointer points to an empty value. So instead of an empty pointer assign a valid 
value in "ad" pointer which is your function parameter. So change the above line to

appdata_s *ad = data;

Now your code will execute after evas_object_image_filled_add function.

 

Hope it will help you.

If you find my post is helpful for you, please mark it as Best Answer  so that other may find it easier in the future.

Asiful Nobel

Thank you for your helpful reply. From your reply, I was able to understand that I was actually initializing a pointer to appdata_s struct, which was not actually pointing to anything. So, I fixed it like this.

Eina_Bool view_history_create(void *data)
{
        Evas_Object *nf = (Evas_Object *)data;
	appdata_s ad;

	dlog_print(DLOG_ERROR, LOG_TAG, "Creating evas_object_image.");
	ad.img = evas_object_image_filled_add(evas_object_evas_get(nf));

	dlog_print(DLOG_ERROR, LOG_TAG, "Showing image.");
	evas_object_show(ad.img);

	dlog_print(DLOG_ERROR, LOG_TAG, "Calling evas_object_geometry_get...");
	evas_object_geometry_get(nf, NULL, NULL, &ad.width, &ad.height);

	dlog_print(DLOG_ERROR, LOG_TAG, "Calling cairo_image_surface_create...");
	ad.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, ad.width, ad.height);

	dlog_print(DLOG_ERROR, LOG_TAG, "Calling cairo_create...");
	ad.cairo = cairo_create(ad.surface);

	dlog_print(DLOG_ERROR, LOG_TAG, "Calling cairo_drawing...");
	cairo_drawing(&ad);

	dlog_print(DLOG_ERROR, LOG_TAG, "Calling elm_naviframe_item_push...");
	elm_naviframe_item_push(nf, "History", NULL, NULL, ad.img, NULL);

	dlog_print(DLOG_ERROR, LOG_TAG, "Returning...");
	return EINA_TRUE;
}

Now there is a new problem. The app does not crash anymore, but I am not getting desired output. I am getting a new view with title set as History, but there is no cairo drawing. It is just a transparent view with title over the view which contains the clicked button. Why is this happening? How may I solve it?