(Up to LGI Documentation)

GdcBasePrimitives

This class is the API for drawing on something. That something may be the screen or it could be a bitmap in memory.

You never directly allocate an object of this type, but you may want to derive an object from this class. It would allow you to be "painted on" by other objects.

The most useful objects that are derived from this object are GdcMemDC that defines a bitmap in memory and GdcGdiScreen or GdcViewDC (Win32 and BeOS respectively) screen DC's.


class GdcBasePrimitives
{
public:
    // Blt
    virtual void Blt(int x, int y, GdcBasePrimitives *Src, GdcRegion *a = NULL)
    virtual void StretchBlt(GdcRegion *d, GdcBasePrimitives *Src, GdcRegion *s)

    // Curve
    virtual void Arc(double cx, double cy, double radius, double start, double end)
    virtual void Circle(double cx, double cy, double radius)
    virtual void Ellipse(double cx, double cy, double x, double y)
    virtual void FilledArc(double cx, double cy, double radius, double start, double end)
    virtual void FilledCircle(double cx, double cy, double radius)
    virtual void FilledEllipse(double cx, double cy, double x, double y)

    // Line
    virtual uint LineStyle(uint Bits)
    virtual uint LineStyle()
    virtual void HLine(int x1, int x2, int y)
    virtual void Line(int x1, int y1, int x2, int y2)
    virtual void VLine(int x, int y1, int y2)

    // Other
    virtual void Bezier(int Threshold, GdcPt2 *Pt)
    virtual void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GdcRegion *Bounds = NULL)
    virtual void Polygon(int Points, GdcPt2 *Data)
    virtual void Text(GdcFont *pFont, int x, int y, char *Str, int Len)

    // Pixel
    virtual COLOUR Get(int x, int y)
    virtual void Set(int x, int y)

    // Properties
    virtual bool IsScreen()
    virtual COLOUR Colour()
    virtual GdcPalette *Palette()
    virtual GdcRegion ClipRgn()
    virtual GdcRegion ClipRgn(GdcRegion *Rgn)
    virtual int GetBits()
    virtual int Op()
    virtual int X()
    virtual int Y()
    virtual uchar *operator[](int y)
    virtual void Colour(COLOUR c, int Bits = 0)
    virtual void GetOrigin(int &x, int &y)
    virtual void Op(int Op)
    virtual void Palette(GdcPalette *pPal, bool bOwnIt = TRUE)
    virtual void SetOrigin(int x, int y)

    // Rectangular
    virtual void Box(int x1, int y1, int x2, int y2)
    virtual void Box(GdcRegion *a = NULL)
    virtual void Rectangle(int x1, int y1, int x2, int y2)
    virtual void Rectangle(GdcRegion *a = NULL)
    // Win32
    HBITMAP GetBitmap()
    HDC Handle()
    virtual HDC StartDC()
    virtual void EndDC()
    // BeOS
    BBitmap *GetBitmap();()
    BView *Handle()
  };

GdcBasePrimitives::Blt

virtual void Blt(int x, int y, GdcBasePrimitives *Src, GdcRegion *a = NULL)

Argument Description
int x x location of the destination
int y y location of the destination
GdcBasePrimitives *Src Source device.
GdcRegion *a = NULL Area in source device to copy from, if not specified or NULL then the whole source device is assumed.

This function copies some or all the the source bitmap to this device. Colour depth conversion will be used if necessary.


GdcBasePrimitives::StretchBlt

virtual void StretchBlt(GdcRegion *d, GdcBasePrimitives *Src, GdcRegion *s)

Argument Description
GdcRegion *d Destination region
GdcBasePrimitives *Src Source device
GdcRegion *s Source region

Copies a bitmap from Src to this device, including scaling.


GdcBasePrimitives::Arc

virtual void Arc(double cx, double cy, double radius, double start, double end)

Argument Description
double cx, double cy Center of the arc.
double radius Radius of the arc.
double start, double end Start and end angles of the arc.

These are specified in degrees. Clockwise around the circle. With 0 at the top.

Draws part of a circle.


GdcBasePrimitives::Circle

virtual void Circle(double cx, double cy, double radius)

Argument Description
double cx, double cy Center of the circle
double radius Radius of the circle

Draws an unfilled circle centered around cx, cy with a radius.


GdcBasePrimitives::Ellipse

virtual void Ellipse(double cx, double cy, double x, double y)

Argument Description
double cx, double cy Center of the ellipse
double x, double y Length of the x and y axis. Specified as the distance from the center to the edge.

Draws a unfilled ellipse.


GdcBasePrimitives::FilledArc

virtual void FilledArc(double cx, double cy, double radius, double start, double end)

