The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

209 lines
6.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCER_COMPONENTEDITORTOOLBAR_H_6B5CA931__
  19. #define __JUCER_COMPONENTEDITORTOOLBAR_H_6B5CA931__
  20. #include "../../utility/jucer_ColourEditorComponent.h"
  21. //==============================================================================
  22. class JucerToolbarButton : public ToolbarItemComponent
  23. {
  24. public:
  25. //==============================================================================
  26. JucerToolbarButton (ComponentEditor& editor_, int itemId_, const String& labelText)
  27. : ToolbarItemComponent (itemId_, labelText, true),
  28. editor (editor_)
  29. {
  30. setClickingTogglesState (false);
  31. }
  32. ~JucerToolbarButton()
  33. {
  34. }
  35. //==============================================================================
  36. bool getToolbarItemSizes (int toolbarDepth, bool isToolbarVertical, int& preferredSize, int& minSize, int& maxSize)
  37. {
  38. preferredSize = minSize = maxSize = 50;
  39. return true;
  40. }
  41. void paintButton (Graphics& g, bool over, bool down)
  42. {
  43. Path p;
  44. p.addRoundedRectangle (1.5f, 2.5f, getWidth() - 3.0f, getHeight() - 5.0f, 3.0f);
  45. if (getToggleState())
  46. {
  47. g.setColour (Colours::grey.withAlpha (0.5f));
  48. g.fillPath (p);
  49. }
  50. g.setColour (Colours::darkgrey.withAlpha (0.3f));
  51. g.strokePath (p, PathStrokeType (1.0f));
  52. g.setFont (11.0f);
  53. g.setColour (Colours::black.withAlpha ((over || down) ? 1.0f : 0.7f));
  54. g.drawFittedText (getButtonText(), 2, 2, getWidth() - 4, getHeight() - 4, Justification::centred, 2);
  55. }
  56. void paintButtonArea (Graphics& g, int width, int height, bool isMouseOver, bool isMouseDown)
  57. {
  58. }
  59. void contentAreaChanged (const Rectangle<int>& newBounds)
  60. {
  61. }
  62. juce_UseDebuggingNewOperator
  63. protected:
  64. ComponentEditor& editor;
  65. private:
  66. JucerToolbarButton (const JucerToolbarButton&);
  67. JucerToolbarButton& operator= (const JucerToolbarButton&);
  68. };
  69. //==============================================================================
  70. class NewComponentToolbarButton : public JucerToolbarButton
  71. {
  72. public:
  73. NewComponentToolbarButton (ComponentEditor& editor_, int itemId_)
  74. : JucerToolbarButton (editor_, itemId_, "create...")
  75. {
  76. setTriggeredOnMouseDown (true);
  77. }
  78. void clicked()
  79. {
  80. editor.showNewComponentMenu (this);
  81. }
  82. };
  83. //==============================================================================
  84. class BackgroundColourToolbarButton : public JucerToolbarButton
  85. {
  86. public:
  87. BackgroundColourToolbarButton (ComponentEditor& editor_, int itemId_)
  88. : JucerToolbarButton (editor_, itemId_, "background")
  89. {
  90. setTriggeredOnMouseDown (true);
  91. }
  92. void clicked()
  93. {
  94. editor.getDocument().getUndoManager()->beginNewTransaction();
  95. PopupColourSelector::showAt (this, editor.getDocument().getBackgroundColour(), Colours::white, true);
  96. }
  97. };
  98. //==============================================================================
  99. class ComponentEditorToolbarFactory : public ToolbarItemFactory
  100. {
  101. public:
  102. ComponentEditorToolbarFactory (ComponentEditor& editor_)
  103. : editor (editor_)
  104. {
  105. }
  106. ~ComponentEditorToolbarFactory()
  107. {
  108. }
  109. //==============================================================================
  110. enum DemoToolbarItemIds
  111. {
  112. createComponent = 1,
  113. changeBackground,
  114. showInfo,
  115. showComponentTree,
  116. showOrHideMarkers,
  117. toggleSnapping
  118. };
  119. void getAllToolbarItemIds (Array <int>& ids)
  120. {
  121. ids.add (createComponent);
  122. ids.add (changeBackground);
  123. ids.add (showInfo);
  124. ids.add (showComponentTree);
  125. ids.add (showOrHideMarkers);
  126. ids.add (toggleSnapping);
  127. ids.add (separatorBarId);
  128. ids.add (spacerId);
  129. ids.add (flexibleSpacerId);
  130. }
  131. void getDefaultItemSet (Array <int>& ids)
  132. {
  133. ids.add (spacerId);
  134. ids.add (createComponent);
  135. ids.add (changeBackground);
  136. ids.add (flexibleSpacerId);
  137. ids.add (showOrHideMarkers);
  138. ids.add (toggleSnapping);
  139. ids.add (flexibleSpacerId);
  140. ids.add (showComponentTree);
  141. ids.add (showInfo);
  142. ids.add (spacerId);
  143. }
  144. ToolbarItemComponent* createItem (int itemId)
  145. {
  146. String name;
  147. int commandId = 0;
  148. switch (itemId)
  149. {
  150. case createComponent: return new NewComponentToolbarButton (editor, itemId);
  151. case changeBackground: return new BackgroundColourToolbarButton (editor, itemId);
  152. case showInfo: name = "info"; commandId = CommandIDs::showOrHideProperties; break;
  153. case showComponentTree: name = "tree"; commandId = CommandIDs::showOrHideTree; break;
  154. case showOrHideMarkers: name = "markers"; commandId = CommandIDs::showOrHideMarkers; break;
  155. case toggleSnapping: name = "snap"; commandId = CommandIDs::toggleSnapping; break;
  156. default: jassertfalse; return 0;
  157. }
  158. JucerToolbarButton* b = new JucerToolbarButton (editor, itemId, name);
  159. b->setCommandToTrigger (commandManager, commandId, true);
  160. return b;
  161. }
  162. private:
  163. ComponentEditor& editor;
  164. ComponentEditorToolbarFactory (const ComponentEditorToolbarFactory&);
  165. ComponentEditorToolbarFactory& operator= (const ComponentEditorToolbarFactory&);
  166. };
  167. #endif // __JUCER_COMPONENTEDITORTOOLBAR_H_6B5CA931__