[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Good code for text wrapping?



hi,

The cookbook entry has been updated with a multiline function, that
seems to work ok.
http://www.pygame.org/wiki/TextWrapping

I guess for right justify, the lines could be blit from the right of
the screen minus text width.  To center it, you would blit at the
(screen_width - text_width) / 2.

cheers,



On Tue, Sep 16, 2008 at 10:09 PM, Michael <zathras@xxxxxxxxxxxxx> wrote:
> On Tuesday 16 September 2008 03:11:45 René Dudfield wrote:
>> The cookbook has this entry, but it doesn't work with new lines.
>> http://www.pygame.org/wiki/TextWrapping
>>
>> Anyone have any code like this that supports new lines?
>
> Is this any use to you?
> https://kamaelia.svn.sourceforge.net/svnroot/kamaelia/trunk/Code/Python/Kamaelia/Kamaelia/UI/Pygame/Text.py
>
> The code can be used by itself but will look a little odd - it's got a
> slightly wierd way of getting a surface to display on inside "initPygame"
> and the equivalent of pygame.flip() is in the end of "updateLine" (the redraw
> request), but other than than it's pretty normal normal code.
>
> (The reason for the oddity is because it allows pygame based components to be
> written as if they own the whole display, and then to be changed slightly in
> small steps to share the display)
>
> To see what it looks like quickly, it'd probably be easiest to grab the latest
> kamaelia release:
>    http://edit.kamaelia.org/release/Kamaelia-0.6.0-rc7.tar.gz
>
> Do the usual setup.py dance, and then:
> ~/Kamaelia-0.6.0-rc7> cd Examples/SimpleGraphicalApps/TextBox/
> ~/Kamaelia-0.6.0-rc7/Examples/SimpleGraphicalApps/TextBox> ./Textbox_TextDisplayer_Demo.py
>
> Handles different font sizes etc happily. Only supports left justified text at
> the moment.
>
>
> Michael.
>