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.

265 lines
11 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. class EDA_RECT;
  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. class EDA_DRAW_PANEL;
  74. void GRSetDrawMode( wxDC* DC, GR_DRAWMODE mode );
  75. GR_DRAWMODE GRGetDrawMode( wxDC* DC );
  76. void GRResetPenAndBrush( wxDC* DC );
  77. void GRSetColorPen( wxDC* DC, COLOR4D Color, int width = 1, wxPenStyle stype = wxPENSTYLE_SOLID );
  78. void GRSetBrush( wxDC* DC, COLOR4D Color, bool fill = false );
  79. /**
  80. * Function GRForceBlackPen
  81. * @param flagforce True to force a black pen whenever the asked color
  82. */
  83. void GRForceBlackPen( bool flagforce );
  84. /**
  85. * Function GetGRForceBlackPenState
  86. * @return ForceBlackPen (True if a black pen was forced)
  87. */
  88. bool GetGRForceBlackPenState( void );
  89. void GRLine( EDA_RECT* aClipBox, wxDC* aDC,
  90. wxPoint aStart, wxPoint aEnd, int aWidth, COLOR4D aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID );
  91. void GRLine( EDA_RECT* ClipBox, wxDC* DC,
  92. int x1, int y1, int x2, int y2, int width, COLOR4D Color, wxPenStyle aStyle = wxPENSTYLE_SOLID );
  93. void GRMixedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  94. int width, COLOR4D Color );
  95. void GRDashedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  96. int width, COLOR4D Color );
  97. void GRDottedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  98. int width, COLOR4D Color );
  99. void GRMoveTo( int x, int y );
  100. void GRLineTo( EDA_RECT* ClipBox, wxDC* DC,
  101. int x, int y, int width, COLOR4D Color );
  102. void GRPoly( EDA_RECT* ClipBox, wxDC* DC, int n, wxPoint Points[], bool Fill,
  103. int width, COLOR4D Color, COLOR4D BgColor );
  104. void GRBezier( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  105. int x3, int y3, int width, COLOR4D Color );
  106. void GRBezier( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  107. int x3, int y3, int x4, int y4, int width, COLOR4D Color );
  108. /**
  109. * Function GRClosedPoly
  110. * draws a closed polygon onto the drawing context \a aDC and optionally fills
  111. * and/or draws a border around it.
  112. * @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
  113. * @param aDC the device context into which drawing should occur.
  114. * @param aPointCount the number of points in the array \a aPoints.
  115. * @param aPoints The points to draw.
  116. * @param doFill true if polygon is to be filled, else false and only the boundary is drawn.
  117. * @param aPenColor the color of the border.
  118. * @param aFillColor the fill color of the polygon's interior.
  119. */
  120. void GRClosedPoly( EDA_RECT* ClipBox,
  121. wxDC * aDC,
  122. int aPointCount,
  123. wxPoint aPoints[],
  124. bool doFill,
  125. COLOR4D aPenColor,
  126. COLOR4D aFillColor );
  127. // @todo could make these 2 closed polygons calls a single function and default
  128. // the aPenWidth argument
  129. /**
  130. * Function GRClosedPoly
  131. * draws a closed polygon onto the drawing context \a aDC and optionally fills
  132. * and/or draws a border around it.
  133. * @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
  134. * @param aDC the device context into which drawing should occur.
  135. * @param aPointCount the number of points in the array \a aPointArray.
  136. * @param aPoints the points to draw.
  137. * @param doFill true if polygon is to be filled, else false and only the boundary is drawn.
  138. * @param aPenWidth is the width of the pen to use on the perimeter, can be zero.
  139. * @param aPenColor the color of the border.
  140. * @param aFillColor the fill color of the polygon's interior.
  141. */
  142. void GRClosedPoly( EDA_RECT* ClipBox,
  143. wxDC* aDC,
  144. int aPointCount,
  145. wxPoint aPoints[],
  146. bool doFill,
  147. int aPenWidth,
  148. COLOR4D aPenColor,
  149. COLOR4D aFillColor );
  150. /**
  151. * Function GRCircle
  152. * draws a circle onto the drawing context \a aDC centered at the user
  153. * coordinates (x,y)
  154. *
  155. * @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
  156. * @param aDC the device context into which drawing should occur.
  157. * @param x The x coordinate in user space of the center of the circle.
  158. * @param y The y coordinate in user space of the center of the circle.
  159. * @param aRadius is the radius of the circle.
  160. * @param aColor is the color to draw
  161. * @see COLOR4D
  162. */
  163. void GRCircle( EDA_RECT* ClipBox, wxDC* aDC, int x, int y, int aRadius, COLOR4D aColor );
  164. void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width, COLOR4D Color );
  165. void GRFilledCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width,
  166. COLOR4D Color, COLOR4D BgColor );
  167. void GRFilledCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, COLOR4D aColor );
  168. void GRCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, int aWidth, COLOR4D aColor );
  169. void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
  170. double EndAngle, int r, COLOR4D Color );
  171. void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
  172. double EndAngle, int r, int width, COLOR4D Color );
  173. void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  174. int xc, int yc, COLOR4D Color );
  175. void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  176. int xc, int yc, int width, COLOR4D Color );
  177. void GRArc1( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
  178. wxPoint aCenter, int aWidth, COLOR4D aColor );
  179. void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y,
  180. double StAngle, double EndAngle, int r, COLOR4D Color, COLOR4D BgColor );
  181. void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
  182. double EndAngle, int r, int width, COLOR4D Color, COLOR4D BgColor );
  183. void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, COLOR4D Color );
  184. void GRFillCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  185. int width, COLOR4D Color );
  186. void GRFilledSegment( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
  187. int aWidth, COLOR4D aColor );
  188. void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  189. int width, int aPenSize, COLOR4D Color );
  190. void GRCSegm( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
  191. int aWidth, COLOR4D aColor );
  192. void GRSetColor( COLOR4D Color );
  193. void GRSetDefaultPalette();
  194. COLOR4D GRGetColor();
  195. void GRPutPixel( EDA_RECT* ClipBox, wxDC* DC, int x, int y, COLOR4D color );
  196. void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  197. int x2, int y2, COLOR4D Color, COLOR4D BgColor );
  198. void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  199. int x2, int y2, int width, COLOR4D Color, COLOR4D BgColor );
  200. void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, COLOR4D Color );
  201. void GRRect( EDA_RECT* ClipBox, wxDC* DC,const EDA_RECT& aRect, int aWidth, COLOR4D Color );
  202. void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  203. int x2, int y2, int width, COLOR4D Color );
  204. void GRRectPs( EDA_RECT* aClipBox, wxDC* aDC,const EDA_RECT& aRect,
  205. int aWidth, COLOR4D aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID );
  206. void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  207. int x2, int y2, int width, COLOR4D Color, COLOR4D BgColor );
  208. /**
  209. * Function GRLineArray
  210. * draws an array of lines (not a polygon).
  211. * @param aClipBox = the clip box
  212. * @param aDC = the device context into which drawing should occur.
  213. * @param aLines = a list of pair of coordinate in user space: a pair for each line.
  214. * @param aWidth = the width of each line.
  215. * @param aColor = the color of the lines
  216. * @see COLOR4D
  217. */
  218. void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC,std::vector<wxPoint>& aLines,
  219. int aWidth, COLOR4D aColor );
  220. void GRDrawAnchor( EDA_RECT* aClipBox, wxDC *aDC, int x, int y, int aSize,
  221. COLOR4D aColor );
  222. /**
  223. * Draw text centered on a wxDC with wrapping.
  224. * @param aDC wxDC instance onto which the text will be drawn
  225. * @param aText the text to draw
  226. */
  227. void GRDrawWrappedText( wxDC& aDC, wxString const& aText );
  228. #endif /* define GR_BASIC */