~ubuntu-branches/ubuntu/warty/pygame/warty

« back to all changes in this revision

Viewing changes to src/rect.c

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-09-17 17:09:53 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040917170953-caomeukd8awvvpwv
Tags: 1.6-0.2ubuntu1
Add missing build-depends: python

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
staticforward PyTypeObject PyRect_Type;
31
31
#define PyRect_Check(x) ((x)->ob_type == &PyRect_Type)
32
32
 
 
33
#if PYTHON_API_VERSION >= 1011 /*this is the python-2.2 constructor*/
 
34
static PyObject* rect_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
 
35
#endif
 
36
 
33
37
 
34
38
 
35
39
GAME_Rect* GameRect_FromObject(PyObject* obj, GAME_Rect* temp)
36
40
{
37
 
        short val;
 
41
        int val;
 
42
        int length;
38
43
 
39
44
        if(PyRect_Check(obj))
40
45
                return &((PyRectObject*)obj)->r;
41
 
 
42
 
        if(PySequence_Check(obj))
 
46
        if(PySequence_Check(obj) && (length=PySequence_Length(obj))>0)
43
47
        {
44
 
                if(PySequence_Length(obj) == 4)
 
48
                if(length == 4)
45
49
                {
46
 
                        if(!ShortFromObjIndex(obj, 0, &val)) return NULL; temp->x = val;
47
 
                        if(!ShortFromObjIndex(obj, 1, &val)) return NULL; temp->y = val;
48
 
                        if(!ShortFromObjIndex(obj, 2, &val)) return NULL; temp->w = val;
49
 
                        if(!ShortFromObjIndex(obj, 3, &val)) return NULL; temp->h = val;
 
50
                        if(!IntFromObjIndex(obj, 0, &val)) return NULL; temp->x = val;
 
51
                        if(!IntFromObjIndex(obj, 1, &val)) return NULL; temp->y = val;
 
52
                        if(!IntFromObjIndex(obj, 2, &val)) return NULL; temp->w = val;
 
53
                        if(!IntFromObjIndex(obj, 3, &val)) return NULL; temp->h = val;
50
54
                        return temp;
51
55
                }
52
 
                if(PySequence_Length(obj) == 2)
 
56
                if(length == 2)
53
57
                {
54
58
                        PyObject* sub = PySequence_GetItem(obj, 0);
55
59
                        if(!sub || !PySequence_Check(sub) || PySequence_Length(sub)!=2)
56
60
                                {Py_XDECREF(sub); return NULL;}
57
 
                        if(!ShortFromObjIndex(sub, 0, &val)) {Py_DECREF(sub); return NULL;} temp->x = val;
58
 
                        if(!ShortFromObjIndex(sub, 1, &val)) {Py_DECREF(sub); return NULL;} temp->y = val;
 
61
                        if(!IntFromObjIndex(sub, 0, &val)) {Py_DECREF(sub); return NULL;} temp->x = val;
 
62
                        if(!IntFromObjIndex(sub, 1, &val)) {Py_DECREF(sub); return NULL;} temp->y = val;
59
63
                        Py_DECREF(sub);
60
64
                        sub = PySequence_GetItem(obj, 1);
61
65
                        if(!sub || !PySequence_Check(sub) || PySequence_Length(sub)!=2)
62
66
                                {Py_XDECREF(sub); return NULL;}
63
 
                        if(!ShortFromObjIndex(sub, 0, &val)) {Py_DECREF(sub); return NULL;} temp->w = val;
64
 
                        if(!ShortFromObjIndex(sub, 1, &val)) {Py_DECREF(sub); return NULL;} temp->h = val;
 
67
                        if(!IntFromObjIndex(sub, 0, &val)) {Py_DECREF(sub); return NULL;} temp->w = val;
 
68
                        if(!IntFromObjIndex(sub, 1, &val)) {Py_DECREF(sub); return NULL;} temp->h = val;
65
69
                        Py_DECREF(sub);
66
70
                        return temp;
67
71
                }
68
 
                if(PyTuple_Check(obj) && PyTuple_Size(obj) == 1) /*looks like an arg?*/
 
72
                if(PyTuple_Check(obj) && length == 1) /*looks like an arg?*/
69
73
                {
70
74
                        PyObject* sub = PyTuple_GET_ITEM(obj, 0);
71
75
                        if(sub)
72
76
                                return GameRect_FromObject(sub, temp);
73
77
                }
74
78
        }
 
79
    if(PyObject_HasAttrString(obj, "rect"))
 
80
    {
 
81
                PyObject *rectattr;
 
82
        GAME_Rect *returnrect;
 
83
                rectattr = PyObject_GetAttrString(obj, "rect");
 
84
        if(PyCallable_Check(rectattr)) /*call if it's a method*/
 
85
        {
 
86
            PyObject *rectresult = PyObject_CallObject(rectattr, NULL);
 
87
            Py_DECREF(rectattr);
 
88
            if(!rectresult)
 
89
                return NULL;
 
90
            rectattr = rectresult;
 
91
        }
 
92
        returnrect = GameRect_FromObject(rectattr, temp);
 
93
        Py_DECREF(rectattr);
 
94
        return returnrect;
 
95
    }
75
96
        return NULL;
76
97
}
77
98
 
78
 
static int Rect_SetTop(GAME_Rect* r, short val)
 
99
static int Rect_SetTop(GAME_Rect* r, int val)
79
100
{
80
101
        r->y = val;
81
102
        return 0;
82
 
}       
83
 
static int Rect_SetBottom(GAME_Rect* r, short val)
 
103
}
 
104
static int Rect_SetBottom(GAME_Rect* r, int val)
84
105
{
85
106
        r->y = val - r->h;
86
107
        return 0;
87
 
}       
88
 
static int Rect_SetLeft(GAME_Rect* r, short val)
 
108
}
 
109
static int Rect_SetLeft(GAME_Rect* r, int val)
89
110
{
90
111
        r->x = val;
91
112
        return 0;
92
 
}       
93
 
static int Rect_SetRight(GAME_Rect* r, short val)
 
113
}
 
114
static int Rect_SetRight(GAME_Rect* r, int val)
94
115
{
95
116
        r->x = val - r->w;
96
117
        return 0;
97
118
}
98
 
static int Rect_SetWidth(GAME_Rect* r, short val)
 
119
static int Rect_SetWidth(GAME_Rect* r, int val)
99
120
{
100
121
//      r->x -= val - r->w;
101
122
        r->w = val;
102
123
        return 0;
103
124
}
104
 
