##### pygame documentation

Pygame Home || Help Contents || Reference Index

Most useful stuff: Color | display | draw | event | font | image | key | locals | mixer | mouse | Rect | Surface | time | music | pygame

Advanced stuff: cursors | joystick | mask | sprite | transform | BufferProxy | freetype | gfxdraw | midi | Overlay | PixelArray | pixelcopy | sndarray | surfarray | math

Other: camera | cdrom | examples | scrap | tests | touch | version

## src_c/rect.c

This extension module defines Python type `pygame.Rect` pygame object for storing rectangular coordinates.

Header file: src_c/pygame.h

`GAME_Rect`
  int `x`

    Horizontal position of the top-left corner.

  int `y`

    Vertical position of the top-left corner.

  int `w`

    Width.

  int `h`

    Height.

  A rectangle at (x, y) and of size (w, h).

  SDL 2: equivalent to SDL_Rect.

`pgRectObject`
  GAME_Rect `r`

  The Pygame rectangle type instance.

PyTypeObject *`pgRect_Type`

  The Pygame rectangle object type pygame.Rect.

GAME_Rect `pgRect_AsRect`(PyObject *obj)

  A macro to access the GAME_Rect field of a `pygame.Rect` instance.

PyObject* `pgRect_New`(SDL_Rect *r)

  Return a new `pygame.Rect` instance from the SDL_Rect r. On failure, raise a Python exception and return NULL.

PyObject* `pgRect_New4`(int x, int y, int w, int h)

  Return a new pygame.Rect instance with position (x, y) and size (w, h). On failure raise a Python exception and return NULL.

GAME_Rect* `pgRect_FromObject`(PyObject *obj, GAME_Rect *temp)

  Translate a Python rectangle representation as a Pygame `GAME_Rect`. A rectangle can be a length 4 sequence integers (x, y, w, h), or a length 2 sequence of position (x, y) and size (w, h), or a length 1 tuple containing a rectangle representation, or have a method rect that returns a rectangle. Pass a pointer to a locally declared c:type:GAME_Rect as temp. Do not rely on this being filled in; use the function's return value instead. On success return a pointer to a `GAME_Rect` representation of the rectangle. One failure may raise a Python exception before returning NULL.

Edit on GitHub