Skip to content

Commit f754c62

Browse files
committed
Fixed the bug #65.
Analysis: This bug is there for following reasons. 1.ElectrodeButton for channels is directly added to the ChannelMappingEditor component. 2.When we drag the button we set the visibility of the lastHoverButton which makes it visible and shows on top of other components. 3. Also finding the correct button Logic is not proper as we are not considering the buttons which are scrolled up and invisible. Solution: 1. Create Viewport for holding the ElectrodeButton for channels. 2. Also create a Holder Component to hold all ElectrodeButton. 3. Add the ElectrodeButton to Holder Component and set the size of the Holder Component to fit all buttons. 4. Set setViewPosition for Viewport based on the scroll and drag. More Improvement: 1. We can remove upButton and downButton. 2. Viewport has its own scrolling which can be used for scrolling. Currently its been hidden using code "electrodeButtonViewport->setScrollBarsShown(false,false,true,true);"
1 parent 6d5ec90 commit f754c62

2 files changed

Lines changed: 40 additions & 18 deletions

File tree

Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp

100644100755
Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ ChannelMappingEditor::ChannelMappingEditor(GenericProcessor* parentNode, bool us
6767
downButton->setBounds(320,45,10,8);
6868
addAndMakeVisible(downButton);
6969
downButton->setVisible(false);
70+
71+
addAndMakeVisible(electrodeButtonViewport = new Viewport());
72+
electrodeButtonViewport->setBounds(10,30,330,70);
73+
electrodeButtonViewport->setScrollBarsShown(false,false,true,true);
74+
electrodeButtonHolder = new Component();
75+
electrodeButtonViewport->setViewedComponent(electrodeButtonHolder,false);
76+
7077

7178
loadButton = new LoadButton();
7279
loadButton->addListener(this);
@@ -169,7 +176,7 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded, bool clearPrevi
169176
// if (!getCollapsedState())
170177
// addAndMakeVisible(button);
171178
// else
172-
addChildComponent(button); // determine visibility in refreshButtonLocations()
179+
electrodeButtonHolder->addAndMakeVisible(button); // determine visibility in refreshButtonLocations()
173180

174181
button->addListener(this);
175182
if (reorderActive)
@@ -223,29 +230,28 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded, bool clearPrevi
223230

224231
void ChannelMappingEditor::refreshButtonLocations()
225232
{
233+
electrodeButtonViewport->setVisible(!getCollapsedState());
234+
235+
electrodeButtonViewport->setViewPosition( 0,scrollDistance);
226236
int width = 19;
227237
int height = 15;
228-
int row = (int) -scrollDistance;
238+
int row = 0;
229239
int column = 0;
230-
240+
int totalWidth = 0;
241+
int totalHeight = 0;
231242
for (int i = 0; i < electrodeButtons.size(); i++)
232243
{
233-
234244
ElectrodeButton* button = electrodeButtons[i];
235-
236-
button->setBounds(10+(column++)*(width), 30+row*(height), width, 15);
237-
238-
if (row <= 4 && row >= 0 && !getCollapsedState())
239-
button->setVisible(true);
240-
else
241-
button->setVisible(false);
242-
245+
button->setBounds(column*width, row*height, width, height);
246+
totalWidth = jmax(totalWidth, ++column*width);
247+
243248
if (column % 16 == 0)
244249
{
245-
column = 0;
246-
row++;
250+
totalHeight = jmax(totalHeight, ++row*height);
251+
column = 0;
247252
}
248253
}
254+
electrodeButtonHolder->setSize(totalWidth,totalHeight);
249255
}
250256

251257
void ChannelMappingEditor::collapsedStateChanged()
@@ -767,12 +773,26 @@ void ChannelMappingEditor::mouseDrag(const MouseEvent& e)
767773
else if (isDragging)
768774
{
769775
MouseEvent ev = e.getEventRelativeTo(this);
770-
771-
int col = ((ev.x-5) / 20);
776+
int mouseDownY = ev.getMouseDownY()-30;
777+
int mouseDownX = ev.getMouseDownX()-10;
778+
Point<int> viewPosition =electrodeButtonViewport->getViewPosition();
779+
780+
int distanceY = ev.getDistanceFromDragStartY();
781+
int distanceX = ev.getDistanceFromDragStartX();
782+
783+
int newPosY = viewPosition.getY()+ mouseDownY + distanceY;
784+
int newPosX = viewPosition.getX()+ mouseDownX + distanceX;
785+
if ( mouseDownY + distanceY > 70){
786+
electrodeButtonViewport->setViewPosition(viewPosition.getX(),newPosY);
787+
}else if( mouseDownY + distanceY < 0 ){
788+
electrodeButtonViewport->setViewPosition(viewPosition.getX(),newPosY);
789+
}
790+
791+
792+
int col = (newPosX / 19);
772793
if (col < 0) col = 0;
773794
else if (col > 16) col = 16;
774-
775-
int row = ((ev.y-30) / 15);
795+
int row = (newPosY / 15);
776796
if (row < 0) row = 0;
777797

778798
int hoverButton = row*16+col;

Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h

100644100755
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ class ChannelMappingEditor : public GenericEditor,
9090
ScopedPointer<TriangleButton> downButton;
9191
ScopedPointer<LoadButton> loadButton;
9292
ScopedPointer<SaveButton> saveButton;
93+
ScopedPointer<Viewport> electrodeButtonViewport;
94+
ScopedPointer<Component> electrodeButtonHolder;
9395

9496
Array<int> channelArray;
9597
Array<int> referenceArray;

0 commit comments

Comments
 (0)