aboutsummaryrefslogtreecommitdiff
path: root/src/libdraw/x11-fill.c
blob: ff0b2e86527813a32cc37367cbf08b71c2f43600 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "x11-inc.h"

#include <u.h>
#include <libc.h>
#include <draw.h>
#include <memdraw.h>
#include "x11-memdraw.h"

void
memfillcolor(Memimage *m, u32int val)
{
	_memfillcolor(m, val);
	if(m->X == nil)
		return;
	if((val & 0xFF) == 0xFF)	/* full alpha */
		xfillcolor(m, m->r, _rgbatoimg(m, val));
	else
		xputxdata(m, m->r);
}

void
xfillcolor(Memimage *m, Rectangle r, u32int v)
{
	Point p;
	Xmem *xm;
	XGC gc;
	
	xm = m->X;
	assert(xm != nil);

	/*
	 * Set up fill context appropriately.
	 */
	if(m->chan == GREY1){
		gc = _x.gcfill0;
		if(_x.gcfill0color != v){
			XSetForeground(_x.display, gc, v);
			_x.gcfill0color = v;
		}
	}else{
		if(m->chan == CMAP8 && _x.usetable)
			v = _x.tox11[v];
		gc = _x.gcfill;
		if(_x.gcfillcolor != v){
			XSetForeground(_x.display, gc, v);
			_x.gcfillcolor = v;
		}
	}

	/*
	 * XFillRectangle takes coordinates relative to image rectangle.
	 */
	p = subpt(r.min, m->r.min);
	XFillRectangle(_x.display, xm->pixmap, gc, p.x, p.y, Dx(r), Dy(r));
}