Code cleanup: move expose redraw to draw.c
authorH.G. Muller <h.g.muller@hccnet.nl>
Sat, 13 Oct 2012 05:50:56 +0000 (07:50 +0200)
committerH.G. Muller <h.g.muller@hccnet.nl>
Sun, 21 Oct 2012 09:28:25 +0000 (11:28 +0200)
dialogs.h
draw.c
draw.h
xoptions.c

index bf4b45c..22e368c 100644 (file)
--- a/dialogs.h
+++ b/dialogs.h
@@ -166,6 +166,7 @@ void Browse P((DialogClass dlg, char *label, char *proposed, char *ext,
 
 void InitDrawingParams P((int reload)); // in draw.c
 void InitDrawingHandle P((Option *opt));
+void ExposeRedraw P((Option *opt, int x, int y, int w, int h));
 void DrawLogo P((Option *opt, void *logo));
 void ErrorPopUp P((char *title, char *text, int modal));
 int  ShiftKeys P((void));
diff --git a/draw.c b/draw.c
index 7307e66..ea6e4be 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -200,6 +200,17 @@ InitDrawingSizes (BoardSize boardSize, int flags)
   oldMono = appData.monoMode;
 }
 
+void
+ExposeRedraw (Option *graph, int x, int y, int w, int h)
+{   // copy a selected part of the buffer bitmap to the display
+    cairo_t *cr = cairo_create((cairo_surface_t *) graph->textValue);
+    cairo_set_source_surface(cr, (cairo_surface_t *) graph->choice, 0, 0);
+    cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
+    cairo_rectangle(cr, x, y, w, h);
+    cairo_fill(cr);
+    cairo_destroy(cr);
+}
+
 static void
 CreatePNGBoard (char *s, int kind)
 {
diff --git a/draw.h b/draw.h
index 3ba9efe..fee4ccb 100644 (file)
--- a/draw.h
+++ b/draw.h
@@ -69,7 +69,6 @@ extern Pixel lightSquareColor, darkSquareColor, whitePieceColor, blackPieceColor
 
 // defined in draw.c
 void CreateGCs P((int redo));
-void NewSurfaces P((void));
 void CreateAnyPieces P((void));
 void CreatePNGPieces P((void));
 void CreateGrid P((void));
index 979399a..e9cc0c4 100644 (file)
@@ -541,7 +541,6 @@ GraphEventProc(Widget widget, caddr_t client_data, XEvent *event)
     int j, button=10, f=1, sizing=0;
     Option *opt, *graph = (Option *) client_data;
     PointerCallback *userHandler = graph->target;
-    cairo_t *cr;
 
     if (!XtIsRealized(widget)) return;
 
@@ -567,12 +566,8 @@ GraphEventProc(Widget widget, caddr_t client_data, XEvent *event)
                graph->choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
                break;
            }
-           cr = cairo_create((cairo_surface_t *) graph->textValue);
-           cairo_set_source_surface(cr, (cairo_surface_t *) graph->choice, 0, 0);
-           cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
-           cairo_rectangle(cr, ((XExposeEvent*)event)->x, ((XExposeEvent*)event)->y, ((XExposeEvent*)event)->width, ((XExposeEvent*)event)->height);
-           cairo_fill(cr);
-           cairo_destroy(cr);
+           ExposeRedraw(graph, ((XExposeEvent*)event)->x, ((XExposeEvent*)event)->y,
+                               ((XExposeEvent*)event)->width, ((XExposeEvent*)event)->height);
            return;
        case MotionNotify:
            f = 0;