comparison win/dw.c @ 1681:e02101d1b8ba

Decided to move to all GDI+ drawing when GDIPLUS is defined... instead of just using it when antialiasing is needed. dw_draw_point() and dw_draw_text() still need to be converted.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 28 Apr 2012 20:42:49 +0000
parents b09f5f73189c
children ea749fb90f7e
comparison
equal deleted inserted replaced
1680:b09f5f73189c 1681:e02101d1b8ba
9877 /* Sanity check */ 9877 /* Sanity check */
9878 if(npoints < 1) 9878 if(npoints < 1)
9879 return; 9879 return;
9880 9880
9881 #ifdef GDIPLUS 9881 #ifdef GDIPLUS
9882 if(!(flags & DW_DRAW_NOAA))
9883 { 9882 {
9884 GpGraphics *graphics = NULL; 9883 GpGraphics *graphics = NULL;
9885 9884
9886 if(handle) 9885 if(handle)
9887 GdipCreateFromHWND(handle, &graphics); 9886 GdipCreateFromHWND(handle, &graphics);
9888 else if(pixmap) 9887 else if(pixmap)
9889 GdipCreateFromHDC(pixmap->hdc, &graphics); 9888 GdipCreateFromHDC(pixmap->hdc, &graphics);
9890 else 9889 else
9891 return; 9890 return;
9892 9891
9893 GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias); 9892 /* Enable antialiasing if the DW_DRAW_NOAA flag isn't set */
9893 if(!(flags & DW_DRAW_NOAA))
9894 GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias);
9895
9894 if((points = _makePoints(&npoints, x, y))) 9896 if((points = _makePoints(&npoints, x, y)))
9895 { 9897 {
9896 if(flags & DW_DRAW_FILL) 9898 if(flags & DW_DRAW_FILL)
9897 { 9899 {
9898 GpBrush *brush = TlsGetValue(_gpBrush); 9900 GpBrush *brush = TlsGetValue(_gpBrush);
9906 GdipDrawPolygonI(graphics, pen, points, npoints); 9908 GdipDrawPolygonI(graphics, pen, points, npoints);
9907 } 9909 }
9908 } 9910 }
9909 GdipDeleteGraphics(graphics); 9911 GdipDeleteGraphics(graphics);
9910 } 9912 }
9911 else 9913 #else
9912 #endif
9913 { 9914 {
9914 HDC hdcPaint; 9915 HDC hdcPaint;
9915 9916
9916 if ( handle ) 9917 if ( handle )
9917 hdcPaint = GetDC( handle ); 9918 hdcPaint = GetDC( handle );
9935 } 9936 }
9936 9937
9937 if ( !pixmap ) 9938 if ( !pixmap )
9938 ReleaseDC( handle, hdcPaint ); 9939 ReleaseDC( handle, hdcPaint );
9939 } 9940 }
9941 #endif
9940 if(points) 9942 if(points)
9941 free(points); 9943 free(points);
9942 } 9944 }
9943 9945
9944 /* Draw a rectangle on a window (preferably a render window). 9946 /* Draw a rectangle on a window (preferably a render window).
9951 * width: Width of rectangle. 9953 * width: Width of rectangle.
9952 * height: Height of rectangle. 9954 * height: Height of rectangle.
9953 */ 9955 */
9954 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height) 9956 void API dw_draw_rect(HWND handle, HPIXMAP pixmap, int flags, int x, int y, int width, int height)
9955 { 9957 {
9956 #ifdef GDIPLUS1 9958 #ifdef GDIPLUS
9957 if(!(flags & DW_DRAW_NOAA)) 9959 GpGraphics *graphics = NULL;
9958 { 9960
9959 GpGraphics *graphics = NULL; 9961 if(handle)
9962 GdipCreateFromHWND(handle, &graphics);
9963 else if(pixmap)
9964 GdipCreateFromHDC(pixmap->hdc, &graphics);
9965 else
9966 return;
9967
9968 if(flags & DW_DRAW_FILL)
9969 {
9970 GpBrush *brush = TlsGetValue(_gpBrush);
9971
9972 GdipFillRectangleI(graphics, brush, x, y, width, height);
9973 }
9974 else
9975 {
9976 GpPen *pen = TlsGetValue(_gpPen);
9960 9977
9961 if(handle) 9978 GdipDrawRectangleI(graphics, pen, x, y, width, height);
9962 GdipCreateFromHWND(handle, &graphics); 9979 }
9963 else if(pixmap) 9980 GdipDeleteGraphics(graphics);
9964 GdipCreateFromHDC(pixmap->hdc, &graphics); 9981 #else
9965 else 9982 HDC hdcPaint;
9966 return; 9983 RECT Rect;
9967 9984
9968 GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias); 9985 if(handle)
9969 if(flags & DW_DRAW_FILL) 9986 hdcPaint = GetDC(handle);
9970 { 9987 else if(pixmap)
9971 GpBrush *brush = TlsGetValue(_gpBrush); 9988 hdcPaint = pixmap->hdc;
9972
9973 GdipFillRectangleI(graphics, brush, x, y, width, height);
9974 }
9975 else
9976 {
9977 GpPen *pen = TlsGetValue(_gpPen);
9978
9979 GdipDrawRectangleI(graphics, pen, x, y, width, height);
9980 }
9981 GdipDeleteGraphics(graphics);
9982 }
9983 else 9989 else
9990 return;
9991
9992 SetRect(&Rect, x, y, x + width , y + height );
9993 if(flags & DW_DRAW_FILL)
9994 FillRect(hdcPaint, &Rect, TlsGetValue(_hBrush));
9995 else
9996 FrameRect(hdcPaint, &Rect, TlsGetValue(_hBrush));
9997 if(!pixmap)
9998 ReleaseDC(handle, hdcPaint);
9984 #endif 9999 #endif
9985 {
9986 HDC hdcPaint;
9987 RECT Rect;
9988
9989 if(handle)
9990 hdcPaint = GetDC(handle);
9991 else if(pixmap)
9992 hdcPaint = pixmap->hdc;
9993 else
9994 return;
9995
9996 SetRect(&Rect, x, y, x + width , y + height );
9997 if(flags & DW_DRAW_FILL)
9998 FillRect(hdcPaint, &Rect, TlsGetValue(_hBrush));
9999 else
10000 FrameRect(hdcPaint, &Rect, TlsGetValue(_hBrush));
10001 if(!pixmap)
10002 ReleaseDC(handle, hdcPaint);
10003 }
10004 } 10000 }
10005 10001
10006 /* Draw an arc on a window (preferably a render window). 10002 /* Draw an arc on a window (preferably a render window).
10007 * Parameters: 10003 * Parameters:
10008 * handle: Handle to the window. 10004 * handle: Handle to the window.
10017 * y2: Y coordinate of second segment of arc. 10013 * y2: Y coordinate of second segment of arc.
10018 */ 10014 */
10019 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2) 10015 void API dw_draw_arc(HWND handle, HPIXMAP pixmap, int flags, int xorigin, int yorigin, int x1, int y1, int x2, int y2)
10020 { 10016 {
10021 #ifdef GDIPLUS 10017 #ifdef GDIPLUS
10018 GpGraphics *graphics = NULL;
10019 GpPen *pen = TlsGetValue(_gpPen);
10020
10021 if(handle)
10022 GdipCreateFromHWND(handle, &graphics);
10023 else if(pixmap)
10024 GdipCreateFromHDC(pixmap->hdc, &graphics);
10025 else
10026 return;
10027
10028 /* Enable antialiasing if the DW_DRAW_NOAA flag isn't set */
10022 if(!(flags & DW_DRAW_NOAA)) 10029 if(!(flags & DW_DRAW_NOAA))
10023 { 10030 GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias);
10024 GpGraphics *graphics = NULL; 10031
10025 GpPen *pen = TlsGetValue(_gpPen); 10032 if(flags & DW_DRAW_FULL)
10033 {
10034 if(flags & DW_DRAW_FILL)
10035 {
10036 GpBrush *brush = TlsGetValue(_gpBrush);
10026 10037
10027 if(handle) 10038 GdipFillEllipseI(graphics, brush, x1 < x2 ? x1 : x2, y1 < y2 ? y1 : y2, abs(x1-x2), abs(y1-y2));
10028 GdipCreateFromHWND(handle, &graphics); 10039 }
10029 else if(pixmap)
10030 GdipCreateFromHDC(pixmap->hdc, &graphics);
10031 else 10040 else
10032 return; 10041 GdipDrawEllipseI(graphics, pen, x1 < x2 ? x1 : x2, y1 < y2 ? y1 : y2, abs(x1-x2), abs(y1-y2));
10033
10034 GdipSetSmoothingMode(graphics, SmoothingModeAntiAlias);
10035 if(flags & DW_DRAW_FULL)
10036 {
10037 if(flags & DW_DRAW_FILL)
10038 {
10039 GpBrush *brush = TlsGetValue(_gpBrush);
10040
10041 GdipFillEllipseI(graphics, brush, x1 < x2 ? x1 : x2, y1 < y2 ? y1 : y2, abs(x1-x2), abs(y1-y2));
10042 }
10043 else
10044 GdipDrawEllipseI(graphics, pen, x1 < x2 ? x1 : x2, y1 < y2 ? y1 : y2, abs(x1-x2), abs(y1-y2));
10045 }
10046 else
10047 {
10048 double a1 = atan2((y1-yorigin), (x1-xorigin));
10049 double a2 = atan2((y2-yorigin), (x2-xorigin));
10050 double dx = xorigin - x1;
10051 double dy = yorigin - y1;
10052 double r = sqrt(dx*dx + dy*dy);
10053 double sweep;
10054 int ri = (int)r;
10055
10056 /* Convert to degrees */
10057 a1 *= (180.0 / M_PI);
10058 a2 *= (180.0 / M_PI);
10059 sweep = fabs(a1 - a2);
10060
10061 GdipDrawArcI(graphics, pen, xorigin-ri, yorigin-ri, ri*2, ri*2, (REAL)a1, (REAL)sweep);
10062 }
10063 GdipDeleteGraphics(graphics);
10064 } 10042 }
10065 else 10043 else
10066 #endif 10044 {
10067 { 10045 double a1 = atan2((y1-yorigin), (x1-xorigin));
10068 HDC hdcPaint; 10046 double a2 = atan2((y2-yorigin), (x2-xorigin));
10069 HBRUSH oldBrush;
10070 HPEN oldPen;
10071 double dx = xorigin - x1; 10047 double dx = xorigin - x1;
10072 double dy = yorigin - y1; 10048 double dy = yorigin - y1;
10073 double r = sqrt(dx*dx + dy*dy); 10049 double r = sqrt(dx*dx + dy*dy);
10050 double sweep;
10074 int ri = (int)r; 10051 int ri = (int)r;
10075 10052
10076 if(handle) 10053 /* Convert to degrees */
10077 hdcPaint = GetDC(handle); 10054 a1 *= (180.0 / M_PI);
10078 else if(pixmap) 10055 a2 *= (180.0 / M_PI);
10079 hdcPaint = pixmap->hdc; 10056 sweep = fabs(a1 - a2);
10080 else 10057
10081 return; 10058 GdipDrawArcI(graphics, pen, xorigin-ri, yorigin-ri, ri*2, ri*2, (REAL)a1, (REAL)sweep);
10082 10059 }
10083 if(flags & DW_DRAW_FILL) 10060 GdipDeleteGraphics(graphics);
10084 oldBrush = SelectObject( hdcPaint, TlsGetValue(_hBrush) ); 10061 #else
10085 else 10062 HDC hdcPaint;
10086 oldBrush = SelectObject( hdcPaint, GetStockObject(HOLLOW_BRUSH) ); 10063 HBRUSH oldBrush;
10087 oldPen = SelectObject( hdcPaint, TlsGetValue(_hPen) ); 10064 HPEN oldPen;
10088 if(flags & DW_DRAW_FULL) 10065 double dx = xorigin - x1;
10089 Ellipse(hdcPaint, x1, y1, x2, y2); 10066 double dy = yorigin - y1;
10090 else 10067 double r = sqrt(dx*dx + dy*dy);
10091 Arc(hdcPaint, xorigin-ri, yorigin-ri, xorigin+ri, yorigin+ri, x2, y2, x1, y1); 10068 int ri = (int)r;
10092 SelectObject( hdcPaint, oldBrush ); 10069
10093 SelectObject( hdcPaint, oldPen ); 10070 if(handle)
10094 10071 hdcPaint = GetDC(handle);
10095 if(!pixmap) 10072 else if(pixmap)
10096 ReleaseDC(handle, hdcPaint); 10073 hdcPaint = pixmap->hdc;
10097 } 10074 else
10075 return;
10076
10077 if(flags & DW_DRAW_FILL)
10078 oldBrush = SelectObject( hdcPaint, TlsGetValue(_hBrush) );
10079 else
10080 oldBrush = SelectObject( hdcPaint, GetStockObject(HOLLOW_BRUSH) );
10081 oldPen = SelectObject( hdcPaint, TlsGetValue(_hPen) );
10082 if(flags & DW_DRAW_FULL)
10083 Ellipse(hdcPaint, x1, y1, x2, y2);
10084 else
10085 Arc(hdcPaint, xorigin-ri, yorigin-ri, xorigin+ri, yorigin+ri, x2, y2, x1, y1);
10086 SelectObject( hdcPaint, oldBrush );
10087 SelectObject( hdcPaint, oldPen );
10088
10089 if(!pixmap)
10090 ReleaseDC(handle, hdcPaint);
10091 #endif
10098 } 10092 }
10099 10093
10100 /* Draw text on a window (preferably a render window). 10094 /* Draw text on a window (preferably a render window).
10101 * Parameters: 10095 * Parameters:
10102 * handle: Handle to the window. 10096 * handle: Handle to the window.