fix redraw issues

This commit is contained in:
Eyck Jentzsch 2020-06-20 17:58:26 +02:00
parent 230e8dcc7a
commit db1d377da6
9 changed files with 244 additions and 146 deletions

View File

@ -89,9 +89,8 @@ public class ArrowPainter implements IPainter {
deferredUpdate = true; deferredUpdate = true;
return; return;
} }
selectionOffset = waveCanvas.getXOffset();
int laneHeight = painter.getHeight() / stream.getMaxConcurrency(); int laneHeight = painter.getHeight() / stream.getMaxConcurrency();
txRectangle = new Rectangle((int) (tx.getBeginTime() / scaleFactor-waveCanvas.getXOffset()), txRectangle = new Rectangle((int) (tx.getBeginTime() / scaleFactor),
waveCanvas.rulerHeight + painter.getVerticalOffset() + laneHeight * tx.getConcurrencyIndex(), waveCanvas.rulerHeight + painter.getVerticalOffset() + laneHeight * tx.getConcurrencyIndex(),
(int) ((tx.getEndTime() - tx.getBeginTime()) / scaleFactor), laneHeight); (int) ((tx.getEndTime() - tx.getBeginTime()) / scaleFactor), laneHeight);
deriveGeom(tx.getIncomingRelations(), iRect, false); deriveGeom(tx.getIncomingRelations(), iRect, false);
@ -105,7 +104,7 @@ public class ArrowPainter implements IPainter {
ITxStream<?> stream = otherTx.getStream(); ITxStream<?> stream = otherTx.getStream();
IWaveformPainter painter = waveCanvas.wave2painterMap.get(stream); IWaveformPainter painter = waveCanvas.wave2painterMap.get(stream);
int laneHeight = painter.getHeight() / stream.getMaxConcurrency(); int laneHeight = painter.getHeight() / stream.getMaxConcurrency();
Rectangle bb = new Rectangle((int) (otherTx.getBeginTime() / scaleFactor-waveCanvas.getXOffset()), Rectangle bb = new Rectangle((int) (otherTx.getBeginTime() / scaleFactor),
waveCanvas.rulerHeight + painter.getVerticalOffset() waveCanvas.rulerHeight + painter.getVerticalOffset()
+ laneHeight * otherTx.getConcurrencyIndex(), + laneHeight * otherTx.getConcurrencyIndex(),
(int) ((otherTx.getEndTime() - otherTx.getBeginTime()) / scaleFactor), laneHeight); (int) ((otherTx.getEndTime() - otherTx.getBeginTime()) / scaleFactor), laneHeight);
@ -115,7 +114,7 @@ public class ArrowPainter implements IPainter {
} }
@Override @Override
public void paintArea(GC gc, Rectangle area) { public void paintArea(Projection proj, Rectangle clientRect) {
Color fgColor = waveCanvas.colors[WaveformColors.REL_ARROW.ordinal()]; Color fgColor = waveCanvas.colors[WaveformColors.REL_ARROW.ordinal()];
Color highliteColor = waveCanvas.colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()]; Color highliteColor = waveCanvas.colors[WaveformColors.REL_ARROW_HIGHLITE.ordinal()];
@ -124,33 +123,30 @@ public class ArrowPainter implements IPainter {
calculateGeometries(); calculateGeometries();
} }
if(txRectangle == null) return; if(txRectangle == null) return;
int correctionValue = (int)(selectionOffset - waveCanvas.getXOffset()); int correctionValue = (int)(selectionOffset);
Rectangle correctedTargetRectangle = new Rectangle(txRectangle.x+correctionValue, txRectangle.y, txRectangle.width, txRectangle.height); Rectangle correctedTargetRectangle = new Rectangle(txRectangle.x+correctionValue, txRectangle.y, txRectangle.width, txRectangle.height);
for (LinkEntry entry : iRect) { for (LinkEntry entry : iRect) {
Rectangle correctedRectangle = new Rectangle(entry.rectangle.x+correctionValue, entry.rectangle.y, entry.rectangle.width, entry.rectangle.height); Rectangle correctedRectangle = new Rectangle(entry.rectangle.x+correctionValue, entry.rectangle.y, entry.rectangle.width, entry.rectangle.height);
Point target = drawPath(gc, highlightType.equals(entry.relationType) ? highliteColor : fgColor, Point target = drawPath(proj, highlightType.equals(entry.relationType) ? highliteColor : fgColor,
correctedRectangle, correctedTargetRectangle); correctedRectangle, correctedTargetRectangle);
drawArrow(gc, target); drawArrow(proj, target);
} }
for (LinkEntry entry : oRect) { for (LinkEntry entry : oRect) {
Rectangle correctedRectangle = new Rectangle(entry.rectangle.x+correctionValue, entry.rectangle.y, entry.rectangle.width, entry.rectangle.height); Rectangle correctedRectangle = new Rectangle(entry.rectangle.x+correctionValue, entry.rectangle.y, entry.rectangle.width, entry.rectangle.height);
Point target = drawPath(gc, highlightType.equals(entry.relationType) ? highliteColor : fgColor, correctedTargetRectangle, Point target = drawPath(proj, highlightType.equals(entry.relationType) ? highliteColor : fgColor, correctedTargetRectangle,
correctedRectangle); correctedRectangle);
drawArrow(gc, target); drawArrow(proj, target);
} }
} }
protected void drawArrow(GC gc, Point target) { protected void drawArrow(Projection proj, Point target) {
gc.drawLine(target.x - 8, target.y - 5, target.x, target.y); proj.drawLine(target.x - 8, target.y - 5, target.x, target.y);
gc.drawLine(target.x - 8, target.y + 5, target.x, target.y); proj.drawLine(target.x - 8, target.y + 5, target.x, target.y);
} }
protected Point drawPath(GC gc, Color fgColor, Rectangle srcRectangle, Rectangle tgtRectangle) { protected Point drawPath(Projection proj, Color fgColor, Rectangle srcRectangle, Rectangle tgtRectangle) {
Point point1 = new Point(0, srcRectangle.y + srcRectangle.height / 2); Point point1 = proj.project(new Point(srcRectangle.x, srcRectangle.y + srcRectangle.height / 2));
Point point2 = new Point(0, tgtRectangle.y + tgtRectangle.height / 2); Point point2 = proj.project(new Point(tgtRectangle.x, tgtRectangle.y + tgtRectangle.height / 2));
point1.x = srcRectangle.x;
point2.x = tgtRectangle.x;
if (point2.x > point1.x + srcRectangle.width) if (point2.x > point1.x + srcRectangle.width)
point1.x += srcRectangle.width; point1.x += srcRectangle.width;
@ -165,9 +161,9 @@ public class ArrowPainter implements IPainter {
path.cubicTo(center.x + xCtrlOffset, center.y, point2.x - xCtrlOffset, point2.y, point2.x, point2.y); path.cubicTo(center.x + xCtrlOffset, center.y, point2.x - xCtrlOffset, point2.y, point2.x, point2.y);
} else } else
path.cubicTo(point1.x + xCtrlOffset, point1.y, point2.x - xCtrlOffset, point2.y, point2.x, point2.y); path.cubicTo(point1.x + xCtrlOffset, point1.y, point2.x - xCtrlOffset, point2.y, point2.x, point2.y);
gc.setAntialias(SWT.ON); proj.setAntialias(SWT.ON);
gc.setForeground(fgColor); proj.setForeground(fgColor);
gc.drawPath(path); proj.getGC().drawPath(path);
path.dispose(); path.dispose();
return point2; return point2;
} }

