Plan 9 from Bell Labs’s /usr/web/sources/contrib/pdt/sky/libgfx/gfx.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#include <u.h>
#include <libc.h>
#include <draw.h>

#include "gfx.h"

Image *pen = nil;

int setpen(RGBi c);

int
gfxinit(void)
{
	if(!pen && (pen = allocimage(display, Rect(0, 0, 1, 1), RGB24, 1, 0)) == nil)
		return Gfailed;

	return 0;
}

void
gfxterm(void)
{
	if(pen) freeimage(pen);
}

void
resize(int w, int h)
{
	int fd;

	fd = open("/dev/wctl", OWRITE);
	if(fd >= 0){
		fprint(fd, "resize -dx %d -dy %d", w, h);
		close(fd);
	}
}

int
marker(Image *dst, Point pt, RGBi c, int size, int mark, Rune *s)
{
	Point sh[4];

	if(!setpen(c)) return Gfailed;

	pt = addpt(pt, screen->r.min);
	switch(mark){
	case Msquare:
		line(dst, pt, pt, Endsquare, Endsquare, size, pen, ZP);
		break;
	case Mdisc:
		line(dst, pt, pt, Enddisc, Enddisc, size, pen, ZP);
		break;
	case Mdiamond:
		sh[0] = addpt(pt, Pt(-size,0));
		sh[1] = addpt(pt, Pt(0,-size));
		sh[2] = addpt(pt, Pt(size,0));
		sh[3] = addpt(pt, Pt(0,size));
		fillpoly(dst, sh, 4, 0, pen, ZP);
		break;
	case Mplus:
		line(dst, addpt(pt, Pt(0, -size)), addpt(pt, Pt(0, size)), Endsquare, Endsquare, 1, pen, ZP);
		line(dst, addpt(pt, Pt(-size, 0)), addpt(pt, Pt(size, 0)), Endsquare, Endsquare, 1, pen, ZP);
		break;
	case Mcross:
		line(dst, addpt(pt, Pt(-size, -size)), addpt(pt, Pt(size, size)), Endsquare, Endsquare, 1, pen, ZP);
		line(dst, addpt(pt, Pt(-size, size)), addpt(pt, Pt(size, -size)), Endsquare, Endsquare, 1, pen, ZP);
		break;
	default:
		return Gunsupported;
	}

	if(s) runestring(dst, addpt(pt, Pt(size+1, size+1)), pen, pt, font, s);

	return 0;
}

int
setpen(RGBi c)
{
	return loadimage(pen, pen->r, c.buf, 3);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].