Hello, I think I could really use some help converting some pygame text
drawing code into pyglet code. The code is essentially drawing an 80x25
text console many times a second. The code was simple to write using
pygame but pygame and pypy don't seem to work well with each other, so I
thought I'd try pyglet instead, but I can't find any good examples for this
in the docs. The code is so basic I thought it would be straightforward.
There's essentially two challenges, the first is to open a window sized for
80x25 text using a monospaced font. The part that seems hard to rewrite in
pyglet is getting a character's metrics (width and height) (all chars are
the same) so I can multiply them by 80 and 25.
80x25 window:
pygame.init()
self.font = pygame.font.SysFont("Lucida Console, Lucida Typewriter,
monospace", 16, bold=False, italic=False)
pygame.display.set_caption(app_name)
zero = self.font.metrics('0')
self.char_width = zero[0][4]
self.char_height = self.font.get_linesize()
self.screen = pygame.display.set_mode(
(80 * self.char_width, 25 * self.char_height),
pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE)
self.screen.fill(pygame.color.Color('white'))
pygame.display.update()
The second is to draw patches of text to render the console. Again, the
parts that seems hard to rewrite in pyglet are finding the width of the
text, positioning the text into the screen, and controlling the text's
forground and background color. Can you control how/where GlyphString
draws? Do you really call get_glyphs() for every text chunk? How do you
specify underline?
text drawing (vaguely):
screen_y = y * self.char_height
screen_x = 0
text_surface = self.font.render(text, True, fore_color,
back_color)
self.screen.blit(text_surface, (screen_x, screen_y))
screen_x += text_surface.get_width()
fore_color, back_color, underline =
self.get_colors(new_attribute)
self.font.set_underline(underline)
pygame.display.update()
Is this even possible? It feels like the text api is too rich and advanced
and thus hidden away what I need, and the pieces I can use are spread over
too many classes.
Thanks,
-Roger
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/pyglet-users/-/aQ3XnNCCNMIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en.