CapeSoft.Com
Clarion Accessories
Draw
Documentation
Draw Layers
CapeSoft Logo

CapeSoft Draw Layers
Documentation

Installed Version Latest Version  

Introduction to Layers

CapeSoft Draw allows you to use multiple layers, each layer can be drawn on independently and data can be copied between layers. In addition, layers support both index transparency and alpha transparency, as well as a number of additional features. Some of the features provided by layers:

Each layer is an entry in the Draw.layers array. The size of the array (and hence the maximum number of layers that can be initialized) is determined by the Draw:numLayers equate in the Draw.inc file.



Transparency

Transparency can be done in one of two different ways; Index Transparency and Layer Transparency. Index transparency is the easiest to implement, but has some limitations. Layer transparency is a little more complex, but also gives you finer control.

Index Transparency

The basic idea behind index transparency is really simple. One of the colors on this layer is considered to be "transparent". By setting this transparent color, and then drawing in this color, those areas on the layer will be transparent. For example;

Drawer.Blank(color:white) ! clear the base layer to white
Drawer.Image(15, 100, , ,'capesoft.bmp') ! draw something on the base layer

someLayer = 2
transparentColor = 3
! (3 is a good index transparency color as it is very unlikely to ever be used as a color as it is very close to black)

Drawer.InitLayer(someLayer, self.width, self.height)
! create a new layer for drawing
Drawer.IndexTransparency(someLayer, transparentcolor, true)

Drawer.WithLayer(someLayer )
! select the new layer
Drawer.Blank(transparentColor )
! clear the layer to its index transparency color

! Draw a box on somelayer - use Random to draw a slightly different position and size box each time
Drawer.ShadeBox(Random(10, 250), Random(10, 250), Random(50, 200), Random(50, 200), color:red, color:yellow)

Drawer.Display() ! Display the layers

The above code is simple, but demonstrates the idea. the base layer consists of some image, and a random box is drawn on top if it. Because the new layer is cleared to the transparent color, only the box part will appear, merged with the original layer, when the control is displayed.

There are two disadvantages to this approach. The first is the choice of the transparentColor value. If any part of the drawing on this later is actually in this color, then that part of the drawing will end up being transparent. This can lead to unexpected results when shaded items, or photos or things like that are include on the layer. Some careful thought around the choice of transparent color can help.

The second issue is that the transparency is always either 100% on or off. Partial transparency is not available. This in turn means no anti-aliasing between the layers, which can lead to a less smooth merging of the layers.

Layer Transparency

Layer Transparency uses a second layer, known as the Alpha layer, as a tool to merge two layers together. The setup is a little more complex, but more complex transparency options are possible.

First the new drawing layer is created as before;

Drawer.Blank(color:white) ! clear the base layer to white
Drawer.Image(15, 100, , ,'capesoft.bmp') ! draw something on the base layer

someLayer = 2
Drawer.InitLayer(someLayer, self.width, self.height) ! create a new layer for drawing

Then an alpha layer is created and initialised.

alphaLayer = 3
Drawer.InitLayer(alphaLayer, self.width, self.height)
Drawer.HideLayer(alphaLayer)
! the alpha layer is always hidden

Now the alpha layer is tied to the drawing layer.

Drawer.SetMode(someLayer,draw:withAlpha,true)     ! turn on alpha transparency for the SomeLayer
Drawer.AddAlpha(someLayer,AlphaLayer,Channel:Red) ! and bind the AlphaLayer to SomeLayer

I'll explain Channels in a moment, but for now just use Channel:Red.

If you want the alpha layer to default to "perfectly transparent" then blank the layer to white.

self.withLayer(DrawShot:AlphaLayer)
self.blank(color:white)


If you want the alpha layer to default to "completely opaque" then blank the layer to black.

self.withLayer(DrawShot:AlphaLayer)
self.blank(color:black)


If you want the transparency to be semi transparent then use a shade of grey between white and black. Color:Gray is half way, but any shade of grey can be used. The closer it is to White, the more transparent the layer (by default).
Think of the alpha layer as a mixer. When the layers are merged each pixel is merged with the pixel below it. In an opaque situation the top pixel is the pixel used. In a 100% transparent mix the bottom pixel will be used. If the pixel on the alpha layer though is between opaque (black) and transparent (white) then the two pixels will be mixed together, in proportion to the shade of gray.

