Our XBM images is made up of two types of objects


Our XBM images is made up of two types of objects: the xbmRow object, which contains an array of 16-bit numbers, and the xbmImage object, which contains an array of xbmRow objects
These objects both contain additional information used in manipulating the image and in translating it to ASCII text for display.

The xbmImage() constructor takes the width and height of the image


The xbmImage() constructor takes the width and height of the image, in pixels, as parameters. An optional initial value can also be specified-if supplied; this will create a pattern of vertical lines in the image. Otherwise, a zero is assumed, which results in a blank image.
The xbmImage() constructor calls the xbmRow() constructor to create each row in the image. xbmRow() should be considered an internal function. You don’t need to call it directly.

Both xbmImage and xbmRow have toString() methods


Both xbmImage and xbmRow have toString() methods: xbmImageString() and xbmRowString(), respectively. These create the ASCII representation of the XBM image when it’s time to display it.
A third method, xbmPartitionString(), optimizes the string-building process, which would otherwise consume an excessive amount of memory.

The foundation of our XBM drawing capability is the drawPoint() method


The foundation of our XBM drawing capability is the drawPoint() method, xbmDrawPoint().As all of our XBM drawing methods, the drawPoint() method doesn’t actually draw anything on the screen.
Instead, it updates the internal state of the xbmImage object to indicate that the specified point needs to be drawn.

The drawPoint() method takes the x and y coordinates of the point to be drawn


The drawPoint() method takes the x and y coordinates of the point to be drawn. These are specified relative to the upper-left corner of the image, which is point (0,0).
The y coordinate is used as an index into the array of xbmRow objects. The high-order bits of the x coordinate are used to compute an index into the array of JavaScript numbers representing the row. The low-order bits are then used to calculate the bit offset for the desired pixel coordinate, which is turned on.

The drawCircle() method, xbmDrawCircle(), and the drawFilledCircle() method


The drawCircle() method, xbmDrawCircle(), and the drawFilledCircle() method, xbmDrawFilledCircle(), take the coordinates of the center point of the circle plus the radius.
These methods take advantage of the fact that it’s necessary only to compute the points for a single octant (one-eighth) of a circle. They compute these points relative to an origin of (0,0), and then translate them to the eight octants relative to the x and y coordinates.

Once an xbmImage has been displayed, any subsequent changes to it will


Once an xbmImage has been displayed, any subsequent changes to it will not be displayed when you redraw the frame. Netscape assumes that images of a given name don’t change, so it uses its cached copy after the first draw.
The workaround is to assign the xbmImage object to an object with a different name and then redraw it. The JS-Draw application, shown in the next section, uses an array for this purpose.

To understand JavaScript’s event handling model


To understand JavaScript’s event handling model, you must first think about the things that can actually happen on a Web page. Although there are many different things you can do with the browser, most of these have nothing to do with Web navigation.
When you save a page as text, print a page, or edit your hotlist, you are not actually navigating the Web. In these cases, you are using some of the graphical capabilities of the browser, which are independent of the Web.

To understand which browser actions correspond to JavaScript events


To understand which browser actions correspond to JavaScript events and which do not, it is important to distinguish those actions that actually cause some change in the Web page being displayed.
From the user’s standpoint the number of such actions is actually quite limited. In fact, there are really only two types of top level actions: the user can navigate, or the user can interact with an element of an HTML form.