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.
CWindow
CControl
CControlRoot
CClip
1.0.1 Added drawFilledBorderedRectangle function
1.0.2 Moved windows format to GDI+
1.0.3 Made text colour alpha based
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
Definition at line 87 of file CGraphics.hpp.
Text alignment.
Definition at line 97 of file CGraphics.hpp.
Exponent::GUI::Graphics::CGraphics::CGraphics | ( | ) |
Construction
virtual Exponent::GUI::Graphics::CGraphics::~CGraphics | ( | ) | [virtual] |
Destruction
void Exponent::GUI::Graphics::CGraphics::appendToDrawingAreaOffset | ( | const CPoint & | point | ) | [inline] |
Append to the offset for drawing
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
alpha | The alpha level you want to draw with, 0 = fully transparent 0.5 = 50/50 blend src and dest 1.0 = fully opaque |
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); } }
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
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
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
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
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
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
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
area | The bounding rectangle |
void Exponent::GUI::Graphics::CGraphics::drawFilledBorderedRectangle | ( | const CRect & | area | ) |
Draw a filled rectangle with a border
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
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
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
toThisPoint | Position to end drawing at |
Draw a line
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
point | The position to draw the point |
void Exponent::GUI::Graphics::CGraphics::drawPolygon | ( | const CPolygon & | polygon | ) |
Draw a polygon
polygon | The polygon |
void Exponent::GUI::Graphics::CGraphics::drawRectangle | ( | const CRect & | area | ) |
Draw a rectangle outline
area | The area to to outline |
void Exponent::GUI::Graphics::CGraphics::drawRoundedRectangle | ( | const CRect & | rect, | |
const CDimension & | roundingEffect | |||
) |
Draw a rounded rectangle
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
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
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
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) |
void Exponent::GUI::Graphics::CGraphics::fillEllipse | ( | const CRect & | rect | ) |
Fill an ellipse with the current brush
rect | The bounding rectangle |
void Exponent::GUI::Graphics::CGraphics::fillPolygon | ( | const CPolygon & | polygon | ) |
Fill a polygon
polygon | The polygon |
void Exponent::GUI::Graphics::CGraphics::fillRectangle | ( | const CRect & | rect | ) |
fill a rectange with the current brush
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
rect | The rect to fill | |
roundingEffect | The amount of rounding to apply |
const CBrush* Exponent::GUI::Graphics::CGraphics::getBrush | ( | ) | const |
Get the brush
const | CBrush* The brush |
CClip& Exponent::GUI::Graphics::CGraphics::getClippingRegion | ( | ) |
Get the clipping region
CClip& | The clipping area |
const CPoint& Exponent::GUI::Graphics::CGraphics::getDrawingAreaOffset | ( | ) | const [inline] |
Get the drawing area offset
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
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
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
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
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
const | CPen* The pen |
const CRect& Exponent::GUI::Graphics::CGraphics::getUpdateArea | ( | ) | const [inline] |
Get the update area
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
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
point | The point to move to |
void Exponent::GUI::Graphics::CGraphics::negateFromDrawingArea | ( | const CPoint & | point | ) | [inline] |
Netaget from the offset to drawing
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
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
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
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
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
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.
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.
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().
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().
The update area
Definition at line 590 of file CGraphics.hpp.
Referenced by getUpdateArea(), and setUpdateArea().