wxArt2D
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members

Drawing context abstraction. More...

#include <drawer2d.h>

Inheritance diagram for a2dDrawer2D:
Inheritance graph
[legend]
Collaboration diagram for a2dDrawer2D:
Collaboration graph
[legend]

Public Member Functions

 a2dDrawer2D (int width=0, int height=0)
 constructor More...
 
 a2dDrawer2D (const wxSize &size)
 constructor More...
 
 a2dDrawer2D (const a2dDrawer2D &other)
 copy constructor
 
virtual ~a2dDrawer2D ()
 destructor
 
void SetDisplay (wxWindow *window)
 the display
 
void SetPrimitiveThreshold (wxUint16 pixels, bool asrect=true)
 set at what size to stop drawing
 
wxUint16 GetPrimitiveThreshold () const
 get drawing threshold More...
 
bool GetThresholdDrawRectangle () const
 underneath the threshold draw a rectangle instead of the real object.
 
void SetPolygonFillThreshold (wxUint16 pixels)
 set threshold at which polygon is drawn filled or only outline
 
wxUint16 GetPolygonFillThreshold () const
 get threshold at which polygon is drawn filled or only outline
 
virtual wxDC * GetRenderDC () const
 get the DC that is used for rendering
 
virtual wxDC * GetDeviceDC () const
 get the DC that is used for rendering
 
void SetDisplayAberration (double aber)
 Set the display aberration of curved shapes. More...
 
double GetDisplayAberration () const
 Returns the display aberration of curved shapes. More...
 
virtual wxBitmap GetBuffer () const =0
 Return the buffer as a bitmap.
 
virtual void SetBufferSize (int w, int h)=0
 Change the buffer size. More...
 
virtual void CopyIntoBuffer (const wxBitmap &bitm)
 
void BlitBuffer ()
 blit whole buffer to device
 
void BlitBuffer (int x, int y, int width, int height, int xbuf=0, int ybuf=0)
 blit given rect contents within buffer to device
 
virtual void BlitBuffer (wxRect rect, const wxPoint &bufferpos=wxPoint(0, 0))=0
 blit given rect contents within buffer to device
 
virtual void BlitBuffer (wxDC *dc, wxRect rect, const wxPoint &bufferpos=wxPoint(0, 0))=0
 used for blitting to a wxDC.
 
virtual void ShiftBuffer (int dxy, bool yshift)
 quick scroll over small distance
 
virtual wxBitmap GetSubBitmap (wxRect sub_rect) const =0
 A way to get parts form the buffer that is drawn into. More...
 
bool GetYaxis () const
 get y axis orientation
 
virtual void SetYaxis (bool up)
 set if the Yaxis goes up or down
 
void SetMappingDeviceRect (int mapx, int mapy, int mapWidth, int mapHeight, bool remap=false)
 to change the default mapping (to the complete buffer). More...
 
virtual void SetMappingWidthHeight (double vx1, double vy1, double width, double height)
 Give the virtual size to be displayed, the mapping matrix will be calculated. More...
 
void SetMappingWidthHeight (const a2dBoundingBox &box)
 Give the virtual size to be displayed, the mapping matrix will be calculated. More...
 
void SetMappingUpp (double vx1, double vy1, double xpp, double ypp)
 Give the virtual size to be displayed, the mapping matrix will be calculated. More...
 
double GetUppX () const
 return xpp Number of user units per pixel in x
 
double GetUppY () const
 return ypp Number of user units per pixel in y
 
void SetMinX (double x)
 Set Minimal X of the visible part in world coordinates.
 
void SetMinY (double y)
 Set Minimal Y of the visible part in world coordinates.
 
void SetUppX (double x)
 set world units per pixel in X
 
void SetUppY (double y)
 set world units per pixel in Y
 
bool GetVirtualAreaSet () const
 if the virtual area has been set already return true else false. More...
 
void StartRefreshDisplayDisable ()
 when called a mapping change will result not result in a refresh of the m_display. More...
 
void EndRefreshDisplayDisable ()
 see StartRefreshDisplayDisable()
 
bool GetRefreshDisplayDisable () const
 see StartRefreshDisplayDisable()
 
int GetWidth () const
 get buffer/device width
 
int GetHeight () const
 get buffer/device height
 
int GetMapWidth () const
 get mapping to device width
 
int GetMapHeight () const
 get mapping to device height
 
int GetMapX () const
 X mapping position in device coordinates.
 
int GetMapY () const
 Y mapping position in device coordinates.
 
double GetVisibleMinX () const
 get Minimal X of the visible part in world coordinates
 
double GetVisibleMinY () const
 get Minimal X of the visible part in world coordinates
 
virtual double GetVisibleMaxX () const
 get Maximum X of the visible part in world coordinates
 
virtual double GetVisibleMaxY () const
 get Maximum Y of the visible part in world coordinates
 
virtual double GetVisibleWidth () const
 get Width of visible part in world coordinates
 
virtual double GetVisibleHeight () const
 get Height of visible part in world coordinates
 
a2dBoundingBox GetVisibleBbox () const
 get visible area as a boundingbox in world coordinates
 
wxRect ToDevice (const a2dBoundingBox &bbox)
 convert the bounding box in world coordinates to device coordinates and return that rectangle.
 
a2dBoundingBox ToWorld (const wxRect &rect)
 convert the rect in device coordinates to a bounding box in world coordinates and return that boundingbox.
 
double DeviceToWorldX (double x) const
 convert x from device to world coordinates
 
double DeviceToWorldY (double y) const
 convert y from device to world coordinates
 
double DeviceToWorldXRel (double x) const
 convert x relative from device to world coordinates More...
 
double DeviceToWorldYRel (double y) const
 convert y relative from device to world coordinates More...
 
int WorldToDeviceX (double x) const
 convert x from world to device coordinates
 
int WorldToDeviceY (double y) const
 convert y from world to device coordinates
 
int WorldToDeviceXRel (double x) const
 convert x relative from world to device coordinates More...
 
int WorldToDeviceYRel (double y) const
 convert y relative from world to device coordinates More...
 
double WorldToDeviceXRelNoRnd (double x) const
 convert x relative from world to device coordinates (result not rounded to integer) More...
 
