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.

126 lines
2.9 KiB

  1. #include <common.h>
  2. #include <colors_selection.h>
  3. #include <layers_id_colors_and_visibility.h>
  4. #include <bitmaps.h>
  5. #include <colors.h>
  6. #include <wx/wx.h>
  7. #include <wx/ownerdrw.h>
  8. #include <wx/menuitem.h>
  9. #include <class_layer_box_selector.h>
  10. LAYER_SELECTOR::LAYER_SELECTOR()
  11. {
  12. m_layerhotkeys = true;
  13. m_hotkeys = NULL;
  14. }
  15. bool LAYER_SELECTOR::SetLayersHotkeys( bool value )
  16. {
  17. m_layerhotkeys = value;
  18. return m_layerhotkeys;
  19. }
  20. void LAYER_SELECTOR::SetBitmapLayer( wxBitmap& aLayerbmp, LAYER_NUM aLayer )
  21. {
  22. wxMemoryDC bmpDC;
  23. wxBrush brush;
  24. // Prepare Bitmap
  25. bmpDC.SelectObject( aLayerbmp );
  26. brush.SetColour( MakeColour( GetLayerColor( aLayer ) ) );
  27. #if wxCHECK_VERSION( 3, 0, 0 )
  28. brush.SetStyle( wxBRUSHSTYLE_SOLID );
  29. #else
  30. brush.SetStyle( wxSOLID );
  31. #endif
  32. bmpDC.SetBrush( brush );
  33. bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
  34. bmpDC.SetBrush( *wxTRANSPARENT_BRUSH );
  35. bmpDC.SetPen( *wxBLACK_PEN );
  36. bmpDC.DrawRectangle( 0, 0, aLayerbmp.GetWidth(), aLayerbmp.GetHeight() );
  37. }
  38. /* class to display a layer list in a wxBitmapComboBox.
  39. */
  40. LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
  41. const wxPoint& pos, const wxSize& size,
  42. int n, const wxString choices[] ) :
  43. wxBitmapComboBox( parent, id, wxEmptyString, pos, size, n, choices, wxCB_READONLY ),
  44. LAYER_SELECTOR()
  45. {
  46. if( choices != NULL )
  47. ResyncBitmapOnly();
  48. }
  49. LAYER_BOX_SELECTOR::LAYER_BOX_SELECTOR( wxWindow* parent, wxWindowID id,
  50. const wxPoint& pos, const wxSize& size,
  51. const wxArrayString& choices ) :
  52. wxBitmapComboBox( parent, id, wxEmptyString, pos, size, choices, wxCB_READONLY ),
  53. LAYER_SELECTOR()
  54. {
  55. if( !choices.IsEmpty() )
  56. ResyncBitmapOnly();
  57. }
  58. // Get Current Item #
  59. int LAYER_BOX_SELECTOR::GetChoice()
  60. {
  61. return GetSelection();
  62. }
  63. // Get Current Layer
  64. LAYER_NUM LAYER_BOX_SELECTOR::GetLayerSelection() const
  65. {
  66. if( GetSelection() < 0 )
  67. return UNDEFINED_LAYER;
  68. return (LAYER_NUM)(intptr_t) GetClientData( GetSelection() );
  69. }
  70. // Set Layer #
  71. int LAYER_BOX_SELECTOR::SetLayerSelection( LAYER_NUM layer )
  72. {
  73. int elements = GetCount();
  74. for( int i = 0; i < elements; i++ )
  75. {
  76. if( GetClientData( i ) == (void*)(intptr_t) layer )
  77. {
  78. if( GetSelection() != i ) // Element (i) is not selected
  79. {
  80. SetSelection( i );
  81. return i;
  82. }
  83. else
  84. return i; //If element already selected; do nothing
  85. }
  86. }
  87. // Not Found
  88. SetSelection( -1 );
  89. return -1;
  90. }
  91. void LAYER_BOX_SELECTOR::ResyncBitmapOnly()
  92. {
  93. int elements = GetCount();
  94. for( LAYER_NUM i = 0; i < elements; ++i )
  95. {
  96. wxBitmap layerbmp( 14, 14 );
  97. SetBitmapLayer( layerbmp, i );
  98. }
  99. }