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)
Drawer.Image(15, 100, , ,'capesoft.bmp')
someLayer = 2
transparentColor = 3
Drawer.InitLayer(someLayer, self.width, self.height)
Drawer.IndexTransparency(someLayer,
transparentcolor, true)
Drawer.WithLayer(someLayer )
Drawer.Blank(transparentColor )
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)
Drawer.Image(15, 100, , ,'capesoft.bmp')
someLayer = 2
Drawer.InitLayer(someLayer, self.width, self.height)
Then an alpha layer is created and initialised.
alphaLayer = 3
Drawer.InitLayer(alphaLayer, self.width, self.height)
Drawer.HideLayer(alphaLayer)
Now the alpha layer is tied to the drawing layer.
Drawer.SetMode(someLayer,draw:withAlpha,true)
Drawer.AddAlpha(someLayer,AlphaLayer,Channel:Red)
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 )
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 )
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 )
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 |
name |
data type |
description |
bitmapData | &string | Pointer to the layer data. Assigned by InitLayer(). |
xpos | long | X Coordinate of the top left hand corner of the layer. |
ypos | long | Y Coordinate of the top left hand corner of the layer. |
width | long | Width, in pixels, of the layer. |
height | long | Height, in pixels, of the layer. |
alpha | &string | Pointer to an alpha layer. Assigned by AddAlpha(). |
alphaLayer | long | The number of the layer used as an alpha channel |
alphaChannel | byte | The channel to use for the alpha calculations. See AddAlpha(). |
indexColor | long | Color to use for index transparency. See
IndexTransparency(). |
zeroPad | byte | Set by InitLayer(). |
bufferSize | ulong | Set by InitLayer(), and
ResizeLayer(). |
displayMode | byte | The 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.AddAlpha | Add an alpha channel to a layer |
Draw.AlphaCopy | Handles alpha blending for CopyLayer. Do not call directly. |
Draw.CopyLayer | Copy a block of pixels from one layer to another. |
Draw.IndexTransparency | Set the index transparency of the layer. |
Draw.HasAlpha | Returns whether a layer has an alpha channel |
Draw.HideLayer | Set a layer to hidden. |
Draw.InitLayer |
Initialize a new layer |
Draw.KillLayer | Delete a layer. |
Draw.LayerMode | Return whether a layer has a display mode enabled or disabled. |
Draw.MoveLayer | Change a layer's display order. |
Draw.NumLayers | Return the number of
initialized layers. |
Draw.ResizeLayer | Resize a specific layer. |
Draw.SetMode | Set the display mode. |
Draw.Showlayer | Set a layer to be shown when Display() is called. |
Draw.SwapLayers | Swap two slayer's display order. |
Draw.ToAlpha | Copy one RGB channel from one layer to another. |
Draw.WithLayer | Activate 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.
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 |
layerNumber | The layer to add the alpha channel to (no extra
data is created, this is just a reference assignment). |
alphaLayer | The source layer to be used. Typically an extra (hidden)
layer would be created to be used as an alpha layer. |
channel | Which 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 if
drawer.LayerMode(layerNum, Draw:withAlpha) = 0 drawer.AddAlpha(layerNum, alphaLayer,
Channel:Red) 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 |
src | The layer number of the source layer. |
srcX | The x-coordinate on the source layer of the top left hand corner of the
block of pixels to copy |
srcY | The y-coordinate on the source layer of the top left hand corner of the
block of pixels to copy |
srcWidth | The width of the block of pixels to copy from the source layer |
srcHeight | The height of the block of pixels to copy from the source layer |
dest | The layer number of the destination layer |
destX | The x-coordinate to copy the block of pixels to |
destY | The 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 |
drawer.copyLayer(fromLayer,
1, 1, drawer.layers[fromLayer].width, drawer.layers[fromLayer].height, toLayer,
1, 1)
|
HideLayer
HideLayer (long layerNumber)
Description
Sets a layer to hidden.
Parameters
Parameter |
Description |
layerNumber | The 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)
drawer.HideLayer(layerNum)
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 |
layerNumber | The 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. |
width | The layer width in pixels |
height | The layer height in pixels |
xpos | The 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. |
ypos | The y-coordinate of the top left hand corner of the layer. |
indexColor | The index color of the layer, optional |
mode | The 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
drawer.InitLayer(curLayer)
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 |
layerNumber | The 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. |
indexColor | The 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. |
useIndex | Allows 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
drawer.IndexTransparency(layerNum,
color:black, 1)
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 |
layerNumber | The 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 |
layerNumber | The 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
if
drawer.KillLayer(2) = 0
!
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 |
layerNumber | The number of the layer to query the display mode for. |
mode | The 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)
drawer.ShowLayer(layerNum)
elsif
drawer.LayerMode(layerMode,
Draw:indexTransparency)
drawer.AddAlpha(layerNum, alphaLayer,
Channel:Red)
else
drawer.HideLayer(layerNum)
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 |
layerNumber | The number of the layer to move |
newPos | The 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) |
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 |
layerNumber | The number of the layer to resize |
width | The new layer width in pixels |
height | The 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 |
layerNumber | The number of the layer that the displayMode should be set
for. |
mode | The mode to set. valid value are: Draw:Hidden, Draw:withAlpha and Draw:indexTransparency |
value | If 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)
Drawer.SetMode(pLayer, Draw:withAlpha,
false)
Drawer.IndexTransparency(pLayer,
Color:Black)
Drawer.HideLayer(pLayer)
Drawer.Display()
Drawer.SetMode(pLayer, Draw:indexTransparency, false)
Drawer.ShowLayer(pLayer)
Drawer.Display()
Drawer.SetMode(pLayer, Draw:withAlpha,
true)
Drawer.Display()
|
ShowLayer
ShowLayer (long layerNumber)
Description
Sets the layer to visible.
Parameters
Parameter |
Description |
layerNumber | The 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 |
layer1 | The layer to swap with layer2 |
layer2 | The 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 |
srclayer | The layer to copy the data from (the source layer). |
destLayer | The layer to copy the data to (the destination layer). |
channel | Which 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 |
layerNumber | Set 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.