Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.libsdl.video
Class SDLSurface  view SDLSurface download SDLSurface.java

java.lang.Object
  extended byorg.libsdl.SDLStruct
      extended byorg.libsdl.video.SDLSurface
Direct Known Subclasses:
SDLScreen

public class SDLSurface
extends org.libsdl.SDLStruct

The SDLSurface class represents an SDL_Surface C struct. The class extends SDLStruct and thus represents a native C structure. A surface can be created in many ways in SDL. For example, rendering TrueType fonts will create a surface. Loading an image from a file with create a surface.

Surfaces can be modified directly by manipulating the pixel data. In addition they can be modified by blitting other surfaces onto them.

------ EXAMPLE ------

     TTFFont font = ...  // create a font
     SDLColor color = ...  // create a color
     SDLSurface fontSurface = font.renderTextBlended("Hello World", color);
 

------ EXAMPLE ------

     String imageFilePath = ...  // get a path to an image file
     SDLSurface surf = new SDLSurface(imageFilePath);
     int width = surf.getWidth();  // etc...
 

Version:
$revision$

Field Summary
static int SDL_HWSURFACE
           
static int SDL_PREALLOC
           
static int SDL_RLEACCEL
           
static int SDL_RLEACCELOK
           
static int SDL_SRCALPHA
           
static int SDL_SRCCOLORKEY
           
static int SDL_SWSURFACE
           
 
Fields inherited from class org.libsdl.SDLStruct
pointer
 
Constructor Summary
protected SDLSurface(int l)
           
  SDLSurface(int flags, int width, int height, int depth, int rmask, int gmask, int bmask, int amask)
          Constructs a new surface from the given parameters.
  SDLSurface(java.lang.String filename)
          Constructs a new surface from an image file.
 
Method Summary
 int blitSurface(SDLSurface srcSurface, SDLRect srcRect, SDLRect destRect)
          Blit another surface onto this surface.
 SDLSurface convertSurface(SDLPixelFormat format, int flags)
          Converts the surface to the given pixel format.
private static int create(int flags, int width, int height, int depth, int rmask, int gmask, int bmask, int amask)
           
private static int createFromBmpFile(java.lang.String filename)
           
private static int createFromImageFile(java.lang.String filename)
           
 SDLSurface displayFormat()
          Converts this surface to the current format used by the display surface.
 SDLSurface displayFormatAlpha()
          Converts this surface to the current format used by the display surface.
 boolean fillRect(SDLRect rect, int color)
          Fills a portion of this surface with a given color.
 void finalize()
          Called on an object by the Virtual Machine at most once, at some point after the Object is determined unreachable but before it is destroyed.
private  void free()
           
 SDLRect getClipRect()
          Returns the current clipping rectangle of this surface
 int getFlags()
          Returns the flags used to create this surface.
 int getHeight()
          Returns the height of the surface
 short getPitch()
          Returns the pitch of the surface
 SDLPixelFormat getPixelFormat()
          Returns the SDLPixelFormat currently in use by this surface.
 int getWidth()
          Returns the width of the surface
 boolean lock()
          Locks the surface so that its pixels can be directly manipulated
 boolean saveAsBmp(java.lang.String filename)
          Saves the surface as a windows bitmap file.
 boolean setAlpha(int flag, short alpha)
          Sets the surface's alpha value
 void setClipRect(SDLRect rect)
          Sets the surface's current clipping rectangle
 boolean setColorKey(int flag, int key)
          Sets the surface's color key (transparent pixel)
 boolean setColors(SDLRect[] colors, int firstcolor, int numcolors)
          Sets a portion of the color map for this 8 bit surface.
 boolean setPalette(int flags, SDLRect[] colors, int firstcolor, int numcolors)
          Sets a portion of the palette for this 8 bit surface.
 void unlock()
          Unlocks a previously locked surface
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SDL_SWSURFACE

public static int SDL_SWSURFACE

SDL_HWSURFACE

public static int SDL_HWSURFACE

SDL_SRCCOLORKEY

public static int SDL_SRCCOLORKEY

SDL_RLEACCELOK

public static int SDL_RLEACCELOK

SDL_RLEACCEL

public static int SDL_RLEACCEL

SDL_SRCALPHA

public static int SDL_SRCALPHA

SDL_PREALLOC

public static int SDL_PREALLOC
Constructor Detail

SDLSurface

protected SDLSurface(int l)

SDLSurface

public SDLSurface(int flags,
                  int width,
                  int height,
                  int depth,
                  int rmask,
                  int gmask,
                  int bmask,
                  int amask)
Constructs a new surface from the given parameters.

Corresponds:

SDL_CreateRGBSurface()


SDLSurface

public SDLSurface(java.lang.String filename)
           throws java.io.FileNotFoundException,
                  org.libsdl.SDLException,
                  org.libsdl.SDLLibraryNotAvailableException
