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.

258 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-2015 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file gr_basic.h
  27. */
  28. #ifndef GR_BASIC
  29. #define GR_BASIC
  30. #include <colors.h>
  31. #include <vector>
  32. class EDA_RECT;
  33. /// Drawmode. Compositing mode plus a flag or two
  34. enum GR_DRAWMODE {
  35. GR_OR = 0x01000000,
  36. GR_XOR = 0x02000000,
  37. GR_AND = 0x04000000,
  38. GR_NXOR = 0x08000000,
  39. GR_INVERT = 0x10000000,
  40. GR_ALLOW_HIGHCONTRAST = 0x20000000,
  41. GR_COPY = 0x40000000,
  42. GR_HIGHLIGHT = 0x80000000,
  43. UNSPECIFIED_DRAWMODE = -1
  44. };
  45. inline void DrawModeAddHighlight(GR_DRAWMODE *mode)
  46. {
  47. *mode = static_cast<GR_DRAWMODE>( int( *mode ) | GR_HIGHLIGHT );
  48. }
  49. inline void DrawModeAllowHighContrast(GR_DRAWMODE *mode)
  50. {
  51. *mode = static_cast<GR_DRAWMODE>( int( *mode ) | GR_ALLOW_HIGHCONTRAST );
  52. }
  53. inline GR_DRAWMODE operator ~(const GR_DRAWMODE& a)
  54. {
  55. return static_cast<GR_DRAWMODE>( ~int( a ) );
  56. }
  57. inline GR_DRAWMODE operator |(const GR_DRAWMODE& a, const GR_DRAWMODE& b)
  58. {
  59. return static_cast<GR_DRAWMODE>( int( a ) | int( b ) );
  60. }
  61. inline GR_DRAWMODE operator &(const GR_DRAWMODE& a, const GR_DRAWMODE& b)
  62. {
  63. return static_cast<GR_DRAWMODE>( int( a ) & int( b ) );
  64. }
  65. #define GR_M_LEFT_DOWN 0x10000000
  66. #define GR_M_RIGHT_DOWN 0x20000000
  67. #define GR_M_MIDDLE_DOWN 0x40000000
  68. #define GR_M_DCLICK 0x80000000
  69. extern GR_DRAWMODE g_XorMode;
  70. typedef enum {
  71. /* Line styles for Get/SetLineStyle. */
  72. GR_SOLID_LINE = 0,
  73. GR_DOTTED_LINE = 1,
  74. GR_DASHED_LINE = 3
  75. } GRLineStypeType;
  76. class EDA_DRAW_PANEL;
  77. void GRSetDrawMode( wxDC* DC, GR_DRAWMODE mode );
  78. GR_DRAWMODE GRGetDrawMode( wxDC* DC );
  79. void GRResetPenAndBrush( wxDC* DC );
  80. void GRSetColorPen( wxDC* DC, EDA_COLOR_T Color, int width = 1, wxPenStyle stype = wxPENSTYLE_SOLID );
  81. void GRSetBrush( wxDC* DC, EDA_COLOR_T Color, bool fill = false );
  82. /**
  83. * Function GRForceBlackPen
  84. * @param flagforce True to force a black pen whenever the asked color
  85. */
  86. void GRForceBlackPen( bool flagforce );
  87. /**
  88. * Function GetGRForceBlackPenState
  89. * @return ForceBlackPen (True if a black pen was forced)
  90. */
  91. bool GetGRForceBlackPenState( void );
  92. void GRLine( EDA_RECT* aClipBox, wxDC* aDC,
  93. wxPoint aStart, wxPoint aEnd, int aWidth, EDA_COLOR_T aColor );
  94. void GRLine( EDA_RECT* ClipBox, wxDC* DC,
  95. int x1, int y1, int x2, int y2, int width, EDA_COLOR_T Color );
  96. void GRMixedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  97. int width, EDA_COLOR_T Color );
  98. void GRDashedLine( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  99. int width, EDA_COLOR_T Color );
  100. void GRMoveTo( int x, int y );
  101. void GRLineTo( EDA_RECT* ClipBox, wxDC* DC,
  102. int x, int y, int width, EDA_COLOR_T Color );
  103. void GRPoly( EDA_RECT* ClipBox, wxDC* DC, int n, wxPoint Points[], bool Fill,
  104. int width, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
  105. void GRBezier( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  106. int x3, int y3, int width, EDA_COLOR_T Color );
  107. void GRBezier( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  108. int x3, int y3, int x4, int y4, int width, EDA_COLOR_T Color );
  109. /**
  110. * Function GRClosedPoly
  111. * draws a closed polygon onto the drawing context \a aDC and optionally fills
  112. * and/or draws a border around it.
  113. * @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
  114. * @param aDC the device context into which drawing should occur.
  115. * @param aPointCount the number of points in the array \a aPoints.
  116. * @param aPoints The points to draw.
  117. * @param doFill true if polygon is to be filled, else false and only the boundary is drawn.
  118. * @param aPenColor the color index of the border.
  119. * @param aFillColor the fill color of the polygon's interior.
  120. */
  121. void GRClosedPoly( EDA_RECT* ClipBox,
  122. wxDC * aDC,
  123. int aPointCount,
  124. wxPoint aPoints[],
  125. bool doFill,
  126. EDA_COLOR_T aPenColor,
  127. EDA_COLOR_T aFillColor );
  128. // @todo could make these 2 closed polygons calls a single function and default
  129. // the aPenWidth argument
  130. /**
  131. * Function GRClosedPoly
  132. * draws a closed polygon onto the drawing context \a aDC and optionally fills
  133. * and/or draws a border around it.
  134. * @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
  135. * @param aDC the device context into which drawing should occur.
  136. * @param aPointCount the number of points in the array \a aPointArray.
  137. * @param aPoints the points to draw.
  138. * @param doFill true if polygon is to be filled, else false and only the boundary is drawn.
  139. * @param aPenWidth is the width of the pen to use on the perimeter, can be zero.
  140. * @param aPenColor the color index of the border.
  141. * @param aFillColor the fill color of the polygon's interior.
  142. */
  143. void GRClosedPoly( EDA_RECT* ClipBox,
  144. wxDC* aDC,
  145. int aPointCount,
  146. wxPoint aPoints[],
  147. bool doFill,
  148. int aPenWidth,
  149. EDA_COLOR_T aPenColor,
  150. EDA_COLOR_T aFillColor );
  151. /**
  152. * Function GRCircle
  153. * draws a circle onto the drawing context \a aDC centered at the user
  154. * coordinates (x,y)
  155. *
  156. * @param ClipBox defines a rectangular boundary outside of which no drawing will occur.
  157. * @param aDC the device context into which drawing should occur.
  158. * @param x The x coordinate in user space of the center of the circle.
  159. * @param y The y coordinate in user space of the center of the circle.
  160. * @param aRadius is the radius of the circle.
  161. * @param aColor is an index into our color table of RGB colors.
  162. * @see EDA_COLOR_T and colors.h
  163. */
  164. void GRCircle( EDA_RECT* ClipBox, wxDC* aDC, int x, int y, int aRadius, EDA_COLOR_T aColor );
  165. void GRCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width, EDA_COLOR_T Color );
  166. void GRFilledCircle( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int r, int width,
  167. EDA_COLOR_T Color, EDA_COLOR_T BgColor );
  168. void GRFilledCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, EDA_COLOR_T aColor );
  169. void GRCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, int aWidth, EDA_COLOR_T aColor );
  170. void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
  171. double EndAngle, int r, EDA_COLOR_T Color );
  172. void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
  173. double EndAngle, int r, int width, EDA_COLOR_T Color );
  174. void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  175. int xc, int yc, EDA_COLOR_T Color );
  176. void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  177. int xc, int yc, int width, EDA_COLOR_T Color );
  178. void GRArc1( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
  179. wxPoint aCenter, int aWidth, EDA_COLOR_T aColor );
  180. void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y,
  181. double StAngle, double EndAngle, int r, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
  182. void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
  183. double EndAngle, int r, int width, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
  184. void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, EDA_COLOR_T Color );
  185. void GRFillCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  186. int width, EDA_COLOR_T Color );
  187. void GRFilledSegment( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
  188. int aWidth, EDA_COLOR_T aColor );
  189. void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
  190. int width, int aPenSize, EDA_COLOR_T Color );
  191. void GRCSegm( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
  192. int aWidth, EDA_COLOR_T aColor );
  193. void GRSetColor( EDA_COLOR_T Color );
  194. void GRSetDefaultPalette();
  195. EDA_COLOR_T GRGetColor();
  196. void GRPutPixel( EDA_RECT* ClipBox, wxDC* DC, int x, int y, EDA_COLOR_T color );
  197. void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  198. int x2, int y2, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
  199. void GRFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  200. int x2, int y2, int width, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
  201. void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, EDA_COLOR_T Color );
  202. void GRRect( EDA_RECT* ClipBox, wxDC* DC,const EDA_RECT& aRect, int aWidth, EDA_COLOR_T Color );
  203. void GRRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  204. int x2, int y2, int width, EDA_COLOR_T Color );
  205. void GRRectPs( EDA_RECT* aClipBox, wxDC* aDC,const EDA_RECT& aRect,
  206. int aWidth, EDA_COLOR_T aColor, wxPenStyle aStyle = wxPENSTYLE_SOLID );
  207. void GRSFilledRect( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1,
  208. int x2, int y2, int width, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
  209. /**
  210. * Function GRLineArray
  211. * draws an array of lines (not a polygon).
  212. * @param aClipBox = the clip box
  213. * @param aDC = the device context into which drawing should occur.
  214. * @param aLines = a list of pair of coordinate in user space: a pair for each line.
  215. * @param aWidth = the width of each line.
  216. * @param aColor = an index into our color table of RGB colors.
  217. * @see EDA_COLOR_T and colors.h
  218. */
  219. void GRLineArray( EDA_RECT* aClipBox, wxDC* aDC,std::vector<wxPoint>& aLines,
  220. int aWidth, EDA_COLOR_T aColor );
  221. void GRDrawAnchor( EDA_RECT* aClipBox, wxDC *aDC, int x, int y, int aSize,
  222. EDA_COLOR_T aColor );
  223. #endif /* define GR_BASIC */