PageRenderTime 148ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/play/x11/lines.c

https://bitbucket.org/dpgrote/pygist
C | 109 lines | 87 code | 10 blank | 12 comment | 22 complexity | f5107e7cd2bfd5893a433c49abf89f8b MD5 | raw file
  1. /*
  2. * $Id: lines.c,v 1.1 2005-09-18 22:05:33 dhmunro Exp $
  3. * p_lines and p_disjoint for X11
  4. */
  5. /* Copyright (c) 2005, The Regents of the University of California.
  6. * All rights reserved.
  7. * This file is part of yorick (http://yorick.sourceforge.net).
  8. * Read the accompanying LICENSE file for details.
  9. */
  10. #include "config.h"
  11. #include "playx.h"
  12. void
  13. p_dots(p_win *w)
  14. {
  15. p_scr *s = w->s;
  16. Display *dpy = s->xdpy->dpy;
  17. GC gc = x_getgc(s, w, FillSolid);
  18. int nmx = XMaxRequestSize(dpy)-3;
  19. int n = x_pt_count;
  20. x_pt_count = 0;
  21. while (n>0) {
  22. if (n<nmx) nmx = n;
  23. XDrawPoints(dpy, w->d, gc, x_pt_list, nmx, CoordModeOrigin);
  24. n -= nmx;
  25. }
  26. if (p_signalling) p_abort();
  27. }
  28. void
  29. p_lines(p_win *w)
  30. {
  31. p_scr *s = w->s;
  32. Display *dpy = s->xdpy->dpy;
  33. GC gc = x_getgc(s, w, FillSolid);
  34. int nmx = XMaxRequestSize(dpy)-3;
  35. int n = x_pt_count;
  36. x_pt_count = 0;
  37. while (n>1) {
  38. if (n<nmx) nmx = n;
  39. XDrawLines(dpy, w->d, gc, x_pt_list, nmx, CoordModeOrigin);
  40. n -= nmx;
  41. }
  42. if (p_signalling) p_abort();
  43. }
  44. void
  45. p_segments(p_win *w)
  46. {
  47. p_scr *s = w->s;
  48. Display *dpy = s->xdpy->dpy;
  49. GC gc = x_getgc(s, w, FillSolid);
  50. int nmx = (XMaxRequestSize(dpy)-3)/2;
  51. int n = x_pt_count / 2;
  52. x_pt_count = 0;
  53. while (n>0) {
  54. if (n<nmx) nmx = n;
  55. /* note: assume here that XPoint[2] identical to XSegment */
  56. XDrawSegments(dpy, w->d, gc, (XSegment *)x_pt_list, nmx);
  57. n -= nmx;
  58. }
  59. if (p_signalling) p_abort();
  60. }
  61. static char dashed[] = { 5, 5 };
  62. static char dotted[] = { 1, 3 };
  63. static char dashdot[] = { 5, 2, 1, 2 };
  64. static char dashdotdot[] = { 5, 2, 1, 2, 1, 2 };
  65. static char *x_dash[] = { 0, dashed, dotted, dashdot, dashdotdot };
  66. static int x_ndash[] = { 0, 2, 2, 4, 6 };
  67. void
  68. p_pen(p_win *w, int width, int type)
  69. {
  70. p_scr *s = w->s;
  71. GC gc = s->gc;
  72. int disjoint = (type & P_SQUARE);
  73. int same_type = (s->gc_type == type);
  74. if (width<2) width = 0;
  75. else if (width>100) width = 100;
  76. if (s->gc_width==width && same_type) return;
  77. type ^= disjoint;
  78. if (type>4 || type<0) type = 0;
  79. XSetLineAttributes(s->xdpy->dpy, gc, width,
  80. type? LineOnOffDash : LineSolid,
  81. disjoint? CapProjecting : CapRound,
  82. disjoint? JoinMiter : JoinRound);
  83. if (!same_type) s->gc_type = (type | disjoint);
  84. s->gc_width = width;
  85. if (type) {
  86. /* dash pattern depends on linestyle */
  87. int n = x_ndash[type];
  88. if (width<2) {
  89. XSetDashes(s->xdpy->dpy, gc, 0, x_dash[type], n);
  90. } else {
  91. /* dash pattern must scale with line thickness */
  92. int i;
  93. char dash[6];
  94. for (i=0 ; i<n ; i++)
  95. dash[i] = x_dash[type][i]>1? width*x_dash[type][i] : 1;
  96. XSetDashes(s->xdpy->dpy, gc, 0, dash, n);
  97. }
  98. }
  99. }