- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# Exponent::GUI::Graphics::CGraphics Class Reference

List of all members.

## Detailed Description

Graphics context - All drawing is actually done in this class.

Graphics encapsulates the drawing capabilities of the platform. Whilst every effort has been made to make sure that functions work identically on both mac and windows
there are some areas where they dont align exactly. Internally the graphics system maintains a seperate 'back buffer' to enable the double buffering drawing to take place.
All graphics draws are performed in to this back buffer, and then blitted in one operation to the main graphic context that the user can view.
Each graphics context holds pointers to both a pen and a brush that are used for the drawing operations. The pen is used to draw lines, the brush for drawing block areas of colour.
The graphics object also maintains both a clip area and a current offset. Because controls draw relative to their top left we need to maintain internally an offset that id added to all
drawing co-ordinates. This assumes that the top left of a window has coordinates 0,0 with the x and y increasing along their axis (so a window that is 800x600 would have a bottom right of...800,600)
The clipping area can be set to any area inside the total area of the graphics (as it is initialised with). However, not that this may mean that your drawing calls wont show up!
Finally it should be pointed out that generally you should be creating, destroying or altering a CGraphics object. This should be handled internally by any window that needs to do drawing.

See also:
  CBrush

  CPen

  CWindow

  CControl

  CControlRoot

  CClip

Date:
  01/10/2004

Author:
  Paul Chana

Version:
  1.0.0 Initial version

  1.0.1 Added drawFilledBorderedRectangle function

  1.0.2 Moved windows format to GDI+

  1.0.3 Made text colour alpha based

Todo:
  Update more of the graphics context to GDI+ on windows.

Todo:
  Add extra functions and remove any deprecated function

Note:
  On windows this class requires the use of the GDI+ library (gdiplus.lib).

  All contents of this source code are copyright 2005 Exp Digital Uk.
  This source file is covered by the licence conditions of the Infinity API. You should have recieved a copy
  with the source code. If you didnt, please refer to http://www.expdigital.co.uk All content is the Intellectual property of Exp Digital Uk.
  Certain sections of this code may come from other sources. They are credited where applicable.
  If you have comments, suggestions or bug reports please visit http://support.expdigital.co.uk

Id
  CGraphics.hpp,v 1.14 2007/02/08 21:07:54 paul Exp

Definition at line 87 of file CGraphics.hpp.

## Public Types

- enum ETextAlignment {
  e_leftTopAlign = 0,
  e_centerTopAlign,
  e_rightTopAlign,
  e_leftCenterAlign,
  e_centerCenterAlign,
  e_rightCenterAlign,
  e_leftBottomAlign,
  e_centerBottomAlign,
  e_rightBottomAlign,
  e_defaultLabelText,
  e_defaultSingleLine
  }
    Text alignment. More...

## Public Member Functions

- void appendToDrawingAreaOffset (const CPoint &point)
- void beginAlphaDrawing (const double alpha)
- CGraphics ()
- void drawAntiAliasedLine (const CPoint &start, const CPoint &end)
- void drawAntiAliasedPixel (const CPoint &point, const long alpha)
- void drawAntiAliasedPolygon (const CPolygon &polygon)
- void drawArc (const CRect &area, const CPoint &startPos, const CPoint &endPos, const bool clockwise=true)
- void drawEllipse (const CRect &area)
- void drawFilledBorderedRectangle (const CRect &area)
- void drawGradientFilledRectangle (const CRect &area)
- void drawImage (IImage *image, const CRect &drawTo, const CRect &offset)
- void drawImageWithAlpha (IImage *image, const CRect &drawTo, const CRect &offset, const double alpha)
- void drawLine (const CPoint &toThisPoint)
- void drawLine (const CPoint &start, const CPoint &end)
- void drawPixel (const CPoint &point)
- void drawPolygon (const CPolygon &polygon)
- void drawRectangle (const CRect &area)
- void drawRoundedRectangle (const CRect &rect, const CDimension &roundingEffect)
- void drawText (const CString &text, const CRect &area, const CFont *theFont, const ETextAlignment drawOptions=e_defaultLabelText)
- void endAlphaDrawing (const CRect &drawTo=CRect(0, 0, 0, 0), const CRect &offset=CRect(0, 0, 0, 0))
- void fillEllipse (const CRect &rect)
- void fillPolygon (const CPolygon &polygon)
- void fillRectangle (const CRect &rect)
- void fillRoundedRectangle (const CRect &rect, const CDimension &roundingEffect)
- const CBrush * getBrush () const
- CClip & getClippingRegion ()
- const CPoint & getDrawingAreaOffset () const
- CBrush * getMutableBrush () const
- CNativeImage * getMutableNativeImage () const
- CPen * getMutablePen () const
- const CNativeImage * getNativeImage () const
- const CPen * getPen () const
- const CRect & getUpdateArea () const
- void initialise (SWindowHandle *windowHandle, HDC drawContext, const CDimension &area)
- void moveTo (const CPoint &point)
- void negateFromDrawingArea (const CPoint &point)
- void resetDrawingArea ()
- void setBackgroundColour (const CColour &colour)
- void setDrawingAreaOffset (const CPoint &point)
- void setTextColour (const CAlphaColour &textColour=CAlphaColour::CALPHACOLOUR_BLACK)
- void setUpdateArea (const CRect &area)
- void uninitialise ()
- virtual ~CGraphics ()

