mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-04-05 06:25:10 +00:00
insert history and status pages to alarmMonitorRPi
This commit is contained in:
parent
646a2b2913
commit
f7ee3afb5c
4 changed files with 292 additions and 44 deletions
63
exampleAddOns/alarmMonitorRPi/roundrects.py
Normal file
63
exampleAddOns/alarmMonitorRPi/roundrects.py
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
"""
|
||||
Rounded rectangles in both non-antialiased and antialiased varieties.
|
||||
|
||||
@author: Sean J. McKiernan
|
||||
https://github.com/Mekire/rounded-rects-pygame
|
||||
"""
|
||||
|
||||
import pygame as pg
|
||||
|
||||
from pygame import gfxdraw
|
||||
|
||||
|
||||
def round_rect(surface, rect, color, rad=20, border=0, inside=(0,0,0,0)):
|
||||
"""
|
||||
Draw a rect with rounded corners to surface. Argument rad can be specified
|
||||
to adjust curvature of edges (given in pixels). An optional border
|
||||
width can also be supplied; if not provided the rect will be filled.
|
||||
Both the color and optional interior color (the inside argument) support
|
||||
alpha.
|
||||
"""
|
||||
rect = pg.Rect(rect)
|
||||
zeroed_rect = rect.copy()
|
||||
zeroed_rect.topleft = 0,0
|
||||
image = pg.Surface(rect.size).convert_alpha()
|
||||
image.fill((0,0,0,0))
|
||||
_render_region(image, zeroed_rect, color, rad)
|
||||
if border:
|
||||
zeroed_rect.inflate_ip(-2*border, -2*border)
|
||||
_render_region(image, zeroed_rect, inside, rad)
|
||||
surface.blit(image, rect)
|
||||
|
||||
|
||||
def _render_region(image, rect, color, rad):
|
||||
"""Helper function for round_rect."""
|
||||
corners = rect.inflate(-2*rad, -2*rad)
|
||||
for attribute in ("topleft", "topright", "bottomleft", "bottomright"):
|
||||
pg.draw.circle(image, color, getattr(corners,attribute), rad)
|
||||
image.fill(color, rect.inflate(-2*rad,0))
|
||||
image.fill(color, rect.inflate(0,-2*rad))
|
||||
|
||||
|
||||
def aa_round_rect(surface, rect, color, rad=20, border=0, inside=(0,0,0)):
|
||||
"""
|
||||
Draw an antialiased rounded rect on the target surface. Alpha is not
|
||||
supported in this implementation but other than that usage is identical to
|
||||
round_rect.
|
||||
"""
|
||||
rect = pg.Rect(rect)
|
||||
_aa_render_region(surface, rect, color, rad)
|
||||
if border:
|
||||
rect.inflate_ip(-2*border, -2*border)
|
||||
_aa_render_region(surface, rect, inside, rad)
|
||||
|
||||
|
||||
def _aa_render_region(image, rect, color, rad):
|
||||
"""Helper function for aa_round_rect."""
|
||||
corners = rect.inflate(-2*rad-1, -2*rad-1)
|
||||
for attribute in ("topleft", "topright", "bottomleft", "bottomright"):
|
||||
x, y = getattr(corners, attribute)
|
||||
gfxdraw.aacircle(image, x, y, rad, color)
|
||||
gfxdraw.filled_circle(image, x, y, rad, color)
|
||||
image.fill(color, rect.inflate(-2*rad,0))
|
||||
image.fill(color, rect.inflate(0,-2*rad))
|
||||
Loading…
Add table
Add a link
Reference in a new issue