You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
5.3 KiB

3 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software: you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation, either version 3 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef GR_BASIC
  22. #define GR_BASIC
  23. #include <gal/color4d.h>
  24. #include <math/box2.h>
  25. #include <vector>
  26. #include <wx/pen.h>
  27. #include <wx/dc.h>
  28. using KIGFX::COLOR4D;
  29. /// Drawmode. Compositing mode plus a flag or two
  30. enum GR_DRAWMODE {
  31. GR_OR = 0x01000000,
  32. GR_XOR = 0x02000000,
  33. GR_AND = 0x04000000,
  34. GR_NXOR = 0x08000000,
  35. GR_INVERT = 0x10000000,
  36. GR_ALLOW_HIGHCONTRAST = 0x20000000,
  37. GR_COPY = 0x40000000,
  38. GR_HIGHLIGHT = 0x80000000,
  39. UNSPECIFIED_DRAWMODE = -1
  40. };
  41. inline GR_DRAWMODE operator~( const GR_DRAWMODE& a )
  42. {
  43. return static_cast<GR_DRAWMODE>( ~int( a ) );
  44. }
  45. inline GR_DRAWMODE operator|( const GR_DRAWMODE& a, const GR_DRAWMODE& b )
  46. {
  47. return static_cast<GR_DRAWMODE>( int( a ) | int( b ) );
  48. }
  49. inline GR_DRAWMODE operator&( const GR_DRAWMODE& a, const GR_DRAWMODE& b )
  50. {
  51. return static_cast<GR_DRAWMODE>( int( a ) & int( b ) );
  52. }
  53. extern GR_DRAWMODE g_XorMode;
  54. typedef enum {
  55. /* Line styles for Get/SetLineStyle. */
  56. GR_SOLID_LINE = 0,
  57. GR_DOTTED_LINE = 1,
  58. GR_DASHED_LINE = 3
  59. } GRLineStypeType;
  60. void GRResetPenAndBrush( wxDC* DC );
  61. void GRSetColorPen( wxDC* DC, const COLOR4D& Color, int width = 1,
  62. wxPenStyle stype = wxPENSTYLE_SOLID );
  63. void GRSetBrush( wxDC* DC, const COLOR4D& Color, bool fill = false );
  64. /**
  65. * @param flagforce True to force a black pen whenever the asked color.
  66. */
  67. void GRForceBlackPen( bool flagforce );
  68. /**
  69. * @return True if a black pen was forced or false if not forced.
  70. */
  71. bool GetGRForceBlackPenState( void );
  72. void GRLine( wxDC* aDC, const VECTOR2I& aStart, const VECTOR2I& aEnd, int aWidth,
  73. const COLOR4D& aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID );
  74. void GRLine( wxDC* DC, int x1, int y1, int x2, int y2, int width, const COLOR4D& Color,
  75. wxPenStyle aStyle = wxPENSTYLE_SOLID );
  76. void GRMoveTo( int x, int y );
  77. void GRLineTo( wxDC* DC, int x, int y, int width, const COLOR4D& Color );
  78. void GRPoly( wxDC* DC, int n, const VECTOR2I* Points, bool Fill, int width, const COLOR4D& Color,
  79. const COLOR4D& BgColor );
  80. /**
  81. * Draw a closed polygon onto the drawing context \a aDC and optionally fills and/or draws
  82. * a border around it.
  83. *
  84. * @param aDC the device context into which drawing should occur.
  85. * @param aPointCount the number of points in the array \a aPoints.
  86. * @param aPoints The points to draw.
  87. * @param doFill true if polygon is to be filled, else false and only the boundary is drawn.
  88. * @param aColor the color of the border and the fill.
  89. */
  90. void GRClosedPoly( wxDC* aDC, int aPointCount, const VECTOR2I* aPoints, bool doFill,
  91. const COLOR4D& aColor );
  92. /**
  93. * Draw a circle onto the drawing context \a aDC centered at the user coordinates (x,y).
  94. *
  95. * @param aDC the device context into which drawing should occur.
  96. * @param x The x coordinate in user space of the center of the circle.
  97. * @param y The y coordinate in user space of the center of the circle.
  98. * @param aRadius is the radius of the circle.
  99. * @param aColor is the color to draw.
  100. * @see COLOR4D
  101. */
  102. void GRFilledCircle( wxDC* aDC, const VECTOR2I& aPos, int aRadius, int aWidth,
  103. const COLOR4D& aStrokeColor, const COLOR4D& aFillColor );
  104. void GRCircle( wxDC* aDC, const VECTOR2I& aPos, int aRadius, int aWidth, const COLOR4D& aColor );
  105. void GRArc( wxDC* aDC, const VECTOR2I& aStart, const VECTOR2I& aEnd, const VECTOR2I& aCenter,
  106. int aWidth, const COLOR4D& aColor );
  107. void GRFilledArc( wxDC* DC, const VECTOR2I& aStart, const VECTOR2I& aEnd, const VECTOR2I& aCenter,
  108. int width, const COLOR4D& Color, const COLOR4D& BgColor );
  109. void GRFilledSegment( wxDC* aDC, const VECTOR2I& aStart, const VECTOR2I& aEnd, int aWidth,
  110. const COLOR4D& aColor );
  111. void GRCSegm( wxDC* aDC, const VECTOR2I& aStart, const VECTOR2I& aEnd, int aWidth,
  112. const COLOR4D& aColor );
  113. void GRFilledRect( wxDC* DC, const VECTOR2I& aStart, const VECTOR2I& aEnd, int aWidth,
  114. const COLOR4D& aColor, const COLOR4D& aBgColor );
  115. void GRRect( wxDC* DC, const VECTOR2I& aStart, const VECTOR2I& aEnd, int aWidth,
  116. const COLOR4D& aColor );
  117. void GRSFilledRect( wxDC* DC, int x1, int y1, int x2, int y2, int width, const COLOR4D& Color,
  118. const COLOR4D& BgColor );
  119. #endif /* define GR_BASIC */