View File

@ -12,6 +12,7 @@ package com.minres.scviewer.database.swt.internal;
import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
import com.minres.scviewer.database.ui.ICursor; import com.minres.scviewer.database.ui.ICursor;
@ -62,30 +63,30 @@ public class CursorPainter implements IPainter, ICursor {
} }
public void paintArea(GC gc, Rectangle area) { public void paintArea(Projection proj, Rectangle clientRect) {
Rectangle area = proj.unProject(clientRect);
if(this.waveCanvas.painterList.size()>0){ if(this.waveCanvas.painterList.size()>0){
long scaleFactor=waveCanvas.getScaleFactor(); long scaleFactor=waveCanvas.getScaleFactor();
long beginPos = area.x; long beginPos = area.x;
maxPosX = area.x + area.width; maxPosX = area.x + area.width;
maxValX = maxPosX + (int)waveCanvas.getXOffset(); maxValX = maxPosX;
// x position of marker in pixels on canvas // x position of marker in pixels on canvas
int x = (int) (time/scaleFactor); int x = (int) (time/scaleFactor);
// distance of marker from the top of Canvas' painting area // distance of marker from the top of Canvas' painting area
int top = id<0?area.y:area.y+15; int top = id<0?area.y:area.y+15;
Color drawColor=waveCanvas.colors[id<0?WaveformColors.CURSOR.ordinal():WaveformColors.MARKER.ordinal()]; Color drawColor=waveCanvas.colors[id<0?WaveformColors.CURSOR.ordinal():WaveformColors.MARKER.ordinal()];
Color dragColor = waveCanvas.colors[WaveformColors.CURSOR_DRAG.ordinal()]; Color dragColor = waveCanvas.colors[WaveformColors.CURSOR_DRAG.ordinal()];
Color textColor=waveCanvas.colors[id<0?WaveformColors.CURSOR_TEXT.ordinal():WaveformColors.MARKER_TEXT.ordinal()]; Color textColor=waveCanvas.colors[id<0?WaveformColors.CURSOR_TEXT.ordinal():WaveformColors.MARKER_TEXT.ordinal()];
if(x>=beginPos && x<=maxValX){ if(x>=beginPos && x<=maxValX){
gc.setForeground(isDragging?dragColor:drawColor); proj.setForeground(isDragging?dragColor:drawColor);
gc.drawLine(x-(int)waveCanvas.getXOffset(), top, x-(int)waveCanvas.getXOffset(), area.y+area.height); proj.drawLine(x, top, x, area.y+area.height);
gc.setBackground(drawColor); proj.setBackground(drawColor);
gc.setForeground(textColor); proj.setForeground(textColor);
Double dTime=new Double(time); Double dTime=new Double(time);
gc.drawText((dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1-(int)waveCanvas.getXOffset(), top); proj.drawText((dTime/waveCanvas.getScaleFactorPow10())+waveCanvas.getUnitStr(), x+1, top);
} }
} }
} }

View File

@ -10,11 +10,10 @@
*******************************************************************************/ *******************************************************************************/
package com.minres.scviewer.database.swt.internal; package com.minres.scviewer.database.swt.internal;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.graphics.Rectangle;
public interface IPainter { public interface IPainter {
void paintArea(GC gc,Rectangle area); void paintArea(Projection gc, Rectangle area);
} }

View File

@ -0,0 +1,123 @@
package com.minres.scviewer.database.swt.internal;
import java.util.Arrays;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Path;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
public class Projection {
private Point translation;
private GC gc;
public Projection(GC gc) {
super();
this.gc = gc;
translation=new Point(0, 0);
}
void setTranslation(Point t) {
translation = t;
}
void setGC(GC gc) {
this.gc=gc;
}
Point getTranslation() {
return translation;
}
Point project(Point p) {
return new Point(p.x+translation.x, p.y+translation.y);
}
public Rectangle unProject(Rectangle r) {
return new Rectangle(r.x-translation.x, r.y-translation.y, r.width, r.height);
}
public void setBackground(Color color) {
gc.setBackground(color);
}
public void setFillRule(int rule) {
gc.setFillRule(rule);
}
public void fillRectangle(Rectangle rect) {
gc.fillRectangle(rect.x+translation.x, rect.y+translation.y, rect.width, rect.height);
}
public void setLineStyle(int style) {
gc.setLineStyle(style);
}
public void setLineWidth(int width) {
gc.setLineWidth(width);
}
public void setForeground(Color color) {
gc.setForeground(color);
}
public void drawLine(int x1, int y1, int x2, int y2) {
gc.drawLine(x1+translation.x, y1+translation.y, x2+translation.x, y2+translation.y);
}
public GC getGC() {
return gc;
}
public void drawRectangle(Rectangle rect) {
gc.drawRectangle(rect.x+translation.y, rect.y+translation.y, rect.width, rect.height);
}
public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
gc.fillRoundRectangle(x+translation.x, y+translation.y, width, height, arcWidth, arcHeight);
}
public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
gc.drawRoundRectangle(x+translation.x, y+translation.y, width, height, arcWidth, arcHeight);
}
public void setAntialias(int antialias) {
gc.setAntialias(antialias);
}
public void drawText(String string, int x, int y) {
gc.drawText(string, x+translation.x, y+translation.y);
}
private int[] project(int[] points) {
int[] res = Arrays.copyOf(points, points.length);
for(int i=0; i<points.length; i+=2) {
res[i]=points[i]+translation.x;
res[i+1]=points[i+1]+translation.y;
}
return res;
}
public void fillPolygon(int[] points) {
gc.fillPolygon(project(points));
}
public void drawPolygon(int[] points) {
gc.drawPolygon(project(points));
}
public Rectangle getClipping() {
Rectangle c = gc.getClipping();
return new Rectangle(c.x-translation.x, c.y-translation.y, c.width, c.height);
}
public void setClipping(int x, int y, int width, int height) {
gc.setClipping(x+translation.x, y+translation.y, width, height);
}
public void setClipping(Rectangle r) {
gc.setClipping(r.x+translation.x, r.y+translation.y, r.width, r.height);
}
}

