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.

159 lines
4.4 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017-2021 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 ROW_INDICATOR__H_
  24. #define ROW_INDICATOR__H_
  25. #include <wx/statbmp.h>
  26. #include <wx/panel.h>
  27. class wxStaticBitmap;
  28. /**
  29. * representing a row indicator icon for use in
  30. * places like the layer widget
  31. */
  32. class INDICATOR_ICON : public wxPanel
  33. {
  34. public:
  35. /**
  36. * An id that refers to a certain icon state.
  37. *
  38. * Exactly what that state might mean in terms of icons is up
  39. * to the icon provider.
  40. */
  41. using ICON_ID = int;
  42. /**
  43. * A simple object that can provide fixed bitmaps for use as row
  44. * indicators
  45. */
  46. class ICON_PROVIDER
  47. {
  48. public:
  49. virtual ~ICON_PROVIDER() {};
  50. /**
  51. * Get a reference to the row icon in the given mode.
  52. *
  53. * @param aIconId the id of the icon to get (depends on the
  54. * provider).
  55. */
  56. virtual const wxBitmap& GetIndicatorIcon( ICON_ID aIconId ) const = 0;
  57. };
  58. /**
  59. * Accessor for the default icon providers, which take
  60. * true and false for IDs, meaning on/off.
  61. *
  62. * @param aAlternative false for blue arrow/blank, true for the
  63. * green diamond
  64. */
  65. static ICON_PROVIDER& GetDefaultRowIconProvider( bool aAlternative );
  66. /**
  67. * @param aParent the owning window
  68. * @param aIconProvider the icon provider to get icons from
  69. * @param aInitialIcon is the initial state of the icon (the meaning
  70. * depends on what is the purpose of the icon)
  71. * @param aID the ID to use for the widgets - events will have
  72. * this ID.
  73. */
  74. INDICATOR_ICON( wxWindow* aParent, ICON_PROVIDER& aIconProvider,
  75. ICON_ID aInitialIcon, int aID );
  76. /**
  77. * Set the row indicator to the given state.
  78. *
  79. * @param aIconId the icon ID to pass to the provider.
  80. */
  81. void SetIndicatorState( ICON_ID aIconId );
  82. /**
  83. * @return the current state of the indicator
  84. */
  85. ICON_ID GetIndicatorState() const;
  86. /**
  87. * Updates the window ID of this control and its children
  88. * @param aId new Window ID to set
  89. */
  90. void SetWindowID( wxWindowID aId )
  91. {
  92. SetId( aId );
  93. m_bitmap->SetId( aId );
  94. }
  95. private:
  96. ///< An class that delivers icons for the indicator (currently just
  97. ///< uses a default implementation).
  98. ICON_PROVIDER& m_iconProvider;
  99. ///< Handle on the bitmap widget
  100. wxStaticBitmap* m_bitmap;
  101. ///< Is the icon currently "on"
  102. ICON_ID m_currentId;
  103. };
  104. /**
  105. * Icon provider for the "standard" row indicators, for example in layer selection lists
  106. */
  107. class ROW_ICON_PROVIDER: public INDICATOR_ICON::ICON_PROVIDER
  108. {
  109. public:
  110. ///< State constants to select the right icons
  111. enum STATE
  112. {
  113. OFF, ///< Row "off" or "deselected"
  114. DIMMED, ///< Row "dimmed"
  115. ON, ///< Row "on" or "selected"
  116. UP, ///< Row above design alpha
  117. DOWN, ///< Row below design alpha
  118. };
  119. /**
  120. * @param aAlt false: normal icons (blue arrow/blank), true:
  121. * alternative icons (blue arrow/green diamond)
  122. */
  123. ROW_ICON_PROVIDER( int aSize );
  124. ///< @copydoc INDICATOR_ICON::ICON_PROVIDER::GetIndicatorIcon()
  125. const wxBitmap& GetIndicatorIcon( INDICATOR_ICON::ICON_ID aIconId ) const override;
  126. private:
  127. wxBitmap m_blankBitmap;
  128. wxBitmap m_rightArrowBitmap;
  129. wxBitmap m_upArrowBitmap;
  130. wxBitmap m_downArrowBitmap;
  131. wxBitmap m_dotBitmap;
  132. };
  133. #endif // ROW_INDICATOR__H_