35#include <wx/dcbuffer.h>
68 void DrawLine(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint )
override;
72 double aWidth )
override;
75 void DrawCircle(
const VECTOR2D& aCenterPoint,
double aRadius )
override;
78 void DrawHoleWall(
const VECTOR2D& aCenterPoint,
double aHoleRadius,
79 double aWallWidth )
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 DrawEllipse(
const VECTOR2D& aCenterPoint,
double aMajorRadius,
double aMinorRadius,
95 void DrawEllipseArc(
const VECTOR2D& aCenterPoint,
double aMajorRadius,
double aMinorRadius,
100 void DrawRectangle(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint )
override;
103 void DrawSegmentChain(
const std::vector<VECTOR2D>& aPointList,
double aWidth )
override;
104 void DrawSegmentChain(
const SHAPE_LINE_CHAIN& aLineChain,
double aWidth )
override;
116 void DrawPolylines(
const std::vector<std::vector<VECTOR2D>>& aPointLists )
override
118 for(
const std::vector<VECTOR2D>& points : aPointLists )
129 void DrawPolygon(
const SHAPE_POLY_SET& aPolySet,
bool aStrokeTriangulation =
false )
override;
133 void DrawGlyph(
const KIFONT::GLYPH& aPolySet,
int aNth,
int aTotal )
override;
136 void DrawGlyphs(
const std::vector<std::unique_ptr<KIFONT::GLYPH>>& aGlyphs )
override
138 for(
size_t i = 0; i < aGlyphs.size(); i++ )
139 DrawGlyph( *aGlyphs[i], i, aGlyphs.size() );
145 double aFilterValue = 0.0 )
override;
148 void DrawBitmap(
const BITMAP_BASE& aBitmap,
double alphaBlend = 1.0 )
override;
155 void ResizeScreen(
int aWidth,
int aHeight )
override;
158 void Flush()
override;
161 void ClearScreen()
override;
168 void SetIsFill(
bool aIsFillEnabled )
override;
171 void SetIsStroke(
bool aIsStrokeEnabled )
override;
174 void SetStrokeColor(
const COLOR4D& aColor )
override;
177 void SetFillColor(
const COLOR4D& aColor )
override;
180 void SetLineWidth(
float aLineWidth )
override;
183 void SetLayerDepth(
double aLayerDepth )
override;
190 void Transform(
const MATRIX3x3D& aTransformation )
override;
193 void Rotate(
double aAngle )
override;
196 void Translate(
const VECTOR2D& aTranslation )
override;
199 void Scale(
const VECTOR2D& aScale )
override;
202 void Save()
override;
205 void Restore()
override;
212 int BeginGroup()
override;
215 void EndGroup()
override;
218 void DrawGroup(
int aGroupNumber )
override;
221 void ChangeGroupColor(
int aGroupNumber,
const COLOR4D& aNewColor )
override;
224 void ChangeGroupDepth(
int aGroupNumber,
int aDepth )
override;
227 void DeleteGroup(
int aGroupNumber )
override;
230 void ClearCache()
override;
237 void SetNegativeDrawMode(
bool aSetting )
override;
244 void DrawCursor(
const VECTOR2D& aCursorPosition )
override;
246 void EnableDepthTest(
bool aEnabled =
false )
override;
249 void DrawGrid()
override;
252 void BeginDrawing()
override;
255 void EndDrawing()
override;
260 double xform(
double x );
261 const VECTOR2D xform(
double x,
double y );
270 double angle_xform(
double aAngle );
279 void arc_angles_xform_and_normalize(
double& aStartAngle,
double& aEndAngle );
289 void drawGridLine(
const VECTOR2D& aStartPoint,
const VECTOR2D& aEndPoint );
290 void drawGridCross(
const VECTOR2D& aPoint );
291 void drawGridPoint(
const VECTOR2D& aPoint,
double aWidth,
double aHeight );
301 void blitCursor( wxMemoryDC& clientDC );
304 void drawPoly(
const std::deque<VECTOR2D>& aPointList );
305 void drawPoly(
const std::vector<VECTOR2D>& aPointList );
306 void drawPoly(
const VECTOR2D aPointList[],
int aListSize );
314 unsigned int getNewGroupNumber();
316 void syncLineWidth(
bool aForceWidth =
false,
double aWidth = 0.0 );
317 void updateWorldScreenMatrix();
357 typedef std::deque<GROUP_ELEMENT>
GROUP;
381 static constexpr cairo_format_t
GAL_FORMAT = CAIRO_FORMAT_ARGB32;
400 wxEvtHandler* aMouseListener =
nullptr, wxEvtHandler* aPaintListener =
nullptr,
401 const wxString& aName = wxT(
"CairoCanvas" ) );
408 return IsShownOnScreen() && !GetClientRect().IsEmpty();
411 void ResizeScreen(
int aWidth,
int aHeight )
override;
413 bool Show(
bool aShow )
override;
415 int BeginGroup()
override;
417 void EndGroup()
override;
426 void StartDiffLayer()
override;
429 void EndDiffLayer()
override;
432 void StartNegativesLayer()
override;
435 void EndNegativesLayer()
override;
443 void PostPaint( wxPaintEvent& aEvent );
456 bool SetNativeCursorStyle(
KICURSOR aCursor,
bool aHiDPI )
override;
459 void BeginDrawing()
override;
462 void EndDrawing()
override;
468 void deinitSurface();
471 void allocateBitmaps();
474 void deleteBitmaps();
477 void setCompositor();
485 void onPaint( wxPaintEvent& aEvent );
492 void skipMouseEvent( wxMouseEvent& aEvent );
499 void skipGestureEvent( wxGestureEvent& aEvent );
506 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