Mercurial > dwindows
comparison win/dw.c @ 1631:0e6c2aeed041
Got anti-aliased drawing working with GDI+ on Windows.
Problem was I was specifying 0 in the alpha field making everything
drawn invisible. dw_draw_arc() isn't working quite right but the
rest appears to be working in anti-aliased mode.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 28 Mar 2012 18:33:54 +0000 |
parents | 48fabb2f93c5 |
children | fdf874f25076 |
comparison
equal
deleted
inserted
replaced
1630:48fabb2f93c5 | 1631:0e6c2aeed041 |
---|---|
97 typedef enum { | 97 typedef enum { |
98 FlushIntentionFlush = 0, | 98 FlushIntentionFlush = 0, |
99 FlushIntentionSync = 1 | 99 FlushIntentionSync = 1 |
100 } GpFlushIntention; | 100 } GpFlushIntention; |
101 | 101 |
102 typedef enum { | |
103 QualityModeInvalid = -1, | |
104 QualityModeDefault = 0, | |
105 QualityModeLow = 1, | |
106 QualityModeHigh = 2 | |
107 } QualityMode; | |
108 | |
109 typedef enum { | |
110 SmoothingModeInvalid = QualityModeInvalid, | |
111 SmoothingModeDefault = QualityModeDefault, | |
112 SmoothingModeHighSpeed = QualityModeLow, | |
113 SmoothingModeHighQuality = QualityModeHigh, | |
114 SmoothingModeNone, | |
115 SmoothingModeAntiAlias | |
116 } SmoothingMode; | |
117 | |
102 typedef void GpGraphics; | 118 typedef void GpGraphics; |
103 typedef void GpPen; | 119 typedef void GpPen; |
120 typedef void GpBrush; | |
104 typedef void GpBitmap; | 121 typedef void GpBitmap; |
105 typedef void GpImage; | 122 typedef void GpImage; |
106 typedef POINT GpPoint; | 123 typedef POINT GpPoint; |
107 typedef DWORD ARGB; | 124 typedef DWORD ARGB; |
108 typedef float REAL; | 125 typedef float REAL; |
129 GpStatus WINAPI GdiplusStartup(ULONG_PTR *token, const struct GdiplusStartupInput *input, void *output); | 146 GpStatus WINAPI GdiplusStartup(ULONG_PTR *token, const struct GdiplusStartupInput *input, void *output); |
130 VOID WINAPI GdiplusShutdown(ULONG_PTR token); | 147 VOID WINAPI GdiplusShutdown(ULONG_PTR token); |
131 /* Drawing functions */ | 148 /* Drawing functions */ |
132 GpStatus WINAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics); | 149 GpStatus WINAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics); |
133 GpStatus WINAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics); | 150 GpStatus WINAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics); |
151 GpStatus WINAPI GdipDeleteGraphics(GpGraphics *graphics); | |
152 GpStatus WINAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode smoothingMode); | |
153 GpStatus WINAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit, GpPen **pen); | |
154 GpStatus WINAPI GdipDeletePen(GpPen *pen); | |
155 GpStatus WINAPI GdipCreateSolidFill(ARGB color, GpBrush **brush); | |
156 GpStatus WINAPI GdipDeleteBrush(GpBrush *brush); | |
157 GpStatus WINAPI GdipSetSolidFillColor(GpBrush *brush, ARGB color); | |
134 GpStatus WINAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1, INT y1, INT x2, INT y2); | 158 GpStatus WINAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1, INT y1, INT x2, INT y2); |
135 GpStatus WINAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, const GpPoint *points, INT count); | 159 GpStatus WINAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, const GpPoint *points, INT count); |
136 GpStatus WINAPI GdipDeleteGraphics(GpGraphics *graphics); | 160 GpStatus WINAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x, INT y, INT width, INT height); |
137 GpStatus WINAPI GdipCreatePen1(ARGB color, REAL width, GpUnit unit, GpPen **pen); | 161 GpStatus WINAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush, INT x, INT y, INT width, INT height); |
138 GpStatus WINAPI GdipDeletePen(GpPen *pen); | 162 GpStatus WINAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x, INT y, INT width, INT height, REAL startAngle, REAL sweepAngle); |
163 GpStatus WINAPI GdipDrawPolygonI(GpGraphics *graphics, GpPen *pen, const GpPoint *points, INT count); | |
164 GpStatus WINAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush, const GpPoint *points, INT count); | |
165 GpStatus WINAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x, INT y, INT width, INT height); | |
166 GpStatus WINAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x, INT y, INT width, INT height); | |
139 GpStatus WINAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention); | 167 GpStatus WINAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention); |
140 | 168 |
141 /* Pixel format information */ | 169 /* Pixel format information */ |
142 #define PixelFormatIndexed 0x00010000 | 170 #define PixelFormatIndexed 0x00010000 |
143 #define PixelFormatGDI 0x00020000 | 171 #define PixelFormatGDI 0x00020000 |
244 DWORD _background; | 272 DWORD _background; |
245 DWORD _hPen; | 273 DWORD _hPen; |
246 DWORD _hBrush; | 274 DWORD _hBrush; |
247 #ifdef GDIPLUS | 275 #ifdef GDIPLUS |
248 DWORD _gpPen; | 276 DWORD _gpPen; |
277 DWORD _gpBrush; | |
249 #endif | 278 #endif |
250 | 279 |
251 BYTE _red[] = { 0x00, 0xbb, 0x00, 0xaa, 0x00, 0xbb, 0x00, 0xaa, 0x77, | 280 BYTE _red[] = { 0x00, 0xbb, 0x00, 0xaa, 0x00, 0xbb, 0x00, 0xaa, 0x77, |
252 0xff, 0x00, 0xee, 0x00, 0xff, 0x00, 0xff, 0xaa, 0x00 }; | 281 0xff, 0x00, 0xee, 0x00, 0xff, 0x00, 0xff, 0xaa, 0x00 }; |
253 BYTE _green[] = { 0x00, 0x00, 0xbb, 0xaa, 0x00, 0x00, 0xbb, 0xaa, 0x77, | 282 BYTE _green[] = { 0x00, 0x00, 0xbb, 0xaa, 0x00, 0x00, 0xbb, 0xaa, 0x77, |
3776 void _init_thread(void) | 3805 void _init_thread(void) |
3777 { | 3806 { |
3778 COLORREF foreground = RGB(128,128,128); | 3807 COLORREF foreground = RGB(128,128,128); |
3779 COLORREF background = DW_RGB_TRANSPARENT; | 3808 COLORREF background = DW_RGB_TRANSPARENT; |
3780 #ifdef GDIPLUS | 3809 #ifdef GDIPLUS |
3781 ARGB gpfore = MAKEARGB(0, 128, 128, 128); | 3810 ARGB gpfore = MAKEARGB(255, 128, 128, 128); |
3811 GpBrush *brush; | |
3782 GpPen *pen; | 3812 GpPen *pen; |
3783 | 3813 |
3784 GdipCreatePen1(gpfore, 1.0, UnitPixel, &pen); | 3814 GdipCreatePen1(gpfore, 1.0, UnitPixel, &pen); |
3785 TlsSetValue(_gpPen, (LPVOID)pen); | 3815 TlsSetValue(_gpPen, (LPVOID)pen); |
3816 GdipCreateSolidFill(gpfore, &brush); | |
3817 TlsSetValue(_gpBrush, (LPVOID)brush); | |
3786 #endif | 3818 #endif |
3787 TlsSetValue(_foreground, (LPVOID)foreground); | 3819 TlsSetValue(_foreground, (LPVOID)foreground); |
3788 TlsSetValue(_background, (LPVOID)background); | 3820 TlsSetValue(_background, (LPVOID)background); |
3789 TlsSetValue(_hPen, CreatePen(PS_SOLID, 1, foreground)); | 3821 TlsSetValue(_hPen, CreatePen(PS_SOLID, 1, foreground)); |
3790 TlsSetValue(_hBrush, CreateSolidBrush(foreground)); | 3822 TlsSetValue(_hBrush, CreateSolidBrush(foreground)); |
3827 _background = TlsAlloc(); | 3859 _background = TlsAlloc(); |
3828 _hPen = TlsAlloc(); | 3860 _hPen = TlsAlloc(); |
3829 _hBrush = TlsAlloc(); | 3861 _hBrush = TlsAlloc(); |
3830 #ifdef GDIPLUS | 3862 #ifdef GDIPLUS |
3831 _gpPen = TlsAlloc(); | 3863 _gpPen = TlsAlloc(); |
3864 _gpBrush = TlsAlloc(); | |
3832 #endif | 3865 #endif |
3833 | 3866 |
3834 icc.dwSize = sizeof(INITCOMMONCONTROLSEX); | 3867 icc.dwSize = sizeof(INITCOMMONCONTROLSEX); |
3835 icc.dwICC = ICC_WIN95_CLASSES|ICC_DATE_CLASSES; | 3868 icc.dwICC = ICC_WIN95_CLASSES|ICC_DATE_CLASSES; |
3836 | 3869 |
9562 { | 9595 { |
9563 HPEN hPen = TlsGetValue(_hPen); | 9596 HPEN hPen = TlsGetValue(_hPen); |
9564 HBRUSH hBrush = TlsGetValue(_hBrush); | 9597 HBRUSH hBrush = TlsGetValue(_hBrush); |
9565 COLORREF foreground; | 9598 COLORREF foreground; |
9566 #ifdef GDIPLUS | 9599 #ifdef GDIPLUS |
9600 GpBrush *brush = TlsGetValue(_gpBrush); | |
9567 GpPen *pen = TlsGetValue(_gpPen); | 9601 GpPen *pen = TlsGetValue(_gpPen); |
9568 ARGB gpfore; | 9602 ARGB gpfore; |
9569 #endif | 9603 #endif |
9570 | 9604 |
9571 value = _internal_color(value); | 9605 value = _internal_color(value); |
9572 foreground = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); | 9606 foreground = RGB(DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); |
9573 #ifdef GDIPLUS | 9607 #ifdef GDIPLUS |
9574 gpfore = MAKEARGB(0, DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); | 9608 gpfore = MAKEARGB(255, DW_RED_VALUE(value), DW_GREEN_VALUE(value), DW_BLUE_VALUE(value)); |
9575 | 9609 |
9576 GdipDeletePen(pen); | 9610 GdipDeletePen(pen); |
9577 GdipCreatePen1(gpfore, 1.0, UnitPixel, &pen); | 9611 GdipCreatePen1(gpfore, 1.0, UnitPixel, &pen); |
9578 TlsSetValue(_gpPen, (LPVOID)pen); | 9612 TlsSetValue(_gpPen, (LPVOID)pen); |
9613 GdipSetSolidFillColor(brush, gpfore); | |
9579 #endif | 9614 #endif |
9580 | 9615 |
9581 DeleteObject(hPen); | 9616 DeleteObject(hPen); |
9582 DeleteObject(hBrush); | 9617 DeleteObject(hBrush); |
9583 TlsSetValue(_foreground, (LPVOID)foreground); | 9618 TlsSetValue(_foreground, (LPVOID)foreground); |
9664 * x2: Second X coordinate. | 9699 * x2: Second X coordinate. |
9665 * y2: Second Y coordinate. | 9700 * y2: Second Y coordinate. |
9666 */ | 9701 */ |
9667 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) | 9702 void API dw_draw_line(HWND handle, HPIXMAP pixmap, int x1, int y1, int x2, int y2) |
9668 { | 9703 { |
9669 #ifdef GDIPLUS1 | 9704 #ifdef GDIPLUS |
9670 GpGraphics *graphics = NULL; | 9705 GpGraphics *graphics = NULL; |
9671 GpPen *pen = TlsGetValue(_gpPen); | 9706 GpPen *pen = TlsGetValue(_gpPen); |
9672 | 9707 |
9673 if(handle) | 9708 if(handle) |
9674 GdipCreateFromHWND(handle, &graphics); | 9709 GdipCreateFromHWND(handle, &graphics); |
9675 else if(pixmap) | 9710 else if(pixmap) |
9676 GdipCreateFromHDC(pixmap->hdc, &graphics); | 9711 GdipCreateFromHDC(pixmap->hdc, &graphics); |
9677 else | 9712 else |
9678 return; | 9713 return; |
9679 | 9714 |
9715 GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias); | |
9680 GdipDrawLineI(graphics, pen, x1, y1, x2, y2); | 9716 GdipDrawLineI(graphics, pen, x1, y1, x2, y2); |
9681 GdipFlush(graphics, FlushIntentionSync); | |
9682 GdipDeleteGraphics(graphics); | 9717 GdipDeleteGraphics(graphics); |
9683 #else | 9718 #else |
9684 HDC hdcPaint; | 9719 HDC hdcPaint; |
9685 HPEN oldPen; | 9720 HPEN oldPen; |
9686 | 9721 |
9702 if(!pixmap) | 9737 if(!pixmap) |
9703 ReleaseDC(handle, hdcPaint); | 9738 ReleaseDC(handle, hdcPaint); |
9704 #endif | 9739 #endif |
9705 } | 9740 } |
9706 | 9741 |
9742 /* Internal function to generate POINT arrays used by Windows APIs */ | |
9743 POINT *_makePoints(int *npoints, int *x, int *y) | |
9744 { | |
9745 POINT *points; | |
9746 int i; | |
9747 | |
9748 /* | |
9749 * Allocate enough space for the number of points supplied plus 1. | |
9750 * Under windows, unless the first and last points are the same | |
9751 * the polygon won't be closed | |
9752 */ | |
9753 points = (POINT *)malloc( ((*npoints)+1) * sizeof(POINT) ); | |
9754 | |
9755 if(points) | |
9756 { | |
9757 for ( i = 0 ; i < *npoints ; i++ ) | |
9758 { | |
9759 points[i].x = x[i]; | |
9760 points[i].y = y[i]; | |
9761 } | |
9762 if ( !( points[0].x == points[(*npoints)-1].x | |
9763 && points[0].y == points[(*npoints)-1].y ) ) | |
9764 { | |
9765 /* set the last point to be the same as the first point... */ | |
9766 points[*npoints].x = points[0].x; | |
9767 points[*npoints].y = points[0].y; | |
9768 /* ... and increment the number of points */ | |
9769 (*npoints)++; | |
9770 } | |
9771 } | |
9772 return points; | |
9773 } | |
9774 | |
9707 /* Draw a closed polygon on a window (preferably a render window). | 9775 /* Draw a closed polygon on a window (preferably a render window). |
9708 * Parameters: | 9776 * Parameters: |
9709 * handle: Handle to the window. | 9777 * handle: Handle to the window. |
9710 * pixmap: Handle to the pixmap. (choose only one of these) | 9778 * pixmap: Handle to the pixmap. (choose only one of these) |
9711 * flags: DW_DRAW_FILL (1) to fill the polygon or DW_DRAW_DEFAULT (0). | 9779 * flags: DW_DRAW_FILL (1) to fill the polygon or DW_DRAW_DEFAULT (0). |
9713 * x[]: X coordinates. | 9781 * x[]: X coordinates. |
9714 * y[]: Y coordinates. | 9782 * y[]: Y coordinates. |
9715 */ | 9783 */ |
9716 void API dw_draw_polygon(HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y) | 9784 void API dw_draw_polygon(HWND handle, HPIXMAP pixmap, int flags, int npoints, int *x, int *y) |
9717 { | 9785 { |
9718 HDC hdcPaint; | |
9719 HBRUSH oldBrush; | |
9720 HPEN oldPen; | |
9721 POINT *points = NULL; | 9786 POINT *points = NULL; |
9722 int i; | 9787 |
9723 | 9788 /* Sanity check */ |
9724 if ( handle ) | 9789 if(npoints < 1) |
9725 hdcPaint = GetDC( handle ); | 9790 return; |
9726 else if ( pixmap ) | 9791 |
9727 hdcPaint = pixmap->hdc; | 9792 #ifdef GDIPLUS |
9793 if(!(flags & DW_DRAW_NOAA)) | |
9794 { | |
9795 GpGraphics *graphics = NULL; | |
9796 | |
9797 if(handle) | |
9798 GdipCreateFromHWND(handle, &graphics); | |
9799 else if(pixmap) | |
9800 GdipCreateFromHDC(pixmap->hdc, &graphics); | |
9801 else | |
9802 return; | |
9803 | |
9804 GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias); | |
9805 if((points = _makePoints(&npoints, x, y))) | |
9806 { | |
9807 if(flags & DW_DRAW_FILL) | |
9808 { | |
9809 GpBrush *brush = TlsGetValue(_gpBrush); | |
9810 | |
9811 GdipFillPolygon2I(graphics, brush, points, npoints); | |
9812 } | |
9813 else | |
9814 { | |
9815 GpPen *pen = TlsGetValue(_gpPen); | |
9816 | |
9817 GdipDrawPolygonI(graphics, pen, points, npoints); | |
9818 } | |
9819 } | |
9820 GdipDeleteGraphics(graphics); | |
9821 } | |
9728 else | 9822 else |
9729 return; | 9823 #endif |
9730 if ( npoints ) | 9824 { |
9731 { | 9825 HDC hdcPaint; |
9732 /* | 9826 |
9733 * Allocate enough space for the number of points supplied plus 1. | 9827 if ( handle ) |
9734 * Under windows, unless the first and last points are the same | 9828 hdcPaint = GetDC( handle ); |
9735 * the polygon won't be closed | 9829 else if ( pixmap ) |
9736 */ | 9830 hdcPaint = pixmap->hdc; |
9737 points = (POINT *)malloc( (npoints+1) * sizeof(POINT) ); | 9831 else |
9738 /* | 9832 return; |
9739 * should check for NULL pointer return! | 9833 |
9740 */ | 9834 if((points = _makePoints(&npoints, x, y))) |
9741 for ( i = 0 ; i < npoints ; i++ ) | 9835 { |
9742 { | 9836 HBRUSH oldBrush = SelectObject( hdcPaint, TlsGetValue(_hBrush) ); |
9743 points[i].x = x[i]; | 9837 HPEN oldPen = SelectObject( hdcPaint, TlsGetValue(_hPen) ); |
9744 points[i].y = y[i]; | 9838 |
9745 } | 9839 if ( flags & DW_DRAW_FILL ) |
9746 if ( !( points[0].x == points[npoints-1].x | 9840 Polygon( hdcPaint, points, npoints ); |
9747 && points[0].y == points[npoints-1].y ) ) | 9841 else |
9748 { | 9842 Polyline( hdcPaint, points, npoints ); |
9749 /* set the last point to be the same as the first point... */ | 9843 |
9750 points[npoints].x = points[0].x; | 9844 SelectObject( hdcPaint, oldBrush ); |
9751 points[npoints].y = points[0].y; | 9845 SelectObject( hdcPaint, oldPen ); |
9752 /* ... and increment the number of points */ | 9846 } |
9753 npoints++; | 9847 |
9754 } | 9848 if ( !pixmap ) |
9755 } | 9849 ReleaseDC( handle, hdcPaint ); |
9756 else | 9850 } |
9757 return; | 9851 if(points) |
9758 | 9852 free(points); |
9759 oldBrush = SelectObject( hdcPaint, TlsGetValue(_hBrush) ); | |
9760 oldPen = SelectObject( hdcPaint, TlsGetValue(_hPen) ); | |
9761 if ( flags & DW_DRAW_FILL ) | |
9762 Polygon( hdcPaint, points, npoints ); | |
9763 else | |
9764 Polyline( hdcPaint, points, npoints ); | |
9765 SelectObject( hdcPaint, oldBrush ); | |
9766 SelectObject( hdcPaint, oldPen ); | |
9767 if ( !pixmap ) | |
9768 ReleaseDC( handle, hdcPaint ); | |
9769 free(points); | |
9770 } | 9853 } |
9771 | 9854 |
9772 /* Draw a rectangle on a window (preferably a render window). | 9855 /* Draw a rectangle on a window (preferably a render window). |
9773 * Parameters: | 9856 * Parameters: |
9774 * handle: Handle to the window. | 9857 * handle: Handle to the window. |
9779 * width: Width of rectangle. | 9862 * width: Width of rectangle. |
9780 * height: Height of rectangle. | 9863 * height: Height of rectangle. |
9781 */ | 9864 */ |
9782 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height) | 9865 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height) |
9783 { | 9866 { |
9784 HDC hdcPaint; | 9867 #ifdef GDIPLUS |
9785 RECT Rect; | 9868 if(!(flags & DW_DRAW_NOAA)) |
9786 | 9869 { |
9787 if(handle) | 9870 GpGraphics *graphics = NULL; |
9788 hdcPaint = GetDC(handle); | 9871 |
9789 else if(pixmap) | 9872 if(handle) |
9790 hdcPaint = pixmap->hdc; | 9873 GdipCreateFromHWND(handle, &graphics); |
9874 else if(pixmap) | |
9875 GdipCreateFromHDC(pixmap->hdc, &graphics); | |
9876 else | |
9877 return; | |
9878 | |
9879 GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias); | |
9880 if(flags & DW_DRAW_FILL) | |
9881 { | |
9882 GpBrush *brush = TlsGetValue(_gpBrush); | |
9883 | |
9884 GdipFillRectangleI(graphics, brush, x, y, width, height); | |
9885 } | |
9886 else | |
9887 { | |
9888 GpPen *pen = TlsGetValue(_gpPen); | |
9889 | |
9890 GdipDrawRectangleI(graphics, pen, x, y, width, height); | |
9891 } | |
9892 GdipDeleteGraphics(graphics); | |
9893 } | |
9791 else | 9894 else |
9792 return; | 9895 #endif |
9793 | 9896 { |
9794 SetRect(&Rect, x, y, x + width , y + height ); | 9897 HDC hdcPaint; |
9795 if(flags & DW_DRAW_FILL) | 9898 RECT Rect; |
9796 FillRect(hdcPaint, &Rect, TlsGetValue(_hBrush)); | 9899 |
9797 else | 9900 if(handle) |
9798 FrameRect(hdcPaint, &Rect, TlsGetValue(_hBrush)); | 9901 hdcPaint = GetDC(handle); |
9799 if(!pixmap) | 9902 else if(pixmap) |
9800 ReleaseDC(handle, hdcPaint); | 9903 hdcPaint = pixmap->hdc; |
9904 else | |
9905 return; | |
9906 | |
9907 SetRect(&Rect, x, y, x + width , y + height ); | |
9908 if(flags & DW_DRAW_FILL) | |
9909 FillRect(hdcPaint, &Rect, TlsGetValue(_hBrush)); | |
9910 else | |
9911 FrameRect(hdcPaint, &Rect, TlsGetValue(_hBrush)); | |
9912 if(!pixmap) | |
9913 ReleaseDC(handle, hdcPaint); | |
9914 } | |
9801 } | 9915 } |
9802 | 9916 |
9803 /* Draw an arc on a window (preferably a render window). | 9917 /* Draw an arc on a window (preferably a render window). |
9804 * Parameters: | 9918 * Parameters: |
9805 * handle: Handle to the window. | 9919 * handle: Handle to the window. |
9813 * x2: X coordinate of second segment of arc. | 9927 * x2: X coordinate of second segment of arc. |
9814 * y2: Y coordinate of second segment of arc. | 9928 * y2: Y coordinate of second segment of arc. |
9815 */ | 9929 */ |
9816 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) | 9930 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) |
9817 { | 9931 { |
9818 HDC hdcPaint; | |
9819 HBRUSH oldBrush; | |
9820 HPEN oldPen; | |
9821 double dx = xorigin - x1; | 9932 double dx = xorigin - x1; |
9822 double dy = yorigin - y1; | 9933 double dy = yorigin - y1; |
9823 double r = sqrt(dx*dx + dy*dy); | 9934 double r = sqrt(dx*dx + dy*dy); |
9824 | 9935 int ri = (int)r; |
9825 if(handle) | 9936 |
9826 hdcPaint = GetDC(handle); | 9937 #ifdef GDIPLUS |
9827 else if(pixmap) | 9938 if(!(flags & DW_DRAW_NOAA)) |
9828 hdcPaint = pixmap->hdc; | 9939 { |
9940 GpGraphics *graphics = NULL; | |
9941 GpPen *pen = TlsGetValue(_gpPen); | |
9942 | |
9943 if(handle) | |
9944 GdipCreateFromHWND(handle, &graphics); | |
9945 else if(pixmap) | |
9946 GdipCreateFromHDC(pixmap->hdc, &graphics); | |
9947 else | |
9948 return; | |
9949 | |
9950 GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias); | |
9951 if(flags & DW_DRAW_FULL) | |
9952 { | |
9953 if(flags & DW_DRAW_FILL) | |
9954 { | |
9955 GpBrush *brush = TlsGetValue(_gpBrush); | |
9956 | |
9957 GdipFillEllipseI(graphics, brush, xorigin-ri, yorigin-ri, xorigin+ri, yorigin+ri); | |
9958 } | |
9959 else | |
9960 GdipDrawEllipseI(graphics, pen, xorigin-ri, yorigin-ri, xorigin+ri, yorigin+ri); | |
9961 } | |
9962 else | |
9963 { | |
9964 double a1 = atan2((y1-yorigin), (x1-xorigin)); | |
9965 double a2 = atan2((y2-yorigin), (x2-xorigin)); | |
9966 | |
9967 GdipDrawArcI(graphics, pen, xorigin-ri, yorigin-ri, xorigin+ri, yorigin+ri, (REAL)a1, (REAL)a2); | |
9968 } | |
9969 GdipDeleteGraphics(graphics); | |
9970 } | |
9829 else | 9971 else |
9830 return; | 9972 #endif |
9831 | 9973 { |
9832 if(flags & DW_DRAW_FILL) | 9974 HDC hdcPaint; |
9833 oldBrush = SelectObject( hdcPaint, TlsGetValue(_hBrush) ); | 9975 HBRUSH oldBrush; |
9834 else | 9976 HPEN oldPen; |
9835 oldBrush = SelectObject( hdcPaint, GetStockObject(HOLLOW_BRUSH) ); | 9977 |
9836 oldPen = SelectObject( hdcPaint, TlsGetValue(_hPen) ); | 9978 if(handle) |
9837 if(flags & DW_DRAW_FULL) | 9979 hdcPaint = GetDC(handle); |
9838 Ellipse(hdcPaint, x1, y1, x2, y2); | 9980 else if(pixmap) |
9839 else | 9981 hdcPaint = pixmap->hdc; |
9840 Arc(hdcPaint, xorigin-(int)r, yorigin-(int)r, xorigin+(int)r, yorigin+(int)r, x2, y2, x1, y1); | 9982 else |
9841 SelectObject( hdcPaint, oldBrush ); | 9983 return; |
9842 SelectObject( hdcPaint, oldPen ); | 9984 |
9843 | 9985 if(flags & DW_DRAW_FILL) |
9844 if(!pixmap) | 9986 oldBrush = SelectObject( hdcPaint, TlsGetValue(_hBrush) ); |
9845 ReleaseDC(handle, hdcPaint); | 9987 else |
9988 oldBrush = SelectObject( hdcPaint, GetStockObject(HOLLOW_BRUSH) ); | |
9989 oldPen = SelectObject( hdcPaint, TlsGetValue(_hPen) ); | |
9990 if(flags & DW_DRAW_FULL) | |
9991 Ellipse(hdcPaint, x1, y1, x2, y2); | |
9992 else | |
9993 Arc(hdcPaint, xorigin-(int)r, yorigin-(int)r, xorigin+(int)r, yorigin+(int)r, x2, y2, x1, y1); | |
9994 SelectObject( hdcPaint, oldBrush ); | |
9995 SelectObject( hdcPaint, oldPen ); | |
9996 | |
9997 if(!pixmap) | |
9998 ReleaseDC(handle, hdcPaint); | |
9999 } | |
9846 } | 10000 } |
9847 | 10001 |
9848 /* Draw text on a window (preferably a render window). | 10002 /* Draw text on a window (preferably a render window). |
9849 * Parameters: | 10003 * Parameters: |
9850 * handle: Handle to the window. | 10004 * handle: Handle to the window. |
10749 void (* threadfunc)(void *) = NULL; | 10903 void (* threadfunc)(void *) = NULL; |
10750 void **tmp = (void **)data; | 10904 void **tmp = (void **)data; |
10751 HPEN hPen; | 10905 HPEN hPen; |
10752 HBRUSH hBrush; | 10906 HBRUSH hBrush; |
10753 #ifdef GDIPLUS | 10907 #ifdef GDIPLUS |
10908 GpBrush *brush; | |
10754 GpPen *pen; | 10909 GpPen *pen; |
10755 #endif | 10910 #endif |
10756 | 10911 |
10757 _init_thread(); | 10912 _init_thread(); |
10758 | 10913 |
10763 if((hPen = TlsGetValue(_hPen))) | 10918 if((hPen = TlsGetValue(_hPen))) |
10764 DeleteObject(hPen); | 10919 DeleteObject(hPen); |
10765 if((hBrush = TlsGetValue(_hBrush))) | 10920 if((hBrush = TlsGetValue(_hBrush))) |
10766 DeleteObject(hBrush); | 10921 DeleteObject(hBrush); |
10767 #ifdef GDIPLUS | 10922 #ifdef GDIPLUS |
10923 if((brush = TlsGetValue(_gpBrush))) | |
10924 GdipDeleteBrush(brush); | |
10768 if((pen = TlsGetValue(_gpPen))) | 10925 if((pen = TlsGetValue(_gpPen))) |
10769 GdipDeletePen(pen); | 10926 GdipDeletePen(pen); |
10770 #endif | 10927 #endif |
10771 } | 10928 } |
10772 | 10929 |