/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.24 from the
 * contents of GnomeCanvasUtil.xs. Do not edit this file, edit GnomeCanvasUtil.xs instead.
 *
 *    ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "xs/GnomeCanvasUtil.xs"
/*
 * Copyright (c) 2003 by the gtk2-perl team (see the file AUTHORS)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA  02111-1307  USA.
 *
 * $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/GnomeCanvas/xs/GnomeCanvasUtil.xs,v 1.7 2004/08/16 02:03:12 muppetman Exp $
 */
#include "gnomecanvasperl.h"

static SV*      gnomecanvasperl_points_wrap    (GType        gtype,
                                                const char * package,
                                                gpointer     boxed,
                                                gboolean     own);
static gpointer gnomecanvasperl_points_unwrap  (GType        gtype,
                                                const char * package,
                                                SV         * sv);

static GPerlBoxedWrapperClass point_wrapper_class = {
	gnomecanvasperl_points_wrap,
	gnomecanvasperl_points_unwrap,
	NULL
};

static SV*
gnomecanvasperl_points_wrap    (GType        gtype,
                                const char * package,
                                gpointer     boxed,
                                gboolean     own)
{
	AV * av;
	int i;
	GnomeCanvasPoints * points;

	if (!boxed)
		return &PL_sv_undef;

	points = (GnomeCanvasPoints*) boxed;

	av = newAV ();

	for (i = 0; i < points->num_points * 2 ; i++)
		av_push (av, newSVnv (points->coords[i]));

	if (own)
		g_boxed_free (gtype, boxed);

	return newRV_noinc ((SV*)av);
}

