[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Text() class, a pygame.font.Font() helper classes
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Text() class, a pygame.font.Font() helper classes
- From: Frozenball <orkkiolento@xxxxxxxxx>
- Date: Fri, 9 Jan 2009 21:08:37 +0200
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Fri, 09 Jan 2009 14:08:42 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=QSuAwcLZGf0CNIvjcqypsrLJQuq7ID7xLMxH9wgFX8M=; b=KuAWFpcimYqwHcgup5/3r4nlDcNF5Mt6WOyW55ijPe2XTdZ/fowV8wbP8JMzGBuOZl dP+DXYg4J6fIUHzDcX1lzSRvFTWIfcsOAvG1ZFGQVX14Es2ELD/7W3acrcX8GeMkl271 vD2ACeQAro/4qqH3lzthJAs1kpn9ZnG5xj9TY=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=Cns+h8U5zDBuhQDit9wRsVJSataqHbVrs3GP1EydXtZVP6PWpSuw3OiDLIeE8dBC2k ekRTFvOdqqNF1b0pAtSu72DFF76zp1ZGkJ4ZeJfecLsNmiE486xb9C7ycZKPDHWFsZHF A17xrVoBuOqLJU4SyCsnwJPU10dYG7nkVQhiA=
- In-reply-to: <dc44bb3e0901052219j27b687e6p6b83d08e999e81a1@xxxxxxxxxxxxxx>
- References: <dc44bb3e0901052219j27b687e6p6b83d08e999e81a1@xxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Having a proper text wrapper would be a godsend. I tried making my own
but that didn't end up well.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: http://getfiregpg.org
iD8DBQFJZ6CMaOkdBMkI09YRArMQAKCS4dK1IsaCMjiQ1dz342T8XE1hEgCff0B/
c7TWsJehQCjEdpR5j+Qf9rc=
=kr21
-----END PGP SIGNATURE-----
On Tue, Jan 6, 2009 at 8:19 AM, Jake b <ninmonkeys@xxxxxxxxx> wrote:
> I'm sure you have your own text wrappers. I think pygame should get some
> support. I'm thinking of having a Text() or TextGroup() that is similar to
> SpriteGroups().
>
> I have a Text() class that is a wrapper to pygame.font.Font(), and does some
> basic functions. It cache's the font.render() result, and uses cache on
> .draw(). It also only re-renders the text, if it has changed ( in color,
> size, text, font, etc... ) otherwise uses cache.
>
> The second class, FPSText() is a quick way to get a Text() object with the
> current FPS.
>
> I was going to make a TextGroup() that acts like a spritegroup, containing
> my Text() objects. I also planned a multi-line object, and the ability to
> have different colors in a single Text() line. ( think of standard RPG has a
> paragraph of text with certain words escaped with color codes ). Right now I
> need to improve the color methods to use multiple types of color definitions
> ( str, or tuple )
>
> [ In the future could maybe even make clickable links ( aka: url), that
> onclick() call a callback function defined on Text() creation. example:
> civilization in-game-help. )
>
> 1) Is this something that pygame would add? ( I know theres a new dev
> version of pygame, but i'm not sure if it has anything like this. )
> 2) Should I be using pygame.color.Color() OR pygame.Color() ? ( Or use
> either, they point to same class? )
> 3) Any feedback would be appreciated, thanks.
>
> Here is example usage of Text() and FPSText()
>
> Example usage:
>
> in Game.init():
> # create text, later change font
> t = Text('foo')
> t.match_font('arial')
>
> # 2) use filepath to tff
> t2 = Text('foo', font='ttf/freesansbold.ttf')
> # 3) list of font names (without .ttf) to search OS for.
> t3 = Text('foo', font='arial, verdana, foobar')
>
> # set loc using alignment [and optional offset ]
> t = Text("align=topright,offset(x,y)", size=16,color="darkred")
> t.align( "bottomleft", self.width, self.height)
> t.align( "topright", self.width, self.height, (-60,80))
>
> # usage in Game()
> self.points = Text("Points: None!")
> self.fps = FPSText()
>
> # ... append a bunch of Text() objects to align_list
> self.align_list = []
> self.align_list.append( t1 )
> self.align_list.append( t2 )
> self.align_list.append( t3 )
>
> in Game.draw(self):
> self.points = "Points: %s" % ( player_points ) # caches if same
> value
> self.text.draw()
> self.fps.draw()
> self.fps.tick()
>
> for t in self.align_list: t.draw()
>
> [ note: the attached code has a module 'game', which is just a wrapper to
> boilerplate of a pygame game. makes test_text.py code simpler. ]
>