📄 gra.c
字号:
/* * we don't use the Xmu routines here because it would drag the whole Xt libs in */voidJava_java_awt_Toolkit_graDrawRoundRect ( JNIEnv* env UNUSED, jclass clazz UNUSED, jobject ngr, jint x, jint y, jint width, jint height, jint wArc, jint hArc ){ Graphics *gr = UNVEIL_GR(ngr); int x1, x2, y1, y2, a, b; DBG( AWT_GRA, printf("drawRoundRect: %p, %d,%d - %d,%d %d,%d\n", gr, x,y,width,height, wArc, hArc)); x += gr->x0; y += gr->y0; a = wArc / 2; b = hArc / 2; x1 = x + a; x2 = x + width - a; y2 = y + height; XDrawLine( X->dsp, gr->drw, gr->gc, x1, y, x2, y); XDrawLine( X->dsp, gr->drw, gr->gc, x1, y2, x2, y2); y1 = y + b; y2 = y + height - b; x2 = x + width; XDrawLine( X->dsp, gr->drw, gr->gc, x, y1, x, y2); XDrawLine( X->dsp, gr->drw, gr->gc, x2, y1, x2, y2); XDrawArc( X->dsp, gr->drw, gr->gc, x, y, wArc, hArc, 90*64, 90*64); x2 = x + width - wArc; XDrawArc( X->dsp, gr->drw, gr->gc, x2, y, wArc, hArc, 0, 90*64); y2 = y + height - hArc; XDrawArc( X->dsp, gr->drw, gr->gc, x2, y2, wArc, hArc, 0, -90*64); XDrawArc( X->dsp, gr->drw, gr->gc, x, y2, wArc, hArc, 180*64, 90*64); XFLUSH( X, False);}voidJava_java_awt_Toolkit_graFillRoundRect ( JNIEnv* env UNUSED, jclass clazz UNUSED, jobject ngr, jint x, jint y, jint width, jint height, jint wArc, jint hArc ){ Graphics *gr = UNVEIL_GR(ngr); int x1, x2, y1, y2, a, b; DBG( AWT_GRA, printf("fillRoundRect: %p, %d,%d - %d,%d %d,%d\n", gr, x,y,width,height, wArc, hArc)); x += gr->x0; y += gr->y0; a = wArc / 2; b = hArc / 2; y1 = y + b; y2 = y + height - b; if ( y2 > y1 ) XFillRectangle( X->dsp, gr->drw, gr->gc, x, y1, width, y2-y1); x1 = x + a; x2 = x + width - a; if ( x2 > x1 ) { XFillRectangle( X->dsp, gr->drw, gr->gc, x1, y, (x2-x1), b); XFillRectangle( X->dsp, gr->drw, gr->gc, x1, y2, (x2-x1), b); } XFillArc( X->dsp, gr->drw, gr->gc, x, y, wArc, hArc, 90*64, 90*64); x2 = x + width - wArc; XFillArc( X->dsp, gr->drw, gr->gc, x2, y, wArc, hArc, 0, 90*64); y2 = y + height - hArc; XFillArc( X->dsp, gr->drw, gr->gc, x2, y2, wArc, hArc, 0, -90*64); XFillArc( X->dsp, gr->drw, gr->gc, x, y2, wArc, hArc, 180*64, 90*64); XFLUSH( X, False);}voidJava_java_awt_Toolkit_graDraw3DRect ( JNIEnv* env, jclass clazz, jobject ngr, jint x, jint y, jint width, jint height, jboolean raised, jint rgb ){ Graphics *gr = UNVEIL_GR(ngr); int bright, dark; int xw, yh; DBG( AWT_GRA, printf("draw3DRect: %p, %d,%d - %d,%d %d %x\n", gr, x,y,width,height, raised, rgb)); /* we should use the same mechanism like ordinary Graphics brighter()/darker() here */ dark = (int) (Java_java_awt_Toolkit_clrDark( env, clazz, rgb) >> 32); bright = (int) (Java_java_awt_Toolkit_clrBright( env, clazz, rgb) >> 32); x += gr->x0; y += gr->y0; xw = x + width; yh = y + height; XSetForeground( X->dsp, gr->gc, (raised ? bright : dark)); XDrawLine( X->dsp, gr->drw, gr->gc, x, y, xw-1, y); XDrawLine( X->dsp, gr->drw, gr->gc, x, y, x, yh); XSetForeground( X->dsp, gr->gc, (raised ? dark : bright)); XDrawLine( X->dsp, gr->drw, gr->gc, x+1, yh, xw, yh); XDrawLine( X->dsp, gr->drw, gr->gc, xw, y, xw, yh); XSetForeground( X->dsp, gr->gc, gr->fg); XFLUSH( X, False);}voidJava_java_awt_Toolkit_graFill3DRect ( JNIEnv* env, jclass clazz, jobject ngr, jint x, jint y, jint width, jint height, jboolean raised, jint rgb ){ Graphics *gr = UNVEIL_GR(ngr); DBG( AWT_GRA, printf("fill3DRect: %p, %d,%d - %d,%d %d %x\n", gr, x,y,width,height, raised, rgb)); XFillRectangle( X->dsp, gr->drw, gr->gc, x+gr->x0+1, y+gr->y0+1, width-2, height-2); Java_java_awt_Toolkit_graDraw3DRect( env, clazz, ngr, x, y, width-1, height-1, raised, rgb);}voidJava_java_awt_Toolkit_graAddClip ( JNIEnv* env UNUSED, jclass clazz UNUSED, jobject gr UNUSED, jint xClip UNUSED, jint yClip UNUSED, jint wClip UNUSED, jint hClip UNUSED ){ /* not implemented yet */}voidJava_java_awt_Toolkit_graSetClip ( JNIEnv* env, jclass clazz UNUSED, jobject ngr, jint xClip, jint yClip, jint wClip, jint hClip ){ Graphics *gr = UNVEIL_GR(ngr); XRectangle rect; DBG( AWT_GRA, printf("setClip: %p, %d,%d - %d,%d\n", gr, xClip, yClip, wClip, hClip)); rect.x = xClip; rect.y = yClip; rect.width = (wClip > 0) ? wClip : 0; rect.height = (hClip > 0) ? hClip : 0; XSetClipRectangles( X->dsp, gr->gc, gr->x0, gr->y0, &rect, 1, Unsorted);}voidJava_java_awt_Toolkit_graSetColor ( JNIEnv* env, jclass clazz UNUSED, jobject ngr, jint clr ){ Graphics *gr = UNVEIL_GR(ngr); DBG( AWT_GRA, printf("setColor: %p, %x\n", gr, clr)); gr->fg = clr; if ( gr->xor ) clr ^= gr->xclr; XSetForeground( X->dsp, gr->gc, clr);}voidJava_java_awt_Toolkit_graSetBackColor ( JNIEnv* env, jclass clazz UNUSED, jobject ngr, jint clr ){ Graphics *gr = UNVEIL_GR(ngr); DBG( AWT_GRA, printf("setBackColor: %p, %x\n", gr, clr)); gr->bg = clr; XSetBackground( X->dsp, gr->gc, clr);}voidJava_java_awt_Toolkit_graSetFont ( JNIEnv* env, jclass clazz UNUSED, jobject ngr, jobject fnt ){ Graphics *gr = UNVEIL_GR(ngr); DBG( AWT_GRA, printf("setFont: %p, %p\n", gr, fnt));#ifdef KAFFE_I18N gr->oc=UNVEIL_XOC(fnt); #else XSetFont( X->dsp, gr->gc, UNVEIL_FS(fnt)->fid);#endif }voidJava_java_awt_Toolkit_graSetOffset ( JNIEnv* env, jclass clazz UNUSED, jobject ngr, jint xOff, jint yOff ){ Graphics *gr = UNVEIL_GR(ngr); DBG( AWT_GRA, printf("setOffset: %p, %d,%d\n", gr, xOff, yOff)); gr->x0 = xOff; gr->y0 = yOff;}voidJava_java_awt_Toolkit_graSetPaintMode ( JNIEnv* env, jclass clazz UNUSED, jobject ngr ){ Graphics *gr = UNVEIL_GR(ngr); DBG( AWT_GRA, printf("setPaintMode: %p\n", gr)); gr->xor = 0; XSetForeground( X->dsp, gr->gc, gr->fg); XSetFunction( X->dsp, gr->gc, GXcopy);}voidJava_java_awt_Toolkit_graSetXORMode ( JNIEnv* env, jclass clazz UNUSED, jobject ngr, jint xorClr ){ Graphics *gr = UNVEIL_GR(ngr); DBG( AWT_GRA, printf("setXORMode: %p, %x\n", gr, xorClr)); gr->xor = 1; gr->xclr = xorClr; XSetForeground( X->dsp, gr->gc, gr->fg ^ xorClr); XSetFunction( X->dsp, gr->gc, GXxor);}voidJava_java_awt_Toolkit_graSetVisible ( JNIEnv* env, jclass clazz UNUSED, jobject ngr, jint isVisible ){ Graphics *gr = UNVEIL_GR(ngr); DBG( AWT_GRA, printf("setVisble: %p %d\n", gr, isVisible)); /* * This is rather a hack to "defuse" a Graphics object, but we don't want to * add checks on every draw op to test if the target is invisible */ if ( !isVisible ) { if ( gr->y0 >= -10000 ) gr->y0 -= 100000; } else { if ( gr->y0 <= -10000 ) gr->y0 += 100000; }}/************************************************************************************ * image rendering */static voiddrawAlphaImage ( Graphics *gr, Image* img, jint srcX, jint srcY, jint dstX, jint dstY, jint width, jint height, jint bgval ){ Image *dstImg = 0; XImage *dstXim = 0; int i, j, si, sj, alpha; unsigned long dpix, spix, bgpix = 0; int sr, sg, sb, dr, dg, db; DBG( AWT_GRA, printf("drawAlphaImage: %p %p (%p, %p), %d,%d %d,%d %d,%d %x\n", gr, img, img->xImg, img->alpha, srcX, srcY, dstX, dstY, width, height, bgval)); if ( !img ) return; if ( X->shm == USE_SHM ){ dstImg = createImage( width, height); createXImage( X, dstImg); if ( dstImg->shmiImg ){ dstXim = dstImg->xImg; XShmGetImage( X->dsp, gr->drw, dstXim, dstX, dstY, 0xffffffff); } else { /* Shm failed, backup to normal XImage */ imgFreeImage( dstImg); dstImg = 0; } } if ( !dstXim ) { dstXim = XGetImage( X->dsp, gr->drw, dstX, dstY, width, height, 0xffffffff, ZPixmap); } if ( bgval != -1 ) bgpix = pixelValue( X, bgval); if ( dstXim ) { for ( j=0, sj=srcY; j<dstXim->height; j++, sj++ ) { for ( i=0, si=srcX; i<dstXim->width; i++, si++ ) { dpix = (bgval == -1) ? XGetPixel( dstXim, i, j) : bgpix; spix = XGetPixel( img->xImg, si, sj); alpha = GetAlpha( img->alpha, si, sj); rgbValues( X, dpix, &dr, &dg, &db); if ( alpha ) { /* * ints still considered to be substantially faster than floats on most * architectures (avoid div by 255), map all 0..255 -> 1..256 */ alpha++; sr++; sg++; sb++; dr++; dg++; db++; rgbValues( X, spix, &sr, &sg, &sb); dr = ((alpha * sr + (256 - alpha) * dr) + 128) >> 8; dg = ((alpha * sg + (256 - alpha) * dg) + 128) >> 8; db = ((alpha * sb + (256 - alpha) * db) + 128) >> 8; dr--; dg--; db--; XPutPixel( dstXim, i, j, pixelValue( X, (dr << 16)|(dg << 8)|(db) )); } } } if ( dstImg != 0 ){ XShmPutImage( X->dsp, gr->drw, gr->gc, dstXim, 0, 0, dstX, dstY, width, height, False); XSync( X->dsp, False); imgFreeImage( dstImg); } else { XPutImage( X->dsp, gr->drw, gr->gc, dstXim, 0, 0, dstX, dstY, width, height); XFlush( X->dsp); XDestroyImage( dstXim); } XFLUSH( X, True); }}static voiddrawImage (Graphics *gr, Image *img, jint srcX, jint srcY, jint dstX, jint dstY, jint width, jint height, jint bgval ){ XGCValues values; DBG( AWT_GRA, printf("drawImage: %p %p (%p,%p,%p %d,%d) %d,%d, %d,%d, %d,%d, %x\n", gr, img, img->xImg,img->xMask,img->alpha, img->width,img->height, srcX,srcY, dstX,dstY, width,height, bgval)); if ( !img ) return; dstX += gr->x0; dstY += gr->y0; dstX += img->left; dstY += img->top; if ( img->pix ) { XCopyArea( X->dsp, img->pix, gr->drw, gr->gc, srcX, srcY, width, height, dstX, dstY); } else if ( img->xImg ) { if ( img->xMask ) { /* save current gc values, we have to change them temporarily */ XGetGCValues( X->dsp, gr->gc, GCFunction|GCPlaneMask|GCForeground|GCBackground, &values); /* in case we have a specified background color, fill area */ if ( bgval != -1 ) { XSetForeground( X->dsp, gr->gc, bgval); XFillRectangle( X->dsp, gr->drw, gr->gc, dstX, dstY, width, height); } /* set attributes so that a subsequent image draw leaves the mask pels unmodified */ XSetFunction( X->dsp, gr->gc, GXandInverted); XSetForeground( X->dsp, gr->gc, 0xffffffff); XSetBackground( X->dsp, gr->gc, 0); /* draw the mask bitmap */ if ( img->shmiMask ){ XShmPutImage( X->dsp, gr->drw, gr->gc, img->xMask, srcX, srcY, dstX, dstY, width, height, False); } else { XPutImage( X->dsp, gr->drw, gr->gc, img->xMask, srcX, srcY, dstX, dstY, width, height); } /* restore gc values except of the function */ XChangeGC( X->dsp, gr->gc, GCFunction|GCPlaneMask|GCForeground|GCBackground, &values); XSetFunction( X->dsp, gr->gc, GXor); } else if ( img->alpha ) { drawAlphaImage( gr, img, srcX, srcY, dstX, dstY, width, height, bgval); return; } /* this is the real image drawing */ if ( img->shmiImg ){ XShmPutImage( X->dsp, gr->drw, gr->gc, img->xImg, srcX, srcY, dstX, dstY, width, height, False); } else { XPutImage( X->dsp, gr->drw, gr->gc, img->xImg, srcX, srcY, dstX, dstY, width, height); } /* in case we had a mask, restore the original function */ if ( img->xMask ) XSetFunction( X->dsp, gr->gc, values.function); } XFLUSH( X, True);}voidJava_java_awt_Toolkit_graDrawImage ( JNIEnv* env UNUSED, jclass clazz UNUSED, jobject ngr, jobject nimg, jint srcX, jint srcY, jint dstX, jint dstY, jint width, jint height, jint bgval ){ if (nimg == NULL) return; drawImage(UNVEIL_GR(ngr), UNVEIL_IMG(nimg), srcX, srcY, dstX, dstY, width, height, bgval);}voidJava_java_awt_Toolkit_graDrawImageScaled ( JNIEnv* env, jclass clazz, jobject ngr, jobject nimg, jint dx0, jint dy0, jint dx1, jint dy1, jint sx0, jint sy0, jint sx1, jint sy1, jint bgval ){ Graphics *gr = UNVEIL_GR(ngr); Image *img = UNVEIL_IMG(nimg); int iw, x0, y0, x1, y1; Image *tgt; int tmpXImg = (img->xImg == NULL); DBG( AWT_GRA, printf("drawImageScaled: %p %p (%p), %d,%d,%d,%d, %d,%d,%d,%d, %x\n", gr, img, img->xImg, dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, bgval)); if ( !img ) return; /* screen images don't have an XImage, we have to get the data first */ if ( tmpXImg ) { img->xImg = XGetImage( X->dsp, img->pix, 0, 0, img->width, img->height, 0xffffffff, ZPixmap); } iw = img->xImg->width; if ( dx1 > dx0 ) { x0 = dx0; x1 = dx1; } else { x0 = dx1; x1 = dx0; } if ( dy1 > dy0 ) { y0 = dy0; y1 = dy1; } else { y0 = dy1; y1 = dy0; } if ( sx0 < 0 ) sx0 = 0; if ( sx1 < 0 ) sx1 = 0; if ( sx0 >= iw ) sx0 = iw-1; if ( sx1 >= iw ) sx1 = iw-1; tgt = createImage( (x1 - x0 +1), (y1 - y0 +1)); /* alpha image should always go first, since it would disable subsequent Shm usage */ if ( img->alpha ) createAlphaImage( X, tgt); if ( img->xMask ) createXMaskImage( X, tgt); createXImage( X, tgt); initScaledImage( X, tgt, img, dx0-x0, dy0-y0, dx1-x0, dy1-y0, sx0, sy0, sx1, sy1); drawImage ( gr, tgt, 0, 0, x0, y0, tgt->width, tgt->height, bgval); if ( tgt->shmiImg ) { XSync( X->dsp, False); /* since we're going to destroy tgt, process its drawing first */ } imgFreeImage( tgt ); if ( tmpXImg ) { XDestroyImage( img->xImg); img->xImg = NULL; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -