Charles.Forsyth20060303-partialeea662d19 years agoHistory
268 lines · 7.1 KB · Text
RawDownload
.TH DRAW-INTRO 2.SH NAMEdraw \- basic graphics facilities module.SH SYNOPSIS.EXinclude "draw.m";draw := load Draw Draw->PATH; setalpha:  fn(rgba: int, alpha: int): int;.EE.SH DESCRIPTIONInferno's.B Drawmodule provides basic graphics facilities, defining drawingcontexts, images, character fonts, and rectangular geometric operations.See.IR wmlib (2)and.IR tk (2)for higher level operations, such as windows and menu handling..SS PixelsImages are defined on a rectangular region ofan integer plane with a picture element, or.IR pixel ,at each grid point.Pixel values are integers with between 1 and 32 bits per pixel, and allpixels in a given image have the same size, or.IR depth .Some operations allow images with different depths to be combined,for example to do masking.Images have one or more channels: colour channels, greyscale channels, colour map indices,and others, as described in.IR colour (6).Each pixel value contains a component of each such channel.All pixels in an image have the same size, or.IR depth ,and the same component structure..PPWhen an image is displayed, the value of each pixel determines the colourof the display, according to the interpretation of the image's channels.For instance, on `true colour' displays, the display image might contain red, blue and greencolour channels, and each pixel value will have red, blue and green colour components.For displays with only 8 bits per pixel or less,Inferno uses a fixed colour map for each display depth (see.IR colour (6)).Facilities exist in.IR draw-display (2)to convert between (red, green, blue)triplets and colour-mapped pixel values,but the mapping is often done automatically by the graphics operationswhen images with different channel structures are combined..PP.B Drawuses a standard representation of colour constants in calls to create coloured imagesor to initialise new images with a given colour.This is referred to as `32-bit RGBA format'.Each constant colour is represented as a 32-bit integer, with 8-bit red, blue and green colour components,and an 8-bit alpha component, in that order from most to least significant byte..PPThe RGB values in a colour are.I premultipliedby the alpha value; for example, a 50% red is.B "int 16r7F00007F"not.BR "int 16rFF00007F" .The function.B Draw->setalphaperforms the alpha computation on a given colour.I rgbain 32-bit RGBA format,ignoring its initial alpha value, and returning theresult of multiplying each colour component by the supplied.BR alpha .For example, to make a 50% red color value, one could execute.B draw->setalpha(Draw->Red,.BR 16r7F) ..SS Terminology.TF Pointer.PD.TP.B PointThe graphics plane is defined on an integer grid,with each.RI ( x ",\ " y )coordinate identifyingthe upper left corner of the corresponding pixel.The plane's origin, (0,\ 0), resides at the upper left corner of the screen;.I xand.I ycoordinates increase to the right and down.The abstract data type,.BR Pointdefines a coordinate position..TP.B RectThe type.B Rectdefines a rectangular region of the plane.It comprises two.BR Points ,.B minand.BR max ,and specifies the region defined by pixels with coordinatesgreater than or equal to.B minand strictly less than.BR max ,in both.I xand.IR y .This.I half-openproperty allows rectangles that share an edge to have equal coordinates on the edge..TP.B DisplayThe type.B Displayrepresents a physical display, corresponding to a single connection to a.IR draw (3)device.Besides the image of the display itself, the.B Displaytype also stores references to off-screen images, fonts, and so on.The contents of such images are stored in the display device, not in the clientof the display, which affects how they are allocated and used, see for example.IR draw-image (2)..TP.B ScreenThe.B Screentype is used to manage a set of windows on an image, typically but not necessarilythat of a display..B Screensand hence windows may be built recursively upon windows forsubwindowing or even on off-screen images..TP.B ImageThe.B Imagetype provides basic operations on groups of pixels.Through a few simple operations, most importantly the.B drawimage combination operator(see.IR draw-image (2)),the.B Imagetype provides the building blocks for.BR Display ,.BR Screen ,and.BR Font ..TP.B FontA.B Fontdefines which character image to draw for each character code value.Although all character drawing operations ultimately use the.B drawprimitive on the underlying images,.B Fontsprovide convenient and efficient management of display text.Inferno uses the 16-bit Unicode character encoding, so.B Fontsare managed hierarchically to control their size and to makecommon subsets such as ASCII or Greek efficient in practice.See.IR draw-font (2),.IR utf (6),and.IR font (6)..TP.B ContextA.B Contextprovides an interface to the system graphics and interactive devices.The system creates this context when it starts an application..TP.B PointerThe.B Pointertype conveys information for pointing devices, such as mice or trackballs..SS More about Images.PPAn image occupies a rectangle,.BR Image.r ,of the graphics plane.A second rectangle,.BR Image.clipr ,defines a clipping region for the image.Typically, the clipping rectangle is the same as the basic image,but they may differ.For example, the clipping region may be made smaller and centered onthe basic image to define a protected border..PPThe pixel structure of an.B Imageis stored as.B Chansvalue.BR Image.chans ;the image's pixel depth in bits is stored as integer.BR Image.depth ..PPAn image may be marked for replication: when set, the boolean.B Image.replcauses the imageto behave as if replicated across the entire integer plane,thus tiling the destination graphics areawith copies of the source image.When replication is turned on,the clipping rectangle limits the extent of the replication and mayeven usefully be disjoint from.BR Image.r .See.IR draw-image (2)for examples..PPThe.B Imagemember functions provide facilities for drawing text and geometric objects,manipulating windows, and so on..PPObjects of type.BR Display ,.BR Font ,.BR Screen ,and.B Imagemust be allocated by the member functions;if such objects are created with a regular Limbodefinition, they will not behave properly and may generate run-time errors..PPThere are no ``free'' routines for graphics objects.Instead Limbo's garbagecollection frees them automatically.As is generally so within Limbo,one can eliminate references by assigning.B nilto reference variables, returning from functionswhose local variables hold references, etc..SH RETURN VALUESMost drawing operations operate asynchronously, so they haveno error return.Functions that allocate objects return.B nilfor failure; in such cases the system error string may beinterrogated (such as by the.B %rformat (see.IR sys-print (2))) for more information..SH SOURCE.B /libinterp/draw.c.br.B /libdraw/*.c.SH SEE ALSO.IR draw (3),.IR ir (2),.IR prefab-intro (2),.IR tk (2),.IR wmlib (2),.IR colour (6),.IR font (6),.IR image (6)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t