This comes into consideration when drawing on SomeLayer, you also need to draw on AlphaLayer. The image on SomeLayer is what you want to draw, the image on AlphaLayer is the mask, which determines the transparency of each pixel. So consider;

Drawer.WithLayer(someLayer ) ! select the new layer
Drawer.ShadeBox(50,50, 50, 50, color:red, color:yellow)

 If the AlphaLayer defaulted to white (ie transparent) then the box won't appear on the eventual image. The box will be perfectly transparent (which is invisible). Of course the rest of the layer should be invisible, but you probably want the box to be completely opaque, so you would need to add

Drawer.WithLayer(alphaLayer ) ! select the new layer
Drawer.ShadeBox(50,50, 50, 50, color:black, color:black)

Now the box will be completely opaque, and so it will simply be drawn onto the image as if it had been drawn onto the bottom layer. But consider if you'd done this instead;

Drawer.WithLayer(alphaLayer ) ! select the new layer
Drawer.ShadeBox(50,50, 50, 50, color:gray, color:gray)

Now the box will be mixed with the underlying image, and it will be translucent - there, but also allowing the picture underneath to punch through.

By manipulating the Alpha layer you can manipulate how the two images are mixed together, and this allows for some powerful effects.

Channels

This bit is more advanced, and only used in a very small number of cases, so you can skip over it if you like.
In all the above explanation I used various shades of grey on the alpha layer. Black was opaque and white was transparent.

The color grey is made up of equal parts red, blue and green. As you probably know colors are stored as a long, with one byte for red, one for blue and another for green.The call to AddAlpha though specified that the mask will be using the Red part of the color as the mixer.

In other words, while the Alpha layer is created using 24 bit colors, only 8 bits are used when actually doing the mix. This opens the door to creating multiple masks (up to 3 of them) on each alpha layer. This can allow you to use one alpha layer for 3 different drawing layers (which has some space benefits, albeit at the cost of somewhat more complicated drawing code) or you can use it to create 3 different possible transparencies for one drawing layer. How you make use of that depends somewhat on your imagination.

The key difference when using the three different masks is to be careful about the colors you select when drawing on the alpha layer. For the red channel you would use shades of red, for the green channel shades of green and for the blue channel shades of blue.


Layer Data Structure

layer data structure
name data type description
bitmapData&stringPointer to the layer data. Assigned by InitLayer().
xposlongX Coordinate of the top left hand corner of the layer.
yposlongY Coordinate of the top left hand corner of the layer.
widthlongWidth, in pixels, of the layer.
heightlongHeight, in pixels, of the layer.
alpha&stringPointer to an alpha layer. Assigned by AddAlpha().
alphaLayerlongThe number of the layer used as an alpha channel
alphaChannelbyteThe channel to use for the alpha calculations. See AddAlpha().
indexColorlongColor to use for index transparency. See IndexTransparency().
zeroPadbyteSet by InitLayer().
bufferSizeulongSet by InitLayer(), and ResizeLayer().
displayModebyteThe display mode. See SetMode() for how to set the transparency and visibility attributes of the layer. Can be a combination of: Draw:withAlpha, Draw:indexTransparency and Draw:Hidden. The default value is zero (the layer is not hidden and the data is used with no alpha and no index color). The display mode is set by SetMode() as well as AddAlpha(), IndexTransparency(), HideLayer() and ShowLayer().


Layer Methods
Draw.AddAlphaAdd an alpha channel to a layer
Draw.AlphaCopyHandles alpha blending for CopyLayer. Do not call directly.
Draw.CopyLayerCopy a block of pixels from one layer to another.
Draw.IndexTransparencySet the index transparency of the layer.
Draw.HasAlphaReturns whether a layer has an alpha channel
Draw.HideLayerSet a layer to hidden.
Draw.InitLayer Initialize a new layer
Draw.KillLayerDelete a layer.
Draw.LayerModeReturn whether a layer has a display mode enabled or disabled.
Draw.MoveLayerChange a layer's display order.
Draw.NumLayersReturn the number of initialized layers.
Draw.ResizeLayerResize a specific layer.
Draw.SetModeSet the display mode.
Draw.ShowlayerSet a layer to be shown when Display() is called.
Draw.SwapLayersSwap two slayer's display order.
Draw.ToAlphaCopy one RGB channel from one layer to another.
Draw.WithLayerActivate a layer for drawing to.
See the Layers section for more information on using layers, as well as the layer data type.
To create a new Layer call the InitLayer() method. To draw to a layer call WithLayer() and then use the Draw commands exactly as you would normally. When you call WithLayer() the current layer number is stored in the Draw.activeLayer property. This allows you to easily modify the currently layer simply by passing Draw.activeLayer to any of the layer methods.
The first layer in the Draw.layers array is initialized when the Draw class is initialized. If you prefer you can ignore the fact that layers exist and just use Draw as you always have.