## Protected Member Functions

- FORCEINLINE void drawAAPixelIncreasingX (const long x, const long y, const unsigned long alpha)
- FORCEINLINE void drawAAPixelIncreasingY (const long x, const long y, const unsigned long alpha)
- void drawWUAALine (const CPoint &start, const CPoint &end)

## Protected Attributes

- SAlphaGraphics m_alphaGraphics
- CBrush * m_brush
- CClip m_clip
- HDC m_drawContext
- ULONG_PTR m_gdiPlusToken
- CPoint m_graphicsOffset
- bool m_hasGdiPlus
- bool m_isAlphaBlending
- CNativeImage * m_nativeImage
- CPen * m_pen
- CDimension m_rootArea
- CAlphaColour m_textColour
- CRect m_updateArea

## Classes

- struct SAlphaGraphics
    Small struct to store all of the alpha values required. More...

## Member Enumeration Documentation

enum Exponent::GUI::Graphics::CGraphics::ETextAlignment

Text alignment.

Enumerator:

  e_leftTopAlign | Align the text to the top left of the specified area
  e_centerTopAlign | Align the text to the center of the area and the top of the area
  e_rightTopAlign | Align the text to the top right of the specified area
  e_leftCenterAlign | Align the text to the center of the area and the left hand side
  e_centerCenterAlign | Align the text centrally within the given area
  e_rightCenterAlign | Align the text to the center of the area and the right hand side
  e_leftBottomAlign | Align the text to the bottom left of the specified area
  e_centerBottomAlign | Align the text to the center of the area and the bottom of the area
  e_rightBottomAlign | Align the text to the bottom right of the specified area
  e_defaultLabelText | Synonomous with e_leftCenterAlign
  e_defaultSingleLine | Synonomous with e_centerCenterAlign

Definition at line 97 of file CGraphics.hpp.

## Constructor & Destructor Documentation

Exponent::GUI::Graphics::CGraphics::CGraphics | ( |  | ) |

Construction

virtual Exponent::GUI::Graphics::CGraphics::~CGraphics | ( |  | ) | `[virtual]`

Destruction

## Member Function Documentation

void Exponent::GUI::Graphics::CGraphics::appendToDrawingAreaOffset | ( | const CPoint & | point | ) | `[inline]`

Append to the offset for drawing

Parameters:

  | point | The point to offset by

Definition at line 421 of file CGraphics.hpp.

References Exponent::MathTools::CPoint::getXPosition(), Exponent::MathTools::CPoint::getYPosition(), m_graphicsOffset, and Exponent::MathTools::CPoint::offset().

void Exponent::GUI::Graphics::CGraphics::beginAlphaDrawing | ( | const double | alpha | ) |

Begin alpha drawing

Parameters:

  | alpha | The alpha level you want to draw with, 0 = fully transparent 0.5 = 50/50 blend src and dest 1.0 = fully opaque