View File

@ -31,8 +31,8 @@ public class RulerPainter implements IPainter {
} }
@Override @Override
public void paintArea(GC gc, Rectangle area) { public void paintArea(Projection proj, Rectangle area) {
GC gc = proj.getGC();
Color headerFgColor=waveCanvas.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND); Color headerFgColor=waveCanvas.getDisplay().getSystemColor(SWT.COLOR_WIDGET_FOREGROUND);
if(headerFgColor.isDisposed()) if(headerFgColor.isDisposed())
headerFgColor=SWTResourceManager.getColor(0,0,0); headerFgColor=SWTResourceManager.getColor(0,0,0);
@ -44,7 +44,7 @@ public class RulerPainter implements IPainter {
long scaleFactor=waveCanvas.getScaleFactor(); long scaleFactor=waveCanvas.getScaleFactor();
long startPos=area.x*scaleFactor; long startPos=area.x*scaleFactor;
long startVal=startPos + waveCanvas.getXOffset()*scaleFactor; long startVal=startPos - proj.getTranslation().x*scaleFactor;
long endPos=startPos+area.width*scaleFactor; long endPos=startPos+area.width*scaleFactor;
long rulerTickMinor = rulerTickMinorC*scaleFactor; long rulerTickMinor = rulerTickMinorC*scaleFactor;

View File

@ -79,22 +79,22 @@ public class SignalPainter extends TrackPainter {
} }
private int getXPosEnd(long time) { private int getXPosEnd(long time) {
long ltmp = time / this.waveCanvas.getScaleFactor() - waveCanvas.getXOffset(); long ltmp = time / this.waveCanvas.getScaleFactor();
return ltmp > maxPosX ? maxPosX : (int) ltmp; return ltmp > maxPosX ? maxPosX : (int) ltmp;
} }
public void paintArea(GC gc, Rectangle area) { public void paintArea(Projection proj, Rectangle area) {
ISignal<?> signal = trackEntry.getSignal(); ISignal<?> signal = trackEntry.getSignal();
if (trackEntry.selected) if (trackEntry.selected)
gc.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()]); proj.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()]);
else else
gc.setBackground(this.waveCanvas.colors[even ? WaveformColors.TRACK_BG_EVEN.ordinal() : WaveformColors.TRACK_BG_ODD.ordinal()]); proj.setBackground(this.waveCanvas.colors[even ? WaveformColors.TRACK_BG_EVEN.ordinal() : WaveformColors.TRACK_BG_ODD.ordinal()]);
gc.setFillRule(SWT.FILL_EVEN_ODD); proj.setFillRule(SWT.FILL_EVEN_ODD);
gc.fillRectangle(area); proj.fillRectangle(area);
long scaleFactor = this.waveCanvas.getScaleFactor(); long scaleFactor = this.waveCanvas.getScaleFactor();
long beginPos = area.x; long beginPos = area.x;
long beginTime = (beginPos + waveCanvas.getXOffset())*scaleFactor; long beginTime = beginPos*scaleFactor;
long endTime = beginTime + area.width*scaleFactor; long endTime = beginTime + area.width*scaleFactor;
Entry<Long, ?> first = signal.getEvents().floorEntry(beginTime); Entry<Long, ?> first = signal.getEvents().floorEntry(beginTime);
@ -106,18 +106,17 @@ public class SignalPainter extends TrackPainter {
} else if (last == null) { } else if (last == null) {
last = signal.getEvents().lastEntry(); last = signal.getEvents().lastEntry();
} }
gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]); proj.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]);
gc.setLineStyle(SWT.LINE_SOLID); proj.setLineStyle(SWT.LINE_SOLID);
gc.setLineWidth(1); proj.setLineWidth(1);
NavigableMap<Long, ?> entries = signal.getEvents().subMap(first.getKey(), false, last.getKey(), true); NavigableMap<Long, ?> entries = signal.getEvents().subMap(first.getKey(), false, last.getKey(), true);
SignalChange left = new SignalChange(first); SignalChange left = new SignalChange(first);
SignalChange right = new SignalChange(entries.size() > 0 ? entries.firstEntry() : first); SignalChange right = new SignalChange(entries.size() > 0 ? entries.firstEntry() : first);
maxPosX = area.x + area.width; maxPosX = area.x + area.width;
maxValX = maxPosX + (int)waveCanvas.getXOffset();
yOffsetT = this.waveCanvas.getTrackHeight() / 5 + area.y; yOffsetT = this.waveCanvas.getTrackHeight() / 5 + area.y;
yOffsetM = this.waveCanvas.getTrackHeight() / 2 + area.y; yOffsetM = this.waveCanvas.getTrackHeight() / 2 + area.y;
yOffsetB = 4 * this.waveCanvas.getTrackHeight() / 5 + area.y; yOffsetB = 4 * this.waveCanvas.getTrackHeight() / 5 + area.y;
int xSigChangeBeginVal = Math.max(area.x + (int)waveCanvas.getXOffset(), (int) (left.time / this.waveCanvas.getScaleFactor())); int xSigChangeBeginVal = Math.max(area.x, (int) (left.time / this.waveCanvas.getScaleFactor()));
int xSigChangeBeginPos = area.x; int xSigChangeBeginPos = area.x;
int xSigChangeEndPos = Math.max(area.x, getXPosEnd(right.time)); int xSigChangeEndPos = Math.max(area.x, getXPosEnd(right.time));
@ -138,9 +137,9 @@ public class SignalPainter extends TrackPainter {
} }
SignalStencil stencil = getStencil(gc, left, entries); SignalStencil stencil = getStencil(proj.getGC(), left, entries);
do { do {
stencil.draw(gc, area, left.value, right.value, xSigChangeBeginPos, xSigChangeEndPos, multiple); stencil.draw(proj, area, left.value, right.value, xSigChangeBeginPos, xSigChangeEndPos, multiple);
if (right.time >= endTime) if (right.time >= endTime)
break; break;
left.assign(right); left.assign(right);
@ -179,7 +178,7 @@ public class SignalPainter extends TrackPainter {
private interface SignalStencil { private interface SignalStencil {
public void draw(GC gc, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple); public void draw(Projection proj, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple);
} }
private class MultiBitStencil implements SignalStencil { private class MultiBitStencil implements SignalStencil {
@ -193,7 +192,7 @@ public class SignalPainter extends TrackPainter {
tmpAwtFont = new java.awt.Font(fd.getName(), fd.getStyle(), height); tmpAwtFont = new java.awt.Font(fd.getName(), fd.getStyle(), height);
} }
public void draw(GC gc, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple) { public void draw(Projection proj, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple) {
Color colorBorder = waveCanvas.colors[WaveformColors.SIGNAL0.ordinal()]; Color colorBorder = waveCanvas.colors[WaveformColors.SIGNAL0.ordinal()];
BitVector last = (BitVector) left; BitVector last = (BitVector) left;
if (last.getValue().toString().contains("X")) { if (last.getValue().toString().contains("X")) {
@ -211,9 +210,9 @@ public class SignalPainter extends TrackPainter {
xEnd - 1, yOffsetB, xEnd - 1, yOffsetB,
xBegin + 1, yOffsetB xBegin + 1, yOffsetB
}; };
gc.setForeground(colorBorder); proj.setForeground(colorBorder);
gc.drawPolygon(points); proj.drawPolygon(points);
gc.setForeground(waveCanvas.colors[WaveformColors.SIGNAL_TEXT.ordinal()]); proj.setForeground(waveCanvas.colors[WaveformColors.SIGNAL_TEXT.ordinal()]);
//TODO: this code should be provided from a central location //TODO: this code should be provided from a central location
String label = null; String label = null;
switch(trackEntry.valueDisplay) { switch(trackEntry.valueDisplay) {
@ -226,27 +225,23 @@ public class SignalPainter extends TrackPainter {
default: default:
label="h'"+last.toHexString(); label="h'"+last.toHexString();
} }
Point bb = getBoxWidth(gc, label); Point bb = new Point(DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(label), height);
if (xBegin < area.x) { if (xBegin < area.x) {
xBegin = area.x; xBegin = area.x;
width = xEnd - xBegin; width = xEnd - xBegin;
} }
if (width > (bb.x+1)) { if (width > (bb.x+1)) {
Rectangle old = gc.getClipping(); Rectangle old = proj.getClipping();
gc.setClipping(xBegin + 3, yOffsetT, xEnd - xBegin - 5, yOffsetB - yOffsetT); proj.setClipping(xBegin + 3, yOffsetT, xEnd - xBegin - 5, yOffsetB - yOffsetT);
gc.drawText(label, xBegin + 3, yOffsetM - bb.y / 2 - 1); proj.drawText(label, xBegin + 3, yOffsetM - bb.y / 2 - 1);
gc.setClipping(old); proj.setClipping(old);
} }
} else { } else {
gc.setForeground(colorBorder); proj.setForeground(colorBorder);
gc.drawLine(xEnd, yOffsetT, xEnd, yOffsetB); proj.drawLine(xEnd, yOffsetT, xEnd, yOffsetB);
} }
} }
private Point getBoxWidth(GC gc, String label) {
return new Point(DUMMY_PANEL.getFontMetrics(tmpAwtFont).stringWidth(label), height);
}
} }
private class MultiBitStencilAnalog implements SignalStencil { private class MultiBitStencilAnalog implements SignalStencil {
@ -277,25 +272,25 @@ public class SignalPainter extends TrackPainter {
} }
public void draw(GC gc, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple) { public void draw(Projection proj, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple) {
long leftVal = ((BitVector) left).toUnsignedValue(); long leftVal = ((BitVector) left).toUnsignedValue();
long rightVal= ((BitVector) right).toUnsignedValue(); long rightVal= ((BitVector) right).toUnsignedValue();
gc.setForeground(waveCanvas.colors[WaveformColors.SIGNAL_REAL.ordinal()]); proj.setForeground(waveCanvas.colors[WaveformColors.SIGNAL_REAL.ordinal()]);
int yOffsetLeft = (int) ((leftVal-minVal) / range * (yOffsetB-yOffsetT)); int yOffsetLeft = (int) ((leftVal-minVal) / range * (yOffsetB-yOffsetT));
int yOffsetRight = (int) ((rightVal-minVal) / range * (yOffsetB-yOffsetT)); int yOffsetRight = (int) ((rightVal-minVal) / range * (yOffsetB-yOffsetT));
if(continous) { if(continous) {
if (xEnd > maxPosX) { if (xEnd > maxPosX) {
gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetRight); proj.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetRight);
} else { } else {
gc.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight); proj.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight);
} }
} else { } else {
if (xEnd > maxPosX) { if (xEnd > maxPosX) {
gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetLeft); proj.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetLeft);
} else { } else {
gc.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetLeft); proj.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetLeft);
if(yOffsetRight!=yOffsetLeft) { if(yOffsetRight!=yOffsetLeft) {
gc.drawLine(xEnd, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight); proj.drawLine(xEnd, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight);
} }
} }
} }
@ -303,12 +298,12 @@ public class SignalPainter extends TrackPainter {
} }
private class SingleBitStencil implements SignalStencil { private class SingleBitStencil implements SignalStencil {
public void draw(GC gc, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple) { public void draw(Projection proj, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple) {
if (multiple) { if (multiple) {
gc.setForeground(waveCanvas.colors[WaveformColors.SIGNALU.ordinal()]); proj.setForeground(waveCanvas.colors[WaveformColors.SIGNALU.ordinal()]);
gc.drawLine(xBegin, yOffsetT, xBegin, yOffsetB); proj.drawLine(xBegin, yOffsetT, xBegin, yOffsetB);
if(xEnd>xBegin) if(xEnd>xBegin)
gc.drawLine(xEnd, yOffsetT, xEnd, yOffsetB); proj.drawLine(xEnd, yOffsetT, xEnd, yOffsetB);
} else { } else {
Color color = waveCanvas.colors[WaveformColors.SIGNALX.ordinal()]; Color color = waveCanvas.colors[WaveformColors.SIGNALX.ordinal()];
int yOffset = yOffsetM; int yOffset = yOffsetM;
@ -326,11 +321,11 @@ public class SignalPainter extends TrackPainter {
break; break;
default: default:
} }
gc.setForeground(color); proj.setForeground(color);
if (xEnd > maxPosX) { if (xEnd > maxPosX) {
gc.drawLine(xBegin, yOffset, maxPosX, yOffset); proj.drawLine(xBegin, yOffset, maxPosX, yOffset);
} else { } else {
gc.drawLine(xBegin, yOffset, xEnd, yOffset); proj.drawLine(xBegin, yOffset, xEnd, yOffset);
int yNext = yOffsetM; int yNext = yOffsetM;
switch (((BitVector) right).getValue()[0]) { switch (((BitVector) right).getValue()[0]) {
case '1': case '1':
@ -342,7 +337,7 @@ public class SignalPainter extends TrackPainter {
default: default:
} }
if (yOffset != yNext) if (yOffset != yNext)
gc.drawLine(xEnd, yOffset, xEnd, yNext); proj.drawLine(xEnd, yOffset, xEnd, yNext);
} }
} }
} }
@ -383,7 +378,7 @@ public class SignalPainter extends TrackPainter {
} }
} }
public void draw(GC gc, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple) { public void draw(Projection proj, Rectangle area, Object left, Object right, int xBegin, int xEnd, boolean multiple) {
double leftVal = (Double) left; double leftVal = (Double) left;
double rightVal= (Double) right; double rightVal= (Double) right;
if(Double.isNaN(leftVal)) { if(Double.isNaN(leftVal)) {
@ -396,31 +391,31 @@ public class SignalPainter extends TrackPainter {
xEnd, yOffsetB, xEnd, yOffsetB,
xBegin, yOffsetB xBegin, yOffsetB
}; };
gc.setForeground(color); proj.setForeground(color);
gc.drawPolygon(points); proj.drawPolygon(points);
gc.setBackground(color); proj.setBackground(color);
gc.fillPolygon(points); proj.fillPolygon(points);
} else { } else {
gc.setForeground(color); proj.setForeground(color);
gc.drawLine(xEnd, yOffsetT, xEnd, yOffsetB); proj.drawLine(xEnd, yOffsetT, xEnd, yOffsetB);
} }
} else { } else {
gc.setForeground(waveCanvas.colors[WaveformColors.SIGNAL_REAL.ordinal()]); proj.setForeground(waveCanvas.colors[WaveformColors.SIGNAL_REAL.ordinal()]);
int yOffsetLeft = (int) ((leftVal-minVal) / range * (yOffsetB-yOffsetT)); int yOffsetLeft = (int) ((leftVal-minVal) / range * (yOffsetB-yOffsetT));
int yOffsetRight = Double.isNaN(rightVal)?yOffsetLeft:(int) ((rightVal-minVal) / range * (yOffsetB-yOffsetT)); int yOffsetRight = Double.isNaN(rightVal)?yOffsetLeft:(int) ((rightVal-minVal) / range * (yOffsetB-yOffsetT));
if(continous) { if(continous) {
if (xEnd > maxPosX) { if (xEnd > maxPosX) {
gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetRight); proj.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetRight);
} else { } else {
gc.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight); proj.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight);
} }
} else { } else {
if (xEnd > maxPosX) { if (xEnd > maxPosX) {
gc.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetLeft); proj.drawLine(xBegin, yOffsetB-yOffsetLeft, maxPosX, yOffsetB-yOffsetLeft);
} else { } else {
gc.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetLeft); proj.drawLine(xBegin, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetLeft);
if(yOffsetRight!=yOffsetLeft) { if(yOffsetRight!=yOffsetLeft) {
gc.drawLine(xEnd, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight); proj.drawLine(xEnd, yOffsetB-yOffsetLeft, xEnd, yOffsetB-yOffsetRight);
} }
} }
} }

