39#include <wx/dcbuffer.h>
72 void DrawLine(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint )
override;
76 double aWidth )
override;
79 void DrawCircle(
const VECTOR2D& aCenterPoint,
double aRadius )
override;
82 void DrawHoleWall(
const VECTOR2D& aCenterPoint,
double aHoleRadius,
83 double aWallWidth )
override;
86 void DrawArc(
const VECTOR2D& aCenterPoint,
double aRadius,
const EDA_ANGLE& aStartAngle,
91 void DrawArcSegment(
const VECTOR2D& aCenterPoint,
double aRadius,
const EDA_ANGLE& aStartAngle,
92 const EDA_ANGLE& aAngle,
double aWidth,
double aMaxError )
override;
95 void DrawEllipse(
const VECTOR2D& aCenterPoint,
double aMajorRadius,
double aMinorRadius,
99 void DrawEllipseArc(
const VECTOR2D& aCenterPoint,
double aMajorRadius,
double aMinorRadius,
104 void DrawRectangle(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint )
override;
107 void DrawSegmentChain(
const std::vector<VECTOR2D>& aPointList,
double aWidth )
override;
108 void DrawSegmentChain(
const SHAPE_LINE_CHAIN& aLineChain,
double aWidth )
override;
120 void DrawPolylines(
const std::vector<std::vector<VECTOR2D>>& aPointLists )
override
122 for(
const std::vector<VECTOR2D>& points : aPointLists )
133 void DrawPolygon(
const SHAPE_POLY_SET& aPolySet,
bool aStrokeTriangulation =
false )
override;
137 void DrawGlyph(
const KIFONT::GLYPH& aPolySet,
int aNth,
int aTotal )
override;
140 void DrawGlyphs(
const std::vector<std::unique_ptr<KIFONT::GLYPH>>& aGlyphs )
override
142 for(
size_t i = 0; i < aGlyphs.size(); i++ )
143 DrawGlyph( *aGlyphs[i], i, aGlyphs.size() );
149 double aFilterValue = 0.0 )
override;
152 void DrawBitmap(
const BITMAP_BASE& aBitmap,
double alphaBlend = 1.0 )
override;
159 void ResizeScreen(
int aWidth,
int aHeight )
override;
162 void Flush()
override;
165 void ClearScreen()
override;
172 void SetIsFill(
bool aIsFillEnabled )
override;
175 void SetIsStroke(
bool aIsStrokeEnabled )
override;
178 void SetStrokeColor(
const COLOR4D& aColor )
override;
181 void SetFillColor(
const COLOR4D& aColor )
override;
184 void SetLineWidth(
float aLineWidth )
override;
187 void SetLayerDepth(
double aLayerDepth )
override;
194 void Transform(
const MATRIX3x3D& aTransformation )
override;
197 void Rotate(
double aAngle )
override;
200 void Translate(
const VECTOR2D& aTranslation )
override;
203 void Scale(
const VECTOR2D& aScale )
override;
206 void Save()
override;
209 void Restore()
override;
216 int BeginGroup()
override;
219 void EndGroup()
override;
222 void DrawGroup(
int aGroupNumber )
override;
225 void ChangeGroupColor(
int aGroupNumber,
const COLOR4D& aNewColor )
override;
228 void ChangeGroupDepth(
int aGroupNumber,
int aDepth )
override;
231 void DeleteGroup(
int aGroupNumber )
override;
234 void ClearCache()
override;
241 void SetNegativeDrawMode(
bool aSetting )
override;
248 void DrawCursor(
const VECTOR2D& aCursorPosition )
override;
250 void EnableDepthTest(
bool aEnabled =
false )
override;
253 void DrawGrid()
override;
256 void BeginDrawing()
override;
259 void EndDrawing()
override;
264 double xform(
double x );
265 const VECTOR2D xform(
double x,
double y );
274 double angle_xform(
double aAngle );
283 void arc_angles_xform_and_normalize(
double& aStartAngle,
double& aEndAngle );
293 void drawGridLine(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint );
294 void drawGridCross(
const VECTOR2D& aPoint );
295 void drawGridPoint(
const VECTOR2D& aPoint,
double aWidth,
double aHeight );
305 void blitCursor( wxMemoryDC& clientDC );
308 void drawPoly(
const std::deque<VECTOR2D>& aPointList );
309 void drawPoly(
const std::vector<VECTOR2D>& aPointList );
310 void drawPoly(
const VECTOR2D aPointList[],
int aListSize );
318 unsigned int getNewGroupNumber();
320 void syncLineWidth(
bool aForceWidth =
false,
double aWidth = 0.0 );
321 void updateWorldScreenMatrix();
361 typedef std::deque<GROUP_ELEMENT>
GROUP;
385 static constexpr cairo_format_t
GAL_FORMAT = CAIRO_FORMAT_ARGB32;
404 wxEvtHandler* aMouseListener =
nullptr, wxEvtHandler* aPaintListener =
nullptr,
405 const wxString& aName = wxT(
"CairoCanvas" ) );
412 return IsShownOnScreen() && !GetClientRect().IsEmpty();
415 void ResizeScreen(
int aWidth,
int aHeight )
override;
417 bool Show(
bool aShow )
override;
419 int BeginGroup()
override;
421 void EndGroup()
override;
430 void StartDiffLayer()
override;
433 void EndDiffLayer()
override;
436 void StartNegativesLayer()
override;
439 void EndNegativesLayer()
override;
447 void PostPaint( wxPaintEvent& aEvent );
460 bool SetNativeCursorStyle(
KICURSOR aCursor,
bool aHiDPI )
override;
463 void BeginDrawing()
override;
466 void EndDrawing()
override;
472 void deinitSurface();
475 void allocateBitmaps();
478 void deleteBitmaps();
481 void setCompositor();
489 void onPaint( wxPaintEvent& aEvent );
496 void skipMouseEvent( wxMouseEvent& aEvent );
503 void skipGestureEvent( wxGestureEvent& aEvent );
510 void onSetNativeCursor( wxSetCursorEvent& aEvent );
static double roundp(double x)
This class handle bitmap images in KiCad.
void DrawGlyph(const KIFONT::GLYPH &aPolySet, int aNth, int aTotal) override
Draw a polygon representing a font glyph.
cairo_surface_t * m_surface
Cairo surface.
void DrawPolyline(const std::deque< VECTOR2D > &aPointList) override
Draw a polyline.
GAL super
Super class definition.
cairo_matrix_t m_cairoWorldScreenMatrix
Cairo world to screen transform matrix.
unsigned int m_groupCounter
Counter used for generating group keys.
bool m_isElementAdded
Was an graphic element added ?
std::deque< GROUP_ELEMENT > GROUP
A graphic group type definition.
bool IsCairoEngine() override
Return true if the GAL engine is a Cairo based type.
void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs) override
Draw polygons representing font glyphs.
CAIRO_GAL_BASE(GAL_DISPLAY_OPTIONS &aDisplayOptions)
std::vector< cairo_surface_t * > m_imageSurfaces
List of surfaces that were created by painting images, to be cleaned up later.
GROUP * m_currentGroup
Currently used group.
bool m_isGrouping
Is grouping enabled ?
static constexpr cairo_format_t GAL_FORMAT
Format used to store pixels.
cairo_matrix_t m_currentXform
static const int MAX_CAIRO_ARGUMENTS
Maximum number of arguments for one command.
void drawPoly(const std::deque< VECTOR2D > &aPointList)
Drawing polygons & polylines is the same in Cairo, so here is the common code.
void DrawPolygon(const VECTOR2D aPointList[], int aListSize) override
std::map< int, GROUP > m_groups
List of graphic groups.
cairo_t * m_context
Cairo image.
void DrawPolylines(const std::vector< std::vector< VECTOR2D > > &aPointLists) override
Draw multiple polylines.
void DrawPolyline(const SHAPE_LINE_CHAIN &aLineChain) override
std::vector< cairo_matrix_t > m_xformStack
void DrawPolyline(const VECTOR2D aPointList[], int aListSize) override
void DrawPolygon(const std::deque< VECTOR2D > &aPointList) override
Draw a polygon.
cairo_matrix_t m_currentWorld2Screen
cairo_t * m_currentContext
Currently used Cairo context for drawing.
GRAPHICS_COMMAND
Definitions for the command recorder.
@ CMD_SET_STROKE
Enable/disable stroking.
@ CMD_SAVE
Save the transformation matrix.
@ CMD_SCALE
Scale the context.
@ CMD_SET_LINE_WIDTH
Set the line width.
@ CMD_SET_FILL
Enable/disable filling.
@ CMD_CALL_GROUP
Call a group.
@ CMD_ROTATE
Rotate the context.
@ CMD_STROKE_PATH
Set the stroke path.
@ CMD_TRANSLATE
Translate the context.
@ CMD_SET_FILLCOLOR
Set the fill color.
@ CMD_FILL_PATH
Set the fill path.
@ CMD_RESTORE
Restore the transformation matrix.
@ CMD_SET_STROKECOLOR
Set the stroke color.
double m_lineWidthInPixels
unsigned int m_overlayBuffer
Handle to the overlay buffer.
unsigned int m_bufferSize
Size of buffers cairoOutput, bitmapBuffers.
CAIRO_GAL(GAL_DISPLAY_OPTIONS &aDisplayOptions, wxWindow *aParent, wxEvtHandler *aMouseListener=nullptr, wxEvtHandler *aPaintListener=nullptr, const wxString &aName=wxT("CairoCanvas"))
void SetPaintListener(wxEvtHandler *aPaintListener)
void SetMouseListener(wxEvtHandler *aMouseListener)
unsigned char * m_wxOutput
wxImage compatible buffer
bool m_isInitialized
Are Cairo image & surface ready to use.
bool m_validCompositor
Compositor initialization flag.
unsigned int m_mainBuffer
Handle to the main buffer.
int m_stride
Stride value for Cairo.
COLOR4D m_backgroundColor
Background color.
unsigned char * m_bitmapBuffer
Storage of the Cairo image.
wxEvtHandler * m_mouseListener
Mouse listener.
wxEvtHandler * m_paintListener
Paint listener.
bool IsVisible() const override
Return true if the GAL canvas is visible on the screen.
unsigned int m_tempBuffer
Handle to the temp buffer.
RENDER_TARGET m_currentTarget
Current rendering target.
wxWindow * m_parentWindow
Parent window.
std::shared_ptr< CAIRO_COMPOSITOR > m_compositor
Object for layers compositing.
WX_CURSOR_TYPE m_currentwxCursor
wx cursor showing the current native cursor
unsigned int m_savedBuffer
Handle to buffer to restore after rendering to temp buffer.
A color representation with 4 components: red, green, blue, alpha.
GAL(GAL_DISPLAY_OPTIONS &aOptions)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
wxCursor WX_CURSOR_TYPE
Represents either a wxCursorBundle for wx 3.3+ or a wxCursor for older versions.
MATRIX3x3< double > MATRIX3x3D
The Cairo implementation of the graphics abstraction layer.
RENDER_TARGET
RENDER_TARGET: Possible rendering targets.
void DrawSegment(const ROUND_SEGMENT_2D &aSegment, unsigned int aNrSidesPerCircle)
Draw a thick line segment with rounded ends.
Type definition for an graphics group element.
GRAPHICS_COMMAND m_Command
Command to execute.
cairo_path_t * m_CairoPath
Pointer to a Cairo path.
double DblArg[MAX_CAIRO_ARGUMENTS]
Arguments for Cairo commands.
bool BoolArg
A bool argument.
int IntArg
An int argument.
VECTOR2< double > VECTOR2D