Add a corner pin transform to a pyglet window
Find a file
2024-11-08 18:14:14 +01:00
examples Place pins arbitrarily (not just image corners) 2024-11-08 18:14:14 +01:00
pyglet_cornerpin Place pins arbitrarily (not just image corners) 2024-11-08 18:14:14 +01:00
poetry.lock Initial version 2024-10-23 16:39:16 +02:00
pyproject.toml update version 2024-11-05 18:35:41 +01:00
README.md describe keyboard controls 2024-11-05 18:35:03 +01:00

Pyglet CornerPin

This is a little utility that adds corner pin transforms to a pyglet window.

Installation

pip install pyglet-cornerpin

Usage

Create instance for a window, and register the event handlers for dragging the pins. A on_key_release is also registered to handle keyboard controls to move the pins.


pins = PygletCornerPin(window)
# event handlers for dragging:
window.push_handlers(pins)

Then you can draw the pins in your on_draw() event.

@window.event
def on_draw():
    window.clear()
    ...
    # draw corner pins
    pins.draw()

Optionally you can provide initial positions for the pins.

corners = [
    (0, 0),                        # Bottom left
    (window.width),                # Bottom right
    (0, window.height),            # Top left
    (window.width, window.height), # Top right
]
pins = PygletCornerPin(window, corners)

Run pattern.py in the examples folder for a demo.

To use the keyboard, select a pin with number keys 1-4, the use the arrow keys (optionally with ctrl/shift modifier) to move the handle.