[dasher] g/c Gdk2 based drawing code (aka the without-cairo option)



commit 445e8056dde226454b0864ca5b4f77d327c97f2c
Author: Patrick Welche <prlw1 cam ac uk>
Date:   Wed Jun 2 13:40:57 2021 +0100

    g/c Gdk2 based drawing code (aka the without-cairo option)

 Src/Gtk2/Canvas.cpp | 182 ----------------------------------------------------
 Src/Gtk2/Canvas.h   |  57 ++--------------
 configure.ac        |  13 +---
 3 files changed, 5 insertions(+), 247 deletions(-)
---
diff --git a/Src/Gtk2/Canvas.cpp b/Src/Gtk2/Canvas.cpp
index 322d77ca9..4e5dee393 100644
--- a/Src/Gtk2/Canvas.cpp
+++ b/Src/Gtk2/Canvas.cpp
@@ -10,13 +10,7 @@ using namespace Dasher;
 
 CCanvas::CCanvas(GtkWidget *pCanvas)
   : CLabelListScreen(0,0) {
-
-#if WITH_CAIRO
   cairo_colours = 0;
-#else
-  colours = 0;
-#endif
-  
   m_pCanvas = pCanvas;
 
   gtk_widget_add_events(m_pCanvas, GDK_ALL_EVENTS_MASK);
@@ -30,28 +24,10 @@ void CCanvas::InitSurfaces() {
   // Construct the buffer pixmaps
   // FIXME - only allocate without cairo
 
-#if WITH_CAIRO
-
   m_pDisplaySurface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, GetWidth(), GetHeight());
   m_pDecorationSurface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, GetWidth(), GetHeight());
   //m_pOnscreenSurface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, GetWidth(), GetHeight());
 
-#else
-
-  //m_pDummyBuffer = gdk_pixmap_new(m_pCanvas->window, GetWidth(), GetHeight(), -1);
-
-  m_pDisplayBuffer = gdk_pixmap_new(m_pCanvas->window, GetWidth(), GetHeight(), -1);
-  m_pDecorationBuffer = gdk_pixmap_new(m_pCanvas->window, GetWidth(), GetHeight(), -1);
-  //m_pOnscreenBuffer = gdk_pixmap_new(m_pCanvas->window, GetWidth(), GetHeight(), -1);
-
-  // Set the display buffer to be current
-
-  m_pOffscreenBuffer = m_pDisplayBuffer;
-
-#endif
-
-
-#if WITH_CAIRO
   // The lines between origin and pointer is draw here
   decoration_cr = cairo_create(m_pDecorationSurface);
   cr = decoration_cr;
