[gtksourceview/wip/gutter-renderer-folding: 2/2] GutterRendererFolds: draw a vertical line



commit 07b776703724321303ca8696f6dd93a3c6be2e9e
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri Sep 6 18:38:27 2013 +0200

    GutterRendererFolds: draw a vertical line
    
    And add a test program.

 gtksourceview/gtksource.h                    |    1 +
 gtksourceview/gtksourcegutterrendererfolds.c |   42 ++++++++++++++++++
 gtksourceview/gtksourcegutterrendererfolds.h |    4 +-
 tests/Makefile.am                            |    7 +++
 tests/test-folding.c                         |   60 ++++++++++++++++++++++++++
 5 files changed, 113 insertions(+), 1 deletions(-)
---
diff --git a/gtksourceview/gtksource.h b/gtksourceview/gtksource.h
index 1c7bd79..4d09fe9 100644
--- a/gtksourceview/gtksource.h
+++ b/gtksourceview/gtksource.h
@@ -30,6 +30,7 @@
 #include <gtksourceview/gtksourcecompletionprovider.h>
 #include <gtksourceview/gtksourcegutter.h>
 #include <gtksourceview/gtksourcegutterrenderer.h>
+#include <gtksourceview/gtksourcegutterrendererfolds.h>
 #include <gtksourceview/gtksourcegutterrenderertext.h>
 #include <gtksourceview/gtksourcegutterrendererpixbuf.h>
 #include <gtksourceview/gtksourcelanguage.h>
diff --git a/gtksourceview/gtksourcegutterrendererfolds.c b/gtksourceview/gtksourcegutterrendererfolds.c
index d82cc47..e5477c8 100644
--- a/gtksourceview/gtksourcegutterrendererfolds.c
+++ b/gtksourceview/gtksourcegutterrendererfolds.c
@@ -31,6 +31,37 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererFolds,
                            GTK_SOURCE_TYPE_GUTTER_RENDERER)
 
 static void
+gutter_renderer_folds_draw (GtkSourceGutterRenderer      *renderer,
+                           cairo_t                      *cr,
+                           GdkRectangle                 *background_area,
+                           GdkRectangle                 *cell_area,
+                           GtkTextIter                  *start,
+                           GtkTextIter                  *end,
+                           GtkSourceGutterRendererState  state)
+{
+       /* Chain up to draw background */
+       GTK_SOURCE_GUTTER_RENDERER_CLASS (
+               gtk_source_gutter_renderer_folds_parent_class)->draw (renderer,
+                                                                     cr,
+                                                                     background_area,
+                                                                     cell_area,
+                                                                     start,
+                                                                     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);
+
+       cairo_restore (cr);
+}
+
+static void
 gtk_source_gutter_renderer_folds_finalize (GObject *object)
 {
 
@@ -41,8 +72,11 @@ static void
 gtk_source_gutter_renderer_folds_class_init (GtkSourceGutterRendererFoldsClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass);
 
        object_class->finalize = gtk_source_gutter_renderer_folds_finalize;
+
+       renderer_class->draw = gutter_renderer_folds_draw;
 }
 
 static void
@@ -50,3 +84,11 @@ gtk_source_gutter_renderer_folds_init (GtkSourceGutterRendererFolds *self)
 {
        self->priv = gtk_source_gutter_renderer_folds_get_instance_private (self);
 }
+
+GtkSourceGutterRenderer *
+gtk_source_gutter_renderer_folds_new (void)
+{
+       return g_object_new (GTK_SOURCE_TYPE_GUTTER_RENDERER_FOLDS,
+                            "size", 11,
+                            NULL);
+}
diff --git a/gtksourceview/gtksourcegutterrendererfolds.h b/gtksourceview/gtksourcegutterrendererfolds.h
index 09953f6..22d47c5 100644
--- a/gtksourceview/gtksourcegutterrendererfolds.h
+++ b/gtksourceview/gtksourcegutterrendererfolds.h
@@ -51,7 +51,9 @@ struct _GtkSourceGutterRendererFoldsClass
        gpointer padding[10];
 };
 
-GType gtk_source_gutter_renderer_folds_get_type (void) G_GNUC_CONST;
+GType                   gtk_source_gutter_renderer_folds_get_type      (void) G_GNUC_CONST;
+
+GtkSourceGutterRenderer        *gtk_source_gutter_renderer_folds_new           (void);
 
 G_END_DECLS
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b5e6827..b410345 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -32,6 +32,13 @@ test_completion_LDADD =              \
        $(DEP_LIBS)                     \
        $(TESTS_LIBS)
 
+TEST_PROGS += test-folding
+test_folding_SOURCES = test-folding.c
+test_folding_LDADD =                                           \
+       $(top_builddir)/gtksourceview/libgtksourceview-3.0.la   \
+       $(DEP_LIBS)                                             \
+       $(TESTS_LIBS)
+
 TEST_PROGS += test-search
 test_search_SOURCES =          \
        test-search.c           \
diff --git a/tests/test-folding.c b/tests/test-folding.c
new file mode 100644
index 0000000..13c6a09
--- /dev/null
+++ b/tests/test-folding.c
@@ -0,0 +1,60 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/* test-folding.c
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2013 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <gtksourceview/gtksource.h>
+
+static void
+add_folds_gutter (GtkSourceView *view)
+{
+       GtkSourceGutter *gutter;
+       GtkSourceGutterRenderer *renderer;
+
+       gutter = gtk_source_view_get_gutter (view, GTK_TEXT_WINDOW_LEFT);
+       renderer = gtk_source_gutter_renderer_folds_new ();
+       gtk_source_gutter_insert (gutter, renderer, 0);
+}
+
+int
+main (int argc, char *argv[])
+{
+       GtkWidget *window;
+       GtkWidget *sw;
+       GtkWidget *source_view;
+
+       gtk_init (&argc, &argv);
+
+       window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+       gtk_window_set_default_size (GTK_WINDOW (window), 500, 500);
+       g_signal_connect (window, "destroy", gtk_main_quit, NULL);
+
+       sw = gtk_scrolled_window_new (NULL, NULL);
+       gtk_container_add (GTK_CONTAINER (window), sw);
+
+       source_view = gtk_source_view_new ();
+       gtk_container_add (GTK_CONTAINER (sw), source_view);
+
+       add_folds_gutter (GTK_SOURCE_VIEW (source_view));
+
+       gtk_widget_show_all (window);
+
+       gtk_main ();
+       return 0;
+}


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