Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

wftk::Surface Class Reference

Surface represents a bitmap (texture). More...

#include <surface.h>

Inheritance diagram for wftk::Surface:

wftk::Font::Glyph wftk::ScreenSurface wftk::Video wftk::VideoWidget List of all members.

Public Types

typedef Resource< Surface * > Resource
 refcounted resource type

Public Member Functions

 Surface ()
 create an empty surface
 Surface (unsigned w, unsigned h, const Pixelformat &pixelformat=Pixelformat::ABGR8888)
 Create a surface of the given size and pixelformat.
 Surface (const Surface &surf)
 Copy a surface.
 Surface (Surface &parent, const Rect &rect)
 The child surface shares the parent's pixel data.
void setAsChild (Surface &parent, const Rect &rect)
 set this surface to be a child of the given surface
void setSurface (unsigned w, unsigned h, const Pixelformat &pixelformat=Pixelformat::ABGR8888)
 set the surface (uninitialzed) to a particular width, height, and pixelformat
bool readFromXPM (char **data)
 Read from included XPM.
bool readFromHeader (unsigned char *header_data, unsigned int w, unsigned int h)
 Read from included gimp header file.
bool readFromFile (const std::string &filename)
 Load surface from a PNG or BMP file.
bool writeToFile (const std::string &filename)
 Write surface to a png formatted file filename.
Surfaceoperator= (const Surface &surf)
 Copy another surface into this one.
void setPalette (const SDL_Palette *pal)
 Change palette of this surface.
bool empty () const
 check for existing pixeldata.
unsigned width () const
 return surface width
unsigned height () const
 return surface height
Rect rect () const
 return a rectangle the size of the surface
Uint16 pitch () const
 return surface pitch
Region opaqueRegion (Uint8 alpha_cutoff=(SDL_ALPHA_OPAQUE?127:128)) const
 For surfaces with alpha channel, all pixels lying opaque-ward of the cutoff, not including pixels whose alpha value equals the cutoff, are included.
Pixelformat pixelformat () const
 return pixelformat of this surface
bool convert (const Pixelformat &pixelformat, bool dither=true)
 Convert surface into given pixelformat.
bool mirror ()
 mirror this surface horizontally
bool scale (unsigned new_width, unsigned new_height)
 scale this surface to the new size
bool scale (float n)
 scale this surface by given factor
void gammaShift (char g)
 lighten (g > 0) or darken (g < 0) the surface
void gammaShift (const GammaFunction &gamma)
 lighten or darken the surface using a texture
void setColorKey (const Color &color)
 set colorkey for non-alpha surfaces
void clearColorKey ()
 disable colorkey for non-alpha surfaces
Color transparentColor () const
 get the Color value of the colorkey
void setAlpha (unsigned char alpha)
 set alpha, in the range defined by SDL_ALPHA_OPAQUE and SDL_ALPHA_TRANSPARENT
bool usesColorKey () const
 return true if the surface uses a color key
bool hasAlphaChannel () const
 check if surface contains an alpha channel
void useRLEAcceleration (bool flag)
 return true if the surface is RLE accelerated
Rect blit (Surface &s) const
 Blit (copy) pixels.
Rect blit (Surface &s, const Rect &dest) const
 Blit pixels with clipping rectangle.
Rect blit (Surface &s, const Rect &dest, const Rect &src) const
 Blit pixels, clipping both source and destination.
void blit (Surface &s, const Point &dest, const Region &destMask) const
 Blit pixels from this surface to target Region of given Surface.
Rect scaledBlit (Surface &s, bool smooth=false) const
 scaled blit: zoom all of this Surface to fit into target Surface s
Rect scaledBlit (Surface &, const Rect &dest, bool smooth=false) const
 Scaled blit with destination clipping.
Rect scaledBlit (Surface &, const Rect &dest, const Rect &src, bool smooth=false) const
 Scaled blit with destination and source clipping.
Rect textureBlit (Surface &dst, const Point &p1, const Point &p2, const Point &p3, const Point &p4) const
 Textured blit, into destination surface dst.
Rect textureBlit (Surface &dst, const Point &p1, const Point &p2, const Point &p3, const Point &p4, const Rect &src) const
 Clipped & textured blit, into destination Surface dst.
void clear ()
 clear surface to background color
void clear (const Rect &)
 clear given rect
void fill (const Color &)
 fill whole surface with the given color
void fill (const Rect &, const Color &)
 fill the given Rect (rectangle) with the given Color
void fill (const Region &, const Color &)
 fill the given Region with the given Color
void blend (const Color &c)
 like fill, but with alpha blending
void blend (const Rect &, const Color &)
 blend the given Rect (rectangle) with the given Color
void blend (const Region &, const Color &)
 blend the given Region with the given Color
void setWMIcon () const
 set window manager icon - for when the application is running By default WFTK supplies a simple 'tools on stained glass' icon.
void * pixels ()
 this allows pixelaccess....
const void * pixels () const
 this allows pixelaccess....
void lock () const
 lock pixel data for direct access.
void unlock () const
 unlock pixel data.