static int Rect_SetHeight(GAME_Rect* r, short val)
 
125
static int Rect_SetHeight(GAME_Rect* r, int val)
105
126
{
106
127
//      r->y -= val - r->h;
107
128
        r->h = val;
108
129
        return 0;
109
130
}
110
131
 
111
 
PyObject* PyRect_New(GAME_Rect* r)
 
132
PyObject* PyRect_New(SDL_Rect* r)
112
133
{
113
134
        PyRectObject* rect = PyObject_NEW(PyRectObject, &PyRect_Type);
114
135
        if(!rect)
115
136
                return NULL;
116
 
        
 
137
 
117
138
        rect->r.x = r->x;
118
139
        rect->r.y = r->y;
119
140
        rect->r.w = r->w;
122
143
        return (PyObject*)rect;
123
144
}
124
145
 
125
 
PyObject* PyRect_New4(short x, short y, short w, short h)
 
146
PyObject* PyRect_New4(int x, int y, int w, int h)
126
147
{
127
148
        PyRectObject* rect = PyObject_NEW(PyRectObject, &PyRect_Type);
128
149
        if(!rect)
129
150
                return NULL;
130
 
        
 
151
 
131
152
        rect->r.x = x;
132
153
        rect->r.y = y;
133
154
        rect->r.w = w;
134
155
        rect->r.h = h;
135
 
 
136
156
        return (PyObject*)rect;
137
157
}
138
158
 
162
182
        if(!PyArg_ParseTuple(args, ""))
163
183
                return NULL;
164
184
 
165
 
        if((short)self->r.w < 0)
 
185
        if(self->r.w < 0)
166
186
        {
167
187
                self->r.x += self->r.w;
168
188
                self->r.w = -self->r.w;
169
189
        }
170
 
        if((short)self->r.h < 0)
 
190
        if(self->r.h < 0)
