5 blue_font.pir - draw a friendly message to the screen
9 To run this file, run the following command from the Parrot directory:
11 $ ./parrot examples/sdl/blue_font.pir
14 Note that you need to have a font named C<times.ttf> in the current directory.
15 I recommend making a symlink.
17 Yes, getting this to work across platforms is tricky, as is distributing a
18 royalty-free font file. Maybe soon.
24 # first load the necessary libraries
25 load_bytecode "SDL/App.pir"
26 load_bytecode "SDL/Rect.pir"
27 load_bytecode "SDL/Color.pir"
28 load_bytecode "SDL/Font.pir"
30 # create an SDL::App object
33 app.'init'( 'height' => 480, 'width' => 640, 'bpp' => 0, 'flags' => 1 )
35 # fetch the SDL::Surface representing the main window
36 .local pmc main_screen
37 main_screen = app.'surface'()
39 # create an SDL::Rect object
42 rect.'init'( 'height' => 100, 'width' => 100, 'x' => 194, 'y' => 208 )
44 # create SDL::Color objects
46 new blue, 'SDL::Color'
47 blue.'init'( 'r' => 0, 'g' => 0, 'b' => 255 )
50 new white, 'SDL::Color'
51 white.'init'( 'r' => 255, 'g' => 255, 'b' => 255 )
56 .local int font_exists
57 font_exists = file_pmc.'exists'( 'times.ttf' )
59 if font_exists goto have_font
60 print "No font found (expect times.ttf in this directory); exiting...\n"
66 font.'init'( 'font_file' => 'times.ttf', 'point_size' => 48 )
69 full_rect = new 'SDL::Rect'
70 full_rect.'init'( 'width' => 640, 'height' => 480, 'x' => 0, 'y' => 0 )
72 main_screen.'fill_rect'( full_rect, white )
73 main_screen.'update_rect'( full_rect )
75 # draw the rectangle to the surface and update it
76 font.'draw'( 'Hello, world!', blue, main_screen, rect )
77 main_screen.'update_rect'( rect )
79 # pause for people to see it
89 chromatic, E<lt>chromatic at wgz dot orgE<gt>.
93 Copyright (C) 2004-2008, Parrot Foundation.
101 # vim: expandtab shiftwidth=4 ft=pir: