shithub: libdraw.myr

ref: d180b70c6c69ffe8168cc8571772ad6e15ac6aba
dir: /types.myr/

View raw version
use std
use thread

pkg draw =
	type chan = uint32
	type color = uint32
	type refresh = uint32
	type drawop = uint32

	/* KF|1, KF|2, ..., KF|0xC is F1, F2, ..., F12 */
	const KF	= 0xF000	/* Rune: beginning of private Unicode space */
	const Spec	= 0xF800
	const PF	= Spec|0x20	/* num pad function key */
	const Kview	= Spec|0x00	/* view (shift window up) */
	const Khome	= KF|0x0D
	const Kup	= KF|0x0E
	const Kdown	= Kview
	const Kpgup	= KF|0x0F
	const Kprint	= KF|0x10
	const Kleft	= KF|0x11
	const Kright	= KF|0x12
	const Kpgdown	= KF|0x13
	const Kins	= KF|0x14

	const Kalt	= KF|0x15
	const Kshift	= KF|0x16
	const Kctl	= KF|0x17

	const Kend	= KF|0x18
	const Kscroll	= KF|0x19
	const Kscrolloneup	= KF|0x20
	const Kscrollonedown	= KF|0x21

	const Ksoh	= 0x01
	const Kstx	= 0x02
	const Ketx	= 0x03
	const Keof	= 0x04
	const Kenq	= 0x05
	const Kack	= 0x06
	const Kbs	= 0x08
	const Knack	= 0x15
	const Ketb	= 0x17
	const Kdel	= 0x7f
	const Kesc	= 0x1b

	const Kbreak	= Spec|0x61
	const Kcaps	= Spec|0x64
	const Knum	= Spec|0x65
	const Kmiddle	= Spec|0x66
	const Kaltgr	= Spec|0x67
	const Kmouse	= Spec|0x100

	type display = struct
		datafd	: std.fd
		ctlfd	: std.fd

		/* inputs */
		qmtx	: thread.mutex
		rawevt	: bool
		refrfd	: std.fd
		mousefd	: std.fd
		kbdfd	: std.fd
		refrp	: void#
		mousep	: void#
		kbdp	: void#

		ctldir	: int
		windir	: byte[:]

		imageid	: int32
		scrid	: int32

		root	: image#
		screen	: screen#
		dfont	: font#
		buf	: byte[:]
		bufoff	: std.size

		white	: image#
		black	: image#
		opaque	: image#
		trans	: image#
	;;

	type event = union
		`Kp char
		`Kr char
		`Mmove	(int, int)
		`Mdown	(int, int, int)
		`Mup	(int, int, int)
		`Resize	
		`Refresh
	;;

	type err = union
		`Edpy
		`Efont
		`Ewin
		`Ename
		`Enamelen
		`Eimg
		`Eio
		`Efmt
	;;

	type font = struct
		name	: byte[:]
		height	: int
		ascent	: int
		subf	: subfont[:]
		cache	: std.htab(char, fcinfo)#
		cimage	: image#
		x	: int
		nextidx	: int16
	;;

	type fcinfo = struct
		hits	: int
		idx	: int16
	;;

	type subfont = struct
		lo	: char
		hi	: char
		start	: std.size
		path	: byte[:]
		image	: image#
		glyph	: glyph[:]
	;;

	type glyph = struct
		x	: int
		top	: int
		bottom	: int
		left	: int
		width	: int
	;;

	type screen = struct
		dpy	: display#
		id	: int32
		store	: image#
		fill	: image#
	;;

	type image = struct
		dpy	: display#
		chan	: chan
		color	: color
		refresh	: refresh
		depth	: uint32
		id	: int32
		r	: rect
		clipr	: rect
		repl	: bool
	;;

	type rect = struct
		x0	: int
		x1	: int
		y0	: int
		y1	: int
	;;

	type point = struct
		x	: int
		y	: int
	;;

	const Zp	: point = [.x=0, .y=0]
	const Dfont	: byte[:] = "/lib/font/bit/vga/unicode.font"

	const CidxRed	: int = 0
	const CidxGreen	: int = 1
	const CidxBlue	: int = 2
	const CidxGrey	: int = 3
	const CidxAlpha	: int = 4
	const CidxMap	: int = 5
	const CidxIgnore	: int = 6

	const Cgrey1	: chan = 0x31
	const Cgrey2	: chan = 0x32
	const Cgrey4	: chan = 0x34
	const Cgrey8	: chan = 0x38
	const Ccmap8	: chan = 0x58
	const Crgb15	: chan = 0x61051525
	const Crgb16	: chan = 0x51625
	const Crgb24	: chan = 0x81828
	const Crgba32	: chan = 0x8182848
	const Cargb32	: chan = 0x48081828
	const Cxrgb32	: chan = 0x68081828
	const Cbgr24	: chan = 0x281808
	const Cabgr32	: chan = 0x48281808
	const Cxbgr32	: chan = 0x68281808

	/* Porter-Duff compositing operators */
	const Clear	: drawop = 0
	const SinD	: drawop = 8
	const DinS	: drawop = 4
	const SoutD	: drawop = 2
	const DoutS	: drawop = 1

	const S		: drawop = SinD|SoutD
	const SoverD	: drawop = SinD|SoutD|DoutS
	const SatopD	: drawop = SinD|DoutS
	const SxorD	: drawop = SoutD|DoutS

	const D		: drawop = DinS|DoutS
	const DoverS	: drawop = DinS|DoutS|SoutD
	const DatopS	: drawop = DinS|SoutD
	const DxorS	: drawop = DoutS|SoutD	/* == SxorD */

	/* refresh methods */
	const Refbackup	: refresh = 0
	const Refnone	: refresh = 1
	const Refmesg	: refresh = 2

	/* colors */
	const DOpaque		: color =  0xFFFFFFFF
	const DTransparent	: color =  0x00000000	/* only useful for allocimage, memfillcolor */
	const DBlack		: color =  0x000000FF
	const DWhite		: color =  0xFFFFFFFF
	const DRed		: color =  0xFF0000FF
	const DGreen		: color =  0x00FF00FF
	const DBlue		: color =  0x0000FFFF
	const DCyan		: color =  0x00FFFFFF
	const DMagenta		: color =  0xFF00FFFF
	const DYellow		: color =  0xFFFF00FF
	const DPaleyellow	: color =  0xFFFFAAFF
	const DDarkyellow	: color =  0xEEEE9EFF
	const DDarkgreen	: color =  0x448844FF
	const DPalegreen	: color =  0xAAFFAAFF
	const DMedgreen		: color =  0x88CC88FF
	const DDarkblue		: color =  0x000055FF
	const DPalebluegreen	: color =  0xAAFFFFFF
	const DPaleblue		: color =  0x0000BBFF
	const DBluegreen	: color =  0x008888FF
	const DGreygreen	: color =  0x55AAAAFF
	const DPalegreygreen	: color =  0x9EEEEEFF
	const DYellowgreen	: color =  0x99994CFF
	const DMedblue		: color =  0x000099FF
	const DGreyblue		: color =  0x005DBBFF
	const DPalegreyblue	: color =  0x4993DDFF
	const DPurpleblue	: color =  0x8888CCFF

	const DNotacolor	: color =  0xFFFFFF00
	const DNofill		: color =  DNotacolor

	/* rio expects us to reserve space for the border */
	const Borderwidth	: int	= 4

;;