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.

123 lines
3.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2013 CERN
  5. * @author Tomasz Wlostowski <tomasz.wlostowski@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 <preview_items/selection_area.h>
  25. #include <gal/graphics_abstraction_layer.h>
  26. #include <painter.h>
  27. #include <view/view.h>
  28. using namespace KIGFX::PREVIEW;
  29. struct SELECTION_COLORS
  30. {
  31. COLOR4D normal;
  32. COLOR4D additive;
  33. COLOR4D subtract;
  34. COLOR4D exclusiveOr;
  35. COLOR4D outline_l2r;
  36. COLOR4D outline_r2l;
  37. };
  38. static const SELECTION_COLORS selectionColorScheme[2] = {
  39. { // dark background
  40. COLOR4D( 0.3, 0.3, 0.7, 0.3 ), // Slight blue
  41. COLOR4D( 0.3, 0.7, 0.3, 0.3 ), // Slight green
  42. COLOR4D( 0.7, 0.3, 0.3, 0.3 ), // Slight red
  43. COLOR4D( 0.7, 0.3, 0.3, 0.3 ), // Slight red
  44. COLOR4D( 1.0, 1.0, 0.4, 1.0 ), // yellow
  45. COLOR4D( 0.4, 0.4, 1.0, 1.0 ) // blue
  46. },
  47. { // bright background
  48. COLOR4D( 0.5, 0.3, 1.0, 0.5 ), // Slight blue
  49. COLOR4D( 0.5, 1.0, 0.5, 0.5 ), // Slight green
  50. COLOR4D( 1.0, 0.5, 0.5, 0.5 ), // Slight red
  51. COLOR4D( 1.0, 0.5, 0.5, 0.5 ), // Slight red
  52. COLOR4D( 0.7, 0.7, 0.0, 1.0 ), // yellow
  53. COLOR4D( 0.1, 0.1, 1.0, 1.0 ) // blue
  54. }
  55. };
  56. SELECTION_AREA::SELECTION_AREA() :
  57. m_additive( false ),
  58. m_subtractive( false ),
  59. m_exclusiveOr( false )
  60. {
  61. }
  62. const BOX2I SELECTION_AREA::ViewBBox() const
  63. {
  64. BOX2I tmp;
  65. tmp.SetOrigin( m_origin );
  66. tmp.SetEnd( m_end );
  67. tmp.Normalize();
  68. return tmp;
  69. }
  70. void SELECTION_AREA::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
  71. {
  72. KIGFX::GAL& gal = *aView->GetGAL();
  73. RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
  74. const SELECTION_COLORS& scheme = settings->IsBackgroundDark() ? selectionColorScheme[0]
  75. : selectionColorScheme[1];
  76. // Set the fill of the selection rectangle
  77. // based on the selection mode
  78. if( m_additive )
  79. gal.SetFillColor( scheme.additive );
  80. else if( m_subtractive )
  81. gal.SetFillColor( scheme.subtract );
  82. else if( m_exclusiveOr )
  83. gal.SetFillColor( scheme.exclusiveOr );
  84. else
  85. gal.SetFillColor( scheme.normal );
  86. gal.SetIsStroke( true );
  87. gal.SetIsFill( true );
  88. // force 1-pixel-wide line
  89. gal.SetLineWidth( 0.0 );
  90. // Set the stroke color to indicate window or crossing selection
  91. bool windowSelection = ( m_origin.x <= m_end.x ) ? true : false;
  92. if( aView->IsMirroredX() )
  93. windowSelection = !windowSelection;
  94. gal.SetStrokeColor( windowSelection ? scheme.outline_l2r : scheme.outline_r2l );
  95. gal.SetIsFill( false );
  96. gal.DrawRectangle( m_origin, m_end );
  97. gal.SetIsFill( true );
  98. // draw the fill as the second object so that Z test will not clamp
  99. // the single-pixel-wide rectangle sides
  100. gal.DrawRectangle( m_origin, m_end );
  101. }