171
191
        {
172
192
                self->r.y += self->r.h;
173
193
                self->r.h = -self->r.h;
188
208
static PyObject* rect_move(PyObject* oself, PyObject* args)
189
209
{
190
210
        PyRectObject* self = (PyRectObject*)oself;
191
 
        short x, y;
 
211
        int x, y;
192
212
 
193
 
        if(!TwoShortsFromObj(args, &x, &y))
 
213
        if(!TwoIntsFromObj(args, &x, &y))
194
214
                return RAISE(PyExc_TypeError, "argument must contain two numbers");
195
215
 
196
 
        return PyRect_New4((short)(self->r.x+x), (short)(self->r.y+y), self->r.w, self->r.h);
 
216
        return PyRect_New4(self->r.x+x, self->r.y+y, self->r.w, self->r.h);
197
217
}
198
218
 
199
219
    /*DOC*/ static char doc_move_ip[] =
206
226
static PyObject* rect_move_ip(PyObject* oself, PyObject* args)
207
227
{
208
228
        PyRectObject* self = (PyRectObject*)oself;
209
 
        short x, y;
 
229
        int x, y;
210
230
 
211
 
        if(!TwoShortsFromObj(args, &x, &y))
 
231
        if(!TwoIntsFromObj(args, &x, &y))
212
232
                return RAISE(PyExc_TypeError, "argument must contain two numbers");
213
233
 
214
234
        self->r.x += x;
231
251
static PyObject* rect_inflate(PyObject* oself, PyObject* args)
232
252
{
233
253
        PyRectObject* self = (PyRectObject*)oself;
234
 
        short x, y;
 
254
        int x, y;
235
255
 
236
 
        if(!TwoShortsFromObj(args, &x, &y))
 
256
        if(!TwoIntsFromObj(args, &x, &y))
237
257
                return RAISE(PyExc_TypeError, "argument must contain two numbers");
238
258
 
239
 
        return PyRect_New4((short)(self->r.x-x/2), (short)(self->r.y-y/2), (short)(self->r.w+x), (short)(self->r.h+y));
 
259
        return PyRect_New4(self->r.x-x/2, self->r.y-y/2, self->r.w+x, self->r.h+y);
240
260
}
241
261
 
242
262
 
252
272
static PyObject* rect_inflate_ip(PyObject* oself, PyObject* args)
253
273
{
254
274
        PyRectObject* self = (PyRectObject*)oself;
255
 
        short x, y;
 
275
        int x, y;
256
276
 
257
 
        if(!TwoShortsFromObj(args, &x, &y))
 
277
        if(!TwoIntsFromObj(args, &x, &y))
258
278
                return RAISE(PyExc_TypeError, "argument must contain two numbers");
259
279
 
260
280
        self->r.x -= x/2;
270
290
    /*DOC*/    "Rect.union(rectstyle) -> Rect\n"
271
291
    /*DOC*/    "makes new rectangle covering both inputs\n"
272
292
    /*DOC*/    "\n"
273
 
    /*DOC*/    "Creates a new Rect to completely cover the\n"
 
293
    /*DOC*/    "Returns a new Rect to completely cover the\n"
274
294
    /*DOC*/    "given input. There may be area inside the new\n"
275
295
    /*DOC*/    "Rect that is not covered by either input.\n"
276
296
    /*DOC*/ ;
279
299
{
280
300
        PyRectObject* self = (PyRectObject*)oself;
281
301
        GAME_Rect *argrect, temp;
282
 
        short x, y, w, h;
 
302
        int x, y, w, h;
283
303
        if(!(argrect = GameRect_FromObject(args, &temp)))
284
304
                return RAISE(PyExc_TypeError, "Argument must be rect style object");
285
 
        
 
305
 
286
306
        x = min(self->r.x, argrect->x);
287
307
        y = min(self->r.y, argrect->y);
288
308
        w = max(self->r.x+self->r.w, argrect->x+argrect->w) - x;
306
326
{
307
327
        PyRectObject* self = (PyRectObject*)oself;
308
328
        GAME_Rect *argrect, temp;
309
 
        short x, y, w, h;
 
329
        int x, y, w, h;
310
330
        if(!(argrect = GameRect_FromObject(args, &temp)))
311
331
                return RAISE(PyExc_TypeError, "Argument must be rect style object");
312
 
        
 
332
 
313
333
        x = min(self->r.x, argrect->x);
314
334
        y = min(self->r.y, argrect->y);
315
335
        w = max(self->r.x+self->r.w, argrect->x+argrect->w) - x;
348
368
        t = self->r.y;
349
369
        r = self->r.x + self->r.w;
350
370
        b = self->r.y + self->r.h;
351
 
 
352
371
        size = PySequence_Length(list); /*warning, size could be -1 on error?*/
353
372
        if(size < 1)
354
 
                return PyRect_New4((short)l, (short)t, (short)(r-l), (short)(b-t));
 
373
                return PyRect_New4(l, t, r-l, b-t);
355
374
 
356
375
        for(loop = 0; loop < size; ++loop)
357
376
        {
362
381
                        Py_XDECREF(obj);
363
382
                        break;
364
383
                }
365
 
                t = min(t, argrect->x);
366
 
                l = min(l, argrect->y);
367
 
                r = max(b, argrect->x+argrect->w);
 
384
                l = min(l, argrect->x);
 
385
                t = min(t, argrect->y);
 
386
                r = max(r, argrect->x+argrect->w);
368
387
                b = max(b, argrect->y+argrect->h);
369
388
                Py_DECREF(obj);
370
389
        }
371
 
 
372
 
        return PyRect_New4((short)l, (short)t, (short)(r-l), (short)(b-t));
 
390
        return PyRect_New4(l, t, r-l, b-t);
373
391
}
374
392
 
375
393
 
377
395
    /*DOC*/    "Rect.unionall_ip(sequence_of_rectstyles) -> None\n"
378
396
    /*DOC*/    "rectangle covering all inputs\n"
379
397
    /*DOC*/    "\n"
380
 
    /*DOC*/    "Returns a new rectangle that completely covers all the\n"
 
398
    /*DOC*/    "Resizes the rectangle to completely cover all the\n"
381
399
    /*DOC*/    "given inputs. There may be area inside the new\n"
382
400
    /*DOC*/    "rectangle that is not covered by the inputs.\n"
383
401
    /*DOC*/ ;
402
420
 
403
421
        size = PySequence_Length(list); /*warning, size could be -1 on error?*/
404
422
        if(size < 1)
405
 
                return PyRect_New4((short)l, (short)t, (short)(r-l), (short)(b-t));
 
423
                return PyRect_New4(l, t, r-l, b-t);
406
424
 
407
425
        for(loop = 0; loop < size; ++loop)
408
426
        {
413
431
                        Py_XDECREF(obj);
414
432
                        break;
415
433
                }
416
 
                t = min(t, argrect->x);
417
 
                l = min(l, argrect->y);
418
 
                r = max(b, argrect->x+argrect->w);
 
434
                l = min(l, argrect->x);
 
435
                t = min(t, argrect->y);
 
436
                r = max(r, argrect->x+argrect->w);
419
437
                b = max(b, argrect->y+argrect->h);
420
438
                Py_DECREF(obj);
421
439
        }
440
458
static PyObject* rect_collidepoint(PyObject* oself, PyObject* args)
441
459
{
442
460
        PyRectObject* self = (PyRectObject*)oself;
443
 
        short x, y;
 
461
        int x, y;
444
462
        int inside;
445
463
 
446
 
        if(!TwoShortsFromObj(args, &x, &y))
 
464
        if(!TwoIntsFromObj(args, &x, &y))
447
465
                return RAISE(PyExc_TypeError, "argument must contain two numbers");
448
466
 
449
 
        inside = x>=self->r.x && x<self->r.x+self->r.w && 
 
467
        inside = x>=self->r.x && x<self->r.x+self->r.w &&
450
468
                                y>=self->r.y && y<self->r.y+self->r.h;
451
469
 
452
470
        return PyInt_FromLong(inside);
504
522
        {
505
523
                obj = PySequence_GetItem(list, loop);
506
524
                if(!obj || !(argrect = GameRect_FromObject(obj, &temp)))
507
 
                {       
 
525
                {
508
526
                        RAISE(PyExc_TypeError, "Argument must be a sequence of rectstyle objects.");
509
527
                        Py_XDECREF(obj);
510
528
                        break;
520
538
        if(loop == size)
521
539
                ret = PyInt_FromLong(-1);
522
540
 
523
 
        return ret;     
 
541
        return ret;
524
542
}
525
543
 
526
544
 
 
545
 
527
546
    /*DOC*/ static char doc_collidelistall[] =
528
 
    /*DOC*/    "Rect.collidelistall(rectstyle list) -> int index\n"
 
547
    /*DOC*/    "Rect.collidelistall(rectstyle list) -> index list\n"
529
548
    /*DOC*/    "find all overlapping rectangles\n"
530
549
    /*DOC*/    "\n"
531
550
    /*DOC*/    "Returns a list of the indexes that contain\n"
558
577
                obj = PySequence_GetItem(list, loop);
559
578
 
560
579
                if(!obj || !(argrect = GameRect_FromObject(obj, &temp)))
561
 
                {       
 
580
                {
562
581
                        Py_XDECREF(obj);
563
582
                        Py_DECREF(ret);
564
583
                        return RAISE(PyExc_TypeError, "Argument must be a sequence of rectstyle objects.");
578
597
                Py_DECREF(obj);
579
598
        }
580
599
 
581
 
        return ret;     
 
600
        return ret;
 
601
}
 
602
 
 
603
 
 
604
    /*DOC*/ static char doc_collidedict[] =
 
605
    /*DOC*/    "Rect.collidedict(dict if rectstyle keys) -> key/value pair\n"
 
606
    /*DOC*/    "find overlapping rectangle in a dictionary\n"
 
607
    /*DOC*/    "\n"
 
608
    /*DOC*/    "Returns the key/value pair of the first rectangle key\n"
 
609
    /*DOC*/    "in the dict that overlaps the base rectangle. Once an\n"
 
610
    /*DOC*/    "overlap is found, this will stop checking the\n"
 
611
    /*DOC*/    "remaining list. If no overlap is found, it will\n"
 
612
    /*DOC*/    "return None.\n"
 
613
    /*DOC*/    "\n"
 
614
    /*DOC*/    "Remember python dictionary keys must be immutable,\n"
 
615
    /*DOC*/    "Rects are not immutable, so they cannot directly be,\n"
 
616
    /*DOC*/    "dictionary keys. You can convert the Rect to a tuple\n"
 
617
    /*DOC*/    "with the tuple() builtin command.\n"
 
618
    /*DOC*/ ;
 
619
 
 
620
static PyObject* rect_collidedict(PyObject* oself, PyObject* args)
 
621
{
 
622
        PyRectObject* self = (PyRectObject*)oself;
 
623
        GAME_Rect *argrect, temp;
 
624
        int loop=0;
 
625
        PyObject* dict, *key, *val;
 
626
        PyObject* ret = NULL;
 
627
 
 
628
        if(!PyArg_ParseTuple(args, "O", &dict))
 
629
                return NULL;
 
630
        if(!PyDict_Check(dict))
 
631
                return RAISE(PyExc_TypeError, "Argument must be a dict with rectstyle keys.");
 
632
 
 
633
        while(PyDict_Next(dict, &loop, &key, &val))
 
634
        {
 
635
                if(!(argrect = GameRect_FromObject(key, &temp)))
 
636
                {
 
637
                        RAISE(PyExc_TypeError, "Argument must be a dict with rectstyle keys.");
 
638
                        break;
 
639
                }
 
640
                if(DoRectsIntersect(&self->r, argrect))
 
641
                {
 
642
                        ret = Py_BuildValue("(OO)", key, val);
 
643
                        break;
 
644
                }
 
645
        }
 
646
 
 
647
        if(!ret)
 
648
        {
 
649
            Py_INCREF(Py_None);
 
650
            ret = Py_None;
 
651
        }
 
652
        return ret;
 
653
}
 
654
 
 
655
 
 
656
    /*DOC*/ static char doc_collidedictall[] =
 
657
    /*DOC*/    "Rect.collidedictall(rectstyle list) -> key/val list\n"
 
658
    /*DOC*/    "find all overlapping rectangles\n"
 
659
    /*DOC*/    "\n"
 
660
    /*DOC*/    "Returns a list of the indexes that contain\n"
 
661
    /*DOC*/    "rectangles overlapping the base rectangle. If no\n"
 
662
    /*DOC*/    "overlap is found, it will return an empty\n"
 
663
    /*DOC*/    "sequence.\n"
 
664
    /*DOC*/    "\n"
 
665
    /*DOC*/    "Remember python dictionary keys must be immutable,\n"
 
666
    /*DOC*/    "Rects are not immutable, so they cannot directly be,\n"
 
667
    /*DOC*/    "dictionary keys. You can convert the Rect to a tuple\n"
 
668
    /*DOC*/    "with the tuple() builtin command.\n"
 
669
    /*DOC*/ ;
 
670
 
 
671
static PyObject* rect_collidedictall(PyObject* oself, PyObject* args)
 
672
{
 
673
        PyRectObject* self = (PyRectObject*)oself;
 
674
        GAME_Rect *argrect, temp;
 
675
        int loop=0;
 
676
        PyObject* dict, *key, *val;
 
677
        PyObject* ret = NULL;
 
678
 
 
679
        if(!PyArg_ParseTuple(args, "O", &dict))
 
680
                return NULL;
 
681
        if(!PyDict_Check(dict))
 
682
                return RAISE(PyExc_TypeError, "Argument must be a dict with rectstyle keys.");
 
683
 
 
684
        ret = PyList_New(0);
 
685
        if(!ret)
 
686
                return NULL;
 
687
 
 
688
        while(PyDict_Next(dict, &loop, &key, &val))
 
689
        {
 
690
                if(!(argrect = GameRect_FromObject(key, &temp)))
 
691
                {
 
692
                        Py_DECREF(ret);
 
693
                        return RAISE(PyExc_TypeError, "Argument must be a dict with rectstyle keys.");
 
694
                }
 
695
 
 
696
                if(DoRectsIntersect(&self->r, argrect))
 
697
                {
 
698
                        PyObject* num = Py_BuildValue("(OO)", key, val);
 
699
                        if(!num)
 
700
                                return NULL;
 
701
                        PyList_Append(ret, num);
 
702
                        Py_DECREF(num);
 
703
                }
 
704
        }
 
705
 
 
706
        return ret;
582
707
}
583
708
 
584
709
 
596
721
static PyObject* rect_clip(PyObject* self, PyObject* args)
597
722
{
598
723
        GAME_Rect *A, *B, temp;
599
 
        short x, y, w, h;
 
724
        int x, y, w, h;
600
725
 
601
726
        A = &((PyRectObject*)self)->r;
602
727
        if(!(B = GameRect_FromObject(args, &temp)))
616
741
                w = (B->x+B->w) - x;
617
742
        else
618
743
                goto nointersect;
619
 
        
 
744
 
620
745
        /* Top */
621
746
        if((A->y >= B->y) && (A->y < (B->y+B->h)))
622
747
                y = A->y;
655
780
        if(!(argrect = GameRect_FromObject(args, &temp)))
656
781
                return RAISE(PyExc_TypeError, "Argument must be rect style object");
657
782
 
658
 
        contained = (self->r.x <= argrect->x) && (self->r.y <= argrect->y) &&
659
 
                    (self->r.x + self->r.w >= argrect->x + argrect->w) &&
660
 
                    (self->r.y + self->r.h >= argrect->y + argrect->h) &&
661
 
                    (self->r.x + self->r.w > argrect->x) &&
662
 
                    (self->r.y + self->r.h > argrect->y);
 
783
        contained = (self->r.x <= argrect->x) && (self->r.y <= argrect->y) &&
 
784
 
 
785
                    (self->r.x + self->r.w >= argrect->x + argrect->w) &&
 
786
 
 
787
                    (self->r.y + self->r.h >= argrect->y + argrect->h) &&
 
788
 
 
789
                    (self->r.x + self->r.w > argrect->x) &&
 
790
 
 
791
                    (self->r.y + self->r.h > argrect->y);
 
792
 
663
793
 
664
794
        return PyInt_FromLong(contained);
665
795
}
679
809
{
680
810
        PyRectObject* self = (PyRectObject*)oself;
681
811
        GAME_Rect *argrect, temp;
682
 
        short x, y;
 
812
        int x, y;
683
813
        if(!(argrect = GameRect_FromObject(args, &temp)))
684
814
                return RAISE(PyExc_TypeError, "Argument must be rect style object");
685
815
 
719
849
{
720
850
        PyRectObject* self = (PyRectObject*)oself;
721
851
        GAME_Rect *argrect, temp;
722
 
        short x, y;
 
852
        int x, y;
723
853
        if(!(argrect = GameRect_FromObject(args, &temp)))
724
854
                return RAISE(PyExc_TypeError, "Argument must be rect style object");
725
855
 
747
877
}
748
878
 
749
879
 
 
880
/* for pickling */
 
881
static PyObject* rect_reduce(PyObject* oself, PyObject* args)
 
882
{
 
883
        PyRectObject* self = (PyRectObject*)oself;
 
884
        return Py_BuildValue("(O(iiii))", oself->ob_type,
 
885
                    (int)self->r.x, (int)self->r.y, (int)self->r.w, (int)self->r.h);
 
886
}
 
887
 
 
888
 
 
889
 
750
890
static struct PyMethodDef rect_methods[] =
751
891
{
752
892
        {"normalize",           (PyCFunction)rect_normalize,    1, doc_normalize},
755
895
        {"clamp_ip",                     (PyCFunction)rect_clamp_ip,              1,        doc_clamp_ip},
756
896
 
757
897
        {"move",                        (PyCFunction)rect_move,                 1, doc_move},
758
 
        {"inflate",                     (PyCFunction)rect_inflate,              1, doc_inflate},                
 
898
        {"inflate",                     (PyCFunction)rect_inflate,              1, doc_inflate},
759
899
        {"union",                       (PyCFunction)rect_union,                1, doc_union},
760
900
        {"unionall",            (PyCFunction)rect_unionall,             1, doc_unionall},
761
901
 
762
902
        {"move_ip",                     (PyCFunction)rect_move_ip,              1, doc_move_ip},
763
 
        {"inflate_ip",          (PyCFunction)rect_inflate_ip,   1, doc_inflate_ip},             
 
903
        {"inflate_ip",          (PyCFunction)rect_inflate_ip,   1, doc_inflate_ip},
764
904
        {"union_ip",            (PyCFunction)rect_union_ip,             1, doc_union_ip},
765
905
        {"unionall_ip",         (PyCFunction)rect_unionall_ip,  1, doc_unionall_ip},
766
906
 
768
908
        {"colliderect",         (PyCFunction)rect_colliderect,  1, doc_colliderect},
769
909
        {"collidelist",         (PyCFunction)rect_collidelist,  1, doc_collidelist},
770
910
        {"collidelistall",      (PyCFunction)rect_collidelistall,1,doc_collidelistall},
 
911
        {"collidedict",         (PyCFunction)rect_collidedict,  1, doc_collidedict},
 
912
        {"collidedictall",      (PyCFunction)rect_collidedictall,1,doc_collidedictall},
771
913
        {"contains",            (PyCFunction)rect_contains,             1, doc_contains},
772
914
/* these are totally unwritten. volunteers? */
773
915
/*      {"cleanup",                     (PyCFunction)rect_cleanup,              1, doc_cleanup}, */
774
916
/*      {"remove",                      (PyCFunction)rect_remove,               1, doc_remove}, */
 
917
 
 
918
        {"__reduce__",          (PyCFunction)rect_reduce, 0, NULL},
 
919
 
775
920
        {NULL,          NULL}
776
921
};
777
922
 
787
932
 
788
933
static PyObject* rect_item(PyRectObject *self, int i)
789
934
{
790
 
        short* data = (short*)&self->r;
 
935
        int* data = (int*)&self->r;
791
936
        if(i<0 || i>3)
792
937
                return RAISE(PyExc_IndexError, "Invalid rect Index");
793
938
 
796
941
 
797
942
static int rect_ass_item(PyRectObject *self, int i, PyObject *v)
798
943
{
799
 
        short val;
800
 
        short* data = (short*)&self->r;
 
944
        int val;
 
945
        int* data = (int*)&self->r;
801
946
        if(i<0 || i>3)
802
947
        {
803
948
                RAISE(PyExc_IndexError, "Invalid rect Index");
804
949
                return -1;
805
950
        }
806
 
        if(!ShortFromObj(v, &val))
 
951
        if(!IntFromObj(v, &val))
807
952
        {
808
953
                RAISE(PyExc_TypeError, "Must assign numeric values");
809
954
                return -1;
810
955
        }
811
 
        data[i] = (short)val;
 
956
        data[i] = val;
812
957
        return 0;
813
958
}
814
959
 
816
961
static PyObject* rect_slice(PyRectObject *self, int ilow, int ihigh)
817
962
{
818
963
        PyObject *list;
819
 
        short* data = (short*)&self->r;
 
964
        int* data = (int*)&self->r;
820
965
        int numitems, loop, l = 4;
821
 
        
 
966
 
822
967
        if (ihigh < 0) ihigh += l;
823
968
        if (ilow  < 0) ilow  += l;
824
969
        if (ilow < 0) ilow = 0;
839
984
 
840
985
static int rect_ass_slice(PyRectObject *self, int ilow, int ihigh, PyObject *v)
841
986
{
842
 
        short* data = (short*)&self->r;
 
987
        int* data = (int*)&self->r;
843
988
        int numitems, loop, l = 4;
844
 
        short val;
845
 
        
 
989
        int val;
 
990
 
846
991
        if(!PySequence_Check(v))
847
992
        {
848
993
                RAISE(PyExc_TypeError, "Assigned slice must be a sequence");
866
1011
 
867
1012
        for(loop = 0; loop < numitems; ++loop)
868
1013
        {
869
 
                if(!ShortFromObjIndex(v, loop, &val)) return -1;
 
1014
                if(!IntFromObjIndex(v, loop, &val)) return -1;
870
1015
                data[loop+ilow] = val;
871
1016
        }
872
1017
 
904
1049
                Py_INCREF(new1);
905
1050
        }
906
1051
        else if((r = GameRect_FromObject(*o1, &temp)))
907
 
                new1 = PyRect_New(r);
 
1052
                new1 = PyRect_New4(r->x, r->y, r->w, r->h);
908
1053
        else
909
1054
                return 1;
910
1055
 
914
1059
                Py_INCREF(new2);
915
1060
        }
916
1061
        else if((r = GameRect_FromObject(*o2, &temp)))
917
 
                new2 = PyRect_New(r);
 
1062
                new2 = PyRect_New4(r->x, r->y, r->w, r->h);
918
1063
        else
919
1064
        {
920
1065
                Py_DECREF(new1);
935
1080
        (binaryfunc)NULL,               /*divmod*/
936
1081
        (ternaryfunc)NULL,              /*power*/
937
1082
        (unaryfunc)NULL,                /*negative*/
938
 
        (unaryfunc)NULL,                /*pos*/ 
 
1083
        (unaryfunc)NULL,                /*pos*/
939
1084
        (unaryfunc)NULL,                /*abs*/
940
1085
        (inquiry)rect_nonzero,  /*nonzero*/
941
1086
        (unaryfunc)NULL,                /*invert*/
962
1107
 
963
1108
static PyObject *rect_repr(PyRectObject *self)
964
1109
{
965
 
        char string[256];       
966
 
        sprintf(string, "<rect(%d, %d, %d, %d)>", self->r.x, self->r.y, self->r.w, self->r.h);  
 
1110
        char string[256];
 
1111
        sprintf(string, "<rect(%d, %d, %d, %d)>", self->r.x, self->r.y, self->r.w, self->r.h);
967
1112
        return PyString_FromString(string);
968
1113
}
969
1114
 
1002
1147
{
1003
1148
        PyObject *ret = NULL;
1004
1149
        GAME_Rect *r = &self->r;
1005
 
        
1006
 
        if(!strcmp(name, "top"))
 
1150
 
 
1151
        if(!strcmp(name, "top") || !strcmp(name, "y"))
1007
1152
                ret = PyInt_FromLong(r->y);
1008
1153
        else if(!strcmp(name, "bottom"))
1009
1154
                ret = PyInt_FromLong(r->y + r->h);
1010
 
        else if(!strcmp(name, "left"))
 
1155
        else if(!strcmp(name, "left") || !strcmp(name, "x"))
1011
1156
                ret = PyInt_FromLong(r->x);
1012
1157
        else if(!strcmp(name, "right"))
1013
1158
                ret = PyInt_FromLong(r->x + r->w);
1014
 
        else if(!strcmp(name, "width"))
 
1159
        else if(!strcmp(name, "width") || !strcmp(name, "w"))
1015
1160
                ret = PyInt_FromLong(r->w);
1016
 
        else if(!strcmp(name, "height"))
 
1161
        else if(!strcmp(name, "height") || !strcmp(name, "h"))
1017
1162
                ret = PyInt_FromLong(r->h);
1018
1163
        else if(!strcmp(name, "centerx"))
1019
1164
                ret = PyInt_FromLong(r->x+r->w/2);
1041
1186
                ret = Py_BuildValue("(ii)", r->x + r->w / 2, r->y);
1042
1187
        else if(!strcmp(name, "midbottom"))
1043
1188
                ret = Py_BuildValue("(ii)", r->x + r->w / 2, r->y + r->h);
1044
 
        
 
1189
 
 
1190
        else if(!strcmp(name, "__safe_for_unpickling__"))
 
1191
                ret = PyInt_FromLong(1);
1045
1192
        else
1046
1193
                ret = Py_FindMethod(rect_methods, (PyObject *)self, name);
1047
1194
 
1051
1198
static int rect_setattr(PyRectObject *self, char *name, PyObject *op)
1052
1199
{
1053
1200
        int ret = -1;
1054
 
        short val1, val2;
 
1201
        int val1, val2;
1055
1202
        GAME_Rect *r = &self->r;
1056
 
        
1057
 
        if(!strcmp(name, "top"))
 
1203
 
 
1204
        if(!strcmp(name, "top") || !strcmp(name, "y"))
1058
1205
        {
1059
 
                if(ShortFromObj(op, &val1))
 
1206
                if(IntFromObj(op, &val1))
1060
1207
                        ret = Rect_SetTop(r, val1);
1061
 
        }       
 
1208
        }
1062
1209
        else if(!strcmp(name, "bottom"))
1063
1210
        {
1064
 
                if(ShortFromObj(op, &val1))
 
1211
                if(IntFromObj(op, &val1))
1065
1212
                        ret = Rect_SetBottom(r, val1);
1066
 
        }       
1067
 
        else if(!strcmp(name, "left"))
 
1213
        }
 
1214
        else if(!strcmp(name, "left") || !strcmp(name, "x"))
1068
1215
        {
1069
 
                if(ShortFromObj(op, &val1))
 
1216
                if(IntFromObj(op, &val1))
1070
1217
                        ret = Rect_SetLeft(r, val1);
1071
 
        }       
 
1218
        }
1072
1219
        else if(!strcmp(name, "right"))
1073
1220
        {
1074
 
                if(ShortFromObj(op, &val1))
 
1221
                if(IntFromObj(op, &val1))
1075
1222
                        ret = Rect_SetRight(r, val1);
1076
 
        }       
1077
 
        else if(!strcmp(name, "width"))
 
1223
        }
 
1224
        else if(!strcmp(name, "width") || !strcmp(name, "w"))
1078
1225
        {
1079
 
                if(ShortFromObj(op, &val1))
 
1226
                if(IntFromObj(op, &val1))
1080
1227
                        ret = Rect_SetWidth(r, val1);
1081
 
        }       
1082
 
        else if(!strcmp(name, "height"))
 
1228
        }
 
1229
        else if(!strcmp(name, "height") || !strcmp(name, "h"))
1083
1230
        {
1084
 
                if(ShortFromObj(op, &val1))
 
1231
                if(IntFromObj(op, &val1))
1085
1232
                        ret = Rect_SetHeight(r, val1);
1086
 
        }       
 
1233
        }
1087
1234
        else if(!strcmp(name, "topleft"))
1088
1235
        {
1089
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1236
                if(TwoIntsFromObj(op, &val1, &val2))
1090
1237
                {
1091
1238
                        Rect_SetLeft(r, val1);
1092
1239
                        ret = Rect_SetTop(r, val2);
1093
1240
                }
1094
 
        }       
 
1241
        }
1095
1242
        else if(!strcmp(name, "bottomleft"))
1096
1243
        {
1097
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1244
                if(TwoIntsFromObj(op, &val1, &val2))
1098
1245
                {
1099
1246
                        Rect_SetLeft(r, val1);
1100
1247
                        ret = Rect_SetBottom(r, val2);
1101
1248
                }
1102
 
        }       
 
1249
        }
1103
1250
        else if(!strcmp(name, "topright"))
1104
1251
        {
1105
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1252
                if(TwoIntsFromObj(op, &val1, &val2))
1106
1253
                {
1107
1254
                        Rect_SetRight(r, val1);
1108
1255
                        ret = Rect_SetTop(r, val2);
1109
1256
                }
1110
 
        }       
 
1257
        }
1111
1258
        else if(!strcmp(name, "bottomright"))
1112
1259
        {
1113
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1260
                if(TwoIntsFromObj(op, &val1, &val2))
1114
1261
                {
1115
1262
                        Rect_SetRight(r, val1);
1116
1263
                        ret = Rect_SetBottom(r, val2);
1117
1264
                }
1118
 
        }       
 
1265
        }
1119
1266
        else if(!strcmp(name, "size"))
1120
1267
        {
1121
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1268
                if(TwoIntsFromObj(op, &val1, &val2))
1122
1269
                {
1123
1270
                        Rect_SetWidth(r, val1);
1124
1271
                        ret = Rect_SetHeight(r, val2);
1125
1272
                }
1126
 
        }       
 
1273
        }