static gpointer
gnomecanvasperl_points_unwrap  (GType        gtype,
                                const char * package,
                                SV         * sv)
{
	GnomeCanvasPoints * points;
	AV * av;
	int i, n;

	if (!sv || !SvROK (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
		return NULL;

	av = (AV*) SvRV (sv);
	n = av_len (av) + 1;

	points = gperl_alloc_temp (sizeof (GnomeCanvasPoints));
	points->ref_count = 1;
	points->num_points = n / 2;
	points->coords = gperl_alloc_temp (sizeof (double) * n);

	for (i = 0 ; i < n ; i++) {
		SV ** svp = av_fetch (av, i, FALSE);
		points->coords[i] = svp ? SvNV (*svp) : 0.0;
	}

	return points;
}


#line 102 "xs/GnomeCanvasUtil.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef dVAR
#  define dVAR		dNOOP
#endif


/* This stuff is not part of the API! You have been warned. */
#ifndef PERL_VERSION_DECIMAL
#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
#endif
#ifndef PERL_DECIMAL_VERSION
#  define PERL_DECIMAL_VERSION \
	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
#endif
#ifndef PERL_VERSION_GE
#  define PERL_VERSION_GE(r,v,s) \
	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
#endif
#ifndef PERL_VERSION_LE
#  define PERL_VERSION_LE(r,v,s) \
	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
#endif

/* XS_INTERNAL is the explicit static-linkage variant of the default
 * XS macro.
 *
 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
 * for anything but the BOOT XSUB.
 *
 * See XSUB.h in core!
 */


/* TODO: This might be compatible further back than 5.10.0. */
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
#  undef XS_EXTERNAL
#  undef XS_INTERNAL
#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
#    define XS_INTERNAL(name) STATIC XSPROTO(name)
#  endif
#  if defined(__SYMBIAN32__)
#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
#  endif
#  ifndef XS_EXTERNAL
#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
#    else
#      ifdef __cplusplus
#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
#        define XS_INTERNAL(name) static XSPROTO(name)
#      else
#        define XS_EXTERNAL(name) XSPROTO(name)
#        define XS_INTERNAL(name) STATIC XSPROTO(name)
#      endif
#    endif
#  endif
#endif

/* perl >= 5.10.0 && perl <= 5.15.1 */


/* The XS_EXTERNAL macro is used for functions that must not be static
 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
 * macro defined, the best we can do is assume XS is the same.
 * Dito for XS_INTERNAL.
 */
#ifndef XS_EXTERNAL
#  define XS_EXTERNAL(name) XS(name)
#endif
#ifndef XS_INTERNAL
#  define XS_INTERNAL(name) XS(name)
#endif

/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
 * internal macro that we're free to redefine for varying linkage due
 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
 */

#undef XS_EUPXS
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
#  define XS_EUPXS(name) XS_EXTERNAL(name)
#else
   /* default to internal */
#  define XS_EUPXS(name) XS_INTERNAL(name)
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(pTHX_ const CV *const cv, const char *const params)
{
    const GV *const gv = CvGV(cv);

    PERL_ARGS_ASSERT_CROAK_XS_USAGE;

    if (gv) {
        const char *const gvname = GvNAME(gv);
        const HV *const stash = GvSTASH(gv);
        const char *const hvname = stash ? HvNAME(stash) : NULL;

        if (hvname)
            Perl_croak(aTHX_ "Usage: %s::%s(%s)", hvname, gvname, params);
        else
            Perl_croak(aTHX_ "Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
        Perl_croak(aTHX_ "Usage: CODE(0x%"UVxf")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#ifdef PERL_IMPLICIT_CONTEXT
#define croak_xs_usage(a,b)    S_croak_xs_usage(aTHX_ a,b)
#else
#define croak_xs_usage        S_croak_xs_usage
#endif

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#line 244 "xs/GnomeCanvasUtil.c"

XS_EUPXS(XS_Gnome2__Canvas_get_miter_points); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__Canvas_get_miter_points)
{
    dVAR; dXSARGS;
    if (items != 8)
       croak_xs_usage(cv,  "class, x1, y1, x2, y2, x3, y3, width");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	double	x1 = (double)SvNV(ST(1))
;
	double	y1 = (double)SvNV(ST(2))
;
	double	x2 = (double)SvNV(ST(3))
;
	double	y2 = (double)SvNV(ST(4))
;
	double	x3 = (double)SvNV(ST(5))
;
	double	y3 = (double)SvNV(ST(6))
;
	double	width = (double)SvNV(ST(7))
;
#line 121 "xs/GnomeCanvasUtil.xs"
	double mx1, my1, mx2, my2;
#line 271 "xs/GnomeCanvasUtil.c"
#line 123 "xs/GnomeCanvasUtil.xs"
	if (!gnome_canvas_get_miter_points (x1, y1, x2, y2, x3, y3, width,
	                                    &mx1, &my1, &mx2, &my2))
		XSRETURN_EMPTY;
	EXTEND (SP, 4);
	PUSHs (sv_2mortal (newSVnv (mx1)));
	PUSHs (sv_2mortal (newSVnv (my1)));
	PUSHs (sv_2mortal (newSVnv (mx2)));
	PUSHs (sv_2mortal (newSVnv (my2)));
#line 281 "xs/GnomeCanvasUtil.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__Canvas_get_butt_points); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__Canvas_get_butt_points)
{
    dVAR; dXSARGS;
    if (items != 7)
       croak_xs_usage(cv,  "class, x1, y1, x2, y2, width, project");
    PERL_UNUSED_VAR(ax); /* -Wall */
    SP -= items;
    {
	double	x1 = (double)SvNV(ST(1))
;
	double	y1 = (double)SvNV(ST(2))
;
	double	x2 = (double)SvNV(ST(3))
;
	double	y2 = (double)SvNV(ST(4))
;
	double	width = (double)SvNV(ST(5))
;
	int	project = (int)SvIV(ST(6))
;
#line 145 "xs/GnomeCanvasUtil.xs"
	double bx1, by1, bx2, by2;
#line 311 "xs/GnomeCanvasUtil.c"
#line 147 "xs/GnomeCanvasUtil.xs"
	gnome_canvas_get_butt_points (x1, y1, x2, y2, width, project,
	                              &bx1, &by1, &bx2, &by2);
	EXTEND (SP, 4);
	PUSHs (sv_2mortal (newSVnv (bx1)));
	PUSHs (sv_2mortal (newSVnv (by1)));
	PUSHs (sv_2mortal (newSVnv (bx2)));
	PUSHs (sv_2mortal (newSVnv (by2)));
#line 320 "xs/GnomeCanvasUtil.c"
	PUTBACK;
	return;
    }
}


XS_EUPXS(XS_Gnome2__Canvas_polygon_to_point); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__Canvas_polygon_to_point)
{
    dVAR; dXSARGS;
    if (items != 4)
       croak_xs_usage(cv,  "class, poly_ref, x, y");
    {
	SV *	poly_ref = ST(1)
;
	double	x = (double)SvNV(ST(2))
;
	double	y = (double)SvNV(ST(3))
;
#line 167 "xs/GnomeCanvasUtil.xs"
	double *poly;
	AV *array;
	int length, i;
#line 344 "xs/GnomeCanvasUtil.c"
	double	RETVAL;
	dXSTARG;
#line 171 "xs/GnomeCanvasUtil.xs"
	if (! (SvRV (poly_ref) && SvTYPE (SvRV (poly_ref)) == SVt_PVAV))
		croak ("the polygon parameter should be a reference to an "
		       "array of coordinate pairs");

	array = (AV *) SvRV (poly_ref);
	length = av_len (array) + 1;

	if (length % 2 != 0)
		croak ("the polygon array must contain x,y coordinate pairs,"
		       " so its length cannot be odd (got %d)", length);

	poly = g_new0 (double, length);

	for (i = 0; i < length; i += 2) {
		SV **value;
		value = av_fetch (array, i, 0);
		if (value && SvOK (*value))
			poly[i] = SvNV (*value);

		value = av_fetch (array, i + 1, 0);
		if (value && SvOK (*value))
			poly[i + 1] = SvNV (*value);
	}

	RETVAL = gnome_canvas_polygon_to_point (poly, length/2, x, y);

	g_free (poly);
#line 375 "xs/GnomeCanvasUtil.c"
	XSprePUSH; PUSHn((double)RETVAL);
    }
    XSRETURN(1);
}


XS_EUPXS(XS_Gnome2__Canvas__Item_reset_bounds); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__Canvas__Item_reset_bounds)
{
    dVAR; dXSARGS;
    if (items != 1)
       croak_xs_usage(cv,  "item");
    {
	GnomeCanvasItem *	item = SvGnomeCanvasItem (ST(0))
;

	gnome_canvas_item_reset_bounds(item);
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Gnome2__Canvas__Item_update_bbox); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Gnome2__Canvas__Item_update_bbox)
{
    dVAR; dXSARGS;
    if (items != 5)
       croak_xs_usage(cv,  "item, x1, y1, x2, y2");
    {
	GnomeCanvasItem *	item = SvGnomeCanvasItem (ST(0))
;
	int	x1 = (int)SvIV(ST(1))
;
	int	y1 = (int)SvIV(ST(2))
;
	int	x2 = (int)SvIV(ST(3))
;
	int	y2 = (int)SvIV(ST(4))
;

	gnome_canvas_update_bbox(item, x1, y1, x2, y2);
    }
    XSRETURN_EMPTY;
}

#ifdef __cplusplus
extern "C"
#endif
XS_EXTERNAL(boot_Gnome2__Canvas__Util); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Gnome2__Canvas__Util)
{
    dVAR; dXSARGS;
#if (PERL_REVISION == 5 && PERL_VERSION < 9)
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#endif
    XS_VERSION_BOOTCHECK;

        newXS("Gnome2::Canvas::get_miter_points", XS_Gnome2__Canvas_get_miter_points, file);
        newXS("Gnome2::Canvas::get_butt_points", XS_Gnome2__Canvas_get_butt_points, file);
        newXS("Gnome2::Canvas::polygon_to_point", XS_Gnome2__Canvas_polygon_to_point, file);
        newXS("Gnome2::Canvas::Item::reset_bounds", XS_Gnome2__Canvas__Item_reset_bounds, file);
        newXS("Gnome2::Canvas::Item::update_bbox", XS_Gnome2__Canvas__Item_update_bbox, file);

    /* Initialisation Section */

#line 95 "xs/GnomeCanvasUtil.xs"
	/* override default wrapper implementation for GnomeCanvasPoints */
	gperl_register_boxed (GNOME_TYPE_CANVAS_POINTS,
	                      "Gnome2::Canvas::Points",
	                      &point_wrapper_class);

#line 455 "xs/GnomeCanvasUtil.c"

    /* End of Initialisation Section */

#if (PERL_REVISION == 5 && PERL_VERSION >= 9)
  if (PL_unitcheckav)
       call_list(PL_scopestack_ix, PL_unitcheckav);
#endif
    XSRETURN_YES;
}