@@ -65,14 +41,11 @@ void CCanvas::InitSurfaces() {
   cairo_set_line_width(cr, 1.0);
 
   //onscreen_cr = cairo_create(m_pOnscreenSurface);
-
-#endif
 }
 
 void CCanvas::DestroySurfaces() {
   // Free the buffer pixmaps
 
-#if WITH_CAIRO
   cr = NULL;
   cairo_surface_destroy(m_pDisplaySurface);
   cairo_surface_destroy(m_pDecorationSurface);
@@ -80,19 +53,11 @@ void CCanvas::DestroySurfaces() {
   cairo_destroy(display_cr);
   cairo_destroy(decoration_cr);
   //cairo_destroy(onscreen_cr);
-#else
-  //g_object_unref(m_pDummyBuffer);
-  g_object_unref(m_pDisplayBuffer);
-  g_object_unref(m_pDecorationBuffer);
-  //g_object_unref(m_pOnscreenBuffer);
-#endif
 }
 
 CCanvas::~CCanvas() {
   DestroySurfaces();
-#if WITH_CAIRO
   delete[] cairo_colours;
-#endif
 }
 
 void CCanvas::resize(screenint w,screenint h) {
@@ -115,15 +80,6 @@ void CCanvas::Display() {
   // FIXME - Some of this stuff is probably not needed
   //  GdkRectangle update_rect;
 
-#if WITH_CAIRO
-#else
-  GdkGC *graphics_context;
-  GdkColormap *colormap;
-
-  graphics_context = m_pCanvas->style->fg_gc[GTK_WIDGET_STATE(m_pCanvas)];
-  colormap = gdk_colormap_get_system();
-#endif
-
   BEGIN_DRAWING;
   SET_COLOR(0);
 
@@ -161,16 +117,12 @@ void CCanvas::Display() {
   //  GdkRectangle sRect = {0, 0, GetWidth(), GetHeight()};
   //  gdk_window_begin_paint_rect(m_pCanvas->window, &sRect);
 
-#if WITH_CAIRO  
   cairo_t *widget_cr;
   widget_cr = gdk_cairo_create(gtk_widget_get_window(m_pCanvas));
   cairo_set_source_surface(widget_cr, m_pDecorationSurface, 0, 0);
   cairo_rectangle(widget_cr, 0, 0, GetWidth(), GetHeight());
   cairo_fill(widget_cr);
   cairo_destroy(widget_cr);
-#else
-  gdk_draw_drawable(m_pCanvas->window, m_pCanvas->style->fg_gc[GTK_WIDGET_STATE(m_pCanvas)], 
m_pDecorationBuffer, 0, 0, 0, 0, GetWidth(), GetHeight());
-#endif
 
   //   gdk_window_end_paint(m_pCanvas->window);
 
@@ -185,15 +137,6 @@ void CCanvas::DrawRectangle(screenint x1, screenint y1, screenint x2, screenint
 
   //  std::cout << "Raw Rectangle, (" << x1 << ", " << y1 << ") - (" << x2 << ", " << y2 << ")" << std::endl;
 
-#if WITH_CAIRO
-#else
-  GdkGC *graphics_context;
-  GdkColormap *colormap;
-
-  graphics_context = m_pCanvas->style->fg_gc[GTK_WIDGET_STATE(m_pCanvas)];
-  colormap = gdk_colormap_get_system();
-#endif
-
   BEGIN_DRAWING;
 
   int iLeft;
@@ -223,13 +166,9 @@ void CCanvas::DrawRectangle(screenint x1, screenint y1, screenint x2, screenint
 
   if(Color!=-1) {
     SET_COLOR(Color);
-#if WITH_CAIRO
     //cairo_set_line_width(cr, iThickness); //outline done below
     cairo_rectangle(cr, iLeft, iTop, iWidth, iHeight);
     cairo_fill(cr);
-#else
-    gdk_draw_rectangle(m_pOffscreenBuffer, graphics_context, TRUE, iLeft, iTop, iWidth + 1, iHeight + 1);
-#endif
   }
 
   if(iThickness>0) {
@@ -242,51 +181,28 @@ void CCanvas::DrawRectangle(screenint x1, screenint y1, screenint x2, screenint
     // the end of the other map to the same pixel. This generally
     // results in box outlines being truncated.
 
-#if WITH_CAIRO
     cairo_set_line_width(cr, iThickness);
     cairo_rectangle(cr, iLeft + 0.5, iTop + 0.5, iWidth, iHeight);
     cairo_stroke(cr);
-#else
-    gdk_gc_set_line_attributes(graphics_context, iThickness, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND );
-    gdk_draw_rectangle(m_pOffscreenBuffer, graphics_context, FALSE, iLeft, iTop, iWidth, iHeight);
-#endif
   }
   END_DRAWING;
 }
 
 void CCanvas::DrawCircle(screenint iCX, screenint iCY, screenint iR, int iFillColour, int iLineColour, int 
iThickness) {
-#if WITH_CAIRO
-#else
-  GdkGC *graphics_context;
-  GdkColormap *colormap;
-
-  graphics_context = m_pCanvas->style->fg_gc[GTK_WIDGET_STATE(m_pCanvas)];
-  colormap = gdk_colormap_get_system();
-#endif
 
   BEGIN_DRAWING;
 
   if(iFillColour!=-1) {
     SET_COLOR(iFillColour);
-#if WITH_CAIRO
     cairo_arc(cr, iCX, iCY, iR, 0, 2*M_PI);
     cairo_fill(cr);
-#else
-    gdk_draw_arc(m_pOffscreenBuffer, graphics_context, true, iCX - iR, iCY - iR, 2*iR, 2*iR, 0, 23040);
-#endif
   }
 
   if (iThickness>0) {
     SET_COLOR(iLineColour);
-#if WITH_CAIRO
     cairo_set_line_width(cr, iThickness);
     cairo_arc(cr, iCX, iCY, iR, 0, 2*M_PI);
     cairo_stroke(cr);
-#else
-    //note fiddle on iThickness, allegedly "to make it work on Windows"(?)...
-    gdk_gc_set_line_attributes(graphics_context, iThickness==1 ? 0 : iThickness, GDK_LINE_SOLID, 
GDK_CAP_ROUND, GDK_JOIN_ROUND );
-    gdk_draw_arc(m_pOffscreenBuffer, graphics_context, false, iCX - iR, iCY - iR, 2*iR, 2*iR, 0, 23040);
-#endif
   }
 
   END_DRAWING;
@@ -299,18 +215,8 @@ void CCanvas::Polygon(Dasher::CDasherScreen::point *Points, int Number, int fill
   //if(iWidth == 1) // This is to make it work properly on Windows
   //  iWidth = 0; 
 
-#if WITH_CAIRO
-#else
-  GdkGC *graphics_context;
-  GdkColormap *colormap;
-
-  graphics_context = m_pCanvas->style->fg_gc[GTK_WIDGET_STATE(m_pCanvas)];
-  colormap = gdk_colormap_get_system();
-#endif
-
   BEGIN_DRAWING;
 
-#if WITH_CAIRO
  cairo_move_to(cr, Points[0].x, Points[0].y);
   for (int i=1; i < Number; i++)
     cairo_line_to(cr, Points[i].x, Points[i].y);
@@ -327,27 +233,6 @@ void CCanvas::Polygon(Dasher::CDasherScreen::point *Points, int Number, int fill
     SET_COLOR(outlineColour==-1 ? 3 : outlineColour);
     cairo_stroke(cr);
   }
-#else
-  GdkPoint *gdk_points;
-  gdk_points = (GdkPoint *) g_malloc(Number * sizeof(GdkPoint));
-
-  for(int i = 0; i < Number; i++) {
-    gdk_points[i].x = Points[i].x;
-    gdk_points[i].y = Points[i].y;
-  }
-
-  if (fillColour != -1) {
-    SET_COLOR(fillColour);
-    gdk_gc_set_line_attributes(graphics_context, 1, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND );
-    gdk_draw_polygon(m_pOffscreenBuffer, graphics_context, TRUE, gdk_points, Number);
-  }
-  if (iWidth > 0) {
-    SET_COLOR(outlineColour);
-    gdk_gc_set_line_attributes(graphics_context, iWidth, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND );
-    gdk_draw_polygon(m_pOffscreenBuffer, graphics_context, FALSE, gdk_points, Number);
-  }
-  g_free(gdk_points);
-#endif
 
   END_DRAWING;
 }
@@ -356,41 +241,14 @@ void CCanvas::Polyline(Dasher::CDasherScreen::point *Points, int Number, int iWi
 
   // FIXME - combine this with polygon?
 
-#if WITH_CAIRO
-#else
-  if(iWidth == 1) // This is to make it work propely on Windows
-    iWidth = 0; 
-
-  GdkGC *graphics_context;
-  GdkColormap *colormap;
-  
-  graphics_context = m_pCanvas->style->fg_gc[GTK_WIDGET_STATE(m_pCanvas)];
-  colormap = gdk_colormap_get_system();
-#endif
-
   BEGIN_DRAWING;
   SET_COLOR(Colour);
 
-#if WITH_CAIRO
   cairo_set_line_width(cr, iWidth);
   cairo_move_to(cr, Points[0].x+.5, Points[0].y+.5);
   for (int i=1; i < Number; i++)
     cairo_line_to(cr, Points[i].x+.5, Points[i].y+.5);
   cairo_stroke(cr);
-#else
-  GdkPoint *gdk_points;
-  gdk_points = (GdkPoint *) g_malloc(Number * sizeof(GdkPoint));
-
-  gdk_gc_set_line_attributes(graphics_context, iWidth, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND );
-
-  for(int i = 0; i < Number; i++) {
-    gdk_points[i].x = Points[i].x;
-    gdk_points[i].y = Points[i].y;
-  }
-
-  gdk_draw_lines(m_pOffscreenBuffer, graphics_context, gdk_points, Number);
-  g_free(gdk_points);
-#endif 
 
   END_DRAWING;
 }
@@ -420,11 +278,7 @@ PangoLayout *CCanvas::GetLayout(CPangoLabel *label, unsigned int iFontSize) {
     map<unsigned int,PangoLayout *>::iterator it = label->m_mLayouts.find(iFontSize);
     if (it != label->m_mLayouts.end()) return it->second;
   }
-#if WITH_CAIRO
     PangoLayout *pNewPangoLayout(pango_cairo_create_layout(cr));
-#else
-    PangoLayout *pNewPangoLayout(gtk_widget_create_pango_layout(m_pCanvas, ""));
-#endif
   label->m_mLayouts.insert(pair<unsigned int,PangoLayout *>(iFontSize, pNewPangoLayout));
   if (label->m_iWrapSize) pango_layout_set_width(pNewPangoLayout, GetWidth() * PANGO_SCALE);
   pango_layout_set_text(pNewPangoLayout, label->m_strText.c_str(), -1);
@@ -445,16 +299,6 @@ PangoLayout *CCanvas::GetLayout(CPangoLabel *label, unsigned int iFontSize) {
 }
 
 void CCanvas::DrawString(CDasherScreen::Label *label, screenint x1, screenint y1, unsigned int size, int 
iColor) {
-  
-#if WITH_CAIRO
-#else
-  GdkGC *graphics_context;
-  GdkColormap *colormap;
-
-  graphics_context = m_pCanvas->style->fg_gc[GTK_WIDGET_STATE(m_pCanvas)];
-  colormap = gdk_colormap_get_system();
-#endif
-
   BEGIN_DRAWING;
   SET_COLOR(iColor);
 
@@ -465,12 +309,8 @@ void CCanvas::DrawString(CDasherScreen::Label *label, screenint x1, screenint y1
   pango_layout_get_pixel_extents(pLayout, &sPangoInk, NULL);
   x1 -= sPangoInk.x;
   y1 -= sPangoInk.y;
-#if WITH_CAIRO
   cairo_translate(cr, x1, y1);
   pango_cairo_show_layout(cr, pLayout);
-#else
-  gdk_draw_layout(m_pOffscreenBuffer, graphics_context, x1, y1, pLayout);
-#endif
 
   END_DRAWING;
 }
@@ -488,23 +328,14 @@ void CCanvas::SendMarker(int iMarker) {
 
   switch(iMarker) {
   case 0: // Switch to display buffer
-#if WITH_CAIRO
     cr = display_cr;
-#else
-    m_pOffscreenBuffer = m_pDisplayBuffer;
-#endif
     break;
   case 1: // Switch to decorations buffer
 
-#if WITH_CAIRO
     cairo_set_source_surface(decoration_cr, m_pDisplaySurface, 0, 0);
     cairo_rectangle(decoration_cr, 0, 0, GetWidth(), GetHeight());
     cairo_fill(decoration_cr);
     cr = decoration_cr;
-#else
-    gdk_draw_drawable(m_pDecorationBuffer, m_pCanvas->style->fg_gc[GTK_WIDGET_STATE(m_pCanvas)], 
m_pDisplayBuffer, 0, 0, 0, 0, GetWidth(), GetHeight());
-    m_pOffscreenBuffer = m_pDecorationBuffer;
-#endif
     break;
   }
 }
@@ -512,29 +343,16 @@ void CCanvas::SendMarker(int iMarker) {
 void CCanvas::SetColourScheme(const CColourIO::ColourInfo *pColourScheme) {
   int iNumColours(pColourScheme->Reds.size());
 
-#if WITH_CAIRO
   if (cairo_colours)
     delete[] cairo_colours;
   cairo_colours = new cairo_pattern_t*[iNumColours];
-#else
-  if (colours)
-    delete[] colours;
-  colours = new GdkColor[iNumColours];
-#endif
 
   for(int i = 0; i < iNumColours; i++) {
-#if WITH_CAIRO
     cairo_colours[i] = cairo_pattern_create_rgb (
       pColourScheme->Reds[i]   / 255.0,
       pColourScheme->Greens[i] / 255.0,
       pColourScheme->Blues[i]  / 255.0
     );
-#else
-    colours[i].pixel=0;
-    colours[i].red=pColourScheme->Reds[i]*257;
-    colours[i].green=pColourScheme->Greens[i]*257;
-    colours[i].blue=pColourScheme->Blues[i]*257;
-#endif
   }
 }
 
diff --git a/Src/Gtk2/Canvas.h b/Src/Gtk2/Canvas.h
index 6e34c7e9c..a6459e440 100644
--- a/Src/Gtk2/Canvas.h
+++ b/Src/Gtk2/Canvas.h
@@ -13,8 +13,6 @@
 
 #include <iostream>
 
-#if WITH_CAIRO
-
 #define BEGIN_DRAWING_BACKEND                          \
   cairo_save(cr)
 
@@ -24,24 +22,6 @@
 #define SET_COLOR_BACKEND(c)                           \
   cairo_set_source(cr, cairo_colours[(c)])
 
-#else /* WITHOUT_CAIRO */
-
-#define BEGIN_DRAWING_BACKEND                          \
-  GdkGCValues origvalues;                              \
-  gdk_gc_get_values(graphics_context,&origvalues)
-
-#define END_DRAWING_BACKEND                            \
-  gdk_gc_set_values(graphics_context,&origvalues,GDK_GC_FOREGROUND)
-
-#define SET_COLOR_BACKEND(c)                           \
-  do {                                                 \
-    GdkColor _c = colours[(c)];                                \
-    gdk_colormap_alloc_color(colormap, &_c, FALSE, TRUE);      \
-    gdk_gc_set_foreground (graphics_context, &_c);     \
-  } while (0)
-
-#endif /* WITH_CAIRO */
-
 // Some other useful macros (for all backends)
 
 #define BEGIN_DRAWING                                  \
@@ -192,44 +172,20 @@ private:
 
   void InitSurfaces();
   void DestroySurfaces();
-#if WITH_CAIRO
 
-  cairo_surface_t *m_pDisplaySurface;
-  cairo_surface_t *m_pDecorationSurface;
-  //cairo_surface_t *m_pOnscreenSurface;
-
-  cairo_surface_t *m_pOffscreenbuffer;
-
-#else
-
-  ///
   /// The offscreen buffer containing the 'background'
-  ///
-
-  GdkPixmap *m_pDisplayBuffer;
+  cairo_surface_t *m_pDisplaySurface;
 
-  /// 
   /// The offscreen buffer containing the full display. This is
   /// constructed by first copying the display buffer across and then
   /// drawing decorations such as the mouse cursor on top.
-  ///
-
-  GdkPixmap *m_pDecorationBuffer;
+  cairo_surface_t *m_pDecorationSurface;
 
-  ///
   /// The onscreen buffer - copied onscreen whenever an expose event occurs.
-  ///
-
-  //GdkPixmap *m_pOnscreenBuffer;
+  //cairo_surface_t *m_pOnscreenSurface;
 
-  ///
   /// Pointer to which of the offscreen buffers is currently active.
-  ///
-
-  GdkPixmap *m_pOffscreenBuffer;
-  //GdkPixmap *m_pDummyBuffer;
-
-#endif
+  cairo_surface_t *m_pOffscreenbuffer;
 
   std::string m_strFontName;
   std::map<unsigned int,PangoFontDescription *> m_mFonts;
@@ -244,16 +200,11 @@ private:
 
   PangoLayout *GetLayout(CPangoLabel *label, unsigned int iFontSize);
 
-#if WITH_CAIRO
   cairo_t *display_cr;
   cairo_t *decoration_cr;
 
   cairo_t *cr; // offscreen
   cairo_pattern_t **cairo_colours;
-#else
-  GdkColor *colours;
-#endif  
-
 };
 
 #endif
diff --git a/configure.ac b/configure.ac
index d26940be7..3e7b1648f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -103,14 +103,6 @@ dnl           WITHDARWIN=false;
 dnl    fi,
 dnl    WITHDARWIN=false)
 
-AC_ARG_WITH([cairo],
-        AS_HELP_STRING([--with-cairo],[build with cairo support (default is YES)]),
-        if test "x$withval" = "xno"; then
-          WITHCAIRO=false; 
-        else
-          WITHCAIRO=true;
-        fi, 
-        WITHCAIRO=true)
 
 PKG_CHECK_MODULES(GTK, gtk+-3.0)
 
@@ -238,10 +230,7 @@ dnl if test x"$WITHDARWIN" = xtrue ; then
 dnl         AC_DEFINE([WITH_DARWIN], 1, [Targeting Darwin/X11])
 dnl fi
 
-if test x"$WITHCAIRO" = xtrue; then
-       PKG_CHECK_MODULES(cairo, cairo)
-       AC_DEFINE([WITH_CAIRO], 1, [use cairo])
-fi
+PKG_CHECK_MODULES(cairo, cairo)
 
 PKG_CHECK_MODULES(gthread, gthread-2.0)
 AC_SUBST(gthread_LIBS)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]