ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/scrollbar-next.C
Revision: 1.5
Committed: Sat Jan 31 00:20:21 2004 UTC (20 years, 3 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.4: +63 -67 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 /*--------------------------------*-C-*---------------------------------*
2     * File: scrollbar-next.c
3     *----------------------------------------------------------------------*
4 pcg 1.5 * $Id: scrollbar-next.C,v 1.4 2003/12/18 02:07:12 pcg Exp $
5 pcg 1.1 *
6     * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
7     * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
8     * - N*XTstep like scrollbars
9     * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
10     *
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     * the Free Software Foundation; either version 2 of the License, or
14     * (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     #include "scrollbar-next.intpro" /* PROTOS for internal routines */
29    
30     /*----------------------------------------------------------------------*/
31     #if defined(NEXT_SCROLLBAR)
32    
33     #define n_stp_width 8
34     #define n_stp_height 2
35     const unsigned char n_stp_bits[] = { 0x55, 0xaa };
36    
37     /*
38     * N*XTSTEP like scrollbar - written by Alfredo K. Kojima
39     */
40     #define SCROLLER_DIMPLE_WIDTH 6
41     #define SCROLLER_DIMPLE_HEIGHT 6
42     #define ARROW_WIDTH 13
43     #define ARROW_HEIGHT 13
44    
45     const char *const SCROLLER_DIMPLE[] = {
46     ".%###.",
47     "%#%%%%",
48     "#%%...",
49     "#%.. ",
50     "#%. ",
51     ".%. ."
52     };
53     const char *const SCROLLER_ARROW_UP[] = {
54     ".............",
55     ".............",
56     "......%......",
57     "......#......",
58     ".....%#%.....",
59     ".....###.....",
60     "....%###%....",
61     "....#####....",
62     "...%#####%...",
63     "...#######...",
64     "..%#######%..",
65     ".............",
66     "............."
67     };
68     const char *const SCROLLER_ARROW_DOWN[] = {
69     ".............",
70     ".............",
71     "..%#######%..",
72     "...#######...",
73     "...%#####%...",
74     "....#####....",
75     "....%###%....",
76     ".....###.....",
77     ".....%#%.....",
78     "......#......",
79     "......%......",
80     ".............",
81     "............."
82     };
83     const char *const HI_SCROLLER_ARROW_UP[] = {
84     " ",
85     " ",
86     " % ",
87     " % ",
88     " %%% ",
89     " %%% ",
90     " %%%%% ",
91     " %%%%% ",
92     " %%%%%%% ",
93     " %%%%%%% ",
94     " %%%%%%%%% ",
95     " ",
96     " "
97     };
98     const char *const HI_SCROLLER_ARROW_DOWN[] = {
99     " ",
100     " ",
101     " %%%%%%%%% ",
102     " %%%%%%% ",
103     " %%%%%%% ",
104     " %%%%% ",
105     " %%%%% ",
106     " %%% ",
107     " %%% ",
108     " % ",
109     " % ",
110     " ",
111     " "
112     };
113    
114     Pixmap
115 pcg 1.5 rxvt_term::renderPixmap (const char *const *data, int width, int height)
116 pcg 1.1 {
117     char a;
118     int x, y;
119     Pixmap d;
120     GC pointcolour;
121    
122 pcg 1.5 d = XCreatePixmap(Xdisplay, scrollBar.win, width, height, XDEPTH);
123 pcg 1.1
124     for (y = 0; y < height; y++) {
125     for (x = 0; x < width; x++) {
126     if ((a = data[y][x]) == ' ' || a == 'w')
127 pcg 1.5 pointcolour = whiteGC;
128 pcg 1.1 else if (a == '.' || a == 'l')
129 pcg 1.5 pointcolour = grayGC;
130 pcg 1.1 else if (a == '%' || a == 'd')
131 pcg 1.5 pointcolour = darkGC;
132 pcg 1.1 else /* if (a == '#' || a == 'b' || a) */
133 pcg 1.5 pointcolour = blackGC;
134     XDrawPoint(Xdisplay, d, pointcolour, x, y);
135 pcg 1.1 }
136     }
137     return d;
138     }
139    
140     void
141 pcg 1.5 rxvt_term::init_scrollbar_stuff ()
142 pcg 1.1 {
143     XGCValues gcvalue;
144     XColor xcol;
145     Pixmap stipple;
146     unsigned long light, dark;
147    
148     gcvalue.graphics_exposures = False;
149    
150 pcg 1.5 gcvalue.foreground = PixColors[Color_Black];
151     blackGC = XCreateGC(Xdisplay, scrollBar.win,
152 pcg 1.1 GCForeground | GCGraphicsExposures, &gcvalue);
153    
154 pcg 1.5 gcvalue.foreground = PixColors[Color_White];
155     whiteGC = XCreateGC(Xdisplay, scrollBar.win,
156 pcg 1.1 GCForeground | GCGraphicsExposures, &gcvalue);
157    
158     xcol.red = 0xaeba;
159     xcol.green = 0xaaaa;
160     xcol.blue = 0xaeba;
161 pcg 1.5 //if (!rXAllocColor (&xcol, "light gray"))//TODO//D//
162     xcol.pixel = PixColors[Color_AntiqueWhite];
163 pcg 1.1 light = gcvalue.foreground = xcol.pixel;
164 pcg 1.5 grayGC = XCreateGC(Xdisplay, scrollBar.win,
165 pcg 1.1 GCForeground | GCGraphicsExposures, &gcvalue);
166    
167     xcol.red = 0x51aa;
168     xcol.green = 0x5555;
169     xcol.blue = 0x5144;
170 pcg 1.5 //if (!rXAllocColor (&xcol, "dark gray"))//TODO//D//
171     xcol.pixel = PixColors[Color_Grey25];
172 pcg 1.1 dark = gcvalue.foreground = xcol.pixel;
173 pcg 1.5 darkGC = XCreateGC(Xdisplay, scrollBar.win,
174 pcg 1.1 GCForeground | GCGraphicsExposures, &gcvalue);
175    
176 pcg 1.5 stipple = XCreateBitmapFromData(Xdisplay, scrollBar.win,
177 pcg 1.1 (char *)n_stp_bits, n_stp_width,
178     n_stp_height);
179    
180     gcvalue.foreground = dark;
181     gcvalue.background = light;
182     gcvalue.fill_style = FillOpaqueStippled;
183     gcvalue.stipple = stipple;
184    
185 pcg 1.5 /* XSetWindowBackground(Xdisplay, scrollBar.win, PixColors[Color_Red]); */
186 pcg 1.1
187 pcg 1.5 stippleGC = XCreateGC(Xdisplay, scrollBar.win,
188 pcg 1.1 GCForeground | GCBackground | GCStipple
189     | GCFillStyle | GCGraphicsExposures, &gcvalue);
190    
191 pcg 1.5 dimple = renderPixmap (SCROLLER_DIMPLE, SCROLLER_DIMPLE_WIDTH,
192 pcg 1.1 SCROLLER_DIMPLE_HEIGHT);
193    
194 pcg 1.5 upArrow = renderPixmap (SCROLLER_ARROW_UP, ARROW_WIDTH,
195 pcg 1.1 ARROW_HEIGHT);
196 pcg 1.5 downArrow = renderPixmap (SCROLLER_ARROW_DOWN, ARROW_WIDTH,
197 pcg 1.1 ARROW_HEIGHT);
198 pcg 1.5 upArrowHi = renderPixmap (HI_SCROLLER_ARROW_UP, ARROW_WIDTH,
199 pcg 1.1 ARROW_HEIGHT);
200 pcg 1.5 downArrowHi = renderPixmap (HI_SCROLLER_ARROW_DOWN,
201 pcg 1.1 ARROW_WIDTH, ARROW_HEIGHT);
202     }
203    
204     /* Draw bevel & arrows */
205     void
206 pcg 1.5 rxvt_term::drawBevel (Drawable d, int x1, int y1, int w, int h)
207 pcg 1.1 {
208     int x2, y2;
209    
210     x2 = x1 + w - 1; /* right point */
211     y2 = y1 + h - 1; /* bottom point */
212     /* white top and left */
213 pcg 1.5 XDrawLine(Xdisplay, d, whiteGC, x1, y1, x2, y1);
214     XDrawLine(Xdisplay, d, whiteGC, x1, y1, x1, y2);
215 pcg 1.1 /* black bottom and right */
216 pcg 1.5 XDrawLine(Xdisplay, d, blackGC, x1, y2, x2, y2);
217     XDrawLine(Xdisplay, d, blackGC, x2, y1, x2, y2);
218 pcg 1.1 /* dark inside bottom and right */
219     x1++, y1++, x2--, y2--; /* move in one point */
220 pcg 1.5 XDrawLine(Xdisplay, d, darkGC, x1, y2, x2, y2);
221     XDrawLine(Xdisplay, d, darkGC, x2, y1, x2, y2);
222 pcg 1.1 }
223    
224     int
225 pcg 1.5 rxvt_term::scrollbar_show_next (int update, int last_top, int last_bot, int scrollbar_len)
226 pcg 1.1 {
227 pcg 1.5 int height = scrollBar.end + SB_BUTTON_TOTAL_HEIGHT + SB_PADDING;
228 pcg 1.1 Drawable s;
229    
230 pcg 1.5 if ((scrollBar.init & R_SB_NEXT) == 0) {
231     scrollBar.init |= R_SB_NEXT;
232     init_scrollbar_stuff ();
233 pcg 1.1 }
234    
235 pcg 1.5 if (TermWin.nscrolled == 0 || !update) {
236     XFillRectangle(Xdisplay, scrollBar.win, grayGC, 0, 0,
237 pcg 1.1 SB_WIDTH_NEXT + 1, height);
238 pcg 1.5 XDrawRectangle(Xdisplay, scrollBar.win, blackGC, 0,
239 pcg 1.1 -SB_BORDER_WIDTH, SB_WIDTH_NEXT,
240     height + SB_BORDER_WIDTH);
241 pcg 1.5 XFillRectangle(Xdisplay, scrollBar.win, stippleGC,
242 pcg 1.1 SB_LEFT_PADDING, 0, SB_BUTTON_WIDTH, height);
243     }
244 pcg 1.5 if (TermWin.nscrolled) {
245     if (last_top < scrollBar.top || !update)
246     XFillRectangle(Xdisplay, scrollBar.win, stippleGC,
247 pcg 1.1 SB_LEFT_PADDING, SB_PADDING + last_top,
248 pcg 1.5 SB_BUTTON_WIDTH, scrollBar.top - last_top);
249     if (scrollBar.bot < last_bot || !update)
250     XFillRectangle(Xdisplay, scrollBar.win, stippleGC,
251     SB_LEFT_PADDING, scrollBar.bot + SB_PADDING,
252     SB_BUTTON_WIDTH, (last_bot - scrollBar.bot));
253     XFillRectangle(Xdisplay, scrollBar.win, grayGC,
254     SB_LEFT_PADDING, scrollBar.top + SB_PADDING,
255 pcg 1.1 SB_BUTTON_WIDTH, scrollbar_len);
256 pcg 1.5 XCopyArea(Xdisplay, dimple, scrollBar.win, whiteGC, 0, 0,
257 pcg 1.1 SCROLLER_DIMPLE_WIDTH, SCROLLER_DIMPLE_HEIGHT,
258     (SB_WIDTH_NEXT - SCROLLER_DIMPLE_WIDTH) / 2,
259 pcg 1.5 scrollBar.top + SB_BEVEL_WIDTH_UPPER_LEFT +
260 pcg 1.1 (scrollbar_len - SCROLLER_DIMPLE_HEIGHT) / 2);
261    
262 pcg 1.5 drawBevel (scrollBar.win, SB_BUTTON_BEVEL_X,
263     scrollBar.top + SB_PADDING, SB_BUTTON_WIDTH,
264 pcg 1.1 scrollbar_len);
265 pcg 1.5 drawBevel (scrollBar.win, SB_BUTTON_BEVEL_X,
266 pcg 1.1 height - SB_BUTTON_BOTH_HEIGHT, SB_BUTTON_WIDTH,
267     SB_BUTTON_HEIGHT);
268 pcg 1.5 drawBevel (scrollBar.win, SB_BUTTON_BEVEL_X,
269 pcg 1.1 height - SB_BUTTON_SINGLE_HEIGHT, SB_BUTTON_WIDTH,
270     SB_BUTTON_HEIGHT);
271    
272 pcg 1.5 s = (scrollbar_isUp()) ? upArrowHi : upArrow;
273     XCopyArea(Xdisplay, s, scrollBar.win, whiteGC, 0, 0,
274 pcg 1.1 ARROW_WIDTH, ARROW_HEIGHT, SB_BUTTON_FACE_X,
275     height - SB_BUTTON_BOTH_HEIGHT + SB_BEVEL_WIDTH_UPPER_LEFT);
276    
277 pcg 1.5 s = (scrollbar_isDn()) ? downArrowHi : downArrow;
278     XCopyArea(Xdisplay, s, scrollBar.win, whiteGC, 0, 0,
279 pcg 1.1 ARROW_WIDTH, ARROW_HEIGHT, SB_BUTTON_FACE_X,
280     height - SB_BUTTON_SINGLE_HEIGHT + SB_BEVEL_WIDTH_UPPER_LEFT);
281     }
282     return 1;
283     }
284     #endif /* NEXT_SCROLLBAR */
285     /*----------------------- end-of-file (C source) -----------------------*/