ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/scrollbar-next.C
Revision: 1.35
Committed: Fri May 30 19:44:11 2014 UTC (9 years, 11 months ago) by sf-exg
Content type: text/plain
Branch: MAIN
CVS Tags: rxvt-unicode-rel-9_29, rxvt-unicode-rel-9_26, rxvt-unicode-rel-9_25, rxvt-unicode-rel-9_22, rxvt-unicode-rel-9_21, rxvt-unicode-rel-9_30, HEAD
Changes since 1.34: +13 -2 lines
Log Message:
Fix height and position of the stippled area in next scrollbar, patch by totto.

File Contents

# User Rev Content
1 root 1.25 /*----------------------------------------------------------------------*
2 pcg 1.10 * File: scrollbar-next.C
3 pcg 1.1 *----------------------------------------------------------------------*
4     *
5     * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
6     * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
7     * - N*XTstep like scrollbars
8     * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
9 root 1.31 * Copyright (c) 2004-2006 Marc Lehmann <schmorp@schmorp.de>
10 pcg 1.1 *
11     * This program is free software; you can redistribute it and/or modify
12     * it under the terms of the GNU General Public License as published by
13 root 1.33 * the Free Software Foundation; either version 3 of the License, or
14 pcg 1.1 * (at your option) any later version.
15     *
16     * This program is distributed in the hope that it will be useful,
17     * but WITHOUT ANY WARRANTY; without even the implied warranty of
18     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19     * GNU General Public License for more details.
20     *
21     * You should have received a copy of the GNU General Public License
22     * along with this program; if not, write to the Free Software
23     * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24     *----------------------------------------------------------------------*/
25    
26     #include "../config.h" /* NECESSARY */
27     #include "rxvt.h" /* NECESSARY */
28    
29     /*----------------------------------------------------------------------*/
30     #if defined(NEXT_SCROLLBAR)
31    
32     #define n_stp_width 8
33     #define n_stp_height 2
34     const unsigned char n_stp_bits[] = { 0x55, 0xaa };
35    
36     /*
37     * N*XTSTEP like scrollbar - written by Alfredo K. Kojima
38     */
39     #define SCROLLER_DIMPLE_WIDTH 6
40     #define SCROLLER_DIMPLE_HEIGHT 6
41     #define ARROW_WIDTH 13
42     #define ARROW_HEIGHT 13
43    
44 pcg 1.7 const char *const SCROLLER_DIMPLE[] =
45     {
46 pcg 1.1 ".%###.",
47     "%#%%%%",
48     "#%%...",
49     "#%.. ",
50     "#%. ",
51     ".%. ."
52 pcg 1.7 };
53     const char *const SCROLLER_ARROW_UP[] =
54     {
55 pcg 1.1 ".............",
56     ".............",
57     "......%......",
58     "......#......",
59     ".....%#%.....",
60     ".....###.....",
61     "....%###%....",
62     "....#####....",
63     "...%#####%...",
64     "...#######...",
65     "..%#######%..",
66     ".............",
67     "............."
68 pcg 1.7 };
69     const char *const SCROLLER_ARROW_DOWN[] =
70     {
71 pcg 1.1 ".............",
72     ".............",
73     "..%#######%..",
74     "...#######...",
75     "...%#####%...",
76     "....#####....",
77     "....%###%....",
78     ".....###.....",
79     ".....%#%.....",
80     "......#......",
81     "......%......",
82     ".............",
83     "............."
84 pcg 1.7 };
85     const char *const HI_SCROLLER_ARROW_UP[] =
86     {
87 pcg 1.1 " ",
88     " ",
89     " % ",
90     " % ",
91     " %%% ",
92     " %%% ",
93     " %%%%% ",
94     " %%%%% ",
95     " %%%%%%% ",
96     " %%%%%%% ",
97     " %%%%%%%%% ",
98     " ",
99     " "
100 pcg 1.7 };
101     const char *const HI_SCROLLER_ARROW_DOWN[] =
102     {
103 pcg 1.1 " ",
104     " ",
105     " %%%%%%%%% ",
106     " %%%%%%% ",
107     " %%%%%%% ",
108     " %%%%% ",
109     " %%%%% ",
110     " %%% ",
111     " %%% ",
112     " % ",
113     " % ",
114     " ",
115     " "
116 pcg 1.7 };
117 pcg 1.1
118 ayin 1.29 static Pixmap
119     renderPixmap (scrollBar_t *sb, const char *const *data, int width, int height)
120 pcg 1.1 {
121 pcg 1.7 char a;
122     int x, y;
123     Pixmap d;
124     GC pointcolour;
125    
126 ayin 1.29 d = XCreatePixmap (sb->term->dpy, sb->win, width, height, sb->term->depth);
127 pcg 1.7
128     for (y = 0; y < height; y++)
129     {
130     for (x = 0; x < width; x++)
131     {
132     if ((a = data[y][x]) == ' ' || a == 'w')
133 ayin 1.29 pointcolour = sb->whiteGC;
134 pcg 1.7 else if (a == '.' || a == 'l')
135 ayin 1.29 pointcolour = sb->grayGC;
136 pcg 1.7 else if (a == '%' || a == 'd')
137 ayin 1.29 pointcolour = sb->darkGC;
138 pcg 1.7 else /* if (a == '#' || a == 'b' || a) */
139 ayin 1.29 pointcolour = sb->blackGC;
140 root 1.16
141 ayin 1.29 XDrawPoint (sb->term->dpy, d, pointcolour, x, y);
142 pcg 1.7 }
143 pcg 1.1 }
144 pcg 1.7 return d;
145 pcg 1.1 }
146    
147     void
148 ayin 1.29 scrollBar_t::init_next ()
149 pcg 1.1 {
150 pcg 1.7 XGCValues gcvalue;
151 sf-exg 1.34 rxvt_color color;
152 pcg 1.7 Pixmap stipple;
153     unsigned long light, dark;
154    
155     gcvalue.graphics_exposures = False;
156    
157 ayin 1.29 gcvalue.foreground = term->pix_colors_focused[Color_Black];
158     blackGC = XCreateGC (term->dpy, win,
159 root 1.21 GCForeground | GCGraphicsExposures, &gcvalue);
160 pcg 1.7
161 ayin 1.29 gcvalue.foreground = term->pix_colors_focused[Color_White];
162     whiteGC = XCreateGC (term->dpy, win,
163 root 1.21 GCForeground | GCGraphicsExposures, &gcvalue);
164 pcg 1.7
165 sf-exg 1.34 light = term->pix_colors_focused[Color_scroll];
166     #if 0
167     //color used by rxvt
168     if (color.set (term, rgba (0xaeba, 0xaaaa, 0xaeba)))
169     light = color;
170     #endif
171     gcvalue.foreground = light;
172 ayin 1.29 grayGC = XCreateGC (term->dpy, win,
173 root 1.21 GCForeground | GCGraphicsExposures, &gcvalue);
174 pcg 1.7
175 sf-exg 1.34 dark = term->pix_colors_focused[Color_Grey25];
176     #if 0
177     //color used by rxvt
178     if (color.set (term, rgba (0x51aa, 0x5555, 0x5144)))
179     dark = color;
180     #endif
181     gcvalue.foreground = dark;
182 ayin 1.29 darkGC = XCreateGC (term->dpy, win,
183 pcg 1.7 GCForeground | GCGraphicsExposures, &gcvalue);
184    
185 ayin 1.29 stipple = XCreateBitmapFromData (term->dpy, win,
186 root 1.21 (char *)n_stp_bits, n_stp_width,
187     n_stp_height);
188 pcg 1.7
189     gcvalue.foreground = dark;
190     gcvalue.background = light;
191     gcvalue.fill_style = FillOpaqueStippled;
192     gcvalue.stipple = stipple;
193    
194 ayin 1.29 stippleGC = XCreateGC (term->dpy, win,
195 root 1.21 GCForeground | GCBackground | GCStipple
196     | GCFillStyle | GCGraphicsExposures, &gcvalue);
197 pcg 1.7
198 ayin 1.29 dimple = renderPixmap (this, SCROLLER_DIMPLE, SCROLLER_DIMPLE_WIDTH,
199 pcg 1.7 SCROLLER_DIMPLE_HEIGHT);
200    
201 ayin 1.29 upArrow = renderPixmap (this, SCROLLER_ARROW_UP, ARROW_WIDTH,
202 pcg 1.7 ARROW_HEIGHT);
203 ayin 1.29 downArrow = renderPixmap (this, SCROLLER_ARROW_DOWN, ARROW_WIDTH,
204 pcg 1.7 ARROW_HEIGHT);
205 ayin 1.29 upArrowHi = renderPixmap (this, HI_SCROLLER_ARROW_UP, ARROW_WIDTH,
206 pcg 1.7 ARROW_HEIGHT);
207 ayin 1.29 downArrowHi = renderPixmap (this, HI_SCROLLER_ARROW_DOWN,
208 pcg 1.7 ARROW_WIDTH, ARROW_HEIGHT);
209 pcg 1.1 }
210    
211     /* Draw bevel & arrows */
212 ayin 1.29 static void
213     drawBevel (scrollBar_t *sb, int x1, int y1, int w, int h)
214 pcg 1.1 {
215 root 1.16 int x2, y2;
216 ayin 1.29 Drawable d = sb->win;
217     Display *dpy = sb->term->dpy;
218 pcg 1.1
219 pcg 1.7 x2 = x1 + w - 1; /* right point */
220     y2 = y1 + h - 1; /* bottom point */
221     /* white top and left */
222 ayin 1.29 XDrawLine (dpy, d, sb->whiteGC, x1, y1, x2, y1);
223     XDrawLine (dpy, d, sb->whiteGC, x1, y1, x1, y2);
224 pcg 1.7 /* black bottom and right */
225 ayin 1.29 XDrawLine (dpy, d, sb->blackGC, x1, y2, x2, y2);
226     XDrawLine (dpy, d, sb->blackGC, x2, y1, x2, y2);
227 pcg 1.7 /* dark inside bottom and right */
228     x1++, y1++, x2--, y2--; /* move in one point */
229 ayin 1.29 XDrawLine (dpy, d, sb->darkGC, x1, y2, x2, y2);
230     XDrawLine (dpy, d, sb->darkGC, x2, y1, x2, y2);
231 pcg 1.1 }
232    
233     int
234 ayin 1.29 scrollBar_t::show_next (int update)
235 pcg 1.1 {
236 ayin 1.29 int height = end + SB_BUTTON_TOTAL_HEIGHT + SB_PADDING;
237 ayin 1.28 Drawable src;
238 pcg 1.1
239 sf-exg 1.32 if ((init & SB_STYLE_NEXT) == 0)
240 pcg 1.7 {
241 sf-exg 1.32 init |= SB_STYLE_NEXT;
242 ayin 1.29 init_next ();
243 sf-exg 1.35 last_has_sb = false;
244 pcg 1.1 }
245    
246 sf-exg 1.35 bool has_sb = term->top_row;
247     int stipple_height = height - SB_PADDING;
248    
249     if (has_sb)
250     stipple_height -= SB_BUTTON_TOTAL_HEIGHT;
251     else
252     stipple_height -= SB_PADDING;
253    
254     if (has_sb != last_has_sb || !update)
255 pcg 1.7 {
256 sf-exg 1.35 last_has_sb = has_sb;
257 ayin 1.29 XFillRectangle (term->dpy, win, grayGC, 0, 0,
258 root 1.21 SB_WIDTH_NEXT + 1, height);
259 ayin 1.29 XDrawRectangle (term->dpy, win, blackGC, 0,
260 root 1.21 -SB_BORDER_WIDTH, SB_WIDTH_NEXT,
261     height + SB_BORDER_WIDTH);
262 ayin 1.29 XFillRectangle (term->dpy, win, stippleGC,
263 sf-exg 1.35 SB_LEFT_PADDING, SB_PADDING,
264     SB_BUTTON_WIDTH, stipple_height);
265 pcg 1.1 }
266 root 1.15
267 ayin 1.29 if (term->top_row)
268 pcg 1.7 {
269 ayin 1.29 if (last_top < top || !update)
270     XFillRectangle (term->dpy, win, stippleGC,
271 root 1.21 SB_LEFT_PADDING, SB_PADDING + last_top,
272 ayin 1.29 SB_BUTTON_WIDTH, top - last_top);
273 root 1.15
274 ayin 1.29 if (bot < last_bot || !update)
275     XFillRectangle (term->dpy, win, stippleGC,
276     SB_LEFT_PADDING, bot + SB_PADDING,
277     SB_BUTTON_WIDTH, (last_bot - bot));
278    
279     XFillRectangle (term->dpy, win, grayGC,
280     SB_LEFT_PADDING, top + SB_PADDING,
281 ayin 1.30 SB_BUTTON_WIDTH, bot - top);
282 root 1.21
283 ayin 1.29 XCopyArea (term->dpy, dimple, win, whiteGC, 0, 0,
284 root 1.21 SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT,
285     (SB_WIDTH_NEXT - SCROLLER_DIMPLE_WIDTH) / 2,
286 ayin 1.29 top + SB_BEVEL_WIDTH_UPPER_LEFT +
287 ayin 1.30 (bot - top - SCROLLER_DIMPLE_HEIGHT) / 2);
288 pcg 1.7
289 ayin 1.29 drawBevel (this, SB_BUTTON_BEVEL_X,
290     top + SB_PADDING, SB_BUTTON_WIDTH,
291 ayin 1.30 bot - top);
292 ayin 1.29 drawBevel (this, SB_BUTTON_BEVEL_X,
293 pcg 1.7 height - SB_BUTTON_BOTH_HEIGHT, SB_BUTTON_WIDTH,
294     SB_BUTTON_HEIGHT);
295 ayin 1.29 drawBevel (this, SB_BUTTON_BEVEL_X,
296 pcg 1.7 height - SB_BUTTON_SINGLE_HEIGHT, SB_BUTTON_WIDTH,
297     SB_BUTTON_HEIGHT);
298    
299 sf-exg 1.32 src = state == SB_STATE_UP ? upArrowHi : upArrow;
300 ayin 1.29 XCopyArea (term->dpy, src, win, whiteGC, 0, 0,
301 root 1.21 ARROW_WIDTH, ARROW_HEIGHT, SB_BUTTON_FACE_X,
302     height - SB_BUTTON_BOTH_HEIGHT + SB_BEVEL_WIDTH_UPPER_LEFT);
303 pcg 1.7
304 sf-exg 1.32 src = state == SB_STATE_DOWN ? downArrowHi : downArrow;
305 ayin 1.29 XCopyArea (term->dpy, src, win, whiteGC, 0, 0,
306 root 1.21 ARROW_WIDTH, ARROW_HEIGHT, SB_BUTTON_FACE_X,
307     height - SB_BUTTON_SINGLE_HEIGHT + SB_BEVEL_WIDTH_UPPER_LEFT);
308 pcg 1.1 }
309 root 1.15
310 pcg 1.7 return 1;
311 pcg 1.1 }
312 ayin 1.26 #endif /* NEXT_SCROLLBAR */
313 pcg 1.1 /*----------------------- end-of-file (C source) -----------------------*/