F.G.H. 7/2/85 LispCourse #40: Using the Display: Bitmaps, DisplayStreams, & Windows LispCourse #40: Using the Display: Bitmaps, DisplayStreams, & Windows Introduction Interaction with the display from Interlisp-D programs involves 3 basic types of Interlisp objects bitmaps, display streams, and windows. A bitmap is a two-dimensional array of bits (1s and 0s) in your computer's memory. You deal with bitmaps by setting specific bits to 1 or 0, or by copying rectanglular arrays of bits around from bitmap to bitmap. The Interlisp-D display screen is just a special bitmap (called the SCREENBITMAP) that is 808 bits high and 1024 bits wide that is displayed on the screen with every 1-bit is black and every 0-bit is white (or vice versa if you change the VIDEOCOLOR parameter as per page 19.7 in the IRM). Display streams represent an interface that allows you to deal with bit maps at a level higher than bits, i.e., in terms of characters, fonts, lines, circles, regions, etc. You can call functions like DRAWCURVE on a display stream. The result will be a curve drawn on the destination bitmap of that display stream. A display stream is a datatype that represents some destination bitmap. Stored in this datatype are fields that contain things like the current font to be used for writing characters to the destination bitmap, the X-Y position of the "cursor" in the bitmap, left and right margins for writing and drawing on the bitmap, etc. Windows are a way of managing what is being displayed on the most important bitmap of all, the Interlisp-D display screen. A window is a datatype that represents the window object that can be displayed on the Interlisp screen. Stored in the fields of the window datatype are all kinds of functions that specify what is to be done when various operations are carried on the window, e.g., when the window is opened, closed, shrunk, or moved. Also stored in each window datatype is a display stream through which characters, lines, curves, etc. are drawn on the window's bitmap (i.e., the display stream's destination bitmap) which is always SCREENBITMAP. In summary, the data structures underlying each window you see on the screen are as follows: (NIL ((0.0 84.0 NIL) (WIRE ((280.0 . 176.0) (280.0 . 200.0) (416.0 . 200.0) (416.0 . 112.0) (248.0 . 112.0) (248.0 . 72.0)) 2 ((LINE 30.0 12.0) NIL) NIL)) ((0.0 84.0 NIL) (WIRE (( 272.0 . 304.0) (272.0 . 328.0) (416.0 . 328.0) (416.0 . 248.0) (248.0 . 248.0) (248.0 . 208.0)) 2 ((LINE 30.0 12.0) NIL) NIL)) ((.06400001 108.0 NIL) (TEXTBOX (152.0 8.0 216.0 64.0 ) ("SCREENBITMAP") 1.0 (CENTER CENTER) (HELVETICA 10) ((209.0 34.0 103.0 12.0)) NIL 2)) (( .06400001 108.0 NIL) (TEXTBOX (152.0 144.0 216.0 64.0) ("DisplayStream " " " "Fields: Destination bitmap , X-Y" "cursor position, font, offset within" "destination bitmap, etc. ") 1.0 (LEFT CENTER) (HELVETICA 10) ((154.0 194.0 93.0 12.0) (154.0 182.0 6.0 12.0) (154.0 170.0 196.0 12.0) (154.0 158.0 203.0 12.0) (154.0 146.0 143.0 12.0)) NIL 2)) ((.06400001 108.0 NIL) (TEXTBOX (160.0 272.0 216.0 64.0) ("Window " " " "Fields: DisplayStream , location on" "screen, order in window stack," "open function, close function, etc.") 1.0 (LEFT CENTER) (HELVETICA 10) ((162.0 322.0 55.0 12.0) (162.0 310.0 9.0 12.0) (162.0 298.0 216.0 12.0) (162.0 286.0 184.0 12.0) (162.0 274.0 208.0 12.0)) NIL 2)) ((.05 13.0 NIL) (TEXT (144.0 . 304.0) ("Screen" "Management") 1.0 (RIGHT BASELINE) (HELVETICA 12) ((92.0 307.0 52.0 13.0) (50.0 294.0 94.0 13.0)) NIL)) (( .05 13.0 NIL) (TEXT (136.0 . 176.0) ("Drawing objects" "like characters" "and curves") 1.0 ( RIGHT BASELINE) (HELVETICA 12) ((18.0 186.0 118.0 13.0) (27.0 173.0 109.0 13.0) (55.0 160.0 81.0 13.0)) NIL)) ((.05 13.0 NIL) (TEXT (136.0 . 40.0) ("The actual bits" "displayed" "on the screen") 1.0 (RIGHT BASELINE) (HELVETICA 12) ((27.0 50.0 109.0 13.0) (67.0 37.0 69.0 13.0) (35.0 24.0 101.0 13.0)) NIL))) (0 0 423.0 348.0) 1.0 8.0 Coordinate Systems, Positions, & Regions Coordinate Systems for Specifying Locations in Bitmaps, et al. Each bitmap, display stream, and window has its own coordinate system used to specify locations within the object. When dealing with the display, these coordinate systems are always measured in bits (or screen units or the area that it takes to display 1 bit on the screen or 1/72nd of an inch). For all three objects, the coordinate system is a standard Cartesian system in the standard orientation. (NIL ((0.0 60.0 NIL) (WIRE ((112.0 . 144.0) (112.0 . 40.0) (112.0 . 24.0)) 2 ((LINE 30.0 12.0) (LINE 30.0 12.0)) NIL)) ((.05 12.0 NIL) (TEXT (112.0 . 152.0) ("(0,Y)") 1.0 (CENTER BASELINE) (HELVETICA 10) ((98.0 150.0 28.0 12.0)) NIL)) ((.05 12.0 NIL) (TEXT (128.0 . 88.0) ("(0,0)") 1.0 (CENTER BASELINE) (HELVETICA 10) ((115.0 86.0 26.0 12.0)) NIL)) ((.05 12.0 NIL) (TEXT (16.0 . 80.0) ("(--X,0)") 1.0 (CENTER BASELINE) (HELVETICA 10) ((-2.0 78.0 36.0 12.0)) NIL)) ((0.0 72.0 NIL) (WIRE ((40.0 . 80.0) (184.0 . 80.0)) 2 ((LINE 30.0 12.0) (LINE 30.0 12.0)) NIL)) ((.05 12.0 NIL) (TEXT (112.0 . 8.0) ("(0,--Y)") 1.0 (CENTER BASELINE) ( HELVETICA 10) ((94.0 6.0 36.0 12.0)) NIL)) ((.05 12.0 NIL) (TEXT (200.0 . 80.0) ("(X,0)") 1.0 (CENTER BASELINE) (HELVETICA 10) ((186.0 78.0 28.0 12.0)) NIL))) (0 0 211.0 162.0) 1.0 8.0 Bitmaps have a finite size. Thus, for bitmaps the origin of the coordinate system is placed at the lower-left corner of the bitmap and only the upper-right quadrant (positive X and Y) is used to specify locations in the bitmap. Display streams and windows are considered to look onto an infinite plane. Thus the origin is arbitrarily placed (see below) and the entire coordinate system is used. The coordinate system for a window is the same as the coordinate system for its underlying display stream. The coordinate system for a display stream is mapped onto the coordinate system for its destination bitmap using X and Y translation parameters as discussed below. Positions and Regions Positions and regions are data structures that represent X-Y locations and rectangles, respectively, in an arbitrary coordinate system. A POSITION is a record with two fields, XCOORD and YCCORD. Most functions that take an X-Y location as an argument require a POSITION record. To create a POSITION record: (create POSITION XCOORD _ X YCOORD _ Y) A REGION is a record with four fields: LEFT, BOTTOM, WIDTH, and HEIGHT specifying the lower-left corner and extent of a rectangular region in some coordinate space. To create a REGION record: (CREATEREGION Left Bottom Width Height) There are several functions available to manipulate positions and regions, including the following: (INSIDEP Region Position) returns T if Position is inside Region. Examples: 1_ (INSIDEP (CREATEREGION 100 100 10 10)(create POSITION XCOORD _ 150 YCOORD _ 100)) NIL 2_ (INSIDEP (CREATEREGION 100 100 100 10)(create POSITION XCOORD _ 150 YCOORD _ 100)) T (INTERSECTREGIONS Region1 Region2 ... RegionN) returns the region that is the intersections of Region1, Region2, ..., and RegionN. NIL, if there is no intersection. (UNIONREGIONS Region1 Region2 ... RegionN) returns the region that is the union of Region1, Region2, ..., and RegionN. The union is the smallest (rectangular) region that contains all of the given regions. BITMAPs Introduction A bitmap is datatype that represents an N by M array of bits in memory. The bits in a bitmap are identified using a positive integer coordinate system whose origin (0,0) is the lower-left corner of the bitmap. For example, (10,2) represents the bit that is 10 to the left of and 2 up from the bit in the lower-left corner of the bitmap. DDDDDDDDDDDDDDDDDDDDDDDDDD@ Gꪪ@ G>UUUUUUUUUUW@ UUUUUUUUUUW ꪪ Gƌ|:j@ GsyuuUUUUUUUUUUW@ ߳UUUUUUUUUUW ߷ꪪ G߷ꪪ@ G߷UUUUUUUUUUW@ ywUUUUUUUUUUW Jꪪ Gꪪ@ GUUUUUUUUUUW@ UUUUUUUUUUW G @ G @ UUUUUUUUUUUUUUUUUUUUUUS G UUUUUUUUUUUUUUUUUUUUUUS@ G @ UUUUUUUUUUUUUUUUUUUUUUS G UUUUUUUUUUUUUUUUUUUUUUS@ G @ UUUUUUUUUUUUUUUUUUUUUUS G UUUUUUUUUUUUUUUUUUUUUUS@ G @ UUUUUUUUUUUUUUUUUUUUUUS G UUUUUUUUUUUUUUUUUUUUUUS@ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G @ G@ DDDDDDDDDDDDDDDDDDDDDDDDDD@ DDDDDDDDDDDDDDDDDDDDDDDDDD@ Creating Bitmaps To create a bitmap use the following function: (BITMAPCREATE Width Height) creates and returns a bitmap Height bits high and Width bits wide. BITBLT The major operation on bitmaps is the moving of bits from one bit map to another using the BITBLT function: (BITBLT SourceBitMap SourceLeft SourceBottom DestBitMap DestLeft DestBottom Width Height SourceType Operation Texture) copies some bits in SourceBitMap and combines them with some bits in DestBitMap, resulting in a change to these bits in DestBitMap. The bits copied from SourceBitMap are those in the region defined by SourceLeft, SourceBottom, Width, & Height. The bits effected in the DestBitMap are those in the region defined by DestLeft, DestBottom, Width, & Height. If either of these regions overflows the edges of its bitmap, then Width and/or Height are decreased until both regions fit into their bitmaps. The way in which the bits are copied from the SourceBitMap is determined by SourceType and Texture as follows: If SourceType is INPUT, then the bits are copied directly from the region in SourceBitMap. If SourceType is INVERT, then the bits are copied from the region in SourceBitMap, but each bit is inverted (i.e., 1s become 0s and vice versa). If SourceType is TEXTURE, then SourceBitMap, SourceLeft, and SourceBottom are ignored and the bits to be copied are taken from the bitmap specified by Texture. If the Texture bitmap is smaller than Width by Height, then it is repeated as many times as necessary to make a rectangle of bits that is of size Width by Height. Note: the global variables WHITESHADE, BLACKSHADE and GRAYSHADE are small bitmaps for white, black, and gray, respectively. SourceType defaults to INPUT. The way in which the copied bits are combined with the bits already in DestBitMap is determined by Operation as follows: If Operation is REPLACE, the bits in DestBitMap are replaced by the copied bits. If Operation is PAINT, the bits in DestBitMap are logically ORed with the copied bits. If Operation is INVERT, the bits in DestBitMap are logically XORed with the copied bits. If Operation is ERASE, the bits in DestBitMap are logically ANDed with the inversion of the copied bits. Operation defaults to REPLACE. Examples: START BitMap1: y N