- get text box correctly draws text with transparent background
- sprite toggle hidden registered as playable animation
This commit is contained in:
parent
5403896b79
commit
869fed171d
|
@ -29,6 +29,7 @@ class Sprite(Animation):
|
|||
self.locations.append(Location(self))
|
||||
self.motion_overflow = Vector()
|
||||
self.display_surface = self.get_display_surface()
|
||||
self.register(self.toggle_hidden)
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name in ("location", "rect"):
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from random import randint, random
|
||||
from math import sin, cos, atan2, radians, sqrt, pi
|
||||
|
||||
from pygame import Surface, PixelArray, Color, Rect
|
||||
from pygame import Surface, PixelArray, Color, Rect, draw
|
||||
from pygame.mixer import get_num_channels, Channel
|
||||
from pygame.locals import *
|
||||
|
||||
|
@ -165,10 +165,11 @@ def render_box(font, text, antialias, color, background=None, border=None,
|
|||
border_width = [border_width] * 2
|
||||
border_width = [x * 2 for x in border_width]
|
||||
rect = surface.get_rect()
|
||||
bordered_surface = Surface(rect.inflate(border_width).size)
|
||||
bordered_surface = Surface(rect.inflate(border_width).size, SRCALPHA)
|
||||
bordered_surface.fill(border)
|
||||
rect.center = bordered_surface.get_rect().center
|
||||
bordered_surface.blit(surface, rect)
|
||||
bordered_surface.fill((255, 255, 255, 255), rect)
|
||||
bordered_surface.blit(surface, rect, None, BLEND_RGBA_MIN)
|
||||
surface = bordered_surface
|
||||
return surface
|
||||
|
||||
|
@ -238,7 +239,7 @@ def get_blinds_frames(surface, step=.05, count=4, fill=(0, 0, 0, 0)):
|
|||
frames = []
|
||||
rects = []
|
||||
h = int(round(surface.get_height() / float(count)))
|
||||
for ii in range(count):
|
||||
for ii in range(1, count + 1):
|
||||
rects.append(Rect(0, h * ii, surface.get_width(), 0))
|
||||
bar_h = int(round(h * step))
|
||||
if bar_h < 1:
|
||||
|
@ -246,10 +247,10 @@ def get_blinds_frames(surface, step=.05, count=4, fill=(0, 0, 0, 0)):
|
|||
while rects[0].h < h:
|
||||
frame = surface.copy()
|
||||
for rect in rects:
|
||||
rect.inflate_ip(0, bar_h)
|
||||
frame.fill(fill, rect)
|
||||
bottom = rect.bottom
|
||||
rect.inflate_ip(0, bar_h)
|
||||
rect.bottom = bottom
|
||||
frame.fill(fill, rect)
|
||||
frames.append(frame)
|
||||
return frames
|
||||
|
||||
|
@ -264,7 +265,7 @@ def get_random_hsla_color(hue_range=(0, 359), saturation_range=(0, 100),
|
|||
randint(*hue_range), randint(*saturation_range), randint(*lightness_range),
|
||||
randint(*alpha_range))
|
||||
|
||||
# adapted from http://www.pygame.org/wiki/BezierCurve
|
||||
# http://www.pygame.org/wiki/BezierCurve
|
||||
def compute_bezier_points(vertices, numPoints=60):
|
||||
points = []
|
||||
b0x = vertices[0][0]
|
||||
|
@ -285,7 +286,6 @@ def compute_bezier_points(vertices, numPoints=60):
|
|||
dy = b0y
|
||||
numSteps = numPoints - 1
|
||||
h = 1.0 / numSteps
|
||||
# Compute forward differences from Bezier points and "h"
|
||||
pointX = dx
|
||||
pointY = dy
|
||||
firstFDX = ax * h ** 3 + bx * h ** 2 + cx * h
|
||||
|
@ -294,7 +294,6 @@ def compute_bezier_points(vertices, numPoints=60):
|
|||
secondFDY = 6 * ay * h ** 3 + 2 * by * h ** 2
|
||||
thirdFDX = 6 * ax * h ** 3
|
||||
thirdFDY = 6 * ay * h ** 3
|
||||
# Compute points at each step
|
||||
points.append(Vector(pointX, pointY))
|
||||
for i in range(numSteps):
|
||||
pointX += firstFDX
|
||||
|
|
Loading…
Reference in New Issue