com.alienfactory.javamappy.viewer
Class Viewer

java.lang.Object
  extended by com.alienfactory.javamappy.viewer.Viewer
Direct Known Subclasses:
LayerViewer, MapViewer

public abstract class Viewer
extends java.lang.Object

Renders a Map or a Layer (dependent on the concrete implementation) onto the screen. By default the map is rendered to the top left hand corner of the screen as shown below:

    +------------------+---------+
    |                  |         |
    | JavaMappy Viewer |         |
    |                  |         |
    |                  |         |
    +------------------+         |
    |                            |
    | Screen                     |
    |                            |
    +----------------------------+ 
(A Viewer with a width and height smaller than the screen)

However, you can move the viewing area around the screen by specifying an X and Y offset as shown below:
    +----------------------------+
    | Screen                     |
    |    +------------------+    |
    |    |                  |    |
    |    | JavaMappy Viewer |    |
    |    |                  |    |
    |    |                  |    |
    |    +------------------+    |
    |                            |
    +----------------------------+ 
(The same Viewer with an X and Y offset)

Author:
Steve Eynon

Field Summary
protected  MapHeader mapHeader
           
protected  boolean pillarRiserMode
           
protected  int pixelX
           
protected  int pixelY
           
protected  Renderer renderer
           
protected  int viewHeight
           
protected  int viewOffsetX
           
protected  int viewOffsetY
           
protected  int viewWidth
           
 
Constructor Summary
Viewer(MapHeader mapHeader, Renderer renderer, int viewWidth, int viewHeight, int viewOffsetX, int viewOffsetY)
          Creates a Viewer and places the viewing area at the given offset.
 
Method Summary
 void addBlockX(int blockX)
          Increments the X coordinate by the given block amount.
 void addBlockY(int blockY)
          Increments the Y coordinate by the given block amount.
 void addPixelX(int deltaX)
          Increments the X coordinate by the given pixel amount.
 void addPixelY(int deltaY)
          Increments the Y coordinate by the given pixel amount.
abstract  void draw(java.lang.Object objGFX, boolean transparency)
          Draws Mappy data into the viewing area.
abstract  void draw(java.lang.Object objGFX, boolean transparency, int x, int y, int width, int height)
          Draws but just a section of the viewing area.
 int getBlockX()
          Returns the X coordinate in blocks of the top left hand corner of the viewing area.
 int getBlockY()
          Returns the Y coordinate in blocks of the top left hand corner of the viewing area.
 MapHeader getMapHeader()
          Returns the MapHeader associated with this Viewer.
 int getPixelX()
          Returns the X coordinate in pixels of the top left hand corner of the viewing area.
 int getPixelY()
          Returns the Y coordinate in pixels of the top left hand corner of the viewing area.
 Renderer getRenderer()
          Returns the Renderer associated with this Viewer.
 int getViewHeight()
          Returns the height in pixels of the viewing area.
 int getViewOffsetX()
          Returns the horizontal offset in pixels of the viewing area from the top left hand corner of the screen.
 int getViewOffsetY()
          Returns the vertical offset in pixels of the viewing area from the top left hand corner of the screen.
 int getViewWidth()
          Returns the width in pixels of the viewing area.
 boolean isPillarRiserMode()
          Returns true is this viewer is in Pillar Riser Mode, used in isometric maps.
 void setBlockX(int blockX)
          Sets the X coordinate in blocks of the top left hand corner of the viewing area.
 void setBlockY(int blockY)
          Sets the Y coordinate in blocks of the top left hand corner of the viewing area.
 void setPillarRiserMode(boolean pillarRiserMode)
          Sets the Pillar Riser Mode, as used in isometric maps.
 void setPixelX(int pixelX)
          Sets the X coordinate in pixels of the top left hand corner of the viewing area.
 void setPixelY(int pixelY)
          Sets the Y coordinate in pixels of the top left hand corner of the viewing area.
 void setViewHeight(int viewHeight)
          Sets the height in pixels of the viewing area.
 void setViewOffsetX(int viewOffsetX)
          Sets the horizontal offset in pixels of the viewing area from the top left hand corner of the screen.
 void setViewOffsetY(int viewOffsetY)
          Sets the vertical offset in pixels of the viewing area from the top left hand corner of the screen.
 void setViewWidth(int viewWidth)
          Sets the width in pixels of the viewing area.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapHeader

protected final MapHeader mapHeader

renderer

protected final Renderer renderer

viewWidth

protected int viewWidth

viewHeight

protected int viewHeight

viewOffsetX

protected int viewOffsetX

viewOffsetY

protected int viewOffsetY

pixelX

protected int pixelX

pixelY

protected int pixelY

pillarRiserMode

protected boolean pillarRiserMode
Constructor Detail

Viewer

public Viewer(MapHeader mapHeader,
              Renderer renderer,
              int viewWidth,
              int viewHeight,
              int viewOffsetX,
              int viewOffsetY)
       throws java.lang.IllegalArgumentException
Creates a Viewer and places the viewing area at the given offset.

Parameters:
mapHeader - contains useful information
renderer - the Renderer to use when drawing
viewWidth - the width of the viewing area in pixels
viewHeight - the height of the viewing area in pixels
viewOffsetX - the initial offset in pixels of the viewing area from the top left hand corner of the screen
viewOffsetY - the initial offset in pixels of the viewing area from the top left hand corner of the screen
Throws:
java.lang.IllegalArgumentException
Method Detail

