change behavior with a clear distinction
If no modifier key is used the zoombar acts as a scroll bar. If ctrl is used it modifies the zoom level, shift is a speed modifier
This commit is contained in:
parent
bd0629301b
commit
24890f9bbb
|
@ -205,7 +205,7 @@ public class WaveformView implements IWaveformView {
|
||||||
long endTime = waveformCanvas.getTimeForOffset(end.x);
|
long endTime = waveformCanvas.getTimeForOffset(end.x);
|
||||||
if(startTime<endTime) {
|
if(startTime<endTime) {
|
||||||
waveformCanvas.setVisibleRange(startTime, endTime);
|
waveformCanvas.setVisibleRange(startTime, endTime);
|
||||||
} else {
|
} else if(start.x!=end.x){
|
||||||
long targetTimeRange = startTime-endTime;
|
long targetTimeRange = startTime-endTime;
|
||||||
long currentTimeRange = waveformCanvas.getMaxVisibleTime() - waveformCanvas.getMinVisibleTime();
|
long currentTimeRange = waveformCanvas.getMaxVisibleTime() - waveformCanvas.getMinVisibleTime();
|
||||||
long factor = currentTimeRange/targetTimeRange *waveformCanvas.getScale();
|
long factor = currentTimeRange/targetTimeRange *waveformCanvas.getScale();
|
||||||
|
|
|
@ -96,8 +96,10 @@ public class RangeSlider extends Canvas {
|
||||||
addListener(SWT.MouseDown, e -> {
|
addListener(SWT.MouseDown, e -> {
|
||||||
if (e.button == 1) {
|
if (e.button == 1) {
|
||||||
selectKnobs(e);
|
selectKnobs(e);
|
||||||
if (upperHover || lowerHover) {
|
selectedElement = (lowerHover ? LOWER : NONE) | (upperHover ? UPPER : NONE);
|
||||||
selectedElement = (lowerHover ? LOWER : NONE) + (upperHover ? UPPER : NONE);
|
if (selectedElement!=NONE) {
|
||||||
|
if((e.stateMask & SWT.CTRL)==0)
|
||||||
|
selectedElement=BOTH;
|
||||||
startDragLowerValue = previousLowerValue = lowerValue;
|
startDragLowerValue = previousLowerValue = lowerValue;
|
||||||
startDragUpperValue = previousUpperValue = upperValue;
|
startDragUpperValue = previousUpperValue = upperValue;
|
||||||
startDragPoint = new Point(e.x, e.y);
|
startDragPoint = new Point(e.x, e.y);
|
||||||
|
@ -112,6 +114,16 @@ public class RangeSlider extends Canvas {
|
||||||
super.setToolTipText(clientToolTipText);
|
super.setToolTipText(clientToolTipText);
|
||||||
selectedElement=NONE;
|
selectedElement=NONE;
|
||||||
redraw();
|
redraw();
|
||||||
|
} else {
|
||||||
|
if(e.x<coordLower.x) {
|
||||||
|
translateValues(-pageIncrement);
|
||||||
|
validateNewValues(e);
|
||||||
|
redraw();
|
||||||
|
} else if(e.x>coordUpper.x+markerWidth) {
|
||||||
|
translateValues(pageIncrement);
|
||||||
|
validateNewValues(e);
|
||||||
|
redraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -211,11 +223,8 @@ public class RangeSlider extends Canvas {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectKnobs(final Event e) {
|
private void selectKnobs(final Event e) {
|
||||||
if (coordLower == null) {
|
if (coordLower != null) {
|
||||||
return;
|
final Rectangle imgBounds = slider[0].getBounds();
|
||||||
}
|
|
||||||
final Image img = slider[0];
|
|
||||||
final Rectangle imgBounds = img.getBounds();
|
|
||||||
final int x = e.x, y = e.y;
|
final int x = e.x, y = e.y;
|
||||||
lowerHover = x >= coordLower.x && x <= coordLower.x + imgBounds.width && y >= coordLower.y && y <= coordLower.y + imgBounds.height;
|
lowerHover = x >= coordLower.x && x <= coordLower.x + imgBounds.width && y >= coordLower.y && y <= coordLower.y + imgBounds.height;
|
||||||
upperHover = ((e.stateMask & (SWT.CTRL | SWT.SHIFT)) != 0 || !lowerHover) && //
|
upperHover = ((e.stateMask & (SWT.CTRL | SWT.SHIFT)) != 0 || !lowerHover) && //
|
||||||
|
@ -226,6 +235,7 @@ public class RangeSlider extends Canvas {
|
||||||
lowerHover = upperHover = true;
|
lowerHover = upperHover = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int getCursorValue(int x, int y) {
|
private int getCursorValue(int x, int y) {
|
||||||
int value = -1;
|
int value = -1;
|
||||||
|
@ -296,14 +306,10 @@ public class RangeSlider extends Canvas {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleMouseWheel(final Event e) {
|
private void handleMouseWheel(final Event e) {
|
||||||
if (selectedElement == NONE) {
|
|
||||||
e.doit = false; // we are consuming this event
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
previousLowerValue = lowerValue;
|
previousLowerValue = lowerValue;
|
||||||
previousUpperValue = upperValue;
|
previousUpperValue = upperValue;
|
||||||
final int amount = increment * ((e.stateMask & SWT.SHIFT) != 0 ? 10 : (e.stateMask & SWT.CTRL) != 0 ? 2 : 1);
|
final int amount = Math.max(1, ((e.stateMask & SWT.SHIFT) != 0 ? (upperValue-lowerValue)/6 : (upperValue-lowerValue)/15));
|
||||||
if (selectedElement == BOTH) {
|
if ((e.stateMask&SWT.CTRL)==0) {
|
||||||
int newLower = lowerValue + e.count * amount;
|
int newLower = lowerValue + e.count * amount;
|
||||||
int newUpper = upperValue + e.count * amount;
|
int newUpper = upperValue + e.count * amount;
|
||||||
if (newUpper > maximum) {
|
if (newUpper > maximum) {
|
||||||
|
@ -315,12 +321,23 @@ public class RangeSlider extends Canvas {
|
||||||
}
|
}
|
||||||
upperValue = newUpper;
|
upperValue = newUpper;
|
||||||
lowerValue = newLower;
|
lowerValue = newLower;
|
||||||
} else if ((selectedElement & LOWER) != 0) {
|
|
||||||
lowerValue += e.count * amount;
|
|
||||||
checkLowerValue();
|
|
||||||
} else {
|
} else {
|
||||||
upperValue += e.count * amount;
|
int newLower = lowerValue + e.count * amount/2;
|
||||||
checkUpperValue();
|
int newUpper = upperValue - e.count * amount/2;
|
||||||
|
int dist = newUpper - newLower;
|
||||||
|
if (newUpper > maximum) {
|
||||||
|
newUpper = maximum;
|
||||||
|
newLower = maximum - dist;
|
||||||
|
} else if (newLower < minimum) {
|
||||||
|
newLower = minimum;
|
||||||
|
newUpper = minimum + dist;
|
||||||
|
}
|
||||||
|
if(newUpper<=newLower) {
|
||||||
|
newLower=lowerValue + (upperValue - lowerValue)/2;
|
||||||
|
newUpper=newLower+1;
|
||||||
|
}
|
||||||
|
upperValue = newUpper;
|
||||||
|
lowerValue = newLower;
|
||||||
}
|
}
|
||||||
validateNewValues(e);
|
validateNewValues(e);
|
||||||
e.doit = false; // we are consuming this event
|
e.doit = false; // we are consuming this event
|
||||||
|
|
Loading…
Reference in New Issue