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#include <math/box2.h>
33
34#include <gal/gal.h>
35#include <gal/color4d.h>
36#include <gal/cursors.h>
37#include <gal/definitions.h>
39#include <font/stroke_font.h>
40#include <geometry/eda_angle.h>
41#include <pgm_base.h>
43
45class SHAPE_POLY_SET;
46class BITMAP_BASE;
47
48namespace KIGFX
49{
50
57inline double AutoSparsePitch( double aPitch, unsigned aTick, double aThreshold )
58{
59 const unsigned mult = ( aTick > 1 ) ? aTick : 2u;
60
61 while( aPitch > 0.0 && aPitch <= aThreshold )
62 aPitch *= mult;
63
64 return aPitch;
65}
66
67
74{
75 bool unbounded = false;
77 bool axesEnabled = false;
79 bool snapCursor = false;
80 bool highlighted = false;
81
82 unsigned tick = 0;
83
86};
87
88
91constexpr double GRID_DIM_ALPHA = 0.4;
92
94constexpr double GRID_EDGE_DARKEN = 0.75;
95
97constexpr double GRID_SELECTED_BRIGHTEN = 0.5;
98
99
107
108
119class GAL_API GAL : GAL_DISPLAY_OPTIONS_OBSERVER
120{
121 // These friend declarations allow us to hide routines that should not be called. The
122 // corresponding RAII objects must be used instead.
123 friend class GAL_CONTEXT_LOCKER;
124 friend class GAL_UPDATE_CONTEXT;
126
127public:
128 // Constructor / Destructor
129 GAL( GAL_DISPLAY_OPTIONS& aOptions );
130 virtual ~GAL();
131
133 virtual bool IsInitialized() const { return true; }
134
136 virtual bool IsVisible() const { return true; }
137
139 virtual bool IsCairoEngine() { return false; }
140
142 virtual bool IsOpenGlEngine() { return false; }
143
144 // ---------------
145 // Drawing methods
146 // ---------------
147
156 virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) {};
157
167 virtual void DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint,
168 double aWidth ){};
169
176 virtual void DrawSegmentChain( const std::vector<VECTOR2D>& aPointList, double aWidth ){};
177 virtual void DrawSegmentChain( const SHAPE_LINE_CHAIN& aLineChain, double aWidth ){};
178
184 virtual void DrawPolyline( const std::deque<VECTOR2D>& aPointList ) {};
185 virtual void DrawPolyline( const std::vector<VECTOR2D>& aPointList ) {};
186 virtual void DrawPolyline( const VECTOR2D aPointList[], int aListSize ) {};
187 virtual void DrawPolyline( const SHAPE_LINE_CHAIN& aLineChain ) {};
188
194 virtual void DrawPolylines( const std::vector<std::vector<VECTOR2D>>& aPointLists ){};
195
202 virtual void DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) {};
203
211 virtual void DrawHoleWall( const VECTOR2D& aCenterPoint, double aHoleRadius,
212 double aWallWidth ) {};
213
222 virtual void DrawArc( const VECTOR2D& aCenterPoint, double aRadius,
223 const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aAngle ){};
224
245 virtual void DrawArcSegment( const VECTOR2D& aCenterPoint, double aRadius,
246 const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aAngle,
247 double aWidth, double aMaxError ){};
248
257 virtual void DrawEllipse( const VECTOR2D& aCenterPoint, double aMajorRadius, double aMinorRadius,
258 const EDA_ANGLE& aRotation );
259
270 virtual void DrawEllipseArc( const VECTOR2D& aCenterPoint, double aMajorRadius, double aMinorRadius,
271 const EDA_ANGLE& aRotation, const EDA_ANGLE& aStartAngle, const EDA_ANGLE& aEndAngle );
272
279 virtual void DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) {};
280
281 void DrawRectangle( const BOX2I& aRect )
282 {
283 DrawRectangle( aRect.GetOrigin(), aRect.GetEnd() );
284 }
285
289 virtual void DrawGlyph( const KIFONT::GLYPH& aGlyph, int aNth = 0, int aTotal = 1 ) {};
290
294 virtual void DrawGlyphs( const std::vector<std::unique_ptr<KIFONT::GLYPH>>& aGlyphs )
295 {
296 COLOR4D fillColor = GetFillColor();
297 COLOR4D strokeColor = GetStrokeColor();
298
299 for( size_t i = 0; i < aGlyphs.size(); i++ )
300 {
301 if( aGlyphs[i]->IsHover() )
302 {
305 }
306
307 DrawGlyph( *aGlyphs[i], i, aGlyphs.size() );
308
309 if( aGlyphs[i]->IsHover() )
310 {
311 SetFillColor( fillColor );
312 SetStrokeColor( strokeColor );
313 }
314 }
315 }
316
317
323 virtual void DrawPolygon( const std::deque<VECTOR2D>& aPointList ) {};
324 virtual void DrawPolygon( const VECTOR2D aPointList[], int aListSize ) {};
325 virtual void DrawPolygon( const SHAPE_POLY_SET& aPolySet,
326 bool aStrokeTriangulation = false ) {};
327 virtual void DrawPolygon( const SHAPE_LINE_CHAIN& aPolySet ) {};
328
340 virtual void DrawCurve( const VECTOR2D& startPoint, const VECTOR2D& controlPointA,
341 const VECTOR2D& controlPointB, const VECTOR2D& endPoint,
342 double aFilterValue = 0.0 ) {};
343
347 virtual void DrawBitmap( const BITMAP_BASE& aBitmap, double alphaBlend = 1.0 ) {};
348
349 // --------------
350 // Screen methods
351 // --------------
352
354 virtual void ResizeScreen( int aWidth, int aHeight ) {};
355
357 virtual bool Show( bool aShow ) { return true; };
358
361 {
362 return m_screenSize;
363 }
364
366 virtual int GetSwapInterval() const { return 0; };
367
369 virtual void Flush() {};
370
371 void SetClearColor( const COLOR4D& aColor )
372 {
373 m_clearColor = aColor;
374 }
375
376 const COLOR4D& GetClearColor( ) const
377 {
378 return m_clearColor;
379 }
380
384 virtual void ClearScreen() {};
385
386 // -----------------
387 // Attribute setting
388 // -----------------
389
395 virtual void SetIsFill( bool aIsFillEnabled )
396 {
397 m_isFillEnabled = aIsFillEnabled;
398 }
399
405 inline bool GetIsFill() const
406 {
407 return m_isFillEnabled;
408 }
409
415 virtual void SetIsStroke( bool aIsStrokeEnabled )
416 {
417 m_isStrokeEnabled = aIsStrokeEnabled;
418 }
419
425 inline bool GetIsStroke() const
426 {
427 return m_isStrokeEnabled;
428 }
429
435 virtual void SetFillColor( const COLOR4D& aColor )
436 {
437 m_fillColor = aColor;
438 }
439
445 inline const COLOR4D& GetFillColor() const
446 {
447 return m_fillColor;
448 }
449
455 virtual void SetStrokeColor( const COLOR4D& aColor )
456 {
457 m_strokeColor = aColor;
458 }
459
460 virtual void SetHoverColor( const COLOR4D& aColor )
461 {
462 m_hoverColor = aColor;
463 }
464
470 inline const COLOR4D& GetStrokeColor() const
471 {
472 return m_strokeColor;
473 }
474
480 virtual void SetLineWidth( float aLineWidth )
481 {
482 m_lineWidth = aLineWidth;
483 }
484
490 virtual void SetMinLineWidth( float aLineWidth )
491 {
492 m_minLineWidth = aLineWidth;
493 }
494
500 inline float GetLineWidth() const
501 {
502 return m_lineWidth;
503 }
504
510 inline float GetMinLineWidth() const
511 {
512 return m_minLineWidth;
513 }
514
523 virtual void SetLayerDepth( double aLayerDepth )
524 {
525 wxCHECK_MSG( aLayerDepth <= m_depthRange.y, /*void*/,
526 wxT( "SetLayerDepth: below minimum" ) );
527 wxCHECK_MSG( aLayerDepth >= m_depthRange.x, /*void*/,
528 wxT( "SetLayerDepth: above maximum" ) );
529
530 m_layerDepth = aLayerDepth;
531 }
532
540 inline void AdvanceDepth()
541 {
543 }
544
545 // ----
546 // Text
547 // ----
548
557 virtual void BitmapText( const wxString& aText, const VECTOR2I& aPosition,
558 const EDA_ANGLE& aAngle );
559
566 void ResetTextAttributes();
567
568 void SetGlyphSize( const VECTOR2I aSize ) { m_attributes.m_Size = aSize; }
569 const VECTOR2I& GetGlyphSize() const { return m_attributes.m_Size; }
570
571 inline void SetFontBold( const bool aBold ) { m_attributes.m_Bold = aBold; }
572 inline bool IsFontBold() const { return m_attributes.m_Bold; }
573
574 inline void SetFontItalic( bool aItalic ) { m_attributes.m_Italic = aItalic; }
575 inline bool IsFontItalic() const { return m_attributes.m_Italic; }
576
577 inline void SetFontUnderlined( bool aUnderlined ) { m_attributes.m_Underlined = aUnderlined; }
578 inline bool IsFontUnderlined() const { return m_attributes.m_Underlined; }
579
580 void SetTextMirrored( const bool aMirrored ) { m_attributes.m_Mirrored = aMirrored; }
581 bool IsTextMirrored() const { return m_attributes.m_Mirrored; }
582
583 void SetHorizontalJustify( const GR_TEXT_H_ALIGN_T aHorizontalJustify )
584 {
585 m_attributes.m_Halign = aHorizontalJustify;
586 }
587
589
590 void SetVerticalJustify( const GR_TEXT_V_ALIGN_T aVerticalJustify )
591 {
592 m_attributes.m_Valign = aVerticalJustify;
593 }
594
596
597
598 // --------------
599 // Transformation
600 // --------------
601
607 virtual void Transform( const MATRIX3x3D& aTransformation ) {};
608
614 virtual void Rotate( double aAngle ) {};
615
621 virtual void Translate( const VECTOR2D& aTranslation ) {};
622
628 virtual void Scale( const VECTOR2D& aScale ) {};
629
631 virtual void Save() {};
632
634 virtual void Restore() {};
635
636 // --------------------------------------------
637 // Group methods
638 // ---------------------------------------------
639
648 virtual int BeginGroup() { return 0; };
649
651 virtual void EndGroup() {};
652
658 virtual void DrawGroup( int aGroupNumber ) {};
659
666 virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) {};
667
674 virtual void ChangeGroupDepth( int aGroupNumber, int aDepth ) {};
675
681 virtual void DeleteGroup( int aGroupNumber ) {};
682
686 virtual void ClearCache() {};
687
688 // --------------------------------------------------------
689 // Handling the world <-> screen transformation
690 // --------------------------------------------------------
691
693 virtual void ComputeWorldScreenMatrix();
694
701 {
702 return m_worldScreenMatrix;
703 }
704
711 {
712 return m_screenWorldMatrix;
713 }
714
720 inline void SetWorldScreenMatrix( const MATRIX3x3D& aMatrix )
721 {
722 m_worldScreenMatrix = aMatrix;
723 }
724
728 BOX2D GetVisibleWorldExtents() const;
729
737 void SetWorldUnitLength( double aWorldUnitLength ) { m_worldUnitLength = aWorldUnitLength; }
738
739 double GetWorldUnitLength() const { return m_worldUnitLength; }
740
741 void SetScreenSize( const VECTOR2I& aSize ) { m_screenSize = aSize; }
742
749 void SetScreenDPI( double aScreenDPI ) { m_screenDPI = aScreenDPI; }
750 double GetScreenDPI() const { return m_screenDPI; }
751
757 void SetLookAtPoint( const VECTOR2D& aPoint ) { m_lookAtPoint = aPoint; }
758 const VECTOR2D& GetLookAtPoint() const { return m_lookAtPoint; }
759
760 void SetZoomFactor( double aZoomFactor ) { m_zoomFactor = aZoomFactor; }
761 double GetZoomFactor() const { return m_zoomFactor; }
762
766 void SetRotation( double aRotation ) { m_rotation = aRotation; }
767 double GetRotation() const { return m_rotation; }
768
777 void SetDepthRange( const VECTOR2D& aDepthRange ) { m_depthRange = aDepthRange; }
778 double GetMinDepth() const { return m_depthRange.x; }
779 double GetMaxDepth() const { return m_depthRange.y; }
780
786 double GetWorldScale() const { return m_worldScale; }
787
794 inline void SetFlip( bool xAxis, bool yAxis )
795 {
796 m_globalFlipX = xAxis;
797 m_globalFlipY = yAxis;
798 }
799
800 bool IsFlippedX() const { return m_globalFlipX; }
801 bool IsFlippedY() const { return m_globalFlipY; }
802
803 // ---------------------------
804 // Buffer manipulation methods
805 // ---------------------------
806
812 virtual void SetTarget( RENDER_TARGET aTarget ) {};
813
819 virtual RENDER_TARGET GetTarget() const { return TARGET_CACHED; };
820
826 virtual void ClearTarget( RENDER_TARGET aTarget ) {};
827
833 virtual bool HasTarget( RENDER_TARGET aTarget )
834 {
835 return true;
836 };
837
849 virtual void SetNegativeDrawMode( bool aSetting ) {};
850
858 virtual void StartDiffLayer() {};
859
865 virtual void EndDiffLayer() {};
866
875 virtual void StartNegativesLayer(){};
876
881 virtual void EndNegativesLayer(){};
882
883 // -------------
884 // Grid methods
885 // -------------
886
892 void SetGridVisibility( bool aVisibility ) { m_gridVisibility = aVisibility; }
893
894 bool GetGridVisibility() const { return m_gridVisibility; }
895
896 bool GetGridSnapping() const
897 {
898 return m_options.m_gridSnapping == KIGFX::GRID_SNAPPING::ALWAYS ||
900 }
901
907 inline void SetGridOrigin( const VECTOR2D& aGridOrigin )
908 {
909 m_gridOrigin = aGridOrigin;
910
911 if( m_gridSize.x == 0.0 || m_gridSize.y == 0.0 )
912 {
913 m_gridOffset = VECTOR2D( 0.0, 0.0);
914 }
915 else
916 {
917 m_gridOffset = VECTOR2D( (long) m_gridOrigin.x % (long) m_gridSize.x,
918 (long) m_gridOrigin.y % (long) m_gridSize.y );
919 }
920 }
921
922 inline const VECTOR2D& GetGridOrigin() const
923 {
924 return m_gridOrigin;
925 }
926
932 inline void SetGridSize( const VECTOR2D& aGridSize )
933 {
934 m_gridSize = aGridSize;
935
936 // Avoid stupid grid size values: a grid size should be >= 1 in internal units
937 m_gridSize.x = std::max( 1.0, m_gridSize.x );
938 m_gridSize.y = std::max( 1.0, m_gridSize.y );
939
940 m_gridOffset = VECTOR2D( (long) m_gridOrigin.x % (long) m_gridSize.x,
941 (long) m_gridOrigin.y % (long) m_gridSize.y );
942 }
943
949 inline const VECTOR2D& GetGridSize() const
950 {
951 return m_gridSize;
952 }
953
960 {
961 VECTOR2D gridScreenSize( m_gridSize );
962 gridScreenSize.x = std::max( 100.0, gridScreenSize.x );
963 gridScreenSize.y = std::max( 100.0, gridScreenSize.y );
964
965 double gridThreshold = computeMinGridSpacing() / m_worldScale;
966
968 gridThreshold *= 2.0;
969
970 // If we cannot display the grid density, scale down by a tick size and
971 // try again. Eventually, we get some representation of the grid
972 const double minSize = std::min( gridScreenSize.x, gridScreenSize.y );
973 const double sparsed = AutoSparsePitch( minSize, m_gridTick, gridThreshold );
974
975 if( minSize > 0.0 && sparsed != minSize )
976 gridScreenSize *= sparsed / minSize;
977
978 return gridScreenSize;
979 }
980
986 inline void SetGridColor( const COLOR4D& aGridColor )
987 {
988 m_gridColor = aGridColor;
989 }
990
996 inline void SetAxesColor( const COLOR4D& aAxesColor )
997 {
998 m_axesColor = aAxesColor;
999 }
1000
1004 inline void SetAxesEnabled( bool aAxesEnabled )
1005 {
1006 m_axesEnabled = aAxesEnabled;
1007 }
1008
1014 inline void SetCoarseGrid( int aInterval )
1015 {
1016 m_gridTick = aInterval;
1017 }
1018
1024 inline float GetGridLineWidth() const
1025 {
1026 return m_gridLineWidth;
1027 }
1028
1036 void SetGridSources( std::vector<GRID_SOURCE> aSources );
1037
1038 const std::vector<GRID_SOURCE>& GetGridSources() const { return m_gridSources; }
1039
1041 int GetCoarseGrid() const { return m_gridTick; }
1042 const COLOR4D& GetGridColor() const { return m_gridColor; }
1043
1045 virtual void DrawGrid() {};
1046
1053 VECTOR2D GetGridPoint( const VECTOR2D& aPoint ) const;
1054
1061 inline VECTOR2D ToWorld( const VECTOR2D& aPoint ) const
1062 {
1063 return VECTOR2D( m_screenWorldMatrix * aPoint );
1064 }
1065
1072 inline VECTOR2D ToScreen( const VECTOR2D& aPoint ) const
1073 {
1074 return VECTOR2D( m_worldScreenMatrix * aPoint );
1075 }
1076
1084 virtual bool SetNativeCursorStyle( KICURSOR aCursor, bool aHiDPI );
1085
1091 inline void SetCursorEnabled( bool aCursorEnabled )
1092 {
1093 m_isCursorEnabled = aCursorEnabled;
1094 }
1095
1101 bool IsCursorEnabled() const
1102 {
1104 }
1105
1111 inline void SetCursorColor( const COLOR4D& aCursorColor )
1112 {
1113 m_cursorColor = aCursorColor;
1114 }
1115
1121 virtual void DrawCursor( const VECTOR2D& aCursorPosition ) {};
1122
1123 virtual void EnableDepthTest( bool aEnabled = false ) {};
1124
1129 virtual bool IsContextLocked()
1130 {
1131 return false;
1132 }
1133
1142 virtual bool IsContextValid() const
1143 {
1144 return true;
1145 }
1146
1153 {
1155 }
1156
1162 virtual bool IsResetSettled()
1163 {
1164 return true;
1165 }
1166
1167
1169 virtual void LockContext( int aClientCookie ) {}
1170
1171 virtual void UnlockContext( int aClientCookie ) {}
1172
1177
1180 virtual void BeginDrawing() {};
1181
1184 virtual void EndDrawing() {};
1185protected:
1186
1189 virtual void beginUpdate() {}
1190
1192 virtual void endUpdate() {}
1193
1194
1195
1197 inline void computeWorldScale()
1198 {
1200
1201 PGM_BASE* pgm = PgmOrNull();
1202
1203 if( pgm && pgm->GetCommonSettings() )
1205 }
1206
1212 double computeMinGridSpacing() const;
1213
1218 BOX2D gridScreenBBox( const GRID_SOURCE& aSrc ) const;
1219
1221 static const int MIN_DEPTH;
1222 static const int MAX_DEPTH;
1223
1225 static const int GRID_DEPTH;
1226
1230 COLOR4D getCursorColor() const;
1231
1232 // ---------------
1233 // Settings observer interface
1234 // ---------------
1238 void OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& aOptions ) override;
1239
1248 virtual bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions );
1249
1253 template <typename T>
1254 void normalize( T &a, T &b )
1255 {
1256 if( a > b )
1257 {
1258 T tmp = a;
1259 a = b;
1260 b = tmp;
1261 }
1262 }
1263
1266
1267 std::stack<double> m_depthStack;
1269
1273
1275 double m_rotation;
1279
1282
1285
1288
1293
1296
1297 // Grid settings
1310
1311 std::vector<GRID_SOURCE> m_gridSources;
1312
1313 // Cursor settings
1319
1321
1322private:
1323
1324 inline double getLayerDepth() const
1325 {
1326 return m_layerDepth;
1327 }
1328
1330
1331 friend class GAL_SCOPED_ATTRS;
1332};
1333
1334
1336{
1337public:
1339 m_gal( aGal )
1340 {
1341 m_cookie = rand();
1342 m_gal->LockContext( m_cookie );
1343 }
1344
1346 {
1347 m_gal->UnlockContext( m_cookie );
1348 }
1349
1350protected:
1353};
1354
1355
1357{
1358public:
1360 GAL_CONTEXT_LOCKER( aGal ),
1361 m_updating( aGal->IsContextValid() )
1362 {
1363 if( m_updating )
1364 m_gal->beginUpdate();
1365 }
1366
1368 {
1369 if( m_updating )
1370 m_gal->endUpdate();
1371 }
1372
1374 bool IsUpdating() const
1375 {
1376 return m_updating;
1377 }
1378
1379private:
1381};
1382
1383
1385{
1386public:
1388 GAL_CONTEXT_LOCKER( aGal ),
1389 m_drawing( aGal->IsContextValid() )
1390 {
1391 if( m_drawing )
1392 m_gal->BeginDrawing();
1393 }
1394
1395 ~GAL_DRAWING_CONTEXT() noexcept( false )
1396 {
1397 if( m_drawing )
1398 m_gal->EndDrawing();
1399 }
1400
1402 bool IsDrawing() const
1403 {
1404 return m_drawing;
1405 }
1406
1407private:
1409};
1410
1411
1416{
1417public:
1419 {
1426
1427 // It is not clear to me that GAL needs to save text attributes.
1428 // Only BitmapText uses it, and maybe that should be passed in
1429 // explicitly (like for Draw) - every caller of BitmapText sets
1430 // the text attributes anyway.
1431 // TEXT_ATTRS = 64,
1432
1433 // Convenience flags
1437
1439 };
1440
1446 GAL_SCOPED_ATTRS( KIGFX::GAL& aGal, int aFlags )
1447 : m_gal( aGal ), m_flags( aFlags )
1448 {
1449 // Save what we need to restore later.
1450 // These are all so cheap to copy, it's likely not worth if'ing
1451 m_strokeWidth = aGal.GetLineWidth();
1453 m_isStroke = aGal.GetIsStroke();
1454 m_fillColor = aGal.GetFillColor();
1455 m_isFill = aGal.GetIsFill();
1456 m_layerDepth = aGal.getLayerDepth();
1457 }
1458
1460 {
1461 // Restore the attributes that were saved
1462 // based on the flags that were set.
1463
1464 if( m_flags & STROKE_WIDTH )
1465 m_gal.SetLineWidth( m_strokeWidth );
1466
1467 if( m_flags & STROKE_COLOR )
1468 m_gal.SetStrokeColor( m_strokeColor );
1469
1470 if( m_flags & IS_STROKE )
1471 m_gal.SetIsStroke( m_isStroke );
1472
1473 if( m_flags & FILL_COLOR )
1474 m_gal.SetFillColor( m_fillColor );
1475
1476 if( m_flags & IS_FILL )
1477 m_gal.SetIsFill( m_isFill );
1478
1479 if( m_flags & LAYER_DEPTH )
1480 m_gal.SetLayerDepth( m_layerDepth );
1481 }
1482
1483private:
1486
1490
1493
1495};
1496
1497
1498}; // namespace KIGFX
1499
1500#endif /* GRAPHICSABSTRACTIONLAYER_H_ */
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
BOX2< VECTOR2D > BOX2D
Definition box2.h:915
This class handle bitmap images in KiCad.
Definition bitmap_base.h:45
constexpr const Vec GetEnd() const
Definition box2.h:209
constexpr const Vec & GetOrigin() const
Definition box2.h:207
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.
virtual bool IsContextValid() const
Check whether the locked context is actually the current one.
const std::vector< GRID_SOURCE > & GetGridSources() const
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.
virtual GAL_CONTEXT_LOSS GetContextLoss() const
Check whether a GPU reset destroyed this canvas' rendering context.
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 bool IsResetSettled()
Check whether the driver has finished the reset that destroyed this canvas' context.
virtual void DrawGrid()
Draw the grid.
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)
GRID_STYLE GetGridStyle() const
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.
const COLOR4D & GetGridColor() const
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 ?
std::vector< GRID_SOURCE > m_gridSources
Sources overlayed on the display grid.
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:101
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:546
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
const int minSize
Push and Shove router track width and via size dialog.
#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:30
constexpr double GRID_DIM_ALPHA
Opacity of the background wash laid over a selected grid item's area, to fade the grids showing throu...
GAL_CONTEXT_LOSS
State of a canvas' rendering context after a GPU reset.
@ REPEATED
Contexts keep being lost; stop using this backend.
@ RECOVERABLE
Context was lost; rebuild the canvas.
GRID_STYLE
Type definition of the grid style.
@ SMALL_CROSS
Use small cross instead of 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...
@ NONE
No updates are required.
Definition view_item.h:48
RENDER_TARGET
RENDER_TARGET: Possible rendering targets.
Definition definitions.h:32
@ TARGET_CACHED
Main rendering target (cached)
Definition definitions.h:33
constexpr double GRID_EDGE_DARKEN
How far the hairline round a grid's coverage sits below its own colour.
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
Geometry of a regular grid (cartesian or polar) and the math operations for snapping and coverage tes...
Render-time projection of a grid: GRID_GEOMETRY (kind/origin/pitch/orientation/extent) plus rendering...
bool snapCursor
Participate in the cursor snap (GAL::GetGridPoint).
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.
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:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707