1 11 package org.eclipse.swt.graphics; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.internal.gdip.*; 15 16 31 public class Transform extends Resource { 32 33 43 public int handle; 44 45 67 public Transform (Device device) { 68 this(device, 1, 0, 0, 1, 0, 0); 69 } 70 71 96 public Transform(Device device, float[] elements) { 97 this (device, checkTransform(elements)[0], elements[1], elements[2], elements[3], elements[4], elements[5]); 98 } 99 100 129 public Transform (Device device, float m11, float m12, float m21, float m22, float dx, float dy) { 130 if (device == null) device = Device.getDevice(); 131 if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 132 this.device = device; 133 device.checkGDIP(); 134 handle = Gdip.Matrix_new(m11, m12, m21, m22, dx, dy); 135 if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); 136 if (device.tracking) device.new_Object(this); 137 } 138 139 static float[] checkTransform(float[] elements) { 140 if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 141 if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 142 return elements; 143 } 144 145 150 public void dispose() { 151 if (handle == 0) return; 152 if (device.isDisposed()) return; 153 Gdip.Matrix_delete(handle); 154 handle = 0; 155 if (device.tracking) device.dispose_Object(this); 156 device = null; 157 } 158 159 173 public void getElements(float[] elements) { 174 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 175 if (elements == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 176 if (elements.length < 6) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 177 Gdip.Matrix_GetElements(handle, elements); 178 } 179 180 189 public void invert() { 190 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 191 if (Gdip.Matrix_Invert(handle) != 0) SWT.error(SWT.ERROR_CANNOT_INVERT_MATRIX); 192 } 193 194 204 public boolean isDisposed() { 205 return handle == 0; 206 } 207 208 214 public boolean isIdentity() { 215 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 216 return Gdip.Matrix_IsIdentity(handle); 217 } 218 219 234 public void multiply(Transform matrix) { 235 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 236 if (matrix == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 237 if (matrix.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 238 Gdip.Matrix_Multiply(handle, matrix.handle, Gdip.MatrixOrderPrepend); 239 } 240 241 254 public void rotate(float angle) { 255 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 256 Gdip.Matrix_Rotate(handle, angle, Gdip.MatrixOrderPrepend); 257 } 258 259 270 public void scale(float scaleX, float scaleY) { 271 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 272 Gdip.Matrix_Scale(handle, scaleX, scaleY, Gdip.MatrixOrderPrepend); 273 } 274 275 290 public void setElements(float m11, float m12, float m21, float m22, float dx, float dy) { 291 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 292 Gdip.Matrix_SetElements(handle, m11, m12, m21, m22, dx, dy); 293 } 294 295 309 public void transform(float[] pointArray) { 310 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 311 if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 312 Gdip.Matrix_TransformPoints(handle, pointArray, pointArray.length / 2); 313 } 314 315 326 public void translate(float offsetX, float offsetY) { 327 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); 328 Gdip.Matrix_Translate(handle, offsetX, offsetY, Gdip.MatrixOrderPrepend); 329 } 330 331 337 public String toString() { 338 if (isDisposed()) return "Transform {*DISPOSED*}"; 339 float[] elements = new float[6]; 340 getElements(elements); 341 return "Transform {" + elements [0] + "," + elements [1] + "," +elements [2] + "," +elements [3] + "," +elements [4] + "," +elements [5] + "}"; 342 } 343 344 } 345 | Popular Tags |