mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 03:55:20 +00:00
Updates to Button class
This commit is contained in:
@@ -2,18 +2,20 @@ class Button{
|
|||||||
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
|
||||||
int radius; // Optional corner radius
|
float radius; // Optional corner radius
|
||||||
int mode;
|
int mode; // Stores rect draw mode for button
|
||||||
color c;
|
color col; // Stores static color
|
||||||
|
color highlight; // Stores mouseover color
|
||||||
boolean mouseOver;
|
boolean mouseOver;
|
||||||
|
|
||||||
Button(ClickHandler _ch, PVector _pos, PVector _dim, int _radius){
|
Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius){
|
||||||
ch = _ch;
|
ch = _ch;
|
||||||
pos = _pos.copy();
|
pos = _pos.copy();
|
||||||
dim = _dim.copy();
|
dim = _dim.copy();
|
||||||
radius = _radius;
|
radius = _radius;
|
||||||
mode = CORNER;
|
mode = CORNER;
|
||||||
c = color(200);
|
col = color(200);
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
@@ -21,6 +23,20 @@ class Button{
|
|||||||
this(_ch, _pos, _dim, 0);
|
this(_ch, _pos, _dim, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GETTERS //
|
||||||
|
float[] getRect(){ float[] out = {pos.x, pos.y, dim.x, dim.y}; return out; }
|
||||||
|
float getRadius(){return radius;}
|
||||||
|
color getColor(){return col;}
|
||||||
|
color getHighlight(){return highlight;}
|
||||||
|
int getMode(){return mode; }
|
||||||
|
|
||||||
|
// SETTERS //
|
||||||
|
void setRect(PVector _pos, PVector _dim){pos = _pos; dim = _dim; }
|
||||||
|
void setRadius(float rad){radius = rad;}
|
||||||
|
void setColor(color c){col = c; }
|
||||||
|
void setColor(color c, color h){col = c; highlight = h;}
|
||||||
|
void setHighlight(color h){ highlight = h; }
|
||||||
|
|
||||||
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){
|
||||||
mode = m;
|
mode = m;
|
||||||
@@ -29,22 +45,22 @@ class Button{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DISPLAY //
|
||||||
void display(){
|
void display(){
|
||||||
rectMode(mode);
|
rectMode(mode);
|
||||||
new MethodRelay(this,"mouseOver" + str(mode), float.class, float.class).execute(mouseX,mouseY);
|
new MethodRelay(this,"mouseOver" + str(mode), float.class, float.class).execute(mouseX,mouseY);
|
||||||
if (mouseOver){
|
fill(mouseOver ? highlight : col);
|
||||||
fill(100);
|
|
||||||
}else{fill(c);}
|
|
||||||
rect(pos.x,pos.y,dim.x,dim.y,radius);
|
rect(pos.x,pos.y,dim.x,dim.y,radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// MOUSE FUNCTIONS //
|
||||||
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// DETECT IF MOUSE IS OVER BUTTON //
|
// DETECT IF MOUSE IS OVER BUTTON //
|
||||||
// The numbers in the method name correspond to the mode ids because the method gets called with a relay
|
// The numbers in the method name correspond to the mode ids because the method gets called with a relay
|
||||||
void mouseOver0(float x, float y){ // CORNER
|
void mouseOver0(float x, float y){ // CORNER
|
||||||
|
|||||||
@@ -13,38 +13,6 @@ class MathPad{
|
|||||||
void addchar(){
|
void addchar(){
|
||||||
//math.expression.add(new B12Char('/'));
|
//math.expression.add(new B12Char('/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated since MethodRelay added
|
|
||||||
//class Button{
|
|
||||||
// PVector pos; // Position to render from
|
|
||||||
// PVector dim; // Second coordinate for CORNERS or len/wid for CORNER and CENTER
|
|
||||||
// int radius; // Optional corner radius
|
|
||||||
// color c;
|
|
||||||
// Listener trigger;
|
|
||||||
// BListener clickListener;
|
|
||||||
|
|
||||||
// Button(PVector _pos, PVector _dim, Listener _trigger){
|
|
||||||
// pos = _pos.copy();
|
|
||||||
// dim = _dim.copy();
|
|
||||||
// trigger = _trigger;
|
|
||||||
// }
|
|
||||||
// Button(PVector _pos, PVector _dim, int _radius, Listener _trigger){
|
|
||||||
// pos = _pos.copy();
|
|
||||||
// dim = _dim.copy();
|
|
||||||
// trigger = _trigger;
|
|
||||||
// radius = _radius;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// class BListener extends Listener{
|
|
||||||
// Button parent;
|
|
||||||
// BListener(Handler mh, Button t){
|
|
||||||
// super(mh);
|
|
||||||
// parent = t;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// void trigger(){
|
|
||||||
// parent.trigger();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user