Skip to content

Commit

Permalink
[GTK][HiDpi] Code cleanup for removal of non-cairo scale path
Browse files Browse the repository at this point in the history
Fixes #1300
[GTK][HiDpi] Code cleanup for removal of non-cairo scale path

Fixes #1300

[GTK][HiDpi] Code cleanup for removal of non-cairo scale path

Fixes #1300
  • Loading branch information
deepika-u committed Jul 10, 2024
1 parent b2c0366 commit 52ca34f
Show file tree
Hide file tree
Showing 53 changed files with 410 additions and 1,400 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static Frame new_Frame (final Composite parent) {
});
break;
case SWT.Resize:
final Rectangle clientArea = DPIUtil.autoScaleUp(parent.getClientArea());
final Rectangle clientArea = parent.getClientArea();
EventQueue.invokeLater(() -> frame[0].setSize (clientArea.width, clientArea.height));
break;
}
Expand All @@ -241,7 +241,7 @@ public static Frame new_Frame (final Composite parent) {

parent.getDisplay().asyncExec(() -> {
if (parent.isDisposed()) return;
final Rectangle clientArea = DPIUtil.autoScaleUp(parent.getClientArea());
final Rectangle clientArea = parent.getClientArea();
EventQueue.invokeLater(() -> {
frame[0].setSize (clientArea.width, clientArea.height);
frame[0].validate ();
Expand Down Expand Up @@ -285,7 +285,7 @@ public void componentResized (ComponentEvent e) {
display.syncExec (() -> {
if (shell.isDisposed()) return;
Dimension dim = parent.getSize ();
shell.setSize (DPIUtil.autoScaleDown(new Point(dim.width, dim.height)));
shell.setSize (new Point(dim.width, dim.height));
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4534,10 +4534,8 @@ static long toDisplay (long gdkResource, long x, long y) {
} else {
GDK.gdk_window_get_origin (gdkResource, origin_x, origin_y);
}
int scaledX = DPIUtil.autoScaleDown (origin_x [0]);
int scaledY = DPIUtil.autoScaleDown (origin_y [0]);
C.memmove (x, new int[] {scaledX}, 4);
C.memmove (y, new int[] {scaledY}, 4);
C.memmove (x, origin_x, 4);
C.memmove (y, origin_y, 4);
return 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ boolean setEventData(long context, int x, int y, int time, DNDEvent event) {
long window = GTK3.gtk_widget_get_window (control.handle);
GDK.gdk_window_get_origin(window, origin_x, origin_y);
}
Point coordinates = DPIUtil.autoScaleDown(new Point(origin_x[0] + x, origin_y[0] + y));
Point coordinates = new Point(origin_x[0] + x, origin_y[0] + y);

event.widget = this;
event.x = coordinates.x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public void dragOver(DropTargetEvent event) {
long handle = table.handle;
int effect = checkEffect(event.feedback);
Point coordinates = new Point(event.x, event.y);
coordinates = DPIUtil.autoScaleUp(table.toControl(coordinates));
coordinates = table.toControl(coordinates);
long [] path = new long [1];
GTK.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, path, null, null, null);
int index = -1;
Expand All @@ -154,7 +154,7 @@ public void dragOver(DropTargetEvent event) {
} else {
if (index != -1 && scrollIndex == index && scrollBeginTime != 0) {
if (System.currentTimeMillis() >= scrollBeginTime) {
if (coordinates.y < DPIUtil.autoScaleUp(table.getItemHeight())) {
if (coordinates.y < table.getItemHeight()) {
GTK.gtk_tree_path_prev(path[0]);
} else {
GTK.gtk_tree_path_next(path[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void dragOver(DropTargetEvent event) {

long handle = tree.handle;
Point coordinates = new Point(event.x, event.y);
coordinates = DPIUtil.autoScaleUp(tree.toControl(coordinates));
coordinates = tree.toControl(coordinates);
long [] path = new long [1];
GTK.gtk_tree_view_get_path_at_pos (handle, coordinates.x, coordinates.y, path, null, null, null);
int index = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gtk.*;
import org.eclipse.swt.internal.gtk3.*;
import org.eclipse.swt.internal.opengl.glx.*;
Expand Down Expand Up @@ -164,7 +163,7 @@ public GLCanvas (Composite parent, int style, GLData data) {
GLX.glViewport (viewport [0],viewport [1],viewport [2],viewport [3]);
break;
case SWT.Resize:
Rectangle clientArea = DPIUtil.autoScaleUp(getClientArea());
Rectangle clientArea = getClientArea();
GDK.gdk_window_move (glWindow, clientArea.x, clientArea.y);
GDK.gdk_window_resize (glWindow, clientArea.width, clientArea.height);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ void onDispose (Event e) {
}

void onResize (Event e) {
Rectangle rect = DPIUtil.autoScaleUp(browser.getClientArea ());
Rectangle rect = browser.getClientArea ();
if (webView == 0)
return;
GTK.gtk_widget_set_size_request (webView, rect.width, rect.height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,6 @@ public Path (Device device, PathData data) {
public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (width == 0 || height == 0 || arcAngle == 0) return;
x = DPIUtil.autoScaleUp(x);
y = DPIUtil.autoScaleUp(y);
width = DPIUtil.autoScaleUp(width);
height = DPIUtil.autoScaleUp(height);
addArcInPixels(x, y, width, height, startAngle, arcAngle);
}

void addArcInPixels(float x, float y, float width, float height, float startAngle, float arcAngle) {
moved = true;
if (width == height) {
float angle = -startAngle * (float)Math.PI / 180;
Expand Down Expand Up @@ -292,14 +284,6 @@ public void addPath(Path path) {
*/
public void addRectangle(float x, float y, float width, float height) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
x = DPIUtil.autoScaleUp(x);
y = DPIUtil.autoScaleUp(y);
width = DPIUtil.autoScaleUp(width);
height = DPIUtil.autoScaleUp(height);
addRectangleInPixels(x, y, width, height);
}

void addRectangleInPixels(float x, float y, float width, float height) {
moved = false;
Cairo.cairo_rectangle(handle, x, y, width, height);
closed = true;
Expand All @@ -326,19 +310,14 @@ public void addString(String string, float x, float y, Font font) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (font == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
x = DPIUtil.autoScaleUp(x);
y = DPIUtil.autoScaleUp(y);
// Scale up the font
FontData fd = font.getFontData()[0];
fd.setHeight(DPIUtil.autoScaleUp(fd.getHeight()));
fd.setHeight(fd.getHeight());
Font scaledFont = new Font(font.getDevice(), fd);
addStringInPixels(string, x, y, scaledFont);
scaledFont.dispose(); // Dispose the scaled up font
}
void addStringInPixels(String string, float x, float y, Font font) {
moved = false;
GC.addCairoString(handle, string, x, y, font);
closed = true;
scaledFont.dispose(); // Dispose the scaled up font
}

/**
Expand Down Expand Up @@ -384,11 +363,6 @@ public boolean contains(float x, float y, GC gc, boolean outline) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
x = DPIUtil.autoScaleUp(x);
y = DPIUtil.autoScaleUp(y);
return containsInPixels(x, y, gc, outline);
}
boolean containsInPixels(float x, float y, GC gc, boolean outline) {
//TODO - see Windows
gc.initCairo();
gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH);
Expand Down Expand Up @@ -423,15 +397,6 @@ boolean containsInPixels(float x, float y, GC gc, boolean outline) {
*/
public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
cx1 = DPIUtil.autoScaleUp(cx1);
cy1 = DPIUtil.autoScaleUp(cy1);
cx2 = DPIUtil.autoScaleUp(cx2);
cy2 = DPIUtil.autoScaleUp(cy2);
x = DPIUtil.autoScaleUp(x);
y = DPIUtil.autoScaleUp(y);
cubicToInPixels(cx1, cy1, cx2, cy2, x, y);
}
void cubicToInPixels(float cx1, float cy1, float cx2, float cy2, float x, float y) {
if (!moved) {
double[] currentX = new double[1], currentY = new double[1];
Cairo.cairo_get_current_point(handle, currentX, currentY);
Expand Down Expand Up @@ -647,11 +612,6 @@ PathData getPathDataInPixels() {
*/
public void lineTo(float x, float y) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
x = DPIUtil.autoScaleUp(x);
y = DPIUtil.autoScaleUp(y);
lineToInPixels(x, y);
}
void lineToInPixels(float x, float y) {
if (!moved) {
double[] currentX = new double[1], currentY = new double[1];
Cairo.cairo_get_current_point(handle, currentX, currentY);
Expand All @@ -676,11 +636,6 @@ void lineToInPixels(float x, float y) {
*/
public void moveTo(float x, float y) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
x = DPIUtil.autoScaleUp(x);
y = DPIUtil.autoScaleUp(y);
moveToInPixels(x, y);
}
void moveToInPixels(float x, float y) {
/*
* Bug in Cairo. If cairo_move_to() is not called at the
* begining of a subpath, the first cairo_line_to() or
Expand All @@ -707,13 +662,6 @@ void moveToInPixels(float x, float y) {
*/
public void quadTo(float cx, float cy, float x, float y) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
x = DPIUtil.autoScaleUp(x);
y = DPIUtil.autoScaleUp(y);
cx = DPIUtil.autoScaleUp(cx);
cy = DPIUtil.autoScaleUp(cy);
quadToInPixels(cx, cy, x, y);
}
void quadToInPixels(float cx, float cy, float x, float y) {
double[] currentX = new double[1], currentY = new double[1];
Cairo.cairo_get_current_point(handle, currentX, currentY);
if (!moved) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.swt.graphics;

import org.eclipse.swt.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.cairo.*;

/**
Expand Down Expand Up @@ -173,10 +172,6 @@ public Pattern(Device device, float x1, float y1, float x2, float y2, Color colo
*/
public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
super(device);
x1 = DPIUtil.autoScaleUp(x1);
y1 = DPIUtil.autoScaleUp(y1);
x2 = DPIUtil.autoScaleUp(x2);
y2 = DPIUtil.autoScaleUp(y2);
if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public Transform (Device device, float m11, float m12, float m21, float m22, flo
super(device);
handle = new double[6];
if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, DPIUtil.autoScaleUp(dx), DPIUtil.autoScaleUp(dy));
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, dx, dy);
init();
}

Expand Down Expand Up @@ -320,7 +320,7 @@ public void scale(float scaleX, float scaleY) {
*/
public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, DPIUtil.autoScaleUp(dx), DPIUtil.autoScaleUp(dy));
Cairo.cairo_matrix_init(handle, m11, m12, m21, m22, dx, dy);
}

/**
Expand Down Expand Up @@ -362,8 +362,8 @@ public void transform(float[] pointArray) {
double[] dx = new double[1], dy = new double[1];
int length = pointArray.length / 2;
for (int i = 0, j = 0; i < length; i++, j += 2) {
dx[0] = DPIUtil.autoScaleUp(pointArray[j]);
dy[0] = DPIUtil.autoScaleUp(pointArray[j + 1]);
dx[0] = pointArray[j];
dy[0] = pointArray[j + 1];
Cairo.cairo_matrix_transform_point(handle, dx, dy);
pointArray[j] = DPIUtil.autoScaleDown((float)dx[0]);
pointArray[j + 1] = DPIUtil.autoScaleDown((float)dy[0]);
Expand All @@ -383,7 +383,7 @@ public void transform(float[] pointArray) {
*/
public void translate(float offsetX, float offsetY) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Cairo.cairo_matrix_translate(handle, DPIUtil.autoScaleUp(offsetX), DPIUtil.autoScaleUp(offsetY));
Cairo.cairo_matrix_translate(handle, offsetX, offsetY);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,6 @@ protected void destroy () {
*/
public Rectangle getBounds () {
checkDevice ();
return DPIUtil.autoScaleDown (getBoundsInPixels ());
}

private Rectangle getBoundsInPixels () {
return new Rectangle(0, 0, 0, 0);
}

Expand Down
Loading

0 comments on commit 52ca34f

Please sign in to comment.