diff --git a/B12NumbersV3/guiButton.pde b/B12NumbersV3/guiButton.pde index 87db69c..0f0ac8f 100644 --- a/B12NumbersV3/guiButton.pde +++ b/B12NumbersV3/guiButton.pde @@ -2,18 +2,20 @@ class Button{ ClickHandler ch; PVector pos; // Position to render from PVector dim; // Second coordinate for CORNERS or len/wid for CORNER and CENTER - int radius; // Optional corner radius - int mode; - color c; + float radius; // Optional corner radius + int mode; // Stores rect draw mode for button + color col; // Stores static color + color highlight; // Stores mouseover color boolean mouseOver; - Button(ClickHandler _ch, PVector _pos, PVector _dim, int _radius){ + Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius){ ch = _ch; pos = _pos.copy(); dim = _dim.copy(); radius = _radius; mode = CORNER; - c = color(200); + col = color(200); + highlight = color(100); mouseOver = false; ch.addl(new LiveMethodRelay(this, "clicked", float.class, float.class)); } @@ -21,6 +23,20 @@ class Button{ 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){ if(m == CORNER || m == CORNERS || m == CENTER || m == RADIUS){ mode = m; @@ -29,22 +45,22 @@ class Button{ return; } + // DISPLAY // void display(){ rectMode(mode); new MethodRelay(this,"mouseOver" + str(mode), float.class, float.class).execute(mouseX,mouseY); - if (mouseOver){ - fill(100); - }else{fill(c);} + fill(mouseOver ? highlight : col); rect(pos.x,pos.y,dim.x,dim.y,radius); } + + // MOUSE FUNCTIONS // void clicked(float x, float y){ if(mouseOver){ println(x + " " + y + " mouse pos"); } } - // 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 void mouseOver0(float x, float y){ // CORNER diff --git a/B12NumbersV3/guiMathPad.pde b/B12NumbersV3/guiMathPad.pde index ea234a4..6872244 100644 --- a/B12NumbersV3/guiMathPad.pde +++ b/B12NumbersV3/guiMathPad.pde @@ -13,38 +13,6 @@ class MathPad{ void addchar(){ //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(); -// } -// } -//}