Draw automatically uses the alpha channel and index transparency settings for each layer when merging the layers for display.

You can set the displayMode (for index transparency, showing and hiding layers and alpha transparency) for each layer. The HideLayer() and ShowLayer() methods allow you to specify whether a layer is visible, the AddAlpha() method adds an alpha channel and automatically adds Draw:withAlpha flag to the displayMode variable for the selected layer. You can use IndexTransparency() to add an index transparency color to the layer and add Draw:indexTransparency to displayMode. In addition you can control all of the layer display attributes by calling the SetMode() method.

The actual layer display order is stored in the layerOrder array, which simply stores each of the layer numbers in the order that they are display in, basically this is the order that the layers are "stacked" in. This make it simple to rearrange the layer display order without changing the physical position of the layer in the layers array, which you should not do. See MoveLayer() and SwapLayers() for information. The first entry in the array is the bottom layer, and the layer at draw.numLayers is the top layer. Each time you create a new layer it is added after the last initialized layer, which means that it is on top of all other layers.

Although it is recommended that you use the methods provided, you can access any of the layer data directly, for example:

if Drawer.layers[curLayer].init                           ! check curLayer has been initialized
    Drawer.layers[curLayer].displayMode = Draw:Hidden    
! set the layer to hidden directly, rather than via   SetMode()
end

If you choose to access the layer data directly it is advisable to understand the methods provided for layer data access, and how they manage the layer data. Often changing one layer variable necessitates a number of other changes.

The Draw object has a baseLayer property that you should treat as read only. It cannot be modified using any of the layer methods, however it is useful to access this layer's data, such as Draw.baseLayer.width and Draw.baseLayer.height, as this layer is the buffer onto which all layers are composited for display.

Layer Method Reference

AddAlpha

AddAlpha (long layerNumber, long alphaLayer, byte channel)

Description

Adds an alpha channel to an existing layer. Alpha channels are stored as the red, green and blue components of a layer. The alphaLayer and channel parameters are used to specify which layer to use as the alpha layer and which channel in the alpha layer to use for the alpha values. This method does not modify the display mode of the layer, so if the mode does not contain Draw:withAlpha you will need to call SetMode() to enable the alpha channel. You can call LayerMode() to query whether a particular display mode is enabled for a layer.

Parameters
Parameter Description
layerNumberThe layer to add the alpha channel to (no extra data is created, this is just a reference assignment).
alphaLayerThe source layer to be used. Typically an extra (hidden) layer would be created to be used as an alpha layer.
channelWhich of the RGB components should be used: Channel:Red, Channel:Green or Channel:Blue.
You can use a each channel in an alpha layer as the alpha channel for as many layers as you like, and each alpha layer can store three alpha channels, one in each of the RGB components. The alpha layer will automatically be set to hidden and have no index or alpha transparency when this method is called.
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Remarks

You can draw to an alpha layer the same as any other layer, simply by calling Draw.WithLayer(). The standard Draw methods can be used to manipulate a single channel by drawing in the relevant channel, or all three channels can be modified simultaneously (by drawing in a color that effects more than one channel, for example drawing in white will effect all three channels.). To Draw in the Red channel only colors from 000000h to 0000FFh can be used (Color:Black to Color:Red). To draw in the Green Channels colors with zero Red and Blue components can be used, eg.: 00FA00h, 006600h and 006B00h. The same goes for the blue channel, e.g..: 0FF0000h, 0CB0000h and 0230000h.

Examples
Example
alphaLayer = 10                                                 ! choose the layer to use as an alpha layer
if drawer.LayerMode(layerNum, Draw:withAlpha) = 0               ! layer no alpha transparency
    drawer.AddAlpha(layerNum, alphaLayer, Channel:Red)          ! use the red channel in alphaLayer
end

AlphaCopy

AlphaCopy (long src, long srcx, long srcy, long srcWidth, long srcHeight, long dest, long destx, long desty),long

