[gnome-builder] libide: add cairo helpers



commit 94b3c77085ca18df337bcb9ded38abcd73fd0993
Author: Christian Hergert <christian hergert me>
Date:   Wed Feb 25 11:39:09 2015 -0800

    libide: add cairo helpers

 libide/Makefile.am      |    2 +
 libide/util/ide-cairo.c |   84 +++++++++++++++++++++++++++++++++++++++++++++++
 libide/util/ide-cairo.h |   34 +++++++++++++++++++
 3 files changed, 120 insertions(+), 0 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index fe5fcaa..4253676 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -191,6 +191,8 @@ libide_1_0_la_SOURCES = \
        libide/tasks/ide-load-directory-task.h \
        libide/trie/trie.c \
        libide/trie/trie.h \
+       libide/util/ide-cairo.c \
+       libide/util/ide-cairo.h \
        libide/util/ide-pango.c \
        libide/util/ide-pango.h \
        $(NULL)
diff --git a/libide/util/ide-cairo.c b/libide/util/ide-cairo.c
new file mode 100644
index 0000000..a4fba52
--- /dev/null
+++ b/libide/util/ide-cairo.c
@@ -0,0 +1,84 @@
+/* ide-cairo.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This file 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.
+ *
+ * This file 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "ide-cairo.h"
+
+cairo_region_t *
+ide_cairo_region_create_from_clip_extents (cairo_t *cr)
+{
+  cairo_rectangle_int_t crect;
+  GdkRectangle rect;
+
+  g_return_val_if_fail (cr, NULL);
+
+  gdk_cairo_get_clip_rectangle (cr, &rect);
+  crect.x = rect.x;
+  crect.y = rect.y;
+  crect.width = rect.width;
+  crect.height = rect.height;
+
+  return cairo_region_create_rectangle (&crect);
+}
+
+void
+ide_cairo_rounded_rectangle (cairo_t            *cr,
+                            const GdkRectangle *rect,
+                            gint                x_radius,
+                            gint                y_radius)
+{
+  gint x;
+  gint y;
+  gint width;
+  gint height;
+  gint x1, x2;
+  gint y1, y2;
+  gint xr1, xr2;
+  gint yr1, yr2;
+
+  g_return_if_fail (cr);
+  g_return_if_fail (rect);
+
+  x = rect->x;
+  y = rect->y;
+  width = rect->width;
+  height = rect->height;
+
+  x1 = x;
+  x2 = x1 + width;
+  y1 = y;
+  y2 = y1 + height;
+
+  x_radius = MIN (x_radius, width / 2.0);
+  y_radius = MIN (y_radius, width / 2.0);
+
+  xr1 = x_radius;
+  xr2 = x_radius / 2.0;
+  yr1 = y_radius;
+  yr2 = y_radius / 2.0;
+
+  cairo_move_to (cr, x1 + xr1, y1);
+  cairo_line_to (cr, x2 - xr1, y1);
+  cairo_curve_to (cr, x2 - xr2, y1, x2, y1 + yr2, x2, y1 + yr1);
+  cairo_line_to (cr, x2, y2 - yr1);
+  cairo_curve_to (cr, x2, y2 - yr2, x2 - xr2, y2, x2 - xr1, y2);
+  cairo_line_to (cr, x1 + xr1, y2);
+  cairo_curve_to (cr, x1 + xr2, y2, x1, y2 - yr2, x1, y2 - yr1);
+  cairo_line_to (cr, x1, y1 + yr1);
+  cairo_curve_to (cr, x1, y1 + yr2, x1 + xr2, y1, x1 + xr1, y1);
+  cairo_close_path (cr);
+}
diff --git a/libide/util/ide-cairo.h b/libide/util/ide-cairo.h
new file mode 100644
index 0000000..7245594
--- /dev/null
+++ b/libide/util/ide-cairo.h
@@ -0,0 +1,34 @@
+/* ide-cairo.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This file 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.
+ *
+ * This file 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 General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_CAIRO_H
+#define IDE_CAIRO_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+cairo_region_t *ide_cairo_region_create_from_clip_extents (cairo_t            *cr);
+void            ide_cairo_rounded_rectangle               (cairo_t            *cr,
+                                                           const GdkRectangle *rect,
+                                                           gint                x_radius,
+                                                           gint                y_radius);
+
+G_END_DECLS
+
+#endif /* IDE_CAIRO_H */


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