5d93de07b9a847470ec7a03d74badafafdab5841
[dana/urxvt.git] / src / scrollbar-rxvt.C
1 /*--------------------------------*-C-*---------------------------------*
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  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *----------------------------------------------------------------------*/
22
23 #include "../config.h"          /* NECESSARY */
24 #include "rxvt.h"               /* NECESSARY */
25 #include "scrollbar-rxvt.intpro"        /* PROTOS for internal routines */
26
27 /*----------------------------------------------------------------------*/
28 #if defined(RXVT_SCROLLBAR)
29
30 /* draw triangular button with a shadow of SHADOW (1 or 2) pixels */
31 void
32 rxvt_term::Draw_button (int x, int y, int state, int dirn)
33 {
34   unsigned int    sz, sz2;
35   XPoint          pt[3];
36   GC              top, bot;
37
38   sz = scrollBar.width;
39   sz2 = sz / 2;
40   switch (state)
41     {
42       case +1:
43         top = topShadowGC;
44         bot = botShadowGC;
45         break;
46       case -1:
47         top = botShadowGC;
48         bot = topShadowGC;
49         break;
50       default:
51         top = bot = scrollbarGC;
52         break;
53     }
54
55   /* fill triangle */
56   pt[0].x = x;
57   pt[1].x = x + sz - 1;
58   pt[2].x = x + sz2;
59   if (dirn == UP)
60     {
61       pt[0].y = pt[1].y = y + sz - 1;
62       pt[2].y = y;
63     }
64   else
65     {
66       pt[0].y = pt[1].y = y;
67       pt[2].y = y + sz - 1;
68     }
69   XFillPolygon(Xdisplay, scrollBar.win, scrollbarGC,
70                pt, 3, Convex, CoordModeOrigin);
71
72   /* draw base */
73   XDrawLine(Xdisplay, scrollBar.win, (dirn == UP ? bot : top),
74             pt[0].x, pt[0].y, pt[1].x, pt[1].y);
75
76   /* draw shadow on left */
77   pt[1].x = x + sz2 - 1;
78   pt[1].y = y + (dirn == UP ? 0 : sz - 1);
79   XDrawLine(Xdisplay, scrollBar.win, top,
80             pt[0].x, pt[0].y, pt[1].x, pt[1].y);
81
82 #if (SHADOW > 1)
83   /* doubled */
84   pt[0].x++;
85   if (dirn == UP)
86     {
87       pt[0].y--;
88       pt[1].y++;
89     }
90   else
91     {
92       pt[0].y++;
93       pt[1].y--;
94     }
95   XDrawLine(Xdisplay, scrollBar.win, top,
96             pt[0].x, pt[0].y, pt[1].x, pt[1].y);
97 #endif
98   /* draw shadow on right */
99   pt[1].x = x + sz - 1;
100   /*  pt[2].x = x + sz2; */
101   pt[1].y = y + (dirn == UP ? sz - 1 : 0);
102   pt[2].y = y + (dirn == UP ? 0 : sz - 1);
103   XDrawLine(Xdisplay, scrollBar.win, bot,
104             pt[2].x, pt[2].y, pt[1].x, pt[1].y);
105 #if (SHADOW > 1)
106   /* doubled */
107   pt[1].x--;
108   if (dirn == UP)
109     {
110       pt[2].y++;
111       pt[1].y--;
112     }
113   else
114     {
115       pt[2].y--;
116       pt[1].y++;
117     }
118   XDrawLine(Xdisplay, scrollBar.win, bot,
119             pt[2].x, pt[2].y, pt[1].x, pt[1].y);
120 #endif
121 }
122
123 int
124 rxvt_term::scrollbar_show_rxvt (int update __attribute__((unused)), int last_top, int last_bot, int scrollbar_len)
125 {
126   int             sbshadow = sb_shadow;
127   int             sbwidth = (int)scrollBar.width;
128
129   if ((scrollBar.init & R_SB_RXVT) == 0)
130     {
131       XGCValues       gcvalue;
132
133       scrollBar.init |= R_SB_RXVT;
134       gcvalue.foreground = PixColors[Color_trough];
135       if (sbshadow)
136         {
137           XSetWindowBackground(Xdisplay, scrollBar.win,
138                                gcvalue.foreground);
139           XClearWindow(Xdisplay, scrollBar.win);
140         }
141     }
142   else
143     {
144       /* instead of XClearWindow (Xdisplay, scrollBar.win); */
145       if (last_top < scrollBar.top)
146         XClearArea(Xdisplay, scrollBar.win,
147                    sbshadow, last_top,
148                    sbwidth, (scrollBar.top - last_top),
149                    False);
150
151       if (scrollBar.bot < last_bot)
152         XClearArea(Xdisplay, scrollBar.win,
153                    sbshadow, scrollBar.bot,
154                    sbwidth, (last_bot - scrollBar.bot),
155                    False);
156     }
157
158   /* scrollbar slider */
159 #ifdef SB_BORDER
160   {
161     int             xofs;
162
163     if (Options & Opt_scrollBar_right)
164       xofs = 0;
165     else
166       xofs = sbshadow ? sbwidth : sbwidth - 1;
167
168     XDrawLine(Xdisplay, scrollBar.win, botShadowGC,
169               xofs, 0, xofs, scrollBar.end + sbwidth);
170   }
171 #endif
172   XFillRectangle(Xdisplay, scrollBar.win, scrollbarGC,
173                  sbshadow, scrollBar.top, sbwidth,
174                  scrollbar_len);
175
176   if (sbshadow)
177     /* trough shadow */
178     rxvt_Draw_Shadow(Xdisplay, scrollBar.win,
179                      botShadowGC, topShadowGC,
180                      0, 0,
181                      sbwidth + 2 * sbshadow, /* scrollbar_TotalWidth() */
182                      scrollBar.end + (sbwidth + 1) + sbshadow);
183   /* shadow for scrollbar slider */
184   rxvt_Draw_Shadow(Xdisplay, scrollBar.win,
185                    topShadowGC, botShadowGC,
186                    sbshadow, scrollBar.top, sbwidth,
187                    scrollbar_len);
188
189   /*
190    * Redraw scrollbar arrows
191    */
192   Draw_button (sbshadow, sbshadow,
193                (scrollbar_isUp() ? -1 : +1), UP);
194   Draw_button (sbshadow, (scrollBar.end + 1),
195                (scrollbar_isDn() ? -1 : +1), DN);
196   return 1;
197 }
198 #endif                          /* RXVT_SCROLLBAR */
199 /*----------------------- end-of-file (C source) -----------------------*/