Skip to content

Commit 7b24b7a

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);"
2 parents 19706f4 + f754c62 commit 7b24b7a

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);
@@ -176,7 +183,7 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded, bool clearPrevi
176183
// if (!getCollapsedState())
177184
// addAndMakeVisible(button);
178185
// else
179-
addChildComponent(button); // determine visibility in refreshButtonLocations()
186+
electrodeButtonHolder->addAndMakeVisible(button); // determine visibility in refreshButtonLocations()
180187

181188
button->addListener(this);
182189
if (reorderActive)
@@ -230,29 +237,28 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded, bool clearPrevi
230237

231238
void ChannelMappingEditor::refreshButtonLocations()
232239
{
240+
electrodeButtonViewport->setVisible(!getCollapsedState());
241+
242+
electrodeButtonViewport->setViewPosition( 0,scrollDistance);
233243
int width = 19;
234244
int height = 15;
235-
int row = (int) -scrollDistance;
245+
int row = 0;
236246
int column = 0;
237-
247+
int totalWidth = 0;
248+
int totalHeight = 0;
238249
for (int i = 0; i < electrodeButtons.size(); i++)
239250
{
240-
241251
ElectrodeButton* button = electrodeButtons[i];
242-
243-
button->setBounds(10+(column++)*(width), 30+row*(height), width, 15);
244-
245-
if (row <= 4 && row >= 0 && !getCollapsedState())
246-
button->setVisible(true);
247-
else
248-
button->setVisible(false);
249-
252+
button->setBounds(column*width, row*height, width, height);
253+
totalWidth = jmax(totalWidth, ++column*width);
254+
250255
if (column % 16 == 0)
251256
{
252-
column = 0;
253-
row++;
257+
totalHeight = jmax(totalHeight, ++row*height);
258+
column = 0;
254259
}
255260
}
261+
electrodeButtonHolder->setSize(totalWidth,totalHeight);
256262
}
257263

258264
void ChannelMappingEditor::collapsedStateChanged()
@@ -774,12 +780,26 @@ void ChannelMappingEditor::mouseDrag(const MouseEvent& e)
774780
else if (isDragging)
775781
{
776782
MouseEvent ev = e.getEventRelativeTo(this);
777-
778-
int col = ((ev.x-5) / 20);
783+
int mouseDownY = ev.getMouseDownY()-30;
784+
int mouseDownX = ev.getMouseDownX()-10;
785+
Point<int> viewPosition =electrodeButtonViewport->getViewPosition();
786+
787+
int distanceY = ev.getDistanceFromDragStartY();
788+
int distanceX = ev.getDistanceFromDragStartX();
789+
790+
int newPosY = viewPosition.getY()+ mouseDownY + distanceY;
791+
int newPosX = viewPosition.getX()+ mouseDownX + distanceX;
792+
if ( mouseDownY + distanceY > 70){
793+
electrodeButtonViewport->setViewPosition(viewPosition.getX(),newPosY);
794+
}else if( mouseDownY + distanceY < 0 ){
795+
electrodeButtonViewport->setViewPosition(viewPosition.getX(),newPosY);
796+
}
797+
798+
799+
int col = (newPosX / 19);
779800
if (col < 0) col = 0;
780801
else if (col > 16) col = 16;
781-
782-
int row = ((ev.y-30) / 15);
802+
int row = (newPosY / 15);
783803
if (row < 0) row = 0;
784804

785805
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
@@ -92,6 +92,8 @@ class ChannelMappingEditor : public GenericEditor,
9292
ScopedPointer<TriangleButton> downButton;
9393
ScopedPointer<LoadButton> loadButton;
9494
ScopedPointer<SaveButton> saveButton;
95+
ScopedPointer<Viewport> electrodeButtonViewport;
96+
ScopedPointer<Component> electrodeButtonHolder;
9597

9698
Array<int> channelArray;
9799
Array<int> referenceArray;

0 commit comments

Comments
 (0)