Method XbpIcon():draw() Foundation
Displays an icon.
:draw( [<oTargetPS>] , ;
<aTargetRect> , ;
[<nState>] ) --> lSuccess
Constant | Description |
---|---|
XBP_STATE_NORMAL *) | Normal state; icon is drawn as saved on disk |
XBP_STATE_DISABLED | Icon is drawn shaded to indicate disabled state |
|
This method returns .T. (true) when the icon could be displayed, otherwise it returns .F. (false).
The :draw() method displays the an icon image in the specified presentation space. The area the image is displayed in can be set using the parameter <aTargetRect>. If the size of the area specified differs from the icon dimensions in members :xSize and :ySize, the icon is scaled.
Most icons use an internal mask to define transparent areas within the image. Method :draw() uses this information so that those areas are replaced with information from the underlying background.
Printing icons, using in segments: Printing icons is not supported under Windows. The same is true for rendering icons into graphical segments. If the presentation space in parameter <oTargetPS> is associated with an XbpPrinter object, or if a graphical segment is opened using function GraSegOpen(), method :draw() may produce undesired effects. Transparent areas in the icon may appear black, for example. A work-around for these limitation is suggested in the example below.
Example - 1
// Example for printing an icon
#include "GRA.CH"
#include "XBP.CH"
// Change this to reference an .ICO file
#define ICONFILE "c:\program files\alaska\xppw32\resource\icon\xppfd.ico"
PROCEDURE Main()
LOCAL oPS
LOCAL oIco
LOCAL oPrt
// Load an icon from disk
oIco := XbpIcon():New():Create()
oIco:LoadFile( ICONFILE )
// Create a presentation space and
// associate it with the default
// printer
oPrt := XbpPrinter():New():Create()
oPS := XbpPresSpace():New():Create( oPrt )
// Start a print job and send some
// graphics to the printer, including
// an icon
oPrt:StartDoc()
GraSetColor( oPS, GRA_CLR_PALEGRAY )
GraBox( oPS, {500,500}, {1700,1000}, GRA_FILL )
PrintIcon( oPS, {600,600,900,900}, oIco )
GraSetColor( oPS, GRA_CLR_BLACK )
GraSetFont( oPS, XbpFont():New():Create("36.Arial Black") )
GraStringAt( oPS, {1100,700}, "Test output on printer" )
oPrt:EndDoc()
WAIT "Printing done, please press a key."
RETURN
// Print an icon to the presentation space
// in "oPS", which is assumed to be associated
// with a printer object. To do this, the
// icon is transferred to a bitmap object,
// which is device-independent. Transparent
// areas in the icon are replaced with the
// color set for area fills currently set
// for the presentation space, see function
// GraSetAttrArea().
PROCEDURE PrintIcon( oPS, aRect, oIco )
LOCAL oBmpTmp
LOCAL oPSTmp
LOCAL aAttrs
IF Len(aRect) == 2
ASize( aRect, 4 )
aRect[3] := aRect[1] + oIco:XSize -1
aRect[4] := aRect[2] + oIco:XSize -1
ENDIF
// Create a presentation space associated
// with a temporary bitmap and transfer
// the icon into the PS. First clear the
// background using the color set for
// area fills.
oBmpTmp := XbpBitmap():New():Create( oPS )
oPSTmp := XbpPresSpace():New():Create()
oBmpTmp:PresSpace( oPSTmp )
oBmpTmp:Make( oIco:XSize, oIco:YSize )
aAttrs := GraSetAttrArea( oPS )
GraSetColor( oPSTmp, aAttrs[GRA_AA_COLOR] )
GraBox( oPSTmp, {0,0}, {oIco:XSize-1,oIco:YSize-1}, GRA_FILL )
oIco:Draw( oPSTmp, {0,0} )
// Transfer the temporary bitmap to the
// printer
oBmpTmp:Draw( oPS, aRect,,, GRA_BLT_BBO_IGNORE )
oPSTmp:Destroy()
oBmpTmp:Destroy()
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.