Qt API | Qtopia API | Qtopia Documentation |

# QGfxRasterBase Class Reference

This class is the base class of the QGfxRaster<depth> template and contains the non-depth-dependent code. The QGfxRaster class is used for drawing in software on raw framebuffers of varying depths and is subclassed by hardware drivers. It handles clipping and a movable origin in order to support subwindows. It is available only in Qt/Embedded. QWidget and QPixmap both return a QGfxRaster via their respective graphicsContext() methods, already initialised with the appropriate origin, framebuffer and clip region. QGfxRasterBase and its template subclasses should effectively be considered as one class; a raw QGfxRasterBase is never used, it's simply a handy place to put some of the functionality. More...

`#include <qgfxraster_qws.h>`

List of all member functions.

## Public Members

- QGfxRasterBase ( unsigned char * b, int w, int h )
- ~QGfxRasterBase ()
- virtual void setPen ( const QPen & p )
- virtual void setFont ( const QFont & f )
- virtual void setBrushPixmap ( const QPixmap * p )
- virtual void setBrushOffset ( int x, int y )
- virtual void setBrush ( const QBrush & b )
- virtual void setClipRect ( int x, int y, int w, int h )
- virtual void setClipRegion ( const QRegion & r )
- virtual void setClipDeviceRegion ( const QRegion & )
- virtual void setClipping ( bool b )
- virtual void setOffset ( int x, int y )
- virtual void setWidgetRect ( int x, int y, int w, int h )
- virtual void setWidgetRegion ( const QRegion & r )
- virtual void setWidgetDeviceRegion ( const QRegion & )
- virtual void setGlobalRegionIndex ( int idx )
- virtual void setDashedLines ( bool d )
- virtual void setDashes ( char * dashList, int n )
- virtual void moveTo ( int x, int y )
- virtual void lineTo ( int x, int y )
- virtual void setOpaqueBackground ( bool b )
- virtual void setBackgroundColor ( QColor c )
- virtual void setAlphaType ( AlphaType a )
- virtual void setAlphaSource ( unsigned char * b, int l )
- virtual void setAlphaSource ( int, int = -1, int = -1, int = -1 )
- virtual void drawText ( int x, int y, const QString & s )
- virtual void sync ()
- virtual void setLineStep ( int i )
- int linestep () const
- int pixelWidth () const
- int pixelHeight () const
- virtual int bitDepth () = 0
- virtual void save ()
- virtual void restore ()
- virtual void setRop ( RasterOp r )
- virtual void setClut ( QRgb * cols, int numcols )

## Protected Members

- void * beginTransaction ( const QRect & )
- void endTransaction ( void * )
- void beginDraw ()
- void endDraw ()
- void fixClip ()
- void update_clip ()
- bool inClip ( int x, int y, QRect * cr = 0, bool known_to_be_outside = FALSE )
- virtual void setSourceWidgetOffset ( int x, int y )
- void useBrush ()
- void usePen ()
- virtual void setSourcePen ()
- unsigned char * scanLine ( int i )
- unsigned char * srcScanLine ( int i )
- unsigned int get_value_32 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )
- unsigned int get_value_24 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )
- unsigned int get_value_16 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )
- unsigned int get_value_15 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )
- unsigned int get_value_8 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )
- unsigned int get_value_4 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )
- unsigned int get_value_1 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )

## Detailed Description

This class is the base class of the QGfxRaster<depth> template and contains the non-depth-dependent code. The QGfxRaster class is used for drawing in software on raw framebuffers of varying depths and is subclassed by hardware drivers. It handles clipping and a movable origin in order to support subwindows. It is available only in Qt/Embedded. QWidget and QPixmap both return a QGfxRaster via their respective graphicsContext() methods, already initialised with the appropriate origin, framebuffer and clip region. QGfxRasterBase and its template subclasses should effectively be considered as one class; a raw QGfxRasterBase is never used, it's simply a handy place to put some of the functionality.

## Member Function Documentation

### QGfxRasterBase::QGfxRasterBase ( unsigned char * b, int w, int h )

This constructed a QGfxRasterBase. b is the data buffer pointed to, w and h its width and height in pixels

### QGfxRasterBase::~QGfxRasterBase ()

Destroys a QGfxRaster

### void QGfxRasterBase::drawText ( int x, int y, const QString & s )`[virtual]`

