Changeset 213:36f5cb12e1a2 for dwt/graphics/GC.d
- Timestamp:
- 05/17/08 11:34:28 (8 months ago)
- Files:
-
- dwt/graphics/GC.d (modified) (32 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/graphics/GC.d
r212 r213 74 74 public final class GC : Resource { 75 75 76 alias Resource.init_ init_; 77 76 78 /** 77 79 * the handle to the OS device context … … 182 184 this.device = data.device = device; 183 185 init_ (drawable, data, hDC); 184 i f (device.tracking) device.new_Object(this);186 init_(); 185 187 } 186 188 … … 264 266 } 265 267 if (dashes !is null) { 266 Gdip.Pen_SetDashPattern(pen, dashes , dashes.length);268 Gdip.Pen_SetDashPattern(pen, dashes.ptr, dashes.length); 267 269 Gdip.Pen_SetDashStyle(pen, Gdip.DashStyleCustom); 268 270 Gdip.Pen_SetDashOffset(pen, dashOffset); … … 324 326 } 325 327 if ((state & FONT) !is 0) { 326 OS.SelectObject(handle, data.hFont); 327 auto font = createGdipFont(handle, data.hFont); 328 Font font = data.font; 329 OS.SelectObject(handle, font.handle); 330 auto gdipFont = createGdipFont(handle, font.handle); 328 331 if (data.gdipFont !is null) Gdip.Font_delete(data.gdipFont); 329 data.gdipFont = font;332 data.gdipFont = gdipFont; 330 333 } 331 334 if ((state & DRAW_OFFSET) !is 0) { 332 335 data.gdipXOffset = data.gdipYOffset = 0; 333 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 338 Gdip.Graphics_GetTransform(gdipGraphics, matrix); 336 Gdip.Matrix_ GetElements(matrix, elements);339 Gdip.Matrix_TransformPoints(matrix, cast(Gdip.PointF*)point.ptr, 1); 337 340 Gdip.Matrix_delete(matrix); 338 float scaling = elements[0];341 float scaling = point[0]; 339 342 if (scaling < 0) scaling = -scaling; 340 343 float penWidth = data.lineWidth * scaling; … … 342 345 data.gdipXOffset = 0.5f / scaling; 343 346 } 344 scaling = elements[3];347 scaling = point[1]; 345 348 if (scaling < 0) scaling = -scaling; 346 349 penWidth = data.lineWidth * scaling; … … 440 443 } 441 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 } … … 628 632 * </ul> 629 633 */ 630 override public void dispose() { 631 if (handle is null) return; 632 if (data.device.isDisposed()) return; 633 634 void destroy() { 635 bool gdip = data.gdipGraphics !is null; 634 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 641 /* Select stock pen and brush objects and free resources */ … … 662 667 * Dispose the HDC. 663 668 */ 664 Device device = data.device;665 669 if (drawable !is null) drawable.internal_dispose_GC(handle, data); 666 670 drawable = null; … … 668 672 data.image = null; 669 673 data.ps = null; 670 if (device.tracking) device.dispose_Object(this);671 data.device = null;672 674 data = null; 673 675 } … … 817 819 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 818 820 if ((data.uiState & OS.UISF_HIDEFOCUS) !is 0) return; 821 data.focusDrawn = true; 819 822 HDC hdc = handle; 820 823 int state = 0; … … 838 841 if (!Gdip.Matrix_IsIdentity(matrix)) { 839 842 gotElements = true; 840 Gdip.Matrix_GetElements(matrix, lpXform );843 Gdip.Matrix_GetElements(matrix, lpXform.ptr); 841 844 } 842 845 Gdip.Matrix_delete(matrix); 843 846 hdc = Gdip.Graphics_GetHDC(gdipGraphics); 844 847 state = OS.SaveDC(hdc); 845 OS.SetBkColor(hdc, data.background);846 OS.SetTextColor(hdc, data.foreground);847 848 if (gotElements) { 848 849 OS.SetGraphicsMode(hdc, OS.GM_ADVANCED); … … 854 855 } 855 856 } 857 OS.SetBkColor(hdc, 0xFFFFFF); 858 OS.SetTextColor(hdc, 0x000000); 856 859 RECT rect; 857 860 OS.SetRect(&rect, x, y, x + width, y + height); … … 860 863 OS.RestoreDC(hdc, state); 861 864 Gdip.Graphics_ReleaseHDC(gdipGraphics, hdc); 865 } else { 866 data.state &= ~(BACKGROUND_TEXT | FOREGROUND_TEXT); 862 867 } 863 868 } … … 935 940 if (data.gdipGraphics !is null) { 936 941 //TODO - cache bitmap 937 int [] gdipImage = srcImage.createGdipImage();942 int /*long*/ [] gdipImage = srcImage.createGdipImage(); 938 943 auto img = cast(Gdip.Image) gdipImage[0]; 939 944 int imgWidth = Gdip.Image_GetWidth(img); … … 1427 1432 auto srcHdc = OS.CreateCompatibleDC(handle); 1428 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 1436 HDC tempHdc; 1431 1437 HBITMAP tempBitmap; … … 1807 1813 if (gdipGraphics !is null) { 1808 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 1816 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 1811 1817 return; … … 1852 1858 if (gdipGraphics !is null) { 1853 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 1861 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 1856 1862 return; … … 1899 1905 auto gdipGraphics = data.gdipGraphics; 1900 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 1915 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 1902 1916 Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height); … … 2037 2051 2038 2052 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 2039 auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 2040 if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 2041 if (nw > naw) { 2042 if (nh > nah) { 2043 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); 2044 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); 2045 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); 2046 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); 2053 if (naw is 0 || nah is 0) { 2054 Gdip.Graphics_DrawRectangle(gdipGraphics, data.gdipPen, x, y, width, height); 2055 } else { 2056 auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 2057 if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 2058 if (nw > naw) { 2059 if (nh > nah) { 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 2068 } else { 2048 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); 2049 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); 2050 } 2051 } else { 2052 if (nh > nah) { 2053 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 2054 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 2055 } else { 2056 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 2057 } 2058 } 2059 Gdip.GraphicsPath_CloseFigure(path); 2060 Gdip.Graphics_DrawPath(gdipGraphics, pen, path); 2061 Gdip.GraphicsPath_delete(path); 2069 if (nh > nah) { 2070 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 2071 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 2072 } else { 2073 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 2074 } 2075 } 2076 Gdip.GraphicsPath_CloseFigure(path); 2077 Gdip.Graphics_DrawPath(gdipGraphics, pen, path); 2078 Gdip.GraphicsPath_delete(path); 2079 } 2062 2080 Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend); 2063 2081 } … … 2317 2335 Gdip.StringFormat_SetFormatFlags(format, formatFlags); 2318 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 2338 int hotkeyPrefix = (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone; 2321 2339 if ((flags & DWT.DRAW_MNEMONIC) !is 0 && (data.uiState & OS.UISF_HIDEACCEL) !is 0) hotkeyPrefix = Gdip.HotkeyPrefixHide; … … 2769 2787 if (data.gdipGraphics !is null) { 2770 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 2790 return; 2773 2791 } … … 2804 2822 checkGC(FILL); 2805 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 2832 Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height); 2807 2833 return; … … 2887 2913 nah = 0 - nah; 2888 2914 2889 auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 2890 if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 2891 if (nw > naw) { 2892 if (nh > nah) { 2893 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nah, 0, -90); 2894 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nah, -90, -90); 2895 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, naw, nah, -180, -90); 2896 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny + nh - nah, naw, nah, -270, -90); 2915 if (naw is 0 || nah is 0) { 2916 Gdip.Graphics_FillRectangle(data.gdipGraphics, data.gdipBrush, x, y, width, height); 2917 } else { 2918 auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 2919 if (path is null) DWT.error(DWT.ERROR_NO_HANDLES); 2920 if (nw > naw) { 2921 if (nh > nah) { 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 2930 } else { 2898 Gdip.GraphicsPath_AddArc(path, nx + nw - naw, ny, naw, nh, -270, -180); 2899 Gdip.GraphicsPath_AddArc(path, nx, ny, naw, nh, -90, -180); 2900 } 2901 } else { 2902 if (nh > nah) { 2903 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 2904 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 2905 } else { 2906 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 2907 } 2908 } 2909 Gdip.GraphicsPath_CloseFigure(path); 2910 Gdip.Graphics_FillPath(gdipGraphics, brush, path); 2911 Gdip.GraphicsPath_delete(path); 2931 if (nh > nah) { 2932 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nah, 0, -180); 2933 Gdip.GraphicsPath_AddArc(path, nx, ny + nh - nah, nw, nah, -180, -180); 2934 } else { 2935 Gdip.GraphicsPath_AddArc(path, nx, ny, nw, nh, 0, 360); 2936 } 2937 } 2938 Gdip.GraphicsPath_CloseFigure(path); 2939 Gdip.Graphics_FillPath(gdipGraphics, brush, path); 2940 Gdip.GraphicsPath_delete(path); 2941 } 2912 2942 } 2913 2943 … … 3270 3300 public Font getFont () { 3271 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 … … 3667 3697 if ((data.style & DWT.MIRRORED) !is 0) { 3668 3698 int width = 0; 3669 Image image = data.image; 3670 if (image !is null) { 3699 int technology = OS.GetDeviceCaps(handle, OS.TECHNOLOGY); 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 3705 BITMAP bm; 3672 3706 OS.GetObject(image.handle, BITMAP.sizeof, &bm); 3673 width = bm.bmWidth; 3674 } else if (data.hwnd !is null) { 3675 RECT rect; 3676 OS.GetClientRect(data.hwnd, &rect); 3677 width = rect.right - rect.left; 3707 width = bm.bmWidth; 3708 } else { 3709 HWND hwnd; 3710 static if( OS.IsWinCE ){ 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 3728 POINT pt; … … 3698 3747 } 3699 3748 data.state &= ~(NULL_BRUSH | NULL_PEN); 3700 auto hFont = data.hFont;3701 if ( hFont !is null && hFont !is cast(HFONT)-1) {3749 Font font = data.font; 3750 if (font !is null) { 3702 3751 data.state &= ~FONT; 3703 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 3755 auto hPalette = data.device.hPalette; … … 3764 3813 public bool isClipped() { 3765 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 3823 auto region = OS.CreateRectRgn(0, 0, 0, 0); 3767 autoresult = OS.GetClipRgn(handle, region);3824 int result = OS.GetClipRgn(handle, region); 3768 3825 OS.DeleteObject(region); 3769 3826 return result > 0; … … 4069 4126 int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; 4070 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 } … … 4164 4221 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 4165 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 4224 data.state &= ~FONT; 4168 4225 } … … 4328 4385 } 4329 4386 } 4330 int cap = attributes. join;4387 int cap = attributes.cap; 4331 4388 if (cap !is data.lineCap) { 4332 4389 mask |= LINE_CAP; … … 4801 4858 Gdip.StringFormat_SetFormatFlags(format, formatFlags); 4802 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 4861 Gdip.StringFormat_SetHotkeyPrefix(format, (flags & DWT.DRAW_MNEMONIC) !is 0 ? Gdip.HotkeyPrefixShow : Gdip.HotkeyPrefixNone); 4805 4862 Gdip.Graphics_MeasureString(data.gdipGraphics, buffer, length_, data.gdipFont, pt, format, bounds); … … 4877 4934 GC gc = new GC(); 4878 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 4943 gc.init_(null, data, hDC); 4880 4944 return gc;
