KiCad PCB EDA Suite
Loading...
Searching...
No Matches
graphics_abstraction_layer.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * Graphics Abstraction Layer (GAL) - base class
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef GRAPHICSABSTRACTIONLAYER_H_
24#define GRAPHICSABSTRACTIONLAYER_H_
25
26#include <deque>
27#include <stack>
28#include <limits>
29
30#include <math/matrix3x3.h>
31
32#include <gal/gal.h>
33#include <gal/color4d.h>
34#include <gal/cursors.h>
35#include <gal/definitions.h>
37#include <font/stroke_font.h>
38#include <geometry/eda_angle.h>
39#include <pgm_base.h>
41
43class SHAPE_POLY_SET;
44class BITMAP_BASE;
45
46namespace KIGFX
47{
58class GAL_API GAL : GAL_DISPLAY_OPTIONS_OBSERVER
59{
60 // These friend declarations allow us to hide routines that should not be called. The
61 // corresponding RAII objects must be used instead.
62 friend class GAL_CONTEXT_LOCKER;
63 friend class GAL_UPDATE_CONTEXT;
64 friend class GAL_DRAWING_CONTEXT;
65
66public:
67 // Constructor / Destructor
68 GAL( GAL_DISPLAY_OPTIONS& aOptions );
69 virtual ~GAL();
70
72 virtual bool IsInitialized() const { return true; }
73
75 virtual bool IsVisible() const { return true; }
76
78 virtual bool IsCairoEngine() { return false; }
79
81 virtual bool IsOpenGlEngine() { return false; }
82
83 // ---------------
84 // Drawing methods
85 // ---------------
86
95 virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) {};
96
106 virtual void DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint,
107 double aWidth ){};
108
115 virtual void DrawSegmentChain( const std::vector<VECTOR2D>& aPointList, double aWidth ){};
116 virtual void DrawSegmentChain( const SHAPE_LINE_CHAIN& aLineChain, double aWidth ){};
117
123 virtual void DrawPolyline( const std::deque<VECTOR2D>& aPointList ) {};
124 virtual void DrawPolyline( const std::vector<VECTOR2D>& aPointList ) {};
125 virtual void DrawPolyline( const VECTOR2D aPointList[], int aListSize ) {};
126 virtual void DrawPolyline( const SHAPE_LINE_CHAIN& aLineChain ) {};
127
133 virtual void DrawPolylines( const std::vector<std::vector<VECTOR2D>>& aPointLists ){};
134
141 virtual void DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) {};
142
150 virtual void DrawHoleWall( const VECTOR2D& aCenterPoint, double aHoleRadius,
151 double aWallWidth ) {};
152
161 virtual void DrawArc( const VECTOR2D& aCenterPoint, double aRadius,
162 const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aAngle ){};
163
184 virtual void DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
185 const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aAngle,
186 double aWidth, double aMaxError ){};
187
196 virtual void DrawEllipse( const VECTOR2D& aCenterPoint, double aMajorRadius, double aMinorRadius,
197 const EDA_ANGLE& aRotation );
198
209 virtual void DrawEllipseArc( const VECTOR2D& aCenterPoint, double aMajorRadius, double aMinorRadius,
210 const EDA_ANGLE& aRotation, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle );
211
218 virtual void DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) {};
219
220 void DrawRectangle( const BOX2I& aRect )
221 {
222 DrawRectangle( aRect.GetOrigin(), aRect.GetEnd() );
223 }
224
228 virtual void DrawGlyph( const KIFONT::GLYPH& aGlyph, int aNth = 0, int aTotal = 1 ) {};
229
233 virtual void DrawGlyphs( const std::vector<std::unique_ptr<KIFONT::GLYPH>>& aGlyphs )
234 {
235 COLOR4D fillColor = GetFillColor();
236 COLOR4D strokeColor = GetStrokeColor();
237
238 for( size_t i = 0; i < aGlyphs.size(); i++ )
239 {
240 if( aGlyphs[i]->IsHover() )
241 {
244 }
245
246 DrawGlyph( *aGlyphs[i], i, aGlyphs.size() );
247
248 if( aGlyphs[i]->IsHover() )
249 {
250 SetFillColor( fillColor );
251 SetStrokeColor( strokeColor );
252 }
253 }
254 }
255
256
262 virtual void DrawPolygon( const std::deque<VECTOR2D>& aPointList ) {};
263 virtual void DrawPolygon( const VECTOR2D aPointList[], int aListSize ) {};
264 virtual void DrawPolygon( const SHAPE_POLY_SET& aPolySet,
265 bool aStrokeTriangulation = false ) {};
266 virtual void DrawPolygon( const SHAPE_LINE_CHAIN& aPolySet ) {};
267
279 virtual void DrawCurve( const VECTOR2D& startPoint, const VECTOR2D& controlPointA,
280 const VECTOR2D& controlPointB, const VECTOR2D& endPoint,
281 double aFilterValue = 0.0 ) {};
282
286 virtual void DrawBitmap( const BITMAP_BASE& aBitmap, double alphaBlend = 1.0 ) {};
287
288 // --------------
289 // Screen methods
290 // --------------
291
293 virtual void ResizeScreen( int aWidth, int aHeight ) {};
294
296 virtual bool Show( bool aShow ) { return true; };
297
300 {
301 return m_screenSize;
302 }
303
305 virtual int GetSwapInterval() const { return 0; };
306
308 virtual void Flush() {};
309
310 void SetClearColor( const COLOR4D& aColor )
311 {
312 m_clearColor = aColor;
313 }
314
315 const COLOR4D& GetClearColor( ) const
316 {
317 return m_clearColor;
318 }
319
325 virtual void ClearScreen() {};
326
327 // -----------------
328 // Attribute setting
329 // -----------------
330
336 virtual void SetIsFill( bool aIsFillEnabled )
337 {
338 m_isFillEnabled = aIsFillEnabled;
339 }
340
346 inline bool GetIsFill() const
347 {
348 return m_isFillEnabled;
349 }
350
356 virtual void SetIsStroke( bool aIsStrokeEnabled )
357 {
358 m_isStrokeEnabled = aIsStrokeEnabled;
359 }
360
366 inline bool GetIsStroke() const
367 {
368 return m_isStrokeEnabled;
369 }
370
376 virtual void SetFillColor( const COLOR4D& aColor )
377 {
378 m_fillColor = aColor;
379 }
380
386 inline const COLOR4D& GetFillColor() const
387 {
388 return m_fillColor;
389 }
390
396 virtual void SetStrokeColor( const COLOR4D& aColor )
397 {
398 m_strokeColor = aColor;
399 }
400
401 virtual void SetHoverColor( const COLOR4D& aColor )
402 {
403 m_hoverColor = aColor;
404 }
405
411 inline const COLOR4D& GetStrokeColor() const
412 {
413 return m_strokeColor;
414 }
415
421 virtual void SetLineWidth( float aLineWidth )
422 {
423 m_lineWidth = aLineWidth;
424 }
425
431 virtual void SetMinLineWidth( float aLineWidth )
432 {
433 m_minLineWidth = aLineWidth;
434 }
435
441 inline float GetLineWidth() const
442 {
443 return m_lineWidth;
444 }
445
451 inline float GetMinLineWidth() const
452 {
453 return m_minLineWidth;
454 }
455
464 virtual void SetLayerDepth( double aLayerDepth )
465 {
466 wxCHECK_MSG( aLayerDepth <= m_depthRange.y, /*void*/,
467 wxT( "SetLayerDepth: below minimum" ) );
468 wxCHECK_MSG( aLayerDepth >= m_depthRange.x, /*void*/,
469 wxT( "SetLayerDepth: above maximum" ) );
470
471 m_layerDepth = aLayerDepth;
472 }
473
481 inline void AdvanceDepth()
482 {
484 }
485
486 // ----
487 // Text
488 // ----
489
498 virtual void BitmapText( const wxString& aText, const VECTOR2I& aPosition,
499 const EDA_ANGLE& aAngle );
500
507 void ResetTextAttributes();
508
509 void SetGlyphSize( const VECTOR2I aSize ) { m_attributes.m_Size = aSize; }
510 const VECTOR2I& GetGlyphSize() const { return m_attributes.m_Size; }
511
512 inline void SetFontBold( const bool aBold ) { m_attributes.m_Bold = aBold; }
513 inline bool IsFontBold() const { return m_attributes.m_Bold; }
514
515 inline void SetFontItalic( bool aItalic ) { m_attributes.m_Italic = aItalic; }
516 inline bool IsFontItalic() const { return m_attributes.m_Italic; }
517
518 inline void SetFontUnderlined( bool aUnderlined ) { m_attributes.m_Underlined = aUnderlined; }
519 inline bool IsFontUnderlined() const { return m_attributes.m_Underlined; }
520
521 void SetTextMirrored( const bool aMirrored ) { m_attributes.m_Mirrored = aMirrored; }
522 bool IsTextMirrored() const { return m_attributes.m_Mirrored; }
523
524 void SetHorizontalJustify( const GR_TEXT_H_ALIGN_T aHorizontalJustify )
525 {
526 m_attributes.m_Halign = aHorizontalJustify;
527 }
528
530
531 void SetVerticalJustify( const GR_TEXT_V_ALIGN_T aVerticalJustify )
532 {
533 m_attributes.m_Valign = aVerticalJustify;
534 }
535
537
538
539 // --------------
540 // Transformation
541 // --------------
542
548 virtual void Transform( const MATRIX3x3D& aTransformation ) {};
549
555 virtual void Rotate( double aAngle ) {};
556
562 virtual void Translate( const VECTOR2D& aTranslation ) {};
563
569 virtual void Scale( const VECTOR2D& aScale ) {};
570
572 virtual void Save() {};
573
575 virtual void Restore() {};
576
577 // --------------------------------------------
578 // Group methods
579 // ---------------------------------------------
580
589 virtual int BeginGroup() { return 0; };
590
592 virtual void EndGroup() {};
593
599 virtual void DrawGroup( int aGroupNumber ) {};
600
607 virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) {};
608
615 virtual void ChangeGroupDepth( int aGroupNumber, int aDepth ) {};
616
622 virtual void DeleteGroup( int aGroupNumber ) {};
623
627 virtual void ClearCache() {};
628
629 // --------------------------------------------------------
630 // Handling the world <-> screen transformation
631 // --------------------------------------------------------
632
634 virtual void ComputeWorldScreenMatrix();
635
642 {
643 return m_worldScreenMatrix;
644 }
645
652 {
653 return m_screenWorldMatrix;
654 }
655
661 inline void SetWorldScreenMatrix( const MATRIX3x3D& aMatrix )
662 {
663 m_worldScreenMatrix = aMatrix;
664 }
665
669 BOX2D GetVisibleWorldExtents() const;
670
678 void SetWorldUnitLength( double aWorldUnitLength ) { m_worldUnitLength = aWorldUnitLength; }
679
680 double GetWorldUnitLength() const { return m_worldUnitLength; }
681
682 void SetScreenSize( const VECTOR2I& aSize ) { m_screenSize = aSize; }
683
690 void SetScreenDPI( double aScreenDPI ) { m_screenDPI = aScreenDPI; }
691 double GetScreenDPI() const { return m_screenDPI; }
692
698 void SetLookAtPoint( const VECTOR2D& aPoint ) { m_lookAtPoint = aPoint; }
699 const VECTOR2D& GetLookAtPoint() const { return m_lookAtPoint; }
700
701 void SetZoomFactor( double aZoomFactor ) { m_zoomFactor = aZoomFactor; }
702 double GetZoomFactor() const { return m_zoomFactor; }
703
707 void SetRotation( double aRotation ) { m_rotation = aRotation; }
708 double GetRotation() const { return m_rotation; }
709
718 void SetDepthRange( const VECTOR2D& aDepthRange ) { m_depthRange = aDepthRange; }
719 double GetMinDepth() const { return m_depthRange.x; }
720 double GetMaxDepth() const { return m_depthRange.y; }
721
727 double GetWorldScale() const { return m_worldScale; }
728
735 inline void SetFlip( bool xAxis, bool yAxis )
736 {
737 m_globalFlipX = xAxis;
738 m_globalFlipY = yAxis;
739 }
740
741 bool IsFlippedX() const { return m_globalFlipX; }
742 bool IsFlippedY() const { return m_globalFlipY; }
743
744 // ---------------------------
745 // Buffer manipulation methods
746 // ---------------------------
747
753 virtual void SetTarget( RENDER_TARGET aTarget ) {};
754
760 virtual RENDER_TARGET GetTarget() const { return TARGET_CACHED; };
761
767 virtual void ClearTarget( RENDER_TARGET aTarget ) {};
768
774 virtual bool HasTarget( RENDER_TARGET aTarget )
775 {
776 return true;
777 };
778
790 virtual void SetNegativeDrawMode( bool aSetting ) {};
791
799 virtual void StartDiffLayer() {};
800
806 virtual void EndDiffLayer() {};
807
816 virtual void StartNegativesLayer(){};
817
822 virtual void EndNegativesLayer(){};
823
824 // -------------
825 // Grid methods
826 // -------------
827
833 void SetGridVisibility( bool aVisibility ) { m_gridVisibility = aVisibility; }
834
835 bool GetGridVisibility() const { return m_gridVisibility; }
836
837 bool GetGridSnapping() const
838 {
839 return m_options.m_gridSnapping == KIGFX::GRID_SNAPPING::ALWAYS ||
841 }
842
848 inline void SetGridOrigin( const VECTOR2D& aGridOrigin )
849 {
850 m_gridOrigin = aGridOrigin;
851
852 if( m_gridSize.x == 0.0 || m_gridSize.y == 0.0 )
853 {
854 m_gridOffset = VECTOR2D( 0.0, 0.0);
855 }
856 else
857 {
858 m_gridOffset = VECTOR2D( (long) m_gridOrigin.x % (long) m_gridSize.x,
859 (long) m_gridOrigin.y % (long) m_gridSize.y );
860 }
861 }
862
863 inline const VECTOR2D& GetGridOrigin() const
864 {
865 return m_gridOrigin;
866 }
867
873 inline void SetGridSize( const VECTOR2D& aGridSize )
874 {
875 m_gridSize = aGridSize;
876
877 // Avoid stupid grid size values: a grid size should be >= 1 in internal units
878 m_gridSize.x = std::max( 1.0, m_gridSize.x );
879 m_gridSize.y = std::max( 1.0, m_gridSize.y );
880
881 m_gridOffset = VECTOR2D( (long) m_gridOrigin.x % (long) m_gridSize.x,
882 (long) m_gridOrigin.y % (long) m_gridSize.y );
883 }
884
890 inline const VECTOR2D& GetGridSize() const
891 {
892 return m_gridSize;
893 }
894
901 {
902 VECTOR2D gridScreenSize( m_gridSize );
903 gridScreenSize.x = std::max( 100.0, gridScreenSize.x );
904 gridScreenSize.y = std::max( 100.0, gridScreenSize.y );
905
906 double gridThreshold = computeMinGridSpacing() / m_worldScale;
907
909 gridThreshold *= 2.0;
910
911 // If we cannot display the grid density, scale down by a tick size and
912 // try again. Eventually, we get some representation of the grid
913 while( std::min( gridScreenSize.x, gridScreenSize.y ) <= gridThreshold )
914 {
915 gridScreenSize = gridScreenSize * static_cast<double>( m_gridTick );
916 }
917
918 return gridScreenSize;
919 }
920
926 inline void SetGridColor( const COLOR4D& aGridColor )
927 {
928 m_gridColor = aGridColor;
929 }
930
936 inline void SetAxesColor( const COLOR4D& aAxesColor )
937 {
938 m_axesColor = aAxesColor;
939 }
940
944 inline void SetAxesEnabled( bool aAxesEnabled )
945 {
946 m_axesEnabled = aAxesEnabled;
947 }
948
954 inline void SetCoarseGrid( int aInterval )
955 {
956 m_gridTick = aInterval;
957 }
958
964 inline float GetGridLineWidth() const
965 {
966 return m_gridLineWidth;
967 }
968
970 virtual void DrawGrid() {};
971
978 VECTOR2D GetGridPoint( const VECTOR2D& aPoint ) const;
979
986 inline VECTOR2D ToWorld( const VECTOR2D& aPoint ) const
987 {
988 return VECTOR2D( m_screenWorldMatrix * aPoint );
989 }
990
997 inline VECTOR2D ToScreen( const VECTOR2D& aPoint ) const
998 {
999 return VECTOR2D( m_worldScreenMatrix * aPoint );
1000 }
1001
1008 virtual bool SetNativeCursorStyle( KICURSOR aCursor, bool aHiDPI );
1009
1015 inline void SetCursorEnabled( bool aCursorEnabled )
1016 {
1017 m_isCursorEnabled = aCursorEnabled;
1018 }
1019
1025 bool IsCursorEnabled() const
1026 {
1028 }
1029
1035 inline void SetCursorColor( const COLOR4D& aCursorColor )
1036 {
1037 m_cursorColor = aCursorColor;
1038 }
1039
1045 virtual void DrawCursor( const VECTOR2D& aCursorPosition ) {};
1046
1047 virtual void EnableDepthTest( bool aEnabled = false ) {};
1048
1053 virtual bool IsContextLocked()
1054 {
1055 return false;
1056 }
1057
1058
1060 virtual void LockContext( int aClientCookie ) {}
1061
1062 virtual void UnlockContext( int aClientCookie ) {}
1063
1068
1071 virtual void BeginDrawing() {};
1072
1075 virtual void EndDrawing() {};
1076protected:
1077
1080 virtual void beginUpdate() {}
1081
1083 virtual void endUpdate() {}
1084
1085
1086
1088 inline void computeWorldScale()
1089 {
1091
1092 PGM_BASE* pgm = PgmOrNull();
1093
1094 if( pgm && pgm->GetCommonSettings() )
1096 }
1097
1103 double computeMinGridSpacing() const;
1104
1106 static const int MIN_DEPTH;
1107 static const int MAX_DEPTH;
1108
1110 static const int GRID_DEPTH;
1111
1115 COLOR4D getCursorColor() const;
1116
1117 // ---------------
1118 // Settings observer interface
1119 // ---------------
1123 void OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& aOptions ) override;
1124
1133 virtual bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions );
1134
1138 template <typename T>
1139 void normalize( T &a, T &b )
1140 {
1141 if( a > b )
1142 {
1143 T tmp = a;
1144 a = b;
1145 b = tmp;
1146 }
1147 }
1148
1151
1152 std::stack<double> m_depthStack;
1154
1158
1160 double m_rotation;
1164
1167
1170
1173
1178
1181
1182 // Grid settings
1195
1196 // Cursor settings
1202
1204
1205private:
1206
1207 inline double getLayerDepth() const
1208 {
1209 return m_layerDepth;
1210 }
1211
1213
1214 friend class GAL_SCOPED_ATTRS;
1215};
1216
1217
1219{
1220public:
1222 m_gal( aGal )
1223 {
1224 m_cookie = rand();
1225 m_gal->LockContext( m_cookie );
1226 }
1227
1229 {
1230 m_gal->UnlockContext( m_cookie );
1231 }
1232
1233protected:
1236};
1237
1238
1240{
1241public:
1243 GAL_CONTEXT_LOCKER( aGal )
1244 {
1245 m_gal->beginUpdate();
1246 }
1247
1249 {
1250 m_gal->endUpdate();
1251 }
1252};
1253
1254
1256{
1257public:
1259 GAL_CONTEXT_LOCKER( aGal )
1260 {
1261 m_gal->BeginDrawing();
1262 }
1263
1264 ~GAL_DRAWING_CONTEXT() noexcept( false )
1265 {
1266 m_gal->EndDrawing();
1267 }
1268};
1269
1270
1275{
1276public:
1278 {
1285
1286 // It is not clear to me that GAL needs to save text attributes.
1287 // Only BitmapText uses it, and maybe that should be passed in
1288 // explicitly (like for Draw) - every caller of BitmapText sets
1289 // the text attributes anyway.
1290 // TEXT_ATTRS = 64,
1291
1292 // Convenience flags
1296
1298 };
1299
1305 GAL_SCOPED_ATTRS( KIGFX::GAL& aGal, int aFlags )
1306 : m_gal( aGal ), m_flags( aFlags )
1307 {
1308 // Save what we need to restore later.
1309 // These are all so cheap to copy, it's likely not worth if'ing
1310 m_strokeWidth = aGal.GetLineWidth();
1312 m_isStroke = aGal.GetIsStroke();
1313 m_fillColor = aGal.GetFillColor();
1314 m_isFill = aGal.GetIsFill();
1315 m_layerDepth = aGal.getLayerDepth();
1316 }
1317
1319 {
1320 // Restore the attributes that were saved
1321 // based on the flags that were set.
1322
1323 if( m_flags & STROKE_WIDTH )
1324 m_gal.SetLineWidth( m_strokeWidth );
1325
1326 if( m_flags & STROKE_COLOR )
1327 m_gal.SetStrokeColor( m_strokeColor );
1328
1329 if( m_flags & IS_STROKE )
1330 m_gal.SetIsStroke( m_isStroke );
1331
1332 if( m_flags & FILL_COLOR )
1333 m_gal.SetFillColor( m_fillColor );
1334
1335 if( m_flags & IS_FILL )
1336 m_gal.SetIsFill( m_isFill );
1337
1338 if( m_flags & LAYER_DEPTH )
1339 m_gal.SetLayerDepth( m_layerDepth );
1340 }
1341
1342private:
1345
1349
1352
1354};
1355
1356
1357}; // namespace KIGFX
1358
1359#endif /* GRAPHICSABSTRACTIONLAYER_H_ */
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
BOX2< VECTOR2D > BOX2D
Definition box2.h:919
This class handle bitmap images in KiCad.
Definition bitmap_base.h:45
constexpr const Vec GetEnd() const
Definition box2.h:208
constexpr const Vec & GetOrigin() const
Definition box2.h:206
APPEARANCE m_Appearance
GAL(GAL_DISPLAY_OPTIONS &aOptions)
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
GAL_SCOPED_ATTRS(KIGFX::GAL &aGal, int aFlags)
Instantiate a GAL_SCOPED_ATTRS object, saving the current attributes of the GAL.
Abstract interface for drawing on a 2D-surface.
const VECTOR2D & GetGridOrigin() const
virtual void ResizeScreen(int aWidth, int aHeight)
Resize the canvas.
virtual void DrawPolygon(const std::deque< VECTOR2D > &aPointList)
Draw a polygon.
void SetGridColor(const COLOR4D &aGridColor)
Set the grid color.
float GetGridLineWidth() const
Get the grid line width.
virtual bool Show(bool aShow)
Show/hide the GAL canvas.
virtual void SetLayerDepth(double aLayerDepth)
Set the depth of the layer (position on the z-axis)
double GetScreenDPI() const
const MATRIX3x3D & GetWorldScreenMatrix() const
Get the world <-> screen transformation matrix.
bool IsCursorEnabled() const
Return information about cursor visibility.
virtual void SetIsFill(bool aIsFillEnabled)
Enable/disable fill.
friend class GAL_DRAWING_CONTEXT
COLOR4D m_hoverColor
Color for hovered (active) links.
friend class GAL_CONTEXT_LOCKER
virtual void EndDrawing()
End the drawing, needs to be called for every new frame.
virtual void StartDiffLayer()
Begins rendering of a differential layer.
bool m_isCursorEnabled
Is the cursor enabled?
virtual void DrawGlyph(const KIFONT::GLYPH &aGlyph, int aNth=0, int aTotal=1)
Draw a polygon representing a font glyph.
virtual void EndDiffLayer()
Ends rendering of a differential layer.
virtual void Rotate(double aAngle)
Rotate the context.
virtual void DrawRectangle(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a rectangle.
MATRIX3x3D m_worldScreenMatrix
World transformation.
VECTOR2D GetVisibleGridSize() const
Return the visible grid size in x and y directions.
double m_layerDepth
The actual layer depth.
void SetVerticalJustify(const GR_TEXT_V_ALIGN_T aVerticalJustify)
bool GetIsFill() const
Get the fill status.
void AdvanceDepth()
Change the current depth to deeper, so it is possible to draw objects right beneath other.
const COLOR4D & GetFillColor() const
Get the fill color.
void SetFontBold(const bool aBold)
MATRIX3x3D m_screenWorldMatrix
Screen transformation.
void SetFontUnderlined(bool aUnderlined)
void SetHorizontalJustify(const GR_TEXT_H_ALIGN_T aHorizontalJustify)
virtual RENDER_TARGET GetTarget() const
Get the currently used target for rendering.
double GetMaxDepth() const
bool m_axesEnabled
Should the axes be drawn.
void SetRotation(double aRotation)
Get/set the rotation angle (in radians).
float m_gridLineWidth
Line width of the grid.
void SetFlip(bool xAxis, bool yAxis)
Sets flipping of the screen.
VECTOR2I m_screenSize
Screen size in screen (wx logical) coordinates.
virtual void Flush()
Force all remaining objects to be drawn.
virtual int GetSwapInterval() const
Return the swap interval. -1 for adaptive, 0 for disabled/unknown.
virtual void DeleteGroup(int aGroupNumber)
Delete the group from the memory.
std::stack< double > m_depthStack
Stored depth values.
GR_TEXT_H_ALIGN_T GetHorizontalJustify() const
void normalize(T &a, T &b)
Ensure that the first element is smaller than the second.
VECTOR2D m_depthRange
Range of the depth.
double GetZoomFactor() const
virtual void SetFillColor(const COLOR4D &aColor)
Set the fill color.
void OnGalDisplayOptionsChanged(const GAL_DISPLAY_OPTIONS &aOptions) override
Handler for observer settings changes.
double m_zoomFactor
The zoom factor.
virtual void Translate(const VECTOR2D &aTranslation)
Translate the context.
VECTOR2D ToScreen(const VECTOR2D &aPoint) const
Compute the point position in screen coordinates from given world coordinates.
void SetCursorEnabled(bool aCursorEnabled)
Enable/disable cursor.
void SetAxesEnabled(bool aAxesEnabled)
Enable drawing the axes.
virtual void DrawPolylines(const std::vector< std::vector< VECTOR2D > > &aPointLists)
Draw multiple polylines.
virtual bool HasTarget(RENDER_TARGET aTarget)
Return true if the target exists.
GRID_STYLE m_gridStyle
Grid display style.
void SetCursorColor(const COLOR4D &aCursorColor)
Set the cursor color.
COLOR4D m_cursorColor
Cursor color.
COLOR4D m_axesColor
Color of the axes.
int m_gridMinSpacing
Minimum screen size of the grid (pixels) below which the grid is not drawn.
void SetGridSize(const VECTOR2D &aGridSize)
Set the grid size.
const VECTOR2D & GetLookAtPoint() const
double GetRotation() const
const MATRIX3x3D & GetScreenWorldMatrix() const
Get the screen <-> world transformation matrix.
bool IsFontUnderlined() const
virtual void DrawCircle(const VECTOR2D &aCenterPoint, double aRadius)
Draw a circle using world coordinates.
virtual void Restore()
Restore the context.
float m_lineWidth
The line width.
virtual void DrawHoleWall(const VECTOR2D &aCenterPoint, double aHoleRadius, double aWallWidth)
Draw a hole wall ring.
const COLOR4D & GetStrokeColor() const
Get the stroke color.
virtual void ClearTarget(RENDER_TARGET aTarget)
Clear the target for rendering.
void SetZoomFactor(double aZoomFactor)
virtual void BeginDrawing()
Start/end drawing functions, draw calls can be only made in between the calls to BeginDrawing()/EndDr...
void computeWorldScale()
Compute the scaling factor for the world->screen matrix.
virtual bool IsOpenGlEngine()
Return true if the GAL engine is a OpenGL based type.
virtual int BeginGroup()
Begin a group.
TEXT_ATTRIBUTES m_attributes
static const int MIN_DEPTH
Possible depth range.
const VECTOR2D & GetGridSize() const
Return the grid size.
virtual void DrawPolygon(const VECTOR2D aPointList[], int aListSize)
virtual void SetLineWidth(float aLineWidth)
Set the line width.
double m_rotation
Rotation transformation (radians)
VECTOR2D m_gridSize
The grid size.
virtual void DrawPolygon(const SHAPE_POLY_SET &aPolySet, bool aStrokeTriangulation=false)
COLOR4D getCursorColor() const
Get the actual cursor color to draw.
virtual void ChangeGroupDepth(int aGroupNumber, int aDepth)
Change the depth (Z-axis position) of the group.
virtual void SetHoverColor(const COLOR4D &aColor)
COLOR4D m_fillColor
The fill color.
virtual void EndNegativesLayer()
Ends rendering of a negatives layer and draws it to the main layer.
void DrawRectangle(const BOX2I &aRect)
double m_worldUnitLength
The unit length of the world coordinates [inch].
virtual void StartNegativesLayer()
Begins rendering in a new layer that will be copied to the main layer in EndNegativesLayer().
void SetTextMirrored(const bool aMirrored)
virtual void DrawPolyline(const std::deque< VECTOR2D > &aPointList)
Draw a polyline.
void SetCoarseGrid(int aInterval)
Draw every tick line wider.
virtual bool updatedGalDisplayOptions(const GAL_DISPLAY_OPTIONS &aOptions)
Handle updating display options.
void SetAxesColor(const COLOR4D &aAxesColor)
Set the axes color.
virtual void SetStrokeColor(const COLOR4D &aColor)
Set the stroke color.
virtual void ChangeGroupColor(int aGroupNumber, const COLOR4D &aNewColor)
Change the color used to draw the group.
virtual void DrawArcSegment(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle, double aWidth, double aMaxError)
Draw an arc segment.
virtual bool IsContextLocked()
Checks the state of the context lock.
VECTOR2D m_cursorPosition
Current cursor position (world coordinates)
VECTOR2D m_gridOffset
The grid offset to compensate cursor position.
virtual void SetIsStroke(bool aIsStrokeEnabled)
Enable/disable stroked outlines.
virtual void beginUpdate()
Enable item update mode.
virtual void DrawGroup(int aGroupNumber)
Draw the stored group.
double getLayerDepth() const
const VECTOR2I & GetGlyphSize() const
int m_gridTick
Every tick line gets the double width.
double m_worldScale
The scale factor world->screen.
void SetLookAtPoint(const VECTOR2D &aPoint)
Get/set the Point in world space to look at.
virtual void DrawPolygon(const SHAPE_LINE_CHAIN &aPolySet)
bool GetGridVisibility() const
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
virtual bool IsCairoEngine()
Return true if the GAL engine is a Cairo based type.
virtual void ClearScreen()
Clear the screen.
virtual void DrawLine(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint)
Draw a line.
VECTOR2D m_gridOrigin
The grid origin.
virtual void endUpdate()
Disable item update mode.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
double GetWorldUnitLength() const
virtual void DrawPolyline(const std::vector< VECTOR2D > &aPointList)
virtual void SetMinLineWidth(float aLineWidth)
Set the minimum line width in pixels.
KICURSOR m_currentNativeCursor
Current cursor.
bool m_globalFlipY
Flag for Y axis flipping.
virtual void UnlockContext(int aClientCookie)
void SetClearColor(const COLOR4D &aColor)
void SetScreenSize(const VECTOR2I &aSize)
const COLOR4D & GetClearColor() const
virtual void DrawSegmentChain(const SHAPE_LINE_CHAIN &aLineChain, double aWidth)
static const int GRID_DEPTH
Depth level on which the grid is drawn.
virtual bool IsInitialized() const
Return the initialization status for the canvas.
float GetMinLineWidth() const
Get the minimum line width in pixels.
void SetGlyphSize(const VECTOR2I aSize)
virtual void DrawGlyphs(const std::vector< std::unique_ptr< KIFONT::GLYPH > > &aGlyphs)
Draw polygons representing font glyphs.
virtual void Scale(const VECTOR2D &aScale)
Scale the context.
virtual void DrawCurve(const VECTOR2D &startPoint, const VECTOR2D &controlPointA, const VECTOR2D &controlPointB, const VECTOR2D &endPoint, double aFilterValue=0.0)
Draw a cubic bezier spline.
bool m_isFillEnabled
Is filling of graphic objects enabled ?
float m_minLineWidth
Minimum line width in pixels.
virtual void EndGroup()
End the group.
virtual void DrawArc(const VECTOR2D &aCenterPoint, double aRadius, const EDA_ANGLE &aStartAngle, const EDA_ANGLE &aAngle)
Draw an arc.
virtual void Transform(const MATRIX3x3D &aTransformation)
Transform the context.
virtual void SetNegativeDrawMode(bool aSetting)
Set negative draw mode in the renderer.
COLOR4D m_gridColor
Color of the grid.
VECTOR2D ToWorld(const VECTOR2D &aPoint) const
Compute the point position in world coordinates from given screen coordinates.
COLOR4D m_strokeColor
The color of the outlines.
double computeMinGridSpacing() const
Compute minimum grid spacing from the grid settings.
void SetFontItalic(bool aItalic)
bool m_isStrokeEnabled
Are the outlines stroked ?
virtual void DrawBitmap(const BITMAP_BASE &aBitmap, double alphaBlend=1.0)
Draw a bitmap image.
GAL_DISPLAY_OPTIONS & m_options
bool m_gridVisibility
Should the grid be shown.
double GetMinDepth() const
virtual void ClearCache()
Delete all data created during caching of graphic items.
virtual void SetTarget(RENDER_TARGET aTarget)
Set the target for rendering.
virtual void DrawSegment(const VECTOR2D &aStartPoint, const VECTOR2D &aEndPoint, double aWidth)
Draw a rounded segment.
double m_screenDPI
The dots per inch of the screen.
virtual void DrawPolyline(const SHAPE_LINE_CHAIN &aLineChain)
const VECTOR2I & GetScreenPixelSize() const
Return GAL canvas size in pixels.
friend class GAL_UPDATE_CONTEXT
void SetGridVisibility(bool aVisibility)
Set the visibility setting of the grid.
float GetLineWidth() const
Get the line width.
virtual void Save()
Save the context.
bool m_globalFlipX
Flag for X axis flipping.
virtual void LockContext(int aClientCookie)
Use GAL_CONTEXT_LOCKER RAII object unless you know what you're doing.
virtual void DrawSegmentChain(const std::vector< VECTOR2D > &aPointList, double aWidth)
Draw a chain of rounded segments.
void SetWorldScreenMatrix(const MATRIX3x3D &aMatrix)
Set the world <-> screen transformation matrix.
GR_TEXT_V_ALIGN_T GetVerticalJustify() const
bool GetIsStroke() const
Get the stroke status.
KIGFX::CROSS_HAIR_MODE m_crossHairMode
Crosshair drawing mode.
virtual void DrawCursor(const VECTOR2D &aCursorPosition)
Draw the cursor.
void SetDepthRange(const VECTOR2D &aDepthRange)
Set the range of the layer depth.
double GetWorldScale() const
Get the world scale.
VECTOR2D m_lookAtPoint
Point to be looked at in world space.
GAL(GAL_DISPLAY_OPTIONS &aOptions)
virtual bool IsVisible() const
Return true if the GAL canvas is visible on the screen.
void SetScreenDPI(double aScreenDPI)
Set the dots per inch of the screen.
virtual void DrawPolyline(const VECTOR2D aPointList[], int aListSize)
virtual void EnableDepthTest(bool aEnabled=false)
bool m_forceDisplayCursor
Always show cursor.
static const int MAX_DEPTH
Container for data for KiCad programs.
Definition pgm_base.h:102
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:562
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.
KICURSOR
Definition cursors.h:40
#define GAL_API
Definition gal.h:27
MATRIX3x3< double > MATRIX3x3D
Definition matrix3x3.h:469
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
GRID_STYLE
Type definition of the grid style.
@ SMALL_CROSS
Use small cross instead of dots for the grid.
RENDER_TARGET
RENDER_TARGET: Possible rendering targets.
Definition definitions.h:32
@ TARGET_CACHED
Main rendering target (cached)
Definition definitions.h:33
PGM_BASE * PgmOrNull()
Return a reference that can be nullptr when running a shared lib from a script, not from a kicad app.
see class PGM_BASE
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
GR_TEXT_V_ALIGN_T
This is API surface mapped to common.types.VertialAlignment.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682