Commit d1b49287 authored by Nico Mack's avatar Nico Mack

Minor improvements to handling of presets. Minor optimizations

parent b7d824d8
......@@ -16,6 +16,7 @@ import com.google.common.collect.TreeMultimap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -31,9 +32,9 @@ public class SelectorWidget extends ValueWidget {
protected int currentPosition = NONE;
protected int presetPosition = NONE;
protected float presetAngleOffset = 0;
protected boolean isPersistent = false;
private double segmentSpan;
private List<ValueRange<Double>> segmentSpans;
// ***************************************************************************
// * Constants *
......@@ -62,7 +63,6 @@ public class SelectorWidget extends ValueWidget {
this.presetPosition = builder.preselect;
this.buildFromProperties();
}
// ---------------------------------------------------------------------------
......@@ -90,24 +90,44 @@ public class SelectorWidget extends ValueWidget {
// ---------------------------------------------------------------------------
private void buildFromProperties() {
double overallSpan = (withStopAngles) ? Math.toRadians(upperStopAngle - lowerStopAngle) : AngleUtils.TWO_PI;
double overallSpan = (withStopAngles) ? (upperStopAngle - lowerStopAngle) : AngleUtils.TWO_PI;
segmentSpan = overallSpan / numberOfPositions;
segmentSpans = new ArrayList<>(numberOfPositions);
for (int position = 0; position < numberOfPositions; position++) {
segmentSpans.add(buildSegmentSpan(position));
}
if (presetPosition != NONE) {
this.initialValue = presetPosition;
this.selectPosition(presetPosition);
}
}
// ---------------------------------------------------------------------------
private ValueRange<Double> buildSegmentSpan(int position) {
double lower = 0;
double upper = 0;
lower = (position - 0.5) * segmentSpan;
upper = (position + 0.5) * segmentSpan;
if (withStopAngles) {
lower += lowerStopAngle;
upper += lowerStopAngle;
}
return new ValueRange<>(lower, upper);
}
// ---------------------------------------------------------------------------
protected int getNumberOfPositions() {
List<SelectableCorona> selectableCoronas = getCoronas(SelectableCorona.class);
Multimap<Integer, SelectableCorona> alreadySeen = TreeMultimap.create();
boolean duplicateIndices = false;
for (SelectableCorona corona : selectableCoronas) {
Integer index = corona.getIndex();
if (alreadySeen.containsKey(index)) {
......@@ -135,19 +155,7 @@ public class SelectorWidget extends ValueWidget {
// ---------------------------------------------------------------------------
protected ValueRange<Double> getSegmentSpan(int position) {
double lower = 0;
double upper = 0;
if (withStopAngles) {
lower = (lowerStopAngle + (segmentSpan * position));
upper = (lowerStopAngle + (segmentSpan * (position + 1)));
} else {
lower = (position - 0.5) * segmentSpan;
upper = (position + 0.5) * segmentSpan;
}
return new ValueRange<>(lower, upper);
return segmentSpans.get(position);
}
// ---------------------------------------------------------------------------
......@@ -253,17 +261,14 @@ public class SelectorWidget extends ValueWidget {
@Override
public void actionMove(TangibleObject tuioObject) {
double angle = AngleUtils.moduloTwoPi(tuioObject.getAngle() + presetAngleOffset);
TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), (float) angle));
super.actionMove(clone);
super.actionMove(tuioObject);
int widgetId = tuioObject.getObjectId();
StateManager manager = objectStates.get(widgetId);
if (manager.isRotating()) {
int position = getCurrentPosition(clone.getAngle());
int position = getCurrentPosition((float) this.dialAngle);
if (position != currentPosition) {
this.selectPosition(position);
}
......@@ -285,10 +290,7 @@ public class SelectorWidget extends ValueWidget {
isPersistent = this.isPersistent(tuioObject.getObjectId());
int position = (isPersistent) ? currentPosition : presetPosition;
presetAngleOffset = (isPersistent) ? (float) AngleUtils.moduloTwoPi(this.getCurrentAngle(position) - tuioObject.getAngle()) : 0;
TangibleObject clone = tuioObject.constrainedClone(new Point(tuioObject.getX(), tuioObject.getY(), presetAngleOffset));
super.actionDrop(clone);
super.actionDrop(tuioObject);
this.selectPosition(position);
}
......
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