mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 03:55:20 +00:00
0.1.5.3 - button update, and setter returns
Setters now universally return their object instance. This allows chaining set methods at creation. Much nicer to use now
This commit is contained in:
@@ -12,7 +12,7 @@ class MouseHandler {
|
||||
float sMouseY(){return md.sMouseY();}
|
||||
float pSMouseX(){return md.pSMouseX();}
|
||||
float pSMouseY(){return md.pSMouseY();}
|
||||
void frameUpdate(PVector offset, float scale){md.update(offset, scale); println(mrs.length + " " + millis());}
|
||||
void frameUpdate(PVector offset, float scale){md.update(offset, scale);}// println(mrs.length + " " + millis());}
|
||||
|
||||
|
||||
void addRelay(LiveMethodRelay r) {
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
abstract interface Number{
|
||||
abstract void setPos(PVector _pos);
|
||||
abstract void setPos(float _x, float _y);
|
||||
abstract PVector getPos();
|
||||
|
||||
abstract void setAlignMode(int _mode);
|
||||
abstract void display();
|
||||
}
|
||||
|
||||
class B12Digit{
|
||||
byte value;
|
||||
PVector refPos;
|
||||
private byte value;
|
||||
private PVector refPos;
|
||||
|
||||
B12Digit(int _value){
|
||||
if(_value >= 12 || _value < 0){
|
||||
@@ -27,9 +24,9 @@ class B12Digit{
|
||||
}
|
||||
|
||||
// SETTERS
|
||||
void setRefPos(PVector _refPos){ refPos = _refPos; }
|
||||
void setRefPos(float _x, float _y){ refPos = new PVector(_x,_y); }
|
||||
void setValue(int _value){ value = byte(_value); }
|
||||
B12Digit setRefPos(PVector _refPos){ refPos = _refPos; return this;}
|
||||
B12Digit setRefPos(float _x, float _y){ refPos = new PVector(_x,_y); return this;}
|
||||
B12Digit setValue(int _value){ value = byte(_value); return this;}
|
||||
|
||||
// GETTERS
|
||||
PVector getRefPos(){ return refPos; }
|
||||
@@ -88,24 +85,24 @@ class B12Digit{
|
||||
}
|
||||
|
||||
// Individual shape components to build any B12 number
|
||||
void line0(){ ellipse(0,-13,8,0); }
|
||||
void line1(){ line(6,0,9,-10); }
|
||||
void line2(){ line(3,-10,6,0); }
|
||||
void line3(){ line(0,0,3,-10); }
|
||||
void line4(){ line(9,-10,2,-13); }
|
||||
void line8(){ line(2,-13,9,-16); }
|
||||
private void line0(){ ellipse(0,-13,8,0); }
|
||||
private void line1(){ line(6,0,9,-10); }
|
||||
private void line2(){ line(3,-10,6,0); }
|
||||
private void line3(){ line(0,0,3,-10); }
|
||||
private void line4(){ line(9,-10,2,-13); }
|
||||
private void line8(){ line(2,-13,9,-16); }
|
||||
|
||||
// Individual shape components to build any B12 character
|
||||
void lineTimes(){ line(4,-7,8,-3); line(4,-3,8,-7); }
|
||||
void dotsDiv(){ point(6,-8); point(6,-2); }
|
||||
void lineMinus(){ line(3,-5,9,-5); }
|
||||
void linePlus(){ line(6,-8,6,-2); }
|
||||
void period(){ point(5,0); }
|
||||
void colon(){ point(5,-2); point(5,-8); }
|
||||
private void lineTimes(){ line(4,-7,8,-3); line(4,-3,8,-7); }
|
||||
private void dotsDiv(){ point(6,-8); point(6,-2); }
|
||||
private void lineMinus(){ line(3,-5,9,-5); }
|
||||
private void linePlus(){ line(6,-8,6,-2); }
|
||||
private void period(){ point(5,0); }
|
||||
private void colon(){ point(5,-2); point(5,-8); }
|
||||
|
||||
|
||||
// HELPER FUNCTIONS //
|
||||
boolean inStr(String st, char _c){
|
||||
private boolean inStr(String st, char _c){
|
||||
try{
|
||||
int x = st.indexOf(_c);
|
||||
return true;
|
||||
@@ -137,17 +134,17 @@ class B12Int implements Number {
|
||||
}
|
||||
|
||||
int getValue(){ return value; }
|
||||
void setValue(int _value){ value = _value; arrayLoaded = false; }
|
||||
|
||||
void setPos(PVector _pos){ pos = _pos.copy(); inPosition = false; }
|
||||
void setPos(float _x, float _y){ pos = new PVector(_x, _y); inPosition = false; }
|
||||
PVector getPos(){ return pos; }
|
||||
|
||||
void setMinLen(int i){ minLen = i; }
|
||||
|
||||
void setAlignMode(int _mode){
|
||||
B12Int setValue(int _value){ value = _value; arrayLoaded = false; return this;}
|
||||
B12Int setPos(PVector _pos){ pos = _pos.copy(); inPosition = false; return this;}
|
||||
B12Int setPos(float _x, float _y){ pos = new PVector(_x, _y); inPosition = false;return this; }
|
||||
B12Int setMinLen(int i){ minLen = i; return this;}
|
||||
B12Int setAlignMode(int _mode){
|
||||
if(_mode == DECIMAL || _mode == LEFT || _mode == RIGHT){ mode = _mode; }
|
||||
else{ println("Alignment only accepts LEFT, RIGHT, and DECIMAL"); }
|
||||
return this;
|
||||
}
|
||||
|
||||
void display(){
|
||||
@@ -223,24 +220,25 @@ class B12Float implements Number{
|
||||
}
|
||||
|
||||
float getValue(){ return value; }
|
||||
void setValue(float _value){ value = _value; arrayLoaded = false; }
|
||||
|
||||
PVector getPos(){ return pos; }
|
||||
void setPos(PVector _pos){ pos = _pos.copy(); inPosition = false; }
|
||||
void setPos(float _x, float _y){ pos = new PVector(_x, _y); inPosition = false; }
|
||||
|
||||
int getPlaces(){ return places; }
|
||||
void setPlaces(int _places){
|
||||
|
||||
|
||||
B12Float setValue(float _value){ value = _value; arrayLoaded = false; return this;}
|
||||
B12Float setPos(PVector _pos){ pos = _pos.copy(); inPosition = false;return this; }
|
||||
B12Float setPos(float _x, float _y){ pos = new PVector(_x, _y); inPosition = false;return this; }
|
||||
B12Float setPlaces(int _places){
|
||||
if(_places > 12 || _places < 0){
|
||||
throw new IllegalArgumentException("B12Float ncan only display to 12 duodecimal points");
|
||||
}else{
|
||||
places = _places;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void setAlignMode(int _mode){
|
||||
B12Float setAlignMode(int _mode){
|
||||
if(_mode == DECIMAL || _mode == LEFT || _mode == RIGHT){ mode = _mode; }
|
||||
else{ println("Alignment only accepts LEFT, RIGHT, and DECIMAL"); }
|
||||
return this;
|
||||
}
|
||||
|
||||
void display(){
|
||||
|
||||
@@ -11,8 +11,7 @@ void setup(){
|
||||
size(400,400);
|
||||
offset = new PVector(width/2, height/2);
|
||||
mh = new MouseHandler(new MouseData(offset, scale));
|
||||
b = new Button(mh, new PVector(20,-20), new PVector(20,20));
|
||||
b.setFunction(new MethodRelay(this, "changeMode"));
|
||||
b = new Button(mh, new PVector(20,-20), new PVector(40,20),2).setColor(#06BA63).autoHighlight().setText("Reset").setFunction(new MethodRelay(this, "changeMode"));
|
||||
|
||||
calc = new Calculator(mh);
|
||||
|
||||
@@ -21,11 +20,17 @@ void setup(){
|
||||
void draw(){
|
||||
background(196);
|
||||
mh.frameUpdate(offset, scale);
|
||||
stroke(0);
|
||||
strokeWeight(1);
|
||||
line(width/2,0,width/2,height);
|
||||
line(0,height/2,width,height/2);
|
||||
translate(offset.x,offset.y);
|
||||
scale(scale);
|
||||
|
||||
if(calc != null) calc.display();
|
||||
b.display();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void mouseClicked(){
|
||||
|
||||
@@ -47,28 +47,32 @@ class Time48 extends Thread{
|
||||
Time48 copy(){ return new Time48(this); }
|
||||
|
||||
// SETTERS //
|
||||
void setHour(int h){
|
||||
Time48 setHour(int h){
|
||||
if(h < 0 || h >= 24) throw new IllegalArgumentException();
|
||||
hour48 = h;
|
||||
flattenOther();
|
||||
initialized = true;
|
||||
return this;
|
||||
}
|
||||
void setMin(int m){
|
||||
Time48 setMin(int m){
|
||||
if(m < 0 || m >= 48) throw new IllegalArgumentException();
|
||||
min48 = m;
|
||||
flattenOther();
|
||||
initialized = true;
|
||||
return this;
|
||||
}
|
||||
void setSec(int s){
|
||||
Time48 setSec(int s){
|
||||
if(s < 0 || s >= 48) throw new IllegalArgumentException();
|
||||
sec48 = s;
|
||||
flattenOther();
|
||||
initialized = true;
|
||||
return this;
|
||||
}
|
||||
void setTsec(int s){ // TODO add exception
|
||||
Time48 setTsec(int s){ // TODO add exception
|
||||
tsec48 = s;
|
||||
flattenTSec();
|
||||
initialized = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
// PRIVATE FUNCTIONS //
|
||||
@@ -108,10 +112,11 @@ class STime48 extends Time48{
|
||||
|
||||
// Public sync functions
|
||||
public boolean synced(){return synced;}
|
||||
public void syncTime(){ synced = false; } // Allows syncing after time starts running
|
||||
public void setTime(Time48 _time){
|
||||
public STime48 syncTime(){ synced = false; return this; } // Allows syncing after time starts running
|
||||
public STime48 setTime(Time48 _time){
|
||||
// To get offset we subtract where the current clock is from where we want it to be
|
||||
offset = _time.b10millis() - millis() - tmillis + syncedat;
|
||||
return this;
|
||||
}
|
||||
|
||||
// Threaded code
|
||||
@@ -169,11 +174,11 @@ class Clock {
|
||||
|
||||
// GETTERS and SETTERS //
|
||||
PVector getPos() { return pos; }
|
||||
void setPos(PVector _pos) { pos = _pos.copy(); }
|
||||
void setPos(float _x, float _y) { pos = new PVector(_x, _y);}
|
||||
Clock setPos(PVector _pos) { pos = _pos.copy(); return this;}
|
||||
Clock setPos(float _x, float _y) { pos = new PVector(_x, _y);return this;}
|
||||
|
||||
void setTime(Time48 _time) { t48.setTime(_time); }
|
||||
void resetTime() { t48.setTime(new Time48(0)); }
|
||||
Clock setTime(Time48 _time) { t48.setTime(_time); return this;}
|
||||
Clock resetTime() { t48.setTime(new Time48(0)); return this;}
|
||||
|
||||
void display() {
|
||||
if (t48.synced()) {
|
||||
|
||||
@@ -8,7 +8,7 @@ class B12Expression {
|
||||
B12Digit getDigit(int index){ return expression[index]; }
|
||||
int length(){return expression.length;}
|
||||
|
||||
void setChar(int ind, B12Digit _digit){
|
||||
B12Expression setChar(int ind, B12Digit _digit){
|
||||
expression = (B12Digit[])append(expression, _digit); // Add the new digit
|
||||
if(ind < expression.length - 1){ // Swap new digit
|
||||
for(int i = expression.length - 1; i > ind; i--){ // Start at second to last digit
|
||||
@@ -16,10 +16,12 @@ class B12Expression {
|
||||
}
|
||||
expression[ind] = _digit;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
void addChar(B12Digit _digit){
|
||||
B12Expression addChar(B12Digit _digit){
|
||||
expression = (B12Digit[])append(expression, _digit);
|
||||
return this;
|
||||
}
|
||||
|
||||
void evaluate(){
|
||||
|
||||
@@ -1,24 +1,31 @@
|
||||
class Button{ // TODO make most of the attributes private
|
||||
class Button{
|
||||
private LiveMethodRelay listener;
|
||||
private MouseHandler mh;
|
||||
|
||||
private PVector pos; // Position to render from
|
||||
private PVector dim; // Second coordinate for CORNERS or len/wid for CORNER and CENTER
|
||||
private float radius; // Optional corner radius
|
||||
private int mode; // Stores rect draw mode for button
|
||||
private color col; // Stores static color
|
||||
private color highlight; // Stores mouseover color
|
||||
private String text;
|
||||
|
||||
private MethodRelay function; // Gets called when button is pressed
|
||||
private boolean mouseOver;
|
||||
private Object[] data; // Anything that gets passed to MethodRelay function when key pressed. Must be set manually
|
||||
|
||||
Button(MouseHandler _mh, PVector _pos, PVector _dim, float _radius){
|
||||
mh = _mh;
|
||||
|
||||
pos = _pos.copy();
|
||||
dim = _dim.copy();
|
||||
radius = _radius;
|
||||
mode = CORNER;
|
||||
col = color(200);
|
||||
highlight = color(100);
|
||||
colorMode(HSB);
|
||||
highlight = color(150);
|
||||
text = "";
|
||||
|
||||
mouseOver = false;
|
||||
listener = new LiveMethodRelay(this, "clicked", 'p', Object.class);
|
||||
mh.addRelay(listener);
|
||||
@@ -33,25 +40,22 @@ class Button{ // TODO make most of the attributes private
|
||||
float getRadius(){return radius;}
|
||||
color getColor(){return col;}
|
||||
color getHighlight(){return highlight;}
|
||||
String getText(){return text;}
|
||||
MethodRelay getFunction(){return function;}
|
||||
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 setFunction(MethodRelay _function){function = _function;}
|
||||
void setData(Object... _data){ data = _data; } // Data to pass for button presses. Ugh, note that the array already exists because it's passed as such, no need to create a new one. Stupid bug
|
||||
Button setRect(PVector _pos, PVector _dim){pos = _pos; dim = _dim; return this;}
|
||||
Button setRadius(float rad){radius = rad; return this;}
|
||||
Button setColor(color c){col = c; return this;}
|
||||
Button setColor(color c, color h){col = c; highlight = h; return this;}
|
||||
Button autoHighlight(){ colorMode(RGB,255); highlight = color(int(red(col) * .85), int(green(col) * .85), int(blue(col) * .85)); return this; }
|
||||
Button setHighlight(color h){ highlight = h; return this; }
|
||||
Button setText(String t){text = t; return this;}
|
||||
|
||||
void setMode(int m){
|
||||
if(m == CORNER || m == CORNERS || m == CENTER || m == RADIUS){
|
||||
mode = m;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
Button setFunction(MethodRelay _function){function = _function;return this;}
|
||||
Button setData(Object... _data){ data = _data; return this;} // Data to pass for button presses. Ugh, note that the array already exists because it's passed as such, no need to create a new one. Stupid bug
|
||||
Button setMode(int m){ if(m == CORNER || m == CORNERS || m == CENTER || m == RADIUS){mode = m;return this;} /*Otherwise*/ return this;}
|
||||
|
||||
// DISPLAY //
|
||||
void display(){
|
||||
@@ -60,14 +64,19 @@ class Button{ // TODO make most of the attributes private
|
||||
new MethodRelay(this, "mouseOver" + str(mode), float.class, float.class).execute(mh.sMouseX(),mh.sMouseY());
|
||||
fill(mouseOver ? highlight : col);
|
||||
rect(pos.x,pos.y,dim.x,dim.y,radius);
|
||||
fill(0);
|
||||
textSize(dim.y * 0.8);
|
||||
textAlign(CENTER,BOTTOM);
|
||||
text(text,pos.x + dim.x/2,pos.y + dim.y);
|
||||
}
|
||||
|
||||
|
||||
// MOUSE FUNCTIONS //
|
||||
void clicked(Object _mp){ // mp[0] is smouseX and m[1] is smouseY
|
||||
float[] mp = (float[])_mp;
|
||||
if(mouseOver){
|
||||
println(mp[0] + " " + mp[1] + " mouse pos");
|
||||
if(mouseOver && mouseButton == LEFT){
|
||||
//println(mp[0] + " " + mp[1] + " mouse pos");
|
||||
//println(col + " : " + highlight);
|
||||
function.execute(data);
|
||||
}
|
||||
}
|
||||
@@ -75,60 +84,38 @@ class Button{ // TODO make most of the attributes private
|
||||
// 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
|
||||
//println("CORNER");
|
||||
if(x < pos.x || x > pos.x + dim.x || y < pos.y || y > dim.y + pos.y)
|
||||
{
|
||||
mouseOver = false;
|
||||
return;
|
||||
}
|
||||
mouseOver = true;
|
||||
mouseOver = !(x < pos.x || x > pos.x + dim.x || y < pos.y || y > dim.y + pos.y) ;
|
||||
}
|
||||
|
||||
void mouseOver1(float x, float y){ // CORNERS
|
||||
//println("CORNERS");
|
||||
if(x < (pos.x > dim.x ? dim.x : pos.x) ||
|
||||
mouseOver = !(x < (pos.x > dim.x ? dim.x : pos.x) ||
|
||||
x > (pos.x > dim.x ? pos.x : dim.x) ||
|
||||
y < (pos.y > dim.y ? dim.y : pos.y) ||
|
||||
y > (pos.y > dim.y ? pos.y : dim.y))
|
||||
{
|
||||
mouseOver = false;
|
||||
return;
|
||||
}
|
||||
|
||||
mouseOver = true;
|
||||
y > (pos.y > dim.y ? pos.y : dim.y));
|
||||
}
|
||||
|
||||
void mouseOver2(float x, float y){ // RADIUS
|
||||
//println("RADIUS");
|
||||
if(x < pos.x - dim.x ||
|
||||
mouseOver = !(x < pos.x - dim.x ||
|
||||
x > pos.x + dim.x ||
|
||||
y < pos.x - dim.y ||
|
||||
y > pos.x + dim.y)
|
||||
{
|
||||
mouseOver = false;
|
||||
return;
|
||||
}
|
||||
mouseOver = true;
|
||||
y > pos.x + dim.y);
|
||||
}
|
||||
|
||||
void mouseOver3(float x, float y){ // CENTER
|
||||
//println("CENTER");
|
||||
if(x < pos.x - dim.x/2 ||
|
||||
mouseOver = !(x < pos.x - dim.x/2 ||
|
||||
x > pos.x + dim.x/2 ||
|
||||
y < pos.x - dim.y/2 ||
|
||||
y > pos.y + dim.y/2)
|
||||
{
|
||||
mouseOver = false;
|
||||
return;
|
||||
}
|
||||
mouseOver = true;
|
||||
y > pos.y + dim.y/2);
|
||||
}
|
||||
|
||||
// GARBAGE COLLECTION //
|
||||
// kill the mouse listener so it will get removed from the mouse event cascade
|
||||
@Override
|
||||
protected void finalize(){
|
||||
println("finalized");
|
||||
//println("finalized");
|
||||
listener.kill();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ class MathDisplay {
|
||||
}
|
||||
|
||||
PVector getPos(){ return pos; }
|
||||
void setPos(PVector _pos){ pos = _pos; }
|
||||
MathDisplay setPos(PVector _pos){ pos = _pos; return this;}
|
||||
|
||||
void display(){
|
||||
pushMatrix();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class MathPad{
|
||||
B12Expression ex;
|
||||
MouseHandler mh;
|
||||
B12Button[] buttons;
|
||||
Button[] buttons;
|
||||
PVector pos;
|
||||
|
||||
MathPad(MouseHandler _mh, B12Expression _ex){
|
||||
@@ -14,9 +14,7 @@ class MathPad{
|
||||
|
||||
void initialize(){
|
||||
for(int i = 0; i < 12; i++){
|
||||
buttons[i] = new B12Button(mh, 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] = new B12Button(mh, new PVector(22 * int(i%4),22 * 2 - 22 * floor(i/4)), new PVector(20,20),new B12Digit(i)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +52,7 @@ class B12Button extends Button{
|
||||
|
||||
// GETTERS AND SETTERS //
|
||||
B12Digit getDigit(){ return digit; }
|
||||
void setDigit(B12Digit _digit){ digit = _digit; }
|
||||
B12Button setDigit(B12Digit _digit){ digit = _digit; return this; }
|
||||
|
||||
@Override
|
||||
void display(){
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Beta version of a clock in base 12.
|
||||
by Nayan Sawyer
|
||||
started Mar 2022
|
||||
version 0.1.5.2 April 30 2022
|
||||
version 0.1.5.3 April 30 2022
|
||||
|
||||
Characters are a variation of Kaktovik Inupiaq numerals
|
||||
reversed and in base 12 instead of 20. I take no credit
|
||||
@@ -12,7 +12,6 @@
|
||||
for more details.
|
||||
|
||||
// TODO redo position data handling
|
||||
// WORKING redo mouse handling
|
||||
// TODO add cursor and dynamic position for MathDisplay (Maybe add a "highlighted" attribute to B12Digit?) might need some restructuring
|
||||
// TODO add parsing expression to operable math string (tricky to get base 12 to base 10)
|
||||
// TODO add operator and action buttons to MathPad
|
||||
@@ -20,6 +19,12 @@
|
||||
// MAYBE start clock widget structure
|
||||
// MAYBE add additional operations like power, log, and trig functions
|
||||
|
||||
changelog 0.1.5.3
|
||||
- restricted button presses to left mouse button only.
|
||||
Updated button highlight color functionality. Updated all
|
||||
classes to return themselves from their setters. This
|
||||
allows chaining set methods on one line.
|
||||
|
||||
changelog 0.1.5.2
|
||||
- major changes to mouse handling, and MethodRelay now
|
||||
uses weak references rather than strong references so
|
||||
|
||||
Reference in New Issue
Block a user