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.

244 lines
9.8 KiB

  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@verizon.net>
  6. * Copyright (C) 1992-2018 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. /**
  22. * @file gr_basic.h
  23. */
  24. #ifndef GR_BASIC
  25. #define GR_BASIC
  26. #include <gal/color4d.h>
  27. #include <vector>
  28. #include <eda_rect.h>
  29. using KIGFX::COLOR4D;
  30. /// Drawmode. Compositing mode plus a flag or two
  31. enum GR_DRAWMODE {
  32. GR_OR = 0x01000000,
  33. GR_XOR = 0x02000000,
  34. GR_AND = 0x04000000,
  35. GR_NXOR = 0x08000000,
  36. GR_INVERT = 0x10000000,
  37. GR_ALLOW_HIGHCONTRAST = 0x20000000,
  38. GR_COPY = 0x40000000,
  39. GR_HIGHLIGHT = 0x80000000,
  40. UNSPECIFIED_DRAWMODE = -1
  41. };
  42. inline void DrawModeAddHighlight(GR_DRAWMODE *mode)
  43. {
  44. *mode = static_cast<GR_DRAWMODE>( int( *mode ) | GR_HIGHLIGHT );
  45. }
  46. inline void DrawModeAllowHighContrast(GR_DRAWMODE *mode)
  47. {
  48. *mode = static_cast<GR_DRAWMODE>( int( *mode ) | GR_ALLOW_HIGHCONTRAST );
  49. }
  50. inline GR_DRAWMODE operator ~(const GR_DRAWMODE& a)
  51. {
  52. return static_cast<GR_DRAWMODE>( ~int( a ) );
  53. }
  54. inline GR_DRAWMODE operator |(const GR_DRAWMODE& a, const GR_DRAWMODE& b)
  55. {
  56. return static_cast<GR_DRAWMODE>( int( a ) | int( b ) );
  57. }
  58. inline GR_DRAWMODE operator &(const GR_DRAWMODE& a, const GR_DRAWMODE& b)
  59. {
  60. return static_cast<GR_DRAWMODE>( int( a ) & int( b ) );
  61. }
  62. #define GR_M_LEFT_DOWN 0x10000000
  63. #define GR_M_RIGHT_DOWN 0x20000000
  64. #define GR_M_MIDDLE_DOWN 0x40000000
  65. #define GR_M_DCLICK 0x80000000
  66. extern GR_DRAWMODE g_XorMode;
  67. typedef enum {
  68. /* Line styles for Get/SetLineStyle. */
  69. GR_SOLID_LINE = 0,
  70. GR_DOTTED_LINE = 1,
  71. GR_DASHED_LINE = 3
  72. } GRLineStypeType;
  73. void GRResetPenAndBrush( wxDC* DC );
  74. void GRSetColorPen( wxDC* DC, COLOR4D Color, int width = 1, wxPenStyle stype = wxPENSTYLE_SOLID );
  75. void GRSetBrush( wxDC* DC, COLOR4D Color, bool fill = false );
  76. /**
  77. * Function GRForceBlackPen
  78. * @param flagforce True to force a black pen whenever the asked color
  79. */
  80. void GRForceBlackPen( bool flagforce );
  81. /**
  82. * Function GetGRForceBlackPenState
  83. * @return ForceBlackPen (True if a black pen was forced)
  84. */
  85. bool GetGRForceBlackPenState( void );
  86. void GRLine( EDA_RECT* aClipBox, wxDC* aDC,
  87. wxPoint aStart, wxPoint aEnd, int aWidth, COLOR4D aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID );
  88. void GRLine( EDA_RECT* ClipBox, wxDC* DC,
  89. int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle = wxPENSTYLE_SOLID );
  90. void GRMoveTo( int x, int y );
  91. void GRLineTo( EDA_RECT* ClipBox, wxDC* DC,
  92. int x, int y, int width, COLOR4D Color );
  93. void GRPoly( EDA_RECT* ClipBox, wxDC* DC, int n, const wxPoint* Points, bool Fill, int width,
  94. COLOR4D Color, COLOR4D BgColor );
  95. /** Draw cubic (4 points: start control1, control2, end) bezier curve
  96. */
  97. void GRBezier( EDA_RECT* aClipBox, wxDC* aDC, std::vector<wxPoint>& aPoints,
  98. int aWidth, COLOR4D aColor );
  99. /**
  100. * Function GRClosedPoly
  101. * draws a closed polygon onto the drawing context \a aDC and optionally fills
  102. * and/or draws a border around it.
  103. * @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
  104. * @param aDC the device context into which drawing should occur.
  105. * @param aPointCount the number of points in the array \a aPoints.
  106. * @param aPoints The points to draw.
  107. * @param doFill true if polygon is to be filled, else false and only the boundary is drawn.
  108. * @param aPenColor the color of the border.
  109. * @param aFillColor the fill color of the polygon's interior.
  110. */
  111. void GRClosedPoly( EDA_RECT* ClipBox, wxDC* aDC, int aPointCount, const wxPoint* aPoints,
  112. bool doFill, COLOR4D aPenColor, COLOR4D aFillColor );
  113. // @todo could make these 2 closed polygons calls a single function and default
  114. // the aPenWidth argument
  115. /**
  116. * Function GRClosedPoly
  117. * draws a closed polygon onto the drawing context \a aDC and optionally fills
  118. * and/or draws a border around it.
  119. * @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
  120. * @param aDC the device context into which drawing should occur.
  121. * @param aPointCount the number of points in the array \a aPointArray.
  122. * @param aPoints the points to draw.
  123. * @param doFill true if polygon is to be filled, else false and only the boundary is drawn.
  124. * @param aPenWidth is the width of the pen to use on the perimeter, can be zero.
  125. * @param aPenColor the color of the border.
  126. * @param aFillColor the fill color of the polygon's interior.
  127. */
  128. void GRClosedPoly( EDA_RECT* ClipBox, wxDC* aDC, int aPointCount, const wxPoint* aPoints,
  129. bool doFill, int aPenWidth, COLOR4D aPenColor, COLOR4D aFillColor );
  130. /**
  131. * Function GRCircle
  132. * draws a circle onto the drawing context \a aDC centered at the user
  133. * coordinates (x,y)
  134. *
  135. * @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
  136. * @param aDC the device context into which drawing should occur.
  137. * @param x The x coordinate in user space of the center of the circle.
  138. * @param y The y coordinate in user space of the center of the circle.
  139. * @param aRadius is the radius of the circle.
  140. * @param aColor is the color to draw
  141. * @see COLOR4D
  142. */
  143. void GRCircle( EDA_RECT* ClipBox, wxDC* aDC, int x, int y, int aRadius, COLOR4D aColor );
  144. void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width, COLOR4D Color );
  145. void GRFilledCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width,
  146. COLOR4D Color, COLOR4D BgColor );
  147. void GRFilledCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, COLOR4D aColor );
  148. void GRCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, int aWidth, COLOR4D aColor );
  149. void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
  150. double EndAngle, int r, COLOR4D Color );
  151. void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
  152. double EndAngle, int r, int width, COLOR4D Color );
  153. void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  154. int xc, int yc, COLOR4D Color );
  155. void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  156. int xc, int yc, int width, COLOR4D Color );
  157. void GRArc1( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
  158. wxPoint aCenter, int aWidth, COLOR4D aColor );
  159. void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y,
  160. double StAngle, double EndAngle, int r, COLOR4D Color, COLOR4D BgColor );
  161. void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
  162. double EndAngle, int r, int width, COLOR4D Color, COLOR4D BgColor );
  163. void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color );
  164. void GRFillCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  165. int width, COLOR4D Color );
  166. void GRFilledSegment( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
  167. int aWidth, COLOR4D aColor );
  168. void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  169. int width, int aPenSize, COLOR4D Color );
  170. void GRCSegm( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
  171. int aWidth, COLOR4D aColor );
  172. void GRSetColor( COLOR4D Color );
  173. void GRSetDefaultPalette();
  174. COLOR4D GRGetColor();
  175. void GRPutPixel( EDA_RECT* ClipBox, wxDC* DC, int x, int y, COLOR4D color );
  176. void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  177. int x2, int y2, COLOR4D Color, COLOR4D BgColor );
  178. void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  179. int x2, int y2, int width, COLOR4D Color, COLOR4D BgColor );
  180. void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, COLOR4D Color );
  181. void GRRect( EDA_RECT* ClipBox, wxDC* DC,const EDA_RECT& aRect, int aWidth, COLOR4D Color );
  182. void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  183. int x2, int y2, int width, COLOR4D Color );
  184. void GRRectPs( EDA_RECT* aClipBox, wxDC* aDC,const EDA_RECT& aRect,
  185. int aWidth, COLOR4D aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID );
  186. void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  187. int x2, int y2, int width, COLOR4D Color, COLOR4D BgColor );
  188. /**
  189. * Function GRLineArray
  190. * draws an array of lines (not a polygon).
  191. * @param aClipBox = the clip box
  192. * @param aDC = the device context into which drawing should occur.
  193. * @param aLines = a list of pair of coordinate in user space: a pair for each line.
  194. * @param aWidth = the width of each line.
  195. * @param aColor = the color of the lines
  196. * @see COLOR4D
  197. */
  198. void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC,std::vector<wxPoint>& aLines,
  199. int aWidth, COLOR4D aColor );
  200. void GRDrawAnchor( EDA_RECT* aClipBox, wxDC *aDC, int x, int y, int aSize,
  201. COLOR4D aColor );
  202. /**
  203. * Draw text centered on a wxDC with wrapping.
  204. * @param aDC wxDC instance onto which the text will be drawn
  205. * @param aText the text to draw
  206. */
  207. void GRDrawWrappedText( wxDC& aDC, wxString const& aText );
  208. #endif /* define GR_BASIC */