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.

137 lines
3.8 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.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_SIMPLE_OUTLINE_ITEM__H_
  24. #define PREVIEW_SIMPLE_OUTLINE_ITEM__H_
  25. #include <eda_item.h>
  26. #include <layer_ids.h>
  27. #include <gal/color4d.h>
  28. namespace KIGFX
  29. {
  30. class VIEW;
  31. class GAL;
  32. namespace PREVIEW
  33. {
  34. /**
  35. * SIMPLE_OVERLAY_ITEM is class that represents a visual area drawn on
  36. * a canvas, used to temporarily demarcate an area or show something
  37. * on an overlay. An example could be the drag select lasso box.
  38. *
  39. * This class is pretty generic in terms of what the area looks like.
  40. * It provides a fill, stroke and width, which is probably sufficient
  41. * for most simple previews, but the inheritor has freedom to override
  42. * this.
  43. *
  44. * If this doesn't suit a particular preview, it may mean you should
  45. * implement your own EDA_ITEM derivative rather than inheriting this.
  46. */
  47. class SIMPLE_OVERLAY_ITEM : public EDA_ITEM
  48. {
  49. public:
  50. SIMPLE_OVERLAY_ITEM();
  51. /**
  52. * Set the overlay layer only. You can override this if
  53. * you have more layers to draw on.
  54. */
  55. std::vector<int> ViewGetLayers() const override;
  56. /**
  57. * Draw the preview - this is done by calling the two functions:
  58. * setupGal() and drawPreviewShape(). If you need more than this,
  59. * or direct access to the VIEW, you probably should make a new
  60. *.
  61. */
  62. void ViewDraw( int aLayer, KIGFX::VIEW* aView ) const override;
  63. #if defined(DEBUG)
  64. void Show( int x, std::ostream& st ) const override
  65. {
  66. }
  67. #endif
  68. /**
  69. * Get class name
  70. * @return string "SIMPLE_OVERLAY_ITEM"
  71. */
  72. virtual wxString GetClass() const override
  73. {
  74. return "SIMPLE_OVERLAY_ITEM";
  75. }
  76. ///< Set the stroke color to set before drawing preview
  77. void SetStrokeColor( const COLOR4D& aNewColor )
  78. {
  79. m_strokeColor = aNewColor;
  80. }
  81. ///< Set the fill color to set before drawing preview
  82. void SetFillColor( const COLOR4D& aNewColor )
  83. {
  84. m_fillColor = aNewColor;
  85. }
  86. ///< Set the line width to set before drawing preview
  87. void SetLineWidth( double aNewWidth )
  88. {
  89. m_lineWidth = aNewWidth;
  90. }
  91. private:
  92. /**
  93. * Set up the GAL canvas - this provides a default implementation,
  94. * that sets fill, stroke and width.
  95. *
  96. * If that's not suitable, you can set more options in
  97. * updatePreviewShape(), but you might find that defining a new
  98. * EDA_ITEM derivative is easier for heavily customized cases.
  99. */
  100. void setupGal( KIGFX::GAL& aGal ) const;
  101. /**
  102. * Draw the preview onto the given GAL. setupGal() will be called before this function.
  103. *
  104. * Subclasses should implement this in terms of their own graphical
  105. * data.
  106. */
  107. virtual void drawPreviewShape( KIGFX::VIEW* aView ) const { };
  108. COLOR4D m_fillColor;
  109. COLOR4D m_strokeColor;
  110. double m_lineWidth;
  111. };
  112. } // PREVIEW
  113. } // KIGFX
  114. #endif // PREVIEW_SIMPLE_OUTLINE_ITEM__H_