mirror of
https://github.com/opus-tango/B12NumbersV3.git
synced 2026-03-20 03:55:20 +00:00
Changes to mouse handling
This commit is contained in:
@@ -1,10 +1,18 @@
|
|||||||
class MouseHandler {
|
class MouseHandler {
|
||||||
LiveMethodRelay[] mrs;
|
MouseData md;
|
||||||
|
private LiveMethodRelay[] mrs;
|
||||||
|
|
||||||
MouseHandler() {
|
MouseHandler(MouseData _md) {
|
||||||
|
md = _md;
|
||||||
mrs = new LiveMethodRelay[0];
|
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) {
|
void addRelay(LiveMethodRelay r) {
|
||||||
clean();
|
clean();
|
||||||
if(r.getTag() == '\0'){ throw new IllegalArgumentException("MouseHandler only accepts tagged LiveMethodRelays"); }
|
if(r.getTag() == '\0'){ throw new IllegalArgumentException("MouseHandler only accepts tagged LiveMethodRelays"); }
|
||||||
@@ -30,36 +38,37 @@ class MouseHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MouseData{
|
||||||
|
private PVector offset;
|
||||||
|
private float scale;
|
||||||
|
private float sMouseX;
|
||||||
|
private float sMouseY;
|
||||||
|
private float pSMouseX;
|
||||||
|
private float pSMouseY;
|
||||||
|
|
||||||
//class ClickHandler {
|
MouseData(PVector _offset, float _scale){
|
||||||
// LiveMethodRelay[] mrs;
|
offset = _offset;
|
||||||
|
scale = _scale;
|
||||||
|
sMouseX = (mouseX - offset.x)/scale;
|
||||||
|
sMouseY = (mouseY - offset.y)/scale;
|
||||||
|
pSMouseX = (pmouseX - offset.x)/scale;
|
||||||
|
pSMouseY = (pmouseY - offset.y)/scale;
|
||||||
|
}
|
||||||
|
|
||||||
// ClickHandler() {
|
void update(PVector _offset, float _scale){
|
||||||
// mrs = new LiveMethodRelay[0];
|
offset = _offset;
|
||||||
// }
|
scale = _scale;
|
||||||
|
sMouseX = (mouseX - offset.x)/scale;
|
||||||
// void addl(MethodRelay l) {
|
sMouseY = (mouseY - offset.y)/scale;
|
||||||
// clean();
|
pSMouseX = (pmouseX - offset.x)/scale;
|
||||||
// mrs = (LiveMethodRelay[])append(mrs, l);
|
pSMouseY = (pmouseY - offset.y)/scale;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
float sMouseX(){return sMouseX;}
|
||||||
|
float sMouseY(){return sMouseY;}
|
||||||
|
float pSMouseX(){return pSMouseX;}
|
||||||
|
float pSMouseY(){return pSMouseY;}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,65 +1,17 @@
|
|||||||
/*
|
// B12NumbersV3 //
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
float scale = 2;
|
float scale = 2;
|
||||||
PVector offset;
|
PVector offset;
|
||||||
float sMouseX;
|
|
||||||
float sMouseY;
|
|
||||||
public static final int DECIMAL = 65;
|
public static final int DECIMAL = 65;
|
||||||
MouseHandler mh; // Mouse event handler
|
MouseHandler mh; // Mouse event handler
|
||||||
|
//MouseData md;
|
||||||
|
|
||||||
Calculator calc; //<>//
|
Calculator calc;
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
size(400,400);
|
size(400,400);
|
||||||
offset = new PVector(width/2, height/2);
|
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);
|
calc = new Calculator(mh);
|
||||||
|
|
||||||
@@ -67,8 +19,7 @@ void setup(){
|
|||||||
|
|
||||||
void draw(){
|
void draw(){
|
||||||
background(196);
|
background(196);
|
||||||
sMouseX = (mouseX - offset.x)/scale;
|
mh.frameUpdate(offset, scale);
|
||||||
sMouseY = (mouseY - offset.y)/scale;
|
|
||||||
translate(offset.x,offset.y);
|
translate(offset.x,offset.y);
|
||||||
scale(scale);
|
scale(scale);
|
||||||
|
|
||||||
@@ -76,11 +27,14 @@ void draw(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mouseClicked(){
|
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.
|
// 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){
|
void call(String _call){
|
||||||
method(_call);
|
method(_call);
|
||||||
|
|||||||
70
B12NumbersV3/B12NumbersV318161774659031233896.autosave
Normal file
70
B12NumbersV3/B12NumbersV318161774659031233896.autosave
Normal file
@@ -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);
|
||||||
|
}
|
||||||
15
B12NumbersV3/guiB12Math.pde
Normal file
15
B12NumbersV3/guiB12Math.pde
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class B12Math {
|
||||||
|
ArrayList <B12Digit> expression;
|
||||||
|
|
||||||
|
B12Math(){
|
||||||
|
expression = new ArrayList<B12Digit>();;
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete(int pos){
|
||||||
|
expression.remove(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void evaluate(){
|
||||||
|
//TODO set expression to evaluation of expression
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,7 +19,7 @@ class Button{ // TODO make most of the attributes private
|
|||||||
col = color(200);
|
col = color(200);
|
||||||
highlight = color(100);
|
highlight = color(100);
|
||||||
mouseOver = false;
|
mouseOver = false;
|
||||||
mh.addRelay(new LiveMethodRelay(this, "clicked", 'c', Class.class));
|
mh.addRelay(new LiveMethodRelay(this, "clicked", 'c', Object.class));
|
||||||
data = null;
|
data = null;
|
||||||
}
|
}
|
||||||
Button(MouseHandler _mh, PVector _pos, PVector _dim){
|
Button(MouseHandler _mh, PVector _pos, PVector _dim){
|
||||||
@@ -55,15 +55,15 @@ class Button{ // TODO make most of the attributes private
|
|||||||
void display(){
|
void display(){
|
||||||
noStroke();
|
noStroke();
|
||||||
rectMode(mode);
|
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);
|
fill(mouseOver ? highlight : col);
|
||||||
rect(pos.x,pos.y,dim.x,dim.y,radius);
|
rect(pos.x,pos.y,dim.x,dim.y,radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// MOUSE FUNCTIONS //
|
// MOUSE FUNCTIONS //
|
||||||
void clicked(Class mp){ // mp[0] is smouseX and m[1] is smouseY
|
void clicked(Object _mp){ // mp[0] is smouseX and m[1] is smouseY
|
||||||
float[] _mp = float(mp);
|
float[] mp = (float[])_mp;
|
||||||
if(mouseOver){
|
if(mouseOver){
|
||||||
println(mp[0] + " " + mp[1] + " mouse pos");
|
println(mp[0] + " " + mp[1] + " mouse pos");
|
||||||
function.execute(data);
|
function.execute(data);
|
||||||
|
|||||||
51
B12NumbersV3/zchangelog.pde
Normal file
51
B12NumbersV3/zchangelog.pde
Normal file
@@ -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.
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user