Description

Internal Draw method. This method is called from CopyLayer to handle alpha blending when copying. This method should not be called directly, as all the functionality is encapsulated by CopyLayer.

CopyLayer

CopyLayer (long src, long srcX, long srcY, long srcWidth, long srcHeight, long dest, long destX, long destY)

Description

Copies a block of pixels from one layer to another. The block of pixels that is copied starts at the point (srcX, srcY) and the width and height are determined by the srcWidth and srcHeight parameters. The block is copied to the destination layer with the top left hand corner at the position (destX, destY). The method automatically handles clipping in both the source and destination layers. Automatically uses the index transparency and alpha settings of the layers. If a layer has index and alpha transparency, the index transparency is applied, and the alpha values are used for all pixels that are not the index color.

Parameters
Parameter Description
srcThe layer number of the source layer.
srcXThe x-coordinate on the source layer of the top left hand corner of the block of pixels to copy
srcYThe y-coordinate on the source layer of the top left hand corner of the block of pixels to copy
srcWidthThe width of the block of pixels to copy from the source layer
srcHeightThe height of the block of pixels to copy from the source layer
destThe layer number of the destination layer
destXThe x-coordinate to copy the block of pixels to
destYThe y-coordinate to copy the block of pixels to
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Remarks

If the source layer displayMode contains Draw:indexTransparency the index color is used, pixels that are the index color will not be copied into the destination buffer. Use IndexTransparency() to set the index color as well as turning index transparency on or off for the layer, or call SetMode() to turn index transparency on or off without modifying the layer's index color. To enable the use of an alpha channel call AddAlpha().

Examples
Example
! copy all the data in fromLayer to toLayer:
drawer.copyLayer(fromLayer, 1, 1, drawer.layers[fromLayer].width, drawer.layers[fromLayer].height, toLayer, 1, 1)

! clipping is handled automatically, so only the data that fits onto the destination layer is copied.

HideLayer

HideLayer (long layerNumber)

Description

Sets a layer to hidden.

Parameters
Parameter Description
layerNumberThe number of the layer to set to hidden.
Return Values

No return value. If the method fails it calls ErrorTrap() with an error description.

Information

Whether a layer is used when Display() is called is determined by the layer's visibility. If the layer's displayMode contains Draw:Hidden the layer is ignored, otherwise it is composited ("flattened") with the rest of the layers when Display() is called. Use HideLayer() to hide a layer and ShowLayer() to unhide it. Hidden layers are useful as off screen buffers, temporary pixel storage areas and alpha layers. Alpha layers are normally hidden, as you don't normally want to display the pixel data they store directly.

Example
Example
    if drawer.LayerMode(layerNum, Draw:indexTransparency + Draw:withAlpha)   ! layer has index and alpha transparency
        drawer.HideLayer(layerNum)                                           
! hide the layer
    
end

InitLayer

InitLayer (long layerNumber, long width, long height, long xpos=1, long ypos=1, long indexColor=-1, byte mode=0), long

Description

Initialise a new layer. The numLayers property is incremented and the new layer is added at the first available entry in the Draw.layers array. The layer is added as the last entry in the Draw.displayOrder array, so it is below all the other layers in the display order. Call MoveLayer() or SwapLayer() to change the display order.

Parameters
Parameter Description
layerNumberThe number of the layer to initialize. If an existing layer is specified, the layer is blanked, resized and the layer variable set to the values passed.
widthThe layer width in pixels
heightThe layer height in pixels
xposThe x-coordinate of the top left hand corner of the layer. This is used when displaying layer to determine where the layer is place in relation to the base layer.
yposThe y-coordinate of the top left hand corner of the layer.
indexColorThe index color of the layer, optional
modeThe displayMode of the layer. Can be a combination of: Draw:hidden, Draw:withAlpha and Draw:indexTransparency. To specify multiple option simply add them together, for example: Draw:withAlpha + Draw:indexTransparency. See the SetMode() method for a more detailed description of the layer display mode.
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.
Information

When a new layer is initialized the buffer is created, using the width and height parameters, and the layer variables are populated. Calling InitLayer() on an existing layer will dispose the old buffer an create a new buffer.

Example
Example
    if drawer.layers[curLayer].init = 0                   ! check whether curLayer has been initialised
        drawer.InitLayer(curLayer)                         ! create the new layer
    end

IndexTransparency

