语言

Menu
Sites
Language
Black screen using Cairo

So, I'm trying to follow default Cairo tutorial: https://developer.tizen.org/development/tutorials/native-application/graphics/cairo?langredirect=1, but I have black screen only.

This is my code:

void
cairo_drawing(appdata_s *data)
{
   appdata_s *ad = data;
   int d = 360;
   cairo_set_source_rgba(ad->cairo, 1, 1, 1, 1);
   cairo_paint(ad->cairo);

   cairo_translate(ad->cairo, 0.1 * d, 0.1 * d);
   cairo_set_line_width(ad->cairo, 2);
   cairo_set_source_rgba(ad->cairo, 0.0, 0.0, 1.0, 1.0);

   cairo_move_to(ad->cairo, 0.2 * d , 0.2 * d);
   cairo_line_to(ad->cairo, 0.4 * d, 0.3 * d);
   cairo_rel_line_to(ad->cairo, 0.2 * d, -0.1 * d);
   cairo_arc(ad->cairo, 0.4 * d, 0.4 * d, 0.2* d * sqrt(2), -0.25 * M_PI, 0.25 * M_PI);
   cairo_rel_curve_to(ad->cairo, -0.2* d, -0.1 * d, -0.2* d, 0.1 * d, -0.4 * d, 0);
   cairo_close_path(ad->cairo);
   cairo_fill(ad->cairo);

   cairo_rectangle(ad->cairo, 0, 0, 0.8 * d, 0.8 * d);
   cairo_stroke(ad->cairo);

   cairo_surface_flush(ad->surface);

   unsigned char * imageData = cairo_image_surface_get_data(cairo_get_target(ad->cairo));
   evas_object_image_data_set(ad->img, imageData);
   evas_object_image_data_update_add(ad->img, 0, 0, 360, 360);
}

static void create_gui(appdata_s *ad)
{
  
   ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
  
  if (elm_win_wm_rotation_supported_get(ad->win)) {
      int rots[4] = { 0, 90, 180, 270 };
      elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
   }
 
   evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);

  
   evas_object_show(ad->win);
   ad->img = evas_object_image_filled_add(evas_object_evas_get(ad->win));
   evas_object_show(ad->img);

   evas_object_geometry_get(ad->win, NULL, NULL, ad->width, ad->height);
   ad->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 360, 360);
   ad->cairo = cairo_create(ad->surface);
   dlog_print(DLOG_ERROR, LOG_TAG, cairo_status_to_string(cairo_status(ad->cairo)));

}

static bool
app_create(void *data)
{

	appdata_s *ad = (appdata_s *)data;

	create_gui(ad);
	cairo_drawing(ad);

	return true;
}

So, please, can anyone help me?

响应

2 回复
daniel kim
void cairo_drawing(void *data)
{
    appdata_s *ad = data;

 int d = 360;

 /* clear background as white */
 cairo_set_source_rgba(ad->cairo, 1, 1, 1, 1);
 cairo_paint(ad->cairo);

 cairo_translate(ad->cairo, 0.1 * d, 0.1 * d);
 cairo_set_line_width(ad->cairo,2);
 cairo_set_source_rgba(ad->cairo, 0.0, 0.0, 1.0, 1.0);

 cairo_move_to (ad->cairo, 0.2 * d , 0.2 * d);
 cairo_line_to (ad->cairo, 0.4 * d, 0.3 * d);
 cairo_rel_line_to (ad->cairo, 0.2 * d, -0.1 * d);
 cairo_arc (ad->cairo, 0.4 * d, 0.4 * d, 0.2* d * sqrt(2), -0.25 * M_PI, 0.25 * M_PI);
 cairo_rel_curve_to (ad->cairo, -0.2* d, -0.1 * d, -0.2* d, 0.1 * d, -0.4 * d, 0);
 cairo_close_path (ad->cairo);
 cairo_fill(ad->cairo);

 cairo_rectangle(ad->cairo, 0, 0, 0.8 * d, 0.8 * d);
 cairo_stroke(ad->cairo);
 cairo_surface_flush(ad->surface);

 /* display cairo drawin on screen */
 unsigned char * imageData = cairo_image_surface_get_data(cairo_get_target(ad->cairo));
 evas_object_image_data_set(ad->img, imageData);
 evas_object_image_data_update_add(ad->img, 0, 0, 360,360);
}

static void
cairo_basic_drawing(appdata_s *ad)
{

    ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE);
 elm_win_autodel_set(ad->win, EINA_TRUE);
 if (elm_win_wm_rotation_supported_get(ad->win))
 {
  int rots[4] = { 0, 90, 180, 270 };
  elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
 }
 evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL);
 eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad);
 evas_object_event_callback_add(ad->win, EVAS_CALLBACK_RESIZE, win_resize_cb, ad);
 evas_object_show(ad->win);


 ad->img = evas_object_image_filled_add(evas_object_evas_get(ad->win));
 evas_object_show(ad->img);

 evas_object_geometry_get(ad->win, NULL, NULL, &ad->width, &ad->height);
 ad->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 360,360);
 ad->cairo = cairo_create (ad->surface);
 cairo_drawing(ad);
}

static bool
app_create(void *data)
{
    appdata_s *ad = data;
 cairo_basic_drawing(ad);
 return true;
}

Hi,

I would suggest to check this code.

Regards

Alex Dem

Hi,
Fyi, there is Cairo Basic  example for 2.4 also (Tizen Sdk->File->New->Tizen Native Project-> Online Sample) .
Alexey.