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.

105 lines
3.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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. #include "jucer_JucerTreeViewBase.h"
  19. //==============================================================================
  20. JucerTreeViewBase::JucerTreeViewBase()
  21. {
  22. setLinesDrawnForSubItems (false);
  23. }
  24. JucerTreeViewBase::~JucerTreeViewBase()
  25. {
  26. }
  27. const Font JucerTreeViewBase::getFont() const
  28. {
  29. return Font (getItemHeight() * 0.6f);
  30. }
  31. int JucerTreeViewBase::getTextX() const
  32. {
  33. return getItemHeight() + 6;
  34. }
  35. void JucerTreeViewBase::paintItem (Graphics& g, int width, int height)
  36. {
  37. if (isSelected())
  38. g.fillAll (Colour (0x401111ee));
  39. const int x = getTextX();
  40. g.setColour (isMissing() ? Colours::red : Colours::black);
  41. Image* icon = getIcon();
  42. if (icon != 0)
  43. {
  44. g.drawImageWithin (icon, 2, 2, x - 4, height - 4,
  45. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  46. false);
  47. ImageCache::release (icon);
  48. }
  49. g.setFont (getFont());
  50. g.drawFittedText (getDisplayName(), x, 0, width - x, height, Justification::centredLeft, 1, 0.8f);
  51. }
  52. void JucerTreeViewBase::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  53. {
  54. Path p;
  55. if (isOpen())
  56. p.addTriangle (width * 0.2f, height * 0.25f, width * 0.8f, height * 0.25f, width * 0.5f, height * 0.75f);
  57. else
  58. p.addTriangle (width * 0.25f, height * 0.25f, width * 0.8f, height * 0.5f, width * 0.25f, height * 0.75f);
  59. g.setColour (Colours::lightgrey);
  60. g.fillPath (p);
  61. }
  62. //==============================================================================
  63. void JucerTreeViewBase::showRenameBox()
  64. {
  65. TextEditor ed (String::empty);
  66. ed.setMultiLine (false, false);
  67. ed.setPopupMenuEnabled (false);
  68. ed.setSelectAllWhenFocused (true);
  69. ed.setFont (getFont());
  70. ed.addListener (this);
  71. ed.setText (getRenamingName());
  72. Rectangle<int> r (getItemPosition (true));
  73. r.setLeft (r.getX() + getTextX());
  74. r.setHeight (getItemHeight());
  75. ed.setBounds (r);
  76. getOwnerView()->addAndMakeVisible (&ed);
  77. if (ed.runModalLoop() != 0)
  78. setName (ed.getText());
  79. }