@@ -287,7 +287,7 @@ class Widget{
287287 }
288288 }
289289
290- // For use with one Cp5 controller per class/widget
290+ // For use with one Cp5 controller per class/widget. Can only be called once per widget during update loop.
291291 protected void lockElementOnOverlapCheck (controlP5. Controller c ) {
292292 if (dropdownIsActive != previousDropdownIsActive) {
293293 // println(c.getName(), " lock == ", dropdownIsActive);
@@ -296,7 +296,7 @@ class Widget{
296296 }
297297 }
298298
299- // For use with multiple Cp5 controllers per class/widget
299+ // For use with multiple Cp5 controllers per class/widget. Can only be called once per widget during update loop.
300300 protected void lockElementsOnOverlapCheck (List<controlP5. Controller > listOfControllers ) {
301301 if (dropdownIsActive != previousDropdownIsActive) {
302302 for (controlP5. Controller c : listOfControllers) {
@@ -382,6 +382,7 @@ void WidgetSelector(int n){
382382// This is a helpful class that will add a channel select feature to a Widget
383383class ChannelSelect {
384384 protected Widget widget;
385+ private List<controlP5. Controller > cp5ElementsToCheck = new ArrayList<controlP5. Controller > ();
385386 protected int x, y, w, h, navH, butToggleY;
386387 public float tri_xpos = 0 ;
387388 protected float chanSelectXPos = 0 ;
@@ -395,7 +396,13 @@ class ChannelSelect {
395396 protected boolean isVisible;
396397 public List<Integer > activeChan;
397398 public String chanDropdownName;
398- protected boolean showChannelText = true ;
399+ protected boolean isFirstRowChannelSelect = true ;
400+ protected boolean isDualChannelSelect = false ;
401+
402+ private int labelWidth = 0 ;
403+ private int labelSpacer = 0 ;
404+ private String firstRowLabel = " Top" ;
405+ private String secondRowLabel = " Bottom" ;
399406
400407 ChannelSelect (PApplet _parent , Widget _widget , int _x , int _y , int _w , int _navH , String checkBoxName ) {
401408 widget = _widget;
@@ -427,23 +434,23 @@ class ChannelSelect {
427434 }
428435 // Update position of buttons on every update and check for UI overlap
429436 for (int i = 0 ; i < nchan; i++ ) {
430- channelButtons. get(i). setPosition(x + (button_spacer* (i+ 1 )) + (buttonW* i), y + offset);
431- widget. lockElementOnOverlapCheck(channelButtons. get(i));
437+ channelButtons. get(i). setPosition(x + labelWidth + labelSpacer + (button_spacer* (i+ 1 )) + (buttonW* i), y + offset);
432438 }
433439 }
434440
435441 public void draw () {
442+ chanSelectXPos = x + 2 ;
436443 pushStyle ();
437444 noStroke ();
438- if (showChannelText ) {
445+ if (isFirstRowChannelSelect ) {
439446 // change "Channels" text color and triangle color on hover
440447 if (channelSelectHover) {
441448 fill (OPENBCI_BLUE );
442449 } else {
443450 fill (0 );
444451 }
445452 textFont (p5, 12 );
446- chanSelectXPos = x + 2 ;
453+
447454 text (" Channels" , chanSelectXPos, y - 6 );
448455 tri_xpos = x + textWidth (" Channels" ) + 7 ;
449456
@@ -468,20 +475,27 @@ class ChannelSelect {
468475 if (isVisible) {
469476 // Draw channel select buttons
470477 cp5_chanSelect. draw();
471- }
472-
473- // Draw a border around toggle buttons to indicate if channel is on or off
474- if (isVisible) {
478+ // Draw a border around toggle buttons to indicate if channel is on or off
475479 pushStyle ();
476480 int weight = 1 ;
477481 strokeWeight (weight);
478482 noFill ();
479483 for (int i = 0 ; i < nchan; i++ ) {
480484 color c = currentBoard. isEXGChannelActive(i) ? color (0 ,255 ,0 ,255 ) : color (255 ,0 ,0 ,255 );
481485 stroke (c);
482- rect (x + (button_spacer* (i+ 1 )) + (buttonW* i) - weight, y + offset - weight, channelButtons. get(i). getWidth() + weight, channelButtons. get(i). getHeight() + weight);
486+ rect (x + labelWidth + labelSpacer + (button_spacer* (i+ 1 )) + (buttonW* i) - weight, y + offset - weight, channelButtons. get(i). getWidth() + weight, channelButtons. get(i). getHeight() + weight);
483487 }
484488 popStyle ();
489+ // Draw label
490+ if (isDualChannelSelect) {
491+ pushStyle ();
492+ fill (0 );
493+ textFont (p5, 12 );
494+ textAlign (CENTER , TOP );
495+ String label = isFirstRowChannelSelect ? firstRowLabel : secondRowLabel;
496+ text (label, x + labelSpacer + labelWidth/ 2 , y + offset);
497+ popStyle ();
498+ }
485499 }
486500 }
487501
@@ -514,6 +528,7 @@ class ChannelSelect {
514528 channelButtons. add(
515529 createButton(" ch" + (i+ 1 ), (i+ 1 ), true , x + (button_spacer* (i+ 2 )) + (buttonW* i), y + offset, buttonW, buttonH)
516530 );
531+ cp5ElementsToCheck. add((controlP5. Controller )channelButtons. get(i));
517532 }
518533 }
519534
@@ -550,12 +565,28 @@ class ChannelSelect {
550565 return myButton;
551566 }
552567
553- public void showChannelText () {
554- showChannelText = true ;
568+ public void setIsFirstRowChannelSelect (boolean b ) {
569+ isFirstRowChannelSelect = b;
570+ }
571+
572+ public void setIsDualChannelSelect (boolean b ) {
573+ isDualChannelSelect = b;
574+ if (isDualChannelSelect) {
575+ labelWidth = 36 ;
576+ labelSpacer = 4 ;
577+ }
578+ }
579+
580+ public List<controlP5. Controller > getCp5ElementsForOverlapCheck () {
581+ return cp5ElementsToCheck;
582+ }
583+
584+ public void setFirstRowLabel (String s ) {
585+ firstRowLabel = s;
555586 }
556587
557- public void hideChannelText ( ) {
558- showChannelText = false ;
588+ public void setSecondRowLabel ( String s ) {
589+ secondRowLabel = s ;
559590 }
560591
561592 public boolean isVisible () {
0 commit comments