playfieldgraphic.java

来自「The ONE is a Opportunistic Network Envir」· Java 代码 · 共 73 行

JAVA
73
字号
/*  * Copyright 2008 TKK/ComNet * Released under GPLv3. See LICENSE.txt for details.  */package gui.playfield;

import java.awt.Graphics2D;

/**
 * Superclass for all graphics to be drawn on the "play field".
 */
public abstract class PlayFieldGraphic {
	/** Common scaling factor for all playfield graphics.
	 * @see #setScale(double)
	 */
	protected static double scale = 1;
		
	/**
	 * Set the zooming factor of the graphics to be drawn
	 * @param newScale New scale
	 */
	public static void setScale(double newScale) {
		scale = newScale;
	}

	/**
	 * Returns the currently used scaling factor
	 * @return The scaling factor
	 */
	public static double getScale() {
		return scale;
	}
	
	/**
	 * Draws the graphic component to the graphics context g2
	 * @param g2 The context to draw the graphics to
	 */
	public abstract void draw(Graphics2D g2);

	
	/**
	 * Scales the value according to current zoom level
	 * @param value Value to scale
	 * @return Scaled value bit-truncated (casted) to an integer
	 */
	public static int scale(double value) {
		return (int)Math.round(scale * value);
	}

	/**
	 * Scales the value according to current zoom level
	 * @param value Value to scale
	 * @return Scaled value bit-truncated (casted) to an integer
	 */
	public static int scale(int value) {
		return (int)Math.round(scale * value);
	}
	
	/**
	 * Performs an inverse of the scaling procedure with current scale.
	 * NOTE: invScale(scale(value)) != value because of rounding to integer
	 * at scale() -methods
	 * @param value The value to inverse-scale
	 * @return Inverse-scaled value
	 * @see #scale(double) 
	 */
	public static double invScale(double value) {
		return value/scale;
	}
	

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?