Argument Description
double cx, double cy Center of the arc
double radius Radius of the arc
double start, double end Start and end angles of the arc, specified in degrees starting from 0 at the top and progressing clockwise.

Draws a filled section of a circle. The filled section is calculated by joining the ends of the arc segment to the center of the arc.


GdcBasePrimitives::FilledCircle

virtual void FilledCircle(double cx, double cy, double radius)

Argument Description
double cx, double cy Center of the circle
double radius Radius of the circle

Draws an filled circle centered around cx, cy with a radius.


GdcBasePrimitives::FilledEllipse

virtual void FilledEllipse(double cx, double cy, double x, double y)

Argument Description
double cx, double cy The center of the ellipse
double x, double y The length of the x and y axis. From the center to the edge.

Draws a filled ellipse.


GdcBasePrimitives::LineStyle

virtual uint LineStyle(uint Bits)

Argument Description
uint Bits A bit pattern that says which pixels are drawn and which arn't.

Each bit in this integer is tested in sucession and used to decide what pixels in the line to switch on.

Sets the pixels on the line that are drawn.

Note: Win32 screen DC's don't support this functionality.


GdcBasePrimitives::LineStyle

virtual uint LineStyle()

Returns the current line style.


GdcBasePrimitives::HLine

virtual void HLine(int x1, int x2, int y)

Argument Description
int x1 Start x loc
int x2 End x loc
int y The y location of the line

Draws a horizontal line.


GdcBasePrimitives::Line

virtual void Line(int x1, int y1, int x2, int y2)

Argument Description
int x1, int y1 Start location of the line
int x2, int y2 End location of the line. The final pixel is drawn.

Draws a line between 2 points.


GdcBasePrimitives::VLine

virtual void VLine(int x, int y1, int y2)

Argument Description
int x
int y1
int y2

Draws a vertical line.


GdcBasePrimitives::Bezier

virtual void Bezier(int Threshold, GdcPt2 *Pt)

Argument Description
int Threshold Number of interations to "smooth" the line?
GdcPt2 *Pt Array of 3 points. Start, middle and end.

I've forgotten how this works. Sorry.


GdcBasePrimitives::FloodFill

virtual void FloodFill(int x, int y, int Mode, COLOUR Border = 0, GdcRegion *Bounds = NULL)

Argument Description
int x, int y Place to start fill from.
int Mode Unused.

Currently the fill takes the colour at x, y and fills all surrounding pixels of that colour to the current DC colour.

COLOUR Border = 0 Unused.

The colour of the border. For different fill rules.

GdcRegion *Bounds = NULL Returns the maximum boundry of filling. Really useful for screen update functions.

Flood fills the DC.


GdcBasePrimitives::Polygon

virtual void Polygon(int Points, GdcPt2 *Data)

Argument Description
int Points Number of points in the array.
GdcPt2 *Data Array of points.

Draws a polygon. Can be complex.


GdcBasePrimitives::Text

virtual void Text(GdcFont *pFont, int x, int y, char *Str, int Len)

Argument Description
GdcFont *pFont Font to draw text with.
int x, int y Top-left hand corner of text rectangle.
char *Str String to draw.
int Len Number of characters to draw, or -1. If -1 then the whole NULL terminated string is drawn. This parameter defaults to -1.

Draws some text on the DC.


GdcBasePrimitives::Get

virtual COLOUR Get(int x, int y)

Argument Description
int x X loc of pixel
int y Y loc of pixel

Returns the pixel at the location specified. This function may fail on devices that don't support GetPixel, in this case the function returns 0.


GdcBasePrimitives::Set

virtual void Set(int x, int y)

Argument Description
int x The x location of the pixel to set.
int y The y location of the pixel to set.

Sets a single pixel to the current colour.


GdcBasePrimitives::IsScreen

virtual bool IsScreen()

Returns true of the DC draws on the screen.


GdcBasePrimitives::Colour

virtual COLOUR Colour()

Gets the current drawing colour.


GdcBasePrimitives::Palette

virtual GdcPalette *Palette()

