comparison dwt/graphics/GC.d @ 239:43b41c7fe84a

work on allow null strings and arrays
author Frank Benoit <benoit@tionex.de>
date Fri, 20 Jun 2008 16:27:36 +0200
parents f54496748313
children fd9c62a2998e
comparison
equal deleted inserted replaced
238:efe25e7c8a96 239:43b41c7fe84a
1796 * each consecutive pair, and between the first pair and last pair in the 1796 * each consecutive pair, and between the first pair and last pair in the
1797 * array. 1797 * array.
1798 * 1798 *
1799 * @param pointArray an array of alternating x and y values which are the vertices of the polygon 1799 * @param pointArray an array of alternating x and y values which are the vertices of the polygon
1800 * 1800 *
1801 * @exception IllegalArgumentException <ul>
1802 * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
1803 * </ul>
1804 * @exception DWTException <ul> 1801 * @exception DWTException <ul>
1805 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 1802 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
1806 * </ul> 1803 * </ul>
1807 */ 1804 */
1808 public void drawPolygon( int[] pointArray) { 1805 public void drawPolygon( int[] pointArray) {
1809 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 1806 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
1810 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 1807 // DWT extension: allow null array
1808 //if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
1811 checkGC(DRAW); 1809 checkGC(DRAW);
1812 auto gdipGraphics = data.gdipGraphics; 1810 auto gdipGraphics = data.gdipGraphics;
1813 if (gdipGraphics !is null) { 1811 if (gdipGraphics !is null) {
1814 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 1812 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
1815 Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length/2); 1813 Gdip.Graphics_DrawPolygon(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length/2);
1841 * each consecutive pair, but not between the first pair and last pair in 1839 * each consecutive pair, but not between the first pair and last pair in
1842 * the array. 1840 * the array.
1843 * 1841 *
1844 * @param pointArray an array of alternating x and y values which are the corners of the polyline 1842 * @param pointArray an array of alternating x and y values which are the corners of the polyline
1845 * 1843 *
1846 * @exception IllegalArgumentException <ul>
1847 * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
1848 * </ul>
1849 * @exception DWTException <ul> 1844 * @exception DWTException <ul>
1850 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 1845 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
1851 * </ul> 1846 * </ul>
1852 */ 1847 */
1853 public void drawPolyline(int[] pointArray) { 1848 public void drawPolyline(int[] pointArray) {
1854 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 1849 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
1855 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 1850 // DWT externsion: allow null array
1851 //if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
1856 checkGC(DRAW); 1852 checkGC(DRAW);
1857 auto gdipGraphics = data.gdipGraphics; 1853 auto gdipGraphics = data.gdipGraphics;
1858 if (gdipGraphics !is null) { 1854 if (gdipGraphics !is null) {
1859 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend); 1855 Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
1860 Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2); 1856 Gdip.Graphics_DrawLines(gdipGraphics, data.gdipPen, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2);
2089 * 2085 *
2090 * @param string the string to be drawn 2086 * @param string the string to be drawn
2091 * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn 2087 * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
2092 * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn 2088 * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
2093 * 2089 *
2094 * @exception IllegalArgumentException <ul>
2095 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
2096 * </ul>
2097 * @exception DWTException <ul> 2090 * @exception DWTException <ul>
2098 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 2091 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
2099 * </ul> 2092 * </ul>
2100 */ 2093 */
2101 public void drawString (String string, int x, int y) { 2094 public void drawString (String string, int x, int y) {
2113 * @param string the string to be drawn 2106 * @param string the string to be drawn
2114 * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn 2107 * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn
2115 * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn 2108 * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn
2116 * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque 2109 * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
2117 * 2110 *
2118 * @exception IllegalArgumentException <ul>
2119 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
2120 * </ul>
2121 * @exception DWTException <ul> 2111 * @exception DWTException <ul>
2122 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 2112 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
2123 * </ul> 2113 * </ul>
2124 */ 2114 */
2125 public void drawString (String string, int x, int y, bool isTransparent) { 2115 public void drawString (String string, int x, int y, bool isTransparent) {
2126 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 2116 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
2127 if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 2117 // DWT extension: allow null string
2118 //if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
2128 // TCHAR buffer = new TCHAR (getCodePage(), string, false); 2119 // TCHAR buffer = new TCHAR (getCodePage(), string, false);
2129 wchar[] wstr = StrToWCHARs( string ); 2120 wchar[] wstr = StrToWCHARs( string );
2130 int length_ = wstr.length; 2121 int length_ = wstr.length;
2131 if (length_ is 0) return; 2122 if (length_ is 0) return;
2132 wchar* buffer = wstr.ptr; 2123 wchar* buffer = wstr.ptr;
2245 * 2236 *
2246 * @param string the string to be drawn 2237 * @param string the string to be drawn
2247 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn 2238 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
2248 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn 2239 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
2249 * 2240 *
2250 * @exception IllegalArgumentException <ul>
2251 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
2252 * </ul>
2253 * @exception DWTException <ul> 2241 * @exception DWTException <ul>
2254 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 2242 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
2255 * </ul> 2243 * </ul>
2256 */ 2244 */
2257 public void drawText (String string, int x, int y) { 2245 public void drawText (String string, int x, int y) {
2269 * @param string the string to be drawn 2257 * @param string the string to be drawn
2270 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn 2258 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
2271 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn 2259 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
2272 * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque 2260 * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque
2273 * 2261 *
2274 * @exception IllegalArgumentException <ul>
2275 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
2276 * </ul>
2277 * @exception DWTException <ul> 2262 * @exception DWTException <ul>
2278 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 2263 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
2279 * </ul> 2264 * </ul>
2280 */ 2265 */
2281 public void drawText (String string, int x, int y, bool isTransparent) { 2266 public void drawText (String string, int x, int y, bool isTransparent) {
2309 * @param string the string to be drawn 2294 * @param string the string to be drawn
2310 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn 2295 * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
2311 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn 2296 * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
2312 * @param flags the flags specifying how to process the text 2297 * @param flags the flags specifying how to process the text
2313 * 2298 *
2314 * @exception IllegalArgumentException <ul>
2315 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
2316 * </ul>
2317 * @exception DWTException <ul> 2299 * @exception DWTException <ul>
2318 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 2300 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
2319 * </ul> 2301 * </ul>
2320 */ 2302 */
2321 public void drawText (String string, int x, int y, int flags) { 2303 public void drawText (String string, int x, int y, int flags) {
2322 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 2304 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
2323 if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 2305 // DWT extension: allow null string
2306 //if (string is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
2324 if (string.length is 0) return; 2307 if (string.length is 0) return;
2325 auto gdipGraphics = data.gdipGraphics; 2308 auto gdipGraphics = data.gdipGraphics;
2326 if (gdipGraphics !is null) { 2309 if (gdipGraphics !is null) {
2327 checkGC(FONT | FOREGROUND | ((flags & DWT.DRAW_TRANSPARENT) !is 0 ? 0 : BACKGROUND)); 2310 checkGC(FONT | FOREGROUND | ((flags & DWT.DRAW_TRANSPARENT) !is 0 ? 0 : BACKGROUND));
2328 wchar[] wstr = StrToWCHARs( string ); 2311 wchar[] wstr = StrToWCHARs( string );
2769 * the polygon. Lines are drawn between each consecutive pair, and 2752 * the polygon. Lines are drawn between each consecutive pair, and
2770 * between the first pair and last pair in the array. 2753 * between the first pair and last pair in the array.
2771 * 2754 *
2772 * @param pointArray an array of alternating x and y values which are the vertices of the polygon 2755 * @param pointArray an array of alternating x and y values which are the vertices of the polygon
2773 * 2756 *
2774 * @exception IllegalArgumentException <ul>
2775 * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
2776 * </ul>
2777 * @exception DWTException <ul> 2757 * @exception DWTException <ul>
2778 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 2758 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
2779 * </ul> 2759 * </ul>
2780 * 2760 *
2781 * @see #drawPolygon 2761 * @see #drawPolygon
2782 */ 2762 */
2783 public void fillPolygon(int[] pointArray) { 2763 public void fillPolygon(int[] pointArray) {
2784 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 2764 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
2785 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 2765 // DWT externsion: allow null array
2766 //if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
2786 checkGC(FILL); 2767 checkGC(FILL);
2787 if (data.gdipGraphics !is null) { 2768 if (data.gdipGraphics !is null) {
2788 int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; 2769 int mode = OS.GetPolyFillMode(handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate;
2789 Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2, mode); 2770 Gdip.Graphics_FillPolygon(data.gdipGraphics, data.gdipBrush, cast(Gdip.Point*)pointArray.ptr, pointArray.length / 2, mode);
2790 return; 2771 return;
4734 * </p> 4715 * </p>
4735 * 4716 *
4736 * @param string the string to measure 4717 * @param string the string to measure
4737 * @return a point containing the extent of the string 4718 * @return a point containing the extent of the string
4738 * 4719 *
4739 * @exception IllegalArgumentException <ul>
4740 * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
4741 * </ul>
4742 * @exception DWTException <ul> 4720 * @exception DWTException <ul>
4743 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 4721 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
4744 * </ul> 4722 * </ul>
4745 */ 4723 */
4746 public Point stringExtent(String string) { 4724 public Point stringExtent(String string) {
4747 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 4725 if (handle is null) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
4748 if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT); 4726 // DWT externsion: allow null string
4727 //if (string is null) DWT.error (DWT.ERROR_NULL_ARGUMENT);
4749 checkGC(FONT); 4728 checkGC(FONT);
4750 int length_ = string.length; 4729 int length_ = string.length;
4751 if (data.gdipGraphics !is null) { 4730 if (data.gdipGraphics !is null) {
4752 Gdip.PointF pt; 4731 Gdip.PointF pt;
4753 Gdip.RectF bounds; 4732 Gdip.RectF bounds;