branch update for HEAD-2003050101
[reactos.git] / subsys / win32k / eng / paint.c
1 /*
2  * COPYRIGHT:         See COPYING in the top level directory
3  * PROJECT:           ReactOS kernel
4  * PURPOSE:           GDI Driver Paint Functions
5  * FILE:              subsys/win32k/eng/paint.c
6  * PROGRAMER:         Jason Filby
7  * REVISION HISTORY:
8  *                 3/7/1999: Created
9  */
10
11 #include <ddk/winddi.h>
12 #include <include/object.h>
13 #include <include/paint.h>
14 #include <include/surface.h>
15
16 #include "objects.h"
17 #include <include/mouse.h>
18 #include "../dib/dib.h"
19
20 #include "brush.h"
21 #include "clip.h"
22
23 //#define NDEBUG
24 #include <win32k/debug1.h>
25
26 BOOL FillSolid(SURFOBJ *Surface, PRECTL pRect, ULONG iColor)
27 {
28   LONG y;
29   ULONG LineWidth;
30   SURFGDI *SurfaceGDI;
31
32   SurfaceGDI = (SURFGDI*)AccessInternalObjectFromUserObject(Surface);
33   MouseSafetyOnDrawStart(Surface, SurfaceGDI, pRect->left, pRect->top, pRect->right, pRect->bottom);
34   LineWidth  = pRect->right - pRect->left;
35   DPRINT(" LineWidth: %d, top: %d, bottom: %d\n", LineWidth, pRect->top, pRect->bottom);
36   for (y = pRect->top; y < pRect->bottom; y++)
37   {
38     SurfaceGDI->DIB_HLine(Surface, pRect->left, pRect->right, y, iColor);
39   }
40   MouseSafetyOnDrawEnd(Surface, SurfaceGDI);
41
42   return TRUE;
43 }
44
45 BOOL EngPaintRgn(SURFOBJ *Surface, CLIPOBJ *ClipRegion, ULONG iColor, MIX Mix,
46                BRUSHINST *BrushInst, POINTL *BrushPoint)
47 {
48   RECT_ENUM RectEnum;
49   BOOL EnumMore;
50   ULONG i;
51
52   DPRINT("ClipRegion->iMode:%d, ClipRegion->iDComplexity: %d\n Color: %d", ClipRegion->iMode, ClipRegion->iDComplexity, iColor);
53   switch(ClipRegion->iMode) {
54
55     case TC_RECTANGLES:
56
57     /* Rectangular clipping can be handled without enumeration.
58        Note that trivial clipping is not possible, since the clipping
59        region defines the area to fill */
60
61     if (ClipRegion->iDComplexity == DC_RECT)
62     {
63       FillSolid(Surface, &(ClipRegion->rclBounds), iColor);
64     } else {
65
66       /* Enumerate all the rectangles and draw them */
67       CLIPOBJ_cEnumStart(ClipRegion, FALSE, CT_RECTANGLES, CD_ANY, ENUM_RECT_LIMIT);
68
69       do {
70         EnumMore = CLIPOBJ_bEnum(ClipRegion, sizeof(RectEnum), (PVOID) &RectEnum);
71         for (i = 0; i < RectEnum.c; i++) {
72           FillSolid(Surface, RectEnum.arcl + i, iColor);
73         }
74       } while (EnumMore);
75     }
76
77     return(TRUE);
78
79     default:
80        return(FALSE);
81   }
82 }
83
84 BOOL STDCALL
85 EngPaint(IN SURFOBJ *Surface,
86          IN CLIPOBJ *ClipRegion,
87          IN BRUSHOBJ *Brush,
88          IN POINTL *BrushOrigin,
89          IN MIX  Mix)
90 {
91   BOOLEAN ret;
92
93   // FIXME: We only support a brush's solid color attribute
94   ret = EngPaintRgn(Surface, ClipRegion, Brush->iSolidColor, Mix, NULL, BrushOrigin);
95
96   return ret;
97 }
98
99 BOOL STDCALL
100 IntEngPaint(IN SURFOBJ *Surface,
101          IN CLIPOBJ *ClipRegion,
102          IN BRUSHOBJ *Brush,
103          IN POINTL *BrushOrigin,
104          IN MIX  Mix)
105 {
106   SURFGDI *SurfGDI;
107   BOOL ret;
108
109   // Is the surface's Paint function hooked?
110   SurfGDI = (SURFGDI*)AccessInternalObjectFromUserObject(Surface);
111
112   DPRINT("SurfGDI type: %d, sgdi paint: %x\n", Surface->iType, SurfGDI->Paint);
113   if((Surface->iType!=STYPE_BITMAP) && (SurfGDI->Paint!=NULL))
114   {
115     // Call the driver's DrvPaint
116     MouseSafetyOnDrawStart(Surface, SurfGDI, ClipRegion->rclBounds.left,
117                                  ClipRegion->rclBounds.top, ClipRegion->rclBounds.right,
118                                                          ClipRegion->rclBounds.bottom);
119
120     ret = SurfGDI->Paint(Surface, ClipRegion, Brush, BrushOrigin, Mix);
121     MouseSafetyOnDrawEnd(Surface, SurfGDI);
122     return ret;
123   }
124   return EngPaint( Surface, ClipRegion, Brush, BrushOrigin, Mix );
125
126 }