Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Nemkin2021-02-20 18:16:13 +0000
committerNikita Nemkin2021-03-22 09:13:38 +0000
commitb50f25cf21afe45c8699f4c4ed1878792d69bb8f (patch)
tree1ddece76b997b07904978fc942355f89504277d6 /bundles
parent512c15cccc3155e79536c4267ce0ef8452c5671d (diff)
downloadeclipse.platform.swt-b50f25cf21afe45c8699f4c4ed1878792d69bb8f.tar.gz
eclipse.platform.swt-b50f25cf21afe45c8699f4c4ed1878792d69bb8f.tar.xz
eclipse.platform.swt-b50f25cf21afe45c8699f4c4ed1878792d69bb8f.zip
Bug 571401 - Make Transform lightweight and platform-independent
Transform class represents a 3x2 affine transformation matrix. It's small enough and simple enough that there's no need to use native implementations. Instead, implement it in pure Java and convert to native matrix form at the point of use (GC.setTransform and GC.getTransform). Since native GTK and Cocoa matrices use double precision, shared Java implementation also uses double internally. This change fixes a bug in GTK and Cocoa implmentation of Transform.shear (swapped X and Y shear direction). Change-Id: I4c09c4e83a7f5d359904067bad144999c8876e8d Signed-off-by: Nikita Nemkin <nikita@nemkin.ru>
Diffstat (limited to 'bundles')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo.c42
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.c3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.h3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/FoundationFull.bridgesupport.extras3
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAffineTransform.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip.cpp111
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.cpp11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.h11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/gdip/Gdip.java44
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Transform.java403
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java28
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Transform.java494
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Transform.java (renamed from bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java)242
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java19
18 files changed, 184 insertions, 1255 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo.c
index bcd62a9d07..f7eaf439d4 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo.c
@@ -485,34 +485,6 @@ fail:
}
#endif
-#ifndef NO_cairo_1matrix_1rotate
-JNIEXPORT void JNICALL Cairo_NATIVE(cairo_1matrix_1rotate)
- (JNIEnv *env, jclass that, jdoubleArray arg0, jdouble arg1)
-{
- jdouble *lparg0=NULL;
- Cairo_NATIVE_ENTER(env, that, cairo_1matrix_1rotate_FUNC);
- if (arg0) if ((lparg0 = (*env)->GetDoubleArrayElements(env, arg0, NULL)) == NULL) goto fail;
- cairo_matrix_rotate((cairo_matrix_t *)lparg0, arg1);
-fail:
- if (arg0 && lparg0) (*env)->ReleaseDoubleArrayElements(env, arg0, lparg0, 0);
- Cairo_NATIVE_EXIT(env, that, cairo_1matrix_1rotate_FUNC);
-}
-#endif
-
-#ifndef NO_cairo_1matrix_1scale
-JNIEXPORT void JNICALL Cairo_NATIVE(cairo_1matrix_1scale)
- (JNIEnv *env, jclass that, jdoubleArray arg0, jdouble arg1, jdouble arg2)
-{
- jdouble *lparg0=NULL;
- Cairo_NATIVE_ENTER(env, that, cairo_1matrix_1scale_FUNC);
- if (arg0) if ((lparg0 = (*env)->GetDoubleArrayElements(env, arg0, NULL)) == NULL) goto fail;
- cairo_matrix_scale((cairo_matrix_t *)lparg0, arg1, arg2);
-fail:
- if (arg0 && lparg0) (*env)->ReleaseDoubleArrayElements(env, arg0, lparg0, 0);
- Cairo_NATIVE_EXIT(env, that, cairo_1matrix_1scale_FUNC);
-}
-#endif
-
#ifndef NO_cairo_1matrix_1transform_1point
JNIEXPORT void JNICALL Cairo_NATIVE(cairo_1matrix_1transform_1point)
(JNIEnv *env, jclass that, jdoubleArray arg0, jdoubleArray arg1, jdoubleArray arg2)
@@ -533,20 +505,6 @@ fail:
}
#endif
-#ifndef NO_cairo_1matrix_1translate
-JNIEXPORT void JNICALL Cairo_NATIVE(cairo_1matrix_1translate)
- (JNIEnv *env, jclass that, jdoubleArray arg0, jdouble arg1, jdouble arg2)
-{
- jdouble *lparg0=NULL;
- Cairo_NATIVE_ENTER(env, that, cairo_1matrix_1translate_FUNC);
- if (arg0) if ((lparg0 = (*env)->GetDoubleArrayElements(env, arg0, NULL)) == NULL) goto fail;
- cairo_matrix_translate((cairo_matrix_t *)lparg0, arg1, arg2);
-fail:
- if (arg0 && lparg0) (*env)->ReleaseDoubleArrayElements(env, arg0, lparg0, 0);
- Cairo_NATIVE_EXIT(env, that, cairo_1matrix_1translate_FUNC);
-}
-#endif
-
#ifndef NO_cairo_1move_1to
JNIEXPORT void JNICALL Cairo_NATIVE(cairo_1move_1to)
(JNIEnv *env, jclass that, jlong arg0, jdouble arg1, jdouble arg2)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.c
index 15a1ae04b8..241aeb5ad4 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.c
@@ -66,10 +66,7 @@ char * Cairo_nativeFunctionNames[] = {
"cairo_1matrix_1init_1identity",
"cairo_1matrix_1invert",
"cairo_1matrix_1multiply",
- "cairo_1matrix_1rotate",
- "cairo_1matrix_1scale",
"cairo_1matrix_1transform_1point",
- "cairo_1matrix_1translate",
"cairo_1move_1to",
"cairo_1new_1path",
"cairo_1paint",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.h
index 87688c1e1d..5a75ed3793 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/library/cairo_stats.h
@@ -76,10 +76,7 @@ typedef enum {
cairo_1matrix_1init_1identity_FUNC,
cairo_1matrix_1invert_FUNC,
cairo_1matrix_1multiply_FUNC,
- cairo_1matrix_1rotate_FUNC,
- cairo_1matrix_1scale_FUNC,
cairo_1matrix_1transform_1point_FUNC,
- cairo_1matrix_1translate_FUNC,
cairo_1move_1to_FUNC,
cairo_1new_1path_FUNC,
cairo_1paint_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java
index 19ee94d0de..b970697a4f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cairo/org/eclipse/swt/internal/cairo/Cairo.java
@@ -172,13 +172,7 @@ public static final native int cairo_matrix_invert(double[] matrix);
*/
public static final native void cairo_matrix_multiply(double[] result, double[] a, double[] b);
/** @param matrix cast=(cairo_matrix_t *) */
-public static final native void cairo_matrix_rotate(double[] matrix, double radians);
-/** @param matrix cast=(cairo_matrix_t *) */
-public static final native void cairo_matrix_scale(double[] matrix, double sx, double sy);
-/** @param matrix cast=(cairo_matrix_t *) */
public static final native void cairo_matrix_transform_point(double[] matrix, double[] x, double[] y);
-/** @param matrix cast=(cairo_matrix_t *) */
-public static final native void cairo_matrix_translate(double[] matrix, double tx, double ty);
/** @param cr cast=(cairo_t *) */
public static final native void cairo_move_to(long cr, double x, double y);
/** @param cr cast=(cairo_t *) */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/FoundationFull.bridgesupport.extras b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/FoundationFull.bridgesupport.extras
index 5579aeeb55..5bafd8bbe0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/FoundationFull.bridgesupport.extras
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/FoundationFull.bridgesupport.extras
@@ -1,8 +1,7 @@
<?xml version="1.0" encoding="UTF8"?>
<signatures swt_gen="mixed">
<class name="NSAffineTransform" swt_gen="mixed">
- <method selector="initWithTransform:" swt_gen="true">
- <arg swt_gen="true"></arg>
+ <method selector="init" swt_gen="true">
<retval swt_gen="true"></retval>
</method>
<method selector="invert" swt_gen="true">
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAffineTransform.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAffineTransform.java
index bfbdcc2be8..cefe713fbd 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAffineTransform.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/NSAffineTransform.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -35,8 +35,8 @@ public void set() {
OS.objc_msgSend(this.id, OS.sel_set);
}
-public NSAffineTransform initWithTransform(NSAffineTransform transform) {
- long result = OS.objc_msgSend(this.id, OS.sel_initWithTransform_, transform != null ? transform.id : 0);
+public NSAffineTransform init() {
+ long result = OS.objc_msgSend(this.id, OS.sel_init);
return result == this.id ? this : (result != 0 ? new NSAffineTransform(result) : null);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
index 35163d0c9e..bc31345e7d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/OS.java
@@ -1280,7 +1280,6 @@ public static final long sel_initWithString_ = Selector.sel_initWithString_.valu
public static final long sel_initWithString_attributes_ = Selector.sel_initWithString_attributes_.value;
public static final long sel_initWithTitle_ = Selector.sel_initWithTitle_.value;
public static final long sel_initWithTitle_action_keyEquivalent_ = Selector.sel_initWithTitle_action_keyEquivalent_.value;
-public static final long sel_initWithTransform_ = Selector.sel_initWithTransform_.value;
public static final long sel_initWithType_location_ = Selector.sel_initWithType_location_.value;
public static final long sel_insertColor_key_atIndex_ = Selector.sel_insertColor_key_atIndex_.value;
public static final long sel_insertItem_atIndex_ = Selector.sel_insertItem_atIndex_.value;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java
index 6fe20a0fd6..50560e9f63 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/cocoa/org/eclipse/swt/internal/cocoa/Selector.java
@@ -553,7 +553,6 @@ public enum Selector {
, sel_initWithString_attributes_("initWithString:attributes:")
, sel_initWithTitle_("initWithTitle:")
, sel_initWithTitle_action_keyEquivalent_("initWithTitle:action:keyEquivalent:")
- , sel_initWithTransform_("initWithTransform:")
, sel_initWithType_location_("initWithType:location:")
, sel_insertColor_key_atIndex_("insertColor:key:atIndex:")
, sel_insertItem_atIndex_("insertItem:atIndex:")
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip.cpp b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip.cpp
index 3296efd9ec..a8f498d733 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip.cpp
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip.cpp
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -1805,32 +1805,6 @@ JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1Multiply)
}
#endif
-#ifndef NO_Matrix_1Rotate
-extern "C" JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1Rotate)(JNIEnv *env, jclass that, jlong arg0, jfloat arg1, jint arg2);
-JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1Rotate)
- (JNIEnv *env, jclass that, jlong arg0, jfloat arg1, jint arg2)
-{
- jint rc = 0;
- Gdip_NATIVE_ENTER(env, that, Matrix_1Rotate_FUNC);
- rc = (jint)((Matrix *)arg0)->Rotate((REAL)arg1, (MatrixOrder)arg2);
- Gdip_NATIVE_EXIT(env, that, Matrix_1Rotate_FUNC);
- return rc;
-}
-#endif
-
-#ifndef NO_Matrix_1Scale
-extern "C" JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1Scale)(JNIEnv *env, jclass that, jlong arg0, jfloat arg1, jfloat arg2, jint arg3);
-JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1Scale)
- (JNIEnv *env, jclass that, jlong arg0, jfloat arg1, jfloat arg2, jint arg3)
-{
- jint rc = 0;
- Gdip_NATIVE_ENTER(env, that, Matrix_1Scale_FUNC);
- rc = (jint)((Matrix *)arg0)->Scale((REAL)arg1, (REAL)arg2, (MatrixOrder)arg3);
- Gdip_NATIVE_EXIT(env, that, Matrix_1Scale_FUNC);
- return rc;
-}
-#endif
-
#ifndef NO_Matrix_1SetElements
extern "C" JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1SetElements)(JNIEnv *env, jclass that, jlong arg0, jfloat arg1, jfloat arg2, jfloat arg3, jfloat arg4, jfloat arg5, jfloat arg6);
JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1SetElements)
@@ -1844,53 +1818,6 @@ JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1SetElements)
}
#endif
-#ifndef NO_Matrix_1Shear
-extern "C" JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1Shear)(JNIEnv *env, jclass that, jlong arg0, jfloat arg1, jfloat arg2, jint arg3);
-JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1Shear)
- (JNIEnv *env, jclass that, jlong arg0, jfloat arg1, jfloat arg2, jint arg3)
-{
- jint rc = 0;
- Gdip_NATIVE_ENTER(env, that, Matrix_1Shear_FUNC);
- rc = (jint)((Matrix *)arg0)->Shear((REAL)arg1, (REAL)arg2, (MatrixOrder)arg3);
- Gdip_NATIVE_EXIT(env, that, Matrix_1Shear_FUNC);
- return rc;
-}
-#endif
-
-#ifndef NO_Matrix_1TransformPoints__JLorg_eclipse_swt_internal_gdip_PointF_2I
-extern "C" JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1TransformPoints__JLorg_eclipse_swt_internal_gdip_PointF_2I)(JNIEnv *env, jclass that, jlong arg0, jobject arg1, jint arg2);
-JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1TransformPoints__JLorg_eclipse_swt_internal_gdip_PointF_2I)
- (JNIEnv *env, jclass that, jlong arg0, jobject arg1, jint arg2)
-{
- PointF _arg1, *lparg1=NULL;
- jint rc = 0;
- Gdip_NATIVE_ENTER(env, that, Matrix_1TransformPoints__JLorg_eclipse_swt_internal_gdip_PointF_2I_FUNC);
- if (arg1) if ((lparg1 = getPointFFields(env, arg1, &_arg1)) == NULL) goto fail;
- rc = (jint)((Matrix *)arg0)->TransformPoints(lparg1, arg2);
-fail:
- if (arg1 && lparg1) setPointFFields(env, arg1, lparg1);
- Gdip_NATIVE_EXIT(env, that, Matrix_1TransformPoints__JLorg_eclipse_swt_internal_gdip_PointF_2I_FUNC);
- return rc;
-}
-#endif
-
-#ifndef NO_Matrix_1TransformPoints__J_3FI
-extern "C" JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1TransformPoints__J_3FI)(JNIEnv *env, jclass that, jlong arg0, jfloatArray arg1, jint arg2);
-JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1TransformPoints__J_3FI)
- (JNIEnv *env, jclass that, jlong arg0, jfloatArray arg1, jint arg2)
-{
- jfloat *lparg1=NULL;
- jint rc = 0;
- Gdip_NATIVE_ENTER(env, that, Matrix_1TransformPoints__J_3FI_FUNC);
- if (arg1) if ((lparg1 = env->GetFloatArrayElements(arg1, NULL)) == NULL) goto fail;
- rc = (jint)((Matrix *)arg0)->TransformPoints((PointF *)lparg1, arg2);
-fail:
- if (arg1 && lparg1) env->ReleaseFloatArrayElements(arg1, lparg1, 0);
- Gdip_NATIVE_EXIT(env, that, Matrix_1TransformPoints__J_3FI_FUNC);
- return rc;
-}
-#endif
-
#ifndef NO_Matrix_1TransformVectors
extern "C" JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1TransformVectors)(JNIEnv *env, jclass that, jlong arg0, jobject arg1, jint arg2);
JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1TransformVectors)
@@ -1908,19 +1835,6 @@ fail:
}
#endif
-#ifndef NO_Matrix_1Translate
-extern "C" JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1Translate)(JNIEnv *env, jclass that, jlong arg0, jfloat arg1, jfloat arg2, jint arg3);
-JNIEXPORT jint JNICALL Gdip_NATIVE(Matrix_1Translate)
- (JNIEnv *env, jclass that, jlong arg0, jfloat arg1, jfloat arg2, jint arg3)
-{
- jint rc = 0;
- Gdip_NATIVE_ENTER(env, that, Matrix_1Translate_FUNC);
- rc = (jint)((Matrix *)arg0)->Translate((REAL)arg1, (REAL)arg2, (MatrixOrder)arg3);
- Gdip_NATIVE_EXIT(env, that, Matrix_1Translate_FUNC);
- return rc;
-}
-#endif
-
#ifndef NO_Matrix_1delete
extern "C" JNIEXPORT void JNICALL Gdip_NATIVE(Matrix_1delete)(JNIEnv *env, jclass that, jlong arg0);
JNIEXPORT void JNICALL Gdip_NATIVE(Matrix_1delete)
@@ -1932,15 +1846,28 @@ JNIEXPORT void JNICALL Gdip_NATIVE(Matrix_1delete)
}
#endif
-#ifndef NO_Matrix_1new
-extern "C" JNIEXPORT jlong JNICALL Gdip_NATIVE(Matrix_1new)(JNIEnv *env, jclass that, jfloat arg0, jfloat arg1, jfloat arg2, jfloat arg3, jfloat arg4, jfloat arg5);
-JNIEXPORT jlong JNICALL Gdip_NATIVE(Matrix_1new)
+#ifndef NO_Matrix_1new__
+extern "C" JNIEXPORT jlong JNICALL Gdip_NATIVE(Matrix_1new__)(JNIEnv *env, jclass that);
+JNIEXPORT jlong JNICALL Gdip_NATIVE(Matrix_1new__)
+ (JNIEnv *env, jclass that)
+{
+ jlong rc = 0;
+ Gdip_NATIVE_ENTER(env, that, Matrix_1new___FUNC);
+ rc = (jlong)new Matrix();
+ Gdip_NATIVE_EXIT(env, that, Matrix_1new___FUNC);
+ return rc;
+}
+#endif
+
+#ifndef NO_Matrix_1new__FFFFFF
+extern "C" JNIEXPORT jlong JNICALL Gdip_NATIVE(Matrix_1new__FFFFFF)(JNIEnv *env, jclass that, jfloat arg0, jfloat arg1, jfloat arg2, jfloat arg3, jfloat arg4, jfloat arg5);
+JNIEXPORT jlong JNICALL Gdip_NATIVE(Matrix_1new__FFFFFF)
(JNIEnv *env, jclass that, jfloat arg0, jfloat arg1, jfloat arg2, jfloat arg3, jfloat arg4, jfloat arg5)
{
jlong rc = 0;
- Gdip_NATIVE_ENTER(env, that, Matrix_1new_FUNC);
+ Gdip_NATIVE_ENTER(env, that, Matrix_1new__FFFFFF_FUNC);
rc = (jlong)new Matrix((REAL)arg0, (REAL)arg1, (REAL)arg2, (REAL)arg3, (REAL)arg4, (REAL)arg5);
- Gdip_NATIVE_EXIT(env, that, Matrix_1new_FUNC);
+ Gdip_NATIVE_EXIT(env, that, Matrix_1new__FFFFFF_FUNC);
return rc;
}
#endif
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.cpp b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.cpp
index 26cf2a2afa..a9273e7d46 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.cpp
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.cpp
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -147,16 +147,11 @@ char * Gdip_nativeFunctionNames[] = {
"Matrix_1Invert",
"Matrix_1IsIdentity",
"Matrix_1Multiply",
- "Matrix_1Rotate",
- "Matrix_1Scale",
"Matrix_1SetElements",
- "Matrix_1Shear",
- "Matrix_1TransformPoints__JLorg_eclipse_swt_internal_gdip_PointF_2I",
- "Matrix_1TransformPoints__J_3FI",
"Matrix_1TransformVectors",
- "Matrix_1Translate",
"Matrix_1delete",
- "Matrix_1new",
+ "Matrix_1new__",
+ "Matrix_1new__FFFFFF",
"MoveMemory__Lorg_eclipse_swt_internal_gdip_BitmapData_2J",
"MoveMemory__Lorg_eclipse_swt_internal_gdip_ColorPalette_2JI",
"PathGradientBrush_1SetCenterColor",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.h
index 03c0320e39..a45fecb820 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/gdip_stats.h
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -157,16 +157,11 @@ typedef enum {
Matrix_1Invert_FUNC,
Matrix_1IsIdentity_FUNC,
Matrix_1Multiply_FUNC,
- Matrix_1Rotate_FUNC,
- Matrix_1Scale_FUNC,
Matrix_1SetElements_FUNC,
- Matrix_1Shear_FUNC,
- Matrix_1TransformPoints__JLorg_eclipse_swt_internal_gdip_PointF_2I_FUNC,
- Matrix_1TransformPoints__J_3FI_FUNC,
Matrix_1TransformVectors_FUNC,
- Matrix_1Translate_FUNC,
Matrix_1delete_FUNC,
- Matrix_1new_FUNC,
+ Matrix_1new___FUNC,
+ Matrix_1new__FFFFFF_FUNC,
MoveMemory__Lorg_eclipse_swt_internal_gdip_BitmapData_2J_FUNC,
MoveMemory__Lorg_eclipse_swt_internal_gdip_ColorPalette_2JI_FUNC,
PathGradientBrush_1SetCenterColor_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/gdip/Gdip.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/gdip/Gdip.java
index 375544e4cf..da72f8267d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/gdip/Gdip.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/gdip/Gdip.java
@@ -901,6 +901,8 @@ public static final native int LinearGradientBrush_ScaleTransform(long brush, fl
* @param order cast=(MatrixOrder)
*/
public static final native int LinearGradientBrush_TranslateTransform(long brush, float dx, float dy, int order);
+/** @method flags=new */
+public static final native long Matrix_new();
/**
* @method flags=new
* @param m11 cast=(REAL)
@@ -939,53 +941,11 @@ public static final native int Matrix_Multiply(long matrix, long matrix1, int or
/**
* @method flags=cpp
* @param matrix cast=(Matrix *)
- * @param angle cast=(REAL)
- * @param order cast=(MatrixOrder)
- */
-public static final native int Matrix_Rotate(long matrix, float angle, int order);
-/**
- * @method flags=cpp
- * @param matrix cast=(Matrix *)
- * @param scaleX cast=(REAL)
- * @param scaleY cast=(REAL)
- * @param order cast=(MatrixOrder)
- */
-public static final native int Matrix_Scale(long matrix, float scaleX, float scaleY, int order);
-/**
- * @method flags=cpp
- * @param matrix cast=(Matrix *)
- * @param shearX cast=(REAL)
- * @param shearY cast=(REAL)
- * @param order cast=(MatrixOrder)
- */
-public static final native int Matrix_Shear(long matrix, float shearX, float shearY, int order);
-/**
- * @method flags=cpp
- * @param matrix cast=(Matrix *)
- */
-public static final native int Matrix_TransformPoints(long matrix, PointF pts, int count);
-/**
- * @method flags=cpp
- * @param matrix cast=(Matrix *)
- * @param pts cast=(PointF *)
- */
-public static final native int Matrix_TransformPoints(long matrix, float[] pts, int count);
-/**
- * @method flags=cpp
- * @param matrix cast=(Matrix *)
*/
public static final native int Matrix_TransformVectors(long matrix, PointF pts, int count);
/**
* @method flags=cpp
* @param matrix cast=(Matrix *)
- * @param offsetX cast=(REAL)
- * @param offsetY cast=(REAL)
- * @param order cast=(MatrixOrder)
- */
-public static final native int Matrix_Translate(long matrix, float offsetX, float offsetY, int order);
-/**
- * @method flags=cpp
- * @param matrix cast=(Matrix *)
* @param m11 cast=(REAL)
* @param m12 cast=(REAL)
* @param m21 cast=(REAL)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Transform.java b/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Transform.java
deleted file mode 100644
index f9484fdba8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cairo/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,403 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2016 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.cairo.*;
-
-/**
- * Instances of this class represent transformation matrices for
- * points expressed as (x, y) pairs of floating point numbers.
- * <p>
- * Application code must explicitly invoke the <code>Transform.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Transform extends Resource {
- /**
- * the OS resource for the Transform
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- *
- * @noreference This field is not intended to be referenced by clients.
- */
- public double[] handle;
-
-/**
- * Constructs a new identity Transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * <p>
- * You must dispose the transform when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device) {
- this(device, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Constructs a new Transform given an array of elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * <p>
- * You must dispose the transform when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param elements an array of floats that describe the transformation matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform(Device device, float[] elements) {
- this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]);
-}
-
-/**
- * Constructs a new Transform given all of the elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * <p>
- * You must dispose the transform when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
- 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));
- init();
-}
-
-static float[] checkTransform(float[] elements) {
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return elements;
-}
-
-@Override
-void destroy() {
- handle = null;
-}
-
-/**
- * Fills the parameter with the values of the transformation matrix
- * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
- *
- * @param elements array to hold the matrix values
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values</li>
- * </ul>
- */
-public void getElements(float[] elements) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- elements[0] = (float)handle[0];
- elements[1] = (float)handle[1];
- elements[2] = (float)handle[2];
- elements[3] = (float)handle[3];
- elements[4] = DPIUtil.autoScaleDown((float)handle[4]);
- elements[5] = DPIUtil.autoScaleDown((float)handle[5]);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * identity matrix.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void identity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Cairo.cairo_matrix_init(handle, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes
- * the mathematical inverse of the matrix it previously represented.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li>
- * </ul>
- */
-public void invert() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (Cairo.cairo_matrix_invert(handle) != 0) {
- SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX);
- }
-}
-
-/**
- * Returns <code>true</code> if the Transform has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Transform.
- * When a Transform has been disposed, it is an error to
- * invoke any other method (except {@link #dispose()}) using the Transform.
- *
- * @return <code>true</code> when the Transform is disposed, and <code>false</code> otherwise
- */
-@Override
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns <code>true</code> if the Transform represents the identity matrix
- * and false otherwise.
- *
- * @return <code>true</code> if the receiver is an identity Transform, and <code>false</code> otherwise
- */
-public boolean isIdentity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- float[] m = new float[6];
- getElements(m);
- return m[0] == 1 && m[1] == 0 && m[2] == 0 && m[3] == 1 && m[4] == 0 && m[5] == 0;
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * the result of multiplying the matrix it previously represented by the
- * argument.
- *
- * @param matrix the matrix to multiply the receiver by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- */
-public void multiply(Transform matrix) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Cairo.cairo_matrix_multiply(handle, matrix.handle, handle);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation rotated by the specified angle.
- * The angle is specified in degrees and for the identity transform 0 degrees
- * is at the 3 o'clock position. A positive value indicates a clockwise rotation
- * while a negative value indicates a counter-clockwise rotation.
- *
- * @param angle the angle to rotate the transformation by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void rotate(float angle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Cairo.cairo_matrix_rotate(handle, angle * (float)Math.PI / 180);
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation scaled by (scaleX, scaleY).
- *
- * @param scaleX the amount to scale in the X direction
- * @param scaleY the amount to scale in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void scale(float scaleX, float scaleY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Cairo.cairo_matrix_scale(handle, scaleX, scaleY);
-}
-
-/**
- * Modifies the receiver to represent a new transformation given all of
- * the elements that represent the matrix that describes that transformation.
- *
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-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));
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation sheared by (shearX, shearY).
- *
- * @param shearX the shear factor in the X direction
- * @param shearY the shear factor in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void shear(float shearX, float shearY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- double[] matrix = {1, shearX, shearY, 1, 0, 0};
- Cairo.cairo_matrix_multiply(handle, matrix, handle);
-}
-
-/**
- * Given an array containing points described by alternating x and y values,
- * modify that array such that each point has been replaced with the result of
- * applying the transformation represented by the receiver to that point.
- *
- * @param pointArray an array of alternating x and y values to be transformed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void transform(float[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- 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]);
- Cairo.cairo_matrix_transform_point(handle, dx, dy);
- pointArray[j] = DPIUtil.autoScaleDown((float)dx[0]);
- pointArray[j + 1] = DPIUtil.autoScaleDown((float)dy[0]);
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation translated by (offsetX, offsetY).
- *
- * @param offsetX the distance to translate in the X direction
- * @param offsetY the distance to translate in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-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));
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-@Override
-public String toString() {
- if (isDisposed()) return "Transform {*DISPOSED*}";
- float[] elements = new float[6];
- getElements(elements);
- return "Transform {" + elements [0] + "," + elements [1] + "," +elements [2] + "," +elements [3] + "," +elements [4] + "," +elements [5] + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java
index db83d1ba44..3085d18493 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/GC.java
@@ -3012,9 +3012,14 @@ public void getTransform (Transform transform) {
NSAffineTransform cmt = data.transform;
if (cmt != null) {
NSAffineTransformStruct struct = cmt.transformStruct();
- transform.handle.setTransformStruct(struct);
+ transform.m11 = struct.m11;
+ transform.m12 = struct.m12;
+ transform.m21 = struct.m21;
+ transform.m22 = struct.m22;
+ transform.dx = struct.tX;
+ transform.dy = struct.tY;
} else {
- transform.setElements(1, 0, 0, 1, 0, 0);
+ transform.identity();
}
}
@@ -3164,11 +3169,6 @@ public boolean isDisposed() {
return handle == null;
}
-boolean isIdentity(float[] transform) {
- return transform[0] == 1 && transform[1] == 0 && transform[2] == 0
- && transform[3] == 1 && transform[4] == 0 && transform[5] == 0;
-}
-
/**
* Sets the receiver to always use the operating system's advanced graphics
* subsystem for all graphics operations if the argument is <code>true</code>.
@@ -4033,11 +4033,19 @@ public void setTransform(Transform transform) {
if (handle == null) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
if (transform != null) {
+ NSAffineTransformStruct struct = new NSAffineTransformStruct();
+ struct.m11 = transform.m11;
+ struct.m12 = transform.m12;
+ struct.m21 = transform.m21;
+ struct.m22 = transform.m22;
+ struct.tX = transform.dx;
+ struct.tY = transform.dy;
if (data.transform != null) data.transform.release();
if (data.inverseTransform != null) data.inverseTransform.release();
- data.transform = ((NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle);
- data.inverseTransform = ((NSAffineTransform)new NSAffineTransform().alloc()).initWithTransform(transform.handle);
- NSAffineTransformStruct struct = data.inverseTransform.transformStruct();
+ data.transform = ((NSAffineTransform)new NSAffineTransform().alloc()).init();
+ data.inverseTransform = ((NSAffineTransform)new NSAffineTransform().alloc()).init();
+ data.transform.setTransformStruct(struct);
+ data.inverseTransform.setTransformStruct(struct);
if ((struct.m11 * struct.m22 - struct.m12 * struct.m21) != 0) {
data.inverseTransform.invert();
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Transform.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Transform.java
deleted file mode 100644
index 07e1bae057..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Transform.java
+++ /dev/null
@@ -1,494 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2011 IBM Corporation and others.
- *
- * This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License 2.0
- * which accompanies this distribution, and is available at
- * https://www.eclipse.org/legal/epl-2.0/
- *
- * SPDX-License-Identifier: EPL-2.0
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.cocoa.*;
-
-/**
- * Instances of this class represent transformation matrices for
- * points expressed as (x, y) pairs of floating point numbers.
- * <p>
- * Application code must explicitly invoke the <code>Transform.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <p>
- * This class requires the operating system's advanced graphics subsystem
- * which may not be available on some platforms.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
- *
- * @since 3.1
- */
-public class Transform extends Resource {
- /**
- * the OS resource for the Transform
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- *
- * @noreference This field is not intended to be referenced by clients.
- */
- public NSAffineTransform handle;
-
-/**
- * Constructs a new identity Transform.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * <p>
- * You must dispose the transform when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device) {
- this(device, 1, 0, 0, 1, 0, 0);
-}
-
-/**
- * Constructs a new Transform given an array of elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * <p>
- * You must dispose the transform when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param elements an array of floats that describe the transformation matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform(Device device, float[] elements) {
- this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]);
-}
-
-/**
- * Constructs a new Transform given all of the elements that represent the
- * matrix that describes the transformation.
- * <p>
- * This operation requires the operating system's advanced
- * graphics subsystem which may not be available on some
- * platforms.
- * </p>
- * <p>
- * You must dispose the transform when it is no longer required.
- * </p>
- *
- * @param device the device on which to allocate the Transform
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
- *
- * @see #dispose()
- */
-public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
- super(device);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle = NSAffineTransform.transform();
- if (handle == null) SWT.error(SWT.ERROR_NO_HANDLES);
- handle.retain();
- setElements(m11, m12, m21, m22, dx, dy);
- init();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-static float[] checkTransform(float[] elements) {
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return elements;
-}
-
-@Override
-void destroy() {
- handle.release();
- handle = null;
-}
-
-/**
- * Fills the parameter with the values of the transformation matrix
- * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}.
- *
- * @param elements array to hold the matrix values
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values</li>
- * </ul>
- */
-public void getElements(float[] elements) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = handle.transformStruct();
- elements[0] = (float)struct.m11;
- elements[1] = (float)struct.m12;
- elements[2] = (float)struct.m21;
- elements[3] = (float)struct.m22;
- elements[4] = (float)struct.tX;
- elements[5] = (float)struct.tY;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * identity matrix.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void identity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = new NSAffineTransformStruct();
- struct.m11 = 1;
- struct.m22 = 1;
- handle.setTransformStruct(struct);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes
- * the mathematical inverse of the matrix it previously represented.
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li>
- * </ul>
- */
-public void invert() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = handle.transformStruct();
- if ((struct.m11 * struct.m22 - struct.m12 * struct.m21) == 0) {
- SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX);
- }
- handle.invert();
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns <code>true</code> if the Transform has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the Transform.
- * When a Transform has been disposed, it is an error to
- * invoke any other method (except {@link #dispose()}) using the Transform.
- *
- * @return <code>true</code> when the Transform is disposed, and <code>false</code> otherwise
- */
-@Override
-public boolean isDisposed() {
- return handle == null;
-}
-
-/**
- * Returns <code>true</code> if the Transform represents the identity matrix
- * and false otherwise.
- *
- * @return <code>true</code> if the receiver is an identity Transform, and <code>false</code> otherwise
- */
-public boolean isIdentity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = handle.transformStruct();
- return struct.m11 == 1 && struct.m12 == 0 && struct.m21 == 0 && struct.m22 == 1 && struct.tX == 0 && struct.tY == 0;
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver such that the matrix it represents becomes the
- * the result of multiplying the matrix it previously represented by the
- * argument.
- *
- * @param matrix the matrix to multiply the receiver by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
- * </ul>
- */
-public void multiply(Transform matrix) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.prependTransform(matrix.handle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation rotated by the specified angle.
- * The angle is specified in degrees and for the identity transform 0 degrees
- * is at the 3 o'clock position. A positive value indicates a clockwise rotation
- * while a negative value indicates a counter-clockwise rotation.
- *
- * @param angle the angle to rotate the transformation by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void rotate(float angle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.rotateByDegrees(angle);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation scaled by (scaleX, scaleY).
- *
- * @param scaleX the amount to scale in the X direction
- * @param scaleY the amount to scale in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void scale(float scaleX, float scaleY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.scaleXBy(scaleX, scaleY);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver to represent a new transformation given all of
- * the elements that represent the matrix that describes that transformation.
- *
- * @param m11 the first element of the first row of the matrix
- * @param m12 the second element of the first row of the matrix
- * @param m21 the first element of the second row of the matrix
- * @param m22 the second element of the second row of the matrix
- * @param dx the third element of the first row of the matrix
- * @param dy the third element of the second row of the matrix
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = new NSAffineTransformStruct();
- struct.m11 = m11;
- struct.m12 = m12;
- struct.m21 = m21;
- struct.m22 = m22;
- struct.tX = dx;
- struct.tY = dy;
- handle.setTransformStruct(struct);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation sheared by (shearX, shearY).
- *
- * @param shearX the shear factor in the X direction
- * @param shearY the shear factor in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
- * @since 3.4
- */
-public void shear(float shearX, float shearY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSAffineTransformStruct struct = new NSAffineTransformStruct();
- struct.m11 = 1;
- struct.m12 = shearX;
- struct.m21 = shearY;
- struct.m22 = 1;
- NSAffineTransform matrix = NSAffineTransform.transform();
- matrix.setTransformStruct(struct);
- handle.prependTransform(matrix);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Given an array containing points described by alternating x and y values,
- * modify that array such that each point has been replaced with the result of
- * applying the transformation represented by the receiver to that point.
- *
- * @param pointArray an array of alternating x and y values to be transformed
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void transform(float[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- NSPoint point = new NSPoint();
- int length = pointArray.length / 2;
- for (int i = 0, j = 0; i < length; i++, j += 2) {
- point.x = pointArray[j];
- point.y = pointArray[j + 1];
- point = handle.transformPoint(point);
- pointArray[j] = (float)point.x;
- pointArray[j + 1] = (float)point.y;
- }
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Modifies the receiver so that it represents a transformation that is
- * equivalent to its previous transformation translated by (offsetX, offsetY).
- *
- * @param offsetX the distance to translate in the X direction
- * @param offsetY the distance to translate in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- */
-public void translate(float offsetX, float offsetY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- NSAutoreleasePool pool = null;
- if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
- try {
- handle.translateXBy(offsetX, offsetY);
- } finally {
- if (pool != null) pool.release();
- }
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
- */
-@Override
-public String toString() {
- if (isDisposed()) return "Transform {*DISPOSED*}";
- float[] elements = new float[6];
- getElements(elements);
- return "Transform {" + elements [0] + ", " + elements [1] + ", " +elements [2] + ", " +elements [3] + ", " +elements [4] + ", " +elements [5] + "}";
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Transform.java
index f1294d59f2..a321a3d266 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Transform.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Transform.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2014 IBM Corporation and others.
+ * Copyright (c) 2000, 2021 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,8 +14,6 @@
package org.eclipse.swt.graphics;
import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gdip.*;
/**
* Instances of this class represent transformation matrices for
@@ -36,20 +34,7 @@ import org.eclipse.swt.internal.gdip.*;
* @since 3.1
*/
public class Transform extends Resource {
-
- /**
- * the OS resource for the Transform
- * (Warning: This field is platform dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It is not available on all
- * platforms and should never be accessed from application code.
- * </p>
- *
- * @noreference This field is not intended to be referenced by clients.
- */
- public long handle;
+ double m11, m12, m21, m22, dx, dy;
/**
* Constructs a new identity Transform.
@@ -67,17 +52,12 @@ public class Transform extends Resource {
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
* </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
*
* @see #dispose()
*/
public Transform (Device device) {
- this(device, 1, 0, 0, 1, 0, 0);
+ super(device);
+ identity();
}
/**
@@ -99,17 +79,14 @@ public Transform (Device device) {
* <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device, or the elements array is null</li>
* <li>ERROR_INVALID_ARGUMENT - if the elements array is too small to hold the matrix values</li>
* </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
*
* @see #dispose()
*/
public Transform(Device device, float[] elements) {
- this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]);
+ super(device);
+ if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ setElements(elements);
}
/**
@@ -135,34 +112,12 @@ public Transform(Device device, float[] elements) {
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
* </ul>
- * @exception SWTException <ul>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES if a handle for the Transform could not be obtained</li>
- * </ul>
*
* @see #dispose()
*/
public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) {
super(device);
- this.device.checkGDIP();
- handle = Gdip.Matrix_new(m11, m12, m21, m22,
- DPIUtil.autoScaleUp(this.device, dx), DPIUtil.autoScaleUp(this.device, dy));
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- init();
-}
-
-static float[] checkTransform(float[] elements) {
- if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return elements;
-}
-
-@Override
-void destroy() {
- Gdip.Matrix_delete(handle);
- handle = 0;
+ setElements(m11, m12, m21, m22, dx, dy);
}
/**
@@ -171,37 +126,44 @@ void destroy() {
*
* @param elements array to hold the matrix values
*
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
* <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the matrix values</li>
* </ul>
*/
public void getElements(float[] elements) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Gdip.Matrix_GetElements(handle, elements);
- Drawable drawable = getDevice();
- elements[4] = DPIUtil.autoScaleDown(drawable, elements[4]);
- elements[5] = DPIUtil.autoScaleDown(drawable, elements[5]);
+ elements[0] = (float)m11;
+ elements[1] = (float)m12;
+ elements[2] = (float)m21;
+ elements[3] = (float)m22;
+ elements[4] = (float)dx;
+ elements[5] = (float)dy;
+}
+
+void getElements(double[] elements) {
+ elements[0] = m11;
+ elements[1] = m12;
+ elements[2] = m21;
+ elements[3] = m22;
+ elements[4] = dx;
+ elements[5] = dy;
}
/**
* Modifies the receiver such that the matrix it represents becomes the
* identity matrix.
*
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
* @since 3.4
*/
public void identity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_SetElements(handle, 1, 0, 0, 1, 0, 0);
+ m11 = 1.;
+ m12 = 0.;
+ m21 = 0.;
+ m22 = 1.;
+ dx = 0.;
+ dy = 0.;
}
/**
@@ -209,13 +171,25 @@ public void identity() {
* the mathematical inverse of the matrix it previously represented.
*
* @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
* <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li>
* </ul>
*/
public void invert() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (Gdip.Matrix_Invert(handle) != 0) SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX);
+ double m11 = this.m11;
+ double m12 = this.m12;
+ double m21 = this.m21;
+ double m22 = this.m22;
+ double dx = this.dx;
+ double dy = this.dy;
+ double det = m11 * m22 - m12 * m21;
+ if (det == 0. || !Double.isFinite(det)) SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX);
+ double dinv = 1. / det;
+ this.m11 = m22 * dinv;
+ this.m12 = -m12 * dinv;
+ this.m21 = -m21 * dinv;
+ this.m22 = m11 * dinv;
+ this.dx = (m21 * dy - m22 * dx) * dinv;
+ this.dy = (m12 * dx - m11 * dy) * dinv;
}
/**
@@ -230,7 +204,7 @@ public void invert() {
*/
@Override
public boolean isDisposed() {
- return handle == 0;
+ return device == null;
}
/**
@@ -240,8 +214,7 @@ public boolean isDisposed() {
* @return <code>true</code> if the receiver is an identity Transform, and <code>false</code> otherwise
*/
public boolean isIdentity() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Gdip.Matrix_IsIdentity(handle);
+ return m11 == 1. && m12 == 0. && m21 == 0. && m22 == 1. && dx == 0. && dy == 0.;
}
/**
@@ -251,19 +224,25 @@ public boolean isIdentity() {
*
* @param matrix the matrix to multiply the receiver by
*
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
* <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li>
* </ul>
*/
public void multiply(Transform matrix) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Gdip.Matrix_Multiply(handle, matrix.handle, Gdip.MatrixOrderPrepend);
+ double m11 = this.m11;
+ double m12 = this.m12;
+ double m21 = this.m21;
+ double m22 = this.m22;
+ double dx = this.dx;
+ double dy = this.dy;
+ this.m11 = m11 * matrix.m11 + m12 * matrix.m21;
+ this.m12 = m11 * matrix.m12 + m12 * matrix.m22;
+ this.m21 = m21 * matrix.m11 + m22 * matrix.m21;
+ this.m22 = m21 * matrix.m12 + m22 * matrix.m22;
+ this.dx = dx * matrix.m11 + dy * matrix.m21 + matrix.dx;
+ this.dy = dx * matrix.m12 + dy * matrix.m22 + matrix.dy;
}
/**
@@ -274,14 +253,19 @@ public void multiply(Transform matrix) {
* while a negative value indicates a counter-clockwise rotation.
*
* @param angle the angle to rotate the transformation by
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
*/
public void rotate(float angle) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_Rotate(handle, angle, Gdip.MatrixOrderPrepend);
+ double m11 = this.m11;
+ double m12 = this.m12;
+ double m21 = this.m21;
+ double m22 = this.m22;
+ double rangle = Math.toRadians(angle);
+ double sin = Math.sin(rangle);
+ double cos = Math.cos(rangle);
+ this.m11 = cos * m11 + sin * m21;
+ this.m12 = cos * m12 + sin * m22;
+ this.m21 = -sin * m11 + cos * m21;
+ this.m22 = -sin * m12 + cos * m22;
}
/**
@@ -290,14 +274,12 @@ public void rotate(float angle) {
*
* @param scaleX the amount to scale in the X direction
* @param scaleY the amount to scale in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
*/
public void scale(float scaleX, float scaleY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_Scale(handle, scaleX, scaleY, Gdip.MatrixOrderPrepend);
+ m11 *= scaleX;
+ m12 *= scaleX;
+ m21 *= scaleY;
+ m22 *= scaleY;
}
/**
@@ -310,16 +292,32 @@ public void scale(float scaleX, float scaleY) {
* @param m22 the second element of the second row of the matrix
* @param dx the third element of the first row of the matrix
* @param dy the third element of the second row of the matrix
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
*/
public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Drawable drawable = getDevice();
- Gdip.Matrix_SetElements(handle, m11, m12, m21, m22,
- DPIUtil.autoScaleUp(drawable, dx), DPIUtil.autoScaleUp(drawable, dy));
+ this.m11 = m11;
+ this.m12 = m12;
+ this.m21 = m21;
+ this.m22 = m22;
+ this.dx = dx;
+ this.dy = dy;
+}
+
+void setElements(float [] elements) {
+ m11 = elements[0];
+ m12 = elements[1];
+ m21 = elements[2];
+ m22 = elements[3];
+ dx = elements[4];
+ dy = elements[5];
+}
+
+void setElements(double [] elements) {
+ m11 = elements[0];
+ m12 = elements[1];
+ m21 = elements[2];
+ m22 = elements[3];
+ dx = elements[4];
+ dy = elements[5];
}
/**
@@ -329,15 +327,17 @@ public void setElements(float m11, float m12, float m21, float m22, float dx, fl
* @param shearX the shear factor in the X direction
* @param shearY the shear factor in the Y direction
*
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
- *
* @since 3.4
*/
public void shear(float shearX, float shearY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Gdip.Matrix_Shear(handle, shearX, shearY, Gdip.MatrixOrderPrepend);
+ double m11 = this.m11;
+ double m12 = this.m12;
+ double m21 = this.m21;
+ double m22 = this.m22;
+ this.m11 += shearY * m21;
+ this.m12 += shearY * m22;
+ this.m21 += shearX * m11;
+ this.m22 += shearX * m12;
}
/**
@@ -350,21 +350,15 @@ public void shear(float shearX, float shearY) {
* @exception IllegalArgumentException <ul>
* <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
* </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
*/
public void transform(float[] pointArray) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
int length = pointArray.length;
- Drawable drawable = getDevice();
- for (int i = 0; i < length; i++) {
- pointArray[i] = DPIUtil.autoScaleUp(drawable, pointArray[i]);
- }
- Gdip.Matrix_TransformPoints(handle, pointArray, length / 2);
- for (int i = 0; i < length; i++) {
- pointArray[i] = DPIUtil.autoScaleDown(drawable, pointArray[i]);
+ for (int i = 0; i < length; i += 2) {
+ float x = pointArray[i];
+ float y = pointArray[i+1];
+ pointArray[i] = (float)(x * m11 + y * m21 + dx);
+ pointArray[i+1] = (float)(x * m12 + y * m22 + dy);
}
}
@@ -374,15 +368,10 @@ public void transform(float[] pointArray) {
*
* @param offsetX the distance to translate in the X direction
* @param offsetY the distance to translate in the Y direction
- *
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
*/
public void translate(float offsetX, float offsetY) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Drawable drawable = getDevice();
- Gdip.Matrix_Translate(handle, DPIUtil.autoScaleUp(drawable, offsetX), DPIUtil.autoScaleUp(drawable, offsetY), Gdip.MatrixOrderPrepend);
+ dx += offsetX * m11 + offsetY * m21;
+ dy += offsetX * m12 + offsetY * m22;
}
/**
@@ -393,10 +382,7 @@ public void translate(float offsetX, float offsetY) {
*/
@Override
public String toString() {
- if (isDisposed()) return "Transform {*DISPOSED*}";
- float[] elements = new float[6];
- getElements(elements);
- return "Transform {" + elements [0] + "," + elements [1] + "," +elements [2] + "," +elements [3] + "," +elements [4] + "," +elements [5] + "}";
+ return "Transform {" + m11 + ", " + m12 + ", " + m21 + ", " + m22 + ", " + dx + ", " + dy + "}";
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
index 7c31f411c0..5a60886403 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
@@ -2564,12 +2564,12 @@ public void getTransform(Transform transform) {
* So we return whatever the client specified with setTransform.
*/
if (currentTransform != null) {
- transform.handle = currentTransform.clone();
+ transform.setElements(currentTransform);
} else {
- transform.handle = new double[] { 1.0, 0.0, 0.0, 1.0, 0.0, 0.0 };
+ transform.identity();
}
} else {
- transform.setElements(1, 0, 0, 1, 0, 0);
+ transform.identity();
}
}
@@ -3796,9 +3796,10 @@ public void setTransform(Transform transform) {
}
// Apply user transform on top of the current transformation matrix (and remember it)
if (transform != null) {
- currentTransform = transform.handle.clone();
+ currentTransform = new double[6];
+ transform.getElements(currentTransform);
double[] transformMatrix = identity();
- Cairo.cairo_matrix_multiply(transformMatrix, transform.handle, transformMatrix);
+ Cairo.cairo_matrix_multiply(transformMatrix, currentTransform, transformMatrix);
Cairo.cairo_transform(cairo, transformMatrix);
}
data.state &= ~DRAW_OFFSET;
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
index bab384ef06..3bdfa78162 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
@@ -3742,13 +3742,18 @@ public void getTransform(Transform transform) {
if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
long gdipGraphics = data.gdipGraphics;
if (gdipGraphics != 0) {
- Gdip.Graphics_GetTransform(gdipGraphics, transform.handle);
long identity = identity();
+ long matrix = Gdip.Matrix_new();
Gdip.Matrix_Invert(identity);
- Gdip.Matrix_Multiply(transform.handle, identity, Gdip.MatrixOrderAppend);
+ Gdip.Graphics_GetTransform(gdipGraphics, matrix);
+ Gdip.Matrix_Multiply(matrix, identity, Gdip.MatrixOrderAppend);
+ float[] elements = new float[6];
+ Gdip.Matrix_GetElements(matrix, elements);
+ Gdip.Matrix_delete(matrix);
Gdip.Matrix_delete(identity);
+ transform.setElements(elements);
} else {
- transform.setElements(1, 0, 0, 1, 0, 0);
+ transform.identity();
}
}
@@ -4848,7 +4853,13 @@ public void setTransform(Transform transform) {
initGdip();
long identity = identity();
if (transform != null) {
- Gdip.Matrix_Multiply(identity, transform.handle, Gdip.MatrixOrderPrepend);
+ long matrix = Gdip.Matrix_new();
+ Gdip.Matrix_SetElements(matrix,
+ (float)transform.m11, (float)transform.m12,
+ (float)transform.m21, (float)transform.m22,
+ (float)transform.dx, (float)transform.dy);
+ Gdip.Matrix_Multiply(identity, matrix, Gdip.MatrixOrderPrepend);
+ Gdip.Matrix_delete(matrix);
}
Gdip.Graphics_SetTransform(data.gdipGraphics, identity);
Gdip.Matrix_delete(identity);

Back to the top