# HG changeset patch
# User Frank Benoit
# Date 1201473747 -3600
# Node ID 39834037712c2f8f475cedba073451a09298a719
# Parent fa34113bf4be4bbbf815b484391f405952f782e4
Pattern
diff -r fa34113bf4be -r 39834037712c dwt/graphics/Pattern.d
--- a/dwt/graphics/Pattern.d Sun Jan 27 23:29:42 2008 +0100
+++ b/dwt/graphics/Pattern.d Sun Jan 27 23:42:27 2008 +0100
@@ -12,22 +12,20 @@
*******************************************************************************/
module dwt.graphics.Pattern;
-import dwt.internal.win32.OS;
-import dwt.internal.gdip.Gdip;
-//PORTING_TYPE
-class Pattern{
- Gdip.Brush* handle;
- bool isDisposed();
-}
-
-/++
import dwt.DWT;
import dwt.DWTError;
import dwt.DWTException;
import dwt.internal.gdip.Gdip;
-import dwt.internal.gdip.PointF;
import dwt.internal.win32.OS;
+import dwt.graphics.Resource;
+import dwt.graphics.Color;
+import dwt.graphics.GC;
+import dwt.graphics.Device;
+import dwt.graphics.Image;
+
+import tango.text.convert.Format;
+
/**
* Instances of this class represent patterns to use while drawing. Patterns
* can be specified either as bitmaps or gradients.
@@ -43,7 +41,7 @@
*
* @since 3.1
*/
-public class Pattern extends Resource {
+public class Pattern : Resource {
/**
* the OS resource for the Pattern
@@ -55,7 +53,7 @@
* platforms and should never be accessed from application code.
*
*/
- public int handle;
+ public Gdip.Brush* handle;
/**
* Constructs a new Pattern given an image. Drawing with the resulting
@@ -82,7 +80,7 @@
*
* @see #dispose()
*/
-public Pattern(Device device, Image image) {
+public this(Device device, Image image) {
if (device is null) device = Device.getDevice();
if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
if (image is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
@@ -90,16 +88,16 @@
this.device = device;
device.checkGDIP();
int[] gdipImage = image.createGdipImage();
- int img = gdipImage[0];
+ auto img = cast(Gdip.Image*)gdipImage[0];
int width = Gdip.Image_GetWidth(img);
int height = Gdip.Image_GetHeight(img);
- handle = Gdip.TextureBrush_new(img, Gdip.WrapModeTile, 0, 0, width, height);
- Gdip.Bitmap_delete(img);
+ handle = cast(Gdip.Brush*)Gdip.TextureBrush_new(img, Gdip.WrapModeTile, 0, 0, width, height);
+ Gdip.Bitmap_delete( cast(Gdip.Bitmap*)img);
if (gdipImage[1] !is 0) {
- int hHeap = OS.GetProcessHeap ();
- OS.HeapFree(hHeap, 0, gdipImage[1]);
+ auto hHeap = OS.GetProcessHeap ();
+ OS.HeapFree(hHeap, 0, cast(void*)gdipImage[1]);
}
- if (handle is 0) DWT.error(DWT.ERROR_NO_HANDLES);
+ if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
if (device.tracking) device.new_Object(this);
}
@@ -135,7 +133,7 @@
*
* @see #dispose()
*/
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, Color color2) {
+public this(Device device, float x1, float y1, float x2, float y2, Color color1, Color color2) {
this(device, x1, y1, x2, y2, color1, 0xFF, color2, 0xFF);
}
@@ -175,7 +173,7 @@
*
* @since 3.2
*/
-public Pattern(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
+public this(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) {
if (device is null) device = Device.getDevice();
if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
if (color1 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
@@ -184,31 +182,39 @@
if (color2.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
this.device = device;
device.checkGDIP();
- int colorRef1 = color1.handle;
+ auto colorRef1 = color1.handle;
int rgb = ((colorRef1 >> 16) & 0xFF) | (colorRef1 & 0xFF00) | ((colorRef1 & 0xFF) << 16);
- int foreColor = Gdip.Color_new((alpha1 & 0xFF) << 24 | rgb);
+ auto foreColor = Gdip.Color_new((alpha1 & 0xFF) << 24 | rgb);
if (x1 is x2 && y1 is y2) {
- handle = Gdip.SolidBrush_new(foreColor);
- if (handle is 0) DWT.error(DWT.ERROR_NO_HANDLES);
+ handle = cast(Gdip.Brush*)Gdip.SolidBrush_new(foreColor);
+ if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
} else {
- int colorRef2 = color2.handle;
+ auto colorRef2 = color2.handle;
rgb = ((colorRef2 >> 16) & 0xFF) | (colorRef2 & 0xFF00) | ((colorRef2 & 0xFF) << 16);
- int backColor = Gdip.Color_new((alpha2 & 0xFF) << 24 | rgb);
- PointF p1 = new PointF();
+ auto backColor = Gdip.Color_new((alpha2 & 0xFF) << 24 | rgb);
+ Gdip.PointF p1;
p1.X = x1;
p1.Y = y1;
- PointF p2 = new PointF();
+ Gdip.PointF p2;
p2.X = x2;
p2.Y = y2;
- handle = Gdip.LinearGradientBrush_new(p1, p2, foreColor, backColor);
- if (handle is 0) DWT.error(DWT.ERROR_NO_HANDLES);
+ handle = cast(Gdip.Brush*)Gdip.LinearGradientBrush_new(p1, p2, foreColor, backColor);
+ if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
if (alpha1 !is 0xFF || alpha2 !is 0xFF) {
- int a = (int)((alpha1 & 0xFF) * 0.5f + (alpha2 & 0xFF) * 0.5f);
- int r = (int)(((colorRef1 & 0xFF) >> 0) * 0.5f + ((colorRef2 & 0xFF) >> 0) * 0.5f);
- int g = (int)(((colorRef1 & 0xFF00) >> 8) * 0.5f + ((colorRef2 & 0xFF00) >> 8) * 0.5f);
- int b = (int)(((colorRef1 & 0xFF0000) >> 16) * 0.5f + ((colorRef2 & 0xFF0000) >> 16) * 0.5f);
- int midColor = Gdip.Color_new(a << 24 | r << 16 | g << 8 | b);
- Gdip.LinearGradientBrush_SetInterpolationColors(handle, new int[]{foreColor, midColor, backColor}, new float[]{0, 0.5f, 1}, 3);
+ int a = cast(int)((alpha1 & 0xFF) * 0.5f + (alpha2 & 0xFF) * 0.5f);
+ int r = cast(int)(((colorRef1 & 0xFF) >> 0) * 0.5f + ((colorRef2 & 0xFF) >> 0) * 0.5f);
+ int g = cast(int)(((colorRef1 & 0xFF00) >> 8) * 0.5f + ((colorRef2 & 0xFF00) >> 8) * 0.5f);
+ int b = cast(int)(((colorRef1 & 0xFF0000) >> 16) * 0.5f + ((colorRef2 & 0xFF0000) >> 16) * 0.5f);
+ auto midColor = Gdip.Color_new(a << 24 | r << 16 | g << 8 | b);
+ Gdip.Color[3] c;
+ c[0] = *foreColor;
+ c[1] = *midColor;
+ c[2] = *backColor;
+ float[3] f;
+ f[0] = 0;
+ f[1] = 0.5f;
+ f[2] = 1;
+ Gdip.LinearGradientBrush_SetInterpolationColors( cast(Gdip.LinearGradientBrush*)handle, c.ptr, f.ptr, 3);
Gdip.Color_delete(midColor);
}
Gdip.Color_delete(backColor);
@@ -223,24 +229,24 @@
* they allocate.
*/
public void dispose() {
- if (handle is 0) return;
+ if (handle is null) return;
if (device.isDisposed()) return;
int type = Gdip.Brush_GetType(handle);
switch (type) {
case Gdip.BrushTypeSolidColor:
- Gdip.SolidBrush_delete(handle);
+ Gdip.SolidBrush_delete(cast(Gdip.SolidBrush*)handle);
break;
case Gdip.BrushTypeHatchFill:
- Gdip.HatchBrush_delete(handle);
+ Gdip.HatchBrush_delete(cast(Gdip.HatchBrush*)handle);
break;
case Gdip.BrushTypeLinearGradient:
- Gdip.LinearGradientBrush_delete(handle);
+ Gdip.LinearGradientBrush_delete(cast(Gdip.LinearGradientBrush*)handle);
break;
case Gdip.BrushTypeTextureFill:
- Gdip.TextureBrush_delete(handle);
+ Gdip.TextureBrush_delete(cast(Gdip.TextureBrush*)handle);
break;
}
- handle = 0;
+ handle = null;
if (device.tracking) device.dispose_Object(this);
device = null;
}
@@ -256,7 +262,7 @@
* @return true
when the Pattern is disposed, and false
otherwise
*/
public bool isDisposed() {
- return handle is 0;
+ return handle is null;
}
/**
@@ -265,10 +271,9 @@
*
* @return a string representation of the receiver
*/
-public String toString() {
+public char[] toString() {
if (isDisposed()) return "Pattern {*DISPOSED*}";
- return "Pattern {" + handle + "}";
+ return Format( "Pattern {{{}}", handle );
}
}
-++/
\ No newline at end of file