app: move the GTK-free cairo utility functions to core/gimp-cairo.[ch]

This commit is contained in:
Michael Natterer 2012-04-10 12:09:37 +02:00
parent 25030ce6c4
commit 53cf2c657b
17 changed files with 139 additions and 143 deletions

View File

@ -23,6 +23,8 @@ libappcore_a_sources = \
gimp.h \
gimp-apply-operation.c \
gimp-apply-operation.h \
gimp-cairo.c \
gimp-cairo.h \
gimp-contexts.c \
gimp-contexts.h \
gimp-edit.c \

View File

@ -233,6 +233,18 @@ struct _GimpCoords
gdouble direction;
};
/* temp hack as replacement for GdkSegment */
typedef struct _GimpSegment GimpSegment;
struct _GimpSegment
{
gint x1;
gint y1;
gint x2;
gint y2;
};
#include "gegl/gimp-gegl-types.h"
#include "paint/paint-types.h"

View File

@ -1,8 +1,8 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcairo.c
* Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
* gimp-cairo.c
* Copyright (C) 2010-2012 Michael Natterer <mitch@gimp.org>
*
* Some code here is based on code from librsvg that was originally
* written by Raph Levien <raph@artofcode.com> for Gill.
@ -23,16 +23,14 @@
#include "config.h"
#include <cairo.h>
#include <gegl.h>
#include <gtk/gtk.h>
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "widgets-types.h"
#include "core-types.h"
#include "gimpcairo.h"
#include "gimpcairo-wilber.h"
#include "gimp-cairo.h"
static cairo_user_data_key_t surface_data_key = { 0, };
@ -136,97 +134,3 @@ gimp_cairo_add_segments (cairo_t *cr,
}
}
}
void
gimp_cairo_draw_toolbox_wilber (GtkWidget *widget,
cairo_t *cr)
{
GtkStyle *style;
GtkStateType state;
GtkAllocation allocation;
gdouble wilber_width;
gdouble wilber_height;
gdouble factor;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (cr != NULL);
style = gtk_widget_get_style (widget);
state = gtk_widget_get_state (widget);
gtk_widget_get_allocation (widget, &allocation);
gimp_cairo_wilber_get_size (cr, &wilber_width, &wilber_height);
factor = allocation.width / wilber_width * 0.9;
if (! gtk_widget_get_has_window (widget))
cairo_translate (cr, allocation.x, allocation.y);
cairo_scale (cr, factor, factor);
gimp_cairo_wilber (cr,
(allocation.width / factor - wilber_width) / 2.0,
(allocation.height / factor - wilber_height) / 2.0);
cairo_set_source_rgba (cr,
style->fg[state].red / 65535.0,
style->fg[state].green / 65535.0,
style->fg[state].blue / 65535.0,
0.10);
cairo_fill (cr);
}
void
gimp_cairo_draw_drop_wilber (GtkWidget *widget,
cairo_t *cr)
{
GtkStyle *style;
GtkStateType state;
GtkAllocation allocation;
gdouble wilber_width;
gdouble wilber_height;
gdouble width;
gdouble height;
gdouble side;
gdouble factor;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (cr != NULL);
style = gtk_widget_get_style (widget);
state = gtk_widget_get_state (widget);
gtk_widget_get_allocation (widget, &allocation);
gimp_cairo_wilber_get_size (cr, &wilber_width, &wilber_height);
wilber_width /= 2;
wilber_height /= 2;
side = MIN (MIN (allocation.width, allocation.height),
MAX (allocation.width, allocation.height) / 2);
width = MAX (wilber_width, side);
height = MAX (wilber_height, side);
factor = MIN (width / wilber_width, height / wilber_height);
if (! gtk_widget_get_has_window (widget))
cairo_translate (cr, allocation.x, allocation.y);
cairo_scale (cr, factor, factor);
/* magic factors depend on the image used, everything else is generic
*/
gimp_cairo_wilber (cr,
- wilber_width * 0.6,
allocation.height / factor - wilber_height * 1.1);
cairo_set_source_rgba (cr,
style->fg[state].red / 65535.0,
style->fg[state].green / 65535.0,
style->fg[state].blue / 65535.0,
0.15);
cairo_fill (cr);
}