getViewWidth

public int getViewWidth()
Returns the width in pixels of the viewing area.


setViewWidth

public void setViewWidth(int viewWidth)
                  throws java.lang.IllegalArgumentException
Sets the width in pixels of the viewing area.

Throws:
java.lang.IllegalArgumentException - if viewWidth is less than or equal to zero

getViewHeight

public int getViewHeight()
Returns the height in pixels of the viewing area.


setViewHeight

public void setViewHeight(int viewHeight)
                   throws java.lang.IllegalArgumentException
Sets the height in pixels of the viewing area.

Throws:
java.lang.IllegalArgumentException - if viewWidth is less than or equal to zero

getViewOffsetX

public int getViewOffsetX()
Returns the horizontal offset in pixels of the viewing area from the top left hand corner of the screen.


setViewOffsetX

public void setViewOffsetX(int viewOffsetX)
                    throws java.lang.IllegalArgumentException
Sets the horizontal offset in pixels of the viewing area from the top left hand corner of the screen.

Throws:
java.lang.IllegalArgumentException - if viewOffsetX is less than zero

getViewOffsetY

public int getViewOffsetY()
Returns the vertical offset in pixels of the viewing area from the top left hand corner of the screen.


setViewOffsetY

public void setViewOffsetY(int viewOffsetY)
                    throws java.lang.IllegalArgumentException
Sets the vertical offset in pixels of the viewing area from the top left hand corner of the screen.

Throws:
java.lang.IllegalArgumentException - if viewOffsetX is less than zero

getRenderer

public Renderer getRenderer()
Returns the Renderer associated with this Viewer. This method should not return null.

Returns:
the Renderer associated with this Viewer

getMapHeader

public MapHeader getMapHeader()
Returns the MapHeader associated with this Viewer. This method should not return null.

Returns:
the MapHeader associated with this Viewer

isPillarRiserMode

public boolean isPillarRiserMode()
Returns true is this viewer is in Pillar Riser Mode, used in isometric maps.


setPillarRiserMode

public void setPillarRiserMode(boolean pillarRiserMode)
Sets the Pillar Riser Mode, as used in isometric maps.


getPixelX

public int getPixelX()
Returns the X coordinate in pixels of the top left hand corner of the viewing area.

Returns:
the X coordinate in pixels

setPixelX

public void setPixelX(int pixelX)
Sets the X coordinate in pixels of the top left hand corner of the viewing area.

Parameters:
pixelX - the new X coordinate in pixels

addPixelX

public void addPixelX(int deltaX)
Increments the X coordinate by the given pixel amount. Negative values are allowed.

Parameters:
deltaX - the amount to add to the X coordinate in pixels

getPixelY

public int getPixelY()
Returns the Y coordinate in pixels of the top left hand corner of the viewing area.

Returns:
the Y coordinate in pixels

setPixelY

public void setPixelY(int pixelY)
Sets the Y coordinate in pixels of the top left hand corner of the viewing area.

Parameters:
pixelY - the new Y coordinate in pixels

addPixelY

public void addPixelY(int deltaY)
Increments the Y coordinate by the given pixel amount. Negative values are allowed.

Parameters:
deltaY - the amount to add to the Y coordinate in pixels

getBlockX

public int getBlockX()
Returns the X coordinate in blocks of the top left hand corner of the viewing area.

Returns:
the X coordinate in blocks

setBlockX

public void setBlockX(int blockX)
Sets the X coordinate in blocks of the top left hand corner of the viewing area.

Parameters:
blockX - the new X coordinate in blocks

addBlockX

public void addBlockX(int blockX)
Increments the X coordinate by the given block amount. Negative values are allowed.

Parameters:
blockX - the amount to add to the X coordinate in blocks

getBlockY

public int getBlockY()
Returns the Y coordinate in blocks of the top left hand corner of the viewing area.

Returns:
the Y coordinate in blocks

setBlockY

public void setBlockY(int blockY)
Sets the Y coordinate in blocks of the top left hand corner of the viewing area.

Parameters:
blockY - the new Y coordinate in blocks

addBlockY

public void addBlockY(int blockY)
Increments the Y coordinate by the given block amount. Negative values are allowed.

Parameters:
blockY - the amount to add to the Y coordinate in blocks

draw

public abstract void draw(java.lang.Object objGFX,
                          boolean transparency)
Draws Mappy data into the viewing area.

Parameters:
objGFX - the gfx object specific to the Renderer
transparency - whether or not the background layer of the blocks should be rendered honouring their transparent pixels

draw

public abstract void draw(java.lang.Object objGFX,
                          boolean transparency,
                          int x,
                          int y,
                          int width,
                          int height)
Draws but just a section of the viewing area. To be used when you don't need to render the whole screen, but just part of it.

Parameters:
x - the pixel x coordinate from the left hand side of the viewing area
y - the pixel y coordinate from the top of the viewing area
width - the width, in pixels, of the viewing area to render
height - the height, in pixels, of the viewing area to render


Copyright © 2001-2009 Alien-Factory Ltd. All Rights Reserved.