View File

@ -60,22 +60,22 @@ public class StreamPainter extends TrackPainter{
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void paintArea(GC gc, Rectangle area) { public void paintArea(Projection proj, Rectangle area) {
if(stream.getEvents().size()==0) return; if(stream.getEvents().size()==0) return;
int trackHeight=trackEntry.height/stream.getMaxConcurrency(); int trackHeight=trackEntry.height/stream.getMaxConcurrency();
txBase=trackHeight/5; txBase=trackHeight/5;
txHeight=trackHeight*3/5; txHeight=trackHeight*3/5;
if(trackEntry.selected) { if(trackEntry.selected) {
gc.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()]); proj.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_HIGHLITE.ordinal()]);
} }
else else
gc.setBackground(this.waveCanvas.colors[even?WaveformColors.TRACK_BG_EVEN.ordinal():WaveformColors.TRACK_BG_ODD.ordinal()]); proj.setBackground(this.waveCanvas.colors[even?WaveformColors.TRACK_BG_EVEN.ordinal():WaveformColors.TRACK_BG_ODD.ordinal()]);
gc.setFillRule(SWT.FILL_EVEN_ODD); proj.setFillRule(SWT.FILL_EVEN_ODD);
gc.fillRectangle(area); proj.fillRectangle(area);
long scaleFactor = this.waveCanvas.getScaleFactor(); long scaleFactor = this.waveCanvas.getScaleFactor();
long beginPos = area.x; long beginPos = area.x;
long beginTime = (beginPos + waveCanvas.getXOffset())*scaleFactor; long beginTime = beginPos*scaleFactor;
//long endPos = beginPos + area.width; //long endPos = beginPos + area.width;
long endTime = beginTime + area.width*scaleFactor; long endTime = beginTime + area.width*scaleFactor;
@ -83,21 +83,21 @@ public class StreamPainter extends TrackPainter{
Entry<Long, ?> lastTx=stream.getEvents().ceilingEntry(endTime); Entry<Long, ?> lastTx=stream.getEvents().ceilingEntry(endTime);
if(firstTx==null) firstTx = stream.getEvents().firstEntry(); if(firstTx==null) firstTx = stream.getEvents().firstEntry();
if(lastTx==null) lastTx=stream.getEvents().lastEntry(); if(lastTx==null) lastTx=stream.getEvents().lastEntry();
gc.setFillRule(SWT.FILL_EVEN_ODD); proj.setFillRule(SWT.FILL_EVEN_ODD);
gc.setLineStyle(SWT.LINE_SOLID); proj.setLineStyle(SWT.LINE_SOLID);
gc.setLineWidth(1); proj.setLineWidth(1);
gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]); proj.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]);
for( int y1=area.y+trackHeight/2; y1<area.y+trackEntry.height; y1+=trackHeight) for( int y1=area.y+trackHeight/2; y1<area.y+trackEntry.height; y1+=trackHeight)
gc.drawLine(area.x, y1, area.x+area.width, y1); proj.drawLine(area.x, y1, area.x+area.width, y1);
if(firstTx==lastTx) { if(firstTx==lastTx) {
for(ITxEvent txEvent:(Collection<? extends ITxEvent>)firstTx.getValue()) for(ITxEvent txEvent:(Collection<? extends ITxEvent>)firstTx.getValue())
drawTx(gc, area, txEvent.getTransaction(), false); drawTx(proj, area, txEvent.getTransaction(), false);
}else{ }else{
seenTx.clear(); seenTx.clear();
NavigableMap<Long,?> entries = stream.getEvents().subMap(firstTx.getKey(), true, lastTx.getKey(), true); NavigableMap<Long,?> entries = stream.getEvents().subMap(firstTx.getKey(), true, lastTx.getKey(), true);
boolean highlighed=false; boolean highlighed=false;
gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]); proj.setForeground(this.waveCanvas.colors[WaveformColors.LINE.ordinal()]);
for(Entry<Long, ?> entry: entries.entrySet()) for(Entry<Long, ?> entry: entries.entrySet())
for(ITxEvent txEvent:(Collection<? extends ITxEvent>)entry.getValue()){ for(ITxEvent txEvent:(Collection<? extends ITxEvent>)entry.getValue()){
@ -106,38 +106,38 @@ public class StreamPainter extends TrackPainter{
if(txEvent.getType()==ITxEvent.Type.END){ if(txEvent.getType()==ITxEvent.Type.END){
ITx tx = txEvent.getTransaction(); ITx tx = txEvent.getTransaction();
highlighed|=waveCanvas.currentSelection!=null && waveCanvas.currentSelection.equals(tx); highlighed|=waveCanvas.currentSelection!=null && waveCanvas.currentSelection.equals(tx);
drawTx(gc, area, tx, false); drawTx(proj, area, tx, false);
seenTx.remove(tx); seenTx.remove(tx);
} }
} }
for(ITx tx:seenTx){ for(ITx tx:seenTx){
drawTx(gc, area, tx, false); drawTx(proj, area, tx, false);
} }
if(highlighed){ if(highlighed){
gc.setForeground(this.waveCanvas.colors[WaveformColors.LINE_HIGHLITE.ordinal()]); proj.setForeground(this.waveCanvas.colors[WaveformColors.LINE_HIGHLITE.ordinal()]);
drawTx(gc, area, waveCanvas.currentSelection, true); drawTx(proj, area, waveCanvas.currentSelection, true);
} }
} }
} }
protected void drawTx(GC gc, Rectangle area, ITx tx, boolean highlighted ) { protected void drawTx(Projection proj, Rectangle area, ITx tx, boolean highlighted ) {
// compute colors // compute colors
java.awt.Color[] fallbackColors = trackEntry.getColors(); java.awt.Color[] fallbackColors = trackEntry.getColors();
java.awt.Color[] transColor = TrackEntry.computeColor( tx.getGenerator().getName(), fallbackColors[0], fallbackColors[1] ); java.awt.Color[] transColor = TrackEntry.computeColor( tx.getGenerator().getName(), fallbackColors[0], fallbackColors[1] );
gc.setBackground( toSwtColor( gc, transColor[highlighted?1:0] ) ); proj.setBackground( toSwtColor( proj.getGC(), transColor[highlighted?1:0] ) );
int offset = tx.getConcurrencyIndex()*this.waveCanvas.getTrackHeight(); int offset = tx.getConcurrencyIndex()*this.waveCanvas.getTrackHeight();
Rectangle bb = new Rectangle( Rectangle bb = new Rectangle(
(int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()-waveCanvas.getXOffset()), area.y+offset+txBase, (int)(tx.getBeginTime()/this.waveCanvas.getScaleFactor()), area.y+offset+txBase,
(int)((tx.getEndTime()-tx.getBeginTime())/this.waveCanvas.getScaleFactor()), txHeight); (int)((tx.getEndTime()-tx.getBeginTime())/this.waveCanvas.getScaleFactor()), txHeight);
if(bb.x+bb.width<area.x || bb.x>area.x+area.width) return; if(bb.x+bb.width<area.x || bb.x>area.x+area.width) return;
if(bb.width==0){ if(bb.width==0){
gc.drawLine(bb.x, bb.y, bb.x, bb.y+bb.height); proj.drawLine(bb.x, bb.y, bb.x, bb.y+bb.height);
} else if(bb.width<10){ } else if(bb.width<10){
gc.fillRectangle(bb); proj.fillRectangle(bb);
gc.drawRectangle(bb); proj.drawRectangle(bb);
} else { } else {
if(bb.x < area.x) { if(bb.x < area.x) {
bb.width = bb.width-(area.x-bb.x)+5; bb.width = bb.width-(area.x-bb.x)+5;
@ -149,8 +149,8 @@ public class StreamPainter extends TrackPainter{
bb_x2=area_x2+5; bb_x2=area_x2+5;
bb.width= bb_x2-bb.x; bb.width= bb_x2-bb.x;
} }
gc.fillRoundRectangle(bb.x, bb.y, bb.width, bb.height, 5, 5); proj.fillRoundRectangle(bb.x, bb.y, bb.width, bb.height, 5, 5);
gc.drawRoundRectangle(bb.x, bb.y, bb.width, bb.height, 5, 5); proj.drawRoundRectangle(bb.x, bb.y, bb.width, bb.height, 5, 5);
} }
} }

View File

@ -35,11 +35,11 @@ public class TrackAreaPainter implements IPainter {
this.trackVerticalOffset= new TreeMap<>(); this.trackVerticalOffset= new TreeMap<>();
} }
public void paintArea(GC gc, Rectangle a) { public void paintArea(Projection proj, Rectangle a) {
Rectangle area = new Rectangle(a.x, a.y+waveCanvas.rulerHeight, a.width, a.height-waveCanvas.rulerHeight); Rectangle area = proj.unProject(new Rectangle(a.x, a.y+waveCanvas.rulerHeight, a.width, a.height-waveCanvas.rulerHeight));
gc.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_EVEN.ordinal()]); proj.setBackground(this.waveCanvas.colors[WaveformColors.TRACK_BG_EVEN.ordinal()]);
gc.setFillRule(SWT.FILL_EVEN_ODD); proj.setFillRule(SWT.FILL_EVEN_ODD);
gc.fillRectangle(area); proj.fillRectangle(area);
if(trackVerticalOffset.size()>0){ if(trackVerticalOffset.size()>0){
Integer firstKey=trackVerticalOffset.floorKey(area.y); Integer firstKey=trackVerticalOffset.floorKey(area.y);
if(firstKey==null) firstKey=trackVerticalOffset.firstKey(); if(firstKey==null) firstKey=trackVerticalOffset.firstKey();
@ -49,12 +49,12 @@ public class TrackAreaPainter implements IPainter {
subArea.y=firstKey; subArea.y=firstKey;
IWaveformPainter p = trackVerticalOffset.get(firstKey); IWaveformPainter p = trackVerticalOffset.get(firstKey);
subArea.height=p.getHeight(); subArea.height=p.getHeight();
p.paintArea(gc, subArea); p.paintArea(proj, subArea);
}else{ }else{
for(Entry<Integer, IWaveformPainter> entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true).entrySet()){ for(Entry<Integer, IWaveformPainter> entry : trackVerticalOffset.subMap(firstKey, true, lastKey, true).entrySet()){
subArea.y=entry.getKey(); subArea.y=entry.getKey();
subArea.height=entry.getValue().getHeight(); subArea.height=entry.getValue().getHeight();
entry.getValue().paintArea(gc, subArea); entry.getValue().paintArea(proj, subArea);
} }
} }
} }