Note:
  These functions are for large scale alpha blending (for example if you have rendered a whole interface to the context
  and you now want to blend it back to the main display. Note that all 'Fill / Draw' functions will independantly alpha blend based on the colour
  That is supplied to it.
  How to use alpha blending in the exponent system
  The alpha blending sub system operates in similar ways externally, but internally is very different between the platforms
  windows doesnt understand the concept of having an alpha level applied to its graphics context. For once the mac is better! :)
  Example draw function
  \n

       void drawControl(CGraphics &graphics)
       {
           // Area of each square relative to our top left
           const CRect area[] =
           {
                CRect(10, 20, 50, 50),
                CRect(20, 30, 50, 50),
                CRect(30, 40, 50, 50)
           };

           // We want to draw three squares, each alpha blended differently over the top of the others
           for (long i = 0; i < 3; i++)
           {
               // First we want to know where to draw to within the main native image
               const CRect drawToHereRelativeToMyTopLeft(0, 0, m_area.getWidth(), m_area.getHeight());

               // Next we want to now if there is an offset within the image we are going to alphablend. Use this to move the top left of the alpha blended image
               const CRect offset(0, 0, m_area.getWidth(), m_area.getHeight());

               // Call this before each alpha blend operation you want to make
               graphics.beginAlphaDrawing(0.8);

                 // Set the pen colour or whatever else here

               graphics.fillRectangle(area[i]);

               // Make sure you call this after *each* drawing operation. Not at the end of your entire draw function, else you wont get alpha blending!\n
               graphics.endAlphaDrawing(drawToHereRelativeToMyTopLeft, offset);
           }
       }

See also:
  endAlphaDrawing

FORCEINLINE void Exponent::GUI::Graphics::CGraphics::drawAAPixelIncreasingX | ( | const long | x,
|  | const long | y,
|  | const unsigned long | alpha |
| ) |  |  | `[inline, protected]`

Draw an antialiased pixel with constantly increasing x position

Parameters:

  | x | The x position
  | y | The y position
  | alpha | The alpha value

Definition at line 484 of file CGraphics.hpp.

References Exponent::GUI::Graphics::CPen::getColour(), Exponent::MathTools::CPoint::getXPosition(), Exponent::MathTools::CPoint::getYPosition(), m_drawContext, m_graphicsOffset, m_pen, Exponent::MathTools::CPoint::offset(), and Exponent::GUI::Graphics::CPen::setColour().

FORCEINLINE void Exponent::GUI::Graphics::CGraphics::drawAAPixelIncreasingY | ( | const long | x,
|  | const long | y,
|  | const unsigned long | alpha |
| ) |  |  | `[inline, protected]`

Draw an antialiased pixel with constantly increasing y position

Parameters:

  | x | The x position
  | y | The y position
  | alpha | The alpha value

Definition at line 529 of file CGraphics.hpp.

References Exponent::GUI::Graphics::CPen::getColour(), Exponent::MathTools::CPoint::getXPosition(), Exponent::MathTools::CPoint::getYPosition(), m_drawContext, m_graphicsOffset, m_pen, Exponent::MathTools::CPoint::offset(), and Exponent::GUI::Graphics::CPen::setColour().

void Exponent::GUI::Graphics::CGraphics::drawAntiAliasedLine | ( | const CPoint & | start,
|  | const CPoint & | end |
| ) |  |  |

Draw an anti aliased line

Parameters:

  | start | The start position
  | end | The end position

void Exponent::GUI::Graphics::CGraphics::drawAntiAliasedPixel | ( | const CPoint & | point,
|  | const long | alpha |
| ) |  |  |

Draw an anti aliased pixel

Parameters:

  | point | The position to draw the point
  | alpha | The alpha value to use

void Exponent::GUI::Graphics::CGraphics::drawAntiAliasedPolygon | ( | const CPolygon & | polygon | ) |

Draw an anti aliased polygon

Parameters:

  | polygon | The polygon

void Exponent::GUI::Graphics::CGraphics::drawArc | ( | const CRect & | area,
|  | const CPoint & | startPos,
|  | const CPoint & | endPos,
|  | const bool | clockwise = `true` |
| ) |  |  |

Draw an arc

