Etk Cairo Widget 4

Posted by Hisham Wed, 04 Jul 2007 23:17:00 GMT

So someone on irc (bmz from #etk) mentioned he wanted to do some drawings using the EFL and would like to be able to draw shapes and curves onto Etk widgets. After a couple of hours of tinkering about, I created the Etk_Cairo widget. This widget allows you to creae a "surface" on which you can use Cairo to draw. A short example would be like this.

static void _etk_cairo_test_redraw_required_cb(Etk_Object *object, void *data)
{
  Etk_Widget *cairo;
  cairo_t *cr;
  int w, h;
    
  if (!(cairo = ETK_WIDGET(object)))
    return;
    
  etk_widget_geometry_get(cairo, NULL, NULL, &w, &h);
  cr = etk_cairo_get(ETK_CAIRO(cairo));
  _etk_cairo_test_draw(cr, 0, 0, w, h);
}
      
int main(int argc, char **argv)
{
  Etk_Widget *window;
  Etk_Widget *cairo;
  Etk_Widget *frame;
      
  etk_init(&argc, &argv);
      
  window = etk_window_new();
  etk_window_title_set(ETK_WINDOW(window), "Etk-Cairo Test");
      
  cairo = etk_cairo_new(WIDTH, HEIGHT);
  etk_signal_connect("redraw-required", ETK_OBJECT(cairo),
    ETK_CALLBACK(_etk_cairo_test_redraw_required_cb), NULL);

  frame = etk_frame_new("Cairo Drawing");
  etk_container_add(ETK_CONTAINER(frame), cairo);
  
  etk_container_add(ETK_CONTAINER(window), frame);
  etk_window_resize(ETK_WINDOW(window), WIDTH, HEIGHT);
  etk_widget_show_all(window);

  etk_main();
  etk_shutdown();

  return 0;
}

In this example, the _etk_cairo_test_draw function does all the cairo stuff and can result in something like this or this.
Trackbacks

Use the following link to trackback from your own site:
http://hisham.cc/trackbacks?article_id=etk-cairo-widget&day=04&month=07&year=2007

Comments

Leave a response

  1. Avatar
    swishy 11 minutes later:
    Awesome work Hisham :)
  2. Avatar
    bmz about 8 hours later:
    Agreed, awesome work :)
  3. Avatar
    hisham about 9 hours later:
    Thanks guys! bmz: This and a coulple of other widgets will soon be in cvs.
  4. Avatar
    Veli Ogla Sungutay 2 days later:
    This is what I'm talking about! Now, let's create a Flash Player 9 canvas :)
Comments