@@ -18,25 +18,44 @@ class W_emg extends Widget {
1818
1919 private ControlP5 emgCp5;
2020 private Button emgSettingsButton;
21+ private final int EMG_SETTINGS_BUTTON_WIDTH = 125 ;
2122 private List<controlP5. Controller > cp5ElementsToCheck;
2223
24+ public ChannelSelect emgChannelSelect;
25+
2326 W_emg (PApplet _parent ) {
2427 super (_parent); // calls the parent CONSTRUCTOR method of Widget (DON'T REMOVE)
2528 parent = _parent;
2629
30+ cp5ElementsToCheck = new ArrayList<controlP5. Controller > ();
31+
32+ // Add channel select dropdown to this widget
33+ emgChannelSelect = new ChannelSelect (pApplet, this , x, y, w, navH, " EMG_Channels" );
34+ emgChannelSelect. activateAllButtons();
35+ cp5ElementsToCheck. addAll(emgChannelSelect. getCp5ElementsForOverlapCheck());
36+
2737 emgCp5 = new ControlP5 (ourApplet);
2838 emgCp5. setGraphics(ourApplet, 0 ,0 );
2939 emgCp5. setAutoDraw(false );
3040
3141 createEmgSettingsButton();
32-
33- cp5ElementsToCheck = new ArrayList<controlP5. Controller > ();
3442 cp5ElementsToCheck. add((controlP5. Controller ) emgSettingsButton);
3543 }
3644
3745 public void update () {
3846 super . update(); // calls the parent update() method of Widget (DON'T REMOVE)
3947 lockElementsOnOverlapCheck(cp5ElementsToCheck);
48+
49+ // Update channel checkboxes and active channels
50+ emgChannelSelect. update(x, y, w);
51+
52+ /*
53+ //Flex the Gplot graph when channel select dropdown is open/closed
54+ if (bpChanSelect.isVisible() != prevChanSelectIsVisible) {
55+ flexGPlotSizeAndPosition();
56+ prevChanSelectIsVisible = bpChanSelect.isVisible();
57+ }
58+ */
4059 }
4160
4261 public void draw () {
@@ -45,39 +64,57 @@ class W_emg extends Widget {
4564 drawEmgVisualizations();
4665
4766 emgCp5. draw();
67+
68+ // Draw channel select dropdown
69+ emgChannelSelect. draw();
4870 }
4971
5072 public void screenResized () {
5173 super . screenResized(); // calls the parent screenResized() method of Widget (DON'T REMOVE)
5274 emgCp5. setGraphics(ourApplet, 0 , 0 );
53- emgSettingsButton. setPosition(x0 + 1 , y0 + navH + 1 );
75+ emgSettingsButton. setPosition(x0 + w - EMG_SETTINGS_BUTTON_WIDTH - 2 , y0 + navH + 1 );
76+ emgChannelSelect. screenResized(pApplet);
77+ }
78+
79+ public void mousePressed () {
80+ super . mousePressed(); // calls the parent mousePressed() method of Widget (DON'T REMOVE)
81+ // Calls channel select mousePressed and checks if clicked
82+ emgChannelSelect. mousePressed(this . dropdownIsActive);
5483 }
5584
5685 private void drawEmgVisualizations () {
5786 pushStyle ();
58- noStroke ();
59- fill (255 );
60- rect (x, y, w, h);
6187
6288 float rx = x, ry = y, rw = w, rh = h;
89+ // Flex the EMG graph when channel select dropdown is open/closed
90+ ry = emgChannelSelect. isVisible() ? y + emgChannelSelect. getHeight() : y;
91+ rh = emgChannelSelect. isVisible() ? h - emgChannelSelect. getHeight() : h;
6392 float scaleFactor = 1.0 ;
6493 float scaleFactorJaw = 1.5 ;
65- int rowNum = 4 ;
66- int colNum = currentBoard. getNumEXGChannels() / rowNum;
67- float rowOffset = rh / rowNum;
68- float colOffset = rw / colNum;
69- int index = 0 ;
94+ int rowCount = 4 ;
95+ int columnCount = ceil (emgChannelSelect. activeChan. size() / (rowCount * 1f ));
96+ float rowOffset = rh / rowCount;
97+ float colOffset = rw / columnCount;
7098 float currentX, currentY;
7199
72100 EmgSettingsValues emgSettingsValues = dataProcessing. emgSettings. values;
73101
74- for (int i = 0 ; i < rowNum; i++ ) {
75- for (int j = 0 ; j < colNum; j++ ) {
102+ int channel = 0 ;
103+ for (int i = 0 ; i < rowCount; i++ ) {
104+ for (int j = 0 ; j < columnCount; j++ ) {
105+
106+ int index = i * columnCount + j;
107+
108+ if (index > emgChannelSelect. activeChan. size() - 1 ) {
109+ continue ;
110+ }
111+
112+ channel = emgChannelSelect. activeChan. get(index);
76113
77- int channel = i * colNum + j;
78114 int colorIndex = channel % 8 ;
79115
80116 pushMatrix ();
117+
81118 currentX = rx + j * colOffset;
82119 currentY = ry + i * rowOffset; // never name variables on an empty stomach
83120 translate (currentX, currentY);
@@ -117,12 +154,10 @@ class W_emg extends Widget {
117154 pushStyle ();
118155 stroke (OPENBCI_DARKBLUE );
119156 fill (OPENBCI_DARKBLUE );
120- int _chan = index+ 1 ;
121- textFont (p5, 12 );
122- text (_chan + " " , 10 , 20 );
157+ textFont (h4, 14 );
158+ text ((channel + 1 ), 10 , 20 );
123159 popStyle ();
124160
125- index++ ;
126161 popMatrix ();
127162 }
128163 }
@@ -131,8 +166,9 @@ class W_emg extends Widget {
131166 }
132167
133168 private void createEmgSettingsButton () {
134- emgSettingsButton = createButton(emgCp5, " emgSettingsButton" , " EMG Settings" , (int ) (x0 + 1 ),
135- (int ) (y0 + navH + 1 ), 125 , navH - 3 , p5, 12 , colorNotPressed, OPENBCI_DARKBLUE );
169+ emgSettingsButton = createButton(emgCp5, " emgSettingsButton" , " EMG Settings" ,
170+ (int ) (x0 + w - EMG_SETTINGS_BUTTON_WIDTH - 1 ), (int ) (y0 + navH + 1 ),
171+ EMG_SETTINGS_BUTTON_WIDTH , navH - 3 , p5, 12 , colorNotPressed, OPENBCI_DARKBLUE );
136172 emgSettingsButton. setBorderColor(OBJECT_BORDER_GREY );
137173 emgSettingsButton. onRelease(new CallbackListener () {
138174 public synchronized void controlEvent (CallbackEvent theEvent ) {
0 commit comments