org.sledv.aurinko
Class Surface

java.lang.Object
  extended by org.sledv.aurinko.Surface
All Implemented Interfaces:
java.io.Serializable

public class Surface
extends java.lang.Object
implements java.io.Serializable

A surface is the primitive for all drawing operations. You can draw lines, pixels, and other surfaces on it. If you know what a DirectDraw-Surface is you know what this is

See Also:
Serialized Form

Field Summary
protected  int[] data
           
static int OPAQUE
           
protected  boolean surface_acceleration
           
 
Constructor Summary
Surface(java.awt.image.BufferedImage source)
           
Surface(int width, int height)
           
Surface(java.lang.String surfdata)
          Creates a surface based on the description returned by toString() from another Surface.
 
Method Summary
 void _colorShiftLeft()
           
 void _colorShiftRight()
           
 void _setPixel(int x, int y, int color)
           
 void clear(int color)
          Clears all contents of the surface
 void colorShiftLeft()
          Shifts the colorspace to the left.
 void colorShiftRight()
          Shifts the colorspace to the right.
 void copyBuffer()
          Copys data between front and backbuffer
getPrimary().copyBuffer(); will copy the backbuffer ot the primary surface
getBackBuffer().copyBuffer(); will copy the primary surface to the backbuffer
Note that flip() is faster!
 void dim(int bright)
           
 void draw(int x, int y, Surface source)
          Draws another surface on this surface
 void draw(int x, int y, Surface source, int sx, int sy, int w, int h)
          Draws parts of a another surface on this surface
 int getColorKey()
           
 int getHeight()
           
 int getPixel(int x, int y)
          Gets a pixel value from a Surface.
 int getWidth()
           
 void hline(int x, int y, int length, int color)
          Draws a one pixel high horizontal line.
 boolean isHardwareSurface()
           
 int[] lock(boolean readonly)
          Locks the surface so that pixeldata can be accessed directly.
 void rect(int x1, int y1, int width, int height, int color)
          Draws a one-pixel wide rectangle.
 void rectf(int x, int y, int width, int height, int color)
          Draws a filled rectangle.
 void setColorKey(int key)
           
 void setHeight(int h)
           
 void setPixel(int x, int y, int color)
          Sets a pixel to a new color.
 void setSize(int neww, int newh)
          Resizes the surface.
 void setWidth(int w)
           
 java.lang.String toString()
          Create a textual representation of the surface parameters and its contents.
 void unlock(int[] data)
          Unlocks a previously locked surface.
 void vline(int x, int y, int length, int color)
          Draws a one pixel wide vertical line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OPAQUE

public static final int OPAQUE
See Also:
Constant Field Values

data

protected int[] data

surface_acceleration

protected transient boolean surface_acceleration
Constructor Detail

Surface

public Surface(int width,
               int height)

Surface

public Surface(java.awt.image.BufferedImage source)

Surface

public Surface(java.lang.String surfdata)
Creates a surface based on the description returned by toString() from another Surface.

Parameters:
surfdata - The description
Method Detail

isHardwareSurface

public boolean isHardwareSurface()

getWidth

public int getWidth()

getHeight

public int getHeight()

setWidth

public void setWidth(int w)

setHeight

public void setHeight(int h)

setColorKey

public void setColorKey(int key)

getColorKey

public int getColorKey()

setSize

public void setSize(int neww,
                    int newh)
Resizes the surface. Expanding the surface will cause the new areas to be filled black

Parameters:
neww - The new width
newh - The new height

toString

public java.lang.String toString()
Create a textual representation of the surface parameters and its contents. This can be used to construct a new surface with the same content

Overrides:
toString in class java.lang.Object
Returns:
A string which contains all the surfaces data

lock

public int[] lock(boolean readonly)
Locks the surface so that pixeldata can be accessed directly. After the modifications have been made, a program must call the unlock() method.

