recurfaces


Namerecurfaces JSON
Version 0.3.2 PyPI version JSON
download
home_pagehttps://github.com/immijimmi/recurfaces
SummaryA pygame framework used to organise Surfaces into a chain structure
upload_time2021-08-15 04:55:58
maintainer
docs_urlNone
authorimmijimmi
requires_python
licenseLGPLv3
keywords ui gui graphical user interface game
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # recurfaces

###### A pygame framework used to organise Surfaces into a chain structure

## Quickstart

Below is an example of recurfaces being used in a basic game loop.
The screen will display a red square on a white background, movable by tapping the arrow keys.

```python
import pygame
from recurfaces import Recurface


# pygame setup
pygame.init()
window = pygame.display.set_mode((800, 600))
clock = pygame.time.Clock()

# Creating some recurfaces to display
bg_surface = pygame.Surface((800, 600))
bg_surface.fill("#FFFFFF")
scene = Recurface(bg_surface, position=(0, 0))  # This will be the top-level recurface

red_square_surface = pygame.Surface((64, 64))
red_square_surface.fill("#FF0000")
red_square = Recurface(red_square_surface, position=(100, 100))

scene.add_child(red_square)

# Game loop
move = [0, 0]
while True:
    clock.tick(60)

    # Moving the red square based on input
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                move[1] -= 1
            elif event.key == pygame.K_DOWN:
                move[1] += 1
            elif event.key == pygame.K_LEFT:
                move[0] -= 1
            elif event.key == pygame.K_RIGHT:
                move[0] += 1

    red_square.x += move[0]
    red_square.y += move[1]
    move = [0, 0]

    # Rendering the updated recurfaces
    updated_rects = scene.render(window)
    pygame.display.update(updated_rects)
```

## Functionality

### Properties

Recurface.**surface**  
    Returns a reference to the recurface's stored surface.  
    This surface does not get altered by Recurface - a working copy of it is made on each render.  
 

Recurface.**position**  
    Returns a tuple of the surface's display position within its container.  
    This can be set to `None` in order to stop displaying the surface entirely.  
 

Recurface.**x**, Recurface.**y**  
    These properties access their respective indexes of `.position`.

*Note: If `.position` is currently set to `None`, accessing these will throw a ValueError.*  
 

Recurface.**parent**  
    Returns the container recurface, or `None` if this recurface is top-level.  
    Can be set to a new parent recurface, or `None` to make the current recurface top-level.  
    Equivalent to calling `remove_child()` on the current parent and `add_child()` on the new parent.  
 

Recurface.**children**  
    Returns a frozenset containing all child recurfaces of the accessed recurface. Read-only.

### Methods

Recurface.**add_child**(*self, child: Recurface*)  
    Adds the provided recurface to the current recurface's children.  
    Equivalent to setting `.parent` on the child recurface equal to the current recurface.  
 

Recurface.**remove_child**(*self, child: Recurface*)  
    Removes the provided recurface from the current recurface's children.  
    Equivalent to setting `.parent` on the child recurface equal to `None`.

*Note: This will make the child top-level; It will be garbage collected if there are no references to it elsewhere.*  
 

Recurface.**move**(*self, x_offset: int = 0, y_offset: int = 0*)  
    Adds the provided offset values to the recurface's current position.  
    Returns a tuple representing the updated `.position`.

*Note: If `.position` is currently set to `None`, this will throw a ValueError.*  
 

Recurface.**add_update_rects**(*self, rects: Iterable[Optional[Rect]], update_position: bool = False*)  
    Stores the provided pygame rects to be returned by this recurface on the next `render()` call.  
    Used internally to handle removing child objects.  
    If `update_position` is `True`, the provided rects will be offset by the position of `.__rect` before storing.  
 

Recurface.**render**(*self, destination: Surface*)  
    Draws all child surfaces to a copy of `.surface`, then draws the copy to the provided destination.  
    Returns a list of pygame rects representing updated areas of the provided destination.

*Note: This function should be called on top-level (parent-less) recurfaces once per game tick, and `pygame.display.update()` should be passed all returned rects.*  
 

