-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathW_Template.pde
111 lines (80 loc) · 3.45 KB
/
W_Template.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
////////////////////////////////////////////////////
//
// W_template.pde (ie "Widget Template")
//
// This is a Template Widget, intended to be used as a starting point for OpenBCI Community members that want to develop their own custom widgets!
// Good luck! If you embark on this journey, please let us know. Your contributions are valuable to everyone!
//
// Created by: Conor Russomanno, November 2016
//
///////////////////////////////////////////////////,
class W_template extends Widget {
//to see all core variables/methods of the Widget class, refer to Widget.pde
//put your custom variables here...
Button widgetTemplateButton;
W_template(PApplet _parent){
super(_parent); //calls the parent CONSTRUCTOR method of Widget (DON'T REMOVE)
//This is the protocol for setting up dropdowns.
//Note that these 3 dropdowns correspond to the 3 global functions below
//You just need to make sure the "id" (the 1st String) has the same name as the corresponding function
addDropdown("Dropdown1", "Drop 1", Arrays.asList("A", "B"), 0);
addDropdown("Dropdown2", "Drop 2", Arrays.asList("C", "D", "E"), 1);
addDropdown("Dropdown3", "Drop 3", Arrays.asList("F", "G", "H", "I"), 3);
widgetTemplateButton = new Button (x + w/2, y + h/2, 200, navHeight, "Design Your Own Widget!", 12);
widgetTemplateButton.setFont(p4, 14);
widgetTemplateButton.setURL("http://docs.openbci.com/Tutorials/15-Custom_Widgets");
}
void update(){
super.update(); //calls the parent update() method of Widget (DON'T REMOVE)
//put your code here...
}
void draw(){
super.draw(); //calls the parent draw() method of Widget (DON'T REMOVE)
//put your code here... //remember to refer to x,y,w,h which are the positioning variables of the Widget class
pushStyle();
widgetTemplateButton.draw();
popStyle();
}
void screenResized(){
super.screenResized(); //calls the parent screenResized() method of Widget (DON'T REMOVE)
//put your code here...
widgetTemplateButton.setPos(x + w/2 - widgetTemplateButton.but_dx/2, y + h/2 - widgetTemplateButton.but_dy/2);
}
void mousePressed(){
super.mousePressed(); //calls the parent mousePressed() method of Widget (DON'T REMOVE)
//put your code here...
if(widgetTemplateButton.isMouseHere()){
widgetTemplateButton.setIsActive(true);
}
}
void mouseReleased(){
super.mouseReleased(); //calls the parent mouseReleased() method of Widget (DON'T REMOVE)
//put your code here...
if(widgetTemplateButton.isActive && widgetTemplateButton.isMouseHere()){
widgetTemplateButton.goToURL();
}
widgetTemplateButton.setIsActive(false);
}
//add custom functions here
void customFunction(){
//this is a fake function... replace it with something relevant to this widget
}
};
//These functions need to be global! These functions are activated when an item from the corresponding dropdown is selected
void Dropdown1(int n){
println("Item " + (n+1) + " selected from Dropdown 1");
if(n==0){
//do this
} else if(n==1){
//do this instead
}
closeAllDropdowns(); // do this at the end of all widget-activated functions to ensure proper widget interactivity ... we want to make sure a click makes the menu close
}
void Dropdown2(int n){
println("Item " + (n+1) + " selected from Dropdown 2");
closeAllDropdowns();
}
void Dropdown3(int n){
println("Item " + (n+1) + " selected from Dropdown 3");
closeAllDropdowns();
}