| parrotcode: Parrot class representing surfaces in Parrot SDL | |
| Contents | Libraries |

SDL::Surface - Parrot class representing surfaces in Parrot SDL

# load this library
load_bytecode 'library/SDL/Surface.pir'
# create a new SDL::Surface object
surface = new 'SDL::Surface'
surface.'init'( 'height' => 480, 'width' => 640 )
# ... blit to, fill, update, and flip this surface as necessary

A SDL::Surface object represents a surface in SDL. All drawing operations draw to a surface (and most draw from a surface). You'll likely not instantiate this class directly, but all SDL::Image and SDL::Sprite objects operate on objects of this class, and you'll receive an SDL::Surface from the SDL::App constructor.

All SDL::Surface objects have the following methods:
height and width, two integer values representing the height and width of this surface in pixels. Other keys are depth, the screen depth, flags, the SDL flags, and r, g, b, and a, representing the bit depth of each component.
raw_surface object, sometimes returned from raw SDL functions, create and return a new SDL::Surface object.I'm not sure I like the name of this method. It may change. That may be okay; you have little reason to use it directly.
Array of rects to update.
draw_pixel() or any other pixel operation. Be careful what else you do while you hold the lock.
x and y with the given SDL::Color color.If you want as much speed as possible, call color_for_surface on the SDL::Color and pass in the value you receive instead. This method will not have to perform a time-consuming conversion. This is a classic tradeoff between memory and speed. Happily, colors are (reasonably cheap) integers at heart.
.local pmc surface, pixels .local int offset, x, y, raw_color pixels = surface.'pixels'() offset = surface.'width'() ... $I0 = offset * y $I0 .= x pixels[0; $I0] = raw_color # pixels['array'; $O] = raw_colorPlease note that the function returns an UnManagedStruct pointing to an array, therefore the double indexing is needed.See also draw_pixels() above for locking/unlocking the surface and how to fetch raw colors.

Written and maintained by chromatic, <chromatic at wgz dot org>, with suggestions from Jens Rieks. Please send patches, feedback, and suggestions to the Perl 6 Internals mailing list.

Copyright (C) 2004-2008, The Perl Foundation.
|
|
|