From 3280a6ebe447121c8907405a59dab8ad95d5c75f Mon Sep 17 00:00:00 2001 From: Johann Haarhoff Date: Fri, 26 Mar 2010 22:18:34 +0200 Subject: [PATCH] Added a simple "draw" program This program is meant to serve as a frame for quickly testing cairo code. This should be useful for people like me who are not yet too familiar with cairo. This should ultimately not be part of the wmaker tree, but I think it is useful here while we are getting up to speed. --- Makefile.am | 2 +- configure.ac | 3 +- test/cairo/Makefile.am | 22 ++++++++++ test/cairo/draw.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 test/cairo/Makefile.am create mode 100644 test/cairo/draw.c diff --git a/Makefile.am b/Makefile.am index 69a4dc0d..f79adce9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = wrlib WINGs src util po WindowMaker WPrefs.app doc +SUBDIRS = wrlib WINGs src util po WindowMaker WPrefs.app doc test/cairo EXTRA_DIST = TODO BUGS BUGFORM FAQ FAQ.I18N FAQ.I18N.cs FAQ.I18N.sk \ INSTALL-WMAKER INSTALL-WMAKER.cs INSTALL-WMAKER.fr INSTALL-WMAKER.es \ diff --git a/configure.ac b/configure.ac index cf933007..0f7fc52e 100644 --- a/configure.ac +++ b/configure.ac @@ -878,7 +878,8 @@ AC_OUTPUT(Makefile po/Makefile util/Makefile util/po/Makefile \ WindowMaker/Icons/Makefile WindowMaker/Pixmaps/Makefile \ WindowMaker/Styles/Makefile WindowMaker/Themes/Makefile \ WPrefs.app/Makefile WPrefs.app/tiff/Makefile WPrefs.app/xpm/Makefile \ - WPrefs.app/po/Makefile ) + WPrefs.app/po/Makefile \ + test/cairo/Makefile ) diff --git a/test/cairo/Makefile.am b/test/cairo/Makefile.am new file mode 100644 index 00000000..f1022fde --- /dev/null +++ b/test/cairo/Makefile.am @@ -0,0 +1,22 @@ +## automake input file for WINGs - Tests + +AUTOMAKE_OPTIONS = no-dependencies + +noinst_PROGRAMS = draw + +LDADD= @XLIBS@ @XFTLIBS@ @INTLIBS@ @CAIRO_LIBS@ @GLIB_LIBS@ + + +INCLUDES = @XFTFLAGS@ @HEADER_SEARCH_PATH@ \ + -DDEBUG @GLIB_CFLAGS@ @CAIRO_CFLAGS@ + +LIBTOOL = $(QUIET) $(SHELL) $(top_srcdir)/libtool $(LIBTOOL_ARG) + +.c.o: + $(QUIET)$(COMPILE) -c $< + +.c.obj: + $(QUIET)$(COMPILE) -c `$(CYGPATH_W) '$<'` + +.c.lo: + $(QUIET)$(LTCOMPILE) -c -o $@ $< diff --git a/test/cairo/draw.c b/test/cairo/draw.c new file mode 100644 index 00000000..aded6981 --- /dev/null +++ b/test/cairo/draw.c @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include + + +/* This is meant to be a simple app to quickly test some cairo stuff. + * It creates a single window and runs the "draw" function when it + * receives an ExposeEvent. The idea is that you can put some quick + * cairo code you want to try in draw and very quickly see the results + * -- JH + */ + +void draw(Display *dpy, Screen *scr, Visual *vis, Window win) { + cairo_surface_t *surf; + cairo_t *ct; + + surf = (cairo_surface_t *) cairo_xlib_surface_create(dpy, win, vis, 200, 200); + ct = cairo_create(surf); + + cairo_pattern_t *linpat, *radpat; + linpat = cairo_pattern_create_linear (0, 0, 100, 100); + cairo_pattern_add_color_stop_rgb (linpat, 0, 0, 0.3, 0.8); + cairo_pattern_add_color_stop_rgb (linpat, 1, 0, 0.8, 0.3); + + radpat = cairo_pattern_create_radial (100, 100, 50, 100, 100, 75); + cairo_pattern_add_color_stop_rgba (radpat, 0, 0, 0, 0, 1); + cairo_pattern_add_color_stop_rgba (radpat, 0.5, 0, 0, 0, 0); + + cairo_set_source (ct, linpat); + cairo_mask (ct, radpat); + + cairo_stroke (ct); + + cairo_destroy(ct); + cairo_surface_destroy(surf); +} + +int main() { + + Display *dpy; + Window win; + Screen *scr; + int scrnum; + Visual *vis; + Atom delete_win; + Atom prots[6]; + XClassHint classhint; + XSetWindowAttributes win_attr; + char win_title[32]; + char alive; + + dpy = XOpenDisplay(""); + if (!dpy) { + printf("could not open display"); + return 1; + } + + delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False); + prots[0] = delete_win; + + scr = DefaultScreenOfDisplay(dpy); + scrnum = DefaultScreen(dpy); + vis = DefaultVisualOfScreen(scr); + + win_attr.background_pixel = WhitePixel(dpy,scrnum); + win_attr.event_mask = ExposureMask; + + win = XCreateWindow(dpy, + DefaultRootWindow(dpy), + 10, + 10, + 200, + 200, + 0, + CopyFromParent, + InputOutput, + vis, + CWEventMask | CWBackPixel, + &win_attr); + + XSetWMProtocols(dpy,win,prots,1); + + sprintf(win_title,"Cairo Test"); + XStoreName(dpy,win,win_title); + + classhint.res_name = "cairo"; + classhint.res_class = "Cairo"; + XSetClassHint(dpy,win,&classhint); + + XMapWindow(dpy,win); + + XFlush(dpy); + alive = 1; + while (alive) { + XEvent ev; + XNextEvent(dpy, &ev); + if (ev.type == ClientMessage) { + if (ev.xclient.data.l[0] == delete_win) { + XDestroyWindow(dpy, ev.xclient.window); + alive = 0; + } + } + if (ev.type == Expose) { + draw(dpy,scr,vis,win); + } + } + + + return 0; +} -- 2.11.4.GIT