Draws a line of Unicode text using the font set by QFont. It performs a series of blt's using a pen source in the current pen colour and either an 8-bit alpha channel (for anti-aliased text) or a big-endian mask provided by the font subsystem.

### unsigned int QGfxRasterBase::get_value_1 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )`[protected]`

This is similar to get_value_8, but returns 1-bit values. The number of depths that can be blt'd to a monochrome destination are limited - only monochrome or 32-bit sources are permitted.

### unsigned int QGfxRasterBase::get_value_16 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )`[protected]`

This is similar to get_value_32, but returns 16-bit values

### unsigned int QGfxRasterBase::get_value_24 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )`[protected]`

This is similar to get_value_32, but returns packed 24-bit values

### unsigned int QGfxRasterBase::get_value_32 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )`[protected]`

This converts a pixel in an arbitrary source depth (specified by sdepth, stored at *(*srcdata) to a 32 bit value; it's used by blt() where the source depth is less than 32 bits and the destination depth is 32 bits. *srcdata (the pointer to the data) is auto-incremented by the appropriate number of bytes, or decremented if reverse is true. If the source has a pixel size of less than a byte then auto-incrementing or decrementing will happen as necessary; the current position within the byte is stored in monobitcount (bit within the byte) and monobitval (value of the current byte). In the case of 8-bit source data lookups on the source's colour table are performed.

### unsigned int QGfxRasterBase::get_value_4 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )`[protected]`

This is similar to get_value_8, but returns 4-bit values.

### unsigned int QGfxRasterBase::get_value_8 ( int sdepth, unsigned char ** srcdata, bool reverse = FALSE )`[protected]`

This is similar to get_value_32, but returns 8-bit values. Translation between different colour palettes and from 32/24/16 bit data to the nearest match in the destination's colour palette is performed.

### bool QGfxRasterBase::inClip ( int x, int y, QRect * cr = 0, bool known_to_be_outside = FALSE )`[protected]`

Returns whether the point (x, y) is in the clip region.

If cr is not null, <t>*cr</t> is set to a rectangle containing the point, and within all of which the result does not change. If the result is TRUE, cr is the widest rectangle for which the result remains TRUE (so any point immediately to the left or right of cr will not be part of the clip region).

Passing TRUE for the known_to_be_outside allows optimizations, but the results are not defined it (x, y) is in the clip region.

Using this, you can efficiently iterator over the clip region using:

        bool inside = inClip(x,y,&cr);
        while (change y, preferably by +1) {
            while (change x by +1 or -1) {
                if ( !cr.contains(x,y) )
                    inside = inClip(x,y,&cr,inside);
                if ( inside ) {
                    draw stuff
                }
            }
        }

### void QGfxRasterBase::lineTo ( int x, int y )`[virtual]`

This draws a line from the last values passed to moveTo to the values passed to lineTo. It calls drawLine so there is no need to reimplement it in an accelerated driver.

### void QGfxRasterBase::moveTo ( int x, int y )`[virtual]`

This is the counterpart to QPainter::moveTo. It simply stores the x and y values passed to it until a lineTo.

### void QGfxRasterBase::restore ()`[virtual]`

Restores the brush and pen from a previous save().

### void QGfxRasterBase::save ()`[virtual]`

This saves the current brush and pen state to temporary variables. This is used internally in QGfxRaster when a temporary pen or brush is needed for something. This is not a stack; a save() followed by a save() will obliterate the previously saved brush and pen.

### void QGfxRasterBase::setAlphaSource ( unsigned char * b, int l )`[virtual]`

This is used in conjunction with LittleEndianMask,BigEndianMask or SeparateAlpha alpha channels. b is a pointer to the bytes containing the alpha values, l is the linestep (length in bytes per horizontal line of data)

### void QGfxRasterBase::setAlphaType ( AlphaType a )`[virtual]`

This sets one of several alpha channel types for the next blt operation:

IgnoreAlpha: Always draw source pixels as-is InlineAlpha: An 8-bit alpha value is in the highest byte of the (32-bit) source data SeparateAlpha: A separate 8-bit alpha channel buffer is provided (used for anti-aliased text) LittleEndianMask: A separate little-bit-endian mask is provided BigEndianMask: A separate big-bit-endian mask is provided SolidAlpha: A single 8-bit alpha channel value is to be applied to all pixels

The alpha channel buffer/value is provided by setAlphaSource

### void QGfxRasterBase::setBrush ( const QBrush & b )`[virtual]`

This corresponds to QPainter::setBrush.

### void QGfxRasterBase::setBrushOffset ( int x, int y )`[virtual]`

This sets the offset of a pattern when drawing with a patterned brush - needed when clipping means the start position for drawing doesn't correspond with the start position requested by QPainter, for example.

### void QGfxRasterBase::setClipRect ( int x, int y, int w, int h )`[virtual]`

This is a simplified case of setClipRegion, setting a clip region consisting of one rectangle.

### void QGfxRasterBase::setClipRegion ( const QRegion & r )`[virtual]`

This sets the clipping region for the QGfx. All drawing outside of the region is not displayed. The clip region is defined relative to the QGfx's origin at the time the clip region is set, and consists of an array of rectangles stored in the array cliprect. Note that changing the origin after the clip region is set will not change the position of the clip region within the buffer. Hardware drivers should use this to set their clipping scissors when drawing. Note also that this is the user clip region as set by QPainter; it is combined (via an intersection) with the widget clip region to provide the actual clipping region.

### void QGfxRasterBase::setClipping ( bool b )`[virtual]`

Defines whether to clip or not. If clipping is not enabled then drawing will access the whole buffer. This will be reflected in the cliprect array, which will consist of one rectangle of buffer width and height. The variable regionClip defines whether to clip or not.

### void QGfxRasterBase::setDashedLines ( bool d )`[virtual]`

This defines whether the gfx should draw with dashed or solid lines. It's called by setPen so there is no need to call it directly.

### void QGfxRasterBase::setDashes ( char * dashList, int n )`[virtual]`

This defines the pattern for dashed lines. It's called by setPen so there is no need to call it directly.

### void QGfxRasterBase::setFont ( const QFont & f )`[virtual]`

This corresponds to QPainter::setFont and defines what font drawText() will use.

### void QGfxRasterBase::setOffset ( int x, int y )`[virtual]`

This defines the origin of the gfx. For instance, if the origin is set to 100,100 and a line is then drawn from 0,0 to 10,10 the line will be (relative to the top left of the buffer) from 100,100 to 110,110. This is used to support windows within the buffer.

### void QGfxRasterBase::setPen ( const QPen & p )`[virtual]`

This corresponds to QPainter::setPen - it tells QGfxRaster what line colour and style to use.

### void QGfxRasterBase::setSourcePen ()`[virtual protected]`

This tells blt()s that instead of image data a single solid value should be used as the source, taken from the current pen color. You could reproduce a fillRect() using a pen source and the IgnoreAlpha alpha type, but this would be both pointless and slower than fillRect; its normal use is for anti-aliased text, where the text colour is that of the pen and a separate alpha channel produces the shape of the glyphs.

### void QGfxRasterBase::setSourceWidgetOffset ( int x, int y )`[virtual protected]`

This stores the offset from the screen framebuffer of the widget from which a blt() is being performed - this is added to the source x and y coordinates from a bitBlt to produce the source screen position of the blt

### void QGfxRasterBase::setWidgetRect ( int x, int y, int w, int h )`[virtual]`

This is a special case of setWidgetRegion for widgets which are not shaped and not occluded by any other widgets.

### void QGfxRasterBase::setWidgetRegion ( const QRegion & r )`[virtual]`

This sets the widget's region clip, which is combined with the user clip to determine the widget's drawable region onscreen. It's a combination of the widget's shape (if it's a shaped widget) and the area not obscured by windows on top of it.

### void QGfxRasterBase::sync ()`[virtual]`

This does very little in a purely-software QGfxRasterBase (simply records that the last operation was a software one). Hardware drivers should reimplement this to wait for graphics engine idle in order to allow software and hardware drawing to synchronize properly.

### void QGfxRasterBase::update_clip ()`[protected]`

This combines the currently set widget and user clips and caches the result in an array of QRects, cliprect, the size of which is stored in ncliprect. It's called whenever the widget or user clips are changed.

### void QGfxRasterBase::useBrush ()`[protected]`

This takes the currently-set brush and stores its color value in the variable pixel for drawing points, lines and rectangles.

### void QGfxRasterBase::usePen ()`[protected]`

This takes the currently-set pen and stores its color value in the variable pixel for drawing points, lines and rectangles.

This file is part of the Qtopia , copyright © 1995-2002 Trolltech, all rights reserved.