Mercurial > dwindows
comparison os2/dw.c @ 1282:4f0f816f1e76
Update to draw as an ellipse and fix for circles on OS/2.
This sort of works but it really needs more work.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 31 Oct 2011 02:39:40 +0000 |
parents | 700dc6818431 |
children | 2c04a56eaf63 |
comparison
equal
deleted
inserted
replaced
1281:fe92a6f6d3e7 | 1282:4f0f816f1e76 |
---|---|
8685 int thisheight; | 8685 int thisheight; |
8686 ARCPARAMS ap = { 1, 1, 0, 0 }; | 8686 ARCPARAMS ap = { 1, 1, 0, 0 }; |
8687 POINTL pts[2]; | 8687 POINTL pts[2]; |
8688 double r, a1, a2, a; | 8688 double r, a1, a2, a; |
8689 | 8689 |
8690 /* Handle full circle/ellipse */ | |
8691 if(flags & DW_DRAW_FULL) | |
8692 { | |
8693 /* Draw one half... */ | |
8694 dw_draw_arc(handle, pixmap, flags & ~DW_DRAW_FULL, xorigin, yorigin, x2, y2, x1, y1); | |
8695 /* ... then continue to draw the other half */ | |
8696 } | |
8697 | |
8698 if(handle) | 8690 if(handle) |
8699 { | 8691 { |
8700 hps = _set_colors(handle); | 8692 hps = _set_colors(handle); |
8701 thisheight = _get_height(handle); | 8693 thisheight = _get_height(handle); |
8702 } | 8694 } |
8711 /* For a filled arc we need to start an area */ | 8703 /* For a filled arc we need to start an area */ |
8712 if(flags & DW_DRAW_FILL) | 8704 if(flags & DW_DRAW_FILL) |
8713 GpiBeginArea(hps, 0L); | 8705 GpiBeginArea(hps, 0L); |
8714 /* Setup the arc info on the presentation space */ | 8706 /* Setup the arc info on the presentation space */ |
8715 GpiSetArcParams(hps, &ap); | 8707 GpiSetArcParams(hps, &ap); |
8716 pts[0].x = x1; | 8708 |
8717 pts[0].y = thisheight - y1 - 1; | 8709 /* Handle full circle/ellipse */ |
8718 /* Move to the initial position */ | 8710 if(flags & DW_DRAW_FULL) |
8719 GpiMove(hps, pts); | 8711 { |
8720 /* Calculate the midpoint */ | 8712 int xmid = ((x2 - x1)/2) + x1; |
8721 r = 0.5 * (hypot((double)(y1 - yorigin), (double)(x1 - xorigin)) + | 8713 int ymid = ((y2 - y1)/2) + y1; |
8722 hypot((double)(y2 - yorigin), (double)(x2 - xorigin))); | 8714 |
8723 a1 = atan2((double)(y1 - yorigin), (double)(x1 - xorigin)); | 8715 /* Draw one half... */ |
8724 a2 = atan2((double)(y2 - yorigin), (double)(x2 - xorigin)); | 8716 pts[0].x = x1; |
8725 if(a2 < a1) | 8717 pts[0].y = thisheight - ymid - 1; |
8726 a2 += M_PI * 2; | 8718 GpiMove(hps, pts); |
8727 a = (a1 + a2) / 2.; | 8719 pts[0].x = xmid; |
8728 /* Prepare to draw */ | 8720 pts[0].y = thisheight - y1 - 1; |
8729 pts[0].x = (int)(xorigin + r * cos(a)); | 8721 pts[1].x = x2; |
8730 pts[0].y = thisheight - (int)(yorigin + r * sin(a)) - 1; | 8722 pts[1].y = thisheight - ymid - 1; |
8731 pts[1].x = x2; | 8723 GpiPointArc(hps, pts); |
8732 pts[1].y = thisheight - y2 - 1; | 8724 /* ... then continue to draw the other half */ |
8733 /* Actually draw the arc */ | 8725 GpiMove(hps, &pts[1]); |
8734 GpiPointArc(hps, pts); | 8726 pts[0].x = xmid; |
8727 pts[0].y = thisheight - y2 - 1; | |
8728 pts[1].x = x1; | |
8729 pts[1].y = thisheight - ymid - 1; | |
8730 GpiPointArc(hps, pts); | |
8731 } | |
8732 else | |
8733 { | |
8734 pts[0].x = x1; | |
8735 pts[0].y = thisheight - y1 - 1; | |
8736 /* Move to the initial position */ | |
8737 GpiMove(hps, pts); | |
8738 /* Calculate the midpoint */ | |
8739 r = 0.5 * (hypot((double)(y1 - yorigin), (double)(x1 - xorigin)) + | |
8740 hypot((double)(y2 - yorigin), (double)(x2 - xorigin))); | |
8741 a1 = atan2((double)(y1 - yorigin), (double)(x1 - xorigin)); | |
8742 a2 = atan2((double)(y2 - yorigin), (double)(x2 - xorigin)); | |
8743 if(a2 < a1) | |
8744 a2 += M_PI * 2; | |
8745 a = (a1 + a2) / 2.; | |
8746 /* Prepare to draw */ | |
8747 pts[0].x = (int)(xorigin + r * cos(a)); | |
8748 pts[0].y = thisheight - (int)(yorigin + r * sin(a)) - 1; | |
8749 pts[1].x = x2; | |
8750 pts[1].y = thisheight - y2 - 1; | |
8751 /* Actually draw the arc */ | |
8752 GpiPointArc(hps, pts); | |
8753 } | |
8735 if(flags & DW_DRAW_FILL) | 8754 if(flags & DW_DRAW_FILL) |
8736 GpiEndArea(hps); | 8755 GpiEndArea(hps); |
8737 | 8756 |
8738 if(!pixmap) | 8757 if(!pixmap) |
8739 WinReleasePS(hps); | 8758 WinReleasePS(hps); |