📄 nativegraphics.java
字号:
}public void fillRect ( int x, int y, int width, int height ){ Toolkit.graFillRect( nativeData, x, y, width, height);}public void fillRoundRect ( int x, int y, int width, int height, int arcWidth, int arcHeight ){ Toolkit.graFillRoundRect( nativeData, x, y, width, height, arcWidth, arcHeight);}protected void finalize () throws Throwable { if ( nativeData != null ) { Toolkit.graFreeGraphics( nativeData); nativeData = null; } super.finalize();}Color getBackColor () { return background;}public Shape getClip (){ return (getClipRect());}public Rectangle getClipBounds(Rectangle rect) { rect.x = xClip; rect.y = yClip; rect.width = wClip; rect.height = hClip; return rect;}int getClipHeight () { return hClip;}int getClipWidth () { return wClip;}int getClipX () { return xClip;}int getClipY () { return yClip;}static NativeGraphics getClippedGraphics ( NativeGraphics g, Component c, int xOff, int yOff, int xClip, int yClip, int wClip, int hClip, boolean blank ) { // A bit misnomed, this method returns a NativeGraphics object that is // propperly clipped to its (insetted) parents. The object can either be // a fresh one (with fonts and colors from its target), or a already used, // resident one (in this case this is mainly a native initialization) Container p; Color fg, bg; Font fnt; if ( (c.flags & Component.IS_ADD_NOTIFIED) == 0 ) return null; if ( g == null ) { fg = c.foreground; bg = c.background; fnt = c.font; } else { // otherwise, the silly compiler complains about missing init fg = g.foreground; bg = g.background; fnt = g.font; } while ( true ) { if ( c.parent == null ) { if ( (Toolkit.flags & Toolkit.EXTERNAL_DECO) != 0 ) { // compensate the artificial Frame decoration offsets (NOT insets) // note that this requires the graphics offset to be private xOff -= c.deco.x; yOff -= c.deco.y; } if ( g == null ){ return getGraphics( c, ((Window)c).nativeData, TGT_TYPE_WINDOW, xOff, yOff, xClip, yClip, wClip, hClip, fg, bg, fnt, blank); } else { Toolkit.graInitGraphics( g.nativeData, null, 0, xOff, yOff, xClip, yClip, wClip, hClip, fnt.nativeData, Toolkit.clrGetPixelValue(fg.getRGB()), Toolkit.clrGetPixelValue(bg.getRGB()), blank); return g; } } else { int px, py, pxw, pyh; int xwClip, yhClip, cxw, cyh; xOff += c.x; yOff += c.y; p = c.parent; // clip to parent (inset aware) if ( p.insets != Insets.noInsets ) { Insets in = p.insets; px = in.left; py = in.top; pxw = p.width - in.right; pyh = p.height - in.bottom; } else { px = 0; py = 0; pxw = p.width; pyh = p.height; } if ( xOff + xClip < px ){ int xc = px - xOff; wClip -= (xc - xClip); xClip = xc; } if ( yOff + yClip < py ){ int yc = py - yOff; hClip -= (yc - yClip); yClip = yc; } xwClip = xClip + wClip; yhClip = yClip + hClip; cxw = xOff + xwClip; cyh = yOff + yhClip; if ( cxw > pxw ) { wClip -= cxw - pxw; } if ( cyh > pyh ) { hClip -= cyh - pyh; } c = p; } }}public Color getColor() { return foreground;}public Font getFont() { return font;}public FontMetrics getFontMetrics ( Font fnt ) { return FontMetrics.getFontMetrics( fnt);}static NativeGraphics getGraphics ( Object target, Pointer tgtData, int tgtType, int xOffset, int yOffset, int xClip, int yClip, int wClip, int hClip, Color fg, Color bg, Font fnt, boolean blank ) { NativeGraphics g; if ( tgtData == null ) { return null; } synchronized ( lock ) { if ( cache == null ) { g = new NativeGraphics(); } else { g = cache; cache = g.next; g.next = null; } } g.xOffset = xOffset; g.yOffset = yOffset; g.xClip = xClip; g.yClip = yClip; g.wClip = wClip; g.wClipDefault = wClip; g.hClip = hClip; g.hClipDefault = hClip; g.font = fnt; g.foreground = fg; g.background = bg;if ( fg == null ){ Thread.currentThread().dumpStack();} g.nativeData = Toolkit.graInitGraphics( g.nativeData, tgtData, tgtType, xOffset, yOffset, xClip, yClip, wClip, hClip, fnt.nativeData, Toolkit.clrGetPixelValue(fg.getRGB()), Toolkit.clrGetPixelValue(bg.getRGB()), blank); return g;}void paintChild ( Component c, boolean isUpdate ) { // needs to be here because we are the only one knowing about the clip fields // (a generic version would have to use the dreadful getClipBounds()) int xw = c.x + c.width; int yh = c.y + c.height; int cxw = xClip + wClip; int cyh = yClip + hClip; if ( (xClip > xw) || (yClip > yh) || (c.x > cxw) || (c.y > cyh) ) return; int clx = (c.x > xClip) ? c.x : xClip; int cly = (c.y > yClip) ? c.y : yClip; int clw = ((xw > cxw) ? cxw : xw) - clx; int clh = ((yh > cyh) ? cyh : yh) - cly; clx -= c.x; cly -= c.y;// HACK: maybe we have to set all widgets to IS_ASYNC_UPDATED because// of bad apps implicitly relying on async update solicitation in order to avoid flicker// (doing lots of redundant repaint requests without even knowing about it). The downside is// that it would slow down all nice apps// if ( (c.flags & Component.IS_ASYNC_UPDATED) != 0 ) { if ( (c.flags & Component.IS_NATIVE_LIKE) != 0 ) { // This is a really nasty problem with Panels and Canvases: they don't get // drawn sync, but usually receive their own native paint (not even update!) // events *after* the parent got painted. We have to simulate this because // - believe it or not - some apps rely on UPDATE/PAINT vs. // COMPONENT_RESIZED/SHOWN order (this is *bad*, since it heavily depends // on unspecified behavior ofthe AWT *and* the underlying native window system). // Note that we shouldn't leave the repaint up to the ragman (processPaintEvent) // since some apps might even call update/paint explicitly (again, bad!). But // we want to support at least those who call super.paint() // The PAINT vs. UPDATE problem also shows up in Container.emitRepaints Toolkit.eventQueue.postPaintEvent( PaintEvt.PAINT, c, clx, cly, clw, clh); } else { NativeGraphics g = getGraphics( this, nativeData, TGT_TYPE_GRAPHICS, c.x + xOffset, c.y + yOffset, clx, cly, clw, clh, c.foreground, c.background, c.font, false); if ( g != null ) { if ( isUpdate ) c.update( g); else c.paint( g); g.dispose(); } } c.flags &= ~Component.IS_DIRTY; // no need for subsequent repaints anymore}void setBackColor ( Color clr ){ if ( (clr != null) && (clr != background) ) { background = clr; Toolkit.graSetBackColor( nativeData, Toolkit.clrGetPixelValue(background.getRGB())); }}public void setClip ( Shape clip ){ if ( clip != null ) { Rectangle r = clip.getBounds(); setClip( r.x, r.y, r.width, r.height); } else if ( target != null) { setClip( 0, 0, target.width, target.height ); } else { setClip( 0, 0, wClipDefault, hClipDefault ); }}public void setClip ( int x, int y, int width, int height ) { if ( target != null ) { // be paranoid, native widgets automatically clip to their boundaries if ( x < 0 ) x = 0; if ( y < 0 ) y = 0; if ( (x + width) > target.width ) width = target.width - x; if ( (y + height) > target.height ) height = target.height - y; } xClip = x; yClip = y; wClip = width; hClip = height; Toolkit.graSetClip ( nativeData, x, y, width, height);}public void setColor ( Color clr ){ if ( (clr != null) && (clr != foreground) ) { foreground = clr; Toolkit.graSetColor( nativeData, Toolkit.clrGetPixelValue(foreground.getRGB())); }}public void setFont ( Font newFnt ) { if ( (newFnt != null) && (newFnt != font) ){ font = newFnt; Toolkit.graSetFont( nativeData, font.nativeData); }}void setGraphics ( Pointer tgtData, int tgtType, int xOffset, int yOffset, int xClip, int yClip, int wClip, int hClip, Color fg, Color bg, Font fnt, boolean blank ) { this.xOffset = xOffset; this.yOffset = yOffset; this.xClip = xClip; this.yClip = yClip; this.wClip = wClip; this.hClip = hClip; if ( fnt != null ) { font = fnt; } if ( fg != null ) { foreground = fg; } if ( bg != null ) { background = bg; } nativeData = Toolkit.graInitGraphics( nativeData, tgtData, tgtType, xOffset, yOffset, xClip, yClip, wClip, hClip, font.nativeData, Toolkit.clrGetPixelValue(foreground.getRGB()), Toolkit.clrGetPixelValue(background.getRGB()), blank);}public void setPaintMode() { if ( xClr != null ) { xClr = null; Toolkit.graSetPaintMode( nativeData); }}public void setXORMode ( Color newXorClr ) { if ( newXorClr != xClr ) { xClr = newXorClr; Toolkit.graSetXORMode( nativeData, Toolkit.clrGetPixelValue(xClr.getRGB())); }}public String toString() { return getClass().getName() + ' ' + hashCode() + " [" + xOffset + ',' + yOffset + " clip:" + xClip+','+yClip+' '+wClip+','+hClip + ']';}public void translate ( int x, int y ) { xOffset += x; yOffset += y; xClip -= x; yClip -= y; Toolkit.graSetOffset( nativeData, xOffset, yOffset);}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -