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
|
||||
color col; // Stores static color
|
||||
color highlight; // Stores mouseover color
|
||||
MethodRelay function;
|
||||
MethodRelay function; // Gets called when button is pressed
|
||||
boolean mouseOver;
|
||||
Object[] data; // Anything that gets passed to MethodRelay function
|
||||
|
||||
Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius){
|
||||
ch = _ch;
|
||||
@@ -19,6 +20,7 @@ class Button{
|
||||
highlight = color(100);
|
||||
mouseOver = false;
|
||||
ch.addl(new LiveMethodRelay(this, "clicked", float.class, float.class));
|
||||
data = new Object[0];
|
||||
}
|
||||
Button(ClickHandler _ch, PVector _pos, PVector _dim){
|
||||
this(_ch, _pos, _dim, 0);
|
||||
@@ -62,6 +64,7 @@ class Button{
|
||||
void clicked(float x, float y){
|
||||
if(mouseOver){
|
||||
println(x + " " + y + " mouse pos");
|
||||
function.execute(data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ class MathPad{
|
||||
|
||||
void initialize(){
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -42,28 +43,28 @@ class MathPad{
|
||||
}
|
||||
|
||||
class B12Button extends Button{
|
||||
Object parent;
|
||||
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);
|
||||
data = (Object[])append(data, _digit);
|
||||
digit = _digit;
|
||||
parent = _parent;
|
||||
}
|
||||
B12Button(Object _parent, ClickHandler _ch, PVector _pos, PVector _dim, B12Digit _digit){
|
||||
this(_parent, _ch, _pos, _dim, 2, _digit);
|
||||
B12Button(ClickHandler _ch, PVector _pos, PVector _dim, B12Digit _digit){
|
||||
this(_ch, _pos, _dim, 2, _digit);
|
||||
}
|
||||
|
||||
// GETTERS AND SETTERS //
|
||||
B12Digit getDigit(){ return digit; }
|
||||
void setDigit(B12Digit _digit){ digit = _digit; }
|
||||
|
||||
/*
|
||||
@Override
|
||||
void clicked(float x, float y){
|
||||
if(mouseOver){
|
||||
new MethodRelay(parent, "addChar", B12Digit.class).execute(digit);
|
||||
}
|
||||
new MethodRelay(target, "addChar", B12Digit.class).execute(digit);
|
||||
}
|
||||
}*/
|
||||
|
||||
@Override
|
||||
void display(){
|
||||
|
||||
Reference in New Issue
Block a user