/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * AndroidWorld Library, Copyright 2011 Bryan Chadwick * * * * FILE: ./android/image/Rectangle.java * * * * This file is part of AndroidWorld. * * * * AndroidWorld is free software: you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation, either version * * 3 of the License, or (at your option) any later version. * * * * AndroidWorld is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with AndroidWorld. If not, see . * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ package android.image; import android.graphics.Canvas; import android.graphics.Paint; /** * * * Represents an Image of a Rectangle. * *
 *    new Rectangle(40, 20, "outline", "black")
* *
* *
 *    new Rectangle(20, 40, "solid", "blue")
* *
* */ public class Rectangle extends Image{ double width; double height; int mode; Paint paint; /** Create a Rectangle Image with (double) width and height, mode and color */ public Rectangle(double width, double height, String mode, String color){ this(width,height,mode(mode),color(color)); } /** Create a Rectangle Image with (int) width and height, mode and color */ public Rectangle(int width, int height, String mode, String color){ this((double)width,height,mode,color); } /** Create a Rectangle with converted mode and color */ private Rectangle(double width, double height, int mode, int color){ super(width/2, height/2); this.width = width; this.height = height; this.mode = mode; this.paint = painter(color,mode); } /** Paint this Scene into the given graphics */ public void paint(Canvas g, int x, int y){ g.drawRect((float)(x-width/2),(float)(y-height/2),(float)(x+width/2),(float)(y+height/2), paint); } /** Return the Width of this Image */ public int width(){ return ceil(width); } /** Return the Height of this Image */ public int height(){ return ceil(height); } }