Skip to content

Commit 05371a9

Browse files
committed
Add Marker Widget to Session settings and account for UI overlapping
1 parent 690c0d8 commit 05371a9

2 files changed

Lines changed: 54 additions & 14 deletions

File tree

OpenBCI_GUI/SessionSettings.pde

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ class SessionSettings {
196196
int loadEmgJoystickSmoothing;
197197
List<Integer> loadEmgJoystickInputs = new ArrayList<Integer>();
198198

199+
//Marker Widget
200+
private int loadMarkerWindow;
201+
private int loadMarkerCount;
202+
199203
//Primary JSON objects for saving and loading data
200204
private JSONObject saveSettingsJSONData;
201205
private JSONObject loadSettingsJSONData;
@@ -213,6 +217,7 @@ class SessionSettings {
213217
private final String kJSONKeySpectrogram = "spectrogram";
214218
private final String kJSONKeyEmg = "emg";
215219
private final String kJSONKeyEmgJoystick = "emgJoystick";
220+
private final String kJSONKeyMarker = "marker";
216221

217222
//used only in this class to count the number of channels being used while saving/loading, this gets updated in updateToNChan whenever the number of channels being used changes
218223
int slnchan;
@@ -486,6 +491,12 @@ class SessionSettings {
486491
saveEmgJoystickSettings.setJSONArray("joystickInputs", saveEmgJoystickInputs);
487492
saveSettingsJSONData.setJSONObject(kJSONKeyEmgJoystick, saveEmgJoystickSettings);
488493

494+
///////////////////////////////////////////////Setup new JSON object to save Marker Widget Settings
495+
JSONObject saveMarkerSettings = new JSONObject();
496+
saveMarkerSettings.setInt("markerWindow", w_marker.getMarkerWindow().getIndex());
497+
saveMarkerSettings.setInt("markerCount", w_marker.getMarkerCount().getIndex());
498+
saveSettingsJSONData.setJSONObject(kJSONKeyMarker, saveMarkerSettings);
499+
489500
///////////////////////////////////////////////Setup new JSON object to save Widgets Active in respective Containers
490501
JSONObject saveWidgetSettings = new JSONObject();
491502

@@ -675,6 +686,11 @@ class SessionSettings {
675686
loadEmgJoystickInputs.add(loadJoystickInputsJson.getInt(i));
676687
}
677688

689+
//Get Marker widget settings
690+
JSONObject loadMarkerSettings = loadSettingsJSONData.getJSONObject(kJSONKeyMarker);
691+
loadMarkerWindow = loadMarkerSettings.getInt("markerWindow");
692+
loadMarkerCount = loadMarkerSettings.getInt("markerCount");
693+
678694
//get the Widget/Container settings
679695
JSONObject loadWidgetSettings = loadSettingsJSONData.getJSONObject(kJSONKeyWidget);
680696
//Apply Layout directly before loading and applying widgets to containers
@@ -933,6 +949,12 @@ class SessionSettings {
933949
println("Settings: Exception caught applying EMG Joystick settings " + e);
934950
}
935951

952+
////////////////////////////Apply Marker Widget settings
953+
w_marker.setMarkerWindow(loadMarkerWindow);
954+
w_marker.cp5_widget.getController("markerWindowDropdown").getCaptionLabel().setText(w_marker.getMarkerWindow().getString());
955+
w_marker.setMarkerCount(loadMarkerCount);
956+
w_marker.cp5_widget.getController("markerCountDropdown").getCaptionLabel().setText(w_marker.getMarkerCount().getString());
957+
936958
////////////////////////////////////////////////////////////
937959
// Apply more loaded widget settings above this line //
938960

OpenBCI_GUI/W_Marker.pde

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@
44
// //
55
// Created by: Richard Waltman, August 2023 //
66
// Purpose: Add software markers to data //
7-
// Marker Shortcuts: z x c v //
7+
// Marker Shortcuts: z x c v Z X C V //
88
// //
99
//////////////////////////////////////////////////////
1010

1111
class W_Marker extends Widget {
1212

1313
private ControlP5 localCP5;
14+
private List<controlP5.Controller> cp5ElementsToCheckForOverlap;
1415

1516
private final int MARKER_BUTTON_WIDTH = 125;
1617
private final int MARKER_BUTTON_HEIGHT = 20;
1718
private final int MARKER_BUTTON_GRID_CELL_HEIGHT = 30;
1819
private final int MAX_NUMBER_OF_MARKER_BUTTONS = 8;
1920
private Button[] markerButtons = new Button[MAX_NUMBER_OF_MARKER_BUTTONS];
20-
private MarkerCount markerCount = MarkerCount.FOUR; //Default number of markers to display
2121
private Grid markerButtonGrid;
2222

2323
private MarkerBar markerBar;
2424
private int graphX, graphY, graphW, graphH;
2525
private int PAD_FIVE = 5;
2626
private int GRAPH_PADDING = 30;
27-
private MarkerXLim xLimit = MarkerXLim.TEN;
27+
28+
private MarkerCount markerCount = MarkerCount.FOUR; //Default number of markers to display
29+
private MarkerWindow markerWindow = MarkerWindow.TEN;
2830

2931
W_Marker(PApplet _parent){
3032
super(_parent); //calls the parent CONSTRUCTOR method of Widget (DON'T REMOVE)
@@ -37,18 +39,26 @@ class W_Marker extends Widget {
3739
createMarkerButtons();
3840

3941
updateGraphDims();
40-
addDropdown("markerWindowDropdown", "Window", xLimit.getEnumStringsAsList(), xLimit.getIndex());
42+
addDropdown("markerWindowDropdown", "Window", markerWindow.getEnumStringsAsList(), markerWindow.getIndex());
4143
addDropdown("markerCountDropdown", "Count", markerCount.getEnumStringsAsList(), markerCount.getIndex());
42-
markerBar = new MarkerBar(_parent, MAX_NUMBER_OF_MARKER_BUTTONS, xLimit.getValue(), markerCount.getValue(), graphX, graphY, graphW, graphH);
44+
markerBar = new MarkerBar(_parent, MAX_NUMBER_OF_MARKER_BUTTONS, markerWindow.getValue(), markerCount.getValue(), graphX, graphY, graphW, graphH);
4345

4446
markerButtonGrid = new Grid(2, 4, MARKER_BUTTON_GRID_CELL_HEIGHT);
4547
markerButtonGrid.setDrawTableBorder(true);
4648
markerButtonGrid.setDrawTableInnerLines(true);
49+
50+
//Add all cp5 elements to a list so that they can be checked for overlap
51+
cp5ElementsToCheckForOverlap = new ArrayList<controlP5.Controller>();
52+
for (int i = 0; i < MAX_NUMBER_OF_MARKER_BUTTONS; i++) {
53+
cp5ElementsToCheckForOverlap.add(markerButtons[i]);
54+
}
4755
}
4856

4957
public void update(){
5058
super.update(); //calls the parent update() method of Widget (DON'T REMOVE)
5159

60+
lockElementsOnOverlapCheck(cp5ElementsToCheckForOverlap);
61+
5262
if (currentBoard.isStreaming()) {
5363
markerBar.update();
5464
}
@@ -172,9 +182,9 @@ class W_Marker extends Widget {
172182
}
173183
}
174184

175-
public void setMarkerHorizScale(int n) {
176-
xLimit = xLimit.values()[n];
177-
markerBar.adjustTimeAxis(xLimit.getValue());
185+
public void setMarkerWindow(int n) {
186+
markerWindow = markerWindow.values()[n];
187+
markerBar.adjustTimeAxis(markerWindow.getValue());
178188
}
179189

180190
public void setMarkerCount(int n) {
@@ -189,11 +199,19 @@ class W_Marker extends Widget {
189199
}
190200
}
191201

202+
public MarkerWindow getMarkerWindow() {
203+
return markerWindow;
204+
}
205+
206+
public MarkerCount getMarkerCount() {
207+
return markerCount;
208+
}
209+
192210
};
193211

194212
//The following global functions are used by the Marker widget dropdowns. This method is the least amount of code.
195213
public void markerWindowDropdown(int n) {
196-
w_marker.setMarkerHorizScale(n);
214+
w_marker.setMarkerWindow(n);
197215
}
198216

199217
public void markerCountDropdown(int n) {
@@ -227,10 +245,10 @@ class MarkerBar {
227245

228246
private DataSource markerBoard;
229247

230-
MarkerBar(PApplet _parent, int _numMarkers, int xLimit, float yLimit, int _x, int _y, int _w, int _h) { //channel number, x/y location, height, width
248+
MarkerBar(PApplet _parent, int _numMarkers, int markerWindow, float yLimit, int _x, int _y, int _w, int _h) { //channel number, x/y location, height, width
231249

232250
numMarkers = _numMarkers;
233-
numSeconds = xLimit;
251+
numSeconds = markerWindow;
234252

235253
// This widget is only instantiated when the board is accel capable, so we don't need to check
236254
markerBoard = (DataSource)currentBoard;
@@ -357,7 +375,7 @@ class MarkerBar {
357375

358376

359377

360-
public enum MarkerXLim implements IndexingInterface
378+
public enum MarkerWindow implements IndexingInterface
361379
{
362380
FIVE (0, 5, "5 sec"),
363381
TEN (1, 10, "10 sec"),
@@ -366,9 +384,9 @@ public enum MarkerXLim implements IndexingInterface
366384
private int index;
367385
private int value;
368386
private String label;
369-
private static MarkerXLim[] vals = values();
387+
private static MarkerWindow[] vals = values();
370388

371-
MarkerXLim(int _index, int _value, String _label) {
389+
MarkerWindow(int _index, int _value, String _label) {
372390
this.index = _index;
373391
this.value = _value;
374392
this.label = _label;

0 commit comments

Comments
 (0)