示例#1
0
int GCarrow(Gwidget_t * widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t * ap)
{

    PIXpoint_t pp1, pp2, pa, pb, pd;
    Grect_t gr;
    double tangent, l;

    if (gp1.x < gp2.x)
	gr.o.x = gp1.x, gr.c.x = gp2.x;
    else
	gr.o.x = gp2.x, gr.c.x = gp1.x;
    if (gp1.y < gp2.y)
	gr.o.y = gp1.y, gr.c.y = gp2.y;
    else
	gr.o.y = gp2.y, gr.c.y = gp1.y;

    pp1 = pdrawtopix(widget, gp1), pp2 = pdrawtopix(widget, gp2);
    pd.x = pp1.x - pp2.x, pd.y = pp1.y - pp2.y;
    if (pd.x == 0 && pd.y == 0)
	return 0;
    tangent = atan2((double) pd.y, (double) pd.x);
    if ((l = sqrt((double) (pd.x * pd.x + pd.y * pd.y))) > 30)
	l = 30;
    pa.x = l * cos(tangent + M_PI / 7) + pp2.x;
    pa.y = l * sin(tangent + M_PI / 7) + pp2.y;
    pb.x = l * cos(tangent - M_PI / 7) + pp2.x;
    pb.y = l * sin(tangent - M_PI / 7) + pp2.y;
    setgattr(widget, ap);

    gdk_draw_line(widget->w->window, GC, pp1.x, pp1.y, pp2.x, pp2.y);
    gdk_draw_line(widget->w->window, GC, pa.x, pa.y, pp2.x, pp2.y);
    gdk_draw_line(widget->w->window, GC, pb.x, pb.y, pp2.x, pp2.y);
    return 0;
}
示例#2
0
int GPsplinegon (Gwidget_t *widget, int gpn, Gpoint_t *gpp, Ggattr_t *ap) {
    PIXpoint_t p0, p1, p2, p3;
    int n, i;

    if (gpn == 0)
        return 0;
    Gppi = 1;
    if (Gppi >= Gppn) {
        n = (((Gppi + 1) + PPINCR - 1) / PPINCR) * PPINCR;
        Gppp = Marraygrow (Gppp, (long) n * PPSIZE);
        Gppn = n;
    }
    Gppp[0] = p3 = pdrawtopix (widget, gpp[0]);
    for (i = 1; i < gpn; i += 3) {
        p0 = p3;
        p1 = pdrawtopix (widget, gpp[i]);
        p2 = pdrawtopix (widget, gpp[i + 1]);
        p3 = pdrawtopix (widget, gpp[i + 2]);
        bezier (p0, p1, p2, p3);
    }
    setgattr (widget, ap);
    if (WPU->gattr.fill) {
        if (Gppp[Gppi - 1].x != Gppp[0].x || Gppp[Gppi - 1].y != Gppp[0].y)
            Gppp[Gppi] = Gppp[0], Gppi++;
        Polygon (GC, Gppp, (int) Gppi);
    } else
        Polyline (GC, Gppp, (int) Gppi);
    return 0;
}
示例#3
0
int GPline (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) {
    PIXpoint_t pp1, pp2;

    pp1 = pdrawtopix (widget, gp1), pp2 = pdrawtopix (widget, gp2);
    setgattr (widget, ap);
    MoveToEx (GC, pp1.x, pp1.y, NULL);
    LineTo (GC, pp2.x, pp2.y);
    return 0;
}
示例#4
0
int GCarc(Gwidget_t * widget, Gpoint_t gc, Gsize_t gs, double ang1,
	  double ang2, Ggattr_t * ap)
{

    PIXpoint_t pc;
    PIXsize_t ps;
    Grect_t gr;

    gr.o.x = gc.x - gs.x, gr.o.y = gc.y - gs.y;
    gr.c.x = gc.x + gs.x, gr.c.y = gc.y + gs.y;
/*	if(!ISVISIBLE(gr))
		return 1;
*/

    pc = pdrawtopix(widget, gc), ps = sdrawtopix(widget, gs);
    setgattr(widget, ap);

    if (WCU->gattr.fill) {
	gdk_draw_arc(widget->w->window, GC, TRUE, pc.x - ps.x, pc.y - ps.y,
		     ps.x * 2, ps.y * 2, (int) (ang1 * 64), (ang2 * 64));
    } else {
	gdk_draw_arc(widget->w->window, GC, FALSE, pc.x - ps.x,
		     pc.y - ps.y, ps.x * 2, ps.y * 2, (int) (ang1 * 64),
		     (ang2 * 64));
    }
    return 0;
}
示例#5
0
int GParc (
    Gwidget_t *widget, Gpoint_t gc, Gsize_t gs,
    double ang1, double ang2, Ggattr_t *ap
) {
    PIXpoint_t pc;
    PIXsize_t ps;
    double a1, a2;

    pc = pdrawtopix (widget, gc), ps = sdrawtopix (widget, gs);
    setgattr (widget, ap);
    a1 = ang1 * M_PI / 180, a2 = ang2 * M_PI / 180;
    if (WPU->gattr.fill)
        Chord (
            GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y,
            (int) (cos (a1) * ps.x), (int) (sin (a1) * ps.x),
            (int) (cos (a2) * ps.x), (int) (sin (a2) * ps.x)
        );
    else
        Arc (
            GC, pc.x - ps.x, pc.y - ps.y, pc.x + ps.x, pc.y + ps.y,
            (int) (cos (a1) * ps.x), (int) (sin (a1) * ps.x),
            (int) (cos (a2) * ps.x), (int) (sin (a2) * ps.x)
        );
    return 0;
}
示例#6
0
int GPtext (
    Gwidget_t *widget, Gtextline_t *tlp, int n, Gpoint_t go, char *fn,
    double fs, char *justs, Ggattr_t *ap
) {
    Gsize_t gs;
    PIXpoint_t po;
    PIXsize_t ps;
    PIXrect_t pr;
    HFONT font;
    SIZE size;
    RECT r;
    int x, y, w, h, i;

    po = pdrawtopix (widget, go);
    gs.x = 0, gs.y = fs;
    ps = sdrawtopix (widget, gs);
    if (!(font = findfont (fn, ps.y))) {
        Rectangle (GC, po.x, po.y, po.x + 1, po.y + 1);
        return 0;
    }
    setgattr (widget, ap);
    if (font != WPU->font) {
        WPU->font = font;
        SelectObject (GC, font);
    }
    for (w = h = 0, i = 0; i < n; i++) {
        if (tlp[i].n)
            GetTextExtentPoint32 (GC, tlp[i].p, (int) tlp[i].n, &size);
        else
            GetTextExtentPoint32 (GC, "M", (int) 1, &size);
        tlp[i].w = size.cx, tlp[i].h = size.cy;
        w = max (w, size.cx), h += size.cy;
    }
    switch (justs[0]) {
    case 'l': po.x += w / 2; break;
    case 'r': po.x -= w / 2; break;
    }
    switch (justs[1]) {
    case 'd': po.y -= h; break;
    case 'c': po.y -= h / 2; break;
    }
    pr.o.x = po.x - w / 2, pr.o.y = po.y;
    pr.c.x = po.x + w / 2, pr.c.y = po.y + h;
    for (i = 0; i < n; i++) {
        switch (tlp[i].j) {
        case 'l': x = po.x - w / 2; break;
        case 'n': x = po.x - tlp[i].w / 2; break;
        case 'r': x = po.x - (tlp[i].w - w / 2); break;
        }
        y = po.y + i * tlp[i].h;
        r.left = x, r.top = y;
        r.right = x + tlp[i].w, r.bottom = y + tlp[i].h;
        DrawText (
            GC, tlp[i].p, (int) tlp[i].n, &r, DT_LEFT | DT_TOP | DT_NOPREFIX
        );
    }
    return 0;
}
示例#7
0
int GParrow (Gwidget_t *widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t *ap) {
    PIXpoint_t pp1, pp2, pa, pb, pd;
    double tangent, l;

    pp1 = pdrawtopix (widget, gp1), pp2 = pdrawtopix (widget, gp2);
    pd.x = pp1.x - pp2.x, pd.y = pp1.y - pp2.y;
    if (pd.x == 0 && pd.y == 0)
        return 0;
    tangent = atan2 ((double) pd.y, (double) pd.x);
    if ((l = sqrt ((double) (pd.x * pd.x + pd.y * pd.y))) > 30)
        l = 30;
    pa.x = l * cos (tangent + M_PI / 7) + pp2.x;
    pa.y = l * sin (tangent + M_PI / 7) + pp2.y;
    pb.x = l * cos (tangent - M_PI / 7) + pp2.x;
    pb.y = l * sin (tangent - M_PI / 7) + pp2.y;
    setgattr (widget, ap);
    MoveToEx (GC, pp1.x, pp1.y, NULL), LineTo (GC, pp2.x, pp2.y);
    MoveToEx (GC, pa.x, pa.y, NULL), LineTo (GC, pp2.x, pp2.y);
    MoveToEx (GC, pb.x, pb.y, NULL), LineTo (GC, pp2.x, pp2.y);
    return 0;
}
示例#8
0
int GCline(Gwidget_t * widget, Gpoint_t gp1, Gpoint_t gp2, Ggattr_t * ap)
{
    PIXpoint_t pp1, pp2;
    Grect_t gr;

    if (gp1.x < gp2.x)
	gr.o.x = gp1.x, gr.c.x = gp2.x;
    else
	gr.o.x = gp2.x, gr.c.x = gp1.x;
    if (gp1.y < gp2.y)
	gr.o.y = gp1.y, gr.c.y = gp2.y;
    else
	gr.o.y = gp2.y, gr.c.y = gp1.y;

/*	if(!ISVISIBLE(gr))
		return 1;
*/

    pp1 = pdrawtopix(widget, gp1), pp2 = pdrawtopix(widget, gp2);
    setgattr(widget, ap);
    gdk_draw_line(widget->w->window, GC, pp1.x, pp1.y, pp2.x, pp2.y);
    return 0;
}
示例#9
0
int GCsplinegon(Gwidget_t * widget, int gpn, Gpoint_t * gpp, Ggattr_t * ap)
{

    PIXpoint_t p0, p1, p2, p3;
    Grect_t gr;
    int n, i;

    if (gpn == 0)
	return 0;

    gr.o = gpp[0], gr.c = gpp[0];
    for (i = 1; i < gpn; i++) {
	gr.o.x = min(gr.o.x, gpp[i].x);
	gr.o.y = min(gr.o.y, gpp[i].y);
	gr.c.x = max(gr.c.x, gpp[i].x);
	gr.c.y = max(gr.c.y, gpp[i].y);
    }

    Gppi = 1;
    if (Gppi >= Gppn) {
	n = (((Gppi + 1) + PPINCR - 1) / PPINCR) * PPINCR;
	Gppp = Marraygrow(Gppp, (long) n * PPSIZE);
	Gppn = n;
    }
    Gppp[0] = p3 = pdrawtopix(widget, gpp[0]);
    for (i = 1; i < gpn; i += 3) {
	p0 = p3;
	p1 = pdrawtopix(widget, gpp[i]);
	p2 = pdrawtopix(widget, gpp[i + 1]);
	p3 = pdrawtopix(widget, gpp[i + 2]);
	bezier(p0, p1, p2, p3);
    }
    setgattr(widget, ap);
    gdk_draw_lines(widget->w->window, GC, Gppp, Gppi);
    return 0;
}
示例#10
0
int GPpolygon (Gwidget_t *widget, int gpn, Gpoint_t *gpp, Ggattr_t *ap) {
    int n, i;

    if (gpn == 0)
        return 0;
    if (gpn + 1 > Gppn) {
        n = (((gpn + 1) + PPINCR - 1) / PPINCR) * PPINCR;
        Gppp = Marraygrow (Gppp, (long) n * PPSIZE);
        Gppn = n;
    }
    for (i = 0; i < gpn; i++)
        Gppp[i] = pdrawtopix (widget, gpp[i]);
    setgattr (widget, ap);
    if (WPU->gattr.fill) {
        if (Gppp[gpn - 1].x != Gppp[0].x || Gppp[gpn - 1].y != Gppp[0].y)
            Gppp[gpn] = Gppp[0], gpn++;
        Polygon (GC, Gppp, (int) gpn);
    } else
        Polyline (GC, Gppp, (int) gpn);
    return 0;
}
示例#11
0
int GCpolygon(Gwidget_t * widget, int gpn, Gpoint_t * gpp, Ggattr_t * ap)
{

    Grect_t gr;
    int n, i;

    if (gpn == 0)
	return 0;

    gr.o = gpp[0], gr.c = gpp[0];
    for (i = 1; i < gpn; i++) {
	gr.o.x = min(gr.o.x, gpp[i].x);
	gr.o.y = min(gr.o.y, gpp[i].y);
	gr.c.x = min(gr.c.x, gpp[i].x);
	gr.c.y = min(gr.c.y, gpp[i].y);
    }
/*	if(!ISVISIBLE(gr))
		return 1;
*/
    if (gpn + 1 > Gppn) {
	n = (((gpn + 1) + PPINCR - 1) / PPINCR) * PPINCR;
	Gppp = Marraygrow(Gppp, (long) n * PPSIZE);
	Gppn = n;
    }
    for (i = 0; i < gpn; i++)
	Gppp[i] = pdrawtopix(widget, gpp[i]);

    setgattr(widget, ap);
    if (WCU->gattr.fill) {
	if (Gppp[gpn - 1].x != Gppp[0].x || Gppp[gpn - 1].y != Gppp[0].y)
	    Gppp[gpn] = Gppp[0], gpn++;

	gdk_draw_polygon(widget->w, GC, TRUE, Gppp, gpn);
    } else
	gdk_draw_polygon(widget->w, GC, FALSE, Gppp, gpn);

    return 0;
}
示例#12
0
int GCtext(Gwidget_t * widget, Gtextline_t * tlp, int n, Gpoint_t go,
	   char *fn, double fs, char *justs, Ggattr_t * ap)
{

    Gsize_t gs;
    PIXpoint_t po;
    PIXsize_t ps;
    PIXrect_t pr;
    Grect_t gr;
    GdkFont *font;
    int dir, asc, des, x = 0, y, w, h, i;
    int lbearing, rbearing, width;

    po = pdrawtopix(widget, go);
    gs.x = 0, gs.y = fs;
    ps = sdrawtopix(widget, gs);
    if (!(font = findfont(fn, ps.y))) {
	printf("NO FONT\n");
	gdk_draw_rectangle(widget->w, GC, FALSE, po.x, po.y, 1, 1);
	return 0;
    }

    setgattr(widget, ap);
    SETFONT(font);

    for (w = h = 0, i = 0; i < n; i++) {
	gdk_text_extents(font, tlp[i].p, tlp[i].n, &lbearing, &rbearing,
			 &width, &asc, &des);

	tlp[i].w = width, tlp[i].h = asc + des;
	w = max(w, width), h += asc + des;

    }

    switch (justs[0]) {
    case 'l':
	po.x += w / 2;
	break;
    case 'r':
	po.x -= w / 2;
	break;
    }
    switch (justs[1]) {
    case 'd':
	po.y -= h;
	break;
    case 'c':
	po.y -= h / 2;
	break;
    }
    pr.o.x = po.x - w / 2, pr.o.y = po.y;
    pr.c.x = po.x + w / 2, pr.c.y = po.y + h;
    gr = rpixtodraw(widget, pr);

/*	if(!ISVISIBLE(gr))
		return 1;
*/

    for (i = 0; i < n; i++) {
	switch (tlp[i].j) {
	case 'l':
	    x = po.x - w / 2;
	    break;
	case 'n':
	    x = po.x - tlp[i].w / 2;
	    break;
	case 'r':
	    x = po.x - (tlp[i].w - w / 2);
	    break;
	}
	y = po.y + (i + 1) * tlp[i].h - des;

	gdk_draw_text(widget->w->window, font, GC, x, y, tlp[i].p,
		      tlp[i].n);
    }

    return 0;
}
示例#13
0
int GPbitblt (
    Gwidget_t *widget, Gpoint_t gp, Grect_t gr, Gbitmap_t *bitmap,
    char *mode, Ggattr_t *ap
) {
    PIXrect_t pr, r;
    PIXpoint_t pp;
    PIXsize_t s;
    Gsize_t scale;
    Gxy_t p;
    HBITMAP pix;
    HDC gc;
    double tvx, tvy, twx, twy;

    if (gr.o.x > gr.c.x)
        p.x = gr.o.x, gr.o.x = gr.c.x, gr.c.x = p.x;
    if (gr.o.y > gr.c.y)
        p.y = gr.o.y, gr.o.y = gr.c.y, gr.c.y = p.y;
    if (strcmp (mode, "b2c") == 0) {
        tvx = WPU->vsize.x, tvy = WPU->vsize.y;
        twx = WPU->wrect.c.x - WPU->wrect.o.x;
        twy = WPU->wrect.c.y - WPU->wrect.o.y;
        scale.x = tvx / twx, scale.y = tvy / twy;
        if (scale.x == 1 && scale.y == 1) {
            pix = bitmap->u.bmap.orig;
            bitmap->scale = scale;
        } else {
            if (scale.x != bitmap->scale.x || scale.y != bitmap->scale.y)
                scalebitmap (widget, bitmap, scale, TRUE, 1);
            pix = bitmap->u.bmap.scaled;
        }
        pr = rdrawtopix (widget, gr);
        pp = pdrawtobpix (bitmap, gp);
        s.x = pr.c.x - pr.o.x + 1, s.y = pr.c.y - pr.o.y + 1;
        r.o.x = pp.x, r.o.y = pp.y - s.y + 1;
        r.c.x = r.o.x + s.x - 1, r.c.y = r.o.y + s.y - 1;
        if (r.o.x < 0)
            pr.o.x -= r.o.x, r.o.x = 0;
        if (r.o.y < 0)
            pr.o.y -= r.o.y, r.o.y = 0;
        if (r.c.x >= bitmap->size.x * scale.x) {
            pr.c.x -= (r.c.x + 1 - bitmap->size.x * scale.x);
            r.c.x = bitmap->size.x * scale.x - 1;
        }
        if (r.c.y >= bitmap->size.y * scale.y) {
            pr.c.y -= (r.c.y + 1 - bitmap->size.y * scale.y);
            r.c.y = bitmap->size.y * scale.y - 1;
        }
        if (pr.o.x < 0)
            r.o.x -= pr.o.x, pr.o.x = 0;
        if (pr.o.y < 0)
            r.o.y -= pr.o.y, pr.o.y = 0;
        setgattr (widget, ap);
        gc = CreateCompatibleDC (GC);
        SelectObject (gc, pix);
        BitBlt (
            GC, pr.o.x, pr.o.y, r.c.x - r.o.x + 1, r.c.y - r.o.y + 1,
            gc, r.o.x, r.o.y, (WPU->gattr.mode == G_SRC) ? SRCCOPY : SRCINVERT
        );
        DeleteDC (gc);
    } else if (strcmp (mode, "c2b") == 0) {
        tvx = WPU->vsize.x, tvy = WPU->vsize.y;
        twx = WPU->wrect.c.x - WPU->wrect.o.x;
        twy = WPU->wrect.c.y - WPU->wrect.o.y;
        scale.x = tvx / twx, scale.y = tvy / twy;
        if (scale.x == 1 && scale.y == 1) {
            pix = bitmap->u.bmap.orig;
            bitmap->scale = scale;
        } else {
            if (scale.x != bitmap->scale.x || scale.y != bitmap->scale.y)
                scalebitmap (widget, bitmap, scale, FALSE, 1);
            pix = bitmap->u.bmap.scaled;
        }
        pr = rdrawtobpix (bitmap, gr);
        pp = pdrawtopix (widget, gp);
        s.x = pr.c.x - pr.o.x + 1, s.y = pr.c.y - pr.o.y + 1;
        r.o.x = pp.x, r.o.y = pp.y - s.y + 1;
        r.c.x = r.o.x + s.x - 1, r.c.y = r.o.y + s.y - 1;
        if (pr.o.x < 0)
            r.o.x -= pr.o.x, pr.o.x = 0;
        if (pr.o.y < 0)
            r.o.y -= pr.o.y, pr.o.y = 0;
        if (pr.c.x >= bitmap->size.x * scale.x) {
            r.c.x -= (pr.c.x + 1 - bitmap->size.x * scale.x);
            pr.c.x = bitmap->size.x * scale.x - 1;
        }
        if (pr.c.y >= bitmap->size.y * scale.y) {
            r.c.y -= (pr.c.y + 1 - bitmap->size.y * scale.y);
            pr.c.y = bitmap->size.y * scale.y - 1;
        }
        if (r.o.x < 0)
            pr.o.x -= r.o.x, r.o.x = 0;
        if (r.o.y < 0)
            pr.o.y -= r.o.y, r.o.y = 0;
        setgattr (widget, ap);
        gc = CreateCompatibleDC (GC);
        SelectObject (gc, pix);
        BitBlt (
            gc, pr.o.x, pr.o.y, r.c.x - r.o.x + 1, r.c.y - r.o.y + 1,
            GC, r.o.x, r.o.y, (WPU->gattr.mode == G_SRC) ? SRCCOPY : SRCINVERT
        );
        if (pix != bitmap->u.bmap.orig)
            scalebitmap (widget, bitmap, scale, TRUE, -1);
        DeleteDC (gc);
    }
    return 0;
}