fix fit zoom level calculation

This commit is contained in:
Eyck Jentzsch 2021-03-25 21:07:05 +00:00
parent b75018239a
commit 22b46e0525
2 changed files with 24 additions and 27 deletions

View File

@ -179,8 +179,11 @@ public class WaveformCanvas extends Canvas {
}
public void setZoomLevel(int level, long centerTime) {
if(level<0) {
level = findFitZoomLevel();
if(level<0) level = 0;
}
//FIXME: keep center if zoom-out and cursor is not in view
if(level<0) level = 0;
long xc=centerTime/this.scaleFactor; // cursor total x-offset
if(level<Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length){
this.scaleFactor = (long) Math.pow(10, level>>1);
@ -208,6 +211,24 @@ public class WaveformCanvas extends Canvas {
}
}
private int findFitZoomLevel() {
//get area actually capable of displaying data, i.e. area of the receiver which is capable of displaying data
Rectangle clientArea = getClientArea();
long clientAreaWidth = clientArea.width;
//try to find existing zoomlevel where scaleFactor*clientAreaWidth >= maxTime, if one is found set it as new zoomlevel
int magnitude_factor=1;
for(int magnitude=0; magnitude<Constants.UNIT_STRING.length; magnitude++) {
for (int multiplier=0; multiplier<Constants.UNIT_MULTIPLIER.length; multiplier++){
int tempLevel = magnitude*Constants.UNIT_MULTIPLIER.length+multiplier;
long scaleFactor = Constants.UNIT_MULTIPLIER[multiplier]*magnitude_factor;
if(scaleFactor*clientAreaWidth >= maxTime)
return tempLevel;
}
magnitude_factor*=1000;
}
return -1;
}
public long getScaleFactor() {
return scaleFactor;
}

View File

@ -570,6 +570,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
(result.isMultiStatus() && result.getChildren().length > 0 && result.getChildren()[0].getCode() != Status.OK_STATUS.getCode() ) ){
// kill editor and pop up warning for user
sync.asyncExec(() -> {
if(myParent.isDisposed()) return;
final Display display = myParent.getDisplay();
MessageDialog.openWarning(display.getActiveShell(), "Error loading database", "Database cannot be loaded. Aborting...");
ePartService.hidePart(myPart, true);
@ -1026,32 +1027,7 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
* Sets the zoom fit.
*/
public void setZoomFit() {
//actual max time of signal
long maxTime = waveformPane.getMaxTime();
//get area actually capable of displaying data, i.e. area of the receiver which is capable of displaying data
Rectangle clientArea = myParent.getClientArea();
long clientAreaWidth = clientArea.width;
boolean foundZoom=false;
//try to find existing zoomlevel where scaleFactor*clientAreaWidth >= maxTime, if one is found set it as new zoomlevel
int magnitude_factor=1;
for(int magnitude=0; magnitude<Constants.UNIT_STRING.length; magnitude++) {
for (int multiplier=0; multiplier<Constants.UNIT_MULTIPLIER.length; multiplier++){
int level = magnitude*Constants.UNIT_MULTIPLIER.length+multiplier;
long scaleFactor = Constants.UNIT_MULTIPLIER[multiplier]*magnitude_factor;
if(scaleFactor*clientAreaWidth >= maxTime) {
setZoomLevel(level);
foundZoom=true;
break;
}
}
if(foundZoom) break;
magnitude_factor*=1000;
}
//if no zoom level is found, set biggest one available
if(!foundZoom) setZoomLevel(Constants.UNIT_MULTIPLIER.length*Constants.UNIT_STRING.length-1);
waveformPane.setZoomLevel(-1);
updateAll();
}