28#include <wx/dcclient.h>
88 cairo_surface_destroy( imageSurface );
135 world_rotation =
M_PI - world_rotation;
137 return std::fmod( aAngle + world_rotation, 2.0 *
M_PI );
144 bool is_360deg_arc =
std::abs( aEndAngle - aStartAngle ) >= 2 *
M_PI;
145 double startAngle = aStartAngle;
146 double endAngle = aEndAngle;
152 startAngle =
M_PI - startAngle;
153 endAngle =
M_PI - endAngle;
169 aEndAngle = aStartAngle + 2 *
M_PI;
179 return sqrt( dx * dx + dy * dy );
185 return floor( x + 0.5 ) + 0.5;
194 return VECTOR2D( floor( v.
x + 0.5 ), floor( v.
y + 0.5 ) );
238 for(
size_t i = 0; i + 1 < aPointList.size(); ++i )
239 DrawSegment( aPointList[i], aPointList[i + 1], aWidth );
250 for(
int i = 0; i + 1 < numPoints; ++i )
278 VECTOR2D startEndVector = aEndPoint - aStartPoint;
279 double lineAngle = atan2( startEndVector.
y, startEndVector.
x );
281 double sa = sin( lineAngle +
M_PI / 2.0 );
282 double ca = cos( lineAngle +
M_PI / 2.0 );
302 startEndVector = center_b - center_a;
303 lineAngle = atan2( startEndVector.
y, startEndVector.
x );
304 double radius = ( pa0 - center_a ).EuclideanNorm();
307 double arcStartAngle = lineAngle -
M_PI / 2.0;
309 arcStartAngle +
M_PI );
312 arcStartAngle = lineAngle +
M_PI / 2.0;
314 arcStartAngle +
M_PI );
325 DrawCircle( aCenterPoint, aRadius + aWallWidth );
350 double startAngle = aStartAngle.
AsRadians();
351 double endAngle = startAngle + aAngle.
AsRadians();
357 double r =
xform( aRadius );
370 r = ( ( refStart - mid ).EuclideanNorm() + ( refEnd - mid ).EuclideanNorm() ) / 2.0;
391 double aWidth,
double aMaxError )
399 DrawArc( aCenterPoint, aRadius, aStartAngle, aAngle );
409 double startAngleS = aStartAngle.
AsRadians();
410 double endAngleS = startAngleS + aAngle.
AsRadians();
413 double r =
xform( aRadius );
416 double width =
xform( aWidth / 2.0 );
436 cairo_arc_negative(
m_currentContext, startPointS.
x, startPointS.
y, width, startAngleS,
437 startAngleS +
M_PI );
490 double startAngle = aStartAngle.
AsRadians();
558 double aFilterValue )
582 alphaBlend = std::clamp( alphaBlend, 0.0, 1.0 );
598 cairo_surface_t*
image = cairo_image_surface_create( CAIRO_FORMAT_ARGB32, w, h );
599 cairo_surface_flush(
image );
601 unsigned char* pix_buffer = cairo_image_surface_get_data(
image );
606 uint32_t mask_color = ( bm_pix_buffer.GetMaskRed() << 16 )
607 + ( bm_pix_buffer.GetMaskGreen() << 8 ) + ( bm_pix_buffer.GetMaskBlue() );
612 for(
int row = 0; row < h; row++ )
614 for(
int col = 0; col < w; col++ )
616 unsigned char r = bm_pix_buffer.GetRed( col, row );
617 unsigned char g = bm_pix_buffer.GetGreen( col, row );
618 unsigned char b = bm_pix_buffer.GetBlue( col, row );
619 unsigned char a = wxALPHA_OPAQUE;
621 if( bm_pix_buffer.HasAlpha() )
623 a = bm_pix_buffer.GetAlpha( col, row );
626 r = uint32_t( r ) * a / 0xFF;
627 g = uint32_t( g ) * a / 0xFF;
628 b = uint32_t( b ) * a / 0xFF;
630 else if( bm_pix_buffer.HasMask() && (uint32_t)( r << 16 | g << 8 | b ) == mask_color )
632 a = wxALPHA_TRANSPARENT;
636 uint32_t pixel = a << 24 | r << 16 | g << 8 | b;
639 uint32_t* pix_ptr = (uint32_t*) pix_buffer;
645 cairo_surface_mark_dirty(
image );
775 cairo_matrix_t cairoTransformation, newXform;
777 cairo_matrix_init( &cairoTransformation, aTransformation.
m_data[0][0],
778 aTransformation.
m_data[1][0], aTransformation.
m_data[0][1],
779 aTransformation.
m_data[1][1], aTransformation.
m_data[0][2],
780 aTransformation.
m_data[1][2] );
782 cairo_matrix_multiply( &newXform, &
m_currentXform, &cairoTransformation );
917 for(
auto it =
m_groups[aGroupNumber].begin(); it !=
m_groups[aGroupNumber].end(); ++it )
919 switch( it->m_Command )
931 it->m_Argument.DblArg[2], it->m_Argument.DblArg[3] );
936 it->m_Argument.DblArg[2], it->m_Argument.DblArg[3] );
942 double x = 1.0, y = 1.0;
944 double minWidth = std::min( fabs( x ), fabs( y ) );
946 std::max( it->m_Argument.DblArg[0], minWidth ) );
980 cairo_translate(
m_currentContext, it->m_Argument.DblArg[0], it->m_Argument.DblArg[1] );
984 cairo_scale(
m_currentContext, it->m_Argument.DblArg[0], it->m_Argument.DblArg[1] );
1007 for(
auto it =
m_groups[aGroupNumber].begin(); it !=
m_groups[aGroupNumber].end(); ++it )
1011 it->m_Argument.DblArg[0] = aNewColor.
r;
1012 it->m_Argument.DblArg[1] = aNewColor.
g;
1013 it->m_Argument.DblArg[2] = aNewColor.
b;
1014 it->m_Argument.DblArg[3] = aNewColor.
a;
1032 std::deque<GROUP_ELEMENT>::iterator it,
end;
1037 cairo_path_destroy( it->m_CairoPath );
1054 cairo_set_operator(
m_currentContext, aSetting ? CAIRO_OPERATOR_CLEAR : CAIRO_OPERATOR_OVER );
1098 cairo_surface_destroy( imageSurface );
1184 double sw = std::max( 1.0, aWidth );
1185 double sh = std::max( 1.0, aHeight );
1189 p.
y - std::floor( sh / 2 ) - 0.5, sw, sh );
1280 wxColour color( cColor.
r * cColor.
a * 255, cColor.
g * cColor.
a * 255, cColor.
b * cColor.
a * 255,
1282 clientDC.SetPen( wxPen( color ) );
1293 clientDC.DrawLine( p.
x - diagonalSize, p.
y - diagonalSize,
1294 p.
x + diagonalSize, p.
y + diagonalSize );
1295 clientDC.DrawLine( p.
x - diagonalSize, p.
y + diagonalSize,
1296 p.
x + diagonalSize, p.
y - diagonalSize );
1300 const int cursorSize = 80;
1301 clientDC.DrawLine( p.
x - cursorSize / 2, p.
y, p.
x + cursorSize / 2, p.
y );
1302 clientDC.DrawLine( p.
x, p.
y - cursorSize / 2, p.
x, p.
y + cursorSize / 2 );
1309 if( aPointList.size() <= 1 )
1313 std::deque<VECTOR2D>::const_iterator it = aPointList.begin();
1321 for( ++it; it != aPointList.end(); ++it )
1335 if( aPointList.size() <= 1 )
1339 std::vector<VECTOR2D>::const_iterator it = aPointList.begin();
1347 for( ++it; it != aPointList.end(); ++it )
1361 if( aListSize <= 1 )
1372 for(
int i = 1; i < aListSize; ++i )
1400 for(
int i = 1; i < numPoints; ++i )
1414 wxASSERT_MSG(
m_groups.size() < std::numeric_limits<unsigned int>::max(),
1415 wxT(
"There are no free slots to store a group" ) );
1425 wxEvtHandler* aMouseListener, wxEvtHandler* aPaintListener,
1426 const wxString& aName ) :
1428 wxWindow( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxEXPAND, aName )
1441 SetDoubleBuffered(
false );
1477#if defined _WIN32 || defined _WIN64
1484 SetSize( aParent->GetClientSize() );
1530 for(
int y = 0; y < height; y++ )
1532 for(
int x = 0; x < stride; x += 4 )
1534 const unsigned char* src = srcRow + x;
1536#if defined( __BYTE_ORDER__ ) && ( __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ )
1555 wxBitmap bmp( img );
1556 wxMemoryDC mdc( bmp );
1557 wxClientDC clientDC(
this );
1563 wxPoint origin = GetPosition();
1564 wxRegion visible( 0, 0, clientDC.LogicalToDeviceXRel(
m_screenSize.x ),
1569 rect.Offset( -origin.x, -origin.y );
1571 visible.Subtract( wxRect( clientDC.LogicalToDeviceX( rect.x ),
1572 clientDC.LogicalToDeviceY( rect.y ),
1573 clientDC.LogicalToDeviceXRel( rect.width ),
1574 clientDC.LogicalToDeviceYRel( rect.height ) ) );
1577 clientDC.SetDeviceClippingRegion( visible );
1609 SetSize( wxSize( aWidth, aHeight ) );
1615 bool s = wxWindow::Show( aShow );
1671 unsigned int currentBuffer =
m_compositor->GetBuffer();
1701 cairo_status_t status = cairo_status(
m_context );
1702 wxASSERT_MSG( status == CAIRO_STATUS_SUCCESS, wxT(
"Cairo context creation error" ) );
1772 wxPaintDC dc(
this );
1825#if wxCHECK_VERSION( 3, 3, 0 )
1837#if wxCHECK_VERSION( 3, 3, 0 )
1857 drawAxes( worldStartPoint, worldEndPoint );
1862 if( renderGlobalGrid )
1881 if( renderGlobalGrid )
1895 for(
auto & m_gridSource : std::ranges::reverse_view(
m_gridSources))
1897 if( !m_gridSource.highlighted )
1901 for(
auto & m_gridSource : std::ranges::reverse_view(
m_gridSources))
1903 if( m_gridSource.highlighted )
1928 const double rMax = aSrc.
extent.
x;
1929 const double phiMax = aSrc.
extent.
y;
1931 if( rMax > 0.0 && phiMax > 0.0 )
1933 if( phiMax >= 2 *
M_PI - 1e-6 )
1939 const int kArcSegments = std::max( 16, (
int) ( phiMax / (
M_PI / 16 ) ) );
1940 std::deque<VECTOR2D> poly;
1942 poly.emplace_back( 0.0, 0.0 );
1944 for(
int i = 0; i <= kArcSegments; ++i )
1946 const double phi = phiMax * i / kArcSegments;
1947 poly.emplace_back( rMax * std::cos( phi ), rMax * std::sin( phi ) );
1950 poly.emplace_back( 0.0, 0.0 );
1964 default: wxFAIL_MSG( wxT(
"drawGridCoverageShape: unhandled GRID_SOURCE::KIND" ) );
break;
1993 const float doubleMarker = 2.0f * marker;
2001 auto isMajor = [&](
int aIdx )
2003 return tick > 0 && aIdx % (int) tick == 0;
2006 auto drawCrossAt = [&](
const VECTOR2D& aPos,
bool aMajor,
double aArmAngle )
2008 const float w = aMajor ? doubleMarker : marker;
2009 const double len = 2.0 * w;
2010 const VECTOR2D arm1( std::cos( aArmAngle ) * len, std::sin( aArmAngle ) * len );
2018 auto drawDotAt = [&](
const VECTOR2D& aPos,
bool aMajorX,
bool aMajorY )
2049 rMax = std::hypot( farX, farY ) * 1.01;
2058 if( rMax <= 0.0 || phiMax <= 0.0 )
2068 for(
double r = 0; r <= rMax + 1e-6; r += dr, ++rIdx )
2073 SetLineWidth( isMajor( rIdx ) ? doubleMarker : marker );
2080 for(
double phi = 0; phi <= phiMax + 1e-6; phi += dPhi, ++pIdx )
2082 SetLineWidth( isMajor( pIdx ) ? doubleMarker : marker );
2084 VECTOR2D( rMax * std::cos( phi ), rMax * std::sin( phi ) ), color );
2091 for(
double r = 0; r <= rMax + 1e-6; r += dr, ++rIdx )
2095 for(
double phi = 0; phi <= phiMax + 1e-6; phi += dPhi, ++pIdx )
2097 const VECTOR2D pos( r * std::cos( phi ), r * std::sin( phi ) );
2100 drawDotAt( pos, isMajor( rIdx ), isMajor( pIdx ) );
2102 drawCrossAt( pos, isMajor( rIdx ) && isMajor( pIdx ), phi );
2112 double dx = aSrc.
pitch.
x;
2113 double dy = aSrc.
pitch.
y;
2116 const double minPitch = std::min( dx, dy );
2119 dx *= sparsed / minPitch;
2120 dy *= sparsed / minPitch;
2127 double xMin = visible.
GetLeft();
2129 double yMin = visible.
GetTop();
2132 int ixMin = (int) std::floor( xMin / dx );
2133 int ixMax = (int) std::ceil( xMax / dx );
2134 int iyMin = (int) std::floor( yMin / dy );
2135 int iyMax = (int) std::ceil( yMax / dy );
2139 xMin = std::max( xMin, -aSrc.
extent.
x );
2140 xMax = std::min( xMax, aSrc.
extent.
x );
2141 yMin = std::max( yMin, -aSrc.
extent.
y );
2142 yMax = std::min( yMax, aSrc.
extent.
y );
2144 ixMin = std::max( ixMin, -(
int) ( aSrc.
extent.
x / dx ) );
2145 ixMax = std::min( ixMax, (
int) ( aSrc.
extent.
x / dx ) );
2146 iyMin = std::max( iyMin, -(
int) ( aSrc.
extent.
y / dy ) );
2147 iyMax = std::min( iyMax, (
int) ( aSrc.
extent.
y / dy ) );
2152 for(
int ix = ixMin; ix <= ixMax; ++ix )
2162 for(
int iy = iyMin; iy <= iyMax; ++iy )
2173 for(
int ix = ixMin; ix <= ixMax; ++ix )
2175 for(
int iy = iyMin; iy <= iyMax; ++iy )
2177 const VECTOR2D pos( ix * dx, iy * dy );
2180 drawDotAt( pos, isMajor( ix ), isMajor( iy ) );
2182 drawCrossAt( pos, isMajor( ix ) && isMajor( iy ), 0.0 );
2190 default: wxFAIL_MSG( wxT(
"drawGridSource: unhandled GRID_SOURCE::KIND" ) );
break;
2213 for(
const std::vector<VECTOR2D>& pointList : glyph )
2252 if( aNth == aTotal - 1 )
Class that handles multitarget rendering (ie.
static double roundp(double x)
This class handle bitmap images in KiCad.
VECTOR2I GetSizePixels() const
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
constexpr const Vec GetEnd() const
constexpr coord_type GetLeft() const
constexpr const Vec & GetOrigin() const
constexpr coord_type GetRight() const
constexpr coord_type GetTop() const
constexpr coord_type GetBottom() const
static const WX_CURSOR_TYPE GetCursor(KICURSOR aCursorType, bool aHiDPI=false)
Get a cursor bundle (wx 3.3+) or appropriate cursor (older versions)
virtual bool IsStroke() const
virtual bool IsOutline() const
void Triangulate(std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const VECTOR2I &aPt3)> aCallback) const
void DrawGlyph(const KIFONT::GLYPH &aPolySet, int aNth, int aTotal) override
Draw a polygon representing a font glyph.
void blitCursor(wxMemoryDC &clientDC)
Blit cursor into the current screen.
cairo_surface_t * m_surface
Cairo surface.
void DrawArcSegment(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aWidth, double aMaxError) override
Draw an arc segment.
cairo_matrix_t m_cairoWorldScreenMatrix
Cairo world to screen transform matrix.
void Flush() override
Force all remaining objects to be drawn.
void BeginDrawing() override
Start/end drawing functions, draw calls can be only made in between the calls to BeginDrawing()/EndDr...
void Restore() override
Restore the context.
unsigned int m_groupCounter
Counter used for generating group keys.
void Translate(const VECTOR2D &aTranslation) override
Translate the context.
void Save() override
Save the context.
void ClearCache() override
Delete all data created during caching of graphic items.
bool m_isElementAdded
Was an graphic element added ?
void DeleteGroup(int aGroupNumber) override
Delete the group from the memory.
std::deque< GROUP_ELEMENT > GROUP
A graphic group type definition.
void drawGridCross(const VECTOR2D &aPoint, const COLOR4D &aColor)
void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a line.
void ClearScreen() override
Clear the screen.
void storePath()
Store the actual path.
void drawGridPoint(const VECTOR2D &aPoint, double aWidth, double aHeight, const COLOR4D &aColor)
void DrawGroup(int aGroupNumber) override
Draw the stored group.
void drawAxes(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
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.
void SetFillColor(const COLOR4D &aColor) override
Set the fill color.
GROUP * m_currentGroup
Currently used group.
void DrawCursor(const VECTOR2D &aCursorPosition) override
Draw the cursor.
const VECTOR2D roundp(const VECTOR2D &v)
void drawGridSources()
Render m_gridSources precedence-ascending; each bounded source paints its coverage out first,...
bool m_isGrouping
Is grouping enabled ?
static constexpr cairo_format_t GAL_FORMAT
Format used to store pixels.
void SetNegativeDrawMode(bool aSetting) override
Set negative draw mode in the renderer.
void ChangeGroupDepth(int aGroupNumber, int aDepth) override
Change the depth (Z-axis position) of the group.
int BeginGroup() override
Begin a group.
void SetLayerDepth(double aLayerDepth) override
Set the depth of the layer (position on the z-axis)
unsigned int getNewGroupNumber()
Return a valid key that can be used as a new group number.
cairo_matrix_t m_currentXform
void SetIsStroke(bool aIsStrokeEnabled) override
Enable/disable stroked outlines.
void EndGroup() override
End the group.
void DrawHoleWall(const VECTOR2D &aCenterPoint, double aHoleRadius, double aWallWidth) override
Draw a hole wall ring.
void drawPoly(const std::deque< VECTOR2D > &aPointList)
Drawing polygons & polylines is the same in Cairo, so here is the common code.
void Transform(const MATRIX3x3D &aTransformation) override
Transform the context.
void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint) override
Draw a rectangle.
void ChangeGroupColor(int aGroupNumber, const COLOR4D &aNewColor) override
Change the color used to draw the group.
void DrawEllipseArc(const VECTOR2D &aCenterPoint, double aMajorRadius, double aMinorRadius, const EDA_ANGLE &aRotation, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aEndAngle) override
Draw an elliptical arc in world coordinates.
std::map< int, GROUP > m_groups
List of graphic groups.
void SetStrokeColor(const COLOR4D &aColor) override
Set the stroke color.
cairo_t * m_context
Cairo image.
void EndDrawing() override
End the drawing, needs to be called for every new frame.
void updateWorldScreenMatrix()
void EnableDepthTest(bool aEnabled=false) override
void drawGridLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, const COLOR4D &aColor)
Draw a grid line (usually a simplified line function).
void DrawCurve(const VECTOR2D &startPoint, const VECTOR2D &controlPointA, const VECTOR2D &controlPointB, const VECTOR2D &endPoint, double aFilterValue=0.0) override
Draw a cubic bezier spline.
void Scale(const VECTOR2D &aScale) override
Scale the context.
std::vector< cairo_matrix_t > m_xformStack
void drawGridCoverageShape(const GRID_SOURCE &aSrc)
Fill or stroke a source's coverage region in its own frame, per the current state.
void DrawPolygon(const std::deque< VECTOR2D > &aPointList) override
Draw a polygon.
cairo_matrix_t m_currentWorld2Screen
void DrawEllipse(const VECTOR2D &aCenterPoint, double aMajorRadius, double aMinorRadius, const EDA_ANGLE &aRotation) override
Draw a closed ellipse.
void SetLineWidth(float aLineWidth) override
Set the line width.
void arc_angles_xform_and_normalize(double &aStartAngle, double &aEndAngle)
Transform according to the rotation from m_currentWorld2Screen transform matrix for the start angle a...
double angle_xform(double aAngle)
Transform according to the rotation from m_currentWorld2Screen transform matrix.
void syncLineWidth(bool aForceWidth=false, double aWidth=0.0)
cairo_t * m_currentContext
Currently used Cairo context for drawing.
void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius) override
Draw a circle using world coordinates.
void DrawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth) override
Draw a rounded segment.
void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle) override
Draw an arc.
void SetIsFill(bool aIsFillEnabled) override
Enable/disable fill.
void DrawBitmap(const BITMAP_BASE &aBitmap, double alphaBlend=1.0) override
Draw a bitmap image.
@ 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.
void ResizeScreen(int aWidth, int aHeight) override
Resizes the canvas.
void Rotate(double aAngle) override
Rotate the context.
void DrawSegmentChain(const std::vector< VECTOR2D > &aPointList, double aWidth) override
Draw a chain of rounded segments.
double m_lineWidthInPixels
void drawGridSource(const GRID_SOURCE &aSrc)
Paint one source: coverage wash, grid content, then hairline.
void EndGroup() override
End the group.
void deinitSurface()
Destroy Cairo surfaces when are not needed anymore.
void PostPaint(wxPaintEvent &aEvent)
Post an event to m_paint_listener.
bool Show(bool aShow) override
Show/hide the GAL canvas.
void SetTarget(RENDER_TARGET aTarget) override
Set the target for rendering.
void skipMouseEvent(wxMouseEvent &aEvent)
Mouse event handler, forwards the event to the child.
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 initSurface()
Prepare Cairo surfaces for drawing.
int BeginGroup() override
Begin a group.
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.
void onSetNativeCursor(wxSetCursorEvent &aEvent)
Give the correct cursor image when the native widget asks for it.
void EndDrawing() override
End the drawing, needs to be called for every new frame.
void skipGestureEvent(wxGestureEvent &aEvent)
Skip the gesture event to the parent.
void allocateBitmaps()
Allocate the bitmaps for drawing.
void onPaint(wxPaintEvent &aEvent)
Paint event handler.
void StartNegativesLayer() override
Begins rendering in a new layer that will be copied to the main layer in EndNegativesLayer().
void ResizeScreen(int aWidth, int aHeight) override
Resize the canvas.
RENDER_TARGET GetTarget() const override
Get the currently used target for rendering.
void setCompositor()
Prepare the compositor.
bool SetNativeCursorStyle(KICURSOR aCursor, bool aHiDPI) override
Set the cursor in the native panel.
unsigned char * m_bitmapBuffer
Storage of the Cairo image.
wxEvtHandler * m_mouseListener
Mouse listener.
void ClearTarget(RENDER_TARGET aTarget) override
Clear the target for rendering.
bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions) override
Handle updating display options.
~CAIRO_GAL()
Return true if the GAL canvas is visible on the screen.
void BeginDrawing() override
Start/end drawing functions, draw calls can be only made in between the calls to BeginDrawing()/EndDr...
wxEvtHandler * m_paintListener
Paint listener.
unsigned int m_tempBuffer
Handle to the temp buffer.
RENDER_TARGET m_currentTarget
Current rendering target.
wxWindow * m_parentWindow
Parent window.
void EndDiffLayer() override
Ends rendering of a differential layer.
std::shared_ptr< CAIRO_COMPOSITOR > m_compositor
Object for layers compositing.
void deleteBitmaps()
Allocate the bitmaps for drawing.
WX_CURSOR_TYPE m_currentwxCursor
wx cursor showing the current native cursor
void EndNegativesLayer() override
Ends rendering of a negatives layer and draws it to the main layer.
void StartDiffLayer() override
Begins rendering of a differential layer.
unsigned int m_savedBuffer
Handle to buffer to restore after rendering to temp buffer.
std::vector< wxRect > m_overlayExclusions
Areas the frame blit must leave alone.
A color representation with 4 components: red, green, blue, alpha.
COLOR4D Darkened(double aFactor) const
Return a color that is darker by a given factor, without modifying object.
COLOR4D & Brighten(double aFactor)
Makes the color brighter by a given factor.
static const COLOR4D BLACK
GAL_ANTIALIASING_MODE antialiasing_mode
The grid style to draw the grid in.
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
bool IsCursorEnabled() const
Return information about cursor visibility.
MATRIX3x3D m_worldScreenMatrix
World transformation.
VECTOR2D GetVisibleGridSize() const
Return the visible grid size in x and y directions.
MATRIX3x3D m_screenWorldMatrix
Screen transformation.
bool m_axesEnabled
Should the axes be drawn.
float m_gridLineWidth
Line width of the grid.
VECTOR2I m_screenSize
Screen size in screen (wx logical) coordinates.
void normalize(T &a, T &b)
Ensure that the first element is smaller than the second.
VECTOR2D m_depthRange
Range of the depth.
VECTOR2D ToScreen(const VECTOR2D &aPoint) const
Compute the point position in screen coordinates from given world coordinates.
virtual bool SetNativeCursorStyle(KICURSOR aCursor, bool aHiDPI)
Set the cursor in the native panel.
GRID_STYLE m_gridStyle
Grid display style.
COLOR4D m_axesColor
Color of the axes.
float m_lineWidth
The line width.
virtual void SetLineWidth(float aLineWidth)
Set the line width.
VECTOR2D m_gridSize
The grid size.
COLOR4D getCursorColor() const
Get the actual cursor color to draw.
COLOR4D m_fillColor
The fill color.
double m_worldUnitLength
The unit length of the world coordinates [inch].
virtual bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions)
Handle updating display options.
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
BOX2D gridScreenBBox(const GRID_SOURCE &aSrc) const
VECTOR2D m_cursorPosition
Current cursor position (world coordinates)
int m_gridTick
Every tick line gets the double width.
double m_worldScale
The scale factor world->screen.
VECTOR2D m_gridOrigin
The grid origin.
KICURSOR m_currentNativeCursor
Current cursor.
bool m_isFillEnabled
Is filling of graphic objects enabled ?
virtual void ComputeWorldScreenMatrix()
Compute the world <-> screen transformation matrix.
COLOR4D m_gridColor
Color of the grid.
COLOR4D m_strokeColor
The color of the outlines.
double computeMinGridSpacing() const
Compute minimum grid spacing from the grid settings.
bool m_isStrokeEnabled
Are the outlines stroked ?
std::vector< GRID_SOURCE > m_gridSources
Sources overlayed on the display grid.
GAL_DISPLAY_OPTIONS & m_options
bool m_gridVisibility
Should the grid be shown.
virtual void SetTarget(RENDER_TARGET aTarget)
Set the target for rendering.
KIGFX::CROSS_HAIR_MODE m_crossHairMode
Crosshair drawing mode.
GAL(GAL_DISPLAY_OPTIONS &aOptions)
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
bool IsClosed() const override
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
Represent a set of closed polygons.
int OutlineCount() const
Return the number of outlines in the set.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
MATRIX3x3< double > MATRIX3x3D
The Cairo implementation of the graphics abstraction layer.
constexpr double GRID_DIM_ALPHA
Opacity of the background wash laid over a selected grid item's area, to fade the grids showing throu...
@ SMALL_CROSS
Use small cross instead of dots for the grid.
@ DOTS
Use dots for the grid.
@ LINES
Use lines for the grid.
constexpr double GRID_SELECTED_BRIGHTEN
How far the grid being edited is lifted above its own colour.
double AutoSparsePitch(double aPitch, unsigned aTick, double aThreshold)
Multiply aPitch by aTick until it exceeds aThreshold, so a sub-threshold grid still shows every Nth l...
RENDER_TARGET
RENDER_TARGET: Possible rendering targets.
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
@ TARGET_TEMP
Temporary target for drawing in separate layer.
@ TARGET_CACHED
Main rendering target (cached)
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
constexpr double GRID_EDGE_DARKEN
How far the hairline round a grid's coverage sits below its own colour.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
unsigned priority
Higher wins where grids overlap.
double orientation
Rotation about origin, radians CCW.
VECTOR2D extent
Cartesian: (dx, dy) = size/2 from origin.
VECTOR2D pitch
Cartesian: (dx, dy); polar: (dr, dPhi rad).
Type definition for an graphics group element.
union KIGFX::CAIRO_GAL_BASE::GROUP_ELEMENT::@224355003013256125016006047023123235275076033053 m_Argument
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.
Render-time projection of a grid: GRID_GEOMETRY (kind/origin/pitch/orientation/extent) plus rendering...
unsigned tick
Major-tick interval (0 = inherit default).
bool axesEnabled
Skip grid lines coincident with the world axes (only meaningful for unbounded cartesian).
bool highlighted
Render with edit-mode emphasis (selected grid).
bool unbounded
No extent; visible range derived from screen corners.
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
VECTOR2I ToVECTOR2I(const wxSize &aSize)