~ubuntu-branches/ubuntu/gutsy/pygame/gutsy

« back to all changes in this revision

Viewing changes to examples/fonty.py

  • Committer: Bazaar Package Importer
  • Author(s): Ed Boraas
  • Date: 2002-02-20 06:39:24 UTC
  • Revision ID: james.westby@ubuntu.com-20020220063924-amlzj7tqkeods4eq
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
"""Here we load a .TTF font file, and display it in
 
3
a basic pygame window. It demonstrates several of the
 
4
Font object attributes. Nothing exciting in here, but
 
5
it makes a great example for basic window, event, and
 
6
font management."""
 
7
 
 
8
 
 
9
import pygame
 
10
from pygame.locals import *
 
11
 
 
12
 
 
13
def main():
 
14
    #initialize
 
15
    pygame.init()
 
16
    resolution = 400, 200
 
17
    screen = pygame.display.set_mode(resolution)
 
18
 
 
19
    #the python 1.5.2 way to set the cursor
 
20
    apply(pygame.mouse.set_cursor, pygame.cursors.diamond)
 
21
    #the python 2.0 way to set the cursor
 
22
    #pygame.mouse.set_cursor(*pygame.cursors.diamond)
 
23
 
 
24
    fg = 250, 240, 230
 
25
    bg = 5, 5, 5
 
26
    wincolor = 40, 40, 90
 
27
 
 
28
    #fill background
 
29
    screen.fill(wincolor)
 
30
 
 
31
    #load font, prepare values
 
32
    font = pygame.font.Font(None, 80)
 
33
    text = 'Fonty'
 
34
    size = font.size(text)
 
35
 
 
36
    #no AA, no transparancy, normal
 
37
    ren = font.render(text, 0, fg, bg)
 
38
    screen.blit(ren, (10, 10))
 
39
 
 
40
    #no AA, transparancy, underline
 
41
    font.set_underline(1)
 
42
    ren = font.render(text, 0, fg)
 
43
    screen.blit(ren, (10, 40 + size[1]))
 
44
    font.set_underline(0)
 
45
 
 
46
    #AA, no transparancy, bold
 
47
    font.set_bold(1)
 
48
    ren = font.render(text, 1, fg, bg)
 
49
    screen.blit(ren, (30 + size[0], 10))
 
50
    font.set_bold(0)
 
51
 
 
52
    #AA, transparancy, italic
 
53
    font.set_italic(1)
 
54
    ren = font.render(text, 1, fg)
 
55
    screen.blit(ren, (30 + size[0], 40 + size[1]))
 
56
    font.set_italic(0)
 
57
 
 
58
    #show the surface and await user quit
 
59
    pygame.display.flip()
 
60
    while 1:
 
61
        #use event.wait to keep from polling 100% cpu
 
62
        if pygame.event.wait().type in (QUIT, KEYDOWN, MOUSEBUTTONDOWN):
 
63
            break
 
64
 
 
65
 
 
66
 
 
67
if __name__ == '__main__': main()
 
68
    
 
 
b'\\ No newline at end of file'