IndexTransparency (long layerNumber, long indexColor, byte useIndex=1)

Description

Set the color that should be treated as transparent for a particular layer, you can use SetMode() to specify whether index transparency is used or not without modifying the index color.

Parameters
Parameter Description
layerNumberThe number of the layer to set the index color for. Valid values are from two to Draw:numLayers. Layers[1] is the background layer and cannot use index transparency. If you pass the number of a layer that has not been initialized the Method will call ErrorTrap() and return 0.
indexColorThe color that should be treated as transparent. Valid values are 0 to 0FFFFFFh (Color:black to Color:white). values outside this range will be ignored.
useIndexAllows you to set the layer's displayMode. Setting useIndex to zero will turn off index transparency, setting it to 1 will turn it on.
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Information

The useIndex parameter is optional and allows you to set an index color for future use, without currently enabling index transparency. If you don't explicitly specify a value it defaults to enabling index transparency for the layer.

Example
Example
    if drawer.LayerMode(Draw:indexTransparency) = 0            ! layer does not have index transparency
        drawer.IndexTransparency(layerNum,
color:black, 1)     ! all black pixels will be treated as transparent
    
end

HasAlpha

HasAlpha (long layerNumber)

Description

Returns the alpha layer number if the layer passed has an alpha layer assigned to it, returns zero if it does not.

Parameters
Parameter Description
layerNumberThe number of the layer in the Draw.layers[] array to check for an associated alpha layer.

Return Values

Returns the number of the alpha layer if the layer passed has an alpha layer assigned to it, returns zero if it does not.

Note: This changed in build 3.44. Prior to build 3.44 it returned 1 if an alpha layer existed.

KillLayer

KillLayer (long layerNumber), long

Description

Kill a layer and deallocate the memory that was used by the layer. This does not kill any associated alpha channels. When Draw.Kill() is called it automatically calls KillLayer() to destroy all existing layers, so it is not necessary to do this manually.

Parameters
Parameter Description
layerNumberThe number of the layer to destroy.
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Example
Example
    if drawer.layers[2].init            ! layer 2 is initialised
        
if drawer.KillLayer(2) = 0      ! all black pixels will be treated as transparent
            ! error handling - the KillLayer() method failed
        end

    end

LayerMode

LayerMode (long layerNumber, byte mode)

Description

Returns 1 if the mode is enabled for the layer specified, and zero if the mode is disabled.

Parameters
Parameter Description
layerNumberThe number of the layer to query the display mode for.
modeThe mode, or combination of modes to query.
Return Values

Returns 1 is the layer has the mode enabled, and zero if it is disabled.

Example
Example
    if drawer.LayerMode(layerNum, Draw:indexTransparency + Draw:withAlpha)   ! layer has index and alpha transparency
        drawer.ShowLayer(layerNum)                                           
! make sure the layer is visible
    
elsif drawer.LayerMode(layerMode, Draw:indexTransparency)                ! only index transparency
        drawer.AddAlpha(layerNum, alphaLayer, Channel:Red)                   
! add an alpha channel
    
else
        drawer.HideLayer(layerNum)                                           
! hide the layer
    
end

MoveLayer

MoveLayer (long layerNumber, long newPos), long

Description

Changes the display order of a layer. Effectively this moves a layer up or down in the "stack" of layers.

Parameters
Parameter Description
layerNumberThe number of the layer to move
newPosThe position in the array to move the layer to. The other entries are shifted to make space.
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Information

The layer display order and the order in which the layers are stored in the layers array is not related. The order in the layers array in maintained by Draw and should not be changed, as layers can depend on one another. The order in which the layers composited for display is determined by the order of the layerOrder array. You can change the position of a layer by calling the MoveLayer() to move a specific layer to a specific position, or call SwapLayers() to swap the position of a pair of layers. The layerOrder array is a property of the Draw class, it is an array of longs that stores the layer numbers in the order that they should be displayed. Its size is determined by the Draw:numLayers equate found in the Draw.inc file.

Example
Example
 drawer.MoveLayer(layerNum, layerNum + 1)          ! move the layer up one in the display order  

NumLayers

NumLayers ( ), long

Description

Returns the number of initialized layers. You can also use drawer.numLayers property of the Draw object directly.

Return Values

The number of initialized layers.

Information

The NumLayers() method loops through the layers array and retrieves the number of layers which have been initialized. In addition to the NumLayers() method the Draw class has a numLayers property which stores the current number of initialized layers and is incremented and decremented by InitLayer() and KillLayer().

