[CMAKE]
[reactos.git] / subsystems / win32 / win32k / objects / arc.c
index 4aa462e..17d7f26 100644 (file)
@@ -1,4 +1,6 @@
-#include <w32k.h>
+#include <win32k.h>
+#define _USE_MATH_DEFINES
+#include <math.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -7,31 +9,31 @@
  * a couple macros to fill a single pixel or a line
  */
 #define PUTPIXEL(x,y,BrushInst)        \
-  ret = ret && IntEngLineTo(&BitmapObj->SurfObj, \
-       dc->CombinedClip,                         \
+  ret = ret && IntEngLineTo(&psurf->SurfObj, \
+       dc->rosdc.CombinedClip,                         \
        &BrushInst.BrushObject,                   \
        x, y, (x)+1, y,                           \
        &RectBounds,                              \
-       ROP2_TO_MIX(Dc_Attr->jROP2));
+       ROP2_TO_MIX(pdcattr->jROP2));
 
 #define PUTLINE(x1,y1,x2,y2,BrushInst) \
-  ret = ret && IntEngLineTo(&BitmapObj->SurfObj, \
-       dc->CombinedClip,                         \
+  ret = ret && IntEngLineTo(&psurf->SurfObj, \
+       dc->rosdc.CombinedClip,                         \
        &BrushInst.BrushObject,                   \
        x1, y1, x2, y2,                           \
        &RectBounds,                              \
-       ROP2_TO_MIX(Dc_Attr->jROP2));
+       ROP2_TO_MIX(pdcattr->jROP2));
 
 #define Rsin(d) ((d) == 0.0 ? 0.0 : ((d) == 90.0 ? 1.0 : sin(d*M_PI/180.0)))
 #define Rcos(d) ((d) == 0.0 ? 1.0 : ((d) == 90.0 ? 0.0 : cos(d*M_PI/180.0)))
 
 BOOL FASTCALL IntFillArc( PDC dc, INT XLeft, INT YLeft, INT Width, INT Height, double StartArc, double EndArc, ARCTYPE arctype);
-BOOL FASTCALL IntDrawArc( PDC dc, INT XLeft, INT YLeft, INT Width, INT Height, double StartArc, double EndArc, ARCTYPE arctype, PGDIBRUSHOBJ PenBrushObj);
+BOOL FASTCALL IntDrawArc( PDC dc, INT XLeft, INT YLeft, INT Width, INT Height, double StartArc, double EndArc, ARCTYPE arctype, PBRUSH pbrush);
 
 static
 BOOL
 FASTCALL
