39#include <wx/dcbuffer.h>
56class CAIRO_COMPOSITOR;
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 DrawArc(
const VECTOR2D& aCenterPoint,
double aRadius,
const EDA_ANGLE& aStartAngle,
87 void DrawArcSegment(
const VECTOR2D& aCenterPoint,
double aRadius,
const EDA_ANGLE& aStartAngle,
88 const EDA_ANGLE& aAngle,
double aWidth,
double aMaxError )
override;
91 void DrawRectangle(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint )
override;
94 void DrawSegmentChain(
const std::vector<VECTOR2D>& aPointList,
double aWidth )
override;
95 void DrawSegmentChain(
const SHAPE_LINE_CHAIN& aLineChain,
double aWidth )
override;
98 void DrawPolyline(
const std::deque<VECTOR2D>& aPointList )
override { drawPoly( aPointList ); }
101 drawPoly( aPointList, aListSize );
107 void DrawPolylines(
const std::vector<std::vector<VECTOR2D>>& aPointLists )
override
109 for(
const std::vector<VECTOR2D>& points : aPointLists )
114 void DrawPolygon(
const std::deque<VECTOR2D>& aPointList )
override { drawPoly( aPointList ); }
117 drawPoly( aPointList, aListSize );
120 void DrawPolygon(
const SHAPE_POLY_SET& aPolySet,
bool aStrokeTriangulation =
false )
override;
124 void DrawGlyph(
const KIFONT::GLYPH& aPolySet,
int aNth,
int aTotal )
override;
127 void DrawGlyphs(
const std::vector<std::unique_ptr<KIFONT::GLYPH>>& aGlyphs )
override
129 for(
size_t i = 0; i < aGlyphs.size(); i++ )
130 DrawGlyph( *aGlyphs[i], i, aGlyphs.size() );
136 double aFilterValue = 0.0 )
override;
139 void DrawBitmap(
const BITMAP_BASE& aBitmap,
double alphaBlend = 1.0 )
override;
146 void ResizeScreen(
int aWidth,
int aHeight )
override;
149 void Flush()
override;
152 void ClearScreen()
override;
159 void SetIsFill(
bool aIsFillEnabled )
override;
162 void SetIsStroke(
bool aIsStrokeEnabled )
override;
165 void SetStrokeColor(
const COLOR4D& aColor )
override;
168 void SetFillColor(
const COLOR4D& aColor )
override;
171 void SetLineWidth(
float aLineWidth )
override;
174 void SetLayerDepth(
double aLayerDepth )
override;
181 void Transform(
const MATRIX3x3D& aTransformation )
override;
184 void Rotate(
double aAngle )
override;
187 void Translate(
const VECTOR2D& aTranslation )
override;
190 void Scale(
const VECTOR2D& aScale )
override;
193 void Save()
override;
196 void Restore()
override;
203 int BeginGroup()
override;
206 void EndGroup()
override;
209 void DrawGroup(
int aGroupNumber )
override;
212 void ChangeGroupColor(
int aGroupNumber,
const COLOR4D& aNewColor )
override;
215 void ChangeGroupDepth(
int aGroupNumber,
int aDepth )
override;
218 void DeleteGroup(
int aGroupNumber )
override;
221 void ClearCache()
override;
228 void SetNegativeDrawMode(
bool aSetting )
override;
235 void DrawCursor(
const VECTOR2D& aCursorPosition )
override;
237 void EnableDepthTest(
bool aEnabled =
false )
override;
240 void DrawGrid()
override;
243 void BeginDrawing()
override;
246 void EndDrawing()
override;
251 double xform(
double x );
252 const VECTOR2D xform(
double x,
double y );
264 double angle_xform(
double aAngle );
273 void arc_angles_xform_and_normalize(
double& aStartAngle,
double& aEndAngle );
283 void drawGridLine(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint );
284 void drawGridCross(
const VECTOR2D& aPoint );
285 void drawGridPoint(
const VECTOR2D& aPoint,
double aWidth,
double aHeight );
295 void blitCursor( wxMemoryDC& clientDC );
298 void drawPoly(
const std::deque<VECTOR2D>& aPointList );
299 void drawPoly(
const std::vector<VECTOR2D>& aPointList );
300 void drawPoly(
const VECTOR2D aPointList[],
int aListSize );
308 unsigned int getNewGroupNumber();
310 void syncLineWidth(
bool aForceWidth =
false,
double aWidth = 0.0 );
311 void updateWorldScreenMatrix();
318 static const int MAX_CAIRO_ARGUMENTS = 4;
344 double DblArg[MAX_CAIRO_ARGUMENTS];
348 cairo_path_t* m_CairoPath =
nullptr;
351 typedef std::deque<GROUP_ELEMENT>
GROUP;
375 static constexpr cairo_format_t GAL_FORMAT = CAIRO_FORMAT_ARGB32;
394 wxEvtHandler* aMouseListener =
nullptr, wxEvtHandler* aPaintListener =
nullptr,
395 const wxString& aName = wxT(
"CairoCanvas" ) );
402 return IsShownOnScreen() && !GetClientRect().IsEmpty();
405 void ResizeScreen(
int aWidth,
int aHeight )
override;
407 bool Show(
bool aShow )
override;
409 int BeginGroup()
override;
411 void EndGroup()
override;
420 void StartDiffLayer()
override;
423 void EndDiffLayer()
override;
426 void StartNegativesLayer()
override;
429 void EndNegativesLayer()
override;
437 void PostPaint( wxPaintEvent& aEvent );
441 m_mouseListener = aMouseListener;
446 m_paintListener = aPaintListener;
450 bool SetNativeCursorStyle(
KICURSOR aCursor,
bool aHiDPI )
override;
453 void BeginDrawing()
override;
456 void EndDrawing()
override;
464 void deinitSurface();
467 void allocateBitmaps();
470 void deleteBitmaps();
473 void setCompositor();
481 void onPaint( wxPaintEvent& aEvent );
488 void skipMouseEvent( wxMouseEvent& aEvent );
495 void skipGestureEvent( wxGestureEvent& aEvent );
502 void onSetNativeCursor( wxSetCursorEvent& aEvent );
508 double getScalingFactor()
override;
static double roundp(double x)
This class handle bitmap images in KiCad.
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.
virtual double getScalingFactor()
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.
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 ?
cairo_matrix_t m_currentXform
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_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
wxCursor m_currentwxCursor
wxCursor showing the current native cursor
unsigned int m_overlayBuffer
Handle to the overlay buffer.
unsigned int m_bufferSize
Size of buffers cairoOutput, bitmapBuffers.
void SetPaintListener(wxEvtHandler *aPaintListener)
void SetMouseListener(wxEvtHandler *aMouseListener)
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.
wxBitmap * m_wxBitmap
Output buffer bitmap.
std::shared_ptr< CAIRO_COMPOSITOR > m_compositor
Object for layers compositing.
unsigned int m_savedBuffer
Handle to buffer to restore after rendering to temp buffer.
A color representation with 4 components: red, green, blue, alpha.
Abstract interface for drawing on a 2D-surface.
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.
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.
bool BoolArg
A bool argument.