Constructs a new surface from an image file. If the image file has a .bmp extension, the SDL function SDL_LoadBMP will be used. If the file is some other kind of image, then the SDL_image library will be used. However, if the SDL_image library is not available, an exception of type SDLLibraryNotAvailableException will be thrown. If for some reason the loading of the image fails, an SDLException will be thrown, hopefully explaining why.

Corresponds:

SDL_CreateRGBSurface()

Method Detail

create

private static int create(int flags,
                          int width,
                          int height,
                          int depth,
                          int rmask,
                          int gmask,
                          int bmask,
                          int amask)

createFromBmpFile

private static int createFromBmpFile(java.lang.String filename)

createFromImageFile

private static int createFromImageFile(java.lang.String filename)
                                throws org.libsdl.SDLLibraryNotAvailableException

getFlags

public int getFlags()
Returns the flags used to create this surface.


getPixelFormat

public SDLPixelFormat getPixelFormat()
Returns the SDLPixelFormat currently in use by this surface.


getWidth

public int getWidth()
Returns the width of the surface


getHeight

public int getHeight()
Returns the height of the surface


getPitch

public short getPitch()
Returns the pitch of the surface


lock

public boolean lock()
Locks the surface so that its pixels can be directly manipulated

Corresponds:

SDL_LockSurface()


unlock

public void unlock()
Unlocks a previously locked surface

Corresponds:

SDL_UnlockSurface()


setColorKey

public boolean setColorKey(int flag,
                           int key)
Sets the surface's color key (transparent pixel)

Corresponds:

SDL_SetColorKey()


setAlpha

public boolean setAlpha(int flag,
                        short alpha)
Sets the surface's alpha value

Corresponds:

SDL_SetAlpha()


setClipRect

public void setClipRect(SDLRect rect)
Sets the surface's current clipping rectangle

Corresponds:

SDL_SetSetClipRect()


getClipRect

public SDLRect getClipRect()
Returns the current clipping rectangle of this surface

Corresponds:

SDL_GetSetClipRect()


convertSurface

public SDLSurface convertSurface(SDLPixelFormat format,
                                 int flags)
Converts the surface to the given pixel format.

Corresponds:

SDL_ConvertSurface()


blitSurface

public int blitSurface(SDLSurface srcSurface,
                       SDLRect srcRect,
                       SDLRect destRect)
Blit another surface onto this surface.

Corresponds:

SDL_ConvertSurface()


fillRect

public boolean fillRect(SDLRect rect,
                        int color)
Fills a portion of this surface with a given color.

Corresponds:

SDL_FillRect()


displayFormat

public SDLSurface displayFormat()
Converts this surface to the current format used by the display surface. This works just like convertSurface() except that the pixel format is implied.

Corresponds:

SDL_DisplayFormat()


displayFormatAlpha

public SDLSurface displayFormatAlpha()
Converts this surface to the current format used by the display surface. This works just like convertSurface() except that the pixel format is implied.

Corresponds:

SDL_DisplayFormat()


saveAsBmp

public boolean saveAsBmp(java.lang.String filename)
Saves the surface as a windows bitmap file.

Corresponds:

SDL_SaveBMP()


setColors

public boolean setColors(SDLRect[] colors,
                         int firstcolor,
                         int numcolors)
Sets a portion of the color map for this 8 bit surface. (the surface must have a bit depth of 8 and hence have a color map)

Corresponds:

SDL_SetColors()


setPalette

public boolean setPalette(int flags,
                          SDLRect[] colors,
                          int firstcolor,
                          int numcolors)
Sets a portion of the palette for this 8 bit surface. (the surface must have a bit depth of 8 and hence have a palette)

Corresponds:

SDL_SetPalette()


free

private void free()

finalize

public void finalize()
Description copied from class: java.lang.Object
Called on an object by the Virtual Machine at most once, at some point after the Object is determined unreachable but before it is destroyed. You would think that this means it eventually is called on every Object, but this is not necessarily the case. If execution terminates abnormally, garbage collection does not always happen. Thus you cannot rely on this method to always work. For finer control over garbage collection, use references from the java.lang.ref package.

Virtual Machines are free to not call this method if they can determine that it does nothing important; for example, if your class extends Object and overrides finalize to do simply super.finalize().

finalize() will be called by a java.lang.Thread that has no locks on any Objects, and may be called concurrently. There are no guarantees on the order in which multiple objects are finalized. This means that finalize() is usually unsuited for performing actions that must be thread-safe, and that your implementation must be use defensive programming if it is to always work.

If an Exception is thrown from finalize() during garbage collection, it will be patently ignored and the Object will still be destroyed.

It is allowed, although not typical, for user code to call finalize() directly. User invocation does not affect whether automatic invocation will occur. It is also permitted, although not recommended, for a finalize() method to "revive" an object by making it reachable from normal code again.

Unlike constructors, finalize() does not get called for an object's superclass unless the implementation specifically calls super.finalize().

The default implementation does nothing.