Passed
Push — design ( 79d5ba...44afd9 )
by Matt
03:55 queued 02:27
created

PyDMXControl.design.parts._Rect   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Rect.__init__() 0 9 1
A Rect.design_render() 0 14 1
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