mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 03:55:20 +00:00
Moved Button click calls
Rolled method relay button click calls from B12Button to Button, allowing buttons to function without defining a child class
This commit is contained in:
@@ -6,8 +6,9 @@ class Button{
|
|||||||
int mode; // Stores rect draw mode for button
|
int mode; // Stores rect draw mode for button
|
||||||
color col; // Stores static color
|
color col; // Stores static color
|
||||||
color highlight; // Stores mouseover color
|
color highlight; // Stores mouseover color
|
||||||
MethodRelay function;
|
MethodRelay function; // Gets called when button is pressed
|
||||||
boolean mouseOver;
|
boolean mouseOver;
|
||||||
|
Object[] data; // Anything that gets passed to MethodRelay function
|
||||||
|
|
||||||
Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius){
|
Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius){
|
||||||
ch = _ch;
|
ch = _ch;
|
||||||
@@ -19,6 +20,7 @@ class Button{
|
|||||||
highlight = color(100);
|
highlight = color(100);
|
||||||
mouseOver = false;
|
mouseOver = false;
|
||||||
ch.addl(new LiveMethodRelay(this, "clicked", float.class, float.class));
|
ch.addl(new LiveMethodRelay(this, "clicked", float.class, float.class));
|
||||||
|
data = new Object[0];
|
||||||
}
|
}
|
||||||
Button(ClickHandler _ch, PVector _pos, PVector _dim){
|
Button(ClickHandler _ch, PVector _pos, PVector _dim){
|
||||||
this(_ch, _pos, _dim, 0);
|
this(_ch, _pos, _dim, 0);
|
||||||
@@ -62,6 +64,7 @@ class Button{
|
|||||||
void clicked(float x, float y){
|
void clicked(float x, float y){
|
||||||
if(mouseOver){
|
if(mouseOver){
|
||||||
println(x + " " + y + " mouse pos");
|
println(x + " " + y + " mouse pos");
|
||||||
|
function.execute(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ class MathPad{
|
|||||||
|
|
||||||
void initialize(){
|
void initialize(){
|
||||||
for(int i = 0; i < 12; i++){
|
for(int i = 0; i < 12; i++){
|
||||||
buttons[i] = new B12Button(this, ch, new PVector(25 * int(i%4),25 * floor(i/4)), new PVector(20,20),new B12Digit(i));
|
buttons[i] = new B12Button(ch, new PVector(25 * int(i%4),25 * floor(i/4)), new PVector(20,20),new B12Digit(i));
|
||||||
|
buttons[i].setFunction(new MethodRelay(this, "addChar", B12Digit.class));
|
||||||
buttons[i].setColor(220,150);
|
buttons[i].setColor(220,150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,28 +43,28 @@ class MathPad{
|
|||||||
}
|
}
|
||||||
|
|
||||||
class B12Button extends Button{
|
class B12Button extends Button{
|
||||||
Object parent;
|
|
||||||
B12Digit digit;
|
B12Digit digit;
|
||||||
|
|
||||||
B12Button(Object _parent, 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 = (Object[])append(data, _digit);
|
||||||
digit = _digit;
|
digit = _digit;
|
||||||
parent = _parent;
|
|
||||||
}
|
}
|
||||||
B12Button(Object _parent, ClickHandler _ch, PVector _pos, PVector _dim, B12Digit _digit){
|
B12Button(ClickHandler _ch, PVector _pos, PVector _dim, B12Digit _digit){
|
||||||
this(_parent, _ch, _pos, _dim, 2, _digit);
|
this(_ch, _pos, _dim, 2, _digit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// GETTERS AND SETTERS //
|
// GETTERS AND SETTERS //
|
||||||
B12Digit getDigit(){ return digit; }
|
B12Digit getDigit(){ return digit; }
|
||||||
void setDigit(B12Digit _digit){ digit = _digit; }
|
void setDigit(B12Digit _digit){ digit = _digit; }
|
||||||
|
|
||||||
|
/*
|
||||||
@Override
|
@Override
|
||||||
void clicked(float x, float y){
|
void clicked(float x, float y){
|
||||||
if(mouseOver){
|
if(mouseOver){
|
||||||
new MethodRelay(parent, "addChar", B12Digit.class).execute(digit);
|
new MethodRelay(target, "addChar", B12Digit.class).execute(digit);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void display(){
|
void display(){
|
||||||
|
|||||||
Reference in New Issue
Block a user