Returns the current palette. (Pointer is still owned by the DC, don't delete)


GdcBasePrimitives::ClipRgn

virtual GdcRegion ClipRgn()

Returns the current clipping region.


GdcBasePrimitives::ClipRgn

virtual GdcRegion ClipRgn(GdcRegion *Rgn)

Argument Description
GdcRegion *Rgn New clipping region.

Sets the Cliping region.

Returns:
The old clipping region.


GdcBasePrimitives::GetBits

virtual int GetBits()

Returns the bit depth of the DC.

Currently this also determines the colour space of the DC, because only one colour space is defined per bit depth. I know this is lame but it works reasonably well for me. One day there will be a colour space function as well. The colour spaces are defined in the gdc2.h header file. There are a bunch of accessor macros for the different colour spaces:


GdcBasePrimitives::Op

virtual int Op()

Returns the current operator to combine the source colour / data with the DC's bits.


GdcBasePrimitives::X

virtual int X()

Returns the width of the DC.


GdcBasePrimitives::Y

virtual int Y()

Returns the Height of the DC.


GdcBasePrimitives::operator[]

virtual uchar *operator[](int y)

Argument Description
int y Which scanline to return.

Returns the address of the specified scanline or NULL if not available or index out of range.


GdcBasePrimitives::Colour

virtual void Colour(COLOUR c, int Bits = 0)

Argument Description
COLOUR c Colour to set current colour to.
int Bits = 0 The bit depth of the colour you are passing in. If 0 then the depth is assumed to be equal to the DC's.

Sets the current drawing colour.


GdcBasePrimitives::GetOrigin

virtual void GetOrigin(int &x, int &y)

Argument Description
int &x, int &y

Get the origin of the DC.


GdcBasePrimitives::Op

virtual void Op(int Op)

Argument Description
int Op New operator. Can be one of:
  • GDC_SET
  • GDC_AND
  • GDC_OR
  • GDC_XOR
  • GDC_ALPHA
    To set the alpha level:
    GdcAppAlpha *pApp = (GdcAppAlpha*) pDC->Applicator();
    if (pApp)
    {
    	pApp->SetAlpha(AlphaLevel, pDC->Palette());
    }
    
  • GDC_REMAP

Sets the current operator to combine the source colour / data with the DC's bits.


GdcBasePrimitives::Palette

virtual void Palette(GdcPalette *pPal, bool bOwnIt = TRUE)

Argument Description
GdcPalette *pPal New palette.
bool bOwnIt = TRUE If true the DC takes responsibility to delete the palette object.

If false then the DC makes a copy of the palette object. And ownership of the palette doesn't change.

Sets the current palette.


GdcBasePrimitives::SetOrigin

virtual void SetOrigin(int x, int y)

Argument Description
int x, int y

Set the DC's origin.


GdcBasePrimitives::Box

virtual void Box(int x1, int y1, int x2, int y2)

Argument Description
int x1, int y1 The top-left corner of the rectangle
int x2, int y2 The bottom-right corner of the rectangle.

Note: Coordinates are literal, unlike windows where the bottom-right coordinates are one pixel furthur right and down than the actual drawn rectangle.

Draws the unfilled rectangle.


GdcBasePrimitives::Box

virtual void Box(GdcRegion *a = NULL)

Argument Description
GdcRegion *a = NULL The rectangle's coordinates.

If NULL then the rectangle will fill the entire device context.

Note: Coordinates are literal, unlike windows where the bottom-right coordinates are one pixel furthur right and down than the actual drawn rectangle.

Draws the unfilled rectangle.


GdcBasePrimitives::Rectangle

virtual void Rectangle(int x1, int y1, int x2, int y2)

Argument Description
int x1, int y1 The top-left corner of the rectangle
int x2, int y2 The bottom-right corner of the rectangle.

Note: Coordinates are literal, unlike windows where the bottom-right coordinates are one pixel furthur right and down than the actual drawn rectangle.

Draws a filled rectangle.


GdcBasePrimitives::Rectangle

virtual void Rectangle(GdcRegion *a = NULL)

Argument Description
GdcRegion *a = NULL The rectangle's coordinates.

If NULL then the rectangle will fill the entire device context.

Note: Coordinates are literal, unlike windows where the bottom-right coordinates are one pixel furthur right and down than the actual drawn rectangle.

Draws a filled rectangle.


GdcBasePrimitives::GetBitmap

(Platform: Win32)
HBITMAP GetBitmap()

Returns the handle of bitmap in memory. Only relevent for memory contexts.


GdcBasePrimitives::Handle

(Platform: Win32)
HDC Handle()

Returns the handle of the operating systems context, under windows this is a HDC.


GdcBasePrimitives::StartDC

(Platform: Win32)
virtual HDC StartDC()

This function allocates or returns a valid HDC under windows. This function needs to have a matching 'EndDC' call. ie:

HDC hDC = pDC->StartDC();
// do something with the DC
pDC->EndDC();

Returns:
A valid win32 device context.


GdcBasePrimitives::EndDC

(Platform: Win32)
virtual void EndDC()

Cleans up after a call to StartDC.


GdcBasePrimitives::GetBitmap();

(Platform: BeOS)
BBitmap *GetBitmap();()

Returns a pointer to the bitmap is the DC is a memory bitmap.


GdcBasePrimitives::Handle

(Platform: BeOS)
BView *Handle()

Returns the operating systems context. Under BeOS this is a pointer to a BView.


Built: 13/9/2001 2:28:32 PM
© 2001 Matthew Allen
Lgi HomePage