⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glyph.java

📁 一个基于PlaceLab的室内和室外的智能导航系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			    			    Image buffer = new Image(holder.getDisplay(), getBoundsImpl());			    GC innerGC = new GC(buffer);			    GlyphGC tempGC = new GlyphGC(innerGC);			    			    // make the glyph paint into it			    paintImpl(e, tempGC);			    			    // now mask the image			    ImageData temp = buffer.getImageData();			    			    if(this.getMaskColor() != null) {				    int maskRed = this.getMaskColor().getRed();				    int maskBlue = this.getMaskColor().getBlue();				    int maskGreen = this.getMaskColor().getGreen();					int[] lineData = new int[temp.width];					for (int y = 0; y < temp.height; y++) {						temp.getPixels(0,y,temp.width,lineData,0);						// Analyze each pixel value in the line						for (int x=0; x<lineData.length; x++){							// Extract the red, green and blue component							int pixelValue = lineData[x];							int r = temp.palette.getRGB(pixelValue).red;							int g = temp.palette.getRGB(pixelValue).green;							int b = temp.palette.getRGB(pixelValue).blue;							// if the pixel rgb value is a linear combination of the 							// mask rgb value then choose an appropriate alpha.  							// if it isn't, then make the pixel opaque							double rScale = 1.0 - (double)r / (double)maskRed;							double gScale = 1.0 - (double)g / (double)maskGreen;							double bScale = 1.0 - (double)b / (double)maskBlue;							/*System.out.println("x:" + x + " " +											   "y:" + y + " " +											   "rgb:" + r + "," + g + "," + b + " " +											   "rgbScale:" + rScale + "," + gScale + "," + bScale);*/							int opacity = this.transparency;							if(Math.abs(rScale - gScale) < 0.01								&& Math.abs(rScale - bScale) < 0.01) {								if(rScale < 1.0) {									// map the scale from 0 to 1 into 0 to transparency									opacity = (int)((double)transparency * rScale);								}							}							// note that it is important to set an alpha value							// for every pixel, not just those that are less than 255							temp.setAlpha(x, y, opacity);						}					}			    }			    			    this.setLocation(oldLocation);			    this.setZoom(oldZoom);			    			    // now transform it using the transform			    ImageData transformedImageData;			    try {			        transformedImageData = transform.transformImage(temp, 			                AffineTransform.NEAREST_NEIGHBOR);				    transformedImage = new Image(holder.getDisplay(), transformedImageData);				    gc.drawImage(transformedImage, getBounds().x, getBounds().y);			    } catch (AffineTransform.NotInvertibleException nie) {			        // if its not invertible, i can't make a sensible onscreen representation of it			        // so forget about it			        Logger.println("couldn't draw glyph " + this + " because it has a noninvertible transform attached",			                Logger.HIGH);			        return;			    } finally {				    tempGC.dispose();				    buffer.dispose();				    innerGC.dispose();			    }			    this.setNeedsTransformRedraw(false);		    } else {		        gc.drawImage(transformedImage, getBounds().x, getBounds().y);		    }		    		} else {		    paintImpl(e, gc);		}	}		/**	 * Implement this if you don't want to worry about AffineTransforms.  Your	 * graphics will be rasterized and have an AffineTransform applied to them	 */	protected void paintImpl(PaintEvent e, GlyphGC gc) { }		/**	 * Because swt cannot draw into an image and leave the pixels in the image	 * not drawn on in a transparent state and make the other pixels opaque, Glyphs	 * must set a mask color which stands for transparent.  You may return	 * null if you don't need any areas masked out.	 */	protected Color getMaskColor() {	    return new Color(holder.getDisplay(), 255, 255, 255);	}		/**	 * Return true here if your glyph needs to have its transform image recalculated	 * That is, if its changed anywhere that will matter, return true.	 * If it hasn't, return false and you get the cached image so we don't waste a bunch	 * of time transforming images, which is not fast I might add.	 */	protected boolean getNeedsTransformRedraw() {	    return needsTransformRedraw;	}		protected void setNeedsTransformRedraw(boolean flag) {	    needsTransformRedraw = flag;	}		public void handleMouseEvent(int eventType, MouseEvent e) {		notifyListeners(eventType, GlyphEventTable.getEvent(e));	}	public Glyph pickGlyphAt(int x, int y, boolean checkMouseEnabled) {		if (! isVisible()) return null;		if (checkMouseEnabled && !areMouseEventsEnabled()) 			return null;		return (pointInside(x, y) ? this : null);	}	public void redraw(Rectangle invalidate) {	    this.setNeedsTransformRedraw(true);	    if (!isVisible()) return;		Rectangle r = getBounds();		if (invalidate != null && r.intersects(invalidate)) {			r = r.union(invalidate);		} else if (invalidate != null) {			if (parent != null) {				Point p = parent.toHolder					(new Point(invalidate.x,invalidate.y));				invalidate.x = p.x;				invalidate.y = p.y;			}			getHolder().redraw(invalidate.x, invalidate.y, 					   invalidate.width,invalidate.height, 					   true);		}		if (parent != null) {			Point p = parent.toHolder(new Point(r.x, r.y));			r.x = p.x;			r.y = p.y;		}		getHolder().redraw(r.x, r.y, r.width, r.height, true);	}	public void setVisible(boolean visible) {		if (getFlag(Glyph.VISIBLE) == visible) return;		if (visible) setFlag(Glyph.VISIBLE);		else resetFlag(Glyph.VISIBLE);		Rectangle r = getBounds();		getHolder().redraw(r.x, r.y, r.width, r.height, true);	}	public boolean isVisible() { return getFlag(Glyph.VISIBLE); }	public void enableMouseEvents(boolean enable) {		if (enable) setFlag(Glyph.MOUSE_EVENTS);		else resetFlag(Glyph.MOUSE_EVENTS);	}	public boolean areMouseEventsEnabled() { 		return getFlag(Glyph.MOUSE_EVENTS); 	}	public Rectangle getBounds() {	    if(transform != null) {	        return transform.getBoundingRect(getBoundsImpl());	    } else {	        return getBoundsImpl();	    }	}		public boolean pointInside(int x, int y) {	    if(transform != null) {	        Point transformed;	        try {	            transformed = transform.inverseTransform(new Point(x, y));	        } catch (AffineTransform.NotInvertibleException nie) {	            // if its not invertible, its not drawable, so the mouse isn't inside	            // it	            return false;	        }	        return pointInsideImpl(transformed.x, transformed.y);	    } else {	        return pointInsideImpl(x, y);	    }	}		/**	 * @return your bounds without having the AffineTransform applied to them	 */	protected abstract Rectangle getBoundsImpl();	/**	 * Return if the point is inside your glyph without the AffineTransform applied	 */	protected abstract boolean pointInsideImpl(int x, int y);	public boolean pointInside(Point p) { return pointInside(p.x, p.y); }	public void moveAbove(Glyph glyph) {		if (parent == null) 			throw new IllegalArgumentException("cannot rearrange root of the glyph hierarchy");				if (glyph != null && parent != glyph.getParent())			throw new IllegalArgumentException("glyph is not a sibling");		parent.moveAbove(this, glyph);			}	public void moveBelow(Glyph glyph) {		if (parent == null) 			throw new IllegalArgumentException("cannot rearrange root of the glyph hierarchy");				if (glyph != null && parent != glyph.getParent())			throw new IllegalArgumentException("glyph is not a sibling");		parent.moveBelow(this, glyph);			}	public void setCursor(Cursor cursor) {		this.cursor = cursor;		if (holder.activeCursorGlyph() != this) return;		/* we need to reset the cursor */		activateCursor();	}	void activateCursor() {		if (cursor != null) {			holder.activateCursor(cursor, this);			return;		}		Glyph p = parent;		while (p != null) {			if (p.cursor != null) {				holder.activateCursor(p.cursor, p);				return;			}			p = p.parent;		}		holder.activateCursor();	}	protected void enter(MouseEvent e) {	}	protected void leave(MouseEvent e) {	}}

⌨️ 快捷键说明

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