View File

@ -1,8 +1,8 @@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpcairo.h
* Copyright (C) 2010 Michael Natterer <mitch@gimp.org>
* gimp-cairo.h
* Copyright (C) 2010-2012 Michael Natterer <mitch@gimp.org>
*
* Some code here is based on code from librsvg that was originally
* written by Raph Levien <raph@artofcode.com> for Gill.
@ -39,10 +39,5 @@ void gimp_cairo_add_segments (cairo_t *cr,
GimpSegment *segs,
gint n_segs);
void gimp_cairo_draw_toolbox_wilber (GtkWidget *widget,
cairo_t *cr);
void gimp_cairo_draw_drop_wilber (GtkWidget *widget,
cairo_t *cr);
#endif /* __GIMP_CAIRO_H__ */

View File

@ -28,7 +28,7 @@
#include "display-types.h"
#include "widgets/gimpcairo.h"
#include "core/gimp-cairo.h"
#include "gimpcanvasarc.h"
#include "gimpdisplayshell.h"

View File

@ -28,11 +28,10 @@
#include "display-types.h"
#include "core/gimp-cairo.h"
#include "core/gimpboundary.h"
#include "core/gimpparamspecs.h"
#include "widgets/gimpcairo.h"
#include "gimpcanvasboundary.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-transform.h"

View File

@ -28,7 +28,7 @@
#include "display-types.h"
#include "widgets/gimpcairo.h"
#include "core/gimp-cairo.h"
#include "gimpcanvascursor.h"
#include "gimpdisplayshell.h"

View File

@ -28,7 +28,7 @@
#include "display-types.h"
#include "widgets/gimpcairo.h"
#include "core/gimp-cairo.h"
#include "gimpcanvashandle.h"
#include "gimpcanvasitem-utils.h"

View File

@ -29,7 +29,7 @@
#include "core/gimpimage.h"
#include "core/gimpimage-quick-mask.h"
#include "widgets/gimpcairo.h"
#include "widgets/gimpcairo-wilber.h"
#include "widgets/gimpuimanager.h"
#include "gimpcanvasitem.h"

View File

@ -27,13 +27,12 @@
#include "display-types.h"
#include "core/gimp-cairo.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimppickable.h"
#include "core/gimpprojection.h"
#include "widgets/gimpcairo.h"
#include "gimpcanvas.h"
#include "gimpcanvaspath.h"
#include "gimpdisplay.h"

View File

@ -25,12 +25,11 @@
#include "config/gimpdisplayconfig.h"
#include "core/gimp.h"
#include "core/gimp-cairo.h"
#include "core/gimpboundary.h"
#include "core/gimpchannel.h"
#include "core/gimpimage.h"
#include "widgets/gimpcairo.h"
#include "gimpdisplay.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-appearance.h"

View File

@ -28,11 +28,10 @@
#include "display-types.h"
#include "core/gimp-cairo.h"
#include "core/gimpgrid.h"
#include "core/gimplayer.h"
#include "widgets/gimpcairo.h"
#include "gimpdisplayshell.h"
#include "gimpdisplayshell-style.h"

View File

@ -39,8 +39,6 @@ libappwidgets_a_sources = \
gimpbrushselect.h \
gimpbufferview.c \
gimpbufferview.h \
gimpcairo.c \
gimpcairo.h \
gimpcairo-wilber.c \
gimpcairo-wilber.h \
gimpcellrendererdashes.c \

View File

@ -29,7 +29,104 @@
#include "libgimpmath/gimpmath.h"
#include <gimpcairo-wilber.h>
#include "widgets-types.h"
#include "gimpcairo-wilber.h"
void
gimp_cairo_draw_toolbox_wilber (GtkWidget *widget,
cairo_t *cr)
{
GtkStyle *style;
GtkStateType state;
GtkAllocation allocation;
gdouble wilber_width;
gdouble wilber_height;
gdouble factor;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (cr != NULL);
style = gtk_widget_get_style (widget);
state = gtk_widget_get_state (widget);
gtk_widget_get_allocation (widget, &allocation);
gimp_cairo_wilber_get_size (cr, &wilber_width, &wilber_height);
factor = allocation.width / wilber_width * 0.9;
if (! gtk_widget_get_has_window (widget))
cairo_translate (cr, allocation.x, allocation.y);
cairo_scale (cr, factor, factor);
gimp_cairo_wilber (cr,
(allocation.width / factor - wilber_width) / 2.0,
(allocation.height / factor - wilber_height) / 2.0);
cairo_set_source_rgba (cr,
style->fg[state].red / 65535.0,
style->fg[state].green / 65535.0,
style->fg[state].blue / 65535.0,
0.10);
cairo_fill (cr);
}
void
gimp_cairo_draw_drop_wilber (GtkWidget *widget,
cairo_t *cr)
{
GtkStyle *style;
GtkStateType state;
GtkAllocation allocation;
gdouble wilber_width;
gdouble wilber_height;
gdouble width;
gdouble height;
gdouble side;
gdouble factor;
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (cr != NULL);
style = gtk_widget_get_style (widget);
state = gtk_widget_get_state (widget);
gtk_widget_get_allocation (widget, &allocation);
gimp_cairo_wilber_get_size (cr, &wilber_width, &wilber_height);
wilber_width /= 2;
wilber_height /= 2;
side = MIN (MIN (allocation.width, allocation.height),
MAX (allocation.width, allocation.height) / 2);
width = MAX (wilber_width, side);
height = MAX (wilber_height, side);
factor = MIN (width / wilber_width, height / wilber_height);
if (! gtk_widget_get_has_window (widget))
cairo_translate (cr, allocation.x, allocation.y);
cairo_scale (cr, factor, factor);
/* magic factors depend on the image used, everything else is generic
*/
gimp_cairo_wilber (cr,
- wilber_width * 0.6,
allocation.height / factor - wilber_height * 1.1);
cairo_set_source_rgba (cr,
style->fg[state].red / 65535.0,
style->fg[state].green / 65535.0,
style->fg[state].blue / 65535.0,
0.15);
cairo_fill (cr);
}
/* This string is a path description as found in SVG files. You can

View File

@ -25,12 +25,17 @@
#define __GIMP_CAIRO_WILBER_H__
void gimp_cairo_wilber (cairo_t *cr,
gdouble x,
gdouble y);
void gimp_cairo_wilber_get_size (cairo_t *cr,
gdouble *width,
gdouble *height);
void gimp_cairo_draw_toolbox_wilber (GtkWidget *widget,
cairo_t *cr);
void gimp_cairo_draw_drop_wilber (GtkWidget *widget,
cairo_t *cr);
void gimp_cairo_wilber (cairo_t *cr,
gdouble x,
gdouble y);
void gimp_cairo_wilber_get_size (cairo_t *cr,
gdouble *width,
gdouble *height);
#endif /* __GIMP_CAIRO_WILBER_H__ */

View File

@ -37,7 +37,7 @@
#include "file/file-open.h"
#include "file/file-utils.h"
#include "gimpcairo.h"
#include "gimpcairo-wilber.h"
#include "gimpdevices.h"
#include "gimpdialogfactory.h"
#include "gimpdockwindow.h"

View File

@ -281,17 +281,4 @@ typedef gboolean (* GimpPanedBoxDroppedFunc) (GtkWidget *source,
gpointer data);
/* temp hack as replacement for GdkSegment */
typedef struct _GimpSegment GimpSegment;
struct _GimpSegment
{
gint x1;
gint y1;
gint x2;
gint y2;
};
#endif /* __WIDGETS_TYPES_H__ */