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.

92 lines
3.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2022 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 CALLBACK_GAL_H
  24. #define CALLBACK_GAL_H
  25. #include <gal/gal.h>
  26. #include <gal/graphics_abstraction_layer.h>
  27. class GAL_API CALLBACK_GAL : public KIGFX::GAL
  28. {
  29. public:
  30. CALLBACK_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions,
  31. std::function<void( const VECTOR2I& aPt1,
  32. const VECTOR2I& aPt2 )> aStrokeCallback,
  33. std::function<void( const VECTOR2I& aPt1,
  34. const VECTOR2I& aPt2,
  35. const VECTOR2I& aPt3 )> aTriangleCallback ) :
  36. GAL( aDisplayOptions )
  37. {
  38. m_strokeCallback = std::move( aStrokeCallback );
  39. m_triangleCallback = std::move( aTriangleCallback );
  40. m_outlineCallback = []( const SHAPE_LINE_CHAIN& ) {};
  41. m_stroke = true;
  42. m_triangulate = true;
  43. }
  44. CALLBACK_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions,
  45. std::function<void( const VECTOR2I& aPt1,
  46. const VECTOR2I& aPt2 )> aStrokeCallback,
  47. std::function<void( const SHAPE_LINE_CHAIN& aPoly )> aOutlineCallback ) :
  48. GAL( aDisplayOptions )
  49. {
  50. m_strokeCallback = std::move( aStrokeCallback );
  51. m_triangleCallback = []( const VECTOR2I&, const VECTOR2I&, const VECTOR2I& ) {};
  52. m_outlineCallback = std::move( aOutlineCallback );
  53. m_stroke = true;
  54. m_triangulate = false;
  55. }
  56. CALLBACK_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions,
  57. std::function<void( const SHAPE_LINE_CHAIN& aPoly )> aOutlineCallback ) :
  58. GAL( aDisplayOptions )
  59. {
  60. m_strokeCallback = []( const VECTOR2I& aPt1, const VECTOR2I& aPt2 ) {};
  61. m_triangleCallback = []( const VECTOR2I&, const VECTOR2I&, const VECTOR2I& ) {};
  62. m_outlineCallback = std::move( aOutlineCallback );
  63. m_stroke = false;
  64. m_triangulate = false;
  65. }
  66. /**
  67. * Draw a polygon representing an outline font glyph.
  68. */
  69. void DrawGlyph( const KIFONT::GLYPH& aGlyph, int aNth, int aTotal ) override;
  70. private:
  71. std::function<void( const VECTOR2I& aPt1,
  72. const VECTOR2I& aPt2 )> m_strokeCallback;
  73. std::function<void( const VECTOR2I& aPt1,
  74. const VECTOR2I& aPt2,
  75. const VECTOR2I& aPt3 )> m_triangleCallback;
  76. std::function<void( const SHAPE_LINE_CHAIN& aPoly )> m_outlineCallback;
  77. bool m_stroke;
  78. bool m_triangulate;
  79. };
  80. #endif // define CALLBACK_GAL_H