View File

@ -45,7 +45,7 @@ import com.minres.scviewer.database.ui.IWaveformViewer;
import com.minres.scviewer.database.ui.TrackEntry; import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.database.ui.WaveformColors; import com.minres.scviewer.database.ui.WaveformColors;
public class WaveformCanvas extends Canvas{ public class WaveformCanvas extends Canvas {
Color[] colors = new Color[WaveformColors.values().length]; Color[] colors = new Color[WaveformColors.values().length];
@ -60,9 +60,7 @@ public class WaveformCanvas extends Canvas{
private long maxTime; private long maxTime;
protected Point origin; /* original size */ protected Point origin; /* original size */
protected Transform transform;
protected int rulerHeight=40; protected int rulerHeight=40;
protected List<IPainter> painterList; protected List<IPainter> painterList;
@ -89,7 +87,7 @@ public class WaveformCanvas extends Canvas{
* the style of this control. * the style of this control.
*/ */
public WaveformCanvas(final Composite parent, int style) { public WaveformCanvas(final Composite parent, int style) {
super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL); super(parent, style | SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND | SWT.V_SCROLL | SWT.H_SCROLL);
addControlListener(new ControlAdapter() { /* resize listener. */ addControlListener(new ControlAdapter() { /* resize listener. */
public void controlResized(ControlEvent event) { public void controlResized(ControlEvent event) {
syncScrollBars(); syncScrollBars();
@ -102,7 +100,6 @@ public class WaveformCanvas extends Canvas{
}); });
painterList = new LinkedList<IPainter>(); painterList = new LinkedList<IPainter>();
origin = new Point(0, 0); origin = new Point(0, 0);
transform = new Transform(getDisplay());
selectionListeners = new LinkedList<>(); selectionListeners = new LinkedList<>();
cursorPainters= new ArrayList<>(); cursorPainters= new ArrayList<>();
wave2painterMap=new HashMap<>(); wave2painterMap=new HashMap<>();
@ -150,10 +147,6 @@ public class WaveformCanvas extends Canvas{
} }
public long getXOffset() {
return -origin.x;
}
public void addCursoPainter(CursorPainter cursorPainter){ public void addCursoPainter(CursorPainter cursorPainter){
painterList.add(cursorPainter); painterList.add(cursorPainter);
cursorPainters.add(cursorPainter); cursorPainters.add(cursorPainter);
@ -323,7 +316,6 @@ public class WaveformCanvas extends Canvas{
* Dispose the garbage here * Dispose the garbage here
*/ */
public void dispose() { public void dispose() {
transform.dispose();
for (WaveformColors c : WaveformColors.values()) for (WaveformColors c : WaveformColors.values())
colors[c.ordinal()].dispose(); colors[c.ordinal()].dispose();
super.dispose(); super.dispose();
@ -402,24 +394,16 @@ public class WaveformCanvas extends Canvas{
vertical.setSelection(-origin.y); vertical.setSelection(-origin.y);
redraw(); redraw();
fireSelectionEvent(); fireSelectionEvent();
} }
/* Paint function */ /* Paint function */
private void paint(GC gc) { private void paint(GC gc) {
Rectangle clientRect = getClientArea(); /* Canvas' painting area */ Rectangle clientRect = getClientArea(); /* Canvas' painting area */
// clientRect.x = -origin.x; Projection p = new Projection(gc);
clientRect.y = -origin.y; p.setTranslation(origin);
// reset the transform
transform.identity();
// shift the content
// DO NOT SHIFT HORIZONTALLY, the range is WAY TOO BIG for float!!!
transform.translate(0, origin.y);
gc.setTransform(transform);
gc.setClipping(clientRect);
if (painterList.size() > 0 ) { if (painterList.size() > 0 ) {
for (IPainter painter : painterList) for (IPainter painter : painterList)
painter.paintArea(gc, clientRect); painter.paintArea(p, clientRect);
} else { } else {
gc.fillRectangle(clientRect); gc.fillRectangle(clientRect);
initScrollBars(); initScrollBars();