ResizeLayer

ResizeLayer (long layerNumber, long width, long height), long

Description

Resize a layer. ResizeLayer() resizes the layer buffer, while preserving the data in the buffer, it also recalculates the layer properties, such as the bufferSize and zeroPad.

Parameters
Parameter Description
layerNumberThe number of the layer to resize
widthThe new layer width in pixels
heightThe new layer height in pixels
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Information

Each layer is completely independent, so they can be any size that is convenient. The Resize() method will perform the same task, using the currently active layer (see Withlayer()). ResizeLayer() allows you to resize any layer without having to make it active first. If you increase the resolution of the primary layer it is advisable to increase the resolution of other layers that you will be using. See Drawing on Reports and Resize() for more information on resizing and resolution.

SetMode

SetMode (long layerNumber, byte mode, byte value), long

Description

SetMode allows you to change the layer's displayMode. The displayMode is made up of a combination of Draw:Hidden, Draw:withAlpha and Draw:indexTransparency. To turn any of the display options on or off for a layer call SetMode with the layer number, the displayMode option and set the value parameter to true or false, depending on whether you would like to turn the mode on or off.

Parameters
Parameter Description
layerNumberThe number of the layer that the displayMode should be set for.
modeThe mode to set. valid value are: Draw:Hidden, Draw:withAlpha and Draw:indexTransparency
valueIf this is set to true the mode will be enable, if it is false it will be disabled.
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Information

SetMode() allows you to temporarily turn display features on and off without altering the layer itself. Note that Draw:withAlpha can only be set to true if AddAlpha() has been called, similarly Draw:indexTransparency can only be set to true if indexTransparency() has been called. SetMode can be used to set whether the layer is hidden or not, or you can simply call ShowLayer() and HideLayer().

Example
Example
Drawer.AddAlpha(pLayer, alphaLayer, Channel:Red)         ! Add an alpha channel
Drawer.SetMode(pLayer, Draw:withAlpha,
false)            ! Don't use the alpha channel when displaying
Drawer.IndexTransparency(pLayer,
Color:Black)            ! Add an index transparency color

Drawer.HideLayer(pLayer)                                 ! Hide the layer
Drawer.Display()                                         
! Display all visible layers,
                                                         
! pLayer is hidden and won't be displayed
Drawer.SetMode(pLayer, Draw:indexTransparency,
false)    ! Turn index Transparency off for pLayer
Drawer.ShowLayer(pLayer)                                 
! Unhide pLayer
Drawer.Display()                                         
! Display all visible layers,
                                                         
! this time pLayer is visible and will be displayed.
Drawer.SetMode(pLayer, Draw:withAlpha, true)             ! Use the layer alpha channel
Drawer.Display()                                         ! Display all visible layers, including pLayer,
                                                         ! and use pLayer's alpha channel.

ShowLayer

ShowLayer (long layerNumber)

Description

Sets the layer to visible.

Parameters
Parameter Description
layerNumberThe number of the layer to set to visible
Return Values

No return value. If the method fails it calls ErrorTrap() with an error description.

Information

Whether a layer is used when Display() is called is determined by the layers visibility. If the layer's displayMode contains Draw:Hidden the layer is ignored, otherwise it is composited ("flattened") with the rest of the layers when Display() is called. Use HideLayer() to hide a layer and ShowLayer() to unhide it. Hidden layers are useful as off screen buffers, temporary pixel storage areas and alpha layers. Alpha layers are hidden by default, as you don't normally want to display the pixel data they store directly.

SwapLayers

SwapLayers (long layer1, long layer2)

Description

Swap the display order of two layers.

Parameters
Parameter Description
layer1The layer to swap with layer2
layer2The layer to swap with layer1

Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Information

The layer display order and the order in which the layers are stored in the layers array is not related. The order in the layers array in maintained by Draw and should not be changed, as layers can depend on one another. The order in which the layers composited for display is determined by the order of the layerOrder array. You can change the position of a layer by calling the MoveLayer() to move a specific layer to a specific position, or call SwapLayers() to swap the position of a pair of layers. The layerOrder array is a property of the Draw class, it is an array of longs that stores the layer numbers in the order that they should be displayed. Its size is determined by the Draw:numLayers equate found in the Draw.inc file.

ToAlpha

