com.sun.electric.tool.user.redisplay
Class PixelDrawing

java.lang.Object
  extended by com.sun.electric.tool.user.redisplay.PixelDrawing

public class PixelDrawing
extends java.lang.Object

This class manages an offscreen display for an associated EditWindow. It renders an Image for copying to the display.

Every offscreen display consists of two parts: the transparent layers and the opaque image. To tell how a layer is displayed, look at the "transparentLayer" field of its "EGraphics" object. When this is nonzero, the layer is drawn transparent. When this is zero, use the "red, green, blue" fields for the opaque color.

The opaque image is a full-color Image that is the size of the EditWindow. Any layers that are marked "opaque" are drawn in full color in the image. Colors are not combined in the opaque image: every color placed in it overwrites the previous color. For this reason, opaque colors are often stipple patterns, so that they won't completely obscure other opaque layers.

The transparent layers are able to combine with each other. Typically, the more popular layers are made transparent (metal, poly, active, etc.) For every transparent layer, there is a 1-bit deep bitmap that is the size of the EditWindow. The bitmap is an array of "byte []" pointers, one for every Y coordinate in the EditWindow. Each array contains the bits for that row, packed 8 per byte. All of this information is in the "layerBitMaps" field, which is triply indexed.

Thus, to find bit (x,y) of transparent layer T, first lookup the appropriate transparent layer, ("layerBitMaps[T]"). Then, for that layer, find the array of bytes for the appropriate row (by indexing the the Y coordinate into the rowstart array, "layerBitMaps[T][y]"). Next, figure out which byte has the bit (by dividing the X coordinate by 8: "layerBitMaps[T][y][x>>3]"). Finally, determine which bit to use (by using the low 3 bits of the X coordinate, layerBitMaps[T][y][x>>3] & (1 << (x&7)) ).

Transparent layers are not allocated until needed. Thus, if there are 5 possible transparent layers, but only 2 are used, then only two bitplanes will be created.

Each technology declares the number of possible transparent layers that it can generate. In addition, it must provide a color map for describing every combination of transparent layer. This map is, of course, 2-to-the-number-of-possible-transparent-layers long.

The expected number of transparent layers is taken from the current technology. If the user switches the current technology, but draws something from a different technology, then the drawn circuitry may make use of transparent layers that don't exist in the current technology. In such a case, the transparent request is made opaque.

When all rendering is done, the full-color image is composited with the transparent layers to produce the final image. This is done by scanning the full-color image for any entries that were not filled-in. These are then replaced by the transparent color at that point. The transparent color is computed by looking at the bits in every transparent bitmap and constructing an index. This is looked-up in the color table and the appropriate color is used. If no transparent layers are set, the background color is used.

There are a number of efficiencies implemented here.


Field Summary
static int MAXIMUMTEXTSIZE
          Text larger than this is granular.
static int MINIMUMTEXTSIZE
          Text smaller than this will not be drawn.
static int SINGLETONSTOADD
          Number of singleton cells to cache when redisplaying.
 
Constructor Summary
PixelDrawing(java.awt.Dimension sz)
          Constructor creates an offscreen PixelDrawing object.
PixelDrawing(double scale, java.awt.Rectangle screenBounds)
           
 
Method Summary
 void clearImage(java.awt.Rectangle bounds)
          Method to erase the offscreen data in this PixelDrawing.
static void clearSubCellCache()
          Method to clear the cache of expanded subcells.
 java.awt.Image composite(java.awt.Rectangle bounds)
          Method to complete rendering by combining the transparent and opaque imagery.
 void drawText(java.awt.Rectangle rect, Poly.Type style, TextDescriptor descript, java.lang.String s, byte[][] layerBitMap, EGraphics desc, boolean dimmed)
          Method to draw a text on the off-screen buffer
static void forceRedraw(Cell cell)
           
 java.awt.image.BufferedImage getBufferedImage()
          Method for obtaining the rendered image after "drawImage" has finished.
static java.awt.Font getFont(java.lang.String msg, java.lang.String font, int tSize, boolean italic, boolean bold, boolean underline)
           
 java.awt.Dimension getSize()
          Method for obtaining the size of the offscreen bitmap.
 void printImage(double scale, java.awt.geom.Point2D offset, Cell cell, VarContext varContext, GraphicsPreferences gp)
          This is the entry point for rendering.
 void setBackgroundColor(java.awt.Color bg)
          Method to override the background color.
 void setPrintingMode(int mode)
          Method to set the printing mode used for all drawing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MINIMUMTEXTSIZE

public static final int MINIMUMTEXTSIZE
Text smaller than this will not be drawn.

See Also:
Constant Field Values

MAXIMUMTEXTSIZE

public static final int MAXIMUMTEXTSIZE
Text larger than this is granular.

See Also:
Constant Field Values

SINGLETONSTOADD

public static final int SINGLETONSTOADD
Number of singleton cells to cache when redisplaying.

See Also:
Constant Field Values
Constructor Detail

PixelDrawing

public PixelDrawing(java.awt.Dimension sz)
Constructor creates an offscreen PixelDrawing object.

Parameters:
sz - the size of an offscreen PixelDrawinf object.

PixelDrawing

public PixelDrawing(double scale,
                    java.awt.Rectangle screenBounds)
Method Detail

setPrintingMode

public void setPrintingMode(int mode)
Method to set the printing mode used for all drawing.

Parameters:
mode - the printing mode: 0=color display (default), 1=color printing, 2=B&W printing.

setBackgroundColor

public void setBackgroundColor(java.awt.Color bg)
Method to override the background color. Must be called before "drawImage()". This is used by printing, which forces the background to be white.

Parameters:
bg - the background color to use.

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage()
Method for obtaining the rendered image after "drawImage" has finished.

Returns:
an Image for this edit window.

getSize

public java.awt.Dimension getSize()
Method for obtaining the size of the offscreen bitmap.

Returns:
the size of the offscreen bitmap.

clearSubCellCache

public static void clearSubCellCache()
Method to clear the cache of expanded subcells. This is used by layer visibility which, when changed, causes everything to be redrawn.


printImage

public void printImage(double scale,
                       java.awt.geom.Point2D offset,
                       Cell cell,
                       VarContext varContext,
                       GraphicsPreferences gp)
This is the entry point for rendering. It displays a cell in this offscreen window. The rendered Image can then be obtained with "getImage()".


clearImage

public void clearImage(java.awt.Rectangle bounds)
Method to erase the offscreen data in this PixelDrawing. This is called before any rendering is done.

Parameters:
bounds - the area of the image to actually draw (null to draw all).

composite

public java.awt.Image composite(java.awt.Rectangle bounds)
Method to complete rendering by combining the transparent and opaque imagery. This is called after all rendering is done.

Returns:
the offscreen Image with the final display.

forceRedraw

public static void forceRedraw(Cell cell)

drawText

public void drawText(java.awt.Rectangle rect,
                     Poly.Type style,
                     TextDescriptor descript,
                     java.lang.String s,
                     byte[][] layerBitMap,
                     EGraphics desc,
                     boolean dimmed)
Method to draw a text on the off-screen buffer


getFont

public static java.awt.Font getFont(java.lang.String msg,
                                    java.lang.String font,
                                    int tSize,
                                    boolean italic,
                                    boolean bold,
                                    boolean underline)