[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pygame] Transparent text + scrollback
Sean R. Lynch KG6CVV wrote:
> I am attempting to create a transparent text widget with a scrollback
> buffer....
sean, unfortunately you can't easily do this. when SDL does blitting, it
does not transfer the alpha information from the source to the
destination. i consider this a mistake, but that's the way it is, and
apparantly the way it will stay (at least for quite awhile).
you have two options. the first one is to use the Numeric and surfarray
modules to transfer the alpha information around. this will get you the
exact results you want, but is a bit of a hassle, and will require
Numeric python as a dependency.
the other option is to stick with colorkeys. you can still use colorkeys
with smoothed text. what you need is to supply a background color that
matches the background area for the text as best as possible. then set
the colorkey for the image and blit away.
in your case, you won't want to set the colorkey on the rendered images,
but on your larger scrollback buffer image. here's some code, let's say
you have a scrollback buffer created and it has a colorkey already setup...
def render_text_to_buffer(buffer, font, message):
"warning, email entered code"
textcolor = 255,255,255 #white?
bgdcolor = buffer.get_colorkey()
text = font.render(message, 1, textcolor, bgdcolor)
pos = text.get_rect()
pos.bottomleft = 0, buffer.get_height()
buffer.blit(text, pos)
tada, that should do the job for you. then you can just blit the buffer
to the screen, however you please. just be sure the colorkey for the
buffer is something that resembles the screen color :]
btw, i don't think you are going to really gain anything by keeping the
text in a full image. it does let you blit the scrolling text tool in a
single blit call, but it won't really be faster than blitting each line
separately. still, as long as you don't let the image get too long, you
won't have any trouble either :]
btw, this colorkeyed smooth text is a lot faster than using regular
smoothed text with alphas. here's a simple version of the text rendering
code in solarwolf...
def text(font, color, text):
bgd = 0, 0, 0
try:
if surface.get_bytesize()>1:
img = font.render(text, 1, color, bgd)
img.set_colorkey(bgd, RLEACCEL)
else:
img = font.render(text, 0, color)
img = img.convert()
except pygame.error:
print 'TEXTFAILED', text, color
img = pygame.Surface((10, 10))
return [img, img.get_rect()]
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org