void writePixel (Uint32 pixeladdr, Uint32 pixel)
 pixel address in bytes
Uint32 readPixel (Uint32 pixeladdr) const
 pixel address in bytes
Color getPixel (const Point &) const
 get pixel color
void setPixel (const Point &, const Color &)
 set pixel color
void makeGLTexture ()

Static Public Attributes

ResourceRegistry< Surface *,
ResLoad > 
registry
 Load bitmapped surface from file.

Protected Attributes

SDL_Surface * sdlSurface_
 the underlying SDL_Surface
SDL_Surface * glSurface_
unsigned int glTexture_
float glTexMaxX_
float glTexMaxY_

Detailed Description

Surface represents a bitmap (texture).


Constructor & Destructor Documentation

wftk::Surface::Surface Surface parent,
const Rect rect
 

The child surface shares the parent's pixel data.

The parent reference is _not_ const.


Member Function Documentation

void wftk::Surface::blit Surface s,
const Point dest,
const Region destMask
const
 

Blit pixels from this surface to target Region of given Surface.

Parameters:
s destination Surface for blit
dest Point (x,y) offset for blitting to target
destMask Region describing destination mask

Rect wftk::Surface::blit Surface s,
const Rect dest,
const Rect src
const
 

Blit pixels, clipping both source and destination.

Blit contents within Rect src of this surface to within the Rect dest of Surface s

Rect wftk::Surface::blit Surface s,
const Rect dest
const
 

Blit pixels with clipping rectangle.

Blit all of this surface within the Rect dest of the target Surface s

Rect wftk::Surface::blit Surface s  )  const
 

Blit (copy) pixels.

Blit all of this surface to the target Surface s

bool wftk::Surface::convert const Pixelformat pixelformat,
bool  dither = true
 

Convert surface into given pixelformat.

Since version 0.3.37 a instance of Pixelformat is passed; by this the palette of the target format can be set ! Per default floyd-steinberg dithering is used.

bool wftk::Surface::empty  )  const [inline]
 

check for existing pixeldata.

An empty surface results from an unsuccessful file read for example.

void wftk::Surface::lock  )  const
 

lock pixel data for direct access.

This is also need for pure read access, so it seems acceptable to make lock() a const method.

Region wftk::Surface::opaqueRegion Uint8  alpha_cutoff = (SDL_ALPHA_OPAQUE?127:128)  )  const
 

For surfaces with alpha channel, all pixels lying opaque-ward of the cutoff, not including pixels whose alpha value equals the cutoff, are included.

For surfaces with a color key, the cutoff is ignored, and all non-color-key pixels are returned.

For surfaces without any form of transparency, returns a rectangle equal to the size of the surface.

const void* wftk::Surface::pixels  )  const [inline]
 

this allows pixelaccess....

you should know what you do here. pixels accesses should be enclosed in lock()/unlock() pairs

void* wftk::Surface::pixels  )  [inline]
 

this allows pixelaccess....

you should know what you're doing. direct pixel access should be enclosed in lock()/unlock() pairs

bool wftk::Surface::readFromFile const std::string &  filename  ) 
 

Load surface from a PNG or BMP file.

Parameters:
filename File to load
Returns:
true if surface loaded successfully

bool wftk::Surface::readFromHeader unsigned char *  header_data,
unsigned int  w,
unsigned int  h
 

Read from included gimp header file.

This is the alternative to readFromXPM; it uses header files generated by GIMP.

bool wftk::Surface::readFromXPM char **  data  ) 
 

Read from included XPM.

Use #include "image.xpm" to compile images into your binaries. You may then construct your surface by surface.readFromXPM(image_xpm).

void wftk::Surface::setPalette const SDL_Palette *  pal  ) 
 

Change palette of this surface.

This does not change the pixel data !

Rect wftk::Surface::textureBlit Surface dst,
const Point p1,
const Point p2,
const Point p3,
const Point p4,
const Rect src
const
 

Clipped & textured blit, into destination Surface dst.

Source rectangle described by the Rect src, destination polygon described by the four points p1, p2, p3, p4.

Rect wftk::Surface::textureBlit Surface dst,
const Point p1,
const Point p2,
const Point p3,
const Point p4
const
 

Textured blit, into destination surface dst.

Source is this entire Surface, destination polygon described by the four vertices (points) p1, p2, p3, p4.

void wftk::Surface::unlock  )  const
 

unlock pixel data.

Never forget to call this after a lock(), otherwise the application might run into a deadlock.


Member Data Documentation

ResourceRegistry< Surface *, Surface::ResLoad > wftk::Surface::registry [static]
 

Load bitmapped surface from file.

Use the load() function to load a surface from a file on disk and register it with wftk's Resources engine, e.g.:

   Surface::registry::load("button_clicked", "button.png");
Use the find() function to retrieve a pointer to the surface. If the named surface has not been registered, find() will return 0.
   Surface::registry.find("button_clicked");
   myWidget->setBackground(Surface::registry.find("back_image"));


The documentation for this class was generated from the following files:

Generated Mon Sep 6 21:58:17 2004.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.