Recurface.**unlink**(*self*)  
    Detaches the recurface from its parent and children.  
    If there is a parent recurface, all children are added to the parent.  
    This effectively removes the recurface from its place in the chain without leaving the chain broken.  
 
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/immijimmi/recurfaces",
    "name": "recurfaces",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "ui,gui,graphical,user,interface,game",
    "author": "immijimmi",
    "author_email": "imranhamid99@msn.com",
    "download_url": "https://files.pythonhosted.org/packages/d0/1b/c1386e6f2128263c91e421319ad3db3ac11bee63c6eb4f47ee4e4dd9fde1/recurfaces-0.3.2.tar.gz",
    "platform": "",
    "description": "# recurfaces\n\n###### A pygame framework used to organise Surfaces into a chain structure\n\n## Quickstart\n\nBelow is an example of recurfaces being used in a basic game loop.\nThe screen will display a red square on a white background, movable by tapping the arrow keys.\n\n```python\nimport pygame\nfrom recurfaces import Recurface\n\n\n# pygame setup\npygame.init()\nwindow = pygame.display.set_mode((800, 600))\nclock = pygame.time.Clock()\n\n# Creating some recurfaces to display\nbg_surface = pygame.Surface((800, 600))\nbg_surface.fill(\"#FFFFFF\")\nscene = Recurface(bg_surface, position=(0, 0))  # This will be the top-level recurface\n\nred_square_surface = pygame.Surface((64, 64))\nred_square_surface.fill(\"#FF0000\")\nred_square = Recurface(red_square_surface, position=(100, 100))\n\nscene.add_child(red_square)\n\n# Game loop\nmove = [0, 0]\nwhile True:\n    clock.tick(60)\n\n    # Moving the red square based on input\n    for event in pygame.event.get():\n        if event.type == pygame.KEYDOWN:\n            if event.key == pygame.K_UP:\n                move[1] -= 1\n            elif event.key == pygame.K_DOWN:\n                move[1] += 1\n            elif event.key == pygame.K_LEFT:\n                move[0] -= 1\n            elif event.key == pygame.K_RIGHT:\n                move[0] += 1\n\n    red_square.x += move[0]\n    red_square.y += move[1]\n    move = [0, 0]\n\n    # Rendering the updated recurfaces\n    updated_rects = scene.render(window)\n    pygame.display.update(updated_rects)\n```\n\n## Functionality\n\n### Properties\n\nRecurface.**surface**  \n    Returns a reference to the recurface's stored surface.  \n    This surface does not get altered by Recurface - a working copy of it is made on each render.  \n \n\nRecurface.**position**  \n    Returns a tuple of the surface's display position within its container.  \n    This can be set to `None` in order to stop displaying the surface entirely.  \n \n\nRecurface.**x**, Recurface.**y**  \n    These properties access their respective indexes of `.position`.\n\n*Note: If `.position` is currently set to `None`, accessing these will throw a ValueError.*  \n \n\nRecurface.**parent**  \n    Returns the container recurface, or `None` if this recurface is top-level.  \n    Can be set to a new parent recurface, or `None` to make the current recurface top-level.  \n    Equivalent to calling `remove_child()` on the current parent and `add_child()` on the new parent.  \n \n\nRecurface.**children**  \n    Returns a frozenset containing all child recurfaces of the accessed recurface. Read-only.\n\n### Methods\n\nRecurface.**add_child**(*self, child: Recurface*)  \n    Adds the provided recurface to the current recurface's children.  \n    Equivalent to setting `.parent` on the child recurface equal to the current recurface.  \n \n\nRecurface.**remove_child**(*self, child: Recurface*)  \n    Removes the provided recurface from the current recurface's children.  \n    Equivalent to setting `.parent` on the child recurface equal to `None`.\n\n*Note: This will make the child top-level; It will be garbage collected if there are no references to it elsewhere.*  \n \n\nRecurface.**move**(*self, x_offset: int = 0, y_offset: int = 0*)  \n    Adds the provided offset values to the recurface's current position.  \n    Returns a tuple representing the updated `.position`.\n\n*Note: If `.position` is currently set to `None`, this will throw a ValueError.*  \n \n\nRecurface.**add_update_rects**(*self, rects: Iterable[Optional[Rect]], update_position: bool = False*)  \n    Stores the provided pygame rects to be returned by this recurface on the next `render()` call.  \n    Used internally to handle removing child objects.  \n    If `update_position` is `True`, the provided rects will be offset by the position of `.__rect` before storing.  \n \n\nRecurface.**render**(*self, destination: Surface*)  \n    Draws all child surfaces to a copy of `.surface`, then draws the copy to the provided destination.  \n    Returns a list of pygame rects representing updated areas of the provided destination.\n\n*Note: This function should be called on top-level (parent-less) recurfaces once per game tick, and `pygame.display.update()` should be passed all returned rects.*  \n \n\nRecurface.**unlink**(*self*)  \n    Detaches the recurface from its parent and children.  \n    If there is a parent recurface, all children are added to the parent.  \n    This effectively removes the recurface from its place in the chain without leaving the chain broken.  \n ",
    "bugtrack_url": null,
    "license": "LGPLv3",
    "summary": "A pygame framework used to organise Surfaces into a chain structure",
    "version": "0.3.2",
    "split_keywords": [
        "ui",
        "gui",
        "graphical",
        "user",
        "interface",
        "game"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "811ab881fe9b2e97297f8fcda9956fb9",
                "sha256": "9ba26af0f878f64d31dff0ba75acc493fa53ebc1a878ab6f236b232753a18a46"
            },
            "downloads": -1,
            "filename": "recurfaces-0.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "811ab881fe9b2e97297f8fcda9956fb9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8342,
            "upload_time": "2021-08-15T04:55:58",
            "upload_time_iso_8601": "2021-08-15T04:55:58.236062Z",
            "url": "https://files.pythonhosted.org/packages/d0/1b/c1386e6f2128263c91e421319ad3db3ac11bee63c6eb4f47ee4e4dd9fde1/recurfaces-0.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-08-15 04:55:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "immijimmi",
    "github_project": "recurfaces",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "recurfaces"
}
        
Elapsed time: 0.26881s