~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/xplt/src/play/x11/lines.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * lines.c -- $Id: lines.c,v 1.1 2003/03/08 15:26:51 travo Exp $
 
3
 * p_lines and p_disjoint for X11
 
4
 *
 
5
 * Copyright (c) 1998.  See accompanying LEGAL file for details.
 
6
 */
 
7
 
 
8
#include "config.h"
 
9
#include "playx.h"
 
10
 
 
11
void
 
12
p_dots(p_win *w)
 
13
{
 
14
  p_scr *s = w->s;
 
15
  Display *dpy = s->xdpy->dpy;
 
16
  GC gc = x_getgc(s, w, FillSolid);
 
17
  int nmx = XMaxRequestSize(dpy)-3;
 
18
  int n = x_pt_count;
 
19
  x_pt_count = 0;
 
20
  while (n>0) {
 
21
    if (n<nmx) nmx = n;
 
22
    XDrawPoints(dpy, w->d, gc, x_pt_list, nmx, CoordModeOrigin);
 
23
    n -= nmx;
 
24
  }
 
25
  if (p_signalling) p_abort();
 
26
}
 
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
 
 
45
void
 
46
p_segments(p_win *w)
 
47
{
 
48
  p_scr *s = w->s;
 
49
  Display *dpy = s->xdpy->dpy;
 
50
  GC gc = x_getgc(s, w, FillSolid);
 
51
  int nmx = (XMaxRequestSize(dpy)-3)/2;
 
52
  int n = x_pt_count / 2;
 
53
  x_pt_count = 0;
 
54
  while (n>0) {
 
55
    if (n<nmx) nmx = n;
 
56
    /* note: assume here that XPoint[2] identical to XSegment */
 
57
    XDrawSegments(dpy, w->d, gc, (XSegment *)x_pt_list, nmx);
 
58
    n -= nmx;
 
59
  }
 
60
  if (p_signalling) p_abort();
 
61
}
 
62
 
 
63
static char dashed[] = { 5, 5 };
 
64
static char dotted[] = { 1, 3 };
 
65
static char dashdot[] = { 5, 2, 1, 2 };
 
66
static char dashdotdot[] = { 5, 2, 1, 2, 1, 2 };
 
67
static char *x_dash[] = { 0, dashed, dotted, dashdot, dashdotdot };
 
68
static int x_ndash[] = { 0, 2, 2, 4, 6 };
 
69
 
 
70
void
 
71
p_pen(p_win *w, int width, int type)
 
72
{
 
73
  p_scr *s = w->s;
 
74
  GC gc = s->gc;
 
75
  int disjoint = (type & P_SQUARE);
 
76
  int same_type = (s->gc_type == type);
 
77
 
 
78
  if (width<2) width = 0;
 
79
  else if (width>100) width = 100;
 
80
 
 
81
  if (s->gc_width==width && same_type) return;
 
82
 
 
83
  type ^= disjoint;
 
84
  if (type>4 || type<0) type = 0;
 
85
  XSetLineAttributes(s->xdpy->dpy, gc, width,
 
86
                     type? LineOnOffDash : LineSolid,
 
87
                     disjoint? CapProjecting : CapRound,
 
88
                     disjoint? JoinMiter : JoinRound);
 
89
  if (!same_type) s->gc_type = (type | disjoint);
 
90
  s->gc_width = width;
 
91
 
 
92
  if (type) {
 
93
    /* dash pattern depends on linestyle */
 
94
    int n = x_ndash[type];
 
95
    if (width<2) {
 
96
      XSetDashes(s->xdpy->dpy, gc, 0, x_dash[type], n);
 
97
    } else {
 
98
      /* dash pattern must scale with line thickness */
 
99
      int i;
 
100
      char dash[6];
 
101
      for (i=0 ; i<n ; i++)
 
102
        dash[i] = x_dash[type][i]>1? width*x_dash[type][i] : 1;
 
103
      XSetDashes(s->xdpy->dpy, gc, 0, dash, n);
 
104
    }
 
105
  }
 
106
}