Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare foundation to add new themes #1063

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 32 additions & 51 deletions OpenBCI_GUI/Debugging.pde
Original file line number Diff line number Diff line change
Expand Up @@ -73,58 +73,36 @@ class HelpWidget {
public void draw() {

pushStyle();

if(colorScheme == COLOR_SCHEME_DEFAULT){
// draw background of widget
stroke(OPENBCI_DARKBLUE);
fill(255);
rect(-1, height-h, width+2, h);
noStroke();

//draw bg of text field of widget
strokeWeight(1);
stroke(color(0, 5, 11));
fill(color(0, 5, 11));
rect(x + padding, height-h + padding, width - padding*2, h - padding *2);

textFont(p4);
textSize(14);
fill(255);
textAlign(LEFT, TOP);
text(currentOutput, padding*2, height - h + padding);
} else if (colorScheme == COLOR_SCHEME_ALTERNATIVE_A){
// draw background of widget
stroke(OPENBCI_DARKBLUE);
fill(31,69,110);
rect(-1, height-h, width+2, h);
noStroke();

//draw bg of text field of widget
strokeWeight(1);
int saturationFadeValue = 0;
if (outputWasTriggered) {
int timeDelta = millis() - colorFadeCounter;
saturationFadeValue = (int)map(timeDelta, 0, colorFadeTimeMillis, 100, 0);
if (timeDelta > colorFadeTimeMillis) {
outputWasTriggered = false;
}
// draw background of widget
stroke(OPENBCI_DARKBLUE);
fill(31,69,110);
rect(-1, height-h, width+2, h);
noStroke();

//draw bg of text field of widget
strokeWeight(1);
int saturationFadeValue = 0;
if (outputWasTriggered) {
int timeDelta = millis() - colorFadeCounter;
saturationFadeValue = (int)map(timeDelta, 0, colorFadeTimeMillis, 100, 0);
if (timeDelta > colorFadeTimeMillis) {
outputWasTriggered = false;
}
//Colors in this method are calculated using Hue, Saturation, Brightness
colorMode(HSB, 360, 100, 100);
color c = getBackgroundColor(saturationFadeValue);
stroke(c);
fill(c);
rect(x + padding, height-h + padding, width - padding*2, h - padding *2);

// Revert color mode back to standard RGB here
colorMode(RGB, 255, 255, 255);
textFont(p4);
textSize(14);
fill(getTextColor());
textAlign(LEFT, TOP);
text(currentOutput, padding*2, height - h + padding);
}

//Colors in this method are calculated using Hue, Saturation, Brightness
colorMode(HSB, 360, 100, 100);
color c = getBackgroundColor(saturationFadeValue);
stroke(c);
fill(c);
rect(x + padding, height-h + padding, width - padding*2, h - padding *2);

// Revert color mode back to standard RGB here
colorMode(RGB, 255, 255, 255);
textFont(p4);
textSize(14);
fill(getTextColor());
textAlign(LEFT, TOP);
text(currentOutput, padding*2, height - h + padding);
popStyle();
}

Expand Down Expand Up @@ -195,7 +173,10 @@ public void output(String _output) {
}

public void output(String _output, OutputLevel level) {
helpWidget.output(_output, level);
if (helpWidget != null)
helpWidget.output(_output, level);
else
println(level + "::" + _output);
}

public void outputError(String _output) {
Expand Down
48 changes: 44 additions & 4 deletions OpenBCI_GUI/GuiSettings.pde
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum ExpertModeEnum implements GuiSettingsEnum {
public class GuiSettingsValues {
public ExpertModeEnum expertMode = ExpertModeEnum.OFF;
public boolean showCytonSmoothingPopup = true;
public ThemeType themeType = ThemeType.LIGHT;

public GuiSettingsValues() {
}
Expand All @@ -43,11 +44,12 @@ class GuiSettings {

private GuiSettingsValues values;
private String filename;
private List<String> valueKeys = Arrays.asList("expertMode", "showCytonSmoothingPopup");
private Theme currentTheme;
private List<String> valueKeys = Arrays.asList("expertMode", "showCytonSmoothingPopup", "themeType");

GuiSettings(String settingsDirectory) {

values = new GuiSettingsValues();
currentTheme = new OpenBCILightTheme();
StringBuilder settingsFilename = new StringBuilder(settingsDirectory);
settingsFilename.append("GuiWideSettings.json");
filename = settingsFilename.toString();
Expand Down Expand Up @@ -81,7 +83,7 @@ class GuiSettings {
println("OpenBCI_GUI::Settings: Incompatible GUI-wide Settings found. Creating new file and resetting defaults.");
saveToFile();
}

setTheme(values.themeType);
return true;

} catch (IOException e) {
Expand Down Expand Up @@ -146,7 +148,7 @@ class GuiSettings {

//Call this method at the end of GUI main Setup in OpenBCI_GUI.pde to make sure everything exists
//Has to be in this class to make sure other classes exist
public void applySettings() {
public void applyExpertModeSettings () {
topNav.configSelector.toggleExpertModeFrontEnd(getExpertModeBoolean());
}

Expand All @@ -167,4 +169,42 @@ class GuiSettings {
public boolean getShowCytonSmoothingPopup() {
return values.showCytonSmoothingPopup;
}

public void setTheme(ThemeType themeType) {
println("Setting theme to: " + themeType.getName());
boolean is_valid = true;
values.themeType = themeType;
switch (themeType) {
case LIGHT:
currentTheme = new OpenBCILightTheme();
break;
case DARK:
currentTheme = new OpenBCIDarkTheme();
break;
default:
is_valid = false;
break;
}
if (is_valid) {
saveToFile();
outputSuccess("Restart OpenBCI GUI to load new theme.");
}
else {
outputWarn("Unsupported theme.");
}
}

public Theme getTheme() {
return currentTheme;
}

public ThemeType getThemeType() {
return values.themeType;
}

public void nextTheme() {
ThemeType nextTheme = values.themeType.next();
setTheme(nextTheme);
}

}
10 changes: 1 addition & 9 deletions OpenBCI_GUI/Interactivity.pde
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ void parseKey(char val) {
drawContainers = !drawContainers;
return;
case '{':
if(colorScheme == COLOR_SCHEME_DEFAULT){
colorScheme = COLOR_SCHEME_ALTERNATIVE_A;
} else if(colorScheme == COLOR_SCHEME_ALTERNATIVE_A) {
colorScheme = COLOR_SCHEME_DEFAULT;
}
//topNav.updateNavButtonsBasedOnColorScheme();
output("New Dark color scheme coming soon!");
return;

break;
//deactivate channels 1-4
case '1':
currentBoard.setEXGChannelActive(1-1, false);
Expand Down
20 changes: 7 additions & 13 deletions OpenBCI_GUI/OpenBCI_GUI.pde
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ PFont p6; //small Open Sans

boolean setupComplete = false;

// TODO[theme manager] remove all colors from this place
//Starting to collect the GUI-wide color pallet here. Rename constants all caps later...
final color WHITE = color(255);
final color BLACK = color(0);
Expand Down Expand Up @@ -264,12 +265,6 @@ final color SIGNAL_CHECK_YELLOW_LOWALPHA = color(221, 178, 13, 150);
final color SIGNAL_CHECK_RED = BOLD_RED;
final color SIGNAL_CHECK_RED_LOWALPHA = color(224, 56, 45, 150);


final int COLOR_SCHEME_DEFAULT = 1;
final int COLOR_SCHEME_ALTERNATIVE_A = 2;
// int COLOR_SCHEME_ALTERNATIVE_B = 3;
int colorScheme = COLOR_SCHEME_ALTERNATIVE_A;

WidgetManager wm;
boolean wmVisible = true;
CColor cp5_colors;
Expand Down Expand Up @@ -345,7 +340,11 @@ void settings() {
}

void setup() {
frameRate(120);
frameRate(120);
directoryManager = new DirectoryManager();
directoryManager.init();
settings = new SessionSettings();
guiSettings = new GuiSettings(directoryManager.getSettingsPath());

copyPaste = new CopyPaste();

Expand Down Expand Up @@ -388,8 +387,6 @@ void setup() {
"If this error persists, contact the OpenBCI team for support.";
return; // early exit
}

directoryManager = new DirectoryManager();

// redirect all output to a custom stream that will intercept all prints
// write them to file and display them in the GUI's console window
Expand Down Expand Up @@ -424,9 +421,6 @@ void setup() {
println("For more information, please visit: https://docs.openbci.com/Software/OpenBCISoftware/GUIDocs/");

// Copy sample data to the Users' Documents folder + create Recordings folder
directoryManager.init();
settings = new SessionSettings();
guiSettings = new GuiSettings(directoryManager.getSettingsPath());
userPlaybackHistoryFile = directoryManager.getSettingsPath()+"UserPlaybackHistory.json";

//open window
Expand Down Expand Up @@ -494,7 +488,7 @@ void delayedSetup() {
}

//Apply GUI-wide settings to front end at the end of setup
guiSettings.applySettings();
guiSettings.applyExpertModeSettings();

if (!isAdminUser() || isElevationNeeded()) {
outputError("OpenBCI_GUI: This application is not being run with Administrator access. This could limit the ability to connect to devices or read/write files.");
Expand Down
Loading