From 534abc229c8a6feaee00cc6db6e167a8e147d222 Mon Sep 17 00:00:00 2001 From: 61616 Date: Thu, 12 May 2022 18:08:27 -0400 Subject: [PATCH] 0.1.5.6 - MathPad complete --- B12NumbersV3/guiB12Expression.pde | 10 ++++- B12NumbersV3/guiButton.pde | 73 ++++++++++++++++++------------- B12NumbersV3/guiMathPad.pde | 5 ++- B12NumbersV3/zchangelog.pde | 17 +++---- 4 files changed, 64 insertions(+), 41 deletions(-) diff --git a/B12NumbersV3/guiB12Expression.pde b/B12NumbersV3/guiB12Expression.pde index 88741b4..be84923 100644 --- a/B12NumbersV3/guiB12Expression.pde +++ b/B12NumbersV3/guiB12Expression.pde @@ -5,9 +5,11 @@ class B12Expression { expression = new B12Digit[0]; } + // GETTERS // B12Digit getDigit(int index){ return expression[index]; } int length(){return expression.length;} + // SETTERS // B12Expression insertChar(int ind, B12Digit _digit){ expression = (B12Digit[])append(expression, _digit); // Add the new digit if(ind < expression.length - 1){ // Swap new digit @@ -18,14 +20,18 @@ class B12Expression { } return this; } - B12Expression addChar(B12Digit _digit){ expression = (B12Digit[])append(expression, _digit); return this; } + B12Expression delete(){ + expression = (B12Digit[])shorten(expression); + return this; + } - void clear(){ + B12Expression clear(){ expression = new B12Digit[0]; + return this; } void evaluate(){ diff --git a/B12NumbersV3/guiButton.pde b/B12NumbersV3/guiButton.pde index 82cdac2..91b962d 100644 --- a/B12NumbersV3/guiButton.pde +++ b/B12NumbersV3/guiButton.pde @@ -9,6 +9,9 @@ class Button{ private color col; // Stores static color private color highlight; // Stores mouseover color private String text; + private float textSize; + private color textColor; + private int renderPriority; // 0: default, render text size within button size 1: render button around text private MethodRelay function; // Gets called when button is pressed private boolean mouseOver; @@ -25,6 +28,9 @@ class Button{ colorMode(HSB); highlight = color(150); text = ""; + textSize = dim.y * 0.8; + textColor = 0; + renderPriority = 0; mouseOver = false; listener = new LiveMethodRelay(this, "clicked", 'p', Object.class); @@ -38,8 +44,10 @@ class Button{ color getColor(){return col;} color getHighlight(){return highlight;} String getText(){return text;} + color getTextColor(){return textColor;} MethodRelay getFunction(){return function;} int getMode(){return mode; } + int getRenderPriority(){return renderPriority;} // SETTERS // Button setPos(PVector _pos){pos = _pos.copy(); return this;} @@ -52,6 +60,9 @@ class Button{ 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;} + Button setTextSize(float s){textSize = s; return this;} // TODO make robust + Button setTextColor(color c){textColor = c; return this;} + Button setRenderPriority(int p){if(p < 0 || p > 1) throw new IllegalArgumentException(); renderPriority = p; return this;} 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 @@ -59,13 +70,21 @@ class Button{ // DISPLAY // void display(){ + mouseOver(mh.sMouseX(),mh.sMouseY()); noStroke(); rectMode(mode); - 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); + + //stroke(textColor); fix this + textSize(textSize); + if(renderPriority == 0){ + while(textWidth(text) > dim.x * 0.95){ // WARNING! NOT ROBUST make this a function at some point to allow other rectModes to render properly + textSize = textSize - 1; + textSize(textSize); + } + } + //textSize(dim.y * 0.8); textAlign(CENTER,BOTTOM); text(text,pos.x + dim.x/2,pos.y + dim.y); } @@ -81,33 +100,27 @@ class 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 - void mouseOver0(float x, float y){ // CORNER - 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"); - 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)); - } - - void mouseOver2(float x, float y){ // RADIUS - //println("RADIUS"); - mouseOver = !(x < pos.x - dim.x || - x > pos.x + dim.x || - y < pos.x - dim.y || - y > pos.x + dim.y); - } - - void mouseOver3(float x, float y){ // CENTER - //println("CENTER"); - 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); + // Must account for rect render mode + void mouseOver(float x, float y){ // CORNER + switch(mode){ + case 0: + mouseOver = !(x < pos.x || x > pos.x + dim.x || y < pos.y || y > dim.y + pos.y); break; + case 1: + 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)); break; + case 2: + mouseOver = !(x < pos.x - dim.x || + x > pos.x + dim.x || + y < pos.x - dim.y || + y > pos.x + dim.y); break; + case 3: + 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); break; + } } // GARBAGE COLLECTION // diff --git a/B12NumbersV3/guiMathPad.pde b/B12NumbersV3/guiMathPad.pde index 90566eb..a3fe74a 100644 --- a/B12NumbersV3/guiMathPad.pde +++ b/B12NumbersV3/guiMathPad.pde @@ -8,7 +8,7 @@ class MathPad{ ex = _ex; mh = _mh; pos = new PVector(0,0); - buttons = new B12Button[12]; + buttons = new Button[12]; initialize(); } @@ -31,6 +31,9 @@ class MathPad{ buttons = (Button[])append(buttons, new B12Button(mh, new B12Digit('*')).setPos(new PVector(pos.x + 22*4,pos.y)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150)); buttons = (Button[])append(buttons, new B12Button(mh, new B12Digit('/')).setPos(new PVector(pos.x + 22*4,pos.y + 22)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150)); buttons = (Button[])append(buttons, new B12Button(mh, new B12Digit('.')).setPos(new PVector(pos.x + 22*4,pos.y + 22*2)).setFunction(new MethodRelay(this, "addChar", B12Digit.class)).setColor(220,150)); + buttons = (Button[])append(buttons, new Button(mh).setText("Enter").setPos(new PVector(pos.x + 22*4,pos.y + 22*3)).setDim(new PVector(42,20)).setFunction(new MethodRelay(this.ex, "evaluate")).setColor(220,150)); //<>// + buttons = (Button[])append(buttons, new Button(mh).setText("Cl").setPos(new PVector(pos.x + 22*5,pos.y + 22)).setDim(new PVector(20,42)).setFunction(new MethodRelay(this.ex, "clear")).setColor(220,150)); + buttons = (Button[])append(buttons, new Button(mh).setText("Del").setPos(new PVector(pos.x + 22*5,pos.y)).setDim(new PVector(20,20)).setFunction(new MethodRelay(this.ex, "delete")).setColor(220,150)); } // DONE send characters to display diff --git a/B12NumbersV3/zchangelog.pde b/B12NumbersV3/zchangelog.pde index c131488..02366ed 100644 --- a/B12NumbersV3/zchangelog.pde +++ b/B12NumbersV3/zchangelog.pde @@ -3,7 +3,7 @@ Beta version of a clock in base 12. by Nayan Sawyer started Mar 2022 - version 0.1.5.5 April 30 2022 + version 0.1.5.6 April 30 2022 Characters are a variation of Kaktovik Inupiaq numerals reversed and in base 12 instead of 20. I take no credit @@ -11,16 +11,17 @@ Includes method relay code be Quark - see https://forum.processing.org/two/discussion/13093/how-to-call-function-by-string-content.html for more details. - // TODO add addition method to number interface as well as B12Int and B12Float - // TODO change zero character - // TODO redo position data 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 - // TODO add parenthesis functionality + // TODO add actual math evaluation to B12Expression + // TODO finalize calculator design // MAYBE start clock widget structure // MAYBE add additional operations like power, log, and trig functions + changelog 0.1.5.6 + - MathPad complete. Changed internal button mouseOver code + from MethodRelay to switch statement. Added delete + functionality to B12Expression. Improved but did not + finish button text features. + changelog 0.1.5.5 - finished parsing input array to string in B12Expression. Added parenthesis chars to B12Digit and changed 0 char.