Skip to content

Commit fc4476e

Browse files
committed
Add labels to spectrogram channel select aka DualChannelSelect
1 parent bc3fd53 commit fc4476e

2 files changed

Lines changed: 57 additions & 20 deletions

File tree

OpenBCI_GUI/W_Spectrogram.pde

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class W_Spectrogram extends Widget {
1414
public ChannelSelect spectChanSelectTop;
1515
public ChannelSelect spectChanSelectBot;
1616
private boolean chanSelectWasOpen = false;
17+
List<controlP5.Controller> cp5ElementsToCheck = new ArrayList<controlP5.Controller>();
1718

1819
int xPos = 0;
1920
int hueLimit = 160;
@@ -70,7 +71,11 @@ class W_Spectrogram extends Widget {
7071
spectChanSelectTop = new ChannelSelect(pApplet, this, x, y, w, navH, "Spectrogram_Channels_Top");
7172
spectChanSelectBot = new ChannelSelect(pApplet, this, x, y + navH, w, navH, "Spectrogram_Channels_Bot");
7273
activateDefaultChannels();
73-
spectChanSelectBot.hideChannelText();
74+
spectChanSelectTop.setIsDualChannelSelect(true);
75+
spectChanSelectBot.setIsDualChannelSelect(true);
76+
spectChanSelectBot.setIsFirstRowChannelSelect(false);
77+
cp5ElementsToCheck.addAll(spectChanSelectTop.getCp5ElementsForOverlapCheck());
78+
cp5ElementsToCheck.addAll(spectChanSelectBot.getCp5ElementsForOverlapCheck());
7479

7580
xPos = w - 1; //draw on the right, and shift pixels to the left
7681
prevW = w;
@@ -115,8 +120,10 @@ class W_Spectrogram extends Widget {
115120
//Allow spectrogram to flex size and position depending on if the channel select is open
116121
flexSpectrogramSizeAndPosition();
117122
}
118-
119-
123+
124+
if (spectChanSelectTop.isVisible()) {
125+
lockElementsOnOverlapCheck(cp5ElementsToCheck);
126+
}
120127

121128
if (currentBoard.isStreaming()) {
122129
//Make sure we are always draw new pixels on the right
@@ -226,7 +233,6 @@ class W_Spectrogram extends Widget {
226233

227234
spectChanSelectTop.draw();
228235
spectChanSelectBot.draw();
229-
//if (spectChanSelectTop.isVisible()) spectChanSelectBot.forceDrawChecklist(dropdownIsActive);
230236
drawAxes(scaleW, scaleH);
231237
drawCenterLine();
232238
}

OpenBCI_GUI/Widget.pde

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
383383
class 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

Comments
 (0)