GooCanvas 라이브러리를 이용하여 배경 이미지 그리기

가장 처음으로 png 파일로 부터 배경이미지를 표시하는 작업을 진행합니다.

테스트 코드 컴파일을 위해서는 라이브러리 설치가 필요합니다. 이 문서에서는 Ubuntu 배포판을 기준으로 설명하도록 하겠습니다.

  • libgoocanvas-common
  • libgoocanvas-dev
  • libgoocanvas3

위 패키지를 설치하고  간단히 라이브러리 path를 이용하여 컴파일 하면 됩니다.

“pkg-config –cflags –libs goocanvas” 이용하면 의존하는 헤더파일과 라이브러리링크 위치를 얻을 수 있습니다.

-I/usr/include/goocanvas-1.0 -I/usr/include/gtk-2.0 -I/usr/include/cairo
-I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/pango-1.0
-I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/pixman-1
-I/usr/include/freetype2 -I/usr/include/libpng12  -lgoocanvas -lgtk-x11-2.0
-lgdk-x11-2.0 -latk-1.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0
-lgio-2.0 -lcairo -lpango-1.0 -lfreetype -lz -lfontconfig -lgobject-2.0
-lgmodule-2.0 -lglib-2.0

아래 테스트 코드는 png 파일을 이용하여 배경을 그리고 위에 간단한 텍스트를 표시하는 기능을 수행합니다.

#include <goocanvas.h>
#include <gtk/gtk.h>
#include <stdio.h>
 
int main (int argc, char *argv[])
{
  GtkWidget *window, *canvas;
  GooCanvasItem *root, *image_item, *text_item;
  GdkPixbuf *pixbuf;
  GError *err;
 
  /* Initialize GTK+. */
  gtk_set_locale ();
  gtk_init (&argc, &argv);
 
  /* Create the window and widgets. */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
  gtk_widget_show (window);
 
  canvas = goo_canvas_new ();
  gtk_widget_set_size_request (canvas, 640, 480);
  goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000);
  gtk_widget_show (canvas);
  gtk_container_add (GTK_CONTAINER (window), canvas);
 
  root = goo_canvas_get_root_item (GOO_CANVAS (canvas));
 
  /* Add a few simple items. */
  err = NULL;
  pixbuf = gdk_pixbuf_new_from_file ("bg.png", &err);
  if (!pixbuf || err)
    {
      fprintf (stderr, "%s\n", err->message);
      g_error_free (err);
      return -1;
    }
  image_item = goo_canvas_image_new (root, pixbuf, 0, 0, NULL);
 
  text_item = goo_canvas_text_new (root, "Hello World", 300, 300, -1,
    GTK_ANCHOR_CENTER,
    "font", "Sans 24",
    NULL);
 
  /* Pass control to the GTK+ main event loop. */
  gtk_main ();
 
  return 0;
}
배경 이미지 표시 화면

배경 이미지 표시 화면

Creative Commons License
This work, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.0 Korea License.
This entry was posted in Development and tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Notify me of followup comments via e-mail. You can also subscribe without commenting.