PaintScreen.java :  » Game » iseek » org » mixare » gui » Android Open Source

Android Open Source » Game » iseek 
iseek » org » mixare » gui » PaintScreen.java
/*
 * Copyright (C) 2010- Peer internet solutions
 * 
 * This file is part of mixare.
 * 
 * This program 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. 
 * 
 * This program 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 
 * this program. If not, see <http://www.gnu.org/licenses/>
 */
package org.mixare.gui;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class PaintScreen {
  Canvas canvas;
  int width, height;
  Paint paint = new Paint();
  Paint bPaint = new Paint();

  public PaintScreen() {
    paint.setTextSize(16);
    paint.setAntiAlias(true);
    paint.setColor(Color.BLUE);
    paint.setStyle(Paint.Style.STROKE);
  }

  public Canvas getCanvas() {
    return canvas;
  }

  public void setCanvas(Canvas canvas) {
    this.canvas = canvas;
  }

  public void setWidth(int width) {
    this.width = width;
  }

  public void setHeight(int height) {
    this.height = height;
  }

  public int getWidth() {
    return width;
  }

  public int getHeight() {
    return height;
  }

  public void setFill(boolean fill) {
    if (fill)
      paint.setStyle(Paint.Style.FILL);
    else
      paint.setStyle(Paint.Style.STROKE);
  }

  public void setColor(int c) {
    paint.setColor(c);
  }

  public void setStrokeWidth(float w) {
    paint.setStrokeWidth(w);
  }

  public void paintLine(float x1, float y1, float x2, float y2) {
    canvas.drawLine(x1, y1, x2, y2, paint);
  }

  public void paintRect(float x, float y, float width, float height) {
    canvas.drawRect(x, y, x + width, y + height, paint);
  }

  public void paintCircle(float x, float y, float radius) {
    canvas.drawCircle(x, y, radius, paint);
  }

  public void paintText(float x, float y, String text) {
    canvas.drawText(text, x, y, paint);
  }

  public void paintObj(ScreenObj obj, float x, float y, float rotation,
      float scale) {
    canvas.save();
    canvas.translate(x + obj.getWidth() / 2, y + obj.getHeight() / 2);
    canvas.rotate(rotation);
    canvas.scale(scale, scale);
    canvas.translate(-(obj.getWidth() / 2), -(obj.getHeight() / 2));
    obj.paint(this);
    canvas.restore();
  }

  public float getTextWidth(String txt) {
    return paint.measureText(txt);
  }

  public float getTextAsc() {
    return -paint.ascent();
  }

  public float getTextDesc() {
    return paint.descent();
  }

  public float getTextLead() {
    return 0;
  }

  public void setFontSize(float size) {
    paint.setTextSize(size);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.