--- rxvt-unicode/src/scrollbar-rxvt.C 2006/01/16 18:09:28 1.23 +++ rxvt-unicode/src/scrollbar-rxvt.C 2008/02/19 13:01:33 1.37 @@ -1,10 +1,10 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: scrollbar-rxvt.C *----------------------------------------------------------------------* * * Copyright (c) 1997,1998 mj olesen * Copyright (c) 1999-2001 Geoff Wing - * Copyright (c) 2004 Marc Lehmann + * Copyright (c) 2004-2006 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,54 +27,56 @@ /*----------------------------------------------------------------------*/ #if defined(RXVT_SCROLLBAR) -#define SHADOW_WIDTH 1 - -static void -draw_shadow (rxvt_term *term, int x, int y, int w, int h) -{ +static void +draw_shadow (scrollBar_t *sb, int x, int y, int w, int h) +{ int shadow; - + Drawable d = sb->win; + Display *dpy = sb->term->dpy; + shadow = (w == 0 || h == 0) ? 1 : SHADOW_WIDTH; w += x - 1; h += y - 1; + for (; shadow-- > 0; x++, y++, w--, h--) - { - XDrawLine (term->display->display, term->scrollBar.win, term->topShadowGC, x, y, w, y); - XDrawLine (term->display->display, term->scrollBar.win, term->topShadowGC, x, y, x, h); - XDrawLine (term->display->display, term->scrollBar.win, term->botShadowGC, w, h, w, y + 1); - XDrawLine (term->display->display, term->scrollBar.win, term->botShadowGC, w, h, x + 1, h); - } -} + { + XDrawLine (dpy, d, sb->topShadowGC, x, y, w , y ); + XDrawLine (dpy, d, sb->topShadowGC, x, y, x , h ); + XDrawLine (dpy, d, sb->botShadowGC, w, h, w , y + 1); + XDrawLine (dpy, d, sb->botShadowGC, w, h, x + 1, h ); + } +} /* draw triangular button with a shadow of 2 pixels */ static void -draw_button (rxvt_term *term, int x, int y, int state, int dirn) +draw_button (scrollBar_t *sb, int x, int y, int dirn) { unsigned int sz, sz2; XPoint pt[3]; GC top, bot; + Drawable d = sb->win; + Display *dpy = sb->term->dpy; - sz = term->scrollBar.width; + sz = sb->width; sz2 = sz / 2; - switch (state) + + if ((dirn == UP && sb->state == STATE_UP) + || (dirn == DN && sb->state == STATE_DOWN)) { - case +1: - top = term->topShadowGC; - bot = term->botShadowGC; - break; - case -1: - top = term->botShadowGC; - bot = term->topShadowGC; - break; - default: - top = bot = term->scrollbarGC; - break; + top = sb->botShadowGC; + bot = sb->topShadowGC; + } + else + { + top = sb->topShadowGC; + bot = sb->botShadowGC; } /* fill triangle */ pt[0].x = x; pt[1].x = x + sz - 1; pt[2].x = x + sz2; + if (dirn == UP) { pt[0].y = pt[1].y = y + sz - 1; @@ -86,17 +88,17 @@ pt[2].y = y + sz - 1; } - XFillPolygon (term->display->display, term->scrollBar.win, term->scrollbarGC, + XFillPolygon (dpy, d, sb->scrollbarGC, pt, 3, Convex, CoordModeOrigin); /* draw base */ - XDrawLine (term->display->display, term->scrollBar.win, (dirn == UP ? bot : top), + XDrawLine (dpy, d, (dirn == UP ? bot : top), pt[0].x, pt[0].y, pt[1].x, pt[1].y); /* draw shadow on left */ pt[1].x = x + sz2 - 1; pt[1].y = y + (dirn == UP ? 0 : sz - 1); - XDrawLine (term->display->display, term->scrollBar.win, top, + XDrawLine (dpy, d, top, pt[0].x, pt[0].y, pt[1].x, pt[1].y); #if SHADOW_WIDTH > 1 @@ -114,7 +116,7 @@ pt[1].y--; } - XDrawLine (term->display->display, term->scrollBar.win, top, + XDrawLine (dpy, d, top, pt[0].x, pt[0].y, pt[1].x, pt[1].y); #endif @@ -123,7 +125,7 @@ /* pt[2].x = x + sz2; */ pt[1].y = y + (dirn == UP ? sz - 1 : 0); pt[2].y = y + (dirn == UP ? 0 : sz - 1); - XDrawLine (term->display->display, term->scrollBar.win, bot, + XDrawLine (dpy, d, bot, pt[2].x, pt[2].y, pt[1].x, pt[1].y); #if SHADOW_WIDTH > 1 @@ -140,45 +142,53 @@ pt[1].y++; } - XDrawLine (term->display->display, term->scrollBar.win, bot, + XDrawLine (dpy, d, bot, pt[2].x, pt[2].y, pt[1].x, pt[1].y); #endif } int -rxvt_term::scrollbar_show_rxvt (int update, int last_top, int last_bot, int scrollbar_len) +scrollBar_t::show_rxvt (int update) { - int sbshadow = sb_shadow; - int sbwidth = (int)scrollBar.width; + int sbshadow = shadow; + int sbwidth = (int)width; - if ((scrollBar.init & R_SB_RXVT) == 0) + if ((init & R_SB_RXVT) == 0) { - scrollBar.init |= R_SB_RXVT; + XGCValues gcvalue; + + init |= R_SB_RXVT; + gcvalue.foreground = term->pix_colors[Color_topShadow]; + topShadowGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue); + gcvalue.foreground = term->pix_colors[Color_bottomShadow]; + botShadowGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue); + gcvalue.foreground = term->pix_colors[ (term->depth <= 2 ? Color_fg : Color_scroll)]; + scrollbarGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue); if (sbshadow) { - XSetWindowBackground (display->display, scrollBar.win, pix_colors_focused[Color_trough]); - XClearWindow (display->display, scrollBar.win); + XSetWindowBackground (term->dpy, win, term->pix_colors_focused[Color_trough]); + XClearWindow (term->dpy, win); } } else { if (update) { - if (last_top < scrollBar.top) - XClearArea (display->display, scrollBar.win, + if (last_top < top) + XClearArea (term->dpy, win, sbshadow, last_top, - sbwidth, (scrollBar.top - last_top), + sbwidth, (top - last_top), False); - if (scrollBar.bot < last_bot) - XClearArea (display->display, scrollBar.win, - sbshadow, scrollBar.bot, - sbwidth, (last_bot - scrollBar.bot), + if (bot < last_bot) + XClearArea (term->dpy, win, + sbshadow, bot, + sbwidth, (last_bot - bot), False); } else - XClearWindow (display->display, scrollBar.win); + XClearWindow (term->dpy, win); } /* scrollbar slider */ @@ -186,33 +196,33 @@ { int xofs; - if (OPTION (Opt_scrollBar_right)) + if (term->option (Opt_scrollBar_right)) xofs = 0; else xofs = sbshadow ? sbwidth : sbwidth - 1; - XDrawLine (display->display, scrollBar.win, botShadowGC, - xofs, 0, xofs, scrollBar.end + sbwidth); + XDrawLine (term->dpy, win, botShadowGC, + xofs, 0, xofs, end + sbwidth); } #endif - XFillRectangle (display->display, scrollBar.win, scrollbarGC, - sbshadow, scrollBar.top, sbwidth, - scrollbar_len); + XFillRectangle (term->dpy, win, scrollbarGC, + sbshadow, top, sbwidth, + len); if (sbshadow) /* trough shadow */ - draw_shadow (this, 0, 0, sbwidth + 2 * sbshadow, scrollBar.end + (sbwidth + 1) + sbshadow); + draw_shadow (this, 0, 0, sbwidth + 2 * sbshadow, end + (sbwidth + 1) + sbshadow); /* shadow for scrollbar slider */ - draw_shadow (this, sbshadow, scrollBar.top, sbwidth, scrollbar_len); + draw_shadow (this, sbshadow, top, sbwidth, len); /* Redraw scrollbar arrows */ - draw_button (this, sbshadow, sbshadow, (scrollbar_isUp () ? -1 : +1), UP); - draw_button (this, sbshadow, scrollBar.end + 1, (scrollbar_isDn () ? -1 : +1), DN); + draw_button (this, sbshadow, sbshadow, UP); + draw_button (this, sbshadow, end + 1, DN); return 1; } -#endif /* RXVT_SCROLLBAR */ +#endif /* RXVT_SCROLLBAR */ /*----------------------- end-of-file (C source) -----------------------*/