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.

88 lines
3.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 CERN
  5. * @author Maciej Suminski <maciej.suminski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include <origin_viewitem.h>
  25. #include <gal/graphics_abstraction_layer.h>
  26. using namespace KIGFX;
  27. ORIGIN_VIEWITEM::ORIGIN_VIEWITEM( const COLOR4D& aColor, MARKER_STYLE aStyle, int aSize, const VECTOR2D& aPosition ) :
  28. EDA_ITEM( NOT_USED ), // this item is never added to a BOARD so it needs no type
  29. m_position( aPosition ), m_size( aSize ), m_color( aColor ), m_style( aStyle ), m_drawAtZero( false )
  30. {
  31. }
  32. const BOX2I ORIGIN_VIEWITEM::ViewBBox() const
  33. {
  34. BOX2I bbox;
  35. bbox.SetMaximum();
  36. return bbox;
  37. }
  38. void ORIGIN_VIEWITEM::ViewDraw( int, VIEW* aView ) const
  39. {
  40. auto gal = aView->GetGAL();
  41. // Nothing to do if the target shouldn't be drawn at 0,0 and that's where the target is. This
  42. // mimics the Legacy canvas that doesn't display most targets at 0,0
  43. if( !m_drawAtZero && ( m_position.x == 0 ) && ( m_position.y == 0 ) )
  44. return;
  45. gal->SetIsStroke( true );
  46. gal->SetIsFill( false );
  47. gal->SetLineWidth( 1 );
  48. gal->SetStrokeColor( m_color );
  49. VECTOR2D scaledSize = aView->ToWorld( VECTOR2D( m_size, m_size ), false );
  50. // Draw a circle around the marker's centre point if the style demands it
  51. if( ( m_style == CIRCLE_CROSS ) || ( m_style == CIRCLE_DOT ) || ( m_style == CIRCLE_X ) )
  52. gal->DrawCircle( m_position, fabs( scaledSize.x ) );
  53. switch( m_style )
  54. {
  55. case NONE:
  56. break;
  57. case CROSS:
  58. case CIRCLE_CROSS:
  59. gal->DrawLine( m_position - VECTOR2D( scaledSize.x, 0 ),
  60. m_position + VECTOR2D( scaledSize.x, 0 ) );
  61. gal->DrawLine( m_position - VECTOR2D( 0, scaledSize.y ),
  62. m_position + VECTOR2D( 0, scaledSize.y ) );
  63. break;
  64. case X:
  65. case CIRCLE_X:
  66. gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
  67. scaledSize.y = -scaledSize.y;
  68. gal->DrawLine( m_position - scaledSize, m_position + scaledSize );
  69. break;
  70. case DOT:
  71. case CIRCLE_DOT:
  72. gal->DrawCircle( m_position, scaledSize.x / 4 );
  73. break;
  74. }
  75. }