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 <pcg@goof.com> |
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 2 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 == STATE_UP) |
64 |
|| (dirn == DN && sb->state == 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 & R_SB_RXVT) == 0) |
156 |
{ |
157 |
XGCValues gcvalue; |
158 |
|
159 |
init |= R_SB_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 |
if (shadow) |
168 |
{ |
169 |
XSetWindowBackground (term->dpy, win, term->pix_colors_focused[Color_trough]); |
170 |
XClearWindow (term->dpy, win); |
171 |
} |
172 |
} |
173 |
else |
174 |
{ |
175 |
if (update) |
176 |
{ |
177 |
if (last_top < top) |
178 |
XClearArea (term->dpy, win, |
179 |
shadow, last_top, |
180 |
sbwidth, (top - last_top), |
181 |
False); |
182 |
|
183 |
if (bot < last_bot) |
184 |
XClearArea (term->dpy, win, |
185 |
shadow, bot, |
186 |
sbwidth, (last_bot - bot), |
187 |
False); |
188 |
} |
189 |
else |
190 |
XClearWindow (term->dpy, win); |
191 |
} |
192 |
|
193 |
/* scrollbar slider */ |
194 |
#ifdef SB_BORDER |
195 |
{ |
196 |
int xofs; |
197 |
|
198 |
if (term->option (Opt_scrollBar_right)) |
199 |
xofs = 0; |
200 |
else |
201 |
xofs = shadow ? sbwidth : sbwidth - 1; |
202 |
|
203 |
XDrawLine (term->dpy, win, botShadowGC, |
204 |
xofs, 0, xofs, end + sbwidth); |
205 |
} |
206 |
#endif |
207 |
|
208 |
XFillRectangle (term->dpy, win, scrollbarGC, |
209 |
shadow, top, sbwidth, |
210 |
bot - top); |
211 |
|
212 |
if (shadow) |
213 |
/* trough shadow */ |
214 |
draw_shadow (this, 0, 0, sbwidth + 2 * shadow, end + (sbwidth + 1) + shadow); |
215 |
|
216 |
/* shadow for scrollbar slider */ |
217 |
draw_shadow (this, shadow, top, sbwidth, bot - top); |
218 |
|
219 |
/* Redraw scrollbar arrows */ |
220 |
draw_button (this, shadow, shadow, UP); |
221 |
draw_button (this, shadow, end + 1, DN); |
222 |
|
223 |
return 1; |
224 |
} |
225 |
#endif /* RXVT_SCROLLBAR */ |
226 |
/*----------------------- end-of-file (C source) -----------------------*/ |
227 |
|