Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ static Stream<Arguments> singleValueTestCombinations() {
.stream(diagramZooms).mapToObj(diagramZoom -> Arguments.of(source, monitorZoom, diagramZoom))));
}

@Test
@SuppressWarnings("static-method")
public void testTranlsationWithMulipleScaledLayers() {
Display display = Display.getDefault();
Image image = new Image(display, 100, 100);
GC gc = new GC(image);
RecordingSwtGraphics graphics = new RecordingSwtGraphics(gc);
ScaledGraphics scaledGraphics = new ScaledGraphics(graphics);
scaledGraphics.scale(1.5);
scaledGraphics.translate(1f, 1f);
ScaledGraphics scaledGraphics2 = new ScaledGraphics(scaledGraphics);
scaledGraphics2.scale(2.5);
scaledGraphics2.translate(1f, 1f);

scaledGraphics2.drawRectangle(0, 0, 10, 10);
assertEquals(5, graphics.translation.x);
assertEquals(5, graphics.translation.y);

validateDrawRectangle(graphics, new Rectangle(5, 5, 37, 37));
scaledGraphics2.dispose();
scaledGraphics.dispose();
graphics.dispose();
gc.dispose();
image.dispose();
}

@Test
@SuppressWarnings("static-method")
public void testDrawLineForRegression() {
Expand Down Expand Up @@ -1108,8 +1134,8 @@ public RecordingSwtGraphics(GC gc) {

@Override
public void translate(int dx, int dy) {
translation.setX(dx);
translation.setY(dy);
translation.setX(translation.x + dx);
translation.setY(translation.y + dy);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,14 @@ protected void setValues(double zoom, double x, double y, Font font, float lineW
* @param g the base graphics object
*/
public ScaledGraphics(Graphics g) {
graphics = g;
if (g instanceof ScaledGraphics scaledGraphics) {
graphics = scaledGraphics.graphics;
zoom = scaledGraphics.zoom;
fractionalX = scaledGraphics.fractionalX;
fractionalY = scaledGraphics.fractionalY;
} else {
graphics = g;
}
localFont = g.getFont();
localLineWidth = g.getLineWidthFloat();
}
Expand Down
Loading