1127
1274
        else if(!strcmp(name, "center"))
1128
1275
        {
1129
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1276
                if(TwoIntsFromObj(op, &val1, &val2))
1130
1277
                {
1131
1278
                        r->x += val1 - (r->x + r->w / 2);
1132
1279
                        r->y += val2 - (r->y + r->h / 2);
1135
1282
        }
1136
1283
        else if(!strcmp(name, "centerx"))
1137
1284
        {
1138
 
                if(ShortFromObj(op, &val1))
 
1285
                if(IntFromObj(op, &val1))
1139
1286
                {
1140
1287
                        r->x += val1 - (r->x + r->w / 2);
1141
1288
                        ret = 0;
1143
1290
        }
1144
1291
        else if(!strcmp(name, "centery"))
1145
1292
        {
1146
 
                if(ShortFromObj(op, &val1))
 
1293
                if(IntFromObj(op, &val1))
1147
1294
                {
1148
1295
                        r->y += val1 - (r->y + r->h / 2);
1149
1296
                        ret = 0;
1152
1299
 
1153
1300
        else if(!strcmp(name, "midleft"))
1154
1301
        {
1155
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1302
                if(TwoIntsFromObj(op, &val1, &val2))
1156
1303
                {
1157
1304
                        r->x = val1;
1158
1305
                        r->y += val2 - (r->y + r->h / 2);
1161
1308
        }
1162
1309
        else if(!strcmp(name, "midright"))
1163
1310
        {
1164
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1311
                if(TwoIntsFromObj(op, &val1, &val2))
1165
1312
                {
1166
1313
                        r->x = val1 - r->w;
1167
1314
                        r->y += val2 - (r->y + r->h / 2);
1170
1317
        }
1171
1318
        else if(!strcmp(name, "midtop"))
1172
1319
        {
1173
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1320
                if(TwoIntsFromObj(op, &val1, &val2))
1174
1321
                {
1175
1322
                        r->x += val1 - (r->x + r->w / 2);
1176
1323
                        r->y = val2;
1179
1326
        }
1180
1327
        else if(!strcmp(name, "midbottom"))
1181
1328
        {
1182
 
                if(TwoShortsFromObj(op, &val1, &val2))
 
1329
                if(TwoIntsFromObj(op, &val1, &val2))
1183
1330
                {
1184
1331
                        r->x += val1 - (r->x + r->w / 2);
1185
1332
                        r->y = val2 - r->h;
1186
1333
                        ret = 0;
1187
1334
                }
1188
1335
        }
1189
 
        
1190
 
        else    
 
1336
 
 
1337
        else
1191
1338
        {
1192
1339
                RAISE(PyExc_AttributeError, "Attribute cannot be modified");
1193
1340
                return -1;
1203
1350
    /*DOC*/ static char doc_Rect_MODULE[] =
1204
1351
    /*DOC*/    "The rectangle object is a useful object\n"
1205
1352
    /*DOC*/    "representing a rectangle area. Rectangles are\n"
1206
 
        /*DOC*/    "created from the pygame.Rect() function. This routine\n"
1207
 
        /*DOC*/    "is also in the locals module, so importing the locals\n"
1208
 
        /*DOC*/    "into your namespace allows you to just use Rect().\n"
 
1353
    /*DOC*/    "created from the pygame.Rect() function. This routine\n"
 
1354
    /*DOC*/    "is also in the locals module, so importing the locals\n"
 
1355
    /*DOC*/    "into your namespace allows you to just use Rect().\n"
1209
1356
    /*DOC*/    "\n"
1210
1357
    /*DOC*/    "Rect contains helpful methods, as well as a list of\n"
1211
1358
    /*DOC*/    "modifiable members:\n"
1212
 
    /*DOC*/    "top, bottom, left, right, topleft, topright,\n"
1213
 
    /*DOC*/    "bottomleft, bottomright, size, width, height,\n"
1214
 
    /*DOC*/    "center, centerx, centery, midleft, midright, midtop,\n"
1215
 
        /*DOC*/    "midbottom. When changing thesemembers, the rectangle\n"
 
1359
#if 1
 
1360
  /*NODOC*/    "top, bottom, left, right, topleft, topright,\n"
 
1361
  /*NODOC*/    "bottomleft, bottomright, size, width, height,\n"
 
1362
  /*NODOC*/    "center, centerx, centery, midleft, midright, midtop,\n"
 
1363
  /*NODOC*/    "midbottom.\n"
 
1364
#else
 
1365
    /*DOC*/    "<table border="0" cellspacing=0 cellpadding=0 width=66%><tr valign=top><td align=left><ul><li>top<li>bottom<li>left<li>right</ul></td>\n"
 
1366
    /*DOC*/    "<td align=left><ul><li>topleft<li>topright<li>bottomleft<li>bottomright</ul></td>\n"
 
1367
    /*DOC*/    "<td align=left><ul><li>midleft<li>midright<li>midtop<li>midbottom</ul></td>\n"
 
1368
    /*DOC*/    "<td align=left><ul><li>center<li>centerx<li>centery</ul></td>\n"
 
1369
    /*DOC*/    "<td align=left><ul><li>size<li>width<li>height</ul></td>\n"
 
1370
    /*DOC*/    "</tr></table><br>\n"
 
1371
#endif
 
1372
    /*DOC*/    "When changing these members, the rectangle\n"
1216
1373
    /*DOC*/    "will be moved to the given assignment. (except when\n"
1217
1374
    /*DOC*/    "changing the size, width, or height member, which will\n"
1218
1375
    /*DOC*/    "resize the rectangle from the topleft corner)\n"
1219
1376
    /*DOC*/    "\n"
1220
1377
    /*DOC*/    "The rectstyle arguments used frequently with the\n"
1221
1378
    /*DOC*/    "Rect object (and elsewhere in pygame) is one of\n"
1222
 
    /*DOC*/    "the following things. First, an actual Rect\n"
1223
 
    /*DOC*/    "object. Second, a sequence of [xpos, ypos, width,\n"
1224
 
    /*DOC*/    "height]. Lastly, a pair of sequences, representing\n"
1225
 
    /*DOC*/    "the position and size [[xpos, ypos], [width,\n"
1226
 
    /*DOC*/    "height]]. Also, if a method takes a rectstyle\n"
1227
 
    /*DOC*/    "argument as its only argument, you can simply pass\n"
1228
 
    /*DOC*/    "four arguments representing xpos, ypos, width,\n"
1229
 
    /*DOC*/    "height.\n"
 
1379
    /*DOC*/    "the following things.\n"
 
1380
#if 1
 
1381
  /*NODOC*/    "First, an actual Rect\n"
 
1382
  /*NODOC*/    "object. Second, a sequence of [xpos, ypos, width,\n"
 
1383
  /*NODOC*/    "height]. Lastly, a pair of sequences, representing\n"
 
1384
  /*NODOC*/    "the position and size [[xpos, ypos], [width,\n"
 
1385
  /*NODOC*/    "height]]. Also, if a method takes a rectstyle\n"
 
1386
  /*NODOC*/    "argument as its only argument, you can simply pass\n"
 
1387
  /*NODOC*/    "four arguments representing xpos, ypos, width,\n"
 
1388
  /*NODOC*/    "height. A rectstyle argument can also be _any_ python\n"
 
1389
  /*NODOC*/    "object with an attribute named 'rect'.\n"
 
1390
#else
 
1391
    /*DOC*/    "<table border=0 cellspacing=0 cellpadding=0 width=80%>\n"
 
1392
    /*DOC*/    "<tr align=left valign=top><td align=left valign=middle width=20%><blockquote> </blockquote></td><td align=left valign=top><ul>\n"
 
1393
    /*DOC*/    "<li>an actual Rect object. \n"
 
1394
    /*DOC*/    "<li>a sequence of [xpos, ypos, width, height]. \n"
 
1395
    /*DOC*/    "<li>a pair of sequences, representing the position and size [[xpos, ypos], [width,height]]. \n"
 
1396
    /*DOC*/    "<li>if a method takes a rectstyle argument <b>as its <i>only</i> argument</b>, you can simply pass four arguments representing xpos, ypos, width, height. \n"
 
1397
    /*DOC*/    "</ul>and perhaps most importantly:\n"
 
1398
    /*DOC*/    "<ul><li>A rectstyle argument can also be <b><strong>_any_ python object</b> with an attribute named <b>'rect'.</b></strong>\n"
 
1399
    /*DOC*/    "</ul></td></tr></table>\n"
 
1400
#endif
1230
1401
    /*DOC*/ ;
1231
1402
 
1232
 
static PyTypeObject PyRect_Type = { 
 
1403
static PyTypeObject PyRect_Type = {
1233
1404
        PyObject_HEAD_INIT(0)
1234
1405
        0,                                                      /*size*/
1235
1406
        "Rect",                                         /*name*/
1250
1421
        (reprfunc)rect_str,                     /*str*/
1251
1422
 
1252
1423
        /* Space for future expansion */
1253
 
        0L,0L,0L,0L,
1254
 
        doc_Rect_MODULE /* Documentation string */
 
1424
        0L,0L,0L,
 
1425
#if PYTHON_API_VERSION >= 1011 /*PYTHON2.2*/
 
1426
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES | Py_TPFLAGS_BASETYPE, /* tp_flags */
 
1427
#else
 
1428
        0,                                      /* tp_flags */
 
1429
#endif
 
1430
        doc_Rect_MODULE,    /* Documentation string */
 
1431
#if PYTHON_API_VERSION >= 1011 /*PYTHON2.2*/
 
1432
        0,                                      /* tp_traverse */
 
1433
        0,                                      /* tp_clear */
 
1434
        0,                                      /* tp_richcompare */
 
1435
        0,                                      /* tp_weaklistoffset */
 
1436
        0,                                      /* tp_iter */
 
1437
        0,                                      /* tp_iternext */
 
1438
        0,                                      /* tp_methods */
 
1439
        0,                                      /* tp_members */
 
1440
        0,                                      /* tp_getset */
 
1441
        0,                                      /* tp_base */
 
1442
        0,                                      /* tp_dict */
 
1443
        0,                                      /* tp_descr_get */
 
1444
        0,                                      /* tp_descr_set */
 
1445
        0,                                      /* tp_dictoffset */
 
1446
        0,                                      /* tp_init */
 
1447
        0,                                      /* tp_alloc */
 
1448
        rect_new,                       /* tp_new */
 
1449
#endif
1255
1450
};
1256
1451
 
1257
1452
 
1285
1480
}
1286
1481
 
1287
1482
 
 
1483
#if PYTHON_API_VERSION >= 1011 /*this is the python-2.2 constructor*/
 
1484
static PyObject* rect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 
1485
{
 
1486
        GAME_Rect *argrect, temp;
 
1487
        if(!(argrect = GameRect_FromObject(args, &temp)))
 
1488
                return RAISE(PyExc_TypeError, "Argument must be rect style object");
 
1489
 
 
1490
        return PyRect_New4(argrect->x, argrect->y, argrect->w, argrect->h);
 
1491
}
 
1492
#endif
 
1493
 
1288
1494
 
1289
1495
static PyMethodDef rect__builtins__[] =
1290
1496
{
1291
 
        { "Rect", RectInit, 1, doc_Rect }, 
 
1497
#if PYTHON_API_VERSION < 1011 /*PYTHON2.2*/
 
1498
        { "Rect", RectInit, 1, doc_Rect },
 
1499
#endif
1292
1500
        {NULL, NULL}
1293
1501
};
1294
1502
 
1303
1511
{
1304
1512
        PyObject *module, *dict, *apiobj;
1305
1513
        static void* c_api[PYGAMEAPI_RECT_NUMSLOTS];
1306
 
        
1307
 
        PyGAME_C_API[0] = PyGAME_C_API[0]; /*this cleans a compiler warning*/
1308
1514
 
1309
1515
        /* Create the module and add the functions */
1310
1516
        PyType_Init(PyRect_Type);
1314
1520
        dict = PyModule_GetDict(module);
1315
1521
 
1316
1522
        PyDict_SetItemString(dict, "RectType", (PyObject *)&PyRect_Type);
 
1523
#if PYTHON_API_VERSION >= 1011 /*this is the python-2.2 constructor*/
 
1524
        PyDict_SetItemString(dict, "Rect", (PyObject *)&PyRect_Type);
 
1525
#endif
1317
1526
 
1318
1527
        /* export the c api */
1319
1528
        c_api[0] = &PyRect_Type;