Parameters:
readonly - Whether write access to this surface is needed.
Returns:
A pointer to this surfaces' memory

unlock

public void unlock(int[] data)
Unlocks a previously locked surface. Only non-readonly surfaces need to be unlocked.

Parameters:
data - The result from the lock()-call

setPixel

public void setPixel(int x,
                     int y,
                     int color)
Sets a pixel to a new color. This is the most basic (and also most inefficient) way of generating output.

Parameters:
x - The X-Coordinate
y - The Y-Coordinate
color - The new color for the given position

_setPixel

public void _setPixel(int x,
                      int y,
                      int color)

getPixel

public int getPixel(int x,
                    int y)
Gets a pixel value from a Surface. If the coordinates are outside the Surface, black will be returned

Parameters:
x - The X-Coordinate
y - The Y-Coordinate
Returns:
The color of that pixel

hline

public void hline(int x,
                  int y,
                  int length,
                  int color)
Draws a one pixel high horizontal line.

Parameters:
x - X-Coordinate for the start of the line
y - Y-Coordinate for the start of the line
length - The length of the line in pixels, the line will extend rightwards
color - The color for the line

vline

public void vline(int x,
                  int y,
                  int length,
                  int color)
Draws a one pixel wide vertical line.

Parameters:
x - X-Coordinate for the start of the line
y - Y-Coordinate for the start of the line
length - The length of the line in pixels, the line will extend downwards
color - The color for the line

rect

public void rect(int x1,
                 int y1,
                 int width,
                 int height,
                 int color)
Draws a one-pixel wide rectangle.

Parameters:
x1 - Left X-Coordinate
y1 - Top Y-Coordinate
width - Width of the rectangle in pixels, the rectangle will extend rightwards on the X-axis
height - Height of the rectangle in pixels, the rectangle will extend downwards on the Y-axis
color - The color for the rectangle

rectf

public void rectf(int x,
                  int y,
                  int width,
                  int height,
                  int color)
Draws a filled rectangle.

Parameters:
x1 - Left X-Coordinate
y1 - Top Y-Coordinate
width - Width of the rectangle in pixels, the rectangle will extend rightwards on the X-axis
height - Height of the rectangle in pixels, the rectangle will extend downwards on the Y-axis
color - The color for the rectangle

clear

public void clear(int color)
Clears all contents of the surface

Parameters:
color - The color the surface will be filled with

draw

public void draw(int x,
                 int y,
                 Surface source,
                 int sx,
                 int sy,
                 int w,
                 int h)
Draws parts of a another surface on this surface

Parameters:
x - X-Coordinate for drawing on the destination surface (this)
y - Y-Coordinate for drawing on the destination surface (this)
source - The source surface
sx - X-Coordinate on the source surface where copying should begin
sy - Y-Coordinate on the source surface where copying should begin
w - How many pixels to the right should be transferred
h - How many pixels downwards should be transferred

draw

public final void draw(int x,
                       int y,
                       Surface source)
Draws another surface on this surface

Parameters:
x - X-Coordinate where the image should be placed
y - Y-Coordinate where the image should be placed
source - The source surface

_colorShiftRight

public void _colorShiftRight()

colorShiftRight

public void colorShiftRight()
Shifts the colorspace to the right.
Red will become green ; green will become blue ; blue will become white ; white will become red.


_colorShiftLeft

public void _colorShiftLeft()

colorShiftLeft

public void colorShiftLeft()
Shifts the colorspace to the left.
Green will become red ; red will become white ; white will become blue ; blue will become green.


copyBuffer

public void copyBuffer()
Copys data between front and backbuffer
getPrimary().copyBuffer(); will copy the backbuffer ot the primary surface
getBackBuffer().copyBuffer(); will copy the primary surface to the backbuffer
Note that flip() is faster! This method is not valid on offscreen surfaces and will throw an UnsupportedOperationException.


dim

public void dim(int bright)