double WorldToDeviceYRelNoRnd (double y) const
 convert y relative from world to device coordinates (result not rounded to integer) More...
 
const a2dAffineMatrixGetMappingMatrix ()
 get the world-to-device (aka mapping) matrix
 
void SetMappingMatrix (const a2dAffineMatrix &mapping)
 
virtual void SetTransform (const a2dAffineMatrix &userToWorld)
 set user-to-world transform matrix. More...
 
const a2dAffineMatrixGetTransform () const
 get the user-to-world transform matrix. More...
 
const a2dAffineMatrixGetUserToDeviceTransform () const
 get matrix which transforms directly from user coordinates to device
 
virtual void PushTransform ()
 Save the current user-to-world transform on the affine stack.
 
virtual void PushIdentityTransform ()
 push no transform, to draw directly in device coordinates
 
virtual void PushTransform (const a2dAffineMatrix &affine)
 Save the current transform on the affine stack and then multiply it by the given affine. More...
 
virtual void PopTransform (void)
 Recall the previously saved user-to-world transform off the matrix stack.
 
void SetSplineAberration (double aber)
 Set the detail level for spline drawing. More...
 
virtual void ResetStyle ()
 set a pre-defined style reseting cashed values. More...
 
void SetDrawerStroke (const a2dStroke &stroke)
 Used to set the current stroke. More...
 
a2dStroke GetDrawerStroke () const
 get the current stroke
 
void SetDrawerFill (const a2dFill &fill)
 Used to set the current fill. More...
 
a2dFill GetDrawerFill () const
 get the current fill
 
void SetFont (const a2dFont &font)
 set font to use for drawing text
 
a2dFont GetFont () const
 get font used for drawing text
 
void SetNormalizedFont (bool forceNormalizedFont)
 Use a fixed device height for drawing text.
 
bool GetNormalizedFont ()
 Get setting for a fixed device height for drawing text.
 
void SetSmallTextThreshold (wxUint16 pixels)
 
wxUint16 GetSmallTextThreshold () const
 See SetSmallTextThreshold.
 
virtual void DrawVpath (const a2dVpath *path)
 Draw vector path in world coordinates.
 
