From e5951abb21cf8b8bb0af91486b974b325a14a49e Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Fri, 5 Jan 2024 22:43:49 +0100 Subject: [PATCH] Added crop_surface() function. --- pg.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pg.py b/pg.py index 8cad092..7b44f88 100644 --- a/pg.py +++ b/pg.py @@ -4,6 +4,7 @@ import pygame from tools import text from typing import Union, Callable + pygame.init() log = text.Log() @@ -225,6 +226,18 @@ def set_rot_point(img, pos): return img2, (w, h) +def crop_surface(surface: pygame.Surface, position: tuple, size: tuple): + new_surface = pygame.Surface(size, flags=pygame.SRCALPHA) + + x, y = position + x = -x + y = -y + + new_surface.blit(surface, (x, y)) + + return new_surface + + def bt_from_ca(ca, function): # bt_from_ca = button from collide able return Button(function, ca)