-IntArc( DC *dc, 
+IntArc( DC *dc,
         int  Left,
         int  Top,
         int  Right,
@@ -42,11 +44,10 @@ IntArc( DC *dc,
         int  YRadialEnd,
         ARCTYPE arctype)
 {
-    PDC_ATTR Dc_Attr;
+    PDC_ATTR pdcattr;
     RECTL RectBounds, RectSEpts;
-    PGDIBRUSHOBJ PenBrushObj;
-    GDIBRUSHINST PenBrushInst;
-    BITMAPOBJ *BitmapObj;
+    PBRUSH pbrushPen;
+    SURFACE *psurf;
     BOOL ret = TRUE;
     LONG PenWidth, PenOrigWidth;
     double AngleStart, AngleEnd;
@@ -68,21 +69,20 @@ IntArc( DC *dc,
         (Bottom - Top == 1))))
        return TRUE;
 
-    Dc_Attr = dc->pDc_Attr;
-    if(!Dc_Attr) Dc_Attr = &dc->Dc_Attr;
+    pdcattr = dc->pdcattr;
 
-    PenBrushObj = PENOBJ_LockPen(Dc_Attr->hpen);
-    if (NULL == PenBrushObj)
+    pbrushPen = PEN_LockPen(pdcattr->hpen);
+    if (!pbrushPen)
     {
         DPRINT1("Arc Fail 1\n");
-        SetLastWin32Error(ERROR_INTERNAL_ERROR);
+        EngSetLastError(ERROR_INTERNAL_ERROR);
         return FALSE;
     }
 
-    PenOrigWidth = PenWidth = PenBrushObj->ptPenWidth.x;
-    if (PenBrushObj->ulPenStyle == PS_NULL) PenWidth = 0;
+    PenOrigWidth = PenWidth = pbrushPen->ptPenWidth.x;
+    if (pbrushPen->ulPenStyle == PS_NULL) PenWidth = 0;
 
-    if (PenBrushObj->ulPenStyle == PS_INSIDEFRAME)
+    if (pbrushPen->ulPenStyle == PS_INSIDEFRAME)
     {
        if (2*PenWidth > (Right - Left)) PenWidth = (Right -Left + 1)/2;
        if (2*PenWidth > (Bottom - Top)) PenWidth = (Bottom -Top + 1)/2;
@@ -93,7 +93,7 @@ IntArc( DC *dc,
     }
 
     if (!PenWidth) PenWidth = 1;
-    PenBrushObj->ptPenWidth.x = PenWidth;  
+    pbrushPen->ptPenWidth.x = PenWidth;
 
     RectBounds.left   = Left;
     RectBounds.right  = Right;
@@ -107,7 +107,7 @@ IntArc( DC *dc,
 
     IntLPtoDP(dc, (LPPOINT)&RectBounds, 2);
     IntLPtoDP(dc, (LPPOINT)&RectSEpts, 2);
-    
+
     RectBounds.left   += dc->ptlDCOrig.x;
     RectBounds.right  += dc->ptlDCOrig.x;
     RectBounds.top    += dc->ptlDCOrig.y;
@@ -156,30 +156,27 @@ IntArc( DC *dc,
               AngleStart,
               AngleEnd,
               arctype,
-             PenBrushObj);
+              pbrushPen);
 
-    BitmapObj = BITMAPOBJ_LockBitmap(dc->w.hBitmap);
-    if (NULL == BitmapObj)
+    psurf = dc->dclevel.pSurface;
+    if (NULL == psurf)
     {
         DPRINT1("Arc Fail 2\n");
-        PENOBJ_UnlockPen(PenBrushObj);
-        SetLastWin32Error(ERROR_INTERNAL_ERROR);
+        PEN_UnlockPen(pbrushPen);
+        EngSetLastError(ERROR_INTERNAL_ERROR);
         return FALSE;
     }
 
-    IntGdiInitBrushInstance(&PenBrushInst, PenBrushObj, dc->XlatePen);
-
     if (arctype == GdiTypePie)
     {
-       PUTLINE(CenterX, CenterY, SfCx + CenterX, SfCy + CenterY, PenBrushInst);
-       PUTLINE(EfCx + CenterX, EfCy + CenterY, CenterX, CenterY, PenBrushInst);
+       PUTLINE(CenterX, CenterY, SfCx + CenterX, SfCy + CenterY, dc->eboLine);
+       PUTLINE(EfCx + CenterX, EfCy + CenterY, CenterX, CenterY, dc->eboLine);
     }
     if (arctype == GdiTypeChord)
-        PUTLINE(EfCx + CenterX, EfCy + CenterY, SfCx + CenterX, SfCy + CenterY, PenBrushInst);
-           
-    PenBrushObj->ptPenWidth.x = PenOrigWidth;
-    BITMAPOBJ_UnlockBitmap(BitmapObj);
-    PENOBJ_UnlockPen(PenBrushObj);
+        PUTLINE(EfCx + CenterX, EfCy + CenterY, SfCx + CenterX, SfCy + CenterY, dc->eboLine);
+
+    pbrushPen->ptPenWidth.x = PenOrigWidth;
+    PEN_UnlockPen(pbrushPen);
     DPRINT("IntArc Exit.\n");
     return ret;
 }
@@ -199,6 +196,7 @@ IntGdiArcInternal(
           int YEndArc)
 {
   BOOL Ret;
+  PDC_ATTR pdcattr;
 
   DPRINT("StartX: %d, StartY: %d, EndX: %d, EndY: %d\n",
            XStartArc,YStartArc,XEndArc,YEndArc);
@@ -207,7 +205,7 @@ IntGdiArcInternal(
 
   if ((LeftRect == RightRect) || (TopRect == BottomRect)) return TRUE;
 
-  if (PATH_IsPathOpen(dc->DcLevel))
+  if (PATH_IsPathOpen(dc->dclevel))
   {
      return PATH_Arc( dc,
                 LeftRect,
@@ -221,9 +219,11 @@ IntGdiArcInternal(
                  arctype);
   }
 
+  pdcattr = dc->pdcattr;
+
   if (arctype == GdiTypeArcTo)
   {
-    if (dc->DcLevel.flPath & DCPATH_CLOCKWISE)
+    if (dc->dclevel.flPath & DCPATH_CLOCKWISE)
        IntGdiLineTo(dc, XEndArc, YEndArc);
     else
        IntGdiLineTo(dc, XStartArc, YStartArc);
@@ -242,10 +242,10 @@ IntGdiArcInternal(
 
   if (arctype == GdiTypeArcTo)
   {
-     if (dc->DcLevel.flPath & DCPATH_CLOCKWISE)
-       IntGdiMoveToEx(dc, XStartArc, YStartArc, NULL);
+     if (dc->dclevel.flPath & DCPATH_CLOCKWISE)
+       IntGdiMoveToEx(dc, XStartArc, YStartArc, NULL, TRUE);
      else
-       IntGdiMoveToEx(dc, XEndArc, YEndArc, NULL);
+       IntGdiMoveToEx(dc, XEndArc, YEndArc, NULL, TRUE);
   }
   return Ret;
 }
@@ -269,11 +269,11 @@ IntGdiAngleArc( PDC pDC,
   x1 = x + (INT)(cos((eStartAngle/360)*(M_PI*2)) * dwRadius);
   y1 = y - (INT)(sin((eStartAngle/360)*(M_PI*2)) * dwRadius);
 
-  arcdir = pDC->DcLevel.flPath & DCPATH_CLOCKWISE;
+  arcdir = pDC->dclevel.flPath & DCPATH_CLOCKWISE;
   if (eSweepAngle >= 0)
-     pDC->DcLevel.flPath &= ~DCPATH_CLOCKWISE;
+     pDC->dclevel.flPath &= ~DCPATH_CLOCKWISE;
   else
-     pDC->DcLevel.flPath |= DCPATH_CLOCKWISE;
+     pDC->dclevel.flPath |= DCPATH_CLOCKWISE;
 
   result = IntGdiArcInternal( GdiTypeArcTo,
                                        pDC,
@@ -286,11 +286,11 @@ IntGdiAngleArc( PDC pDC,
                                         x2,
                                         y2 );
 
-  pDC->DcLevel.flPath |= (arcdir & DCPATH_CLOCKWISE);
+  pDC->dclevel.flPath |= (arcdir & DCPATH_CLOCKWISE);
 
   if (result)
   {
-     IntGdiMoveToEx(pDC, x2, y2, NULL); // Dont forget Path.
+     IntGdiMoveToEx(pDC, x2, y2, NULL, TRUE);
   }
   return result;
 }
@@ -314,10 +314,10 @@ NtGdiAngleArc(
   pDC = DC_LockDc (hDC);
   if(!pDC)
   {
-    SetLastWin32Error(ERROR_INVALID_HANDLE);
+    EngSetLastError(ERROR_INVALID_HANDLE);
     return FALSE;
   }
-  if (pDC->DC_Type == DC_TYPE_INFO)
+  if (pDC->dctype == DC_TYPE_INFO)
   {
     DC_UnlockDc(pDC);
     /* Yes, Windows really returns TRUE in this case */
@@ -325,13 +325,20 @@ NtGdiAngleArc(
   }
   worker.l  = dwStartAngle;
   worker1.l = dwSweepAngle;
+  DC_vPrepareDCsForBlit(pDC, pDC->rosdc.CombinedClip->rclBounds,
+                           NULL, pDC->rosdc.CombinedClip->rclBounds);
+  if (pDC->pdcattr->ulDirty_ & (DIRTY_FILL | DC_BRUSH_DIRTY))
+    DC_vUpdateFillBrush(pDC);
+  if (pDC->pdcattr->ulDirty_ & (DIRTY_LINE | DC_PEN_DIRTY))
+    DC_vUpdateLineBrush(pDC);
   Ret = IntGdiAngleArc( pDC, x, y, dwRadius, worker.f, worker1.f);
+  DC_vFinishBlit(pDC, NULL);
   DC_UnlockDc( pDC );
   return Ret;
 }
 
 BOOL
-STDCALL
+APIENTRY
 NtGdiArcInternal(
         ARCTYPE arctype,
         HDC  hDC,
@@ -350,16 +357,25 @@ NtGdiArcInternal(
   dc = DC_LockDc (hDC);
   if(!dc)
   {
-    SetLastWin32Error(ERROR_INVALID_HANDLE);
+    EngSetLastError(ERROR_INVALID_HANDLE);
     return FALSE;
   }
-  if (dc->DC_Type == DC_TYPE_INFO)
+  if (dc->dctype == DC_TYPE_INFO)
   {
     DC_UnlockDc(dc);
     /* Yes, Windows really returns TRUE in this case */
     return TRUE;
   }
 
+  DC_vPrepareDCsForBlit(dc, dc->rosdc.CombinedClip->rclBounds,
+                            NULL, dc->rosdc.CombinedClip->rclBounds);
+
+  if (dc->pdcattr->ulDirty_ & (DIRTY_FILL | DC_BRUSH_DIRTY))
+    DC_vUpdateFillBrush(dc);
+
+  if (dc->pdcattr->ulDirty_ & (DIRTY_LINE | DC_PEN_DIRTY))
+    DC_vUpdateLineBrush(dc);
+
   Ret = IntGdiArcInternal(
                   arctype,
                   dc,
@@ -372,6 +388,7 @@ NtGdiArcInternal(
                   XEndArc,
                   YEndArc);
 
+  DC_vFinishBlit(dc, NULL);
   DC_UnlockDc( dc );
   return Ret;
 }