Commit 66f13a5b authored by Eric Tobias's avatar Eric Tobias

Added rotation functionality to value widget

parent a6862732
......@@ -58,6 +58,12 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
/** Whether the value is dynamic, that is if it changes and is not simply triggered. */
private boolean dynamic = true;
private double stepAngle;
private double steps;
private double delta;
private double dialAngle;
/**
* Constructor setting all fields by calling the super constructor.
*
......@@ -87,6 +93,11 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
} else {
this.baseValue = Double.NaN;
}
dialAngle = lowerStopAngle;
steps = (upperBound - lowerBound + 1) / stepSize;
stepAngle = (upperStopAngle - lowerStopAngle) / steps;
delta = Double.NaN;
}
@Override
......@@ -111,16 +122,35 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
public void actionMove(TangibleObject tangibleObject) {
super.actionMove(tangibleObject);
// System.out.println("Name: " + this.name + " Variable: " + this.variable + "Position: " +
// positions.get(positions.keySet().toArray()[0]));
boolean angleChanged = false;
double angle = lowerStopAngle;
if (!modifyValueOnRotation) {
if (!modifyValueOnRotation || Float.compare(tangibleObject.getRotationSpeed(), 0f) == 0) {
return;
}
// if (Double.isNaN(delta)) {
// delta = (tangibleObject.getAngle() + Math.PI) % (2 * Math.PI);
// }
angle = (lowerStopAngle + Math.PI + tangibleObject.getAngle()) % (2 * Math.PI);
if ((angle >= lowerStopAngle) && (angle <= upperStopAngle)) {
dialAngle = angle;
}
angleChanged = true;
if (null == getPosition()) {
super.actionMove(tangibleObject.constrainedClone(new Point()));
} else {
super.actionMove(tangibleObject.constrainedClone(new Point(getPosition().x, getPosition().y, (float) dialAngle, getPosition().getState().getClass())));
}
if (angleChanged && (variable != null)) {
this.updateFromRotation(dialAngle);
}
// TODO
}
/** {@inheritDoc} */
......@@ -149,11 +179,9 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
*
* @param variable
* The value to set variable to.
* @return
*/
public TangibleNumericalVariable setVariable(TangibleNumericalVariable variable) {
public void setVariable(TangibleNumericalVariable variable) {
this.variable = variable;
return variable;
}
@SuppressWarnings("unchecked")
......@@ -166,4 +194,19 @@ public final class ValueWidget extends BaseWidget implements InformationProvider
}
super.paint(canvas);
}
private void updateFromRotation(double angle) {
double value = lowerBound + (stepSize * Math.floor(((angle - lowerStopAngle) / stepAngle)));
if (value < this.lowerBound) {
value = this.lowerBound;
}
if (value > this.upperBound) {
value = this.upperBound;
}
variable.setValue(value);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment