comparison dwt/graphics/GC.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children 4436505b216f
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
71 * @see dwt.events.PaintEvent 71 * @see dwt.events.PaintEvent
72 */ 72 */
73 73
74 public final class GC : Resource { 74 public final class GC : Resource {
75 75
76 alias Resource.init_ init_;
77
76 /** 78 /**
77 * the handle to the OS device context 79 * the handle to the OS device context
78 * (Warning: This field is platform dependent) 80 * (Warning: This field is platform dependent)
79 * <p> 81 * <p>
80 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT 82 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT
179 Device device = data.device; 181 Device device = data.device;
180 if (device is null) device = Device.getDevice(); 182 if (device is null) device = Device.getDevice();
181 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 183 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
182 this.device = data.device = device; 184 this.device = data.device = device;
183 init_ (drawable, data, hDC); 185 init_ (drawable, data, hDC);
184 if (device.tracking) device.new_Object(this); 186 init_();
185 } 187 }
186 188
187 static int checkStyle(int style) { 189 static int checkStyle(int style) {
188 if ((style & DWT.LEFT_TO_RIGHT) !is 0) style &= ~DWT.RIGHT_TO_LEFT; 190 if ((style & DWT.LEFT_TO_RIGHT) !is 0) style &= ~DWT.RIGHT_TO_LEFT;
189 return style & (DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT); 191 return style & (DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT);
261 } 263 }
262 } 264 }
263 default: 265 default:
264 } 266 }
265 if (dashes !is null) { 267 if (dashes !is null) {
266 Gdip.Pen_SetDashPattern(pen, dashes, dashes.length); 268 Gdip.Pen_SetDashPattern(pen, dashes.ptr, dashes.length);
267 Gdip.Pen_SetDashStyle(pen, Gdip.DashStyleCustom); 269 Gdip.Pen_SetDashStyle(pen, Gdip.DashStyleCustom);
268 Gdip.Pen_SetDashOffset(pen, dashOffset); 270 Gdip.Pen_SetDashOffset(pen, dashOffset);
269 } else { 271 } else {
270 Gdip.Pen_SetDashStyle(pen, dashStyle); 272 Gdip.Pen_SetDashStyle(pen, dashStyle);
271 } 273 }
321 data.gdipBrush = cast(Gdip.Brush)brush; 323 data.gdipBrush = cast(Gdip.Brush)brush;
322 data.gdipBgBrush = brush; 324 data.gdipBgBrush = brush;
323 } 325 }
324 } 326 }
325 if ((state & FONT) !is 0) { 327 if ((state & FONT) !is 0) {
326 OS.SelectObject(handle, data.hFont); 328 Font font = data.font;
327 auto font = createGdipFont(handle, data.hFont); 329 OS.SelectObject(handle, font.handle);
330 auto gdipFont = createGdipFont(handle, font.handle);
328 if (data.gdipFont !is null) Gdip.Font_delete(data.gdipFont); 331 if (data.gdipFont !is null) Gdip.Font_delete(data.gdipFont);
329 data.gdipFont = font; 332 data.gdipFont = gdipFont;
330 } 333 }
331 if ((state & DRAW_OFFSET) !is 0) { 334 if ((state & DRAW_OFFSET) !is 0) {
332 data.gdipXOffset = data.gdipYOffset = 0; 335 data.gdipXOffset = data.gdipYOffset = 0;
333 auto matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); 336 auto matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
334 float[6] elements; 337 float[2] point; point[0]=1.0; point[1]=1.0;
335 Gdip.Graphics_GetTransform(gdipGraphics, matrix); 338 Gdip.Graphics_GetTransform(gdipGraphics, matrix);
336 Gdip.Matrix_GetElements(matrix, elements ); 339 Gdip.Matrix_TransformPoints(matrix, cast(Gdip.PointF*)point.ptr, 1);
337 Gdip.Matrix_delete(matrix); 340 Gdip.Matrix_delete(matrix);
338 float scaling = elements[0]; 341 float scaling = point[0];
339 if (scaling < 0) scaling = -scaling; 342 if (scaling < 0) scaling = -scaling;
340 float penWidth = data.lineWidth * scaling; 343 float penWidth = data.lineWidth * scaling;
341 if (penWidth is 0 || (cast(int)penWidth % 2) is 1) { 344 if (penWidth is 0 || (cast(int)penWidth % 2) is 1) {
342 data.gdipXOffset = 0.5f / scaling; 345 data.gdipXOffset = 0.5f / scaling;
343 } 346 }
344 scaling = elements[3]; 347 scaling = point[1];
345 if (scaling < 0) scaling = -scaling; 348 if (scaling < 0) scaling = -scaling;
346 penWidth = data.lineWidth * scaling; 349 penWidth = data.lineWidth * scaling;
347 if (penWidth is 0 || (cast(int)penWidth % 2) is 1) { 350 if (penWidth is 0 || (cast(int)penWidth % 2) is 1) {
348 data.gdipYOffset = 0.5f / scaling; 351 data.gdipYOffset = 0.5f / scaling;
349 } 352 }
437 } 440 }
438 if ((state & FOREGROUND_TEXT) !is 0) { 441 if ((state & FOREGROUND_TEXT) !is 0) {
439 OS.SetTextColor(handle, data.foreground); 442 OS.SetTextColor(handle, data.foreground);
440 } 443 }
441 if ((state & FONT) !is 0) { 444 if ((state & FONT) !is 0) {
442 OS.SelectObject(handle, data.hFont); 445 Font font = data.font;
446 OS.SelectObject(handle, font.handle);
443 } 447 }
444 } 448 }
445 449
446 /** 450 /**
447 * Copies a rectangular area of the receiver at the specified 451 * Copies a rectangular area of the receiver at the specified
625 * 629 *
626 * @exception DWTError <ul> 630 * @exception DWTError <ul>
627 * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li> 631 * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li>
628 * </ul> 632 * </ul>
629 */ 633 */
630 override public void dispose() { 634 void destroy() {
631 if (handle is null) return; 635 bool gdip = data.gdipGraphics !is null;
632 if (data.device.isDisposed()) return;
633
634 disposeGdip(); 636 disposeGdip();
637 if (gdip && (data.style & DWT.MIRRORED) !is 0) {
638 OS.SetLayout(handle, OS.GetLayout(handle) | OS.LAYOUT_RTL);
639 }
635 640
636 /* Select stock pen and brush objects and free resources */ 641 /* Select stock pen and brush objects and free resources */
637 if (data.hPen !is null) { 642 if (data.hPen !is null) {
638 OS.SelectObject(handle, OS.GetStockObject(OS.NULL_PEN)); 643 OS.SelectObject(handle, OS.GetStockObject(OS.NULL_PEN));
639 OS.DeleteObject(data.hPen); 644 OS.DeleteObject(data.hPen);
659 if (image !is null) image.memGC = null; 664 if (image !is null) image.memGC = null;
660 665
661 /* 666 /*
662 * Dispose the HDC. 667 * Dispose the HDC.
663 */ 668 */
664 Device device = data.device;
665 if (drawable !is null) drawable.internal_dispose_GC(handle, data); 669 if (drawable !is null) drawable.internal_dispose_GC(handle, data);
666 drawable = null; 670 drawable = null;
667 handle = null; 671 handle = null;
668 data.image = null; 672 data.image = null;
669 data.ps = null; 673 data.ps = null;
670 if (device.tracking) device.dispose_Object(this);
671 data.device = null;
672 data = null; 674 data = null;
673 } 675 }
674 676
675 void disposeGdip() { 677 void disposeGdip() {
676 if (data.gdipPen !is null) Gdip.Pen_delete(data.gdipPen); 678 if (data.gdipPen !is null) Gdip.Pen_delete(data.gdipPen);
814 * @see #drawRectangle(int, int, int, int) 816 * @see #drawRectangle(int, int, int, int)
815 */ 817 */
816 public void drawFocus (int x, int y, int width, int height) { 818 public void drawFocus (int x, int y, int width, int height) {
817 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 819 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
818 if ((data.uiState & OS.UISF_HIDEFOCUS) !is 0) return; 820 if ((data.uiState & OS.UISF_HIDEFOCUS) !is 0) return;
821 data.focusDrawn = true;
819 HDC hdc = handle; 822 HDC hdc = handle;
820 int state = 0; 823 int state = 0;
821 auto gdipGraphics = data.gdipGraphics; 824 auto gdipGraphics = data.gdipGraphics;
822 if (gdipGraphics !is null) { 825 if (gdipGraphics !is null) {
823 HRGN clipRgn; 826 HRGN clipRgn;
835 auto matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0); 838 auto matrix = Gdip.Matrix_new(1, 0, 0, 1, 0, 0);
836 if (matrix is null) DWT.error(DWT.ERROR_NO_HANDLES); 839 if (matrix is null) DWT.error(DWT.ERROR_NO_HANDLES);
837 Gdip.Graphics_GetTransform(gdipGraphics, matrix); 840 Gdip.Graphics_GetTransform(gdipGraphics, matrix);
838 if (!Gdip.Matrix_IsIdentity(matrix)) { 841 if (!Gdip.Matrix_IsIdentity(matrix)) {
839 gotElements = true; 842 gotElements = true;
840 Gdip.Matrix_GetElements(matrix, lpXform); 843 Gdip.Matrix_GetElements(matrix, lpXform.ptr);
841 } 844 }
842 Gdip.Matrix_delete(matrix); 845 Gdip.Matrix_delete(matrix);
843 hdc = Gdip.Graphics_GetHDC(gdipGraphics); 846 hdc = Gdip.Graphics_GetHDC(gdipGraphics);
844 state = OS.SaveDC(hdc); 847 state = OS.SaveDC(hdc);
845 OS.SetBkColor(hdc, data.background);
846 OS.SetTextColor(hdc, data.foreground);
847 if (gotElements) { 848 if (gotElements) {
848 OS.SetGraphicsMode(hdc, OS.GM_ADVANCED); 849 OS.SetGraphicsMode(hdc, OS.GM_ADVANCED);
849 OS.SetWorldTransform(hdc, cast(XFORM*)lpXform.ptr); 850 OS.SetWorldTransform(hdc, cast(XFORM*)lpXform.ptr);
850 } 851 }
851 if (clipRgn !is null) { 852 if (clipRgn !is null) {
852 OS.SelectClipRgn(hdc, clipRgn); 853 OS.SelectClipRgn(hdc, clipRgn);
853 OS.DeleteObject(clipRgn); 854 OS.DeleteObject(clipRgn);
854 } 855 }
855 } 856 }
857 OS.SetBkColor(hdc, 0xFFFFFF);
858 OS.SetTextColor(hdc, 0x000000);
856 RECT rect; 859 RECT rect;
857 OS.SetRect(&rect, x, y, x + width, y + height); 860 OS.SetRect(&rect, x, y, x + width, y + height);
858 OS.DrawFocusRect(hdc, &rect); 861 OS.DrawFocusRect(hdc, &rect);
859 if (gdipGraphics !is null) { 862 if (gdipGraphics !is null) {
860 OS.RestoreDC(hdc, state); 863 OS.RestoreDC(hdc, state);
861 Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc); 864 Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc);
865 } else {
866 data.state &= ~(BACKGROUND_TEXT | FOREGROUND_TEXT);
862 } 867 }
863 } 868 }
864 869
865 /** 870 /**
866 * Draws the given image in the receiver at the specified 871 * Draws the given image in the receiver at the specified
932 } 937 }
933 938
934 void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, bool simple) { 939 void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, bool simple) {
935 if (data.gdipGraphics !is null) { 940 if (data.gdipGraphics !is null) {
936 //TODO - cache bitmap 941 //TODO - cache bitmap
937 int[] gdipImage = srcImage.createGdipImage(); 942 int /*long*/ [] gdipImage = srcImage.createGdipImage();
938 auto img = cast(Gdip.Image) gdipImage[0]; 943 auto img = cast(Gdip.Image) gdipImage[0];
939 int imgWidth = Gdip.Image_GetWidth(img); 944 int imgWidth = Gdip.Image_GetWidth(img);
940 int imgHeight = Gdip.Image_GetHeight(img); 945 int imgHeight = Gdip.Image_GetHeight(img);
941 if (simple) { 946 if (simple) {
942 srcWidth = destWidth = imgWidth; 947 srcWidth = destWidth = imgWidth;
1424 srcColor = srcMask; 1429 srcColor = srcMask;
1425 srcColorY += imgHeight; 1430 srcColorY += imgHeight;
1426 } 1431 }
1427 auto srcHdc = OS.CreateCompatibleDC(handle); 1432 auto srcHdc = OS.CreateCompatibleDC(handle);
1428 auto oldSrcBitmap = OS.SelectObject(srcHdc, srcColor); 1433 auto oldSrcBitmap = OS.SelectObject(srcHdc, srcColor);
1429 auto destHdc = handle, x = destX, y = destY; 1434 auto destHdc = handle;
1435 int x = destX, y = destY;
1430 HDC tempHdc; 1436 HDC tempHdc;
1431 HBITMAP tempBitmap; 1437 HBITMAP tempBitmap;
1432 HBITMAP oldTempBitmap; 1438 HBITMAP oldTempBitmap;
1433 int oldBkColor = 0, oldTextColor = 0; 1439 int oldBkColor = 0, oldTextColor = 0;
1434 if (offscreen) { 1440 if (offscreen) {
1804 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 1810 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
1805 checkGC(DRAW); 1811 checkGC(DRAW);
1806 auto gdipGraphics = data.gdipGraphics; 1812 auto gdipGraphics = data.gdipGraphics;
1807 if (gdipGraphics !is null) { 1813 if (gdipGraphics !is null) {
1808 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 1814 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
1809 Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, cast(Gdip.Point[])pointArray, pointArray.length/2); 1815 Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length/2);
1810 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 1816 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
1811 return; 1817 return;
1812 } 1818 }
1813 if ((data.style & DWT.MIRRORED) !is 0) { 1819 if ((data.style & DWT.MIRRORED) !is 0) {
1814 if (data.lineWidth !is 0 && data.lineWidth % 2 is 0) { 1820 if (data.lineWidth !is 0 && data.lineWidth % 2 is 0) {
1849 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 1855 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
1850 checkGC(DRAW); 1856 checkGC(DRAW);
1851 auto gdipGraphics = data.gdipGraphics; 1857 auto gdipGraphics = data.gdipGraphics;
1852 if (gdipGraphics !is null) { 1858 if (gdipGraphics !is null) {
1853 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 1859 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
1854 Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, cast(Gdip.Point[])pointArray, pointArray.length / 2); 1860 Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2);
1855 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 1861 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
1856 return; 1862 return;
1857 } 1863 }
1858 if ((data.style & DWT.MIRRORED) !is 0) { 1864 if ((data.style & DWT.MIRRORED) !is 0) {
1859 if (data.lineWidth !is 0 && data.lineWidth % 2 is 0) { 1865 if (data.lineWidth !is 0 && data.lineWidth % 2 is 0) {
1896 public void drawRectangle (int x, int y, int width, int height) { 1902 public void drawRectangle (int x, int y, int width, int height) {
1897 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 1903 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
1898 checkGC(DRAW); 1904 checkGC(DRAW);
1899 auto gdipGraphics = data.gdipGraphics; 1905 auto gdipGraphics = data.gdipGraphics;
1900 if (gdipGraphics !is null) { 1906 if (gdipGraphics !is null) {
1907 if (width < 0) {
1908 x = x + width;
1909 width = -width;
1910 }
1911 if (height < 0) {
1912 y = y + height;
1913 height = -height;
1914 }
1901 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 1915 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
1902 Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height); 1916 Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height);
1903 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 1917 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
1904 return; 1918 return;
1905 } 1919 }
2034 naw = 0 - naw; 2048 naw = 0 - naw;
2035 if (nah < 0) 2049 if (nah < 0)
2036 nah = 0 - nah; 2050 nah = 0 - nah;
2037 2051
2038 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 2052 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
2039 auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 2053 if (naw is 0 || nah is 0) {
2040 if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 2054 Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height);
2041 if (nw > naw) { 2055 } else {
2042 if (nh > nah) { 2056 auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
2043 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); 2057 if (path is null) DWT.error(DWT.ERROR_NO_HANDLES);
2044 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); 2058 if (nw > naw) {
2045 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); 2059 if (nh > nah) {
2046 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); 2060 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90);
2061 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90);
2062 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90);
2063 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90);
2064 } else {
2065 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180);
2066 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180);
2067 }
2047 } else { 2068 } else {
2048 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); 2069 if (nh > nah) {
2049 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); 2070 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180);
2050 } 2071 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180);
2051 } else { 2072 } else {
2052 if (nh > nah) { 2073 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360);
2053 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 2074 }
2054 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 2075 }
2055 } else { 2076 Gdip.GraphicsPath_CloseFigure(path);
2056 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 2077 Gdip.Graphics_DrawPath(gdipGraphics, pen, path);
2057 } 2078 Gdip.GraphicsPath_delete(path);
2058 } 2079 }
2059 Gdip.GraphicsPath_CloseFigure(path);
2060 Gdip.Graphics_DrawPath(gdipGraphics, pen, path);
2061 Gdip.GraphicsPath_delete(path);
2062 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 2080 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
2063 } 2081 }
2064 2082
2065 /** 2083 /**
2066 * Draws the given string, using the receiver's current font and 2084 * Draws the given string, using the receiver's current font and
2314 auto format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); 2332 auto format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic());
2315 int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces; 2333 int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces;
2316 if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft; 2334 if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft;
2317 Gdip.StringFormat_SetFormatFlags(format, formatFlags); 2335 Gdip.StringFormat_SetFormatFlags(format, formatFlags);
2318 float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [ cast(float) measureSpace(data.gdipFont, format) * 8] : new float[1]; 2336 float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [ cast(float) measureSpace(data.gdipFont, format) * 8] : new float[1];
2319 Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs); 2337 Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs.ptr);
2320 int hotkeyPrefix = (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone; 2338 int hotkeyPrefix = (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone;
2321 if ((flags & DWT.DRAW_MNEMONIC) !is 0 && (data.uiState & OS.UISF_HIDEACCEL) !is 0) hotkeyPrefix = Gdip.HotkeyPrefixHide; 2339 if ((flags & DWT.DRAW_MNEMONIC) !is 0 && (data.uiState & OS.UISF_HIDEACCEL) !is 0) hotkeyPrefix = Gdip.HotkeyPrefixHide;
2322 Gdip.StringFormat_SetHotkeyPrefix(format, hotkeyPrefix); 2340 Gdip.StringFormat_SetHotkeyPrefix(format, hotkeyPrefix);
2323 if ((flags & DWT.DRAW_TRANSPARENT) is 0) { 2341 if ((flags & DWT.DRAW_TRANSPARENT) is 0) {
2324 Gdip.RectF bounds; 2342 Gdip.RectF bounds;
2766 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 2784 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
2767 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 2785 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
2768 checkGC(FILL); 2786 checkGC(FILL);
2769 if (data.gdipGraphics !is null) { 2787 if (data.gdipGraphics !is null) {
2770 int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; 2788 int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate;
2771 Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, cast(Gdip.Point[])pointArray, pointArray.length / 2, mode); 2789 Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2, mode);
2772 return; 2790 return;
2773 } 2791 }
2774 if ((data.style & DWT.MIRRORED) !is 0) { 2792 if ((data.style & DWT.MIRRORED) !is 0) {
2775 for (int i = 0; i < pointArray.length; i+=2) { 2793 for (int i = 0; i < pointArray.length; i+=2) {
2776 pointArray[i]--; 2794 pointArray[i]--;
2801 */ 2819 */
2802 public void fillRectangle (int x, int y, int width, int height) { 2820 public void fillRectangle (int x, int y, int width, int height) {
2803 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 2821 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
2804 checkGC(FILL); 2822 checkGC(FILL);
2805 if (data.gdipGraphics !is null) { 2823 if (data.gdipGraphics !is null) {
2824 if (width < 0) {
2825 x = x + width;
2826 width = -width;
2827 }
2828 if (height < 0) {
2829 y = y + height;
2830 height = -height;
2831 }
2806 Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height); 2832 Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height);
2807 return; 2833 return;
2808 } 2834 }
2809 int rop2 = 0; 2835 int rop2 = 0;
2810 static if (OS.IsWinCE) { 2836 static if (OS.IsWinCE) {
2884 if (naw < 0) 2910 if (naw < 0)
2885 naw = 0 - naw; 2911 naw = 0 - naw;
2886 if (nah < 0) 2912 if (nah < 0)
2887 nah = 0 - nah; 2913 nah = 0 - nah;
2888 2914
2889 auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 2915 if (naw is 0 || nah is 0) {
2890 if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 2916 Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height);
2891 if (nw > naw) { 2917 } else {
2892 if (nh > nah) { 2918 auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
2893 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); 2919 if (path is null) DWT.error(DWT.ERROR_NO_HANDLES);
2894 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); 2920 if (nw > naw) {
2895 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); 2921 if (nh > nah) {
2896 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); 2922 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90);
2923 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90);
2924 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90);
2925 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90);
2926 } else {
2927 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180);
2928 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180);
2929 }
2897 } else { 2930 } else {
2898 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); 2931 if (nh > nah) {
2899 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); 2932 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180);
2900 } 2933 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180);
2901 } else { 2934 } else {
2902 if (nh > nah) { 2935 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360);
2903 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 2936 }
2904 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 2937 }
2905 } else { 2938 Gdip.GraphicsPath_CloseFigure(path);
2906 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 2939 Gdip.Graphics_FillPath(gdipGraphics, brush, path);
2907 } 2940 Gdip.GraphicsPath_delete(path);
2908 } 2941 }
2909 Gdip.GraphicsPath_CloseFigure(path);
2910 Gdip.Graphics_FillPath(gdipGraphics, brush, path);
2911 Gdip.GraphicsPath_delete(path);
2912 } 2942 }
2913 2943
2914 void flush () { 2944 void flush () {
2915 if (data.gdipGraphics !is null) { 2945 if (data.gdipGraphics !is null) {
2916 Gdip.Graphics_Flush(data.gdipGraphics, 0); 2946 Gdip.Graphics_Flush(data.gdipGraphics, 0);
3267 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 3297 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
3268 * </ul> 3298 * </ul>
3269 */ 3299 */
3270 public Font getFont () { 3300 public Font getFont () {
3271 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 3301 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
3272 return Font.win32_new(data.device, data.hFont); 3302 return data.font;
3273 } 3303 }
3274 3304
3275 /** 3305 /**
3276 * Returns a FontMetrics which contains information 3306 * Returns a FontMetrics which contains information
3277 * about the font currently being used by the receiver 3307 * about the font currently being used by the receiver
3664 } 3694 }
3665 3695
3666 Gdip.Matrix identity() { 3696 Gdip.Matrix identity() {
3667 if ((data.style & DWT.MIRRORED) !is 0) { 3697 if ((data.style & DWT.MIRRORED) !is 0) {
3668 int width = 0; 3698 int width = 0;
3669 Image image = data.image; 3699 int technology = OS.GetDeviceCaps(handle, OS.TECHNOLOGY);
3670 if (image !is null) { 3700 if (technology is OS.DT_RASPRINTER) {
3701 width = OS.GetDeviceCaps(handle, OS.PHYSICALWIDTH);
3702 } else {
3703 Image image = data.image;
3704 if (image !is null) {
3671 BITMAP bm; 3705 BITMAP bm;
3672 OS.GetObject(image.handle, BITMAP.sizeof, &bm); 3706 OS.GetObject(image.handle, BITMAP.sizeof, &bm);
3673 width = bm.bmWidth; 3707 width = bm.bmWidth;
3674 } else if (data.hwnd !is null) { 3708 } else {
3675 RECT rect; 3709 HWND hwnd;
3676 OS.GetClientRect(data.hwnd, &rect); 3710 static if( OS.IsWinCE ){
3677 width = rect.right - rect.left; 3711 hwnd = data.hwnd;
3712 }
3713 else{
3714 hwnd = OS.WindowFromDC(handle);
3715 }
3716 if (hwnd !is null) {
3717 RECT rect;
3718 OS.GetClientRect(hwnd, &rect);
3719 width = rect.right - rect.left;
3720 } else {
3721 auto hBitmap = OS.GetCurrentObject(handle, OS.OBJ_BITMAP);
3722 BITMAP bm;
3723 OS.GetObject(hBitmap, BITMAP.sizeof, &bm);
3724 width = bm.bmWidth;
3725 }
3726 }
3678 } 3727 }
3679 POINT pt; 3728 POINT pt;
3680 static if (!OS.IsWinCE) OS.GetWindowOrgEx (handle, &pt); 3729 static if (!OS.IsWinCE) OS.GetWindowOrgEx (handle, &pt);
3681 return Gdip.Matrix_new(-1, 0, 0, 1, width + 2 * pt.x, 0); 3730 return Gdip.Matrix_new(-1, 0, 0, 1, width + 2 * pt.x, 0);
3682 } 3731 }
3695 data.state &= ~(BACKGROUND | BACKGROUND_TEXT | BRUSH); 3744 data.state &= ~(BACKGROUND | BACKGROUND_TEXT | BRUSH);
3696 } else { 3745 } else {
3697 data.background = OS.GetBkColor(hDC); 3746 data.background = OS.GetBkColor(hDC);
3698 } 3747 }
3699 data.state &= ~(NULL_BRUSH | NULL_PEN); 3748 data.state &= ~(NULL_BRUSH | NULL_PEN);
3700 auto hFont = data.hFont; 3749 Font font = data.font;
3701 if (hFont !is null && hFont !is cast(HFONT)-1 ) { 3750 if (font !is null) {
3702 data.state &= ~FONT; 3751 data.state &= ~FONT;
3703 } else { 3752 } else {
3704 data.hFont = OS.GetCurrentObject(hDC, OS.OBJ_FONT); 3753 data.font = Font.win32_new(device, OS.GetCurrentObject(hDC, OS.OBJ_FONT));
3705 } 3754 }
3706 auto hPalette = data.device.hPalette; 3755 auto hPalette = data.device.hPalette;
3707 if (hPalette !is null) { 3756 if (hPalette !is null) {
3708 OS.SelectPalette(hDC, hPalette, true); 3757 OS.SelectPalette(hDC, hPalette, true);
3709 OS.RealizePalette(hDC); 3758 OS.RealizePalette(hDC);
3761 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 3810 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
3762 * </ul> 3811 * </ul>
3763 */ 3812 */
3764 public bool isClipped() { 3813 public bool isClipped() {
3765 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 3814 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
3815 auto gdipGraphics = data.gdipGraphics;
3816 if (gdipGraphics !is null) {
3817 auto rgn = Gdip.Region_new();
3818 Gdip.Graphics_GetClip(data.gdipGraphics, rgn);
3819 bool isInfinite = Gdip.Region_IsInfinite(rgn, gdipGraphics) !is 0;
3820 Gdip.Region_delete(rgn);
3821 return !isInfinite;
3822 }
3766 auto region = OS.CreateRectRgn(0, 0, 0, 0); 3823 auto region = OS.CreateRectRgn(0, 0, 0, 0);
3767 auto result = OS.GetClipRgn(handle, region); 3824 int result = OS.GetClipRgn(handle, region);
3768 OS.DeleteObject(region); 3825 OS.DeleteObject(region);
3769 return result > 0; 3826 return result > 0;
3770 } 3827 }
3771 3828
3772 /** 3829 /**
4066 setClipping(cast(HRGN)null); 4123 setClipping(cast(HRGN)null);
4067 if (path !is null) { 4124 if (path !is null) {
4068 initGdip(); 4125 initGdip();
4069 int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; 4126 int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate;
4070 Gdip.GraphicsPath_SetFillMode(path.handle, mode); 4127 Gdip.GraphicsPath_SetFillMode(path.handle, mode);
4071 Gdip.Graphics_SetClip(data.gdipGraphics, path.handle); 4128 Gdip.Graphics_SetClipPath(data.gdipGraphics, path.handle);
4072 } 4129 }
4073 } 4130 }
4074 4131
4075 /** 4132 /**
4076 * Sets the area of the receiver which can be changed 4133 * Sets the area of the receiver which can be changed
4161 * </ul> 4218 * </ul>
4162 */ 4219 */
4163 public void setFont (Font font) { 4220 public void setFont (Font font) {
4164 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 4221 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
4165 if (font !is null && font.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 4222 if (font !is null && font.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
4166 data.hFont = font !is null ? font.handle : data.device.systemFont; 4223 data.font = font !is null ? font : data.device.systemFont;
4167 data.state &= ~FONT; 4224 data.state &= ~FONT;
4168 } 4225 }
4169 4226
4170 /** 4227 /**
4171 * Sets the foreground color. The foreground color is used 4228 * Sets the foreground color. The foreground color is used
4325 break; 4382 break;
4326 default: 4383 default:
4327 DWT.error(DWT.ERROR_INVALID_ARGUMENT); 4384 DWT.error(DWT.ERROR_INVALID_ARGUMENT);
4328 } 4385 }
4329 } 4386 }
4330 int cap = attributes.join; 4387 int cap = attributes.cap;
4331 if (cap !is data.lineCap) { 4388 if (cap !is data.lineCap) {
4332 mask |= LINE_CAP; 4389 mask |= LINE_CAP;
4333 switch (cap) { 4390 switch (cap) {
4334 case DWT.JOIN_MITER: 4391 case DWT.JOIN_MITER:
4335 case DWT.JOIN_ROUND: 4392 case DWT.JOIN_ROUND:
4798 auto format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic()); 4855 auto format = Gdip.StringFormat_Clone(Gdip.StringFormat_GenericTypographic());
4799 int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces; 4856 int formatFlags = Gdip.StringFormat_GetFormatFlags(format) | Gdip.StringFormatFlagsMeasureTrailingSpaces;
4800 if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft; 4857 if ((data.style & DWT.MIRRORED) !is 0) formatFlags |= Gdip.StringFormatFlagsDirectionRightToLeft;
4801 Gdip.StringFormat_SetFormatFlags(format, formatFlags); 4858 Gdip.StringFormat_SetFormatFlags(format, formatFlags);
4802 float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [measureSpace(data.gdipFont, format) * 8] : new float[1]; 4859 float[] tabs = (flags & DWT.DRAW_TAB) !is 0 ? [measureSpace(data.gdipFont, format) * 8] : new float[1];
4803 Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs); 4860 Gdip.StringFormat_SetTabStops(format, 0, tabs.length, tabs.ptr);
4804 Gdip.StringFormat_SetHotkeyPrefix(format, (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone); 4861 Gdip.StringFormat_SetHotkeyPrefix(format, (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone);
4805 Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, length_, data.gdipFont, pt, format, bounds); 4862 Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, length_, data.gdipFont, pt, format, bounds);
4806 Gdip.StringFormat_delete(format); 4863 Gdip.StringFormat_delete(format);
4807 return new Point(length_ is 0 ? 0 : Math.rndint(bounds.Width), Math.rndint(bounds.Height)); 4864 return new Point(length_ is 0 ? 0 : Math.rndint(bounds.Width), Math.rndint(bounds.Height));
4808 } 4865 }
4874 * @return a new <code>GC</code> 4931 * @return a new <code>GC</code>
4875 */ 4932 */
4876 public static GC win32_new(HDC hDC, GCData data) { 4933 public static GC win32_new(HDC hDC, GCData data) {
4877 GC gc = new GC(); 4934 GC gc = new GC();
4878 gc.device = data.device; 4935 gc.device = data.device;
4936 data.style |= DWT.LEFT_TO_RIGHT;
4937 if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
4938 int flags = OS.GetLayout (hDC);
4939 if ((flags & OS.LAYOUT_RTL) !is 0) {
4940 data.style |= DWT.RIGHT_TO_LEFT | DWT.MIRRORED;
4941 }
4942 }
4879 gc.init_(null, data, hDC); 4943 gc.init_(null, data, hDC);
4880 return gc; 4944 return gc;
4881 } 4945 }
4882 4946
4883 } 4947 }