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.

113 lines
3.7 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Kicad Developers, see change_log.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef PREVIEW_PREVIEW_DRAW_CONTEXT__H_
  24. #define PREVIEW_PREVIEW_DRAW_CONTEXT__H_
  25. #include <painter.h>
  26. #include <math/vector2d.h>
  27. namespace KIGFX
  28. {
  29. class GAL;
  30. class VIEW;
  31. namespace PREVIEW
  32. {
  33. /**
  34. * A KIGFX::PREVIEW::DRAW_CONTEXT is a wrapper around a GAL and some other
  35. * settings that makes it easy to draw preview items consistently.
  36. *
  37. * This class provides some graphical items that are often used by preview
  38. * items. Complex items can be composed from these.
  39. */
  40. class DRAW_CONTEXT
  41. {
  42. public:
  43. DRAW_CONTEXT( KIGFX::VIEW& aView );
  44. /**
  45. * Draw a preview circle on the current layer
  46. *
  47. * @param aOrigin circle origin
  48. * @param aRad circle radius
  49. * @param aDeEmphasised draw the circle de-emphasised
  50. */
  51. void DrawCircle( const VECTOR2I& aOrigin, double aRad, bool aDeEmphasised );
  52. /**
  53. * Draw a simple line on the current layer.
  54. *
  55. * @param aStart line start point
  56. * @param aEnd line end point
  57. * @param aDeEmphasised draw the line de-emphasised
  58. */
  59. void DrawLine( const VECTOR2I& aStart, const VECTOR2I& aEnd, bool aDeEmphasised );
  60. /**
  61. * Draw a straight line on the current layer, with a special highlight when
  62. * the line angle is a multiple of 45 degrees.
  63. *
  64. * @param aStart line start point
  65. * @param aEnd line end point
  66. * @param aDeEmphasised draw the line de-emphasised
  67. */
  68. void DrawLineWithAngleHighlight(
  69. const VECTOR2I& aStart, const VECTOR2I& aEnd, bool aDeEmphasised );
  70. /**
  71. * Draw an arc on the current layer, with a special highlight when
  72. * the line angle is a multiple of 45 degrees.
  73. *
  74. * @param aOrigin the arc centre
  75. * @param aRad the arc radius
  76. * @param aStartAngle the arc start angle
  77. * @param aEndAngle the arc end angle
  78. */
  79. void DrawArcWithAngleHighlight(
  80. const VECTOR2I& aOrigin, double aRad, double aStartAngle, double aEndAngle );
  81. private:
  82. /**
  83. * @return the colour to use for "special" angles
  84. */
  85. COLOR4D getSpecialAngleColour() const;
  86. ///< The GAL to draw into
  87. KIGFX::GAL& m_gal;
  88. const KIGFX::RENDER_SETTINGS& m_render_settings;
  89. ///< The current layer to draw onto
  90. GAL_LAYER_ID m_currLayer;
  91. /// The line width to use for items
  92. float m_lineWidth;
  93. };
  94. } // namespace PREVIEW
  95. } // namespace KIGFX
  96. #endif // PREVIEW_PREVIEW_DRAW_CONTEXT__H_