Parameters:

  | area | The bounding rectangle
  | startPos | The starting position around the circle
  | endPos | The ending position around the circle
  | clockwise | Line draw clockwise if true, anticlockwise if false

void Exponent::GUI::Graphics::CGraphics::drawEllipse | ( | const CRect & | area | ) |

Draw an ellipse

Parameters:

  | area | The bounding rectangle

void Exponent::GUI::Graphics::CGraphics::drawFilledBorderedRectangle | ( | const CRect & | area | ) |

Draw a filled rectangle with a border

Parameters:

  | area | The are to draw

void Exponent::GUI::Graphics::CGraphics::drawGradientFilledRectangle | ( | const CRect & | area | ) |

Draw a gradient filled rectangle. Fades from current pen colour to white in the middle

void Exponent::GUI::Graphics::CGraphics::drawImage | ( | IImage * | image,
|  | const CRect & | drawTo,
|  | const CRect & | offset |
| ) |  |  |

Draw an image

Parameters:

  | image | The image to draw
  | drawTo | The area to draw to
  | offset | The offset within the original object

void Exponent::GUI::Graphics::CGraphics::drawImageWithAlpha | ( | IImage * | image,
|  | const CRect & | drawTo,
|  | const CRect & | offset,
|  | const double | alpha |
| ) |  |  |

Draw an image with alpha

Parameters:

  | image | The image to draw
  | drawTo | The area to draw to
  | offset | The offset within the original object
  | alpha | The alpha level to draw with

void Exponent::GUI::Graphics::CGraphics::drawLine | ( | const CPoint & | toThisPoint | ) |

Draw a line from the current position to this position

Parameters:

  | toThisPoint | Position to end drawing at

void Exponent::GUI::Graphics::CGraphics::drawLine | ( | const CPoint & | start,
|  | const CPoint & | end |
| ) |  |  |

Draw a line

Parameters:

  | start | The start position
  | end | The end position

void Exponent::GUI::Graphics::CGraphics::drawPixel | ( | const CPoint & | point | ) |

Draw a single pixel at the point specified

Parameters:

  | point | The position to draw the point

void Exponent::GUI::Graphics::CGraphics::drawPolygon | ( | const CPolygon & | polygon | ) |

Draw a polygon

Parameters:

  | polygon | The polygon

void Exponent::GUI::Graphics::CGraphics::drawRectangle | ( | const CRect & | area | ) |

Draw a rectangle outline

Parameters:

  | area | The area to to outline

void Exponent::GUI::Graphics::CGraphics::drawRoundedRectangle | ( | const CRect & | rect,
|  | const CDimension & | roundingEffect |
| ) |  |  |

Draw a rounded rectangle

Parameters:

  | rect | The rect to fill
  | roundingEffect | The amount of rounding to apply

void Exponent::GUI::Graphics::CGraphics::drawText | ( | const CString & | text,
|  | const CRect & | area,
|  | const CFont * | theFont,
|  | const ETextAlignment | drawOptions = `e_defaultLabelText` |
| ) |  |  |

Draw some text

Parameters:

  | text | The text to draw
  | area | The area to draw in
  | theFont | The font to draw with
  | drawOptions | The drawing options to use

void Exponent::GUI::Graphics::CGraphics::drawWUAALine | ( | const CPoint & | start,
|  | const CPoint & | end |
| ) |  |  | `[protected]`

Draw an AA line using wu algorithm

Parameters:

  | start | The start point
  | end | The end point

void Exponent::GUI::Graphics::CGraphics::endAlphaDrawing | ( | const CRect & | drawTo = `CRect(0, 0, 0, 0)`,
|  | const CRect & | offset = `CRect(0, 0, 0, 0)` |
| ) |  |  |

End the alpha drawing

Parameters:

  | drawTo | The area To draw to. Normally within a control that draws within itself, you would make this CRect(0, 0, w, h)
  | offset | The offset drawing position within the native window. Normally within a control that draws within itself, you would make this CRect(0, 0, w, h)

See also:
  beginAlphaDrawing

void Exponent::GUI::Graphics::CGraphics::fillEllipse | ( | const CRect & | rect | ) |

Fill an ellipse with the current brush

Parameters:

  | rect | The bounding rectangle

