PageRenderTime 68ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/src/scrollbar-rxvt.c

https://gitlab.com/Jehan_ZeMarmot/mrxvt
C | 271 lines | 186 code | 34 blank | 51 comment | 25 complexity | f407fc50c9444a851f6c94a3cc21e593 MD5 | raw file
  1. /*--------------------------------*-C-*---------------------------------*
  2. * File: scrollbar-rxvt.c
  3. *----------------------------------------------------------------------*
  4. *
  5. * All portions of code are copyright by their respective author/s.
  6. * Copyright (c) 1997,1998 mj olesen <olesen@me.QueensU.CA>
  7. * Copyright (c) 1999-2001 Geoff Wing <gcw@pobox.com>
  8. * Copyright (c) 2004 Jingmin Zhou <jimmyzhou@users.sourceforge.net>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *----------------------------------------------------------------------*/
  24. #include "../config.h"
  25. #include "rxvt.h"
  26. /*----------------------------------------------------------------------*/
  27. #ifdef HAVE_SCROLLBARS
  28. #ifdef RXVT_SCROLLBAR
  29. #define CHOOSE_GC_FG(R, PIXCOL) \
  30. XSetForeground ((R)->Xdisplay, (R)->scrollBar.gc, (PIXCOL))
  31. /* draw triangular button with a shadow of SHADOW (1 or 2) pixels */
  32. /* INTPROTO */
  33. void
  34. rxvt_draw_button(rxvt_t *r, int x, int y, int state, int dirn)
  35. {
  36. unsigned int sz, sz2;
  37. XPoint pt[3];
  38. unsigned long top, bot;
  39. sz = r->scrollBar.width;
  40. sz2 = sz / 2;
  41. switch (state) {
  42. case +1:
  43. top = r->scrollBar.rxvt_topshadow;
  44. bot = r->scrollBar.rxvt_botshadow;
  45. break;
  46. case -1:
  47. top = r->scrollBar.rxvt_botshadow;
  48. bot = r->scrollBar.rxvt_topshadow;
  49. break;
  50. default:
  51. top = bot = r->scrollBar.rxvt_fg;
  52. break;
  53. }
  54. /* fill triangle */
  55. pt[0].x = x;
  56. pt[1].x = x + sz - 1;
  57. pt[2].x = x + sz2;
  58. if (dirn == UP) {
  59. pt[0].y = pt[1].y = y + sz - 1;
  60. pt[2].y = y;
  61. } else {
  62. pt[0].y = pt[1].y = y;
  63. pt[2].y = y + sz - 1;
  64. }
  65. CHOOSE_GC_FG (r, r->scrollBar.rxvt_fg);
  66. XFillPolygon(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  67. pt, 3, Convex, CoordModeOrigin);
  68. /* draw base */
  69. CHOOSE_GC_FG (r, (dirn == UP) ? bot : top);
  70. XDrawLine(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  71. pt[0].x, pt[0].y, pt[1].x, pt[1].y);
  72. /* draw shadow on left */
  73. pt[1].x = x + sz2 - 1;
  74. pt[1].y = y + (dirn == UP ? 0 : sz - 1);
  75. CHOOSE_GC_FG (r, top);
  76. XDrawLine(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  77. pt[0].x, pt[0].y, pt[1].x, pt[1].y);
  78. #if (SHADOW > 1)
  79. /* doubled */
  80. pt[0].x++;
  81. if (dirn == UP) {
  82. pt[0].y--;
  83. pt[1].y++;
  84. } else {
  85. pt[0].y++;
  86. pt[1].y--;
  87. }
  88. CHOOSE_GC_FG (r, top);
  89. XDrawLine(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  90. pt[0].x, pt[0].y, pt[1].x, pt[1].y);
  91. #endif
  92. /* draw shadow on right */
  93. pt[1].x = x + sz - 1;
  94. /* pt[2].x = x + sz2; */
  95. pt[1].y = y + (dirn == UP ? sz - 1 : 0);
  96. pt[2].y = y + (dirn == UP ? 0 : sz - 1);
  97. CHOOSE_GC_FG (r, bot);
  98. XDrawLine(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  99. pt[2].x, pt[2].y, pt[1].x, pt[1].y);
  100. #if (SHADOW > 1)
  101. /* doubled */
  102. pt[1].x--;
  103. if (dirn == UP) {
  104. pt[2].y++;
  105. pt[1].y--;
  106. } else {
  107. pt[2].y--;
  108. pt[1].y++;
  109. }
  110. CHOOSE_GC_FG (r, bot);
  111. XDrawLine(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  112. pt[2].x, pt[2].y, pt[1].x, pt[1].y);
  113. #endif
  114. }
  115. /* EXTPROTO */
  116. void
  117. rxvt_scrollbar_init_rxvt (rxvt_t* r)
  118. {
  119. XGCValues gcvalue;
  120. unsigned long gcmask;
  121. /* Initialize the colors */
  122. r->scrollBar.rxvt_fg = r->pixColorsFocus[Color_trough];
  123. r->scrollBar.rxvt_bg = r->pixColorsFocus[Color_bottomShadow];
  124. r->scrollBar.rxvt_topshadow = r->pixColorsFocus[Color_topShadow];
  125. r->scrollBar.rxvt_botshadow = r->pixColorsFocus[Color_bottomShadow];
  126. gcvalue.foreground = r->scrollBar.rxvt_fg;
  127. # ifdef TRANSPARENT
  128. /* set background color when there's no transparent */
  129. if (!(ISSET_OPTION(r, Opt_transparent) &&
  130. ISSET_OPTION(r, Opt_transparent_scrollbar)
  131. ))
  132. # endif
  133. # ifdef BACKGROUND_IMAGE
  134. /* set background color when there's no bg image */
  135. if (NOT_PIXMAP(r->scrollBar.pixmap))
  136. # endif
  137. gcvalue.background = r->scrollBar.rxvt_bg;
  138. gcmask = GCForeground;
  139. # ifdef TRANSPARENT
  140. /* set background color when there's no transparent */
  141. if (!(ISSET_OPTION(r, Opt_transparent) &&
  142. ISSET_OPTION(r, Opt_transparent_scrollbar)
  143. ))
  144. # endif
  145. # ifdef BACKGROUND_IMAGE
  146. /* set background color when there's no bg image */
  147. if (NOT_PIXMAP(r->scrollBar.pixmap))
  148. # endif
  149. gcmask |= GCBackground;
  150. r->scrollBar.gc = XCreateGC (r->Xdisplay, r->scrollBar.win,
  151. gcmask, &gcvalue);
  152. assert (IS_GC(r->scrollBar.gc));
  153. # ifdef TRANSPARENT
  154. /* set background color when there's no transparent */
  155. if (!(ISSET_OPTION(r, Opt_transparent) &&
  156. ISSET_OPTION(r, Opt_transparent_scrollbar)
  157. ))
  158. # endif
  159. # ifdef BACKGROUND_IMAGE
  160. /* set background color when there's no bg image */
  161. if (NOT_PIXMAP(r->scrollBar.pixmap))
  162. # endif
  163. XSetWindowBackground (r->Xdisplay, r->scrollBar.win,
  164. r->scrollBar.rxvt_bg);
  165. }
  166. /* EXTPROTO */
  167. void
  168. rxvt_scrollbar_exit_rxvt (rxvt_t* r)
  169. {
  170. /* No resources to free */
  171. }
  172. /* EXTPROTO */
  173. int
  174. rxvt_scrollbar_show_rxvt(rxvt_t *r, int update __attribute__((unused)), int last_top, int last_bot, int scroller_len)
  175. {
  176. int sbshadow = r->sb_shadow;
  177. int sbwidth = (int)r->scrollBar.width;
  178. if (last_top < r->scrollBar.top)
  179. XClearArea(r->Xdisplay, r->scrollBar.win,
  180. sbshadow, last_top,
  181. sbwidth, (r->scrollBar.top - last_top),
  182. False);
  183. if (r->scrollBar.bot < last_bot)
  184. XClearArea(r->Xdisplay, r->scrollBar.win,
  185. sbshadow, r->scrollBar.bot,
  186. sbwidth, (last_bot - r->scrollBar.bot),
  187. False);
  188. /* scrollbar slider */
  189. #ifdef TRANSPARENT
  190. /* clear background when there's transparent */
  191. if (ISSET_OPTION(r, Opt_transparent) &&
  192. ISSET_OPTION(r, Opt_transparent_scrollbar)
  193. )
  194. {
  195. XClearArea (r->Xdisplay, r->scrollBar.win,
  196. sbshadow, r->scrollBar.top, sbwidth, scroller_len,
  197. False);
  198. }
  199. else
  200. #endif
  201. # ifdef BACKGROUND_IMAGE
  202. /* clear background when there's bg image */
  203. if (IS_PIXMAP(r->scrollBar.pixmap))
  204. {
  205. XClearArea (r->Xdisplay, r->scrollBar.win,
  206. sbshadow, r->scrollBar.top, sbwidth, scroller_len,
  207. False);
  208. }
  209. else
  210. # endif
  211. {
  212. CHOOSE_GC_FG (r, r->scrollBar.rxvt_fg);
  213. XFillRectangle (r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  214. sbshadow, r->scrollBar.top, sbwidth, scroller_len);
  215. }
  216. if (sbshadow)
  217. /* trough shadow */
  218. rxvt_draw_shadow(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  219. r->scrollBar.rxvt_botshadow, r->scrollBar.rxvt_topshadow,
  220. 0, 0,
  221. sbwidth + 2 * sbshadow, /* scrollbar_TotalWidth() */
  222. r->scrollBar.end + (sbwidth + 1) + sbshadow);
  223. /* shadow for scrollbar slider */
  224. rxvt_draw_shadow(r->Xdisplay, r->scrollBar.win, r->scrollBar.gc,
  225. r->scrollBar.rxvt_topshadow, r->scrollBar.rxvt_botshadow,
  226. sbshadow, r->scrollBar.top, sbwidth,
  227. scroller_len);
  228. /* Redraw scrollbar arrows */
  229. rxvt_draw_button(r, sbshadow, sbshadow,
  230. (scrollbar_isUp() ? -1 : +1), UP);
  231. rxvt_draw_button(r, sbshadow, (r->scrollBar.end + 1),
  232. (scrollbar_isDn() ? -1 : +1), DN);
  233. return 1;
  234. }
  235. #endif /* RXVT_SCROLLBAR */
  236. #endif /* HAVE_SCROLLBARS */
  237. /*----------------------- end-of-file (C source) -----------------------*/