virtual void DrawPolyPolygon (a2dListOfa2dVertexList polylist, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
 draw a list of polygons ( contour clockwise becomes hole )
 
virtual void DrawPolygon (a2dVertexArray *points, bool spline=false, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
 Draw polygon in world coordinates using pointarray.
 
virtual void DrawPolygon (const a2dVertexList *list, bool spline=false, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)
 Draw polygon in world coordinates using pointlist.
 
virtual void DrawLines (a2dVertexArray *points, bool spline=false)
 Draw polyline in world coordinates using pointarray.
 
virtual void DrawLines (const a2dVertexList *list, bool spline=false)
 Draw polyline in world coordinates using pointlist.
 
virtual void DrawLine (double x1, double y1, double x2, double y2)
 Draw line in world coordinates.
 
virtual void DrawArc (double x1, double y1, double x2, double y2, double xc, double yc, bool chord)
 Draw Arc in world coordinates.
 
virtual void DrawEllipticArc (double xc, double yc, double width, double height, double sa, double ea, bool chord)
 Draw Elliptic Arc in world coordinates.
 
virtual void DrawRoundedRectangle (double x, double y, double width, double height, double radius, bool pixelsize=false)
 Draw RoundedRectangle in world coordinates.
 
virtual void DrawCenterRoundedRectangle (double xc, double yc, double width, double height, double radius, bool pixelsize=false)
 Draw CenterRoundedRectangle in world coordinates. More...
 
virtual void DrawCircle (double x, double y, double radius)
 Draw Circle in world coordinates. More...
 
virtual void DrawEllipse (double x, double y, double width, double height)
 Draw Ellipse in world coordinates. More...
 
virtual void DrawImage (const wxImage &image, double x, double y, double width, double height, wxUint8 Opacity=255)=0
 Draw wxImage in world coordinates. More...
 
virtual void DrawImage (const a2dImageRGBA &image, double x, double y, double width, double height, wxUint8 Opacity=255)=0
 
void DrawImage (const wxImage &image, double x=0, double y=0, wxUint8 Opacity=255)
 Draw wxImage in world coordinates. More...
 
virtual void DrawPoint (double xc, double yc)=0
 draw a single point
 
void SetRealScale (bool realScale)
 If true use real scale else different scale by x and y.
 
virtual void DrawText (const wxString &text, double x, double y, int alignment=wxMINX|wxMINY, bool Background=true)
 Draw text in user coordinates. More...
 
virtual void DeviceDrawAnnotation (const wxString &text, wxCoord x, wxCoord y, const wxFont &font)
 text drawn in device coordinates
 
void SetDrawStyle (a2dDrawStyle drawstyle)
 set drawstyle to use for drawing, More...
 
a2dDrawStyle GetDrawStyle () const
 get drawstyle used for drawing.
 
void SetPrintMode (bool onOff)
 to modify drawing feature when used as context for printing
 
void OverRuleFixedStyle ()
 id style is FIXED, saves current style and sets style to a2dFILLED
 
void ResetFixedStyle ()
 only way to reset style after SetDrawStyle( a2dFIXED*** );
 
void ReStoreFixedStyle ()
 when fixed drawing style is set, it can be overruled. More...
 
void SetDisableDrawing (bool disableDrawing)
 when set, all drawing functions return immediately. More...
 
bool GetDisableDrawing ()
 see SetDisableDrawing()
 
virtual void SetClippingRegion (a2dVertexList *points, bool spline=false, wxPolygonFillMode fillStyle=wxODDEVEN_RULE)=0
 set clipping region from polygon to which everything drawn will be clipped.
 
virtual void ExtendClippingRegion (a2dVertexList *points, bool spline=false, wxPolygonFillMode fillStyle=wxODDEVEN_RULE, a2dBooleanClip clipoperation=a2dCLIP_AND)=0
 extend clipping region with a polygon to which everything drawn will be clipped.
 
virtual void ExtendAndPushClippingRegion (a2dVertexList *points, bool spline=false, wxPolygonFillMode fillStyle=wxODDEVEN_RULE, a2dBooleanClip clipoperation=a2dCLIP_AND)=0
 push on stack the current clipping region and extend clipping region More...
 
virtual void PopClippingRegion ()=0
 pop a previously pushed clipping region
 
virtual void SetClippingRegionDev (wxCoord minx, wxCoord miny, wxCoord maxx, wxCoord maxy)=0
 set clipping region using x y values in device coordinates
 
virtual void SetClippingRegion (double minx, double miny, double maxx, double maxy)=0
 set clipping region using x y values in world coordinates
 
virtual void DestroyClippingRegion ()=0
 set clipping region off
 
void GetClippingBox (double &x, double &y, double &w, double &h) const
 what is the current clipping region in world coordinates
 
a2dBoundingBoxGetClippingBox ()
 what is the current clipping region in world coordinates
 
void GetClippingMinMax (double &xmin, double &ymin, double &xmax, double &ymax) const
 what is the current clipping region in world coordinates
 
wxRect & GetClippingBoxDev ()
 what is the current clipping region in device coordinates
 
void GetClippingBoxDev (int &x, int &y, int &w, int &h) const
 what is the current clipping region in device coordinates
 
void Init ()
 Initialize a drawer.
 
virtual void BeginDraw ()=0
 start to draw on this context (used to initialize a specific drawer)
 
virtual void EndDraw ()=0
 end drawing on this context (used to reset a specific drawer)
 
void SetOpacityFactor (wxUint8 OpacityFactor)
 when enabling m_useOpacityFactor, this is how transparent More...
 
wxUint8 GetOpacityFactor ()
 see SetOpacityFactor()
 
virtual bool HasAlpha ()
 does a derived drawer have alpha support or not
 
void DrawCharStrokeCb (wxChar c)
 Wrapper for DrawCharStroke. More...
 
void DrawCharFreetypeCb (wxChar c)
 Wrapper for DrawCharFreetype. More...
 
void DrawCharDcCb (wxChar c)
 Wrapper for DrawCharDc. More...
 

Static Public Attributes

static const a2dSignal sig_changedZoom = wxNewId()
 

Protected Member Functions

virtual void SetActiveStroke (const a2dStroke &stroke)
 sync with actual API graphical context More...
 
virtual void SetActiveFill (const a2dFill &fill)
 sync with actual API graphical context More...
 
virtual void DoSetDrawStyle (a2dDrawStyle drawstyle)=0
 
virtual void DoSetActiveStroke ()=0
 per drawer implementation
 
virtual void DoSetActiveFill ()=0
 per drawer implementation
 
virtual void DoSetActiveFont (const a2dFont &font)
 
wxPen ConvertActiveToPen ()
 get active stroke as wxPen
 
wxBrush ConvertActiveToBrush ()
 get active fill as wxBrush
 
bool IsStrokeOnly ()
 wxART2D_USE_GRAPHICS_CONTEXT More...
 
bool IsStroked ()
 
int ToDeviceLines (a2dVertexArray *points, a2dBoundingBox &devbbox, bool &smallPoly, bool replaceByRectangle=false)
 convert vertex array containing line and arc segments in user coordinates to device coordinate lines.
 
int ToDeviceLines (const a2dVertexList *list, a2dBoundingBox &devbbox, bool &smallPoly, bool replaceByRectangle=false)
 convert vertex list containing line and arc segments in user coordinates to device coordinate lines.
 
void SetMappingUpp (double x, double y, double wx, double wy, double vx1, double vy1, double xpp, double ypp)
 Given the rectangle in world coordinate to be displayed, update the mappingmatrix. More...
 
unsigned int ConvertSplinedPolygon2 (unsigned int n)
 converts internal device points array to spline. Returns new number of points.
 
unsigned int ConvertSplinedPolyline2 (unsigned int n)
 converts internal device points array to spline. Returns new number of points.
 
bool Clipping (double &x1, double &y1, double &x2, double &y2)
 clip lines
 
int GetClipCode (double x, double y)
 clip code of a point
 
void FillPolygon (int n, wxRealPoint points[])
 Used for filling with Gradient fill style.
 
bool MoveUp (int n, wxRealPoint points[], double horline, int &index, int direction)
 Used for filling with Gradient fill style.
 
void DetectCriticalPoints (int n, wxRealPoint points[])
 Used for filling with Gradient fill style.
 
void DrawTextGeneric (const wxString &text, double x, double y, void(a2dDrawer2D::*drawchar)(wxChar))
 
virtual void DrawCharUnknown (wxChar c)
 Draw a cross instead of a character.
 
virtual void DrawTextUnknown (const wxString &text, double x, double y, bool words=false)
 Draw a cross, indicating an unsupported font type for this drawer. More...
 
virtual void DrawCharStroke (wxChar c)
 Draw a stroke character. More...
 
virtual void DrawTextStroke (const wxString &text, double x, double y)
 Draw text in user coordinates, based on a stroke font. More...
 
virtual void DrawCharFreetype (wxChar c)
 Draw a freetype character. More...
 
virtual void DrawTextFreetype (const wxString &text, double x, double y)
 Draw text in world coordinates, based on a freetype font .
 
virtual void DrawCharDc (wxChar c)
 Draw a dc character. More...
 
virtual void DrawTextDc (const wxString &text, double x, double y)
 Draw text in user coordinates, based on a dc font .
 
wxPoint * _convertToIntPointCache (int n, wxRealPoint *pts)
 Convert double points to integer coords in the point cache and return pointer.
 
virtual void DeviceDrawPolygon (unsigned int n, bool spline, wxPolygonFillMode fillStyle)
 draw an internal polygon in device coordinates
 
virtual void DeviceDrawLines (unsigned int n, bool spline)
 draw an internal polyline in device coordinates
 
virtual void DeviceDrawLine (double x1, double y1, double x2, double y2)
 draw in pixels
 
virtual void DeviceDrawHorizontalLine (int x1, int y1, int x2, bool use_stroke_color)
 Draw a pixel-width, unstroked horizontal line in device (pixel) coordinates. More...
 
virtual void DeviceDrawVerticalLine (int x1, int y1, int y2, bool use_stroke_color)
 Draw a pixel-width, unstroked vertical line in device (pixel) coordinates. More...
 
virtual void DeviceDrawPixel (int x1, int y1, unsigned char r, unsigned char g, unsigned char b, unsigned char a=255)
 draw a single, unstroked pixel in device coordinates with the given color
 

Protected Attributes

bool m_frozen
 buffer updating activity possible or not
 
bool m_mouseevents
 enable/ disable mouse events handling by canvas
 
a2dStroke m_currentstroke
 used while rendering
 
a2dFill m_currentfill
 used while rendering
 
a2dStroke m_activestroke
 used while rendering
 
a2dFill m_activefill
 used while rendering
 
a2dFont m_currentfont
 current font set
 
a2dDrawStyle m_drawstyle
 drawstyle (like invert mode)
 
a2dStroke m_fixStrokeRestore
 used to restore an overruled fix style
 
a2dFill m_fixFillRestore
 used to restore an overruled fix style
 
a2dDrawStyle m_fixDrawstyle
 used to restore an overruled fix style
 
bool m_yaxis
 up or down
 
double m_virt_minX
 virtual coordinates box its miminum X
 
double m_virt_minY
 virtual coordinates box its miminum Y
 
double m_xpp
 user units per pixel in x
 
double m_ypp
 user units per pixel in y
 
bool m_fixedStyledOverRuled
 keep track of this
 
bool m_forceNormalizedFont
 up or down
 
wxUint16 m_smallTextThreshold
 
bool m_pendingSig_changedZoom
 When display refresh is on hold, this triggers a delayed zoom signal, when released.
 
a2dVertexList m_tempPoints
 used internally in some methods to avoid constructor, new, ...
 
wxUint8 m_StrokeOpacityCol1
 active stroke alpha
 
wxUint8 m_StrokeOpacityCol2
 active stroke alpha
 
wxUint8 m_FillOpacityCol1
 active fill alpha
 
wxUint8 m_FillOpacityCol2
 active fill alpha
 
unsigned char m_colour1redStroke
 active stroke colours
 
unsigned char m_colour1greenStroke
 active stroke colours
 
unsigned char m_colour1blueStroke
 active stroke colours
 
unsigned char m_colour1redFill
 active fill colours
 
unsigned char m_colour1greenFill
 active fill colours
 
unsigned char m_colour1blueFill
 active fill colours
 
unsigned char m_colour2redFill
 active fill colours
 
unsigned char m_colour2greenFill
 active fill colours
 
unsigned char m_colour2blueFill
 active fill colours
 
a2dAffineMatrix m_worldtodevice
 world to device coordinate mapping
 
a2dAffineMatrix m_usertoworld
 pointer to current user-to-world transform matrix
 
a2dAffineMatrix m_usertodevice
 pointer to current user-to-device transform matrix ( so includes mapping matrix )
 
bool m_virtualarea_set
 is the virtual area set already (used during startup)
 
int m_refreshDisplay
 see SetRefreshDisplay()
 
int m_width
 device size width
 
int m_height
 device size height
 
int m_mapX
 X mapping position in device coordinates.
 
int m_mapY
 Y mapping position in device coordinates.
 
int m_mapWidth
 width for mapping in device coordinates
 
int m_mapHeight
 height for mapping in device coordinates
 
a2dCriticalPointList m_CRlist
 critical point list for polygon
 
a2dAETList m_AETlist
 scanline list of intersections with polygon
 
std::vector< wxPoint > m_cpointsInt
 cached array for containing transformed device coordinates (integer)
 
std::vector< wxRealPoint > m_cpointsDouble
 cached array for containing transformed device coordinates (double)
 
double m_splineaberration
 accuracy of spline
 
a2dClipRegionList m_clipregionlist
 pushed clipping regions
 
double m_displayaberration
 accuracy of arc segment calculation etc. in device coordinates
 
wxUint16 m_drawingthreshold
 object smaller than this value will not be rendered
 
wxUint16 m_polygonFillThreshold
 polygon smaller than this value will be rendered non filled.
 
bool m_asrectangle
 underneath the threshold draw rectangles if true else nothing
 
a2dBoundingBox m_clipboxworld
 current clipping area in world coordinates
 
wxRect m_clipboxdev
 current clipping area in device coordinates
 
int m_beginDraw_endDraw
 counter for BeginDraw EndDraw calls
 
wxWindow * m_display
 view its window.
 
bool m_disableDrawing
 all drawing is disabled when this is true
 
wxUint8 m_OpacityFactor
 opacity will be the one set, derived by this
 
std::vector< a2dAffineMatrixm_affineStack
 Affine transform stack. More...
 
bool m_realScale
 If true use real scale else different scale by x and y.
 
bool m_printingMode
 can be used to modify drawing features when used as context for printing
 

Detailed Description

Drawing context abstraction.

a2dDrawer2D presents a unified abstract view of underlying system-dependent drawing contexts. It provides a simple low-level interface for drawing rectangles and other basic primitives, and it also handles the mapping and transformations from world coordinates to device coordinates.

The current a2dFill and a2dStroke need to be set, those classes are always reference counted, and a2dDrawer2D will increment and decrement them when setting and releasing them. This means that if the reference count reaches zero it will actually be deleted.

Mapping from device to Logical/World coordinates needs to be set for a drawer. The Yaxis orientation can also be set via the SetYaxis() method.

About Transformations

There are three different coordinate systems used by a2dDrawer2D, and two transformations that map between them. These are referred to in a2d as

User coordinates are the coordinates you give to drawing functions like DrawCircle(). User coordinates are transformed to World coordinates by the transformation returned from GetTransform(). The idea behind user coordinates is that one can draw in a relative coordinate system, which can be at a position, angle and scale relative to the world coordinates. The drawing context will correctly transform the relative coordinates, to world and device. This way of drawing especialy becomes important when working with canvas objects. Inside such object one can use drawing functions relative to the origin of that object, and one does not have to take into account how and where this object is placed in the world coordinate system. World coordinates are transformed to Device coordinates using the transformation returned by GetMappingMatrix(). One can draw in device coordinates without transformations by calling PushIdentityTransform(). PopTransform() will restore the previous transformation. As an example one can draw the vertexes in a plot as a circle in device coordinates (with a fixed radius in pixels that is), while the curve itself is draw in normal user coordinates.

Given an input point (x,y), the final location on the output device (e.g. screen) in device units (e.g. pixels) for any of the Draw*() methods is given by

(devx,devy) = GetMappingMatrix() * GetTransform() * (x,y)

The compound of the world-to-device mapping and user-to-world transform is also kept up-to-date. It can be obtained by calling GetUserToDeviceTransform(). So we can also say

(devx,devy) = GetUserToDeviceTransform() * (x,y)

We can also depict this relationship as

            User coordinates
           /                \
  [ GetTransform() ]         |
          |                  |
    World coordinates     [ GetUserToDeviceTransform() ]
          |                  |
[ GetMappingMatrix() ]       |
           \                /
          Device coordiantes
The Mapping Matrix

The mapping matrix returned by GetMappingMatrix() contains only translation and axis-aligned scaling. So an input of an axis-aligned rectangle is always transformed to another axis-aligned rectangle. This lets you have an unlimited virtual canvas (aka "world") and map different portions of it to the drawing surface. Additionally, some objects like fonts are aware of the orientation of the Y axis defined by the mapping, and will draw right-side up, even if the Y axis is mirrored in the mapping.

The mapping matrix can be manipulated using the following methods:

The User to World Transform Matrix

The user-to-world transform matrix returned by GetTransform() is a 2x3 affine matrix that can contain translation, rotation, and scaling (including shearing and mirroring).

The relative transform can be manipulated with these methods:

double buffering

A derived drawing context can be buffered or not. But this class is prepared as a buffered drawing context, so it assumes in certain member fucntions that one is drawing to a buffer. A drawing context which does not use a buffer needs to implement those pur virtual members and give assert.

See Also
a2dDcDrawer, a2dMemDcDrawer, a2dAggDrawer

Definition at line 177 of file drawer2d.h.

Constructor & Destructor Documentation

a2dDrawer2D::a2dDrawer2D ( int  width = 0,
int  height = 0 
)

constructor

Remarks
Do not forget to call SetDocument() if used standalone (in a a2dDocumentCommandProcessor setting this is taken care of).

Definition at line 77 of file drawer2d.cpp.

a2dDrawer2D::a2dDrawer2D ( const wxSize &  size)

constructor

Remarks
Do not forget to call SetDocument() if used standalone (in a a2dDocumentCommandProcessor setting this is taken care of)

Definition at line 65 of file drawer2d.cpp.

Member Function Documentation

void a2dDrawer2D::DeviceDrawHorizontalLine ( int  x1,
int  y1,
int  x2,
bool  use_stroke_color 
)
protectedvirtual

Draw a pixel-width, unstroked horizontal line in device (pixel) coordinates.

This method is useful for implementing low level fill routines.
Parameters
x1x start of line
x2x end of line
y1y of line
use_stroke_colorIf true, then use the current stroke color If false, then use the current fill color.

Reimplemented in a2dDcDrawer.

Definition at line 3090 of file drawer2d.cpp.

void a2dDrawer2D::DeviceDrawVerticalLine ( int  x1,
int  y1,
int  y2,
bool  use_stroke_color 
)
protectedvirtual

Draw a pixel-width, unstroked vertical line in device (pixel) coordinates.

This method is useful for implementing low level fill routines.
Parameters
x1x of line
y1y start of line
y2y end of line
use_stroke_colorIf true, then use the current stroke color If false, then use the current fill color.

Reimplemented in a2dDcDrawer.

Definition at line 3095 of file drawer2d.cpp.

double a2dDrawer2D::DeviceToWorldXRel ( double  x) const
inline

convert x relative from device to world coordinates

Use this to convert a length of a line for instance

Definition at line 444 of file drawer2d.h.

double a2dDrawer2D::DeviceToWorldYRel ( double  y) const
inline

convert y relative from device to world coordinates

Use this to convert a length of a line for instance

Definition at line 449 of file drawer2d.h.

void a2dDrawer2D::DrawCenterRoundedRectangle ( double  xc,
double  yc,
double  width,
double  height,
double  radius,
bool  pixelsize = false 
)
virtual

Draw CenterRoundedRectangle in world coordinates.

Draws a rounded rectangle centered at the point (xc,yc) in world coordinates.

Reimplemented in a2dBlindDrawer2D.

Definition at line 2040 of file drawer2d.cpp.

virtual void a2dDrawer2D::DrawCharDc ( wxChar  c)
inlineprotectedvirtual

Draw a dc character.

This is an internal function, used by DrawTextDc This function assumes that the affine matrix has been set up by the calling function in such a way, that the (0,0) coordinate will match with the lowerleft bbox corner of the character. Also mirroring should be performed by the calling function.

Reimplemented in a2dAggDrawerBase, and a2dDcDrawer.

Definition at line 981 of file drawer2d.h.

void a2dDrawer2D::DrawCharDcCb ( wxChar  c)
inline

Wrapper for DrawCharDc.

See Also
DrawCharStrokeCb

Definition at line 804 of file drawer2d.h.

virtual void a2dDrawer2D::DrawCharFreetype ( wxChar  c)
inlineprotectedvirtual

Draw a freetype character.

This is an internal function, used by DrawTextFreetype This function assumes that the affine matrix has been set up by the calling function in such a way, that the (0,0) coordinate will match with the lowerleft bbox corner of the character. Also mirroring should be performed by the calling function.

Reimplemented in a2dAggDrawerBase, a2dMemDcDrawer, and a2dDcDrawer.

Definition at line 966 of file drawer2d.h.

void a2dDrawer2D::DrawCharFreetypeCb ( wxChar  c)
inline

Wrapper for DrawCharFreetype.

See Also
DrawCharStrokeCb

Definition at line 800 of file drawer2d.h.

void a2dDrawer2D::DrawCharStroke ( wxChar  c)
protectedvirtual

Draw a stroke character.

This is an internal function, used by DrawTextStroke. This function assumes that the affine matrix has been set up by the calling function in such a way, that the (0,0) coordinate will match with the lowerleft bbox corner of the character. Also mirroring should be performed by the calling function.

Reimplemented in a2dAggDrawerBase.

Definition at line 2270 of file drawer2d.cpp.

void a2dDrawer2D::DrawCharStrokeCb ( wxChar  c)
inline

Wrapper for DrawCharStroke.

ISO C++ seems(?) to forbid directly calling the address of virtual member functions. Calling &a2dDrawer2D::DrawCharStroke refers to the actual function in a2dDrawer2D and does not refer to the virtual function. Calling &(this->DrawCharStroke) should refer to the virtual function and is accepted by some compilers (MSVC, gcc <3.3), but according to gcc 3.4 this is not allowed by ISO C++. Therefore the virtual function is called through this intermediate function

Definition at line 796 of file drawer2d.h.

void a2dDrawer2D::DrawCircle ( double  x,
double  y,
double  radius 
)
virtual

Draw Circle in world coordinates.

Remarks
circle gets rotates and scaled etc. in x and y when required.

Reimplemented in a2dBlindDrawer2D, a2dAggDrawerBase, and a2dDcDrawer.

Definition at line 2116 of file drawer2d.cpp.

void a2dDrawer2D::DrawEllipse ( double  x,
double  y,
double  width,
double  height 
)
virtual

Draw Ellipse in world coordinates.

Remarks
ellipse gets rotates and scaled etc. in x and y when required.

Reimplemented in a2dBlindDrawer2D, a2dAggDrawerBase, and a2dDcDrawer.

Definition at line 2121 of file drawer2d.cpp.

virtual void a2dDrawer2D::DrawImage ( const wxImage &  image,
double  x,
double  y,
double  width,
double  height,
wxUint8  Opacity = 255 
)
pure virtual

Draw wxImage in world coordinates.

Draw the wxImage to the screen in such a manner that the image is mapped into the rectangle defined by points (x-width/2,y-width/2) and (x+width/2,y+height/2) in world coordinates, with the center of the image at (x,y).

Parameters
imageimage to draw
xworld x position of center of image
yworld y position of center of image
widthwidth in world coordinates to map width of image to
heightheight in world coordinates to map height of image to

Implemented in a2dBlindDrawer2D, a2dAggDrawerRgba, a2dAggDrawer, a2dMemDcDrawer, and a2dDcDrawer.

void a2dDrawer2D::DrawImage ( const wxImage &  image,
double  x = 0,
double  y = 0,
wxUint8  Opacity = 255 
)
inline

Draw wxImage in world coordinates.

Equivalent to calling DrawImage(image, x,y, image.GetWidth(),image.GetHeight())

Parameters
imageimage to draw
xworld x position of center of image
yworld y position of center of image

Definition at line 649 of file drawer2d.h.

void a2dDrawer2D::DrawText ( const wxString &  text,
double  x,
double  y,
int  alignment = wxMINX | wxMINY,
bool  Background = true 
)
virtual

Draw text in user coordinates.

Draws text at the given position in user coordinates.

Adding rotation etc. to the user transform matrix makes it possible to draw rotated text.

Parameters
textThe text which should be drawn.
x,yThe position to draw at.
alignmentUse this to align the text (eg. wxMINX | wxMINY). See also a2dFontAlignment.
Backgroundwith or without background rectangle
See Also
SetFont()

Definition at line 2329 of file drawer2d.cpp.

void a2dDrawer2D::DrawTextGeneric ( const wxString &  text,
double  x,
double  y,
void(a2dDrawer2D::*)(wxChar)  drawchar 
)
protected

This function will draw each character separately using the function drawchar. It will also advance and kern the characters, by adjusting the affine matrices. The character will also be checked against the clipbox. This function assumes (0,0) is the lowerleft bbox corner. This function will not draw the background fill.

Parameters
textThe text to be drawn.
xx-Position of the text.
yy-Position of the text.
drawcharA function which will draw a given character.

Definition at line 2291 of file drawer2d.cpp.

void a2dDrawer2D::DrawTextStroke ( const wxString &  text,
double  x,
double  y 
)
protectedvirtual

Draw text in user coordinates, based on a stroke font.

todo what about the style (pixel or not of stroke font )

Definition at line 2245 of file drawer2d.cpp.

void a2dDrawer2D::DrawTextUnknown ( const wxString &  text,
double  x,
double  y,
bool  words = false 
)
protectedvirtual

Draw a cross, indicating an unsupported font type for this drawer.

Draws text at the given position in user coordinates. Adding rotation etc. to that matrix makes it possible to draw rotated text.

Parameters
textdraw unknown text
xx position
yy position
wordsIf false, draw a boxed cross for the whole line. If true, draw a piece of line for each word.

Definition at line 2198 of file drawer2d.cpp.

virtual void a2dDrawer2D::ExtendAndPushClippingRegion ( a2dVertexList points,
bool  spline = false,
wxPolygonFillMode  fillStyle = wxODDEVEN_RULE,
a2dBooleanClip  clipoperation = a2dCLIP_AND 
)
pure virtual

push on stack the current clipping region and extend clipping region

The clipping region will be extended with a polygon to which everything drawn will be clipped.

Implemented in a2dBlindDrawer2D, a2dAggDrawerBase, and a2dDcDrawer.

double a2dDrawer2D::GetDisplayAberration ( ) const
inline

Returns the display aberration of curved shapes.

, The drawing of curved shapes will not deviate more than this from the ideal curve.

Definition at line 244 of file drawer2d.h.

wxUint16 a2dDrawer2D::GetPrimitiveThreshold ( ) const
inline

get drawing threshold

See Also
SetDrawingThreshold

Definition at line 214 of file drawer2d.h.

virtual wxBitmap a2dDrawer2D::GetSubBitmap ( wxRect  sub_rect) const
pure virtual

A way to get parts form the buffer that is drawn into.

Used for freetype text at the moment since it mixes with the colors already there.

Implemented in a2dBlindDrawer2D, a2dAggDrawerRgba, a2dAggDrawer, a2dMemDcDrawer, and a2dDcDrawer.

const a2dAffineMatrix& a2dDrawer2D::GetTransform ( ) const
inline

get the user-to-world transform matrix.

The user-to-world matrix transforms all drawing primitives from user coordinates to world coordinates.

Definition at line 500 of file drawer2d.h.

bool a2dDrawer2D::GetVirtualAreaSet ( ) const
inline

if the virtual area has been set already return true else false.

Use this during initialization of an application.

Definition at line 374 of file drawer2d.h.

bool a2dDrawer2D::IsStroked ( )
inlineprotected

return true if the the drawstyle in combination with the active stroke, does not require stroking

Definition at line 860 of file drawer2d.h.

bool a2dDrawer2D::IsStrokeOnly ( )
inlineprotected

wxART2D_USE_GRAPHICS_CONTEXT

return true if the drawstyle in combination with the active stroke and fill, does not require filling

Definition at line 847 of file drawer2d.h.

void a2dDrawer2D::PushTransform ( const a2dAffineMatrix affine)
virtual

Save the current transform on the affine stack and then multiply it by the given affine.

This is a convenience function that is equivalent to calling

PushTransform(); Transform(affine);

Definition at line 459 of file drawer2d.cpp.

void a2dDrawer2D::ResetStyle ( )
virtual

set a pre-defined style reseting cashed values.

setting a style ( stroke fill ) for a a2dDrawer2D, takes into account the style that is currently set for it. If the style being set is equal to the current style, internal nothing is done for the underlying device. Of course this only works if everyone obeys the rules. Routines not using a2dDrawer2D as an entry to device, may fool this trick. Therefore to be sure to start with a proper a2dDrawer2D, first call this function. It will make the a2dDrawer2D style the actual style used on the device.

Reimplemented in a2dBlindDrawer2D, a2dAggDrawerBase, and a2dDcDrawer.

Definition at line 545 of file drawer2d.cpp.

void a2dDrawer2D::ReStoreFixedStyle ( )

when fixed drawing style is set, it can be overruled.

The last fixed style stroke and fill are restored.

Definition at line 711 of file drawer2d.cpp.

void a2dDrawer2D::SetActiveFill ( const a2dFill fill)
protectedvirtual

sync with actual API graphical context

The fill is set to the API that is doing the actual drawing. Depending on the API the m_drawStyle should be taken into account, if it does not already yield for any stroke set by SetDrawStyle()

Definition at line 633 of file drawer2d.cpp.

void a2dDrawer2D::SetActiveStroke ( const a2dStroke stroke)
protectedvirtual

sync with actual API graphical context

The stroke is set to the API that is doing the actual drawing. Depending on the API the m_drawStyle should be taken into account, if it does not already yield for any stroke set by SetDrawStyle()

Definition at line 581 of file drawer2d.cpp.

virtual void a2dDrawer2D::SetBufferSize ( int  w,
int  h 
)
pure virtual

Change the buffer size.

Remarks
SetMappingDeviceRect() is NOT reset.

Implemented in a2dBlindDrawer2D, a2dAggDrawerRgba, a2dAggDrawer, a2dMemDcDrawer, and a2dDcDrawer.

void a2dDrawer2D::SetDisableDrawing ( bool  disableDrawing)
inline

when set, all drawing functions return immediately.

This can be used to render only nested parts of documents. The parent part are drawn from their a2dCanvasObjects, but in reality nothing will be drawn until drawing is enabled for the deeper nested objects.

Definition at line 716 of file drawer2d.h.

void a2dDrawer2D::SetDisplayAberration ( double  aber)
inline

Set the display aberration of curved shapes.

The drawing of curved shapes will not deviate more than this from the ideal curve.

Remarks
the smaller the number the longer the drawing takes.
Parameters
abermaximum deviation in device coordinates

Definition at line 238 of file drawer2d.h.

void a2dDrawer2D::SetDrawerFill ( const a2dFill fill)

Used to set the current fill.

The a2dFill objects are reference counted, so passing a fill pointer allocated with 'new' to this function will not result in a leak.

Definition at line 621 of file drawer2d.cpp.

void a2dDrawer2D::SetDrawerStroke ( const a2dStroke stroke)

Used to set the current stroke.

The a2dStroke objects are reference counted, so passing a stroke pointer allocated with 'new' to this function will not result in a leak.

Definition at line 565 of file drawer2d.cpp.

void a2dDrawer2D::SetDrawStyle ( a2dDrawStyle  drawstyle)

set drawstyle to use for drawing,

The draw style is used for drawing in a certain fashion.

The current fill, stroke are not changed while setting a diffrent drawstyle. Therefore first set the required fill and stroke. Setting a2dFIX_STYLE or a2dFIX_STYLE_INVERT can only be reset using ResetFixedStyle(). Still it can be temprarely overruled with OverRuleFixedStyle() to be restored with ReStoreFixedStyle().

New settings for fill, stroke may or may not have effect in how is drawn, but do change the current fill are stroke, independent of the drawing style. This depends if it makes sense to have a different style when the drawstyle is in action. When drawstyle is set, the last set fill, stroke are made active when needed.

Parameters
drawstyleone of the draw styles

Definition at line 557 of file drawer2d.cpp.

void a2dDrawer2D::SetMappingDeviceRect ( int  mapx,
int  mapy,
int  mapWidth,
int  mapHeight,
bool  remap = false 
)

to change the default mapping (to the complete buffer).

By default the mapping from world coordinates to device coordinates is based on the size of the double buffer. For application where the a2dDrawer2D is used as a double buffered device context within a a2dCanvas window, it is better to oversize the buffer of the a2dDrawer2D. This prevents continuously reallocating/redrawing of the buffer after even the smallest resize. To still keep the mapping to what is visible on the window client window, one can independently from the buffer size set the mapping rectangle. Even a rectangle bigger then the buffer rectangle is possible, but of course the a2dDrawer2D will never draw outside the buffer eventually.

Parameters
remapif true change mapping to

Definition at line 216 of file drawer2d.cpp.

void a2dDrawer2D::SetMappingMatrix ( const a2dAffineMatrix mapping)

set world to device matrix ( better use SetMappingWidthHeight() etc. ) Side ffect m_usertodevice is modified to m_worldtodevice * m_usertoworld

Definition at line 396 of file drawer2d.cpp.

void a2dDrawer2D::SetMappingUpp ( double  vx1,
double  vy1,
double  xpp,
double  ypp 
)

Give the virtual size to be displayed, the mapping matrix will be calculated.

To display all of a drawing, set this here to the boundingbox of the root object of the canvas.

So vx1 and vx2 to the minimum x and y of the boundingbox. Calculate xpp and ypp in such a manner that it will show the whole drawing.

The buffer size or SetMappingDeviceRect() is used when setting the mapping with this function.

Remarks
when a user-to-world matrix SetTransform() is set, the m_usertodevice is recalculated to take the new mapping matrix and the already set user-to-world matrix into account.
Parameters
vx1,:minimum x coordinate of display area
vy1,:minimum y coordinate of display area
xpp,:Number of user units per pixel in x
ypp,:Number of user units per pixel in y

Definition at line 250 of file drawer2d.cpp.

void a2dDrawer2D::SetMappingUpp ( double  x,
double  y,
double  wx,
double  wy,
double  vx1,
double  vy1,
double  xpp,
double  ypp 
)
protected

Given the rectangle in world coordinate to be displayed, update the mappingmatrix.

To display all of a drawing, set this to the bounding box of the root object of the canvas.

So vx1 and vx2 to the minimum x and y of the bounding box. Calculate xpp and ypp in such a manner that it will show the whole drawing.

The buffer size or SetMappingDeviceRect() are not used when setting the mapping with this function. In fact all other mapping functions in a2dDrawer2D use this function to set the mapping for the a2dDrawer2D in the end.

Remarks
when a relative world matrix SetTransform() is set, the m_usertodevice is recalculated to take the new mapping matrix and the already set user matrix into account.
Parameters
x,:map to device x (non zero if canvas window is smaller than drawer)
y,:map to device y (non zero if canvas window is smaller than drawer)
wx,:map to device of this size in x, normally same as width of buffer bitmap
wy,:map to device of this size in y, normally same as height of buffer bitmap
vx1,:minimum x coordinate of display area
vy1,:minimum y coordinate of display area
xpp,:Number of world units per pixel in x
ypp,:Number of world units per pixel in y

transformation from world to device coordinates

Definition at line 257 of file drawer2d.cpp.

void a2dDrawer2D::SetMappingWidthHeight ( double  vx1,
double  vy1,
double  width,
double  height 
)
virtual

Give the virtual size to be displayed, the mapping matrix will be calculated.

The current buffer size is used to calculate how to at least display all of the area given.

See Also
SetMappingDeviceRect to map to a different device/buffer rectangle.
Remarks
do not use during start up since window/buffer size is not well defined in that case resulting in
bad settings for the mapping.
Parameters
vx1,:minimum x coordinate of display area
vy1,:minimum y coordinate of display area
width,:width of displayed area in world coordinates
height,:height of displayed area in world coordinates

Definition at line 333 of file drawer2d.cpp.

void a2dDrawer2D::SetMappingWidthHeight ( const a2dBoundingBox box)

Give the virtual size to be displayed, the mapping matrix will be calculated.

The current buffer size is used to calculate how to at least display all of the area given.

Remarks
do not use during start up since window/buffer size is not well defined in that case resulting in
bad settings for the mapping.
See Also
SetMappingDeviceRect to map to a different device/buffer rectangle.
Parameters
boxa boundingbox to set mapping

Definition at line 358 of file drawer2d.cpp.

void a2dDrawer2D::SetOpacityFactor ( wxUint8  OpacityFactor)

when enabling m_useOpacityFactor, this is how transparent

Parameters
OpacityFactorReal opacity is set opacity * m_OpacityFactor/255

Definition at line 550 of file drawer2d.cpp.

void a2dDrawer2D::SetSmallTextThreshold ( wxUint16  pixels)
inline

set device text size at which textdrawing will switch to device specific text drawing. Small text will only be drawn correctly, when fitting text to pixels. For bigger text it is no problem, so at a certain size one switches to device specific drawing of text. only works if m_forceNormalizedFont = false;

Definition at line 576 of file drawer2d.h.

void a2dDrawer2D::SetSplineAberration ( double  aber)

Set the detail level for spline drawing.

Parameters
aberAccuracy in world coordinates

Definition at line 195 of file drawer2d.cpp.

void a2dDrawer2D::SetTransform ( const a2dAffineMatrix userToWorld)
virtual

set user-to-world transform matrix.

Sets the current user-to-world transform matrix at the top of the transform stack. The user-to-world matrix transforms all drawing primitives from user coordinates to world coordinates.

Parameters
userToWorldThe matrix for transforming from user to world.

Definition at line 446 of file drawer2d.cpp.

void a2dDrawer2D::StartRefreshDisplayDisable ( )
inline

when called a mapping change will result not result in a refresh of the m_display.

m_refreshDisplay is incremented, and EndRefreshDisplayDisable() does decrement it. When m_refreshDisplay > 0 no refresh is done when changing mapping.

Used to prevent looping and unneeded refresh when changing mapping several times within a function.

Definition at line 383 of file drawer2d.h.

int a2dDrawer2D::WorldToDeviceXRel ( double  x) const
inline

convert x relative from world to device coordinates

Use this to convert a length of a line for instance

Definition at line 460 of file drawer2d.h.

double a2dDrawer2D::WorldToDeviceXRelNoRnd ( double  x) const
inline

convert x relative from world to device coordinates (result not rounded to integer)

Use this to convert a length of a line for instance

Definition at line 470 of file drawer2d.h.

int a2dDrawer2D::WorldToDeviceYRel ( double  y) const
inline

convert y relative from world to device coordinates

Use this to convert a length of a line for instance

Definition at line 465 of file drawer2d.h.

double a2dDrawer2D::WorldToDeviceYRelNoRnd ( double  y) const
inline

convert y relative from world to device coordinates (result not rounded to integer)

Use this to convert a length of a line for instance

Definition at line 475 of file drawer2d.h.

Member Data Documentation

std::vector<a2dAffineMatrix> a2dDrawer2D::m_affineStack
protected

Affine transform stack.

The stack actually is a double stack, for both m_relativetransform and m_usertodevice This prevents some additional affine matrix multiplications. The stack is implemented as a 'fixed' array, preventing (slow) dynamic memory allocation.

Definition at line 1218 of file drawer2d.h.

const a2dSignal a2dDrawer2D::sig_changedZoom = wxNewId()
static

id for changed zoom sent from a2dDrawer2D to a2dEventDistributer when zoom has changed.

Definition at line 1232 of file drawer2d.h.


The documentation for this class was generated from the following files:
a2dDrawer2D Class Reference -- Sun Oct 12 2014 17:04:36 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation