Removed generate.
[universe.git] / simple_window.cc
index ae981ed..cbb3506 100644 (file)
@@ -77,6 +77,13 @@ SimpleWindow::SimpleWindow(const char *name, int x, int y, int w, int h) {
     XSetState(_display, _gc, 0, 0, GXcopy, AllPlanes);
     XFillRectangle(_display, _pixmap, _gc, 0, 0, _width, _height);
     XFlush(_display);
+
+#ifdef CAIRO_SUPPORT
+    _cairo_surface = cairo_xlib_surface_create(_display, _pixmap, _visual, _width, _height);
+    cairo_xlib_surface_set_size(_cairo_surface, _width, _height);
+    _cairo_context = cairo_create(_cairo_surface);
+#endif
+
   } else abort();
 }
 
@@ -85,6 +92,10 @@ SimpleWindow::~SimpleWindow() {
   XUnmapWindow(_display, _window);
   XDestroyWindow(_display, _window);
   XCloseDisplay(_display);
+#ifdef CAIRO_SUPPORT
+  cairo_destroy(_cairo_context);
+  cairo_surface_destroy(_cairo_surface);
+#endif
 }
 
 int SimpleWindow::width() {
@@ -214,12 +225,6 @@ SimpleEvent SimpleWindow::event() {
 
 #ifdef CAIRO_SUPPORT
 cairo_t *SimpleWindow::get_cairo_context_resource() {
-  cairo_surface_t *surface;
-
-  surface = cairo_xlib_surface_create(_display, _pixmap, _visual, _width, _height);
-
-  cairo_xlib_surface_set_size(surface, _width, _height);
-
-  return cairo_create(surface);
+  return _cairo_context;
 }
 #endif