org.refcodes.checkerboard.CheckerboardViewer Maven / Gradle / Ivy
package org.refcodes.checkerboard;
import org.refcodes.component.Initializable.InitializeBuilder;
import org.refcodes.component.InitializableComponent;
import org.refcodes.graphical.GridDimension;
import org.refcodes.graphical.GridModeAccessor;
import org.refcodes.graphical.MinViewportDimension.MinViewportDimensionBuilder;
import org.refcodes.graphical.MinViewportDimension.MinViewportDimensionProperty;
import org.refcodes.graphical.Viewport;
import org.refcodes.graphical.ViewportDimension.ViewportDimensionBuilder;
import org.refcodes.graphical.ViewportDimension.ViewportDimensionProperty;
import org.refcodes.graphical.ViewportOffset.ViewportOffsetBuilder;
import org.refcodes.graphical.ViewportOffset.ViewportOffsetProperty;
import org.refcodes.graphical.ViewportWidthAccessor.ViewportWidthBuilder;
import org.refcodes.graphical.ViewportWidthAccessor.ViewportWidthProperty;
/**
* The Interface CheckerboardViewer.
*
* @param The type representing a {@link Player}
* @param The type which's instances represent a {@link Player} state.
* @param The {@link CheckerboardViewer}'s type implementing this
* interface.
*/
public interface CheckerboardViewer, S, CBV extends CheckerboardViewer
> extends CheckerboardObserver
, Viewport, ViewportDimensionProperty, ViewportDimensionBuilder, MinViewportDimensionProperty, MinViewportDimensionBuilder, ViewportWidthProperty, ViewportWidthBuilder, ViewportOffsetProperty, ViewportOffsetBuilder, GridDimension, GridModeAccessor, InitializableComponent, InitializeBuilder {
/**
* {@inheritDoc}
*/
@Override
default void centerViewortOffset( int aPositionX, int aPositionY ) {
centerViewortOffset( aPositionX, aPositionY, getViewportWidth(), getViewportHeight() );
}
/**
* {@inheritDoc}
*/
@Override
default void centerViewortOffset( int aPositionX, int aPositionY, int aViewportWidth, int aViewportHeight ) {
int theGridWidth = getGridWidth();
int theGridHeight = getGridHeight();
int theOffsetX = aPositionX - (aViewportWidth / 2);
int theOffsetY = aPositionY - (aViewportHeight / 2);
if ( theOffsetX > theGridWidth - aViewportWidth ) theOffsetX = theGridWidth - aViewportWidth;
if ( theOffsetY > theGridHeight - aViewportHeight ) theOffsetY = theGridHeight - aViewportHeight;
if ( theOffsetX < 0 ) theOffsetX = 0;
if ( theOffsetY < 0 ) theOffsetY = 0;
setViewportOffset( -theOffsetX, -theOffsetY );
}
}