diff --git a/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp b/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp old mode 100644 new mode 100755 index 293edda18e9f4f75d1ff7089407d3ccc038ab9a6..ddcbcce467609ca069d63d04e00eef41c1a09f4e --- a/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp +++ b/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp @@ -32,8 +32,6 @@ ChannelMappingEditor::ChannelMappingEditor(GenericProcessor* parentNode, bool us { desiredWidth = 350; - - scrollDistance = 0; selectAllButton = new ElectrodeEditorButton("Select All",Font("Small Text",14,Font::plain)); selectAllButton->addListener(this); @@ -56,17 +54,13 @@ ChannelMappingEditor::ChannelMappingEditor(GenericProcessor* parentNode, bool us resetButton->setClickingTogglesState(false); resetButton->setEnabled(false); - upButton = new TriangleButton(1); - upButton->addListener(this); - upButton->setBounds(320,30,10,8); - addAndMakeVisible(upButton); - upButton->setVisible(false); - - downButton = new TriangleButton(2); - downButton->addListener(this); - downButton->setBounds(320,45,10,8); - addAndMakeVisible(downButton); - downButton->setVisible(false); + + addAndMakeVisible(electrodeButtonViewport = new Viewport()); + electrodeButtonViewport->setBounds(10,30,330,70); + electrodeButtonViewport->setScrollBarsShown(true,false,true,true); + electrodeButtonHolder = new Component(); + electrodeButtonViewport->setViewedComponent(electrodeButtonHolder,false); + loadButton = new LoadButton(); loadButton->addListener(this); @@ -176,7 +170,7 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded, bool clearPrevi // if (!getCollapsedState()) // addAndMakeVisible(button); // else - addChildComponent(button); // determine visibility in refreshButtonLocations() + electrodeButtonHolder->addAndMakeVisible(button); // determine visibility in refreshButtonLocations() button->addListener(this); if (reorderActive) @@ -217,42 +211,30 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded, bool clearPrevi channelSelector->setRadioStatus(true); refreshButtonLocations(); - - if (numNeeded > 100) - { - upButton->setVisible(true); - downButton->setVisible(true); - } else { - upButton->setVisible(false); - downButton->setVisible(false); - } } void ChannelMappingEditor::refreshButtonLocations() { + electrodeButtonViewport->setVisible(!getCollapsedState()); int width = 19; int height = 15; - int row = (int) -scrollDistance; + int row = 0; int column = 0; - + int totalWidth = 0; + int totalHeight = 0; for (int i = 0; i < electrodeButtons.size(); i++) { - ElectrodeButton* button = electrodeButtons[i]; - - button->setBounds(10+(column++)*(width), 30+row*(height), width, 15); - - if (row <= 4 && row >= 0 && !getCollapsedState()) - button->setVisible(true); - else - button->setVisible(false); - + button->setBounds(column*width, row*height, width, height); + totalWidth = jmax(totalWidth, ++column*width); + if (column % 16 == 0) { - column = 0; - row++; + totalHeight = jmax(totalHeight, ++row*height); + column = 0; } } + electrodeButtonHolder->setSize(totalWidth,totalHeight); } void ChannelMappingEditor::collapsedStateChanged() @@ -531,28 +513,6 @@ void ChannelMappingEditor::buttonEvent(Button* button) } - } else if (button == upButton) - { - - scrollDistance -= 1; - - if (scrollDistance < 0) - scrollDistance = 0; - - refreshButtonLocations(); - - } else if (button == downButton) - { - - float maxScrollDistance = ceil(float(electrodeButtons.size() - 80) / 16.0f); - - scrollDistance += 1; - - if (scrollDistance > maxScrollDistance) - scrollDistance = maxScrollDistance; - - refreshButtonLocations(); - } else if (button == saveButton) { //std::cout << "Save button clicked." << std::endl; @@ -774,12 +734,26 @@ void ChannelMappingEditor::mouseDrag(const MouseEvent& e) else if (isDragging) { MouseEvent ev = e.getEventRelativeTo(this); - - int col = ((ev.x-5) / 20); + int mouseDownY = ev.getMouseDownY()-30; + int mouseDownX = ev.getMouseDownX()-10; + Point<int> viewPosition =electrodeButtonViewport->getViewPosition(); + + int distanceY = ev.getDistanceFromDragStartY(); + int distanceX = ev.getDistanceFromDragStartX(); + + int newPosY = viewPosition.getY()+ mouseDownY + distanceY; + int newPosX = viewPosition.getX()+ mouseDownX + distanceX; + if ( mouseDownY + distanceY > 70){ + electrodeButtonViewport->setViewPosition(viewPosition.getX(),newPosY); + }else if( mouseDownY + distanceY < 0 ){ + electrodeButtonViewport->setViewPosition(viewPosition.getX(),newPosY); + } + + + int col = (newPosX / 19); if (col < 0) col = 0; else if (col > 16) col = 16; - - int row = ((ev.y-30) / 15); + int row = (newPosY / 15); if (row < 0) row = 0; int hoverButton = row*16+col; @@ -899,25 +873,6 @@ void ChannelMappingEditor::mouseDoubleClick(const MouseEvent& e) } } -void ChannelMappingEditor::mouseWheelMove(const MouseEvent& event, - const MouseWheelDetails& wheel) -{ - - float maxScrollDistance = ceil(float(electrodeButtons.size() - 80) / 16.0f); - - // std::cout << "Got wheel move: " << wheel.deltaY << std::endl; - // channelSelector->shiftChannelsVertical(-wheel.deltaY); - scrollDistance -= wheel.deltaY*2; - - if (scrollDistance > maxScrollDistance) - scrollDistance = maxScrollDistance; - - if (scrollDistance < 0) - scrollDistance = 0; - - refreshButtonLocations(); -} - void ChannelMappingEditor::checkUnusedChannels() { for (int i = 0; i < electrodeButtons.size(); i++) diff --git a/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h b/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h old mode 100644 new mode 100755 index 4d36e967ef3c2bd4dd135de93a6806a1367c59cf..291f07f8d7f057d0e4cd6c333c88a1ef4723e9d5 --- a/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h +++ b/Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h @@ -63,8 +63,6 @@ public: void mouseDoubleClick(const MouseEvent& e); - void mouseWheelMove(const MouseEvent& event, const MouseWheelDetails& wheel); - void collapsedStateChanged(); void startAcquisition(); @@ -88,10 +86,10 @@ private: ScopedPointer<ElectrodeEditorButton> selectAllButton; ScopedPointer<ElectrodeEditorButton> modifyButton; ScopedPointer<ElectrodeEditorButton> resetButton; - ScopedPointer<TriangleButton> upButton; - ScopedPointer<TriangleButton> downButton; ScopedPointer<LoadButton> loadButton; ScopedPointer<SaveButton> saveButton; + ScopedPointer<Viewport> electrodeButtonViewport; + ScopedPointer<Component> electrodeButtonHolder; Array<int> channelArray; Array<int> referenceArray; @@ -114,9 +112,6 @@ private: ScopedPointer<DynamicObject> info; - float scrollDistance; - - JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ChannelMappingEditor); };