diff --git a/B12NumbersV3/ActionCodeAll.pde b/B12NumbersV3/ActionCodeAll.pde index a9bcfde..91a5142 100644 --- a/B12NumbersV3/ActionCodeAll.pde +++ b/B12NumbersV3/ActionCodeAll.pde @@ -1,9 +1,17 @@ class MouseHandler { - LiveMethodRelay[] mrs; + MouseData md; + private LiveMethodRelay[] mrs; - MouseHandler() { + MouseHandler(MouseData _md) { + md = _md; mrs = new LiveMethodRelay[0]; } + + float sMouseX(){return md.sMouseX();} + 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);} void addRelay(LiveMethodRelay r) { clean(); @@ -30,36 +38,37 @@ class MouseHandler { } } - -//class ClickHandler { -// LiveMethodRelay[] mrs; - -// ClickHandler() { -// mrs = new LiveMethodRelay[0]; -// } - -// void addl(MethodRelay l) { -// clean(); -// mrs = (LiveMethodRelay[])append(mrs, l); -// } - -// void clean() { -// if (mrs.length == 0) return; -// for (int i = mrs.length -1; i >= 0; i--) { -// if (!mrs[i].live) { -// mrs[i] = mrs[mrs.length - 1]; -// mrs = (LiveMethodRelay[])shorten(mrs); -// } -// } -// } - -// void cascade(float x, float y) { -// for (int i = 0; i < mrs.length; i++) { -// mrs[i].execute(x, y); -// } -// } -//} - +class MouseData{ + private PVector offset; + private float scale; + private float sMouseX; + private float sMouseY; + private float pSMouseX; + private float pSMouseY; + + MouseData(PVector _offset, float _scale){ + offset = _offset; + scale = _scale; + sMouseX = (mouseX - offset.x)/scale; + sMouseY = (mouseY - offset.y)/scale; + pSMouseX = (pmouseX - offset.x)/scale; + pSMouseY = (pmouseY - offset.y)/scale; + } + + void update(PVector _offset, float _scale){ + offset = _offset; + scale = _scale; + sMouseX = (mouseX - offset.x)/scale; + sMouseY = (mouseY - offset.y)/scale; + pSMouseX = (pmouseX - offset.x)/scale; + pSMouseY = (pmouseY - offset.y)/scale; + } + + float sMouseX(){return sMouseX;} + float sMouseY(){return sMouseY;} + float pSMouseX(){return pSMouseX;} + float pSMouseY(){return pSMouseY;} +} diff --git a/B12NumbersV3/B12NumbersV3.pde b/B12NumbersV3/B12NumbersV3.pde index 1055bfd..0abb95f 100644 --- a/B12NumbersV3/B12NumbersV3.pde +++ b/B12NumbersV3/B12NumbersV3.pde @@ -1,65 +1,17 @@ -/* - B12NumbersV3 - Beta version of a clock in base 12. - by Nayan Sawyer - started Mar 2022 - version 0.1.5.0 April 30 2022 - - Characters are a variation of Kaktovik Inupiaq numerals - reversed and in base 12 instead of 20. I take no credit - for the design. - 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 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 - // TODO add parenthesis functionality - // MAYBE start clock widget structure - // MAYBE add additional operations like power, log, and trig functions - - changelog 0.1.5.0 - - Quite a few changes by this point. The readme has been - fixed, the button class has gone through many revisions - and now allows dynamic calls defined at object creation, - the MathPad now works and inputs B12Digits into a - B12Expression, MathDisplay now works and displays the - contents of a B12Expression, and many miscellaneous bugs - and inefficiencies have been fixed. I still need to get - better at version numbering, but it is slowly getting - better. - - changelog 0.1.4.0 - - Added MethodRelay code from Quark. Some fixes and - changes as well. Condesed some things into fewer files - for so the ide is easier to use, but they will be moved - back into their own files as version 1.0 approaches. - Everything is prep for adding gui elements (MethodRelay - included) - - changelog 0.1.3 - - Deprecated B12Char by rolling it's code into B12Digit. - Makes for easier to handle arrays, and will hopefully - make implementing the math functionality much easier. - It appears that only Clock may need true refactoring to - make the most of this change. B12Int and B12Float seem - to be fine with simply swithing out the reference. -*/ - +// B12NumbersV3 // float scale = 2; PVector offset; -float sMouseX; -float sMouseY; public static final int DECIMAL = 65; MouseHandler mh; // Mouse event handler +//MouseData md; -Calculator calc; //<>// +Calculator calc; void setup(){ size(400,400); offset = new PVector(width/2, height/2); - mh = new MouseHandler(); + mh = new MouseHandler(new MouseData(offset, scale)); + //md = new MouseData(offset, scale); calc = new Calculator(mh); @@ -67,8 +19,7 @@ void setup(){ void draw(){ background(196); - sMouseX = (mouseX - offset.x)/scale; - sMouseY = (mouseY - offset.y)/scale; + mh.frameUpdate(offset, scale); translate(offset.x,offset.y); scale(scale); @@ -76,11 +27,14 @@ void draw(){ } void mouseClicked(){ - //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. - mh.cascade('c', sMouseX, sMouseY); + mh.cascade('c', mh.sMouseX(), mh.sMouseY(), mouseButton); } +void mouseMoved(){mh.cascade('m', mh.sMouseX(), mh.sMouseY());} +void mousePressed(){mh.cascade('m', mh.sMouseX(), mh.sMouseY(), mouseButton);} +void mouseReleased(){mh.cascade('m', mh.sMouseX(), mh.sMouseY(), mouseButton);} +void mouseWheel(MouseEvent event){mh.cascade('m', mh.sMouseX(), mh.sMouseY(), event.getCount());} +void mouseDragged(){mh.cascade('m', mh.sMouseX(), mh.sMouseY(), mouseButton);} void call(String _call){ method(_call); diff --git a/B12NumbersV3/B12NumbersV318161774659031233896.autosave b/B12NumbersV3/B12NumbersV318161774659031233896.autosave new file mode 100644 index 0000000..7184bbe --- /dev/null +++ b/B12NumbersV3/B12NumbersV318161774659031233896.autosave @@ -0,0 +1,70 @@ +/* + B12NumbersV3 + Beta version of a clock in base 12. + by Nayan Sawyer + started Mar 2022 + version 0.1.4.3 April 30 2022 + + Characters are a variation of Kaktovik Inupiaq numerals + reversed and in base 12 instead of 20. I take no credit + for the design. + 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. + + changelog 0.1.4.0 + - Added MethodRelay code from Quark. Some fixes and + changes as well. Condesed some things into fewer files + for so the ide is easier to use, but they will be moved + back into their own files as version 1.0 approaches. + Everything is prep for adding gui elements (MethodRelay + included) + + changelog 0.1.3 + - Deprecated B12Char by rolling it's code into B12Digit. + Makes for easier to handle arrays, and will hopefully + make implementing the math functionality much easier. + It appears that only Clock may need true refactoring to + make the most of this change. B12Int and B12Float seem + to be fine with simply swithing out the reference. +*/ + +float scale = 2; +PVector offset; +float sMouseX; +float sMouseY; +public static final int DECIMAL = 65; +ClickHandler ch; // Mouse event handler + +Calculator calc; ///blblblblb //<>// + +void setup(){ + size(400,400); + offset = new PVector(width/2, height/2); + ch = new ClickHandler(); + +} + +void draw(){ + background(196); + sMouseX = (mouseX - offset.x)/scale; + sMouseY = (mouseY - offset.y)/scale; + translate(offset.x,offset.y); + scale(scale); + point(0,0); + m.display(); + clock.display(); + //p.display(); + t.display(); + //println( + " " + ; +} + +void mouseClicked(){ + //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. + ch.cascade(sMouseX, sMouseY); +} + +void call(String _call){ + method(_call); +} diff --git a/B12NumbersV3/guiB12Math.pde b/B12NumbersV3/guiB12Math.pde new file mode 100644 index 0000000..7a96bbd --- /dev/null +++ b/B12NumbersV3/guiB12Math.pde @@ -0,0 +1,15 @@ +class B12Math { + ArrayList expression; + + B12Math(){ + expression = new ArrayList();; + } + + void delete(int pos){ + expression.remove(pos); + } + + void evaluate(){ + //TODO set expression to evaluation of expression + } +} diff --git a/B12NumbersV3/guiButton.pde b/B12NumbersV3/guiButton.pde index 88a88d6..fadd91b 100644 --- a/B12NumbersV3/guiButton.pde +++ b/B12NumbersV3/guiButton.pde @@ -19,7 +19,7 @@ class Button{ // TODO make most of the attributes private col = color(200); highlight = color(100); mouseOver = false; - mh.addRelay(new LiveMethodRelay(this, "clicked", 'c', Class.class)); + mh.addRelay(new LiveMethodRelay(this, "clicked", 'c', Object.class)); data = null; } Button(MouseHandler _mh, PVector _pos, PVector _dim){ @@ -55,15 +55,15 @@ class Button{ // TODO make most of the attributes private void display(){ noStroke(); rectMode(mode); - new MethodRelay(this, "mouseOver" + str(mode), float.class, float.class).execute(sMouseX,sMouseY); + 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); } // MOUSE FUNCTIONS // - void clicked(Class mp){ // mp[0] is smouseX and m[1] is smouseY - float[] _mp = float(mp); + 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"); function.execute(data); diff --git a/B12NumbersV3/guiCalculator.pde b/B12NumbersV3/guiCalculator.pde index 023226d..0cac130 100644 --- a/B12NumbersV3/guiCalculator.pde +++ b/B12NumbersV3/guiCalculator.pde @@ -5,7 +5,7 @@ class Calculator{ Calculator(MouseHandler _mh){ ex = new B12Expression(); - m = new MathPad(_mh,ex); + m = new MathPad(_mh, ex); d = new MathDisplay(ex); } diff --git a/B12NumbersV3/zchangelog.pde b/B12NumbersV3/zchangelog.pde new file mode 100644 index 0000000..00ec12e --- /dev/null +++ b/B12NumbersV3/zchangelog.pde @@ -0,0 +1,51 @@ +/* + B12NumbersV3 + Beta version of a clock in base 12. + by Nayan Sawyer + started Mar 2022 + version 0.1.5.2 April 30 2022 + + Characters are a variation of Kaktovik Inupiaq numerals + reversed and in base 12 instead of 20. I take no credit + for the design. + 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 redo mouse handling -- in progress + // 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 + // MAYBE start clock widget structure + // MAYBE add additional operations like power, log, and trig functions + + changelog 0.1.5.2 + - major changes to mouse handling + + changelog 0.1.5.0 + - Quite a few changes by this point. The readme has been + fixed, the button class has gone through many revisions + and now allows dynamic calls defined at object creation, + the MathPad now works and inputs B12Digits into a + B12Expression, MathDisplay now works and displays the + contents of a B12Expression, and many miscellaneous bugs + and inefficiencies have been fixed. I still need to get + better at version numbering, but it is slowly getting + better. + + changelog 0.1.4.0 + - Added MethodRelay code from Quark. Some fixes and + changes as well. Condesed some things into fewer files + for so the ide is easier to use, but they will be moved + back into their own files as version 1.0 approaches. + Everything is prep for adding gui elements (MethodRelay + included) + + changelog 0.1.3 + - Deprecated B12Char by rolling it's code into B12Digit. + Makes for easier to handle arrays, and will hopefully + make implementing the math functionality much easier. + It appears that only Clock may need true refactoring to + make the most of this change. B12Int and B12Float seem + to be fine with simply swithing out the reference. +*/