ch.sahits.game.graphic.display.util
Class OffsetCalculator

java.lang.Object
  extended by ch.sahits.game.graphic.display.util.OffsetCalculator

public final class OffsetCalculator
extends Object

This helper class lets you calculate the relative offset in an overlayed image. This is needed if you place your image not at a fixed distance from the right border or the top. As with different screen resolutions you would like it to have it placed 150px to the left of the right border. What you actually want is not the offset of the image but a point within. Defining the image you know the relative location within the image, but you need to know the absolute position on the screen. This helper class lets you compute these coordinates.

Author:
Andi Hotz, (c) Sahits GmbH, 2011 Created on Mar 4, 2011

Field Summary
private  int xOff
           
private  int yOff
           
 
Constructor Summary
OffsetCalculator(int xOff, int yOff)
          Initialize the offset of the image.
 
Method Summary
 Point computeOffset(int relativeXOffset, double xScale, int relativeYOffset, double yScale)
          Compute the absolute offset of the point in the case that the relative offsets are scaled dynamically.
 Point computeOffset(int relativeXOffset, int relativeYOffset)
          Compute the absolute offset of the point
 int computeXOffset(int relativeXOffset)
          Compute the absolute offset of the point X
 int computeXOffset(int relativeXOffset, double xScale)
          Compute the absolute offset of the point X in the case that the relative offset is scaled dynamically
 int computeYOffset(int relativeYOffset)
          Compute the absolute offset of the point Y
 int computeYOffset(int relativeYOffset, double yScale)
          Compute the absolute offset of the point Y in the case that the relative offset is scaled dynamically
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xOff

private final int xOff

yOff

private final int yOff
Constructor Detail

OffsetCalculator

public OffsetCalculator(int xOff,
                        int yOff)
Initialize the offset of the image. These are the absolute coordinates of the top left corner of the image on the screen.

Parameters:
xOff - Offset in direction X (to the right)
yOff - Offset in direction Y (down)
Method Detail

computeXOffset

public int computeXOffset(int relativeXOffset)
Compute the absolute offset of the point X

Parameters:
relativeXOffset - relative offset (in relation to the image) of X
Returns:
absolute offset of X

computeYOffset

public int computeYOffset(int relativeYOffset)
Compute the absolute offset of the point Y

Parameters:
relativeYOffset - relative offset (in relation to the image) of Y
Returns:
absolute offset of Y

computeOffset

public Point computeOffset(int relativeXOffset,
                           int relativeYOffset)
Compute the absolute offset of the point

Parameters:
relativeYOffset - relative offset (in relation to the image) of Y
relativeYOffset - relative offset (in relation to the image) of Y
Returns:
absolute offset

computeXOffset

public int computeXOffset(int relativeXOffset,
                          double xScale)
Compute the absolute offset of the point X in the case that the relative offset is scaled dynamically

Parameters:
relativeXOffset - relative offset (in relation to the image) of X
Returns:
absolute offset of X

computeYOffset

public int computeYOffset(int relativeYOffset,
                          double yScale)
Compute the absolute offset of the point Y in the case that the relative offset is scaled dynamically

Parameters:
relativeYOffset - relative offset (in relation to the image) of Y
Returns:
absolute offset of Y

computeOffset

public Point computeOffset(int relativeXOffset,
                           double xScale,
                           int relativeYOffset,
                           double yScale)
Compute the absolute offset of the point in the case that the relative offsets are scaled dynamically.

Parameters:
relativeYOffset - relative offset (in relation to the image) of Y
relativeYOffset - relative offset (in relation to the image) of Y
Returns:
absolute offset


Copyright © 2011 Sahits GmbH. All Rights Reserved.