ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/scrollbar-rxvt.C
Revision: 1.40
Committed: Tue Mar 30 10:31:07 2010 UTC (14 years, 1 month ago) by sf-exg
Content type: text/plain
Branch: MAIN
CVS Tags: before_dynamic_fontidx, rel-9_10, dynamic_fontidx, rel-9_09
Changes since 1.39: +2 -1 lines
Log Message:
Move 'shadow' initialization to 'show_rxvt'.

File Contents

# User Rev Content
1 root 1.29 /*----------------------------------------------------------------------*
2 pcg 1.9 * File: scrollbar-rxvt.C
3 pcg 1.1 *----------------------------------------------------------------------*
4     *
5     * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
6     * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
7 root 1.28 * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com>
8 pcg 1.1 *
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 root 1.24 static void
31 ayin 1.37 draw_shadow (scrollBar_t *sb, int x, int y, int w, int h)
32 root 1.24 {
33 root 1.23 int shadow;
34 ayin 1.37 Drawable d = sb->win;
35     Display *dpy = sb->term->dpy;
36 root 1.24
37 root 1.22 shadow = (w == 0 || h == 0) ? 1 : SHADOW_WIDTH;
38     w += x - 1;
39     h += y - 1;
40 root 1.24
41 root 1.22 for (; shadow-- > 0; x++, y++, w--, h--)
42 root 1.24 {
43 ayin 1.37 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 root 1.24 }
48     }
49 root 1.21
50     /* draw triangular button with a shadow of 2 pixels */
51 root 1.23 static void
52 ayin 1.37 draw_button (scrollBar_t *sb, int x, int y, int dirn)
53 pcg 1.1 {
54 root 1.23 unsigned int sz, sz2;
55     XPoint pt[3];
56     GC top, bot;
57 ayin 1.37 Drawable d = sb->win;
58     Display *dpy = sb->term->dpy;
59 pcg 1.6
60 ayin 1.37 sz = sb->width;
61 pcg 1.6 sz2 = sz / 2;
62 root 1.26
63 ayin 1.37 if ((dirn == UP && sb->state == STATE_UP)
64     || (dirn == DN && sb->state == STATE_DOWN))
65 pcg 1.6 {
66 ayin 1.37 top = sb->botShadowGC;
67     bot = sb->topShadowGC;
68 ayin 1.36 }
69     else
70     {
71 ayin 1.37 top = sb->topShadowGC;
72     bot = sb->botShadowGC;
73 pcg 1.6 }
74    
75     /* fill triangle */
76     pt[0].x = x;
77     pt[1].x = x + sz - 1;
78     pt[2].x = x + sz2;
79 root 1.26
80 pcg 1.6 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 root 1.10
91 ayin 1.37 XFillPolygon (dpy, d, sb->scrollbarGC,
92 root 1.10 pt, 3, Convex, CoordModeOrigin);
93 pcg 1.6
94     /* draw base */
95 ayin 1.37 XDrawLine (dpy, d, (dirn == UP ? bot : top),
96 root 1.10 pt[0].x, pt[0].y, pt[1].x, pt[1].y);
97 pcg 1.6
98     /* draw shadow on left */
99     pt[1].x = x + sz2 - 1;
100     pt[1].y = y + (dirn == UP ? 0 : sz - 1);
101 ayin 1.37 XDrawLine (dpy, d, top,
102 root 1.10 pt[0].x, pt[0].y, pt[1].x, pt[1].y);
103 pcg 1.1
104 root 1.22 #if SHADOW_WIDTH > 1
105 pcg 1.6 /* doubled */
106     pt[0].x++;
107 root 1.17
108 pcg 1.6 if (dirn == UP)
109     {
110     pt[0].y--;
111     pt[1].y++;
112 pcg 1.1 }
113 pcg 1.6 else
114     {
115     pt[0].y++;
116     pt[1].y--;
117     }
118 root 1.17
119 ayin 1.37 XDrawLine (dpy, d, top,
120 root 1.10 pt[0].x, pt[0].y, pt[1].x, pt[1].y);
121 pcg 1.1 #endif
122 root 1.21
123 pcg 1.6 /* 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 ayin 1.37 XDrawLine (dpy, d, bot,
129 root 1.10 pt[2].x, pt[2].y, pt[1].x, pt[1].y);
130 root 1.17
131 root 1.22 #if SHADOW_WIDTH > 1
132 pcg 1.6 /* doubled */
133     pt[1].x--;
134     if (dirn == UP)
135     {
136     pt[2].y++;
137     pt[1].y--;
138 pcg 1.1 }
139 pcg 1.6 else
140     {
141     pt[2].y--;
142     pt[1].y++;
143     }
144 root 1.10
145 ayin 1.37 XDrawLine (dpy, d, bot,
146 root 1.10 pt[2].x, pt[2].y, pt[1].x, pt[1].y);
147 pcg 1.1 #endif
148     }
149    
150     int
151 ayin 1.37 scrollBar_t::show_rxvt (int update)
152 pcg 1.1 {
153 ayin 1.37 int sbwidth = (int)width;
154 pcg 1.1
155 ayin 1.37 if ((init & R_SB_RXVT) == 0)
156 pcg 1.6 {
157 ayin 1.34 XGCValues gcvalue;
158    
159 ayin 1.37 init |= R_SB_RXVT;
160 root 1.18
161 ayin 1.37 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 sf-exg 1.40 if (!term->option (Opt_scrollBar_floating))
168 pcg 1.6 {
169 sf-exg 1.40 shadow = SHADOW_WIDTH;
170 ayin 1.37 XSetWindowBackground (term->dpy, win, term->pix_colors_focused[Color_trough]);
171     XClearWindow (term->dpy, win);
172 pcg 1.6 }
173     }
174     else
175     {
176 root 1.16 if (update)
177     {
178 ayin 1.37 if (last_top < top)
179     XClearArea (term->dpy, win,
180 sf-exg 1.39 shadow, last_top,
181 ayin 1.37 sbwidth, (top - last_top),
182 root 1.16 False);
183    
184 ayin 1.37 if (bot < last_bot)
185     XClearArea (term->dpy, win,
186 sf-exg 1.39 shadow, bot,
187 ayin 1.37 sbwidth, (last_bot - bot),
188 root 1.16 False);
189     }
190     else
191 ayin 1.37 XClearWindow (term->dpy, win);
192 pcg 1.1 }
193    
194 pcg 1.6 /* scrollbar slider */
195 pcg 1.1 #ifdef SB_BORDER
196 pcg 1.6 {
197 root 1.10 int xofs;
198 pcg 1.1
199 ayin 1.37 if (term->option (Opt_scrollBar_right))
200 pcg 1.6 xofs = 0;
201     else
202 sf-exg 1.39 xofs = shadow ? sbwidth : sbwidth - 1;
203 pcg 1.6
204 ayin 1.37 XDrawLine (term->dpy, win, botShadowGC,
205     xofs, 0, xofs, end + sbwidth);
206 pcg 1.6 }
207     #endif
208 root 1.10
209 ayin 1.37 XFillRectangle (term->dpy, win, scrollbarGC,
210 sf-exg 1.39 shadow, top, sbwidth,
211 ayin 1.38 bot - top);
212 pcg 1.1
213 sf-exg 1.39 if (shadow)
214 pcg 1.6 /* trough shadow */
215 sf-exg 1.39 draw_shadow (this, 0, 0, sbwidth + 2 * shadow, end + (sbwidth + 1) + shadow);
216 root 1.10
217 pcg 1.6 /* shadow for scrollbar slider */
218 sf-exg 1.39 draw_shadow (this, shadow, top, sbwidth, bot - top);
219 pcg 1.6
220 root 1.10 /* Redraw scrollbar arrows */
221 sf-exg 1.39 draw_button (this, shadow, shadow, UP);
222     draw_button (this, shadow, end + 1, DN);
223 root 1.10
224 pcg 1.6 return 1;
225 pcg 1.1 }
226 ayin 1.31 #endif /* RXVT_SCROLLBAR */
227 pcg 1.1 /*----------------------- end-of-file (C source) -----------------------*/
228 root 1.18