If you think the Android project android-augment-reality-framework 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
package com.jwetherell.augmented_reality.ui.objects;
/*www.java2s.com*/import android.graphics.Canvas;
import android.graphics.Color;
/**
* This class extends PaintableObject to draw an outlined box.
*
* @author Justin Wetherell <phishman3579@gmail.com>
*/publicclass PaintableBox extends PaintableObject {
privatefloat width = 0, height = 0;
privateint borderColor = Color.rgb(255, 255, 255);
privateint backgroundColor = Color.argb(128, 0, 0, 0);
public PaintableBox(float width, float height) {
this(width, height, Color.rgb(255, 255, 255), Color.argb(128, 0, 0, 0));
}
public PaintableBox(float width, float height, int borderColor, int bgColor) {
set(width, height, borderColor, bgColor);
}
/**
* Set this objects parameters. This should be used instead of creating new
* objects.
*
* @param width
* width of the box.
* @param height
* height of the box.
*/publicvoid set(float width, float height) {
set(width, height, borderColor, backgroundColor);
}
/**
* Set this objects parameters. This should be used instead of creating new
* objects.
*
* @param width
* width of the box.
* @param height
* height of the box.
* @param borderColor
* Color of the border.
* @param bgColor
* Background color of the surrounding box.
*/publicvoid set(float width, float height, int borderColor, int bgColor) {
this.width = width;
this.height = height;
this.borderColor = borderColor;
this.backgroundColor = bgColor;
}
/**
* {@inheritDoc}
*/
@Override
publicvoid paint(Canvas canvas) {
if (canvas == null) thrownew NullPointerException();
canvas.save();
canvas.translate(-width/2, -height/2);
setFill(true);
setColor(backgroundColor);
paintRect(canvas, x, y, width, height);
setFill(false);
setColor(borderColor);
paintRect(canvas, x, y, width, height);
canvas.restore();
}
/**
* {@inheritDoc}
*/
@Override
publicfloat getWidth() {
return width;
}
/**
* {@inheritDoc}
*/
@Override
publicfloat getHeight() {
return height;
}
}