Skip to content

Commit 6d4c6a6

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);" Implemented the improvements. Removed the upButton and DownButton. We have scrolling bar on the right to do the same. � Now scrolling in Remap works fine.
2 parents 19706f4 + f754c62 commit 6d4c6a6

2 files changed

Lines changed: 38 additions & 88 deletions

File tree

Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp

100644100755
Lines changed: 36 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ ChannelMappingEditor::ChannelMappingEditor(GenericProcessor* parentNode, bool us
3232

3333
{
3434
desiredWidth = 350;
35-
36-
scrollDistance = 0;
3735

3836
selectAllButton = new ElectrodeEditorButton("Select All",Font("Small Text",14,Font::plain));
3937
selectAllButton->addListener(this);
@@ -56,17 +54,13 @@ ChannelMappingEditor::ChannelMappingEditor(GenericProcessor* parentNode, bool us
5654
resetButton->setClickingTogglesState(false);
5755
resetButton->setEnabled(false);
5856

59-
upButton = new TriangleButton(1);
60-
upButton->addListener(this);
61-
upButton->setBounds(320,30,10,8);
62-
addAndMakeVisible(upButton);
63-
upButton->setVisible(false);
64-
65-
downButton = new TriangleButton(2);
66-
downButton->addListener(this);
67-
downButton->setBounds(320,45,10,8);
68-
addAndMakeVisible(downButton);
69-
downButton->setVisible(false);
57+
58+
addAndMakeVisible(electrodeButtonViewport = new Viewport());
59+
electrodeButtonViewport->setBounds(10,30,330,70);
60+
electrodeButtonViewport->setScrollBarsShown(true,false,true,true);
61+
electrodeButtonHolder = new Component();
62+
electrodeButtonViewport->setViewedComponent(electrodeButtonHolder,false);
63+
7064

7165
loadButton = new LoadButton();
7266
loadButton->addListener(this);
@@ -176,7 +170,7 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded, bool clearPrevi
176170
// if (!getCollapsedState())
177171
// addAndMakeVisible(button);
178172
// else
179-
addChildComponent(button); // determine visibility in refreshButtonLocations()
173+
electrodeButtonHolder->addAndMakeVisible(button); // determine visibility in refreshButtonLocations()
180174

181175
button->addListener(this);
182176
if (reorderActive)
@@ -217,42 +211,30 @@ void ChannelMappingEditor::createElectrodeButtons(int numNeeded, bool clearPrevi
217211
channelSelector->setRadioStatus(true);
218212

219213
refreshButtonLocations();
220-
221-
if (numNeeded > 100)
222-
{
223-
upButton->setVisible(true);
224-
downButton->setVisible(true);
225-
} else {
226-
upButton->setVisible(false);
227-
downButton->setVisible(false);
228-
}
229214
}
230215

231216
void ChannelMappingEditor::refreshButtonLocations()
232217
{
218+
electrodeButtonViewport->setVisible(!getCollapsedState());
233219
int width = 19;
234220
int height = 15;
235-
int row = (int) -scrollDistance;
221+
int row = 0;
236222
int column = 0;
237-
223+
int totalWidth = 0;
224+
int totalHeight = 0;
238225
for (int i = 0; i < electrodeButtons.size(); i++)
239226
{
240-
241227
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-
228+
button->setBounds(column*width, row*height, width, height);
229+
totalWidth = jmax(totalWidth, ++column*width);
230+
250231
if (column % 16 == 0)
251232
{
252-
column = 0;
253-
row++;
233+
totalHeight = jmax(totalHeight, ++row*height);
234+
column = 0;
254235
}
255236
}
237+
electrodeButtonHolder->setSize(totalWidth,totalHeight);
256238
}
257239

258240
void ChannelMappingEditor::collapsedStateChanged()
@@ -531,28 +513,6 @@ void ChannelMappingEditor::buttonEvent(Button* button)
531513

532514

533515
}
534-
} else if (button == upButton)
535-
{
536-
537-
scrollDistance -= 1;
538-
539-
if (scrollDistance < 0)
540-
scrollDistance = 0;
541-
542-
refreshButtonLocations();
543-
544-
} else if (button == downButton)
545-
{
546-
547-
float maxScrollDistance = ceil(float(electrodeButtons.size() - 80) / 16.0f);
548-
549-
scrollDistance += 1;
550-
551-
if (scrollDistance > maxScrollDistance)
552-
scrollDistance = maxScrollDistance;
553-
554-
refreshButtonLocations();
555-
556516
} else if (button == saveButton)
557517
{
558518
//std::cout << "Save button clicked." << std::endl;
@@ -774,12 +734,26 @@ void ChannelMappingEditor::mouseDrag(const MouseEvent& e)
774734
else if (isDragging)
775735
{
776736
MouseEvent ev = e.getEventRelativeTo(this);
777-
778-
int col = ((ev.x-5) / 20);
737+
int mouseDownY = ev.getMouseDownY()-30;
738+
int mouseDownX = ev.getMouseDownX()-10;
739+
Point<int> viewPosition =electrodeButtonViewport->getViewPosition();
740+
741+
int distanceY = ev.getDistanceFromDragStartY();
742+
int distanceX = ev.getDistanceFromDragStartX();
743+
744+
int newPosY = viewPosition.getY()+ mouseDownY + distanceY;
745+
int newPosX = viewPosition.getX()+ mouseDownX + distanceX;
746+
if ( mouseDownY + distanceY > 70){
747+
electrodeButtonViewport->setViewPosition(viewPosition.getX(),newPosY);
748+
}else if( mouseDownY + distanceY < 0 ){
749+
electrodeButtonViewport->setViewPosition(viewPosition.getX(),newPosY);
750+
}
751+
752+
753+
int col = (newPosX / 19);
779754
if (col < 0) col = 0;
780755
else if (col > 16) col = 16;
781-
782-
int row = ((ev.y-30) / 15);
756+
int row = (newPosY / 15);
783757
if (row < 0) row = 0;
784758

785759
int hoverButton = row*16+col;
@@ -899,25 +873,6 @@ void ChannelMappingEditor::mouseDoubleClick(const MouseEvent& e)
899873
}
900874
}
901875

902-
void ChannelMappingEditor::mouseWheelMove(const MouseEvent& event,
903-
const MouseWheelDetails& wheel)
904-
{
905-
906-
float maxScrollDistance = ceil(float(electrodeButtons.size() - 80) / 16.0f);
907-
908-
// std::cout << "Got wheel move: " << wheel.deltaY << std::endl;
909-
// channelSelector->shiftChannelsVertical(-wheel.deltaY);
910-
scrollDistance -= wheel.deltaY*2;
911-
912-
if (scrollDistance > maxScrollDistance)
913-
scrollDistance = maxScrollDistance;
914-
915-
if (scrollDistance < 0)
916-
scrollDistance = 0;
917-
918-
refreshButtonLocations();
919-
}
920-
921876
void ChannelMappingEditor::checkUnusedChannels()
922877
{
923878
for (int i = 0; i < electrodeButtons.size(); i++)

Source/Plugins/ChannelMappingNode/ChannelMappingEditor.h

100644100755
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ class ChannelMappingEditor : public GenericEditor,
6363

6464
void mouseDoubleClick(const MouseEvent& e);
6565

66-
void mouseWheelMove(const MouseEvent& event, const MouseWheelDetails& wheel);
67-
6866
void collapsedStateChanged();
6967

7068
void startAcquisition();
@@ -88,10 +86,10 @@ class ChannelMappingEditor : public GenericEditor,
8886
ScopedPointer<ElectrodeEditorButton> selectAllButton;
8987
ScopedPointer<ElectrodeEditorButton> modifyButton;
9088
ScopedPointer<ElectrodeEditorButton> resetButton;
91-
ScopedPointer<TriangleButton> upButton;
92-
ScopedPointer<TriangleButton> downButton;
9389
ScopedPointer<LoadButton> loadButton;
9490
ScopedPointer<SaveButton> saveButton;
91+
ScopedPointer<Viewport> electrodeButtonViewport;
92+
ScopedPointer<Component> electrodeButtonHolder;
9593

9694
Array<int> channelArray;
9795
Array<int> referenceArray;
@@ -114,9 +112,6 @@ class ChannelMappingEditor : public GenericEditor,
114112

115113
ScopedPointer<DynamicObject> info;
116114

117-
float scrollDistance;
118-
119-
120115
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ChannelMappingEditor);
121116

122117
};

0 commit comments

Comments
 (0)