Much better button data pass

Using a setter is much better. Cleaned up B12Button as well
This commit is contained in:
61616
2022-05-05 18:00:56 -04:00
parent 24a4ff043e
commit 81423f79e1
3 changed files with 7 additions and 14 deletions

View File

@@ -3,7 +3,7 @@
Beta version of a clock in base 12. Beta version of a clock in base 12.
by Nayan Sawyer by Nayan Sawyer
started Mar 2022 started Mar 2022
version 0.1.4.2 April 30 2022 version 0.1.4.3 April 30 2022
Characters are a variation of Kaktovik Inupiaq numerals Characters are a variation of Kaktovik Inupiaq numerals
reversed and in base 12 instead of 20. I take no credit reversed and in base 12 instead of 20. I take no credit

View File

@@ -1,4 +1,4 @@
class Button{ class Button{ // TODO make most of the attributes private
ClickHandler ch; ClickHandler ch;
PVector pos; // Position to render from PVector pos; // Position to render from
PVector dim; // Second coordinate for CORNERS or len/wid for CORNER and CENTER PVector dim; // Second coordinate for CORNERS or len/wid for CORNER and CENTER
@@ -8,7 +8,7 @@ class Button{
color highlight; // Stores mouseover color color highlight; // Stores mouseover color
MethodRelay function; // Gets called when button is pressed MethodRelay function; // Gets called when button is pressed
boolean mouseOver; boolean mouseOver;
Object[] data; // Anything that gets passed to MethodRelay function Object[] data; // Anything that gets passed to MethodRelay function when key pressed. Must be set manually
Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius){ Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius){
ch = _ch; ch = _ch;
@@ -40,7 +40,8 @@ class Button{
void setColor(color c){col = c; } void setColor(color c){col = c; }
void setColor(color c, color h){col = c; highlight = h;} void setColor(color c, color h){col = c; highlight = h;}
void setHighlight(color h){ highlight = h; } void setHighlight(color h){ highlight = h; }
void setFunction(MethodRelay _function){function = _function;} // TODO finish implementation void setFunction(MethodRelay _function){function = _function;} // DONE finish implementation
void setData(Object... _data){ data = _data; } // Data to pass for button presses. Ugh, note that the array already exists because it's passed as such, no need to create a new one. Stupid bug
void setMode(int m){ void setMode(int m){
if(m == CORNER || m == CORNERS || m == CENTER || m == RADIUS){ if(m == CORNER || m == CORNERS || m == CENTER || m == RADIUS){

View File

@@ -47,8 +47,9 @@ class B12Button extends Button{
B12Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius, B12Digit _digit){ B12Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius, B12Digit _digit){
super(_ch,_pos,_dim,_radius); super(_ch,_pos,_dim,_radius);
data = new Object[]{_digit}; //(Object[])append(data, _digit); commented version deprecated. required initializing array in Button //data = new Object[]{_digit}; Deprecated
digit = _digit; digit = _digit;
setData(_digit);
} }
B12Button(ClickHandler _ch, PVector _pos, PVector _dim, B12Digit _digit){ B12Button(ClickHandler _ch, PVector _pos, PVector _dim, B12Digit _digit){
this(_ch, _pos, _dim, 2, _digit); this(_ch, _pos, _dim, 2, _digit);
@@ -58,18 +59,9 @@ class B12Button extends Button{
B12Digit getDigit(){ return digit; } B12Digit getDigit(){ return digit; }
void setDigit(B12Digit _digit){ digit = _digit; } void setDigit(B12Digit _digit){ digit = _digit; }
/*
@Override
void clicked(float x, float y){
if(mouseOver){
new MethodRelay(target, "addChar", B12Digit.class).execute(digit);
}
}*/
@Override @Override
void display(){ void display(){
super.display(); //<>// super.display(); //<>//
//new MethodRelay(this, "mouseOver" + str(mode), float.class, float.class).execute(mouseX,mouseY);
pushMatrix(); pushMatrix();