mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 03:55:20 +00:00
Added mathpad beta and number interface
This commit is contained in:
@@ -12,7 +12,7 @@ class ClickHandler{
|
|||||||
|
|
||||||
void clean(){
|
void clean(){
|
||||||
if(mrs.length == 0) return;
|
if(mrs.length == 0) return;
|
||||||
for(int i = mrs.length; i >= 0; i--){
|
for(int i = mrs.length -1; i >= 0; i--){
|
||||||
if(!mrs[i].live){
|
if(!mrs[i].live){
|
||||||
mrs[i] = mrs[mrs.length - 1];
|
mrs[i] = mrs[mrs.length - 1];
|
||||||
mrs = (LiveMethodRelay[])shorten(mrs);
|
mrs = (LiveMethodRelay[])shorten(mrs);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ class B12Digit{
|
|||||||
|
|
||||||
B12Digit(int _value){
|
B12Digit(int _value){
|
||||||
if(_value >= 12 || _value < 0){
|
if(_value >= 12 || _value < 0){
|
||||||
throw new IllegalArgumentException("B12Digit only accepts decimal integers 0 through 11");
|
throw new IllegalArgumentException("B12Digit only accepts decimal integers 0 through 11 -- " + _value);
|
||||||
}
|
}
|
||||||
value = byte(_value);
|
value = byte(_value);
|
||||||
refPos = new PVector(0,0);
|
refPos = new PVector(0,0);
|
||||||
@@ -32,6 +32,7 @@ class B12Digit{
|
|||||||
translate(refPos.x,refPos.y);
|
translate(refPos.x,refPos.y);
|
||||||
strokeWeight(1);
|
strokeWeight(1);
|
||||||
noFill();
|
noFill();
|
||||||
|
stroke(1);
|
||||||
ellipseMode(CORNERS);
|
ellipseMode(CORNERS);
|
||||||
switch(value) {
|
switch(value) {
|
||||||
// NUMBERS //
|
// NUMBERS //
|
||||||
|
|||||||
@@ -28,17 +28,25 @@
|
|||||||
to be fine with simply swithing out the reference.
|
to be fine with simply swithing out the reference.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
float scale = 2;
|
||||||
|
PVector offset;
|
||||||
|
float sMouseX;
|
||||||
|
float sMouseY;
|
||||||
public static final int DECIMAL = 65;
|
public static final int DECIMAL = 65;
|
||||||
ClickHandler ch; // Mouse event handler
|
ClickHandler ch; // Mouse event handler
|
||||||
|
|
||||||
Clock clock; //<>//
|
Clock clock; //<>//
|
||||||
B12Digit p;
|
B12Digit p;
|
||||||
B12Digit t;
|
B12Digit t;
|
||||||
|
MathPad m;
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
size(400,400);
|
size(400,400);
|
||||||
|
offset = new PVector(width/2, height/2);
|
||||||
ch = new ClickHandler();
|
ch = new ClickHandler();
|
||||||
|
|
||||||
|
m = new MathPad(ch,new B12Math());
|
||||||
|
|
||||||
clock = new Clock(new STime48());
|
clock = new Clock(new STime48());
|
||||||
println("waiting");
|
println("waiting");
|
||||||
p = new B12Digit('+');
|
p = new B12Digit('+');
|
||||||
@@ -47,19 +55,23 @@ void setup(){
|
|||||||
|
|
||||||
void draw(){
|
void draw(){
|
||||||
background(196);
|
background(196);
|
||||||
translate(width/2,height/2);
|
sMouseX = (mouseX - offset.x)/scale;
|
||||||
scale(2);
|
sMouseY = (mouseY - offset.y)/scale;
|
||||||
|
translate(offset.x,offset.y);
|
||||||
|
scale(scale);
|
||||||
point(0,0);
|
point(0,0);
|
||||||
|
m.display();
|
||||||
clock.display();
|
clock.display();
|
||||||
//p.display();
|
//p.display();
|
||||||
t.display();
|
t.display();
|
||||||
|
//println( + " " + ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseClicked(){
|
void mouseClicked(){
|
||||||
//clock.setTime(new Time48(16,0,0));
|
//clock.setTime(new Time48(16,0,0));
|
||||||
|
|
||||||
// Every clickable element needs check whether the mouse is over it every frame, and if both clicked and mouseover then do action.
|
// Every clickable element needs check whether the mouse is over it every frame, and if both clicked and mouseover then do action.
|
||||||
ch.cascade(mouseX,mouseY);
|
ch.cascade(sMouseX, sMouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void call(String _call){
|
void call(String _call){
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ 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;
|
||||||
boolean mouseOver;
|
boolean mouseOver;
|
||||||
|
|
||||||
Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius){
|
Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius){
|
||||||
@@ -28,6 +29,7 @@ class Button{
|
|||||||
float getRadius(){return radius;}
|
float getRadius(){return radius;}
|
||||||
color getColor(){return col;}
|
color getColor(){return col;}
|
||||||
color getHighlight(){return highlight;}
|
color getHighlight(){return highlight;}
|
||||||
|
MethodRelay getFunction(){return function;}
|
||||||
int getMode(){return mode; }
|
int getMode(){return mode; }
|
||||||
|
|
||||||
// SETTERS //
|
// SETTERS //
|
||||||
@@ -36,6 +38,7 @@ 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 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){
|
||||||
@@ -47,8 +50,9 @@ class Button{
|
|||||||
|
|
||||||
// DISPLAY //
|
// DISPLAY //
|
||||||
void display(){
|
void display(){
|
||||||
|
noStroke();
|
||||||
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(sMouseX,sMouseY);
|
||||||
fill(mouseOver ? highlight : col);
|
fill(mouseOver ? highlight : col);
|
||||||
rect(pos.x,pos.y,dim.x,dim.y,radius);
|
rect(pos.x,pos.y,dim.x,dim.y,radius);
|
||||||
}
|
}
|
||||||
@@ -65,7 +69,7 @@ class 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
|
||||||
//println("CORNER");
|
//println("CORNER");
|
||||||
if(x < pos.x || x > dim.x + pos.x || y < pos.x || y > dim.y + pos.y)
|
if(x < pos.x || x > pos.x + dim.x || y < pos.y || y > dim.y + pos.y)
|
||||||
{
|
{
|
||||||
mouseOver = false;
|
mouseOver = false;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,10 +1,24 @@
|
|||||||
class MathPad{
|
class MathPad{
|
||||||
B12Math math;
|
B12Math math;
|
||||||
|
ClickHandler ch;
|
||||||
|
B12Button[] buttons;
|
||||||
|
PVector pos;
|
||||||
|
|
||||||
MathPad(B12Math _math){
|
MathPad(ClickHandler _ch, B12Math _math){
|
||||||
math = _math;
|
math = _math;
|
||||||
|
ch = _ch;
|
||||||
|
pos = new PVector(0,0);
|
||||||
|
buttons = new B12Button[12];
|
||||||
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initialize(){
|
||||||
|
int count = 11;
|
||||||
|
for(int i = 0; i < 12; 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].setColor(220,150);
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO draw a grid for buttons
|
// TODO draw a grid for buttons
|
||||||
// TODO draw characters in grid
|
// TODO draw characters in grid
|
||||||
// TODO detect mousepresses on the buttons (maybe a global mouse handler?)
|
// TODO detect mousepresses on the buttons (maybe a global mouse handler?)
|
||||||
@@ -14,5 +28,47 @@ class MathPad{
|
|||||||
//math.expression.add(new B12Char('/'));
|
//math.expression.add(new B12Char('/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void display(){
|
||||||
|
pushMatrix();
|
||||||
|
translate(pos.x,pos.y);
|
||||||
|
for(int i = 0; i < 12; i++){
|
||||||
|
buttons[i].display();
|
||||||
|
}
|
||||||
|
popMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class B12Button extends Button{
|
||||||
|
B12Digit digit;
|
||||||
|
|
||||||
|
B12Button(ClickHandler _ch, PVector _pos, PVector _dim, float _radius, B12Digit _digit){
|
||||||
|
super(_ch,_pos,_dim,_radius);
|
||||||
|
digit = _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 display(){
|
||||||
|
super.display(); //<>//
|
||||||
|
//new MethodRelay(this, "mouseOver" + str(mode), float.class, float.class).execute(mouseX,mouseY);
|
||||||
|
|
||||||
|
pushMatrix();
|
||||||
|
|
||||||
|
translate(pos.x,pos.y);
|
||||||
|
switch(mode){
|
||||||
|
case CORNER: digit.setRefPos(dim.x/2 - 4,dim.y - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
digit.display();
|
||||||
|
|
||||||
|
popMatrix();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user