void Exponent::GUI::Graphics::CGraphics::fillPolygon | ( | const CPolygon & | polygon | ) |

Fill a polygon

Parameters:

  | polygon | The polygon

void Exponent::GUI::Graphics::CGraphics::fillRectangle | ( | const CRect & | rect | ) |

fill a rectange with the current brush

Parameters:

  | rect | The rect to fill

void Exponent::GUI::Graphics::CGraphics::fillRoundedRectangle | ( | const CRect & | rect,
|  | const CDimension & | roundingEffect |
| ) |  |  |

Fill a rounded rectangle with the current brush

Parameters:

  | rect | The rect to fill
  | roundingEffect | The amount of rounding to apply

const CBrush* Exponent::GUI::Graphics::CGraphics::getBrush | ( |  | ) | const

Get the brush

Return values:

  | const | CBrush* The brush

CClip& Exponent::GUI::Graphics::CGraphics::getClippingRegion | ( |  | ) |

Get the clipping region

Return values:

  | CClip& | The clipping area

const CPoint& Exponent::GUI::Graphics::CGraphics::getDrawingAreaOffset | ( |  | ) | const`[inline]`

Get the drawing area offset

Return values:

  | const | CPoint& The amount the initial pen position (0,0) is nmoved by

Definition at line 438 of file CGraphics.hpp.

References m_graphicsOffset.

CBrush* Exponent::GUI::Graphics::CGraphics::getMutableBrush | ( |  | ) | const

Get the brush

Return values:

  | CBrush* | The brush

CNativeImage* Exponent::GUI::Graphics::CGraphics::getMutableNativeImage | ( |  | ) | const`[inline]`

Get the native image. This is the back buffer and you should not be messing with this function directly unless you absolutely know what you are doing

Return values:

  | CNativeImage* | The native drawing image

Definition at line 407 of file CGraphics.hpp.

References m_nativeImage.

CPen* Exponent::GUI::Graphics::CGraphics::getMutablePen | ( |  | ) | const

Get the pen

Return values:

  | CPen* | The pen

const CNativeImage* Exponent::GUI::Graphics::CGraphics::getNativeImage | ( |  | ) | const`[inline]`

Get the native image This is the back buffer and you should not be messing with this function directly unless you absolutely know what you are doing

Return values:

  | const | CNativeImage* The native drawing image

Definition at line 401 of file CGraphics.hpp.

References m_nativeImage.

const CPen* Exponent::GUI::Graphics::CGraphics::getPen | ( |  | ) | const

Get the pen

Return values:

  | const | CPen* The pen

const CRect& Exponent::GUI::Graphics::CGraphics::getUpdateArea | ( |  | ) | const`[inline]`

Get the update area

Return values:

  | const | CRect& The update area in global pixels

Definition at line 452 of file CGraphics.hpp.

References m_updateArea.

void Exponent::GUI::Graphics::CGraphics::initialise | ( | SWindowHandle * | windowHandle,
|  | HDC | drawContext,
|  | const CDimension & | area |
| ) |  |  |

Initialise

Parameters:

  | windowHandle | The handle of the window
  | drawContext | The windows draw contexr
  | area | The area of the drawing area

void Exponent::GUI::Graphics::CGraphics::moveTo | ( | const CPoint & | point | ) |

Move the pen to a location

Parameters:

  | point | The point to move to

void Exponent::GUI::Graphics::CGraphics::negateFromDrawingArea | ( | const CPoint & | point | ) | `[inline]`

Netaget from the offset to drawing

Parameters:

  | point | The point to remove from drawing offset

Definition at line 427 of file CGraphics.hpp.

References Exponent::MathTools::CPoint::getXPosition(), Exponent::MathTools::CPoint::getYPosition(), m_graphicsOffset, and Exponent::MathTools::CPoint::offset().

void Exponent::GUI::Graphics::CGraphics::resetDrawingArea | ( |  | ) | `[inline]`

Reset the areas for drawing, all drawing begins at (0,0) again

Definition at line 432 of file CGraphics.hpp.

References m_graphicsOffset, and Exponent::MathTools::CPoint::setPoint().

void Exponent::GUI::Graphics::CGraphics::setBackgroundColour | ( | const CColour & | colour | ) | `[inline]`

