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.

112 lines
3.6 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. namespace KIGFX
  27. {
  28. class GAL;
  29. class VIEW;
  30. namespace PREVIEW
  31. {
  32. /**
  33. * A KIGFX::PREVIEW::DRAW_CONTEXT is a wrapper around a GAL and some other
  34. * settings that makes it easy to draw preview items consistently.
  35. *
  36. * This class provides some graphical items that are often used by preview
  37. * items. Complex items can be composed from these.
  38. */
  39. class DRAW_CONTEXT
  40. {
  41. public:
  42. DRAW_CONTEXT( KIGFX::VIEW& aView );
  43. /**
  44. * Draw a preview circle on the current layer
  45. *
  46. * @param aOrigin circle origin
  47. * @param aRad circle radius
  48. * @param aDeEmphasised draw the circle de-emphasised
  49. */
  50. void DrawCircle( const VECTOR2I& aOrigin, double aRad, bool aDeEmphasised );
  51. /**
  52. * Draw a simple line on the current layer.
  53. *
  54. * @param aStart line start point
  55. * @param aEnd line end point
  56. * @param aDeEmphasised draw the line de-emphasised
  57. */
  58. void DrawLine( const VECTOR2I& aStart, const VECTOR2I& aEnd, bool aDeEmphasised );
  59. /**
  60. * Draw a straight line on the current layer, with a special highlight when
  61. * the line angle is a multiple of 45 degrees.
  62. *
  63. * @param aStart line start point
  64. * @param aEnd line end point
  65. * @param aDeEmphasised draw the line de-emphasised
  66. */
  67. void DrawLineWithAngleHighlight(
  68. const VECTOR2I& aStart, const VECTOR2I& aEnd, bool aDeEmphasised );
  69. /**
  70. * Draw an arc on the current layer, with a special highlight when
  71. * the line angle is a multiple of 45 degrees.
  72. *
  73. * @param aOrigin the arc centre
  74. * @param aRad the arc radius
  75. * @param aStartAngle the arc start angle
  76. * @param aEndAngle the arc end angle
  77. */
  78. void DrawArcWithAngleHighlight(
  79. const VECTOR2I& aOrigin, double aRad, double aStartAngle, double aEndAngle );
  80. private:
  81. /**
  82. * @return the colour to use for "special" angles
  83. */
  84. COLOR4D getSpecialAngleColour() const;
  85. ///< The GAL to draw into
  86. KIGFX::GAL& m_gal;
  87. const KIGFX::RENDER_SETTINGS& m_render_settings;
  88. ///< The current layer to draw onto
  89. GAL_LAYER_ID m_currLayer;
  90. /// The line width to use for items
  91. float m_lineWidth;
  92. };
  93. } // namespace PREVIEW
  94. } // namespace KIGFX
  95. #endif // PREVIEW_PREVIEW_DRAW_CONTEXT__H_