1Draw: module 2{ 3 PATH: con "$Draw"; 4 5 # predefined colors; pass to Display.color 6 Opaque: con int 16rFFFFFFFF; 7 Transparent: con int 16r00000000; # only useful for Display.newimage 8 Black: con int 16r000000FF; 9 White: con int 16rFFFFFFFF; 10 Red: con int 16rFF0000FF; 11 Green: con int 16r00FF00FF; 12 Blue: con int 16r0000FFFF; 13 Cyan: con int 16r00FFFFFF; 14 Magenta: con int 16rFF00FFFF; 15 Yellow: con int 16rFFFF00FF; 16 Grey: con int 16rEEEEEEFF; 17 Paleyellow: con int 16rFFFFAAFF; 18 Darkyellow: con int 16rEEEE9EFF; 19 Darkgreen: con int 16r448844FF; 20 Palegreen: con int 16rAAFFAAFF; 21 Medgreen: con int 16r88CC88FF; 22 Darkblue: con int 16r000055FF; 23 Palebluegreen: con int 16rAAFFFFFF; 24 Paleblue: con int 16r0000BBFF; 25 Bluegreen: con int 16r008888FF; 26 Greygreen: con int 16r55AAAAFF; 27 Palegreygreen: con int 16r9EEEEEFF; 28 Yellowgreen: con int 16r99994CFF; 29 Medblue: con int 16r000099FF; 30 Greyblue: con int 16r005DBBFF; 31 Palegreyblue: con int 16r4993DDFF; 32 Purpleblue: con int 16r8888CCFF; 33 34 Notacolor: con int 16rFFFFFF00; 35 Nofill: con Notacolor; 36 37 # end styles for line 38 Endsquare: con 0; 39 Enddisc: con 1; 40 Endarrow: con 2; 41 42 # flush control 43 Flushoff: con 0; 44 Flushon: con 1; 45 Flushnow: con 2; 46 47 # image backing store 48 Refbackup: con 0; 49 Refnone: con 1; 50 51 # compositing operators 52 SinD: con 1<<3; 53 DinS: con 1<<2; 54 SoutD: con 1<<1; 55 DoutS: con 1<<0; 56 57 S: con SinD|SoutD; 58 SoverD: con SinD|SoutD|DoutS; 59 SatopD: con SinD|DoutS; 60 SxorD: con SoutD|DoutS; 61 62 D: con DinS|DoutS; 63 DoverS: con DinS|DoutS|SoutD; 64 DatopS: con DinS|SoutD; 65 DxorS: con DoutS|SoutD; 66 67 Clear: con 0; 68 69 # Image channels descriptor 70 Chans: adt 71 { 72 desc: int; # descriptor packed into an int 73 74 # interpret standard channel string 75 mk: fn(s: string): Chans; 76 # standard printable form 77 text: fn(c: self Chans): string; 78 # equality 79 eq: fn(c: self Chans, d: Chans): int; 80 # bits per pixel 81 depth: fn(c: self Chans): int; 82 }; 83 84 CRed, CGreen, CBlue, CGrey, CAlpha, CMap, CIgnore: con iota; 85 86 GREY1: con Chans((CGrey<<4) | 1); 87 GREY2: con Chans((CGrey<<4) | 2); 88 GREY4: con Chans((CGrey<<4) | 4); 89 GREY8: con Chans((CGrey<<4) | 8); 90 CMAP8: con Chans((CMap<<4) | 8); 91 RGB15: con Chans(((CIgnore<<4)|1)<<24 | ((CRed<<4)|5)<<16 | ((CGreen<<4)|5)<<8 | ((CBlue<<4)|5)); 92 RGB16: con Chans(((CRed<<4)|5)<<16 | ((CGreen<<4)|6)<<8 | ((CBlue<<4)|5)); 93 RGB24: con Chans(((CRed<<4)|8)<<16 | ((CGreen<<4)|8)<<8 | ((CBlue<<4)|8)); 94 RGBA32: con Chans((((CRed<<4)|8)<<24 | ((CGreen<<4)|8)<<16 | ((CBlue<<4)|8))<<8 | ((CAlpha<<4)|8)); 95 ARGB32: con Chans(((CAlpha<<4)|8)<<24 | ((CRed<<4)|8)<<16 | ((CGreen<<4)|8)<<8 | ((CBlue<<4)|8)); # stupid VGAs 96 XRGB32: con Chans(((CIgnore<<4)|8)<<24 | ((CRed<<4)|8)<<16 | ((CGreen<<4)|8)<<8 | ((CBlue<<4)|8)); # stupid VGAs 97 98 # Coordinate of a pixel on display 99 Point: adt 100 { 101 x: int; 102 y: int; 103 104 # arithmetic 105 add: fn(p: self Point, q: Point): Point; 106 sub: fn(p: self Point, q: Point): Point; 107 mul: fn(p: self Point, i: int): Point; 108 div: fn(p: self Point, i: int): Point; 109 # equality 110 eq: fn(p: self Point, q: Point): int; 111 # inside rectangle 112 in: fn(p: self Point, r: Rect): int; 113 }; 114 115 # Rectangle of pixels on the display; min <= max 116 Rect: adt 117 { 118 min: Point; # upper left corner 119 max: Point; # lower right corner 120 121 # make sure min <= max 122 canon: fn(r: self Rect): Rect; 123 # extent 124 dx: fn(r: self Rect): int; 125 dy: fn(r: self Rect): int; 126 size: fn(r: self Rect): Point; 127 # equality 128 eq: fn(r: self Rect, s: Rect): int; 129 # intersection and clipping 130 Xrect: fn(r: self Rect, s: Rect): int; 131 inrect: fn(r: self Rect, s: Rect): int; 132 clip: fn(r: self Rect, s: Rect): (Rect, int); 133 contains: fn(r: self Rect, p: Point): int; 134 combine: fn(r: self Rect, s: Rect): Rect; 135 # arithmetic 136 addpt: fn(r: self Rect, p: Point): Rect; 137 subpt: fn(r: self Rect, p: Point): Rect; 138 inset: fn(r: self Rect, n: int): Rect; 139 }; 140 141 # a picture; if made by Screen.newwindow, a window. always attached to a Display 142 Image: adt 143 { 144 # these data are local copies, but repl and clipr 145 # are monitored by the runtime and may be modified as desired. 146 r: Rect; # rectangle in data area, local coords 147 clipr: Rect; # clipping region 148 depth: int; # number of bits per pixel 149 chans: Chans; 150 repl: int; # whether data area replicates to tile the plane 151 display: ref Display; # where Image resides 152 screen: ref Screen; # nil if not window 153 iname: string; 154 155 # graphics operators 156 drawop: fn(dst: self ref Image, r: Rect, src: ref Image, matte: ref Image, p: Point, op: int); 157 draw: fn(dst: self ref Image, r: Rect, src: ref Image, matte: ref Image, p: Point); 158 gendrawop: fn(dst: self ref Image, r: Rect, src: ref Image, p0: Point, matte: ref Image, p1: Point, op: int); 159 gendraw: fn(dst: self ref Image, r: Rect, src: ref Image, p0: Point, matte: ref Image, p1: Point); 160 lineop: fn(dst: self ref Image, p0,p1: Point, end0,end1,radius: int, src: ref Image, sp: Point, op: int); 161 line: fn(dst: self ref Image, p0,p1: Point, end0,end1,radius: int, src: ref Image, sp: Point); 162 polyop: fn(dst: self ref Image, p: array of Point, end0,end1,radius: int, src: ref Image, sp: Point, op: int); 163 poly: fn(dst: self ref Image, p: array of Point, end0,end1,radius: int, src: ref Image, sp: Point); 164 bezsplineop: fn(dst: self ref Image, p: array of Point, end0,end1,radius: int, src: ref Image, sp: Point, op: int); 165 bezspline: fn(dst: self ref Image, p: array of Point, end0,end1,radius: int, src: ref Image, sp: Point); 166 fillpolyop: fn(dst: self ref Image, p: array of Point, wind: int, src: ref Image, sp: Point, op: int); 167 fillpoly: fn(dst: self ref Image, p: array of Point, wind: int, src: ref Image, sp: Point); 168 fillbezsplineop: fn(dst: self ref Image, p: array of Point, wind: int, src: ref Image, sp: Point, op: int); 169 fillbezspline: fn(dst: self ref Image, p: array of Point, wind: int, src: ref Image, sp: Point); 170 ellipseop: fn(dst: self ref Image, c: Point, a, b, thick: int, src: ref Image, sp: Point, op: int); 171 ellipse: fn(dst: self ref Image, c: Point, a, b, thick: int, src: ref Image, sp: Point); 172 fillellipseop: fn(dst: self ref Image, c: Point, a, b: int, src: ref Image, sp: Point, op: int); 173 fillellipse: fn(dst: self ref Image, c: Point, a, b: int, src: ref Image, sp: Point); 174 arcop: fn(dst: self ref Image, c: Point, a, b, thick: int, src: ref Image, sp: Point, alpha, phi: int, op: int); 175 arc: fn(dst: self ref Image, c: Point, a, b, thick: int, src: ref Image, sp: Point, alpha, phi: int); 176 fillarcop: fn(dst: self ref Image, c: Point, a, b: int, src: ref Image, sp: Point, alpha, phi: int, op: int); 177 fillarc: fn(dst: self ref Image, c: Point, a, b: int, src: ref Image, sp: Point, alpha, phi: int); 178 bezierop: fn(dst: self ref Image, a,b,c,d: Point, end0,end1,radius: int, src: ref Image, sp: Point, op: int); 179 bezier: fn(dst: self ref Image, a,b,c,d: Point, end0,end1,radius: int, src: ref Image, sp: Point); 180 fillbezierop: fn(dst: self ref Image, a,b,c,d: Point, wind:int, src: ref Image, sp: Point, op: int); 181 fillbezier: fn(dst: self ref Image, a,b,c,d: Point, wind:int, src: ref Image, sp: Point); 182 textop: fn(dst: self ref Image, p: Point, src: ref Image, sp: Point, font: ref Font, str: string, op: int): Point; 183 text: fn(dst: self ref Image, p: Point, src: ref Image, sp: Point, font: ref Font, str: string): Point; 184 textbgop: fn(dst: self ref Image, p: Point, src: ref Image, sp: Point, font: ref Font, str: string, bg: ref Image, bgp: Point, op: int): Point; 185 textbg: fn(dst: self ref Image, p: Point, src: ref Image, sp: Point, font: ref Font, str: string, bg: ref Image, bgp: Point): Point; 186 border: fn(dst: self ref Image, r: Rect, i: int, src: ref Image, sp: Point); 187 arrow: fn(a,b,c: int): int; 188 # direct access to pixels 189 readpixels: fn(src: self ref Image, r: Rect, data: array of byte): int; 190 writepixels: fn(dst: self ref Image, r: Rect, data: array of byte): int; 191 # publishing 192 name: fn(src: self ref Image, name: string, in: int): int; 193 # windowing 194 top: fn(win: self ref Image); 195 bottom: fn(win: self ref Image); 196 flush: fn(win: self ref Image, func: int); 197 origin: fn(win: self ref Image, log, scr: Point): int; 198 }; 199 200 # a frame buffer, holding a connection to /dev/draw 201 Display: adt 202 { 203 image: ref Image; # holds the contents of the display 204 white: ref Image; 205 black: ref Image; 206 opaque: ref Image; 207 transparent: ref Image; 208 209 # allocate and start refresh slave 210 allocate: fn(dev: string): ref Display; 211 startrefresh: fn(d: self ref Display); 212 # attach to existing Screen 213 publicscreen: fn(d: self ref Display, id: int): ref Screen; 214 getwindow: fn(d: self ref Display, winname: string, screen: ref Screen, image: ref Image, backup: int): (ref Screen, ref Image); 215 # image creation 216 newimage: fn(d: self ref Display, r: Rect, chans: Chans, repl, color: int): ref Image; 217 color: fn(d: self ref Display, color: int): ref Image; 218 colormix: fn(d: self ref Display, c1: int, c2: int): ref Image; 219 rgb: fn(d: self ref Display, r, g, b: int): ref Image; 220 # attach to named Image 221 namedimage: fn(d: self ref Display, name: string): ref Image; 222 # I/O to files 223 open: fn(d: self ref Display, name: string): ref Image; 224 readimage: fn(d: self ref Display, fd: ref Sys->FD): ref Image; 225 writeimage: fn(d: self ref Display, fd: ref Sys->FD, i: ref Image): int; 226 # color map 227 rgb2cmap: fn(d: self ref Display, r, g, b: int): int; 228 cmap2rgb: fn(d: self ref Display, c: int): (int, int, int); 229 cmap2rgba: fn(d: self ref Display, c: int): int; 230 }; 231 232 # a mapping between characters and pictures; always attached to a Display 233 Font: adt 234 { 235 name: string; # *default* or a file name (this may change) 236 height: int; # interline spacing of font 237 ascent: int; # distance from baseline to top 238 display: ref Display; # where Font resides 239 240 # read from file or construct from local description 241 open: fn(d: ref Display, name: string): ref Font; 242 build: fn(d: ref Display, name, desc: string): ref Font; 243 # string extents 244 width: fn(f: self ref Font, str: string): int; 245 bbox: fn(f: self ref Font, str: string): Rect; 246 }; 247 248 # a collection of windows; always attached to a Display 249 Screen: adt 250 { 251 id: int; # for export when public 252 image: ref Image; # root of window tree 253 fill: ref Image; # picture to use when repainting 254 display: ref Display; # where Screen resides 255 256 # create; see also Display.publicscreen 257 allocate: fn(image, fill: ref Image, public: int): ref Screen; 258 # allocate a new window 259 newwindow: fn(screen: self ref Screen, r: Rect, backing: int, color: int): ref Image; 260 # raise or lower a group of windows 261 top: fn(screen: self ref Screen, wins: array of ref Image); 262 bottom: fn(screen: self ref Screen, wins: array of ref Image); 263 }; 264 265 # the state of a pointer device, e.g. a mouse or stylus 266 Pointer: adt 267 { 268 buttons: int; # bits 1 2 4 ... represent state of buttons left to right; 1 means pressed 269 xy: Point; # position 270 msec: int; # millisecond time stamp 271 }; 272 273 # graphics context 274 Context: adt 275 { 276 display: ref Display; # frame buffer on which windows reside 277 screen: ref Screen; # place to make windows (mux only) 278 wm: chan of (string, chan of (string, ref Wmcontext)); # connect to window manager 279 }; 280 281 # connection to window manager for one or more windows (as Images) 282 Wmcontext: adt 283 { 284 kbd: chan of int; # incoming characters from keyboard 285 ptr: chan of ref Pointer; # incoming stream of mouse positions 286 ctl: chan of string; # commands from wm to application 287 wctl: chan of string; # commands from application to wm 288 images: chan of ref Image; # exchange of images 289 connfd: ref Sys->FD; # connection control 290 ctxt: ref Context; 291 }; 292 293 # functions that don't fit well in any adt 294 setalpha: fn(c: int, a: int): int; 295 bytesperline: fn(r: Rect, d: int): int; 296 icossin: fn(deg: int): (int, int); 297 icossin2: fn(p: Point): (int, int); 298}; 299