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.

148 lines
4.0 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2014 KiCad Developers, see CHANGELOG.TXT for contributors.
  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 <common.h>
  25. #include <colors_selection.h>
  26. #include <layers_id_colors_and_visibility.h>
  27. #include <bitmaps.h>
  28. #include <wx/wx.h>
  29. #include <wx/ownerdrw.h>
  30. #include <wx/menuitem.h>
  31. #include <class_layer_box_selector.h>
  32. LAYER_SELECTOR::LAYER_SELECTOR()
  33. {
  34. m_layerhotkeys = true;
  35. m_hotkeys = NULL;
  36. }
  37. bool LAYER_SELECTOR::SetLayersHotkeys( bool value )
  38. {
  39. m_layerhotkeys = value;
  40. return m_layerhotkeys;
  41. }
  42. void LAYER_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer )
  43. {
  44. wxMemoryDC bmpDC;
  45. wxBrush brush;
  46. // Prepare Bitmap
  47. bmpDC.SelectObject( aLayerbmp );
  48. brush.SetColour( GetLayerColor( aLayer ).ToColour() );
  49. brush.SetStyle( wxBRUSHSTYLE_SOLID );
  50. bmpDC.SetBrush( brush );
  51. bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
  52. bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
  53. bmpDC.SetPen( *wxBLACK_PEN );
  54. bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
  55. }
  56. /* class to display a layer list in a wxBitmapComboBox.
  57. */
  58. LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
  59. const wxPoint& pos, const wxSize& size,
  60. int n, const wxString choices[] ) :
  61. wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ),
  62. LAYER_SELECTOR()
  63. {
  64. m_hotkeys = NULL;
  65. if( choices != NULL )
  66. ResyncBitmapOnly();
  67. }
  68. LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
  69. const wxPoint& pos, const wxSize& size,
  70. const wxArrayString& choices ) :
  71. wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ),
  72. LAYER_SELECTOR()
  73. {
  74. m_hotkeys = NULL;
  75. if( !choices.IsEmpty() )
  76. ResyncBitmapOnly();
  77. }
  78. // Get Current Item #
  79. int LAYER_BOX_SELECTOR::GetChoice()
  80. {
  81. return GetSelection();
  82. }
  83. // Get Current Layer
  84. LAYER_NUM LAYER_BOX_SELECTOR::GetLayerSelection() const
  85. {
  86. if( GetSelection() < 0 )
  87. return UNDEFINED_LAYER;
  88. return (LAYER_NUM)(intptr_t) GetClientData( GetSelection() );
  89. }
  90. // Set Layer #
  91. int LAYER_BOX_SELECTOR::SetLayerSelection( LAYER_NUM layer )
  92. {
  93. int elements = GetCount();
  94. for( int i = 0; i < elements; i++ )
  95. {
  96. if( GetClientData( i ) == (void*)(intptr_t) layer )
  97. {
  98. if( GetSelection() != i ) // Element (i) is not selected
  99. {
  100. SetSelection( i );
  101. return i;
  102. }
  103. else
  104. return i; //If element already selected; do nothing
  105. }
  106. }
  107. // Not Found
  108. SetSelection( -1 );
  109. return -1;
  110. }
  111. void LAYER_BOX_SELECTOR::ResyncBitmapOnly()
  112. {
  113. int elements = GetCount();
  114. for( LAYER_NUM i = 0; i < elements; ++i )
  115. {
  116. wxBitmap layerbmp( 14, 14 );
  117. SetBitmapLayer( layerbmp, i );
  118. }
  119. }