GDK/Cairo question
- From: Fabian Greffrath <fabian greffrath com>
- To: gtk-app-devel-list gnome org
- Subject: GDK/Cairo question
- Date: Wed, 18 May 2011 11:22:07 -0700
Dear GTK+-gurus,
I am currently in the process of teaching myself a bit of GDK/Cairo by
porting a small application from using Pixmaps and Bitmaps to Cairo.
Please find a short sample source attached below.
The source compiles fine and the application runs, but instead of
displaying the PNG file, it only shows a black square with no apparent
content.
Please help me, what am I missing or doing wrong?
Best regards,
Fabian
--
/*
gcc -o cairo_test cairo_test.c `pkg-config gdk-3.0 --cflags`
`pkg-config gdk-3.0 --libs`
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <gdk/gdk.h>
int main(int argc, char **argv)
{
GdkEvent *event;
GdkWindow *win;
GdkWindowAttr attr;
if (!gdk_init_check(&argc, &argv))
{
fprintf(stderr, "GDK init failed!\n");
exit(-1);
}
cairo_surface_t *cs = cairo_image_surface_create_from_png
("/usr/share/empathy/icons/hicolor/48x48/apps/im-ekiga.png");
/* just an example, use whatever PNG you want */
attr.width = cairo_image_surface_get_width(cs);
attr.height = cairo_image_surface_get_height(cs);
attr.title = "cairo test";
attr.event_mask = GDK_BUTTON_PRESS_MASK;
attr.wclass = GDK_INPUT_OUTPUT;
attr.window_type = GDK_WINDOW_TOPLEVEL;
win = gdk_window_new(NULL, &attr, GDK_WA_TITLE);
if (!win)
{
fprintf(stderr, "Cannot make toplevel window!\n");
exit (-1);
}
cairo_t *gc = gdk_cairo_create(win);
cairo_set_source_surface(gc, cs, 0, 0);
cairo_paint(gc);
cairo_destroy(gc);
gdk_window_show(win);
while (1)
{
event = gdk_event_get();
if (event)
{
switch (event->type)
{
case GDK_DESTROY:
exit(0);
break;
case GDK_BUTTON_PRESS:
exit(0);
break;
default:
break;
}
}
usleep(100);
}
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]