File: ClutterBehaviourPath.xs

package info (click to toggle)
clutter-perl 0.8.0.1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 652 kB
  • ctags: 42
  • sloc: perl: 645; ansic: 30; makefile: 3
file content (157 lines) | stat: -rw-r--r-- 4,725 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "clutterperl.h"

#define HFETCHIV(hv,key) \
        (((svp = hv_fetch ((hv), (key), strlen ((key)), FALSE)) \
          && SvOK (*svp))                                       \
          ? SvIV (*svp)                                         \
          : 0)

#define AFETCHIV(av,index) \
        (((svp = av_fetch ((av), (index), FALSE))               \
          && SvOK (*svp))                                       \
          ? SvIV (*svp)                                         \
          : 0)

static GPerlBoxedWrapperClass clutter_knot_wrapper_class;

static SV *
clutter_knot_wrap (GType        gtype,
                   const gchar *package,
                   gpointer     boxed,
                   gboolean     own)
{
        ClutterKnot *knot = boxed;
        AV *av;

        if (!knot)
                return &PL_sv_undef;

        av = newAV ();

        av_push (av, newSVuv (knot->x));
        av_push (av, newSVuv (knot->y));

        if (own)
                clutter_knot_free (knot);
        
        return newRV_noinc ((SV *) av);
}

static void *
clutter_knot_unwrap (GType        gtype,
                     const gchar *package,
                     SV          *sv)
{
        ClutterKnot *knot;
        SV **svp;

        if (!sv || !SvOK (sv) || !SvRV (sv))
                return NULL;

        knot = gperl_alloc_temp (sizeof (ClutterKnot));

        switch (SvTYPE (SvRV (sv))) {
                case SVt_PVHV:
                        {
                        HV *hv = (HV *) SvRV (sv);
                        knot->x = HFETCHIV (hv, "x");
                        knot->y = HFETCHIV (hv, "y");
                        }
                        break;
                case SVt_PVAV:
                        {
                        AV *av = (AV *) SvRV (sv);
                        knot->x = AFETCHIV (av, 0);
                        knot->y = AFETCHIV (av, 1);
                        }
                        break;
                default:
                        croak ("a ClutterKnot must either be an array "
                               "or an hash with two values: x and y");
                        break;
       }

       return knot;
}

MODULE = Clutter::Behaviour::Path       PACKAGE = Clutter::Knot PREFIX = clutter_knot_

BOOT:
        PERL_UNUSED_VAR (file);
        clutter_knot_wrapper_class = * gperl_default_boxed_wrapper_class ();
        clutter_knot_wrapper_class.wrap = clutter_knot_wrap;
        clutter_knot_wrapper_class.unwrap = clutter_knot_unwrap;
        gperl_register_boxed (CLUTTER_TYPE_KNOT, "Clutter::Knot",
                              &clutter_knot_wrapper_class);

gboolean
clutter_knot_equal (ClutterKnot *knot_a, ClutterKnot *knot_b)


MODULE = Clutter::Behaviour::Path       PACKAGE = Clutter::Behaviour::Path      PREFIX = clutter_behaviour_path_

=for apidoc
=for signature behaviour = Clutter::Behaviour::Path->new ($alpha, ...)
=for arg knot (__hide__)
=for arg ... list of knots
=cut
ClutterBehaviour_noinc *
clutter_behaviour_path_new (class, alpha, knot=NULL, ...)
        ClutterAlpha_ornull *alpha
        ClutterKnot_ornull *knot
    PREINIT:
        ClutterBehaviourPath *path;
        int i;
    CODE:
        RETVAL = clutter_behaviour_path_new (alpha, NULL, 0);
        path = CLUTTER_BEHAVIOUR_PATH (RETVAL);
        for (i = 2; i < items; i++) {
                clutter_behaviour_path_append_knot (path,
                                                    SvClutterKnot (ST (i)));
        }
    OUTPUT:
        RETVAL

=for apidoc
=for arg knot (__hide__)
=for arg ... list of knots
=cut
void
clutter_behaviour_path_append_knot (behaviour, knot, ...)
        ClutterBehaviourPath *behaviour
        ClutterKnot *knot
    PREINIT:
        int i;
    CODE:
        clutter_behaviour_path_append_knot (behaviour, knot);
        for (i = 2; i < items; i++) {
                clutter_behaviour_path_append_knot (behaviour,
                                                    SvClutterKnot (ST (i)));
        }

void
clutter_behaviour_path_insert_knot (behaviour, offset, knot)
        ClutterBehaviourPath *behaviour
        guint offset
        ClutterKnot *knot

void
clutter_behaviour_path_remove_knot (behaviour, offset)
        ClutterBehaviourPath *behaviour
        guint offset

void
clutter_behaviour_path_get_knots (behaviour)
        ClutterBehaviourPath *behaviour
    PREINIT:
        GSList *knots, *l;
    PPCODE:
        knots = clutter_behaviour_path_get_knots (behaviour);
        for (l = knots; l; l = l->next) {
                XPUSHs (sv_2mortal (newSVClutterKnot (l->data)));
        }
        g_slist_free (knots);

void
clutter_behaviour_path_clear (behaviour)
        ClutterBehaviourPath *behaviour