| 1 |
/*----------------------------------------------------------------------* |
| 2 |
* File: scrollbar-rxvt.C |
| 3 |
*----------------------------------------------------------------------* |
| 4 |
* |
| 5 |
* Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA> |
| 6 |
* Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com> |
| 7 |
* Copyright (c) 2004-2006 Marc Lehmann <schmorp@schmorp.de> |
| 8 |
* |
| 9 |
* This program is free software; you can redistribute it and/or modify |
| 10 |
* it under the terms of the GNU General Public License as published by |
| 11 |
* the Free Software Foundation; either version 3 of the License, or |
| 12 |
* (at your option) any later version. |
| 13 |
* |
| 14 |
* This program is distributed in the hope that it will be useful, |
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
* GNU General Public License for more details. |
| 18 |
* |
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with this program; if not, write to the Free Software |
| 21 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 |
*----------------------------------------------------------------------*/ |
| 23 |
|
| 24 |
#include "../config.h" /* NECESSARY */ |
| 25 |
#include "rxvt.h" /* NECESSARY */ |
| 26 |
|
| 27 |
/*----------------------------------------------------------------------*/ |
| 28 |
#if defined(RXVT_SCROLLBAR) |
| 29 |
|
| 30 |
static void |
| 31 |
draw_shadow (scrollBar_t *sb, int x, int y, int w, int h) |
| 32 |
{ |
| 33 |
int shadow; |
| 34 |
Drawable d = sb->win; |
| 35 |
Display *dpy = sb->term->dpy; |
| 36 |
|
| 37 |
shadow = (w == 0 || h == 0) ? 1 : SHADOW_WIDTH; |
| 38 |
w += x - 1; |
| 39 |
h += y - 1; |
| 40 |
|
| 41 |
for (; shadow-- > 0; x++, y++, w--, h--) |
| 42 |
{ |
| 43 |
XDrawLine (dpy, d, sb->topShadowGC, x, y, w , y ); |
| 44 |
XDrawLine (dpy, d, sb->topShadowGC, x, y, x , h ); |
| 45 |
XDrawLine (dpy, d, sb->botShadowGC, w, h, w , y + 1); |
| 46 |
XDrawLine (dpy, d, sb->botShadowGC, w, h, x + 1, h ); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/* draw triangular button with a shadow of 2 pixels */ |
| 51 |
static void |
| 52 |
draw_button (scrollBar_t *sb, int x, int y, int dirn) |
| 53 |
{ |
| 54 |
unsigned int sz, sz2; |
| 55 |
XPoint pt[3]; |
| 56 |
GC top, bot; |
| 57 |
Drawable d = sb->win; |
| 58 |
Display *dpy = sb->term->dpy; |
| 59 |
|
| 60 |
sz = sb->width; |
| 61 |
sz2 = sz / 2; |
| 62 |
|
| 63 |
if ((dirn == UP && sb->state == SB_STATE_UP) |
| 64 |
|| (dirn == DN && sb->state == SB_STATE_DOWN)) |
| 65 |
{ |
| 66 |
top = sb->botShadowGC; |
| 67 |
bot = sb->topShadowGC; |
| 68 |
} |
| 69 |
else |
| 70 |
{ |
| 71 |
top = sb->topShadowGC; |
| 72 |
bot = sb->botShadowGC; |
| 73 |
} |
| 74 |
|
| 75 |
/* fill triangle */ |
| 76 |
pt[0].x = x; |
| 77 |
pt[1].x = x + sz - 1; |
| 78 |
pt[2].x = x + sz2; |
| 79 |
|
| 80 |
if (dirn == UP) |
| 81 |
{ |
| 82 |
pt[0].y = pt[1].y = y + sz - 1; |
| 83 |
pt[2].y = y; |
| 84 |
} |
| 85 |
else |
| 86 |
{ |
| 87 |
pt[0].y = pt[1].y = y; |
| 88 |
pt[2].y = y + sz - 1; |
| 89 |
} |
| 90 |
|
| 91 |
XFillPolygon (dpy, d, sb->scrollbarGC, |
| 92 |
pt, 3, Convex, CoordModeOrigin); |
| 93 |
|
| 94 |
/* draw base */ |
| 95 |
XDrawLine (dpy, d, (dirn == UP ? bot : top), |
| 96 |
pt[0].x, pt[0].y, pt[1].x, pt[1].y); |
| 97 |
|
| 98 |
/* draw shadow on left */ |
| 99 |
pt[1].x = x + sz2 - 1; |
| 100 |
pt[1].y = y + (dirn == UP ? 0 : sz - 1); |
| 101 |
XDrawLine (dpy, d, top, |
| 102 |
pt[0].x, pt[0].y, pt[1].x, pt[1].y); |
| 103 |
|
| 104 |
#if SHADOW_WIDTH > 1 |
| 105 |
/* doubled */ |
| 106 |
pt[0].x++; |
| 107 |
|
| 108 |
if (dirn == UP) |
| 109 |
{ |
| 110 |
pt[0].y--; |
| 111 |
pt[1].y++; |
| 112 |
} |
| 113 |
else |
| 114 |
{ |
| 115 |
pt[0].y++; |
| 116 |
pt[1].y--; |
| 117 |
} |
| 118 |
|
| 119 |
XDrawLine (dpy, d, top, |
| 120 |
pt[0].x, pt[0].y, pt[1].x, pt[1].y); |
| 121 |
#endif |
| 122 |
|
| 123 |
/* draw shadow on right */ |
| 124 |
pt[1].x = x + sz - 1; |
| 125 |
/* pt[2].x = x + sz2; */ |
| 126 |
pt[1].y = y + (dirn == UP ? sz - 1 : 0); |
| 127 |
pt[2].y = y + (dirn == UP ? 0 : sz - 1); |
| 128 |
XDrawLine (dpy, d, bot, |
| 129 |
pt[2].x, pt[2].y, pt[1].x, pt[1].y); |
| 130 |
|
| 131 |
#if SHADOW_WIDTH > 1 |
| 132 |
/* doubled */ |
| 133 |
pt[1].x--; |
| 134 |
if (dirn == UP) |
| 135 |
{ |
| 136 |
pt[2].y++; |
| 137 |
pt[1].y--; |
| 138 |
} |
| 139 |
else |
| 140 |
{ |
| 141 |
pt[2].y--; |
| 142 |
pt[1].y++; |
| 143 |
} |
| 144 |
|
| 145 |
XDrawLine (dpy, d, bot, |
| 146 |
pt[2].x, pt[2].y, pt[1].x, pt[1].y); |
| 147 |
#endif |
| 148 |
} |
| 149 |
|
| 150 |
int |
| 151 |
scrollBar_t::show_rxvt (int update) |
| 152 |
{ |
| 153 |
int sbwidth = (int)width; |
| 154 |
|
| 155 |
if ((init & SB_STYLE_RXVT) == 0) |
| 156 |
{ |
| 157 |
XGCValues gcvalue; |
| 158 |
|
| 159 |
init |= SB_STYLE_RXVT; |
| 160 |
|
| 161 |
gcvalue.foreground = term->pix_colors[Color_topShadow]; |
| 162 |
topShadowGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue); |
| 163 |
gcvalue.foreground = term->pix_colors[Color_bottomShadow]; |
| 164 |
botShadowGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue); |
| 165 |
gcvalue.foreground = term->pix_colors[ (term->depth <= 2 ? Color_fg : Color_scroll)]; |
| 166 |
scrollbarGC = XCreateGC (term->dpy, term->vt, GCForeground, &gcvalue); |
| 167 |
} |
| 168 |
else |
| 169 |
{ |
| 170 |
if (update) |
| 171 |
{ |
| 172 |
if (last_top < top) |
| 173 |
XClearArea (term->dpy, win, |
| 174 |
shadow, last_top, |
| 175 |
sbwidth, (top - last_top), |
| 176 |
False); |
| 177 |
|
| 178 |
if (bot < last_bot) |
| 179 |
XClearArea (term->dpy, win, |
| 180 |
shadow, bot, |
| 181 |
sbwidth, (last_bot - bot), |
| 182 |
False); |
| 183 |
} |
| 184 |
else |
| 185 |
XClearWindow (term->dpy, win); |
| 186 |
} |
| 187 |
|
| 188 |
/* scrollbar slider */ |
| 189 |
#ifdef SB_BORDER |
| 190 |
{ |
| 191 |
int xofs; |
| 192 |
|
| 193 |
if (term->option (Opt_scrollBar_right)) |
| 194 |
xofs = 0; |
| 195 |
else |
| 196 |
xofs = shadow ? sbwidth : sbwidth - 1; |
| 197 |
|
| 198 |
XDrawLine (term->dpy, win, botShadowGC, |
| 199 |
xofs, 0, xofs, end + sbwidth); |
| 200 |
} |
| 201 |
#endif |
| 202 |
|
| 203 |
XFillRectangle (term->dpy, win, scrollbarGC, |
| 204 |
shadow, top, sbwidth, |
| 205 |
bot - top); |
| 206 |
|
| 207 |
if (shadow) |
| 208 |
/* trough shadow */ |
| 209 |
draw_shadow (this, 0, 0, sbwidth + 2 * shadow, end + (sbwidth + 1) + shadow); |
| 210 |
|
| 211 |
/* shadow for scrollbar slider */ |
| 212 |
draw_shadow (this, shadow, top, sbwidth, bot - top); |
| 213 |
|
| 214 |
/* Redraw scrollbar arrows */ |
| 215 |
draw_button (this, shadow, shadow, UP); |
| 216 |
draw_button (this, shadow, end + 1, DN); |
| 217 |
|
| 218 |
return 1; |
| 219 |
} |
| 220 |
#endif /* RXVT_SCROLLBAR */ |
| 221 |
/*----------------------- end-of-file (C source) -----------------------*/ |
| 222 |
|