ToAlpha (long srcLayer, long destLayer, byte channel)

Description

This copies a single channel from a source to a destination layer.

Parameters
Parameter Description
srclayerThe layer to copy the data from (the source layer).
destLayerThe layer to copy the data to (the destination layer).
channelWhich of the RGB components should be copied, valid values are: Channel:Red, Channel:Green or Channel:Blue.
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Information

Typically ToAlpha() is used for creating of modifying alpha channels. The channel to be copied can be specified by setting the channel parameter to Channel:Red, Channel:Green or Channel:Blue. This means three alpha channels can be stored in a single layer, one in each of the RGB components, and all three can be drawn to by simultaneously with the normal draw commands, after calling WithLayer() to set the alpha layer as the currently active layer for drawing to. See AddAlpha for more information on alpha channels.

The effect of ToAlpha() is similar to CopyLayer(), except that it only copies the RGB component specified, rather than all three RGB components. Unlike CopyLayer() ToAlpha ignores any index transparency.
You can also get an alpha channel stored in a standard RGB bitmap using the Image() method, or store an alpha channel in a bitmap by calling WriteBMP() with the alpha channel as the active layer (call Withlayer() to make a layer the current active layer).
Any standard 24 bit RGB bitmap can stored 3 alpha channels (one in each channel in the bitmap: Red, Green and Blue), this also applies to any Draw layer, which stores RGB information. To get the alpha channel from a bitmap simply make the alpha layer active by calling Withlayer() and the use the Image() method to draw the alpha values onto the layer. You can also use the Image() method to draw the bitmap onto a temporary layer and just copy the desired alpha channel onto the alpha layer by calling ToAlpha().

WithLayer

WithLayer (ulong layerNumber)

Description

Selects a layer to draw to.

Parameters
Parameter Description
layerNumberSet the active layer for drawing to.
Return Values

Returns 1 for success and zero for failure. If the method fails it calls ErrorTrap() with an error description.

Information

When a layer is made active by calling WithLayer(), all Draw commands are performed on that layer, with the exception of Display(). Display() will always display all non hidden layers. If you wish to display a single layer simply set all other layers to hidden (call SetMode()).

If layerNumber specifies an invalid layer the currently active layer is not changed and the method returns zero. Initially the default layer of draw (Draw.layers[1]) is active, so regardless of how many layers you create using InitLayer(), you only need to call WithLayer() when you want to change the active layer.

Draw Properties for Layers

These are the Draw class properties that are useful when working with layers. You can access all these properties directly (they are not private and so you don't need accessor method). Unless otherwise stated you should avoid modifying the properties directly.

activeLayer

activeLayer

Description

The currently active Draw layer, this is set by the WithLayer method and is useful for calling method that need to be applied to the currently layer. To set the current active layer call Draw.WithLayer(). This property should be treated as read only.

Example
Example
    drawer.SetMode(drawer.activelayer, Draw:withAlpha, false)        ! Turn off the use of an alpha channel for the current layer
    drawer.HideLayer(drawer.activeLayer)                             ! Hide the current layer
See Also

SetMode( )

baseLayer

baseLayer

This is the layer onto which Draw composites all the layers together when Draw.Display() is called. The baseLayer is always the same size as the image control, so it is often useful to refer to its properties. The baseLayer should be treated as read only.

Examples
Example
! Create a new layer the same size as the base layer, with black as the index transparency color
! and the displayMode set to draw:indexTransparency


drawer.InitLayer(drawer.numLayers + 1, drawer.baseLayer.width, drawer.baseLayer.height, 1, 1, |
                 
color:black, draw:indexTransparency) 
See Also

numLayers, SetMode( )

numLayers

numLayers

Description

The number of initialized layers for the current Draw object. This property should be treated as read only. Don't confuse this with the Draw:numLayers equate, which is the maximum number of layers supported by the Draw Object, this is the number of layers that

Examples
Example
! Initialise a new layer with the same width and height as the base layer, positioned at (1,1)
! and using black as the transparency index color.


if drawer.InitLayer(drawer.numlayers + 1, drawer.baseLayer.width, drawer.baseLayer.height, |
                    1, 1,
color:black, draw:indexTransparency)
    
! Initialisation successful, drawer.numLayers will have been incremented
else
    
! Layer initialisation failed, Draw.ErrorTrap() was called, handle error.
end
See Also

numLayers, SetMode( )