PageRenderTime 59ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/trunk/src/scrollbar-next.c

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