Set the background colour to draw with

Parameters:

  | colour | The draw area background colour

Definition at line 210 of file CGraphics.hpp.

References m_nativeImage, and Exponent::GUI::Graphics::CNativeImage::setBackgroundColour().

void Exponent::GUI::Graphics::CGraphics::setDrawingAreaOffset | ( | const CPoint & | point | ) | `[inline]`

Offset the areas for drawing

Parameters:

  | point | The point to offset to

Definition at line 415 of file CGraphics.hpp.

References m_graphicsOffset.

void Exponent::GUI::Graphics::CGraphics::setTextColour | ( | const CAlphaColour & | textColour = `CAlphaColour::CALPHACOLOUR_BLACK` | ) | `[inline]`

Set the text colour

Parameters:

  | textColour | The text colour to use

Definition at line 369 of file CGraphics.hpp.

References m_textColour.

void Exponent::GUI::Graphics::CGraphics::setUpdateArea | ( | const CRect & | area | ) | `[inline]`

Set the update area

Parameters:

  | area | The global update area in pixels

Definition at line 446 of file CGraphics.hpp.

References m_updateArea.

void Exponent::GUI::Graphics::CGraphics::uninitialise | ( |  | ) |

Uninitialise

## Member Data Documentation

SAlphaGraphics Exponent::GUI::Graphics::CGraphics::m_alphaGraphics`[protected]`

The alpha graphics components

Definition at line 599 of file CGraphics.hpp.

CBrush* Exponent::GUI::Graphics::CGraphics::m_brush`[protected]`

The brush

Definition at line 585 of file CGraphics.hpp.

CClip Exponent::GUI::Graphics::CGraphics::m_clip`[protected]`

The clipping region

Definition at line 587 of file CGraphics.hpp.

HDC Exponent::GUI::Graphics::CGraphics::m_drawContext`[protected]`

The windows draw context

Definition at line 598 of file CGraphics.hpp.

Referenced by drawAAPixelIncreasingX(), and drawAAPixelIncreasingY().

ULONG_PTR Exponent::GUI::Graphics::CGraphics::m_gdiPlusToken`[protected]`

Token for GDI+

Definition at line 601 of file CGraphics.hpp.

CPoint Exponent::GUI::Graphics::CGraphics::m_graphicsOffset`[protected]`

Amount of offset to apply

Definition at line 589 of file CGraphics.hpp.

Referenced by appendToDrawingAreaOffset(), drawAAPixelIncreasingX(), drawAAPixelIncreasingY(), getDrawingAreaOffset(), negateFromDrawingArea(), resetDrawingArea(), and setDrawingAreaOffset().

bool Exponent::GUI::Graphics::CGraphics::m_hasGdiPlus`[protected]`

Does the system support GDI+

Definition at line 600 of file CGraphics.hpp.

bool Exponent::GUI::Graphics::CGraphics::m_isAlphaBlending`[protected]`

Are we currently alpha blending?

Definition at line 595 of file CGraphics.hpp.

CNativeImage* Exponent::GUI::Graphics::CGraphics::m_nativeImage`[protected]`

The double buffer

Definition at line 586 of file CGraphics.hpp.

Referenced by getMutableNativeImage(), getNativeImage(), and setBackgroundColour().

CPen* Exponent::GUI::Graphics::CGraphics::m_pen`[protected]`

The pen for drawing with..

Definition at line 584 of file CGraphics.hpp.

Referenced by drawAAPixelIncreasingX(), and drawAAPixelIncreasingY().

CDimension Exponent::GUI::Graphics::CGraphics::m_rootArea`[protected]`

The total area (the size of the window this graphics is drawing to

Definition at line 591 of file CGraphics.hpp.

CAlphaColour Exponent::GUI::Graphics::CGraphics::m_textColour`[protected]`

The colour of text drawn onscreen

Definition at line 593 of file CGraphics.hpp.

Referenced by setTextColour().

CRect Exponent::GUI::Graphics::CGraphics::m_updateArea`[protected]`

The update area

Definition at line 590 of file CGraphics.hpp.

Referenced by getUpdateArea(), and setUpdateArea().