|
1
|
|
|
""" |
|
2
|
|
|
* PyDMXControl: A Python 3 module to control DMX using uDMX. |
|
3
|
|
|
* Featuring fixture profiles, built-in effects and a web control panel. |
|
4
|
|
|
* <https://github.com/MattIPv4/PyDMXControl/> |
|
5
|
|
|
* Copyright (C) 2018 Matt Cowley (MattIPv4) ([email protected]) |
|
6
|
|
|
""" |
|
7
|
|
|
|
|
8
|
|
|
from math import floor |
|
9
|
|
|
from typing import Union, List, Tuple |
|
10
|
|
|
|
|
11
|
|
|
import pygame |
|
12
|
|
|
|
|
13
|
|
|
from ._Part import Part |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class Rect(Part): |
|
17
|
|
|
|
|
18
|
|
|
def __init__(self, width: Union[int, float], height: Union[int, float], x: Union[int, float], y: Union[int, float], |
|
19
|
|
|
*, outline_color: Union[List[int], Tuple[int]] = (255, 0, 0), |
|
20
|
|
|
fill_color: Union[List[int], Tuple[int]] = (255, 255, 255, 0), ): |
|
21
|
|
|
super().__init__() |
|
22
|
|
|
self.__width = width |
|
23
|
|
|
self.__height = height |
|
24
|
|
|
self.__outline = outline_color |
|
25
|
|
|
self.__fill = fill_color |
|
26
|
|
|
self.set_pos(x, y) |
|
27
|
|
|
|
|
28
|
|
|
def design_render(self, screen: 'Screen') -> Tuple[int, int, pygame.Surface]: |
|
29
|
|
|
# Create the surface |
|
30
|
|
|
width = int(self.__width * screen.block_size) |
|
31
|
|
|
height = int(self.__height * screen.block_size) |
|
32
|
|
|
surface = pygame.Surface((width, height), pygame.SRCALPHA, 32) |
|
33
|
|
|
surface = surface.convert_alpha() |
|
34
|
|
|
|
|
35
|
|
|
# Draw the rect |
|
36
|
|
|
rect = pygame.Rect(0, 0, width, height) |
|
37
|
|
|
pygame.draw.rect(surface, self.__fill, rect) |
|
38
|
|
|
pygame.draw.rect(surface, self.__outline, rect, int(screen.block_size / 4 * 3)) |
|
39
|
|
|
|
|
40
|
|
|
# Render |
|
41
|
|
|
return int(self._x * screen.block_size), int(self._y * screen.block_size), surface |
|
42
|
|
|
|