public abstract class Surface extends Object
DrawComponent
. A Surface contains methods to render Sprite
s,
get bounding boxes of sprites, add sprites to the canvas, initialize other
graphic components, etc. One of the most used methods for this class is the
add(Sprite)
method, to add sprites to the surface.
Most of the Surface methods are abstract and they have a concrete
implementation in VML
or SVG
engines.Constructor and Description |
---|
Surface() |
Modifier and Type | Method and Description |
---|---|
void |
add(Sprite sprite)
Adds a
Sprite to the surface. |
void |
addGradient(Gradient gradient)
Adds the passed
Gradient to the surface. |
void |
clear()
Removes all sprites from the surface.
|
static Surface |
create(DrawComponent component)
Instantiates a surface instance via deferred binding.
|
static Surface |
create(DrawComponent component,
int width,
int height)
Instantiates a surface instance via deferred binding.
|
void |
deleteSprite(Sprite sprite)
Deletes the given sprite from the surface.
|
void |
draw()
Renders the surface to the DOM as well as any sprites already added.
|
PreciseRectangle |
getBBox(Sprite sprite)
Calculates the bounding box of the given sprite.
|
DrawComponent |
getComponent()
Returns the draw component that the surface is attached.
|
int |
getHeight()
Returns the height of the surface.
|
List<Sprite> |
getSprites()
Returns an immutable
List containing all the sprites in the
surface. |
XElement |
getSurfaceElement()
Returns the element of the surface.
|
int |
getWidth()
Returns the width of the surface.
|
abstract void |
renderSprite(Sprite sprite)
Renders the given sprite to the DOM.
|
void |
setBackground(Color background)
Set the background color of the surface.
|
abstract void |
setCursor(Sprite sprite,
String property)
Sets the cursor property for the given sprite.
|
void |
setHeight(int height)
Sets the height of the surface.
|
abstract void |
setViewBox(double x,
double y,
double width,
double height)
Sets the view box of the surface.
|
void |
setWidth(int width)
Sets the width of the surface.
|
public static Surface create(DrawComponent component)
SVG
. If the user agent is IE 6, 7, or 8 VML
will be
used.component
- the element that the surface will be attachedpublic static Surface create(DrawComponent component, int width, int height)
SVG
. If the user agent is IE 6, 7, or 8 VML
will be
used.component
- the element that the surface will be attachedwidth
- the width of the surfaceheight
- the height of the surfacepublic void add(Sprite sprite)
Sprite
to the surface. The sprite is not rendered to the DOM
until draw()
or Sprite.redraw()
is called.sprite
- the sprite to be addedpublic void addGradient(Gradient gradient)
Gradient
to the surface.gradient
- the gradient to be addedpublic void clear()
public void deleteSprite(Sprite sprite)
sprite
- the sprite to be deletedpublic void draw()
public PreciseRectangle getBBox(Sprite sprite)
sprite
- the sprite to be used in the calculationpublic DrawComponent getComponent()
public int getHeight()
public List<Sprite> getSprites()
List
containing all the sprites in the
surface. Ideally sprites should be kept track of separate from the surface.
This list can differ and may not be in the order added depending on the
surface implementation.List
containing all the sprites in the surfacepublic XElement getSurfaceElement()
public int getWidth()
public abstract void renderSprite(Sprite sprite)
sprite
- the sprite to be renderedpublic void setBackground(Color background)
background
- the background colorpublic abstract void setCursor(Sprite sprite, String property)
sprite
- the sprite to be setproperty
- the property to usepublic void setHeight(int height)
height
- the height of the surface.public abstract void setViewBox(double x, double y, double width, double height)
x
- the x coordinate of the viewboxy
- the y coordinate of the viewboxwidth
- the width of the viewboxheight
- the height of the viewboxpublic void setWidth(int width)
width
- the width of the surface.Copyright © 2015. All rights reserved.