void x11_expose(struct x11bitmap *xb, Region r) { if (xb->frontbuffer) { /* Double-buffered expose update */ XSetRegion(x11_display,x11_gctab[PG_LGOP_NONE],r); XCopyArea(x11_display,xb->d,xb->frontbuffer->d, x11_gctab[PG_LGOP_NONE],0,0,xb->sb.w,xb->sb.h,0,0); XSetRegion(x11_display,x11_gctab[PG_LGOP_NONE],x11_display_region); } else { /* Ugly non-double-buffered expose update */ struct divtree *p; int i; for (i=0;i<=PG_LGOPMAX;i++) if (x11_gctab[i]) XSetRegion(x11_display,x11_gctab[i],r); x11_current_region = r; for (p=dts->top;p;p=p->next) if (p->display == (hwrbitmap)xb) p->flags |= DIVTREE_ALL_REDRAW; update(NULL,1); for (i=0;i<=PG_LGOPMAX;i++) if (x11_gctab[i]) XSetRegion(x11_display,x11_gctab[i],x11_display_region); x11_current_region = x11_display_region; } }
void rebcmp_blit_region(REBCMP_CTX* ctx, Region reg) { //RL_Print("rebcmp_blit_region, ctx: %x\n", ctx); XSetRegion(global_x_info->display, ctx->x_gc, reg); /* XRectangle rect; XClipBox(ctx->Win_Region, &rect); RL_Print("Setting window region at: %dx%d, size:%dx%d\n", rect.x, rect.y, rect.width, rect.height); */ #ifdef USE_XSHM if (global_x_info->has_xshm) { //RL_Print("XshmPutImage\n"); XShmPutImage(global_x_info->display, ctx->host_window->x_id, ctx->x_gc, ctx->x_image, 0, 0, //src x, y 0, 0, //dest x, y ctx->x_image->width, ctx->x_image->height, False); XFlush(global_x_info->display); //x_image could change if we don't flush here } else { #endif Drawable dest = global_x_info->has_double_buffer ? ctx->host_window->x_back_buffer : ctx->host_window->x_id; if (global_x_info->sys_pixmap_format == pix_format_bgra32){ XPutImage (global_x_info->display, dest, ctx->x_gc, ctx->x_image, 0, 0, //src x, y 0, 0, //dest x, y ctx->x_image->width, ctx->x_image->height); } else { put_image(global_x_info->display, dest, ctx->x_gc, ctx->x_image, ctx->x_image->width, ctx->x_image->height, global_x_info->sys_pixmap_format); } if (global_x_info->has_double_buffer) { //RL_Print("Swapping...\n"); XdbeSwapInfo swapInfo; swapInfo.swap_window = ctx->host_window->x_id; swapInfo.swap_action = XdbeUndefined; XdbeSwapBuffers(global_x_info->display, &swapInfo, 1); } #ifdef USE_XSHM } #endif //RL_Print("rebcmp_blit done\n"); }
int _zbar_window_begin (zbar_window_t *w) { window_state_t *xs = w->state; if(xs->exposed) XSetRegion(w->display, xs->gc, xs->exposed); return(0); }
static void sSetGCRegion() { if(UpdateRegionGC) { XSetRegion(sXDisplay(),sXGC,ClipStack[ClipIndex]); UpdateRegionGC = sFALSE; } }
Bool apc_gp_set_region( Handle self, Handle rgn) { DEFXX; Region region; PRegionSysData r; if ( PObject( self)-> options. optInDrawInfo) return false; if ( !XF_IN_PAINT(XX)) return false; if (rgn == nilHandle) { Rect r; r. left = 0; r. bottom = 0; r. right = XX-> size. x - 1; r. top = XX-> size. y - 1; return apc_gp_set_clip_rect( self, r); } r = GET_REGION(rgn); XClipBox( r-> region, &XX-> clip_rect); XX-> clip_rect. y += XX-> size. y - r-> height; XX-> clip_mask_extent. x = XX-> clip_rect. width; XX-> clip_mask_extent. y = XX-> clip_rect. height; if ( XX-> clip_rect. width == 0 || XX-> clip_rect. height == 0) { Rect r; r. left = -1; r. bottom = -1; r. right = -1; r. top = -1; return apc_gp_set_clip_rect( self, r); } region = XCreateRegion(); XUnionRegion( region, r-> region, region); /* offset region if drawable is buffered */ XOffsetRegion( region, XX-> btransform. x, XX-> size.y - r-> height - XX-> btransform. y); /* otherwise ( and only otherwise ), and if there's a X11 clipping, intersect the region with it. X11 clipping must not mix with the buffer clipping */ if (( !XX-> udrawable || XX-> udrawable == XX-> gdrawable) && XX-> paint_region) XIntersectRegion( region, XX-> paint_region, region); XSetRegion( DISP, XX-> gc, region); if ( XX-> flags. kill_current_region) XDestroyRegion( XX-> current_region); XX-> flags. kill_current_region = 1; XX-> current_region = region; XX-> flags. xft_clip = 0; #ifdef USE_XFT if ( XX-> xft_drawable) prima_xft_update_region( self); #endif #ifdef HAVE_X11_EXTENSIONS_XRENDER_H if ( XX-> argb_picture ) XRenderSetPictureClipRegion(DISP, XX->argb_picture, region); #endif return true; }
Bool XftDrawSetClip (XftDraw *draw, Region r) { Region n = 0; if (!r && !draw->clip) return True; if (r) { n = XCreateRegion (); if (n) { if (!XUnionRegion (n, r, n)) { XDestroyRegion (n); return False; } } } if (draw->clip) { XDestroyRegion (draw->clip); } draw->clip = n; if (draw->render_able) { XRenderPictureAttributes pa; if (n) { XRenderSetPictureClipRegion (draw->dpy, draw->render.pict, n); } else { pa.clip_mask = None; XRenderChangePicture (draw->dpy, draw->render.pict, CPClipMask, &pa); } } if (draw->core_set) { XGCValues gv; if (n) XSetRegion (draw->dpy, draw->core.draw_gc, n); else { gv.clip_mask = None; XChangeGC (draw->dpy, draw->core.draw_gc, GCClipMask, &gv); } } return True; }
// Make the system's clip match the top of the clip stack. This can // be used after changing the stack, or to undo any clobbering of clip // done by your program: void fl_restore_clip() { Region r = rstack[rstackptr]; fl_clip_state_number++; #ifdef _WIN32 SelectClipRgn(fl_gc, r); //if r is NULL, clip is automatically cleared #else if (r) XSetRegion(fl_display, fl_gc, r); else XSetClipMask(fl_display, fl_gc, 0); #endif }
void X11Graphics::drawGraphics( const OSGraphics &rGraphics, int xSrc, int ySrc, int xDest, int yDest, int width, int height ) { const X11Graphics& rGraph = (X11Graphics&)rGraphics; // check and adapt to source if needed if( !checkBoundaries( 0, 0, rGraph.getWidth(), rGraph.getHeight(), xSrc, ySrc, width, height ) ) { msg_Err( getIntf(), "nothing to draw from graphics source" ); return; } // check destination if( !checkBoundaries( 0, 0, m_width, m_height, xDest, yDest, width, height ) ) { msg_Err( getIntf(), "out of reach destination! pls, debug your skin" ); return; } // Source drawable Drawable src = rGraph.getDrawable(); // Create the mask for transparency Region voidMask = XCreateRegion(); XRectangle rect; rect.x = xSrc; rect.y = ySrc; rect.width = width; rect.height = height; Region clipMask = XCreateRegion(); XUnionRectWithRegion( &rect, voidMask, clipMask ); Region mask = XCreateRegion(); XIntersectRegion( rGraph.getMask(), clipMask, mask ); XDestroyRegion( clipMask ); XDestroyRegion( voidMask ); XOffsetRegion( mask, xDest - xSrc, yDest - ySrc ); // Copy the pixmap XSetRegion( XDISPLAY, m_gc, mask ); XCopyArea( XDISPLAY, src, m_pixmap, m_gc, xSrc, ySrc, width, height, xDest, yDest ); // Add the source mask to the mask of the graphics Region newMask = XCreateRegion(); XUnionRegion( m_mask, mask, newMask ); XDestroyRegion( mask ); XDestroyRegion( m_mask ); m_mask = newMask; }
int _zbar_window_draw_logo (zbar_window_t *w) { window_state_t *x = w->state; int screen = DefaultScreen(w->display); /* clear to white */ XSetForeground(w->display, x->gc, WhitePixel(w->display, screen)); XFillRectangle(w->display, w->xwin, x->gc, 0, 0, w->width, w->height); if(!x->logo_scale || !x->logo_zbars) return(0); XSetForeground(w->display, x->gc, BlackPixel(w->display, screen)); XFillRectangles(w->display, w->xwin, x->gc, x->logo_bars, 5); XSetLineAttributes(w->display, x->gc, 2 * x->logo_scale, LineSolid, CapRound, JoinRound); XSetForeground(w->display, x->gc, x->logo_colors[0]); XDrawLines(w->display, w->xwin, x->gc, x->logo_z, 4, CoordModeOrigin); if(x->exposed) { XIntersectRegion(x->logo_zbars, x->exposed, x->exposed); XSetRegion(w->display, x->gc, x->exposed); } else XSetRegion(w->display, x->gc, x->logo_zbars); XSetForeground(w->display, x->gc, x->logo_colors[1]); XDrawLines(w->display, w->xwin, x->gc, x->logo_z, 4, CoordModeOrigin); /* reset GC */ XSetLineAttributes(w->display, x->gc, 0, LineSolid, CapButt, JoinMiter); return(0); }
void X11Graphics::drawRect( int left, int top, int width, int height, uint32_t color ) { // Update the mask with the rectangle addHSegmentInRegion( m_mask, left, left + width, top ); addHSegmentInRegion( m_mask, left, left + width, top + height ); addVSegmentInRegion( m_mask, top, top + height, left ); addVSegmentInRegion( m_mask, top, top + height, left + width ); // Draw the rectangle XGCValues gcVal; gcVal.foreground = m_rDisplay.getPixelValue( color >> 16, color >> 8, color ); XChangeGC( XDISPLAY, m_gc, GCForeground, &gcVal ); XSetRegion( XDISPLAY, m_gc, m_mask ); XDrawRectangle( XDISPLAY, m_pixmap, m_gc, left, top, width - 1, height - 1 ); }
void x_drawable_rep::set_clipping (SI x1, SI y1, SI x2, SI y2, bool restore) { (void) restore; outer_round (x1, y1, x2, y2); renderer_rep::set_clipping (x1, y1, x2, y2); Region region= XCreateRegion (); decode (x1, y1); decode (x2, y2); XRectangle r; r.x = x1; r.y = y2; r.width = x2-x1; r.height= y1-y2; XUnionRectWithRegion (&r, region, region); XSetRegion (dpy, gc, region); XDestroyRegion (region); }
void JXGC::SetClipRegion ( const Region clipRegion ) { ClearPrivateClipping(); itsClipRegion = JXCopyRegion(clipRegion); itsClipOffset = JPoint(0,0); XSetRegion(*itsDisplay, itsXGC, clipRegion); const unsigned long valueMask = GCClipXOrigin | GCClipYOrigin; XGCValues values; values.clip_x_origin = 0; values.clip_y_origin = 0; XChangeGC(*itsDisplay, itsXGC, valueMask, &values); }
void X11Graphics::drawGraphics( const OSGraphics &rGraphics, int xSrc, int ySrc, int xDest, int yDest, int width, int height ) { if( width == -1 ) { width = rGraphics.getWidth(); } if( height == -1 ) { height = rGraphics.getHeight(); } // Source drawable Drawable src = ((X11Graphics&)rGraphics).getDrawable(); // Create the mask for transparency Region voidMask = XCreateRegion(); XRectangle rect; rect.x = xSrc; rect.y = ySrc; rect.width = width; rect.height = height; Region clipMask = XCreateRegion(); XUnionRectWithRegion( &rect, voidMask, clipMask ); Region mask = XCreateRegion(); XIntersectRegion( ((X11Graphics&)rGraphics).getMask(), clipMask, mask ); XDestroyRegion( clipMask ); XDestroyRegion( voidMask ); XOffsetRegion( mask, xDest - xSrc, yDest - ySrc ); // Copy the pixmap XSetRegion( XDISPLAY, m_gc, mask ); XCopyArea( XDISPLAY, src, m_pixmap, m_gc, xSrc, ySrc, width, height, xDest, yDest ); // Add the source mask to the mask of the graphics Region newMask = XCreateRegion(); XUnionRegion( m_mask, mask, newMask ); XDestroyRegion( mask ); XDestroyRegion( m_mask ); m_mask = newMask; }
static PyObject * PaxGC_SetRegion(PaxGCObject *self, PyObject*args) { PyObject *arg1; if (self->shared) { PyErr_SetString(PyExc_TypeError, "can't modify shared GC"); return NULL; } if (!PyArg_ParseTuple(args, "O", &arg1)) return NULL; if (!PaxRegion_Check(arg1)) { if (!PyErr_Occurred()) PyErr_SetString(PyExc_TypeError, "arg1 should be Region"); return NULL; } XSetRegion(self->display, self->gc, PaxRegion_AsRegion(arg1)); Py_INCREF(Py_None); return Py_None; }
void X11Graphics::fillRect( int left, int top, int width, int height, uint32_t color ) { // Update the mask with the rectangle area Region newMask = XCreateRegion(); XRectangle rect; rect.x = left; rect.y = top; rect.width = width; rect.height = height; XUnionRectWithRegion( &rect, m_mask, newMask ); XDestroyRegion( m_mask ); m_mask = newMask; // Draw the rectangle XGCValues gcVal; gcVal.foreground = m_rDisplay.getPixelValue( color >> 16, color >> 8, color ); XChangeGC( XDISPLAY, m_gc, GCForeground, &gcVal ); XSetRegion( XDISPLAY, m_gc, m_mask ); XFillRectangle( XDISPLAY, m_pixmap, m_gc, left, top, width, height ); }
Bool apc_gp_set_clip_rect( Handle self, Rect clipRect) { DEFXX; Region region; XRectangle r; if ( !XF_IN_PAINT(XX)) return false; SORT( clipRect. left, clipRect. right); SORT( clipRect. bottom, clipRect. top); r. x = clipRect. left; r. y = REVERT( clipRect. top); r. width = clipRect. right - clipRect. left+1; r. height = clipRect. top - clipRect. bottom+1; XX-> clip_rect = r; XX-> clip_mask_extent. x = r. width; XX-> clip_mask_extent. y = r. height; region = XCreateRegion(); XUnionRectWithRegion( &r, region, region); if ( XX-> paint_region) XIntersectRegion( region, XX-> paint_region, region); if ( XX-> btransform. x != 0 || XX-> btransform. y != 0) { XOffsetRegion( region, XX-> btransform. x, -XX-> btransform. y); } XSetRegion( DISP, XX-> gc, region); if ( XX-> flags. kill_current_region) XDestroyRegion( XX-> current_region); XX-> flags. kill_current_region = 1; XX-> current_region = region; XX-> flags. xft_clip = 0; #ifdef USE_XFT if ( XX-> xft_drawable) prima_xft_update_region( self); #endif #ifdef HAVE_X11_EXTENSIONS_XRENDER_H if ( XX-> argb_picture ) XRenderSetPictureClipRegion(DISP, XX->argb_picture, region); #endif return true; }
/* * Kreslení */ static void expose(XExposeEvent *event) { Region region, region1, region2; XRectangle rect; if(event->count > 0) return; /* Kreslit jen po poslední události v øadì */ XDrawArc(display, topwin, my_gc, 20, 20, topwin_w - 40, topwin_h - 40, 0, 360 * 64); region = XCreateRegion(); region1 = XCreateRegion(); region2 = XCreateRegion(); rect.x = rect.y = 0; rect.width = 100; rect.height = topwin_w - 60; XUnionRectWithRegion(&rect, region, region1); rect.width = 20; rect.height = 10; XUnionRectWithRegion(&rect, region2, region); XOffsetRegion(region, 50, 100); XSubtractRegion(region1, region, region2); XDestroyRegion(region); region = XCreateRegion(); rect.width = 100; rect.height = 30; XUnionRectWithRegion(&rect, region, region1); XOffsetRegion(region1, (int)topwin_w - 120, -30 + ((int)topwin_h - 40) / 2); XUnionRegion(region1, region2, region); XSetRegion(display, my_gc, region); XDestroyRegion(region); XDestroyRegion(region1); XDestroyRegion(region2); XSetClipOrigin(display, my_gc, 20, 20); XFillArc(display, topwin, my_gc, 20, 20, topwin_w - 40, topwin_h - 40, 0, 360 * 64); XSetClipMask(display, my_gc, None); /* Zru¹it oøezávání */ }
void handleExpose(void (*expose)()) /* this function handles the expose event */ { /* set rectangle to be exposed area */ rectangle.x = (short) report.xexpose.x; rectangle.y = (short) report.xexpose.y; rectangle.width = (unsigned short) report.xexpose.width; rectangle.height = (unsigned short) report.xexpose.height; /* union this rect into a region */ XUnionRectWithRegion(&rectangle, region, region); /* if this is the last contiguous expose in a group, set the clip region, clear region for next time, and draw.*/ if (report.xexpose.count == 0) { XSetRegion(display, drawgc, region); XDestroyRegion(region); region = XCreateRegion(); if (expose != NULL) (*expose)(); } }
Bool XftDrawCorePrepare (XftDraw *draw, XftColor *color, XftFont *font) { if (!draw->core_set) { XGCValues gcv; unsigned long mask; draw->core_set = True; draw->core.fg = color->pixel; gcv.foreground = draw->core.fg; mask = GCForeground; if (font) { draw->core.font = font->u.core.font->fid; gcv.font = draw->core.font; mask |= GCFont; } draw->core.draw_gc = XCreateGC (draw->dpy, draw->drawable, mask, &gcv); if (draw->clip) XSetRegion (draw->dpy, draw->core.draw_gc, draw->clip); } if (draw->core.fg != color->pixel) { draw->core.fg = color->pixel; XSetForeground (draw->dpy, draw->core.draw_gc, draw->core.fg); } if (font && draw->core.font != font->u.core.font->fid) { draw->core.font = font->u.core.font->fid; XSetFont (draw->dpy, draw->core.draw_gc, draw->core.font); } return True; }
/* * * Procedure: * menuitem_paint - draws a single entry in a popped up menu * * mr - the menu instance that holds the menu item * mi - the menu item to redraw * fw - the FvwmWindow structure to check against allowed functions * */ void menuitem_paint( struct MenuItem *mi, struct MenuPaintItemParameters *mpip) { struct MenuStyle *ms = mpip->ms; struct MenuDimensions *dim = mpip->dim; static FlocaleWinString *fws = NULL; int y_offset; int text_y; int y_height; int x; int y; int lit_x_start; int lit_x_end; gc_quad_t gcs; gc_quad_t off_gcs; int cs = -1; int off_cs; FvwmRenderAttributes fra; /*Pixel fg, fgsh;*/ int relief_thickness = ST_RELIEF_THICKNESS(ms); Bool is_item_selected; Bool item_cleared = False; Bool xft_clear = False; Bool empty_inter = False; XRectangle b; Region region = None; int i; int sx1; int sx2; FlocaleFont* font; if (!mi) { return; } is_item_selected = (mi == mpip->selected_item); if (MI_IS_TITLE(mi)) { font = ST_PTITLEFONT(ms); } else { font = ST_PSTDFONT(ms); } y_offset = MI_Y_OFFSET(mi); y_height = MI_HEIGHT(mi); if (MI_IS_SELECTABLE(mi)) { text_y = y_offset + MDIM_ITEM_TEXT_Y_OFFSET(*dim); } else { text_y = y_offset + font->ascent + ST_TITLE_GAP_ABOVE(ms); } /* center text vertically if the pixmap is taller */ if (MI_PICTURE(mi)) { text_y += MI_PICTURE(mi)->height; } for (i = 0; i < mpip->used_mini_icons; i++) { y = 0; if (MI_MINI_ICON(mi)[i]) { if (MI_MINI_ICON(mi)[i]->height > y) { y = MI_MINI_ICON(mi)[i]->height; } } y -= font->height; if (y > 1) { text_y += y / 2; } } off_cs = ST_HAS_MENU_CSET(ms) ? ST_CSET_MENU(ms) : -1; /* Note: it's ok to pass a NULL label to is_function_allowed. */ if ( !IS_EWMH_DESKTOP_FW(mpip->fw) && !is_function_allowed( MI_FUNC_TYPE(mi), MI_LABEL(mi)[0], mpip->fw, RQORIG_PROGRAM_US, False)) { gcs = ST_MENU_STIPPLE_GCS(ms); off_gcs = gcs; off_cs = ST_HAS_GREYED_CSET(ms) ? ST_CSET_GREYED(ms) : -1; } else if (is_item_selected) { gcs = ST_MENU_ACTIVE_GCS(ms); off_gcs = ST_MENU_INACTIVE_GCS(ms); } else if (MI_IS_TITLE(mi)) { gcs = ST_MENU_TITLE_GCS(ms); off_gcs = ST_MENU_INACTIVE_GCS(ms); } else { gcs = ST_MENU_INACTIVE_GCS(ms); off_gcs = ST_MENU_INACTIVE_GCS(ms); } if (is_item_selected) { cs = (ST_HAS_ACTIVE_CSET(ms)) ? ST_CSET_ACTIVE(ms) : -1; } else if (MI_IS_TITLE(mi)) { cs = (ST_HAS_TITLE_CSET(ms)) ? ST_CSET_TITLE(ms) : off_cs; } else { cs = off_cs; } /* * Hilight the item. */ if (FftSupport && ST_PSTDFONT(ms)->fftf.fftfont != NULL) { xft_clear = True; } /* Hilight or clear the background. */ lit_x_start = -1; lit_x_end = -1; if (is_item_selected && (ST_DO_HILIGHT_BACK(ms) || ST_DO_HILIGHT_FORE(ms))) { /* Hilight the background. */ if (MDIM_HILIGHT_WIDTH(*dim) - 2 * relief_thickness > 0) { lit_x_start = MDIM_HILIGHT_X_OFFSET(*dim) + relief_thickness; lit_x_end = lit_x_start + MDIM_HILIGHT_WIDTH(*dim) - 2 * relief_thickness; if (ST_DO_HILIGHT_BACK(ms)) { draw_highlight_background( mpip, lit_x_start, y_offset + relief_thickness, lit_x_end - lit_x_start, y_height - relief_thickness, (cs >= 0 ? &Colorset[cs] : NULL), gcs.back_gc); item_cleared = True; } } } else if ((MI_WAS_DESELECTED(mi) && (relief_thickness > 0 || ST_DO_HILIGHT_BACK(ms) || ST_DO_HILIGHT_FORE(ms)) && (ST_FACE(ms).type != GradientMenu || ST_HAS_MENU_CSET(ms)))) { int x1; int x2; /* we clear if xft_clear and !ST_HAS_MENU_CSET(ms) as the * non colorset code is too complicate ... olicha */ int d = 0; if (MI_PREV_ITEM(mi) && mpip->selected_item == MI_PREV_ITEM(mi)) { /* Don't paint over the hilight relief. */ d = relief_thickness; } /* Undo the hilighting. */ x1 = min( MDIM_HILIGHT_X_OFFSET(*dim), MDIM_ITEM_X_OFFSET(*dim)); x2 = max( MDIM_HILIGHT_X_OFFSET(*dim) + MDIM_HILIGHT_WIDTH(*dim), MDIM_ITEM_X_OFFSET(*dim) + MDIM_ITEM_WIDTH(*dim)); clear_menu_item_background( mpip, x1, y_offset + d, x2 - x1, y_height + relief_thickness - d); item_cleared = True; } else if (MI_IS_TITLE(mi)) { lit_x_start = MDIM_ITEM_X_OFFSET(*dim); lit_x_end = lit_x_start + MDIM_ITEM_WIDTH(*dim); /* Hilight the background. */ if ( MDIM_HILIGHT_WIDTH(*dim) > 0 && ST_DO_HILIGHT_TITLE_BACK(ms)) { draw_highlight_background( mpip, lit_x_start, y_offset + relief_thickness, lit_x_end - lit_x_start, y_height - relief_thickness, (cs >= 0 ? &Colorset[cs] : NULL), gcs.back_gc); item_cleared = True; } } MI_WAS_DESELECTED(mi) = False; memset(&fra, 0, sizeof(fra)); fra.mask = 0; /* Hilight 3D */ if (is_item_selected && relief_thickness > 0) { GC rgc; GC sgc; rgc = gcs.hilight_gc; sgc = gcs.shadow_gc; if (ST_IS_ITEM_RELIEF_REVERSED(ms)) { GC tgc = rgc; /* swap gcs for reversed relief */ rgc = sgc; sgc = tgc; } if (MDIM_HILIGHT_WIDTH(*dim) - 2 * relief_thickness > 0) { /* The relief reaches down into the next item, hence * the value for the second y coordinate: * MI_HEIGHT(mi) + 1 */ RelieveRectangle( dpy, mpip->w, MDIM_HILIGHT_X_OFFSET(*dim), y_offset, MDIM_HILIGHT_WIDTH(*dim) - 1, MI_HEIGHT(mi) - 1 + relief_thickness, rgc, sgc, relief_thickness); } } /* * Draw the item itself. */ /* Calculate the separator offsets. */ if (ST_HAS_LONG_SEPARATORS(ms)) { sx1 = MDIM_ITEM_X_OFFSET(*dim) + relief_thickness; sx2 = MDIM_ITEM_X_OFFSET(*dim) + MDIM_ITEM_WIDTH(*dim) - 1 - relief_thickness; } else { sx1 = MDIM_ITEM_X_OFFSET(*dim) + relief_thickness + MENU_SEPARATOR_SHORT_X_OFFSET; sx2 = MDIM_ITEM_X_OFFSET(*dim) + MDIM_ITEM_WIDTH(*dim) - 1 - relief_thickness - MENU_SEPARATOR_SHORT_X_OFFSET; } if (MI_IS_SEPARATOR(mi)) { if (sx1 < sx2) { /* It's a separator. */ draw_separator( mpip->w, gcs.shadow_gc, gcs.hilight_gc, sx1, y_offset + y_height - MENU_SEPARATOR_HEIGHT, sx2); /* Nothing else to do. */ } return; } else if (MI_IS_TEAR_OFF_BAR(mi)) { int tx1; int tx2; tx1 = MDIM_ITEM_X_OFFSET(*dim) + relief_thickness + MENU_TEAR_OFF_BAR_X_OFFSET; tx2 = MDIM_ITEM_X_OFFSET(*dim) + MDIM_ITEM_WIDTH(*dim) - 1 - relief_thickness - MENU_TEAR_OFF_BAR_X_OFFSET; if (tx1 < tx2) { /* It's a tear off bar. */ draw_tear_off_bar( mpip->w, gcs.shadow_gc, gcs.hilight_gc, tx1, y_offset + relief_thickness + MENU_TEAR_OFF_BAR_Y_OFFSET, tx2); } /* Nothing else to do. */ return; } else if (MI_IS_TITLE(mi)) { /* Separate the title. */ if (ST_TITLE_UNDERLINES(ms) > 0 && !mpip->flags.is_first_item) { int add = (MI_IS_SELECTABLE(MI_PREV_ITEM(mi))) ? relief_thickness : 0; text_y += MENU_SEPARATOR_HEIGHT + add; y = y_offset + add; if (sx1 < sx2) { draw_separator( mpip->w, gcs.shadow_gc, gcs.hilight_gc, sx1, y, sx2); } } /* Underline the title. */ switch (ST_TITLE_UNDERLINES(ms)) { case 0: break; case 1: if (MI_NEXT_ITEM(mi) != NULL) { y = y_offset + y_height - MENU_SEPARATOR_HEIGHT; draw_separator( mpip->w, gcs.shadow_gc, gcs.hilight_gc, sx1, y, sx2); } break; default: for (i = ST_TITLE_UNDERLINES(ms); i-- > 0; ) { y = y_offset + y_height - 1 - i * MENU_UNDERLINE_HEIGHT; XDrawLine( dpy, mpip->w, gcs.shadow_gc, sx1, y, sx2, y); } break; } } /* * Draw the labels. */ if (fws == NULL) { FlocaleAllocateWinString(&fws); } fws->win = mpip->w; fws->y = text_y; fws->flags.has_colorset = 0; b.y = text_y - font->ascent; b.height = font->height + 1; /* ? */ if (!item_cleared && mpip->ev) { int u,v; if (!frect_get_seg_intersection( mpip->ev->xexpose.y, mpip->ev->xexpose.height, b.y, b.height, &u, &v)) { /* empty intersection */ empty_inter = True; } b.y = u; b.height = v; } for (i = MAX_MENU_ITEM_LABELS; i-- > 0; ) { if (!empty_inter && MI_LABEL(mi)[i] && *(MI_LABEL(mi)[i])) { Bool draw_string = True; int text_width; int tmp_cs; if (MI_LABEL_OFFSET(mi)[i] >= lit_x_start && MI_LABEL_OFFSET(mi)[i] < lit_x_end) { /* label is in hilighted area */ fws->gc = gcs.fore_gc; tmp_cs = cs; } else { /* label is in unhilighted area */ fws->gc = off_gcs.fore_gc; tmp_cs = off_cs; } if (tmp_cs >= 0) { fws->colorset = &Colorset[tmp_cs]; fws->flags.has_colorset = 1; } fws->str = MI_LABEL(mi)[i]; b.x = fws->x = MI_LABEL_OFFSET(mi)[i]; b.width = text_width = FlocaleTextWidth( font, fws->str, strlen(fws->str)); if (!item_cleared && mpip->ev) { int s_x,s_w; if (frect_get_seg_intersection( mpip->ev->xexpose.x, mpip->ev->xexpose.width, fws->x, text_width, &s_x, &s_w)) { b.x = s_x; b.width = s_w; region = XCreateRegion(); XUnionRectWithRegion( &b, region, region); fws->flags.has_clip_region = True; fws->clip_region = region; draw_string = True; XSetRegion(dpy, fws->gc, region); } else { /* empty intersection */ draw_string = False; } } if (draw_string) { if (!item_cleared && xft_clear) { clear_menu_item_background( mpip, b.x, b.y, b.width, b.height); } FlocaleDrawString(dpy, font, fws, 0); /* hot key */ if (MI_HAS_HOTKEY(mi) && !MI_IS_TITLE(mi) && (!MI_IS_HOTKEY_AUTOMATIC(mi) || ST_USE_AUTOMATIC_HOTKEYS(ms)) && MI_HOTKEY_COLUMN(mi) == i) { FlocaleDrawUnderline( dpy, ST_PSTDFONT(ms), fws, MI_HOTKEY_COFFSET(mi)); } } } if (region) { XDestroyRegion(region); region = None; fws->flags.has_clip_region = False; fws->clip_region = None; XSetClipMask(dpy, fws->gc, None); } } /* * Draw the submenu triangle. */ if (MI_IS_POPUP(mi)) { GC tmp_gc; if (MDIM_TRIANGLE_X_OFFSET(*dim) >= lit_x_start && MDIM_TRIANGLE_X_OFFSET(*dim) < lit_x_end && is_item_selected) { /* triangle is in hilighted area */ if (ST_TRIANGLES_USE_FORE(ms)) { tmp_gc = gcs.fore_gc; } else { tmp_gc = gcs.hilight_gc; } } else { /* triangle is in unhilighted area */ if (ST_TRIANGLES_USE_FORE(ms)) { tmp_gc = off_gcs.fore_gc; } else { tmp_gc = off_gcs.hilight_gc; } } y = y_offset + (y_height - MENU_TRIANGLE_HEIGHT + relief_thickness) / 2; if (ST_TRIANGLES_USE_FORE(ms)) { DrawTrianglePattern( dpy, mpip->w, tmp_gc, tmp_gc, tmp_gc, MDIM_TRIANGLE_X_OFFSET(*dim), y, MENU_TRIANGLE_WIDTH, MENU_TRIANGLE_HEIGHT, 0, (mpip->flags.is_left_triangle) ? 'l' : 'r', ST_HAS_TRIANGLE_RELIEF(ms), !ST_HAS_TRIANGLE_RELIEF(ms), is_item_selected); } else { DrawTrianglePattern( dpy, mpip->w, gcs.hilight_gc, gcs.shadow_gc, tmp_gc, MDIM_TRIANGLE_X_OFFSET(*dim), y, MENU_TRIANGLE_WIDTH, MENU_TRIANGLE_HEIGHT, 0, (mpip->flags.is_left_triangle) ? 'l' : 'r', ST_HAS_TRIANGLE_RELIEF(ms), !ST_HAS_TRIANGLE_RELIEF(ms), is_item_selected); } } /* * Draw the item picture. */ if (MI_PICTURE(mi)) { GC tmp_gc; int tmp_cs; Bool draw_picture = True; x = menudim_middle_x_offset(mpip->dim) - MI_PICTURE(mi)->width / 2; y = y_offset + ((MI_IS_SELECTABLE(mi)) ? relief_thickness : 0); if (x >= lit_x_start && x < lit_x_end) { tmp_gc = gcs.fore_gc; tmp_cs = cs; } else { tmp_gc = off_gcs.fore_gc; tmp_cs = off_cs; } fra.mask = FRAM_DEST_IS_A_WINDOW; if (tmp_cs >= 0) { fra.mask |= FRAM_HAVE_ICON_CSET; fra.colorset = &Colorset[tmp_cs]; } b.x = x; b.y = y; b.width = MI_PICTURE(mi)->width; b.height = MI_PICTURE(mi)->height; if (!item_cleared && mpip->ev) { if (!frect_get_intersection( mpip->ev->xexpose.x, mpip->ev->xexpose.y, mpip->ev->xexpose.width, mpip->ev->xexpose.height, b.x, b.y, b.width, b.height, &b)) { draw_picture = False; } } if (draw_picture) { if ( !item_cleared && (MI_PICTURE(mi)->alpha != None || (tmp_cs >=0 && Colorset[tmp_cs].icon_alpha_percent < 100))) { clear_menu_item_background( mpip, b.x, b.y, b.width, b.height); } PGraphicsRenderPicture( dpy, mpip->w, MI_PICTURE(mi), &fra, mpip->w, tmp_gc, Scr.MonoGC, Scr.AlphaGC, b.x - x, b.y - y, b.width, b.height, b.x, b.y, b.width, b.height, False); } } /* * Draw the mini icons. */ for (i = 0; i < mpip->used_mini_icons; i++) { int k; Bool draw_picture = True; /* We need to reverse the mini icon order for left submenu * style. */ k = (ST_USE_LEFT_SUBMENUS(ms)) ? mpip->used_mini_icons - 1 - i : i; if (MI_MINI_ICON(mi)[i]) { GC tmp_gc; int tmp_cs; if (MI_PICTURE(mi)) { y = y_offset + MI_HEIGHT(mi) - MI_MINI_ICON(mi)[i]->height; } else { y = y_offset + (MI_HEIGHT(mi) + ((MI_IS_SELECTABLE(mi)) ? relief_thickness : 0) - MI_MINI_ICON(mi)[i]->height) / 2; } if (MDIM_ICON_X_OFFSET(*dim)[k] >= lit_x_start && MDIM_ICON_X_OFFSET(*dim)[k] < lit_x_end) { /* icon is in hilighted area */ tmp_gc = gcs.fore_gc; tmp_cs = cs; } else { /* icon is in unhilighted area */ tmp_gc = off_gcs.fore_gc; tmp_cs = off_cs; } fra.mask = FRAM_DEST_IS_A_WINDOW; if (tmp_cs >= 0) { fra.mask |= FRAM_HAVE_ICON_CSET; fra.colorset = &Colorset[tmp_cs]; } b.x = MDIM_ICON_X_OFFSET(*dim)[k]; b.y = y; b.width = MI_MINI_ICON(mi)[i]->width; b.height = MI_MINI_ICON(mi)[i]->height; if (!item_cleared && mpip->ev) { if (!frect_get_intersection( mpip->ev->xexpose.x, mpip->ev->xexpose.y, mpip->ev->xexpose.width, mpip->ev->xexpose.height, b.x, b.y, b.width, b.height, &b)) { draw_picture = False; } } if (draw_picture) { if (!item_cleared && (MI_MINI_ICON(mi)[i]->alpha != None || (tmp_cs >=0 && Colorset[tmp_cs].icon_alpha_percent < 100))) { clear_menu_item_background( mpip, b.x, b.y, b.width, b.height); } PGraphicsRenderPicture( dpy, mpip->w, MI_MINI_ICON(mi)[i], &fra, mpip->w, tmp_gc, Scr.MonoGC, Scr.AlphaGC, b.x - MDIM_ICON_X_OFFSET(*dim)[k], b.y - y, b.width, b.height, b.x, b.y, b.width, b.height, False); } } } return; }
/*ARGSUSED*/ static void XawLabelRedisplay(Widget gw, XEvent *event, Region region) { LabelWidget w = (LabelWidget)gw; GC gc; if (*Superclass->core_class.expose != NULL) (*Superclass->core_class.expose)(gw, event, region); gc = XtIsSensitive(gw) ? w->label.normal_GC : w->label.gray_GC; #ifdef notdef if (region != NULL) XSetRegion(XtDisplay(gw), gc, region); #endif /*notdef*/ if (w->label.pixmap == None) { int len = w->label.label_len; char *label = w->label.label; Position y = w->label.label_y + w->label.font->max_bounds.ascent; Position ksy = w->label.label_y; /* display left bitmap */ if (w->label.left_bitmap && w->label.lbm_width != 0) XCopyPlane (XtDisplay(gw), w->label.left_bitmap, XtWindow(gw), gc, 0, 0, w->label.lbm_width, w->label.lbm_height, w->label.internal_width, w->label.internal_height + w->label.lbm_y, 1L); if (w->simple.international == True) { XFontSetExtents *ext = XExtentsOfFontSet(w->label.fontset); ksy += XawAbs(ext->max_ink_extent.y); if (len == MULTI_LINE_LABEL) { char *nl; while ((nl = index(label, '\n')) != NULL) { XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc, w->label.label_x, ksy, label, (int)(nl - label)); ksy += ext->max_ink_extent.height; label = nl + 1; } len = strlen(label); } if (len) XmbDrawString(XtDisplay(w), XtWindow(w), w->label.fontset, gc, w->label.label_x, ksy, label, len); } else { if (len == MULTI_LINE_LABEL) { char *nl; while ((nl = index(label, '\n')) != NULL) { if (w->label.encoding) XDrawString16(XtDisplay(gw), XtWindow(gw), gc, w->label.label_x, y, (XChar2b *)label, (int)(nl - label) / 2); else XDrawString(XtDisplay(gw), XtWindow(gw), gc, w->label.label_x, y, label, (int)(nl - label)); y += w->label.font->max_bounds.ascent + w->label.font->max_bounds.descent; label = nl + 1; } len = strlen(label); } if (len) { if (w->label.encoding) XDrawString16(XtDisplay(gw), XtWindow(gw), gc, w->label.label_x, y, (XChar2b *)label, len / 2); else XDrawString(XtDisplay(gw), XtWindow(gw), gc, w->label.label_x, y, label, len); } } } else if (w->label.label_len == 1) XCopyPlane(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 0, 0, w->label.label_width, w->label.label_height, w->label.label_x, w->label.label_y, 1L); else XCopyArea(XtDisplay(gw), w->label.pixmap, XtWindow(gw), gc, 0, 0, w->label.label_width, w->label.label_height, w->label.label_x, w->label.label_y); #ifdef notdef if (region != NULL) XSetClipMask(XtDisplay(gw), gc, (Pixmap)None); #endif /* notdef */ }
void X11Graphics::drawBitmap( const GenericBitmap &rBitmap, int xSrc, int ySrc, int xDest, int yDest, int width, int height, bool blend ) { // Get the bitmap size if necessary if( width == -1 ) { width = rBitmap.getWidth(); } else if( width > rBitmap.getWidth() ) { msg_Dbg( getIntf(), "bitmap width too small (%i)", rBitmap.getWidth() ); width = rBitmap.getWidth(); } if( height == -1 ) { height = rBitmap.getHeight(); } else if( height > rBitmap.getHeight() ) { msg_Dbg( getIntf(), "bitmap height too small (%i)", rBitmap.getHeight() ); height = rBitmap.getHeight(); } // Nothing to draw if width or height is null if( width == 0 || height == 0 ) { return; } // Safety check for debugging purpose if( xDest + width > m_width || yDest + height > m_height ) { msg_Dbg( getIntf(), "bitmap too large" ); return; } // Get a buffer on the image data uint8_t *pBmpData = rBitmap.getData(); if( pBmpData == NULL ) { // Nothing to draw return; } // Get the image from the pixmap XImage *pImage = XGetImage( XDISPLAY, m_pixmap, xDest, yDest, width, height, AllPlanes, ZPixmap ); if( pImage == NULL ) { msg_Dbg( getIntf(), "XGetImage returned NULL" ); return; } char *pData = pImage->data; // Get the padding of this image int pad = pImage->bitmap_pad >> 3; int shift = ( pad - ( (width * XPIXELSIZE) % pad ) ) % pad; // Mask for transparency Region mask = XCreateRegion(); // Get a pointer on the right X11Display::makePixel method X11Display::MakePixelFunc_t makePixelFunc = ( blend ? m_rDisplay.getBlendPixel() : m_rDisplay.getPutPixel() ); // Skip the first lines of the image pBmpData += 4 * ySrc * rBitmap.getWidth(); // Copy the bitmap on the image and compute the mask for( int y = 0; y < height; y++ ) { // Skip uninteresting bytes at the beginning of the line pBmpData += 4 * xSrc; // Flag to say whether the previous pixel on the line was visible bool wasVisible = false; // Beginning of the current visible segment on the line int visibleSegmentStart = 0; for( int x = 0; x < width; x++ ) { uint8_t b = *(pBmpData++); uint8_t g = *(pBmpData++); uint8_t r = *(pBmpData++); uint8_t a = *(pBmpData++); // Draw the pixel (m_rDisplay.*makePixelFunc)( (uint8_t*)pData, r, g, b, a ); pData += XPIXELSIZE; if( a > 0 ) { // Pixel is visible if( ! wasVisible ) { // Beginning of a visible segment visibleSegmentStart = x; } wasVisible = true; } else { // Pixel is transparent if( wasVisible ) { // End of a visible segment: add it to the mask addHSegmentInRegion( mask, visibleSegmentStart, x, y ); } wasVisible = false; } } if( wasVisible ) { // End of a visible segment: add it to the mask addHSegmentInRegion( mask, visibleSegmentStart, width, y ); } pData += shift; // Skip uninteresting bytes at the end of the line pBmpData += 4 * (rBitmap.getWidth() - width - xSrc); } // Apply the mask to the graphics context XOffsetRegion( mask, xDest, yDest ); XSetRegion( XDISPLAY, m_gc, mask ); // Copy the image on the pixmap XPutImage( XDISPLAY, m_pixmap, m_gc, pImage, 0, 0, xDest, yDest, width, height); XDestroyImage( pImage ); // Add the bitmap mask to the global graphics mask Region newMask = XCreateRegion(); XUnionRegion( mask, m_mask, newMask ); XDestroyRegion( m_mask ); m_mask = newMask; XDestroyRegion( mask ); }
static void x_gram_draw(Display *dpy, Window w, x_gram *gram, Region region) { int i; GC gc; XGCValues gcvals; xblock *xb; #ifdef X_HAVE_UTF8_STRING XmbTextItem text; #else XwcTextItem text; #endif int startblock, endblock, startpixel = 0, endpixel = 0; gc = XCreateGC(dpy, w, 0, &gcvals); XSetRegion(dpy, gc, region); if ((markgram == gram) && (STARTBLOCK != -1) && (ENDBLOCK != -1)) { if (xmarkSecond() == XMARK_END_BOUND) { startblock = STARTBLOCK; endblock = ENDBLOCK; startpixel = STARTPIXEL; endpixel = ENDPIXEL; } else { startblock = ENDBLOCK; endblock = STARTBLOCK; startpixel = ENDPIXEL; endpixel = STARTPIXEL; } } else { startblock = -1; endblock = -1; } for (i=0, xb = gram->blocks; i < gram->numblocks; i++, xb++) { if (XRectInRegion(region, xb->x1, xb->y1, xb->x2 - xb->x1, xb->y2 - xb->y1) != RectangleOut) { if (i == startblock) { if (i == endblock) { SetFG(dpy, gc, gram->bgcolor); XFillRectangle(dpy, w, gc, xb->x1, xb->y1, startpixel, xb->y2 - xb->y1); SetFG(dpy, gc, xb->fgcolor); XFillRectangle(dpy, w, gc, xb->x1 + startpixel, xb->y1, endpixel - startpixel, xb->y2 - xb->y1); SetFG(dpy, gc, gram->bgcolor); XFillRectangle(dpy, w, gc, xb->x1 + endpixel, xb->y1, xb->x2 - xb->x1 - endpixel, xb->y2 - xb->y1); } else { SetFG(dpy, gc, gram->bgcolor); XFillRectangle(dpy, w, gc, xb->x1, xb->y1, startpixel, xb->y2 - xb->y1); SetFG(dpy, gc, xb->fgcolor); XFillRectangle(dpy, w, gc, xb->x1 + startpixel, xb->y1, xb->x2 - xb->x1 - startpixel,xb->y2 - xb->y1); } } else if (i == endblock) { SetFG(dpy, gc, xb->fgcolor); XFillRectangle(dpy, w, gc, xb->x1, xb->y1, endpixel, xb->y2 - xb->y1); SetFG(dpy, gc, gram->bgcolor); XFillRectangle(dpy, w, gc, xb->x1 + endpixel, xb->y1, xb->x2 - xb->x1 - endpixel, xb->y2 - xb->y1); } else { if (startblock < i && i < endblock) { SetFG(dpy, gc, xb->fgcolor); } else { SetFG(dpy, gc, gram->bgcolor); } XFillRectangle(dpy, w, gc, xb->x1, xb->y1, xb->x2 - xb->x1, xb->y2 - xb->y1); } } } gcvals.function = GXxor; XChangeGC(dpy, gc, GCFunction, &gcvals); for (i=0, xb = gram->blocks; i < gram->numblocks; i++, xb++) { if (XRectInRegion(region, xb->x1, xb->y1, xb->x2 - xb->x1, xb->y2 - xb->y1) != RectangleOut) { SetFG(dpy, gc, gram->bgcolor ^ xb->fgcolor); #ifdef X_HAVE_UTF8_STRING text.chars = xb->wstr; #else text.chars = (wchar_t *)xb->wstr; #endif text.nchars = xb->wlen; text.delta = 0; text.font_set = xb->font; #ifdef X_HAVE_UTF8_STRING Xutf8DrawText(dpy, w, gc, xb->x, xb->y, &text, 1); #else XwcDrawText(dpy, w, gc, xb->x, xb->y, &text, 1); #endif } } XFreeGC(dpy, gc); }
EAPI Eina_Bool ecore_x_xregion_set(Ecore_X_XRegion *region, Ecore_X_GC gc) { LOGFN(__FILE__, __LINE__, __FUNCTION__); return XSetRegion(_ecore_x_disp, gc, (Region)region) ? EINA_TRUE : EINA_FALSE; } /* ecore_x_xregion_set */
void X11Graphics::drawBitmap( const GenericBitmap &rBitmap, int xSrc, int ySrc, int xDest, int yDest, int width, int height, bool blend ) { // check and adapt to source if needed if( !checkBoundaries( 0, 0, rBitmap.getWidth(), rBitmap.getHeight(), xSrc, ySrc, width, height ) ) { msg_Err( getIntf(), "empty source! pls, debug your skin" ); return; } // check destination if( !checkBoundaries( 0, 0, m_width, m_height, xDest, yDest, width, height ) ) { msg_Err( getIntf(), "out of reach destination! pls, debug your skin" ); return; } // Get a buffer on the image data uint8_t *pBmpData = rBitmap.getData(); if( pBmpData == NULL ) { // Nothing to draw return; } // Force pending XCopyArea to be sent to the X Server // before issuing an XGetImage. XSync( XDISPLAY, False ); // Get the image from the pixmap XImage *pImage = XGetImage( XDISPLAY, m_pixmap, xDest, yDest, width, height, AllPlanes, ZPixmap ); if( pImage == NULL ) { msg_Dbg( getIntf(), "XGetImage returned NULL" ); return; } char *pData = pImage->data; // Get the padding of this image int pad = pImage->bitmap_pad >> 3; int shift = ( pad - ( (width * XPIXELSIZE) % pad ) ) % pad; // Mask for transparency Region mask = XCreateRegion(); // Get a pointer on the right X11Display::makePixel method X11Display::MakePixelFunc_t makePixelFunc = ( blend ? m_rDisplay.getBlendPixel() : m_rDisplay.getPutPixel() ); // Skip the first lines of the image pBmpData += 4 * ySrc * rBitmap.getWidth(); // Copy the bitmap on the image and compute the mask for( int y = 0; y < height; y++ ) { // Skip uninteresting bytes at the beginning of the line pBmpData += 4 * xSrc; // Flag to say whether the previous pixel on the line was visible bool wasVisible = false; // Beginning of the current visible segment on the line int visibleSegmentStart = 0; for( int x = 0; x < width; x++ ) { uint8_t b = *(pBmpData++); uint8_t g = *(pBmpData++); uint8_t r = *(pBmpData++); uint8_t a = *(pBmpData++); // Draw the pixel (m_rDisplay.*makePixelFunc)( (uint8_t*)pData, r, g, b, a ); pData += XPIXELSIZE; if( a > 0 ) { // Pixel is visible if( ! wasVisible ) { // Beginning of a visible segment visibleSegmentStart = x; } wasVisible = true; } else { // Pixel is transparent if( wasVisible ) { // End of a visible segment: add it to the mask addHSegmentInRegion( mask, visibleSegmentStart, x, y ); } wasVisible = false; } } if( wasVisible ) { // End of a visible segment: add it to the mask addHSegmentInRegion( mask, visibleSegmentStart, width, y ); } pData += shift; // Skip uninteresting bytes at the end of the line pBmpData += 4 * (rBitmap.getWidth() - width - xSrc); } // Apply the mask to the graphics context XOffsetRegion( mask, xDest, yDest ); XSetRegion( XDISPLAY, m_gc, mask ); // Copy the image on the pixmap XPutImage( XDISPLAY, m_pixmap, m_gc, pImage, 0, 0, xDest, yDest, width, height); XDestroyImage( pImage ); // Add the bitmap mask to the global graphics mask Region newMask = XCreateRegion(); XUnionRegion( mask, m_mask, newMask ); XDestroyRegion( m_mask ); m_mask = newMask; XDestroyRegion( mask ); }
void exposeCB (Widget w, ExposeCD *cd, XtcwpAxesCallbackStruct *ca) { Model *model=cd->model; char *edgecolor=cd->edgecolor; char *tricolor=cd->tricolor; float bclip=cd->bclip; float wclip=cd->wclip; Region region=ca->region; Position x=ca->x,y=ca->y; Dimension width=ca->width,height=ca->height; float x1beg=ca->x1beg,x1end=ca->x1end, x2beg=ca->x2beg,x2end=ca->x2end; int style=ca->style; Display *dpy=NULL; Window win; Region drawregion,tempregion; XWindowAttributes wa; Colormap cmap; XColor scolor,ecolor; XRectangle rect; long black=0; long white=0; GC gcedge,gctri; FGC fgcedge,fgctri,fgc; float x1,y1,x2,y2,x3,y3; Face *f; /* JG */ dpy=XtDisplay(w); win=XtWindow(w); black=(long) BlackPixelOfScreen(XtScreen(w)); white=(long) WhitePixelOfScreen(XtScreen(w)); /* .. JG */ /* determine current colormap */ XGetWindowAttributes(dpy,win,&wa); cmap = wa.colormap; /* create GCs */ gcedge = XCreateGC(dpy,win,0L,NULL); gctri = XCreateGC(dpy,win,0L,NULL); /* set line colors */ if (XAllocNamedColor(dpy,cmap,edgecolor,&scolor,&ecolor)) XSetForeground(dpy,gcedge,ecolor.pixel); else XSetForeground(dpy,gcedge,black); if (XAllocNamedColor(dpy,cmap,tricolor,&scolor,&ecolor)) XSetForeground(dpy,gctri,ecolor.pixel); else XSetForeground(dpy,gctri,white); /* clip to intersection of axes rectangle and expose region */ rect.x = x; rect.y = y; rect.width = width; rect.height = height; tempregion = XCreateRegion(); XUnionRectWithRegion(&rect,tempregion,tempregion); drawregion = XCreateRegion(); XIntersectRegion(region,tempregion,drawregion); XSetRegion(dpy,gcedge,drawregion); XSetRegion(dpy,gctri,drawregion); /* create FGCs with clipping */ if (style==XtcwpNORMAL) { fgcedge = FXCreateFGC(gcedge,x,y,width,height, x1beg,x2end,x1end-x1beg,x2beg-x2end); FSetClipRectangle(fgcedge,x1beg,x2end,x1end,x2beg); fgctri = FXCreateFGC(gctri,x,y,width,height, x1beg,x2end,x1end-x1beg,x2beg-x2end); FSetClipRectangle(fgctri,x1beg,x2end,x1end,x2beg); } else { fgcedge = FXCreateFGC(gcedge,x,y,width,height, x2beg,x1beg,x2end-x2beg,x1end-x1beg); FSetClipRectangle(fgcedge,x2beg,x1beg,x2end,x1end); fgctri = FXCreateFGC(gctri,x,y,width,height, x2beg,x1beg,x2end-x2beg,x1end-x1beg); FSetClipRectangle(fgctri,x2beg,x1beg,x2end,x1end); } /* draw image */ drawimage(dpy,win,drawregion,fgctri,model,bclip,wclip,style); /* loop over triangles */ f = model->f; do { /* get float coordinates of vertices */ if (style==XtcwpNORMAL) { x1 = f->eu->vu->v->x; y1 = f->eu->vu->v->y; x2 = f->eu->euCW->vu->v->x; y2 = f->eu->euCW->vu->v->y; x3 = f->eu->euCCW->vu->v->x; y3 = f->eu->euCCW->vu->v->y; } else { x1 = f->eu->vu->v->y; y1 = f->eu->vu->v->x; x2 = f->eu->euCW->vu->v->y; y2 = f->eu->euCW->vu->v->x; x3 = f->eu->euCCW->vu->v->y; y3 = f->eu->euCCW->vu->v->x; } /* draw edges of triangle */ fgc = f->eu->e->fixed ? fgcedge : fgctri; if (((fgc==fgcedge && !STREQ(edgecolor,"none")) || (fgc==fgctri && !STREQ(tricolor,"none")))) FXDrawLine(dpy,win,fgc,x1,y1,x2,y2); fgc = f->eu->euCW->e->fixed ? fgcedge : fgctri; if (((fgc==fgcedge && !STREQ(edgecolor,"none")) || (fgc==fgctri && !STREQ(tricolor,"none")))) FXDrawLine(dpy,win,fgc,x2,y2,x3,y3); fgc = f->eu->euCCW->e->fixed ? fgcedge : fgctri; if (((fgc==fgcedge && !STREQ(edgecolor,"none")) || (fgc==fgctri && !STREQ(tricolor,"none")))) FXDrawLine(dpy,win,fgc,x3,y3,x1,y1); f = f->fNext; } while (f!=model->f); /* free everything */ FXFreeFGC(fgcedge); FXFreeFGC(fgctri); XFreeGC(dpy,gcedge); XFreeGC(dpy,gctri); XDestroyRegion(drawregion); XDestroyRegion(tempregion); }
void drawBox (KinoWidget w, Element *box, int x, int y, LargeRegion r) { Node *p; Region regExpose, regBox, empty, intersect; XRectangle re, rb; if (box != NULL && box->display != DISPLAY_NONE && (box->display == DISPLAY_INLINE || !(x + box->x + box->width < r.x || x + box->x > r.x + r.width || y + box->y + box->height < r.y || y + box->y > r.y + r.height))) { x = x + box->x; y = y + box->y; if (box->display == DISPLAY_BLOCK) { if (box->background_color.alpha == 0) { changeGC (w, ((XFontStruct *) box->font)->fid, box->background_color, box->background_color, 0); rb.x = x + ElementTotalLeft (box); rb.y = y + ElementTotalTop (box); rb.width = box->width - ElementTotalLeft (box) - ElementTotalRight (box); rb.height = box->height - ElementTotalTop (box) - ElementTotalBottom (box); re.x = r.x; re.y = r.y; re.width = r.width; re.height = r.height; empty = XCreateRegion (); regBox = XCreateRegion (); XUnionRectWithRegion (&rb, empty, regBox); regExpose = XCreateRegion (); XUnionRectWithRegion (&re, empty, regExpose); intersect = XCreateRegion (); XIntersectRegion (regBox, regExpose, intersect); XSetRegion (XtDisplay (w), w->kino.painter->gc, intersect); XFillRectangle (XtDisplay (w), XtWindow (w), w->kino.painter->gc, r.x, r.y, r.width, r.height); XDestroyRegion (regBox); XDestroyRegion (regExpose); XDestroyRegion (empty); XDestroyRegion (intersect); } if (box->border_top_color.alpha == 0 && box->border_top_width.effective > 0) { changeGC (w, ((XFontStruct *) box->font)->fid, box->border_top_color, box->background_color, box->border_top_width.effective); XDrawLine (XtDisplay (w), XtWindow (w), w->kino.painter->gc, x + box->margin_left.effective, y + box->margin_top.effective, x + box->width - box->margin_right.effective, y + box->margin_top.effective); } if (box->border_bottom_color.alpha == 0 && box->border_bottom_width.effective > 0) { changeGC (w, ((XFontStruct *) box->font)->fid, box->border_bottom_color, box->background_color, box->border_bottom_width.effective); XDrawLine (XtDisplay (w), XtWindow (w), w->kino.painter->gc, x + box->margin_left.effective, y + box->height - box->margin_bottom.effective, x + box->width - box->margin_right.effective, y + box->height - box->margin_bottom.effective); } if (box->border_left_color.alpha == 0 && box->border_left_width.effective > 0) { changeGC (w, ((XFontStruct *) box->font)->fid, box->border_left_color, box->background_color, box->border_left_width.effective); XDrawLine (XtDisplay (w), XtWindow (w), w->kino.painter->gc, x + box->margin_left.effective, y + box->margin_top.effective, x + box->margin_left.effective, y + box->height - box->margin_bottom.effective); } if (box->border_right_color.alpha == 0 && box->border_right_width.effective > 0) { changeGC (w, ((XFontStruct *) box->font)->fid, box->border_right_color, box->background_color, box->border_right_width.effective); XDrawLine (XtDisplay (w), XtWindow (w), w->kino.painter->gc, x + box->width - box->margin_right.effective, y + box->margin_top.effective, x + box->width - box->margin_right.effective, y + box->height - box->margin_bottom.effective); } } changeGC (w, ((XFontStruct *) box->font)->fid, box->color, box->background_color, 1); p = box->contents; while (p != NULL) { switch (p->type) { case TEXT_NODE: drawWord (w, box, (Text *) p, x, y, r); break; case ELEMENT_NODE: drawBox (w, (Element *) p, x, y, r); changeGC (w, ((XFontStruct *) box->font)->fid, box->color, box->background_color, 1); break; default: break; } p = p->next; } } }
static PyObject * pixmap_Intersected(PaxPixmapObject * self, PyObject * args) { PyObject * other; XGCValues values; GC gc; Pixmap bitmap; Window root; int x, y; unsigned int width, height, border_width, depth; if (!PyArg_ParseTuple(args, "O", &other)) return NULL; if (!XGetGeometry(self->display, self->pixmap, &root, &x, &y, &width, &height, &border_width, &depth)) { PyErr_SetString(PyExc_RuntimeError, "Cannot get pixmap geometry"); return NULL; } if (depth != 1) { PyErr_SetString(PyExc_TypeError, "pixmap must have depth 1"); return NULL; } bitmap = XCreatePixmap(self->display, self->pixmap, width, height, 1); values.foreground = 0; values.background = 0; gc = XCreateGC(self->display, bitmap, GCForeground | GCBackground, &values); XFillRectangle(self->display, bitmap, gc, 0, 0, width, height); XSetForeground(self->display, gc, 1); if (PaxRegion_Check(other)) { XSetRegion(self->display, gc, PaxRegion_AsRegion(other)); XCopyPlane(self->display, self->pixmap, bitmap, gc, 0, 0, width, height, 0, 0, 1); } else if (PaxPixmap_Check(other)) { XCopyPlane(self->display, self->pixmap, bitmap, gc, 0, 0, width, height, 0, 0, 1); XSetFunction(self->display, gc, GXand); XCopyPlane(self->display, PaxPixmap_AsPixmap(other), bitmap, gc, 0, 0, width, height, 0, 0, 1); } else { XFreeGC(self->display, gc); XFreePixmap(self->display, bitmap); PyErr_SetString(PyExc_TypeError, "argument must be either pixmap or region"); return NULL; } XFreeGC(self->display, gc); return PaxPixmap_FromPixmap(self->display, bitmap, 1); }
static void xf_draw_screen_scaled(xfContext* xfc, int x, int y, int w, int h) { XTransform transform; Picture windowPicture; Picture primaryPicture; XRenderPictureAttributes pa; XRenderPictFormat* picFormat; double xScalingFactor; double yScalingFactor; int x2; int y2; if (xfc->scaledWidth <= 0 || xfc->scaledHeight <= 0) { WLog_ERR(TAG, "the current window dimensions are invalid"); return; } if (xfc->sessionWidth <= 0 || xfc->sessionHeight <= 0) { WLog_ERR(TAG, "the window dimensions are invalid"); return; } xScalingFactor = xfc->sessionWidth / (double)xfc->scaledWidth; yScalingFactor = xfc->sessionHeight / (double)xfc->scaledHeight; XSetFillStyle(xfc->display, xfc->gc, FillSolid); XSetForeground(xfc->display, xfc->gc, 0); /* Black out possible space between desktop and window borders */ { XRectangle box1 = { 0, 0, xfc->window->width, xfc->window->height }; XRectangle box2 = { xfc->offset_x, xfc->offset_y, xfc->scaledWidth, xfc->scaledHeight }; Region reg1 = XCreateRegion(); Region reg2 = XCreateRegion(); XUnionRectWithRegion(&box1, reg1, reg1); XUnionRectWithRegion(&box2, reg2, reg2); if (XSubtractRegion(reg1, reg2, reg1) && !XEmptyRegion(reg1)) { XSetRegion(xfc->display, xfc->gc, reg1); XFillRectangle(xfc->display, xfc->window->handle, xfc->gc, 0, 0, xfc->window->width, xfc->window->height); XSetClipMask(xfc->display, xfc->gc, None); } XDestroyRegion(reg1); XDestroyRegion(reg2); } picFormat = XRenderFindVisualFormat(xfc->display, xfc->visual); pa.subwindow_mode = IncludeInferiors; primaryPicture = XRenderCreatePicture(xfc->display, xfc->primary, picFormat, CPSubwindowMode, &pa); windowPicture = XRenderCreatePicture(xfc->display, xfc->window->handle, picFormat, CPSubwindowMode, &pa); XRenderSetPictureFilter(xfc->display, primaryPicture, FilterBilinear, 0, 0); transform.matrix[0][0] = XDoubleToFixed(xScalingFactor); transform.matrix[0][1] = XDoubleToFixed(0.0); transform.matrix[0][2] = XDoubleToFixed(0.0); transform.matrix[1][0] = XDoubleToFixed(0.0); transform.matrix[1][1] = XDoubleToFixed(yScalingFactor); transform.matrix[1][2] = XDoubleToFixed(0.0); transform.matrix[2][0] = XDoubleToFixed(0.0); transform.matrix[2][1] = XDoubleToFixed(0.0); transform.matrix[2][2] = XDoubleToFixed(1.0); /* calculate and fix up scaled coordinates */ x2 = x + w; y2 = y + h; x = floor(x / xScalingFactor) - 1; y = floor(y / yScalingFactor) - 1; w = ceil(x2 / xScalingFactor) + 1 - x; h = ceil(y2 / yScalingFactor) + 1 - y; XRenderSetPictureTransform(xfc->display, primaryPicture, &transform); XRenderComposite(xfc->display, PictOpSrc, primaryPicture, 0, windowPicture, x, y, 0, 0, xfc->offset_x + x, xfc->offset_y + y, w, h); XRenderFreePicture(xfc->display, primaryPicture); XRenderFreePicture(xfc->display, windowPicture); }
void TkSetRegion(Display *d, GC g, TkRegion r) { XSetRegion(d, g, (Region)r); }