Example #1
0
File: arc.c Project: 4ad/sam
void
arc(Bitmap *b, Point p0, Point p1, Point p2, int v, Fcode f)
{
	unsigned int d;
	int x, y, r, start, end, delta;
	GC g;

	p1.x -= p0.x;
	p1.y -= p0.y;
	p2.x -= p0.x;
	p2.y -= p0.y;
	r = (int)sqrt((double)(p1.x*p1.x + p1.y*p1.y));
	start = (int)(64*rad2deg(atan2(-p2.y, p2.x)));
	end = (int)(64*rad2deg(atan2(-p1.y, p1.x)));
	if(start < 0)
		start += 64*360;
	if(end < 0)
		end += 64*360;
	delta = end - start;
	if(delta < 0)
		delta += 64*360;
	x = p0.x - r;
	y = p0.y - r;
	if(b->flag&SHIFT){
		x -= b->r.min.x;
		y -= b->r.min.y;
	}
	d = 2*r;
	g = _getfillgc(f, b, v);
	/*
	 * delta is positive, so this draws counterclockwise arc
	 * from start to start+delta
	 */
	XDrawArc(_dpy, (Drawable)b->id, g, x, y, d, d, start, delta);
}
Example #2
0
File: disc.c Project: 4ad/sam
void
disc(Bitmap *b, Point p, int r, int v, Fcode f)
{
	unsigned int d;
	int x, y;
	GC g;

	x = p.x - r;
	y = p.y - r;
	if (b->flag&SHIFT){
		x -= b->r.min.x;
		y -= b->r.min.y;
	}
	d = 2*r;
	g = _getfillgc(f, b, v);
	XFillArc(_dpy, (Drawable)b->id, g, x, y, d, d, 0, 23040/* 360 deg */);
}
Example #3
0
void
wrbitmap(Bitmap *b, int miny, int maxy, unsigned char *data)
{
    XImage *im;
    int w, h, inld, outld, l, offset, px;
    GC g;
    char *tdata;

    w = Dx(b->r);
    h = maxy - miny;
    inld = b->ldepth;
    outld = (b->ldepth == 0) ? 0 : screen.ldepth;
    px = 1<<(3-outld);  /* pixels per byte */
    /* set l to number of bytes of data per scan line */
    if(b->r.min.x >= 0)
        offset = b->r.min.x % px;
    else
        offset = px - b->r.min.x % px;
    l = (-b->r.min.x+px-1)/px;
    if(b->r.max.x >= 0)
        l += (b->r.max.x+px-1)/px;
    else
        l -= b->r.max.x/px;
    l *= h;

    tdata = (char *)malloc(l);
    if (tdata == (char *) 0)
            berror("wrbitmap malloc");
    if (inld == outld)
        memcpy((void*)tdata, (void*)data, l);
    else
        _ldconvert((char*)data, inld, tdata, outld, w, h);

    im = XCreateImage(_dpy, 0, 1 << outld, ZPixmap, 0, tdata, w, h, 8, 0);

    /* Botched interface to XCreateImage doesn't let you set these: */
    im->bitmap_bit_order = MSBFirst;
    im->byte_order = MSBFirst;

    g = _getfillgc(S, b, ~0);
    XSetBackground(_dpy, g, b->flag&DP1 ? 0 : _bgpixel);
    XPutImage(_dpy, (Drawable)b->id, g, im, offset, 0, 0, miny - b->r.min.y, w-offset, h);
    XDestroyImage(im);
}
Example #4
0
File: segment.c Project: 4ad/sam
void
segment(Bitmap *d, Point p1, Point p2, int v, Fcode f)
{
	int x1, y1, x2, y2;
	GC g;

	x1 = p1.x;
	y1 = p1.y;
	x2 = p2.x;
	y2 = p2.y;
	if(d->flag&SHIFT){
		x1 -= d->r.min.x;
		y1 -= d->r.min.y;
		x2 -= d->r.min.x;
		y2 -= d->r.min.y;
	}
	g = _getfillgc(f, d, v);
	XDrawLine(_dpy, (Drawable)d->id, g, x1, y1, x2, y2);
}