Flatten code a bit more
This commit is contained in:
parent
86c9e8cdc3
commit
ae982bef88
2 changed files with 93 additions and 24 deletions
|
@ -10,6 +10,34 @@
|
|||
#include <hexagram/window.h>
|
||||
#include <hexagram/cluster.h>
|
||||
|
||||
static void handle_xevents(hexagram_window *window,
|
||||
hexagram_cluster *cluster,
|
||||
Display *display,
|
||||
cairo_t *fg) {
|
||||
while (XPending(display)) {
|
||||
XEvent e;
|
||||
|
||||
XNextEvent(display, &e);
|
||||
|
||||
switch (e.type) {
|
||||
case MapNotify:
|
||||
case Expose:
|
||||
hexagram_window_refresh_bg(window);
|
||||
hexagram_cluster_draw_fg(cluster, fg);
|
||||
hexagram_window_swap_buffer(window);
|
||||
|
||||
break;
|
||||
|
||||
case ButtonPress:
|
||||
case KeyPress:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void cluster_update(hexagram_cluster *cluster,
|
||||
cairo_t *cr,
|
||||
hexagram_window *window,
|
||||
|
@ -140,31 +168,9 @@ int main(int argc, char **argv) {
|
|||
FD_SET(fd2, &rfds);
|
||||
|
||||
while (1) {
|
||||
int pending,
|
||||
nfds = fd2 + 1;
|
||||
int nfds = fd2 + 1;
|
||||
|
||||
while ((pending = XPending(display)) != 0) {
|
||||
XEvent e;
|
||||
|
||||
XNextEvent(display, &e);
|
||||
|
||||
switch (e.type) {
|
||||
case MapNotify:
|
||||
case Expose:
|
||||
hexagram_window_refresh_bg(window);
|
||||
hexagram_cluster_draw_fg(cluster, fg);
|
||||
hexagram_window_swap_buffer(window);
|
||||
|
||||
break;
|
||||
|
||||
case ButtonPress:
|
||||
case KeyPress:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
handle_xevents(window, cluster, display, fg);
|
||||
|
||||
memcpy(&rready, &rfds, sizeof(rfds));
|
||||
|
||||
|
|
63
examples/svg.c
Normal file
63
examples/svg.c
Normal file
|
@ -0,0 +1,63 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <cairo-svg.h>
|
||||
|
||||
#include <hexagram/cluster.h>
|
||||
|
||||
static int usage(int argc, char **argv, const char *message, ...) {
|
||||
if (message) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s output.svg\n", argv[0]);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
hexagram_cluster *cluster;
|
||||
|
||||
int width = 1024,
|
||||
height = 480;
|
||||
|
||||
cairo_surface_t *surface;
|
||||
|
||||
cairo_t *bg;
|
||||
|
||||
if (argc != 2) {
|
||||
return usage(argc, argv, "No output SVG file specified");
|
||||
}
|
||||
|
||||
if ((cluster = hexagram_cluster_new(width, height)) == NULL) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
surface = cairo_svg_surface_create(argv[1], width, height);
|
||||
|
||||
/*
|
||||
* Set up the rendering surfaces
|
||||
*/
|
||||
bg = cairo_create(surface);
|
||||
|
||||
/*
|
||||
* Draw the background layer
|
||||
*/
|
||||
hexagram_cluster_draw_bg(cluster, bg);
|
||||
|
||||
cairo_destroy(bg);
|
||||
|
||||
cairo_surface_destroy(surface);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Reference in a new issue