[gtksourceview/wip/gutter-renderer-folding] GutterRendererFolds: draw a minus sign



commit b7f5f519c1186e82bd19eb3d691022b820a78177
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Sep 6 21:13:53 2013 +0200

    GutterRendererFolds: draw a minus sign

 gtksourceview/gtksourcegutterrendererfolds.c |   83 ++++++++++++++++++++++---
 1 files changed, 73 insertions(+), 10 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutterrendererfolds.c b/gtksourceview/gtksourcegutterrendererfolds.c
index e5477c8..a727cf2 100644
--- a/gtksourceview/gtksourcegutterrendererfolds.c
+++ b/gtksourceview/gtksourcegutterrendererfolds.c
@@ -21,6 +21,11 @@
 
 #include "gtksourcegutterrendererfolds.h"
 
+/* The square size for drawing the box around the minus and plus signs. */
+#define SQUARE_SIZE    9
+
+#define LINE_WIDTH     1.0
+
 struct _GtkSourceGutterRendererFoldsPrivate
 {
        gint something;
@@ -31,6 +36,61 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererFolds,
                            GTK_SOURCE_TYPE_GUTTER_RENDERER)
 
 static void
+draw_minus (cairo_t      *cr,
+           GdkRectangle *cell_area)
+{
+       gint minus_width = SQUARE_SIZE - 4;
+       gint left_margin;
+       gint top_margin;
+       gint x;
+       gint y;
+
+       left_margin = (cell_area->width - SQUARE_SIZE) / 2;
+       top_margin = (cell_area->height - SQUARE_SIZE) / 2;
+
+       x = cell_area->x + left_margin;
+       y = cell_area->y + top_margin;
+
+       cairo_save (cr);
+
+       cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
+       cairo_set_line_width (cr, LINE_WIDTH);
+
+       cairo_rectangle (cr,
+                        x + 0.5,
+                        y + 0.5,
+                        SQUARE_SIZE - 1.0,
+                        SQUARE_SIZE - 1.0);
+
+       cairo_move_to (cr,
+                      x + 2.5,
+                      y + SQUARE_SIZE / 2.0);
+
+       cairo_rel_line_to (cr, minus_width - 1.0, 0);
+
+       cairo_stroke (cr);
+
+       cairo_restore (cr);
+}
+
+static void
+draw_vertical_line (cairo_t      *cr,
+                   GdkRectangle *cell_area)
+{
+       cairo_save (cr);
+
+       cairo_set_line_width (cr, LINE_WIDTH);
+
+       cairo_move_to (cr,
+                      cell_area->x + cell_area->width / 2.0,
+                      cell_area->y);
+       cairo_rel_line_to (cr, 0, cell_area->height);
+       cairo_stroke (cr);
+
+       cairo_restore (cr);
+}
+
+static void
 gutter_renderer_folds_draw (GtkSourceGutterRenderer      *renderer,
                            cairo_t                      *cr,
                            GdkRectangle                 *background_area,
@@ -39,6 +99,8 @@ gutter_renderer_folds_draw (GtkSourceGutterRenderer      *renderer,
                            GtkTextIter                  *end,
                            GtkSourceGutterRendererState  state)
 {
+       gint line_num;
+
        /* Chain up to draw background */
        GTK_SOURCE_GUTTER_RENDERER_CLASS (
                gtk_source_gutter_renderer_folds_parent_class)->draw (renderer,
@@ -49,16 +111,16 @@ gutter_renderer_folds_draw (GtkSourceGutterRenderer      *renderer,
                                                                      end,
                                                                      state);
 
-       cairo_save (cr);
-
-       cairo_move_to (cr,
-                      cell_area->x + cell_area->width / 2.0,
-                      cell_area->y);
-       cairo_rel_line_to (cr, 0, cell_area->height);
-       cairo_set_line_width (cr, 1.0);
-       cairo_stroke (cr);
+       line_num = gtk_text_iter_get_line (start);
 
-       cairo_restore (cr);
+       if (line_num == 0)
+       {
+               draw_minus (cr, cell_area);
+       }
+       else if (line_num < 4)
+       {
+               draw_vertical_line (cr, cell_area);
+       }
 }
 
 static void
@@ -89,6 +151,7 @@ GtkSourceGutterRenderer *
 gtk_source_gutter_renderer_folds_new (void)
 {
        return g_object_new (GTK_SOURCE_TYPE_GUTTER_RENDERER_FOLDS,
-                            "size", 11,
+                            "size", SQUARE_SIZE,
+                            "xpad", 2,
                             NULL);
 }


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