If you think the Android project DolphinOES listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*******************************************************************************
* Copyright 2015 See AUTHORS file./*fromwww.java2s.com*/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/package com.sidereal.dolphinoes.behaviors.renderer.texture;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.math.Vector2;
import com.sidereal.dolphinoes.behaviors.renderer.DrawerBuilder;
/** Builder for {@link TextureDrawer}. Required parameter is a string for the
* filepath used for retrieving a {@link Texture}.
*
* @author Claudiu Bele */publicclass TextureBuilder extends DrawerBuilder<TextureDrawer>
{
// region fields
/** Path to the texture. Set in the constructor */private String filePath;
/** Offset position from the {@link #MISSING()}. Is set by
* Default to 0,0 the bottom-left corner of the texture being rendered at
* that position. */private Vector2 offsetPosition;
/** Size of the texture to draw. Is set by default to the the texture's width
* and height if no value is passed */private Vector2 size;
// endregion fields
// region constructors
public TextureBuilder(String filePath)
{
if (filePath == null)
thrownew NullPointerException(
"Passed null String parameter to TextBuilder.TextBuilder(String)");
this.size = new Vector2(50, 50);
this.offsetPosition = new Vector2();
this.filePath = filePath;
}
// endregion constructors
// region methods
@Override
protected TextureDrawer build(String name)
{
TextureDrawer drawer = new TextureDrawer(renderer, name, filePath);
drawer.setOffsetPosition(offsetPosition);
drawer.setSize(size);
return drawer;
}
public TextureBuilder setOffsetPosition(float x, float y)
{
if (offsetPosition == null)
offsetPosition = new Vector2(x, y);
else
offsetPosition.set(x, y);
returnthis;
}
/** Sets the size. It can be null, as if it is, it will be set to the
* texture's size in {@link TextureDrawer#setSize(Vector2)} automatically.
*
* @param x
* the width
* @param y
* the height
* @return */public TextureBuilder setSize(float x, float y)
{
if (size == null)
size = new Vector2(x, y);
else
size.set(x, y);
returnthis;
}
/** Sets the size. It can be null, as if it is, it will be set to the
* texture's size in {@link TextureDrawer#setSize(Vector2)} automatically.
*
* @param size
* @return */public TextureBuilder setSize(Vector2 size)
{
if (size == null)
returnthis;
return setSize(size.x, size.y);
}
public TextureBuilder setOffsetPosition(Vector2 position)
{
if (position == null)
thrownew NullPointerException(
"Passed null Vector2 parameter to TextBuilder.setOffsetPosition(Vector2)");
return setOffsetPosition(position.x, position.y);
}
// endregion methods
}