Skip to content

Commit d652a68

Browse files
committed
[GTK] Even more *InPixel method removal
Remove nowadays useless extra methods that even has the bad side effect of duplicating checks. Continuation of #2101
1 parent d1859ce commit d652a68

File tree

8 files changed

+21
-139
lines changed

8 files changed

+21
-139
lines changed

bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Path.java

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ public Path (Device device, PathData data) {
218218
public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) {
219219
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
220220
if (width == 0 || height == 0 || arcAngle == 0) return;
221-
addArcInPixels(x, y, width, height, startAngle, arcAngle);
222-
}
223-
224-
void addArcInPixels(float x, float y, float width, float height, float startAngle, float arcAngle) {
225221
moved = true;
226222
if (width == height) {
227223
float angle = -startAngle * (float)Math.PI / 180;
@@ -287,10 +283,6 @@ public void addPath(Path path) {
287283
*/
288284
public void addRectangle(float x, float y, float width, float height) {
289285
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
290-
addRectangleInPixels(x, y, width, height);
291-
}
292-
293-
void addRectangleInPixels(float x, float y, float width, float height) {
294286
moved = false;
295287
Cairo.cairo_rectangle(handle, x, y, width, height);
296288
closed = true;
@@ -320,13 +312,10 @@ public void addString(String string, float x, float y, Font font) {
320312
// Scale up the font
321313
FontData fd = font.getFontData()[0];
322314
Font scaledFont = new Font(font.getDevice(), fd);
323-
addStringInPixels(string, x, y, scaledFont);
324-
scaledFont.dispose(); // Dispose the scaled up font
325-
}
326-
void addStringInPixels(String string, float x, float y, Font font) {
327315
moved = false;
328-
GC.addCairoString(handle, string, x, y, font);
316+
GC.addCairoString(handle, string, x, y, scaledFont);
329317
closed = true;
318+
scaledFont.dispose(); // Dispose the scaled up font
330319
}
331320

332321
/**
@@ -372,9 +361,6 @@ public boolean contains(float x, float y, GC gc, boolean outline) {
372361
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
373362
if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
374363
if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
375-
return containsInPixels(x, y, gc, outline);
376-
}
377-
boolean containsInPixels(float x, float y, GC gc, boolean outline) {
378364
//TODO - see Windows
379365
gc.initCairo();
380366
gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH);
@@ -409,9 +395,6 @@ boolean containsInPixels(float x, float y, GC gc, boolean outline) {
409395
*/
410396
public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) {
411397
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
412-
cubicToInPixels(cx1, cy1, cx2, cy2, x, y);
413-
}
414-
void cubicToInPixels(float cx1, float cy1, float cx2, float cy2, float x, float y) {
415398
if (!moved) {
416399
double[] currentX = new double[1], currentY = new double[1];
417400
Cairo.cairo_get_current_point(handle, currentX, currentY);
@@ -441,9 +424,6 @@ public void getBounds(float[] bounds) {
441424
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
442425
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
443426
if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
444-
getBoundsInPixels(bounds);
445-
}
446-
void getBoundsInPixels(float[] bounds) {
447427
long copy = Cairo.cairo_copy_path(handle);
448428
if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
449429
cairo_path_t path = new cairo_path_t();
@@ -516,10 +496,6 @@ void getBoundsInPixels(float[] bounds) {
516496
*/
517497
public void getCurrentPoint(float[] point) {
518498
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
519-
getCurrentPointInPixels(point);
520-
}
521-
522-
void getCurrentPointInPixels(float[] point) {
523499
if (point == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
524500
if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
525501
double[] x = new double[1], y = new double[1];
@@ -541,10 +517,6 @@ void getCurrentPointInPixels(float[] point) {
541517
*/
542518
public PathData getPathData() {
543519
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
544-
return getPathDataInPixels();
545-
}
546-
547-
PathData getPathDataInPixels() {
548520
long copy = Cairo.cairo_copy_path(handle);
549521
if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES);
550522
cairo_path_t path = new cairo_path_t();
@@ -619,9 +591,6 @@ PathData getPathDataInPixels() {
619591
*/
620592
public void lineTo(float x, float y) {
621593
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
622-
lineToInPixels(x, y);
623-
}
624-
void lineToInPixels(float x, float y) {
625594
if (!moved) {
626595
double[] currentX = new double[1], currentY = new double[1];
627596
Cairo.cairo_get_current_point(handle, currentX, currentY);
@@ -646,9 +615,6 @@ void lineToInPixels(float x, float y) {
646615
*/
647616
public void moveTo(float x, float y) {
648617
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
649-
moveToInPixels(x, y);
650-
}
651-
void moveToInPixels(float x, float y) {
652618
/*
653619
* Bug in Cairo. If cairo_move_to() is not called at the
654620
* begining of a subpath, the first cairo_line_to() or
@@ -675,9 +641,6 @@ void moveToInPixels(float x, float y) {
675641
*/
676642
public void quadTo(float cx, float cy, float x, float y) {
677643
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
678-
quadToInPixels(cx, cy, x, y);
679-
}
680-
void quadToInPixels(float cx, float cy, float x, float y) {
681644
double[] currentX = new double[1], currentY = new double[1];
682645
Cairo.cairo_get_current_point(handle, currentX, currentY);
683646
if (!moved) {

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,6 @@ protected void destroy () {
367367
*/
368368
public Rectangle getBounds () {
369369
checkDevice ();
370-
return getBoundsInPixels ();
371-
}
372-
373-
private Rectangle getBoundsInPixels () {
374370
return new Rectangle(0, 0, 0, 0);
375371
}
376372

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,6 @@ static void cairo_region_get_rectangles(long region, long [] rectangles, int[] n
155155
public void add (int[] pointArray) {
156156
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
157157
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
158-
addInPixels(pointArray);
159-
}
160-
void addInPixels (int[] pointArray) {
161158
/*
162159
* Bug in GTK. If gdk_region_polygon() is called with one point,
163160
* it segment faults. The fix is to make sure that it is called
@@ -186,10 +183,7 @@ void addInPixels (int[] pointArray) {
186183
public void add(Rectangle rect) {
187184
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
188185
if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
189-
addInPixels(rect);
190-
}
191-
void addInPixels(Rectangle rect) {
192-
addInPixels (rect.x, rect.y, rect.width, rect.height);
186+
add (rect.x, rect.y, rect.width, rect.height);
193187
}
194188

195189
/**
@@ -213,9 +207,6 @@ void addInPixels(Rectangle rect) {
213207
public void add(int x, int y, int width, int height) {
214208
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
215209
if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
216-
add(new Rectangle(x, y, width, height));
217-
}
218-
void addInPixels(int x, int y, int width, int height) {
219210
cairo_rectangle_int_t rect = new cairo_rectangle_int_t();
220211
rect.x = x;
221212
rect.y = y;
@@ -261,9 +252,6 @@ public void add(Region region) {
261252
*/
262253
public boolean contains(int x, int y) {
263254
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
264-
return contains(new Point(x, y));
265-
}
266-
boolean containsInPixels(int x, int y) {
267255
return Cairo.cairo_region_contains_point(handle, x, y);
268256
}
269257

@@ -284,11 +272,8 @@ boolean containsInPixels(int x, int y) {
284272
*/
285273
public boolean contains(Point pt) {
286274
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
287-
return containsInPixels(pt);
288-
}
289-
boolean containsInPixels(Point pt) {
290275
if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
291-
return containsInPixels(pt.x, pt.y);
276+
return contains(pt.x, pt.y);
292277
}
293278

294279
@Override
@@ -327,9 +312,6 @@ public boolean equals(Object object) {
327312
*/
328313
public Rectangle getBounds() {
329314
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
330-
return getBoundsInPixels();
331-
}
332-
Rectangle getBoundsInPixels() {
333315
cairo_rectangle_int_t rect = new cairo_rectangle_int_t();
334316
Cairo.cairo_region_get_extents(handle, rect);
335317
return new Rectangle(rect.x, rect.y, rect.width, rect.height);
@@ -389,11 +371,7 @@ public int hashCode() {
389371
public void intersect(Rectangle rect) {
390372
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
391373
if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
392-
intersectInPixels(rect);
393-
}
394-
395-
void intersectInPixels(Rectangle rect) {
396-
intersectInPixels (rect.x, rect.y, rect.width, rect.height);
374+
intersect (rect.x, rect.y, rect.width, rect.height);
397375
}
398376

399377
/**
@@ -417,10 +395,6 @@ void intersectInPixels(Rectangle rect) {
417395
public void intersect(int x, int y, int width, int height) {
418396
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
419397
if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
420-
intersect(new Rectangle(x, y, width, height));
421-
}
422-
423-
void intersectInPixels(int x, int y, int width, int height) {
424398
cairo_rectangle_int_t rect = new cairo_rectangle_int_t();
425399
rect.x = x;
426400
rect.y = y;
@@ -561,10 +535,6 @@ public boolean isEmpty() {
561535
public void subtract (int[] pointArray) {
562536
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
563537
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
564-
subtractInPixels(pointArray);
565-
}
566-
567-
void subtractInPixels (int[] pointArray) {
568538
/*
569539
* Bug in GTK. If gdk_region_polygon() is called with one point,
570540
* it segment faults. The fix is to make sure that it is called
@@ -594,11 +564,7 @@ void subtractInPixels (int[] pointArray) {
594564
public void subtract(Rectangle rect) {
595565
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
596566
if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
597-
subtractInPixels(rect);
598-
}
599-
600-
void subtractInPixels(Rectangle rect) {
601-
subtractInPixels (rect.x, rect.y, rect.width, rect.height);
567+
subtract (rect.x, rect.y, rect.width, rect.height);
602568
}
603569

604570
/**
@@ -622,10 +588,6 @@ void subtractInPixels(Rectangle rect) {
622588
public void subtract(int x, int y, int width, int height) {
623589
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
624590
if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
625-
subtract(new Rectangle(x, y, width, height));
626-
}
627-
628-
void subtractInPixels(int x, int y, int width, int height) {
629591
cairo_rectangle_int_t rect = new cairo_rectangle_int_t ();
630592
rect.x = x;
631593
rect.y = y;
@@ -675,10 +637,6 @@ public void subtract(Region region) {
675637
*/
676638
public void translate (int x, int y) {
677639
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
678-
translate(new Point(x, y));
679-
}
680-
681-
void translateInPixels (int x, int y) {
682640
Cairo.cairo_region_translate (handle, x, y);
683641
}
684642

@@ -700,7 +658,7 @@ void translateInPixels (int x, int y) {
700658
public void translate (Point pt) {
701659
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
702660
if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
703-
translateInPixels(pt.x, pt.y);
661+
translate(pt.x, pt.y);
704662
}
705663

706664
/**

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,6 @@ void deregister () {
550550
*/
551551
public void drawBackground (GC gc, int x, int y, int width, int height, int offsetX, int offsetY) {
552552
checkWidget();
553-
Rectangle rect = new Rectangle (x, y, width, height);
554-
drawBackgroundInPixels(gc, rect.x, rect.y, rect.width, rect.height, offsetX, offsetY);
555-
}
556-
557-
void drawBackgroundInPixels (GC gc, int x, int y, int width, int height, int offsetX, int offsetY) {
558-
checkWidget ();
559553
if (gc == null) error (SWT.ERROR_NULL_ARGUMENT);
560554
if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
561555
Control control = findBackgroundControl ();

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,12 +1780,6 @@ public Point toDisplay (Point point) {
17801780
return toDisplay (point.x, point.y);
17811781
}
17821782

1783-
Point toDisplayInPixels (Point point) {
1784-
checkWidget();
1785-
if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
1786-
return toDisplayInPixels (point.x, point.y);
1787-
}
1788-
17891783
/**
17901784
* GTK4 only function to replace gdk_surface_get_origin
17911785
* @return the origin of the Control's SWTFixed container relative to the Shell
@@ -2693,7 +2687,7 @@ boolean dragDetect (int x, int y, boolean filter, boolean dragOnTimeout, boolean
26932687
//Note, input params x/y are relative, the two points below are absolute coords.
26942688
Point startPos = null;
26952689
Point currPos = null;
2696-
startPos = display.getCursorLocationInPixels();
2690+
startPos = display.getCursorLocation();
26972691

26982692
while (!quit) {
26992693
long eventPtr = 0;
@@ -2709,7 +2703,7 @@ boolean dragDetect (int x, int y, boolean filter, boolean dragOnTimeout, boolean
27092703
if (eventPtr != 0) {
27102704
break;
27112705
} else {
2712-
currPos = display.getCursorLocationInPixels();
2706+
currPos = display.getCursorLocation();
27132707
dragging = GTK3.gtk_drag_check_threshold (handle,
27142708
startPos.x, startPos.y, currPos.x, currPos.y);
27152709
if (dragging) break;
@@ -4701,11 +4695,6 @@ void redraw (boolean all) {
47014695
* @see SWT#DOUBLE_BUFFERED
47024696
*/
47034697
public void redraw (int x, int y, int width, int height, boolean all) {
4704-
checkWidget();
4705-
redrawInPixels(x, y, width, height, all);
4706-
}
4707-
4708-
void redrawInPixels (int x, int y, int width, int height, boolean all) {
47094698
checkWidget();
47104699
if (!GTK.gtk_widget_get_visible (topHandle ())) return;
47114700
if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - width - x;

bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1985,10 +1985,6 @@ boolean filters (int eventType) {
19851985
* </ul>
19861986
*/
19871987
public Point getCursorLocation() {
1988-
return getCursorLocationInPixels();
1989-
}
1990-
1991-
Point getCursorLocationInPixels() {
19921988
checkDevice();
19931989

19941990
int[] x = new int[1], y = new int[1];
@@ -4298,7 +4294,7 @@ public boolean post (Event event) {
42984294

42994295
if (type == SWT.MouseMove) {
43004296
Rectangle loc = event.getBounds();
4301-
setCursorLocationInPixels(new Point(loc.x, loc.y));
4297+
setCursorLocation(new Point(loc.x, loc.y));
43024298
return true;
43034299
}
43044300

@@ -5258,17 +5254,6 @@ public void setCursorLocation (int x, int y) {
52585254
setCursorLocation(new Point (x, y));
52595255
}
52605256

5261-
void setCursorLocationInPixels (Point location) {
5262-
long gdkDisplay = GDK.gdk_display_get_default();
5263-
long gdkPointer = GDK.gdk_get_pointer(gdkDisplay);
5264-
if (GTK.GTK4) {
5265-
//TODO: GTK4 no gdk_device_warp
5266-
} else {
5267-
long gdkScreen = GDK.gdk_screen_get_default();
5268-
GDK.gdk_device_warp(gdkPointer, gdkScreen, location.x, location.y);
5269-
}
5270-
}
5271-
52725257
/**
52735258
* Sets the location of the on-screen pointer relative to the top left corner
52745259
* of the screen. <b>Note: It is typically considered bad practice for a
@@ -5287,7 +5272,14 @@ void setCursorLocationInPixels (Point location) {
52875272
public void setCursorLocation (Point point) {
52885273
checkDevice ();
52895274
if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
5290-
setCursorLocationInPixels(point);
5275+
long gdkDisplay = GDK.gdk_display_get_default();
5276+
long gdkPointer = GDK.gdk_get_pointer(gdkDisplay);
5277+
if (GTK.GTK4) {
5278+
//TODO: GTK4 no gdk_device_warp
5279+
} else {
5280+
long gdkScreen = GDK.gdk_screen_get_default();
5281+
GDK.gdk_device_warp(gdkPointer, gdkScreen, point.x, point.y);
5282+
}
52915283
}
52925284

52935285
/**
@@ -5581,7 +5573,7 @@ void showIMWindow (Control control) {
55815573
OS.pango_font_description_free (fontDesc);
55825574
if (pangoAttrs [0] != 0) GTK.gtk_label_set_attributes (preeditLabel, pangoAttrs[0]);
55835575
GTK.gtk_label_set_text (preeditLabel, preeditString [0]);
5584-
Point point = control.toDisplayInPixels (control.getIMCaretPos ());
5576+
Point point = control.toDisplay (control.getIMCaretPos ());
55855577
GTK3.gtk_window_move (preeditWindow, point.x, point.y);
55865578
GtkRequisition requisition = new GtkRequisition ();
55875579
GTK.gtk_widget_get_preferred_size (preeditLabel, requisition, null);

0 commit comments

Comments
 (0)