From eb916d5e1823a575c459e0e4b94db6ef89a0da91 Mon Sep 17 00:00:00 2001 From: jsiegle <jsiegle@mit.edu> Date: Thu, 30 Jan 2014 21:47:28 -0500 Subject: [PATCH] Add scroll bar to ProcessorList. Closes #127 --- Source/UI/ProcessorList.cpp | 14 ++++++++++++-- Source/UI/ProcessorList.h | 10 +++++++--- Source/UI/UIComponent.cpp | 27 +++++++++++++++++++-------- Source/UI/UIComponent.h | 2 ++ 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/Source/UI/ProcessorList.cpp b/Source/UI/ProcessorList.cpp index c60b9f319..8abc6d000 100755 --- a/Source/UI/ProcessorList.cpp +++ b/Source/UI/ProcessorList.cpp @@ -118,6 +118,11 @@ ProcessorList::~ProcessorList() } +void ProcessorList::resized() +{ + setBounds(0,0,195,getTotalHeight()); +} + bool ProcessorList::isOpen() @@ -137,7 +142,7 @@ void ProcessorList::paint(Graphics& g) void ProcessorList::drawItems(Graphics& g) { - totalHeight = yBuffer; + totalHeight = yBuffer + itemHeight; category = baseItem->getName(); @@ -167,6 +172,11 @@ void ProcessorList::drawItems(Graphics& g) } } + if (isOpen()) + setSize(getWidth(),totalHeight); + + //resized(); + } void ProcessorList::drawItem(Graphics& g, ProcessorListItem* item) @@ -451,7 +461,7 @@ void ProcessorList::mouseDown(const MouseEvent& e) else { getUIComponent()->childComponentChanged(); - totalHeight = itemHeight + 2*yBuffer; + // totalHeight = itemHeight + 2*yBuffer; } } diff --git a/Source/UI/ProcessorList.h b/Source/UI/ProcessorList.h index 9873a0eb8..62a5743a7 100755 --- a/Source/UI/ProcessorList.h +++ b/Source/UI/ProcessorList.h @@ -82,6 +82,12 @@ public: /** Loads the ProcessorList state. */ void loadStateFromXml(XmlElement*); + void resized(); + + /** Returns the height requested by the ProcessorList. Determines whether or not + to draw scroll bars.*/ + int getTotalHeight(); + private: /** The main method for drawing the ProcessorList.*/ @@ -104,9 +110,7 @@ private: int currentColor; - /** Returns the height requested by the ProcessorList. Determines whether or not - to draw scroll bars.*/ - int getTotalHeight(); + /** Deselects all items within the ProcessorList.*/ void clearSelectionState(); diff --git a/Source/UI/UIComponent.cpp b/Source/UI/UIComponent.cpp index b511cbc41..09c76b4c9 100755 --- a/Source/UI/UIComponent.cpp +++ b/Source/UI/UIComponent.cpp @@ -59,8 +59,11 @@ UIComponent::UIComponent(MainWindow* mainWindow_, ProcessorGraph* pgraph, AudioC std::cout << "Created control panel." << std::endl; processorList = new ProcessorList(); - addAndMakeVisible(processorList); - + processorListViewport.setViewedComponent(processorList,false); + processorListViewport.setScrollBarsShown(true,false); + addAndMakeVisible(&processorListViewport); + processorList->setVisible(true); + processorList->setBounds(0,0,195,processorList->getTotalHeight()); std::cout << "Created filter list." << std::endl; messageCenter = new MessageCenter(); @@ -171,15 +174,23 @@ void UIComponent::resized() if (processorList != 0) { if (processorList->isOpen()) + { if (editorViewportButton->isOpen()) - processorList->setBounds(5,5,195,h-200); + processorListViewport.setBounds(5,5,195,h-200); else - processorList->setBounds(5,5,195,h-50); - else - processorList->setBounds(5,5,195,34); + processorListViewport.setBounds(5,5,195,h-50); + + processorListViewport.setScrollBarsShown(true,false); + + } + else{ + processorListViewport.setBounds(5,5,195,34); + processorListViewport.setScrollBarsShown(false,false); + processorListViewport.setViewPosition (0, 0); + } if (w < 460) - processorList->setBounds(5-460+getWidth(),5,195,processorList->getHeight()); + processorListViewport.setBounds(5-460+getWidth(),5,195,processorList->getHeight()); } if (dataViewport != 0) @@ -189,7 +200,7 @@ void UIComponent::resized() top = 40; if (processorList->isOpen()) - left = processorList->getX()+processorList->getWidth()+2; + left = processorListViewport.getX()+processorListViewport.getWidth()+2; else left = 6; diff --git a/Source/UI/UIComponent.h b/Source/UI/UIComponent.h index 8b7cd0605..3f59ad13e 100755 --- a/Source/UI/UIComponent.h +++ b/Source/UI/UIComponent.h @@ -174,6 +174,8 @@ private: ScopedPointer<MessageCenter> messageCenter; ScopedPointer<InfoLabel> infoLabel; ScopedPointer<GraphViewer> graphViewer; + + Viewport processorListViewport; /** Pointer to the GUI's MainWindow, which owns the UIComponent. */ MainWindow* mainWindow; -- GitLab