📄 layerdrawing.java
字号:
// public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}// public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}// } } static void drawTechPalette(Graphics2D g, int imgX, int imgY, Rectangle entrySize, double scale, VectorCache.VectorBase[] shapes) { BufferedImage smallImg = new BufferedImage(entrySize.width, Drawing.SMALL_IMG_HEIGHT, BufferedImage.TYPE_INT_RGB); DataBufferInt smallDbi = (DataBufferInt)smallImg.getRaster().getDataBuffer(); int[] smallOpaqueData = smallDbi.getData(); LayerDrawing offscreen = new LayerDrawing(new Dimension(entrySize.width, entrySize.height)); // set colors to use LayerDrawing.textColor = new Color(User.getColor(User.ColorPrefType.TEXT)); LayerDrawing.textGraphics.setColor(LayerDrawing.textColor); // initialize the cache of expanded cell displays// varContext = wnd.getVarContext(); offscreen.initOrigin(scale, EPoint.ORIGIN); offscreen.renderedWindow = true; offscreen.patternedDisplay = true; offscreen.canDrawText = true; offscreen.canDrawRelativeText = 0; // remember the true window size (since recursive calls may cache individual cells that are smaller)// topSz = sz; // initialize rendering into the offscreen image offscreen.clipLX = 0; offscreen.clipHX = offscreen.sz.width - 1; offscreen.clipLY = 0; offscreen.clipHY = offscreen.sz.height - 1; offscreen.clearImage(null); // now render it all offscreen.renderTextList.clear(); offscreen.greekTextList.clear(); offscreen.crossTextList.clear(); ArrayList<VectorCache.VectorBase> shapeList = new ArrayList<VectorCache.VectorBase>(); for (VectorCache.VectorBase shape: shapes) shapeList.add(shape); offscreen.drawList(0, 0, shapeList); AlphaBlender alphaBlender = new AlphaBlender(); Map<Layer,int[]> layerBits = new HashMap<Layer,int[]>(); for (Map.Entry<Layer,TransparentRaster> e: offscreen.layerRasters.entrySet()) layerBits.put(e.getKey(), e.getValue().layerBitMap); List<AbstractDrawing.LayerColor> blendingOrder = getBlendingOrderForTechPalette(layerBits.keySet()); if (TAKE_STATS) { System.out.print("BlendingOrder:"); for (AbstractDrawing.LayerColor lc: blendingOrder) { int alpha = (int)((1 - lc.inverseAlpha) * 100 + 0.5); System.out.print(" " + lc.layer.getName() + ":" + alpha); } System.out.println(); } alphaBlender.init(User.getColor(User.ColorPrefType.BACKGROUND), blendingOrder, layerBits); int width = offscreen.sz.width; int height = offscreen.sz.height, clipLY = 0, clipHY = height - 1; int numIntsPerRow = offscreen.numIntsPerRow; int baseByteIndex = 0; int y = 0; while (y < height) { int h = Math.min(Drawing.SMALL_IMG_HEIGHT, height - y); int baseIndex = 0; for (int k = 0; k < h; k++) { alphaBlender.composeLine(baseByteIndex, 0, width - 1, smallOpaqueData, baseIndex); baseByteIndex += numIntsPerRow; baseIndex += width; } g.drawImage(smallImg, imgX, imgY + y, null); y += h; } g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); for (RenderTextInfo textInfo: offscreen.renderTextList) { textInfo.offX += imgX; textInfo.offY += imgY; textInfo.draw(g); }// needComposite = true;// layerRasters = new HashMap<Layer,TransparentRaster>(offscreen.layerRasters);// greekText = offscreen.greekTextList.toArray(new GreekTextInfo[offscreen.greekTextList.size()]);// crossText = offscreen.crossTextList.toArray(new CrossTextInfo[offscreen.crossTextList.size()]);// renderText = offscreen.renderTextList.toArray(new RenderTextInfo[offscreen.renderTextList.size()]); } private static List<AbstractDrawing.LayerColor> getBlendingOrderForTechPalette(Set<Layer> layersAvailable) { boolean alphaBlendingOvercolor = true; ArrayList<AbstractDrawing.LayerColor> layerColors = new ArrayList<AbstractDrawing.LayerColor>(); ArrayList<Layer> sortedLayers = new ArrayList<Layer>(layersAvailable); Collections.sort(sortedLayers, Technology.LAYERS_BY_HEIGHT_LIFT_CONTACTS); float[] backgroundComps = (new Color(User.getColor(User.ColorPrefType.BACKGROUND))).getRGBColorComponents(null); float bRed = backgroundComps[0]; float bGreen = backgroundComps[1]; float bBlue = backgroundComps[2]; for(Layer layer : sortedLayers) { Color color = new Color(layer.getGraphics().getRGB()); float[] compArray = color.getRGBComponents(null); float red = compArray[0]; float green = compArray[1]; float blue = compArray[2]; float opacity = 0.7f; float inverseAlpha = 1 - opacity; if (alphaBlendingOvercolor) { red -= bRed*inverseAlpha; green -= bGreen*inverseAlpha; blue -= bBlue*inverseAlpha; } else { red *= opacity; green *= opacity; blue *= opacity; } layerColors.add(new AbstractDrawing.LayerColor(layer, red, green, blue, inverseAlpha)); } return layerColors; } // ************************************* TOP LEVEL ************************************* /** * Constructor creates an offscreen PixelDrawing object. * @param sz the size of an offscreen PixelDrawinf object. */ public LayerDrawing(Dimension sz) { this.sz = new Dimension(sz); width = sz.width; clipLX = 0; clipHX = sz.width - 1; clipLY = 0; clipHY = sz.height - 1; // allocate pointer to the opaque image total = sz.height * sz.width; numIntsPerRow = (sz.width + Integer.SIZE - 1) / Integer.SIZE; renderedWindow = true; } public LayerDrawing(double scale, int lX, int hX, int lY, int hY) { this.scale = scale; scale_ = (float)(scale/DBMath.GRID); this.originX = -lX; this.originY = hY; factorX = (float)(-originX/scale_); factorY = (float)(originY/scale_); this.sz = new Dimension(hX - lX + 1, hY - lY + 1); width = sz.width; clipLX = 0; clipHX = sz.width - 1; clipLY = 0; clipHY = sz.height - 1; // allocate pointer to the opaque image total = sz.height * sz.width; numIntsPerRow = (sz.width + Integer.SIZE - 1) / Integer.SIZE; } void initOrigin(double scale, Point2D offset) { this.scale = scale; scale_ = (float)(scale/DBMath.GRID); this.originX = sz.width/2 - offset.getX()*scale; this.originY = sz.height/2 + offset.getY()*scale; factorX = (float)(offset.getX()*DBMath.GRID - sz.width/2/scale_); factorY = (float)(offset.getY()*DBMath.GRID + sz.height/2/scale_); } /** * Method to set the printing mode used for all drawing. * @param mode the printing mode: 0=color display (default), 1=color printing, 2=B&W printing. */ public void setPrintingMode(int mode) { nowPrinting = mode; } /** * Method for obtaining the size of the offscreen bitmap. * @return the size of the offscreen bitmap. */ public Dimension getSize() { return sz; } /** * Method to clear the cache of expanded subcells. * This is used by layer visibility which, when changed, causes everything to be redrawn. */ public static void clearSubCellCache() { expandedCells = new HashMap<ExpandedCellKey,ExpandedCellInfo>(); } /** * This is the entry point for rendering. * It displays a cell in this offscreen window. * @param fullInstantiate true to display to the bottom of the hierarchy (for peeking). * @param drawLimitBounds the area in the cell to display (null to show all). * The rendered Image can then be obtained with "getImage()". */ private void drawImage(Drawing drawing, boolean fullInstantiate, Rectangle2D drawLimitBounds) { long startTime = 0, clearTime = 0, countTime = 0; long initialUsed = 0; if (TAKE_STATS) {// Runtime.getRuntime().gc(); startTime = System.currentTimeMillis(); initialUsed = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); tinyCells = tinyPrims = totalCells = renderedCells = totalPrims = tinyArcs = linedArcs = totalArcs = 0; offscreensCreated = offscreenPixelsCreated = offscreensUsed = offscreenPixelsUsed = cellsRendered = 0; offscreensUsedSet.clear(); boxArrayCount = boxCount = boxDisplayCount = lineCount = polygonCount = crossCount = circleCount = discCount = arcCount = 0; } if (fullInstantiate != lastFullInstantiate) { clearSubCellCache(); lastFullInstantiate = fullInstantiate; } EditWindow wnd = drawing.wnd; Cell cell = wnd.getInPlaceEditTopCell(); List<NodeInst> inPlaceNodePath = wnd.getInPlaceEditNodePath(); if (inPlaceNodePath.isEmpty()) { inPlaceSubcellPath = null; } else { inPlaceSubcellPath = new BitSet(); for (NodeInst ni: inPlaceNodePath) { Cell subCell = (Cell)ni.getProto(); inPlaceSubcellPath.set(subCell.getId().cellIndex); } } inPlaceCurrent = wnd.getCell(); // set colors to use textColor = new Color(User.getColor(User.ColorPrefType.TEXT)); textGraphics.setColor(textColor); instanceGraphics.setColor(new Color(User.getColor(User.ColorPrefType.INSTANCE))); gridGraphics.setColor(new Color(User.getColor(User.ColorPrefType.GRID))); // initialize the cache of expanded cell displays if (expandedScale != drawing.da.scale) { clearSubCellCache(); expandedScale = drawing.da.scale; } varContext = wnd.getVarContext(); initOrigin(expandedScale, new Point2D.Double(drawing.da.offX, drawing.da.offY)); patternedDisplay = expandedScale > User.getPatternedScaleLimit(); alphaBlendingOvercolor = expandedScale > User.getAlphaBlendingOvercolorLimit(); canDrawText = expandedScale > 1; canDrawRelativeText = canDrawText ? 0 : MINIMUMTEXTSIZE; maxObjectSize = 2 / expandedScale; halfMaxObjectSize = maxObjectSize / 2; // remember the true window size (since recursive calls may cache individual cells that are smaller) topSz = sz; // see if any layers are being highlighted/dimmed highlightingLayers = false; for(Iterator<Layer> it = Technology.getCurrent().getLayers(); it.hasNext(); ) { Layer layer = it.next(); if (layer.isDimmed()) { highlightingLayers = true; break; } } // initialize rendering into the offscreen image Rectangle renderBounds = null; if (drawLimitBounds != null) { renderBounds = databaseToScreen(drawLimitBounds); clipLX = Math.max(renderBounds.x, 0); clipHX = Math.min(renderBounds.x + renderBounds.width, sz.width) - 1; clipLY = Math.max(renderBounds.y, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -