Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / win32ss / gdi / gdi32 / objects / painting.c
1 #include <precomp.h>
2
3
4 /*
5 * @implemented
6 */
7 BOOL
8 WINAPI
9 LineTo(
10 _In_ HDC hdc,
11 _In_ INT x,
12 _In_ INT y )
13 {
14 HANDLE_METADC(BOOL, LineTo, FALSE, hdc, x, y);
15
16 return NtGdiLineTo(hdc, x, y);
17 }
18
19
20 BOOL
21 WINAPI
22 MoveToEx(
23 _In_ HDC hdc,
24 _In_ INT x,
25 _In_ INT y,
26 _Out_opt_ LPPOINT ppt)
27 {
28 PDC_ATTR pdcattr;
29
30 HANDLE_METADC(BOOL, MoveTo, FALSE, hdc, x, y, ppt);
31
32 /* Get the DC attribute */
33 pdcattr = GdiGetDcAttr(hdc);
34 if (pdcattr == NULL)
35 {
36 SetLastError(ERROR_INVALID_PARAMETER);
37 return FALSE;
38 }
39
40 if (ppt)
41 {
42 if ( pdcattr->ulDirty_ & DIRTY_PTLCURRENT ) // Double hit!
43 {
44 ppt->x = pdcattr->ptfxCurrent.x; // ret prev before change.
45 ppt->y = pdcattr->ptfxCurrent.y;
46 DPtoLP (hdc, ppt, 1); // reconvert back.
47 }
48 else
49 {
50 ppt->x = pdcattr->ptlCurrent.x;
51 ppt->y = pdcattr->ptlCurrent.y;
52 }
53 }
54
55 pdcattr->ptlCurrent.x = x;
56 pdcattr->ptlCurrent.y = y;
57
58 pdcattr->ulDirty_ &= ~DIRTY_PTLCURRENT;
59 pdcattr->ulDirty_ |= ( DIRTY_PTFXCURRENT|DIRTY_STYLESTATE); // Set dirty
60 return TRUE;
61 }
62
63
64 /*
65 * @implemented
66 */
67 BOOL
68 WINAPI
69 Ellipse(
70 _In_ HDC hdc,
71 _In_ INT left,
72 _In_ INT top,
73 _In_ INT right,
74 _In_ INT bottom)
75 {
76 HANDLE_METADC(BOOL, Ellipse, FALSE, hdc, left, top, right, bottom);
77
78 return NtGdiEllipse(hdc, left, top, right, bottom);
79 }
80
81
82 /*
83 * @implemented
84 */
85 BOOL
86 WINAPI
87 Rectangle(
88 _In_ HDC hdc,
89 _In_ INT left,
90 _In_ INT top,
91 _In_ INT right,
92 _In_ INT bottom)
93 {
94 HANDLE_METADC(BOOL, Rectangle, FALSE, hdc, left, top, right, bottom);
95
96 return NtGdiRectangle(hdc, left, top, right, bottom);
97 }
98
99
100 /*
101 * @implemented
102 */
103 BOOL
104 WINAPI
105 RoundRect(
106 _In_ HDC hdc,
107 _In_ INT left,
108 _In_ INT top,
109 _In_ INT right,
110 _In_ INT bottom,
111 _In_ INT width,
112 _In_ INT height)
113 {
114 HANDLE_METADC(BOOL, RoundRect, FALSE, hdc, left, top, right, bottom, width, height);
115
116 return NtGdiRoundRect(hdc, left, top, right, bottom, width, height);
117 }
118
119
120 /*
121 * @implemented
122 */
123 COLORREF
124 WINAPI
125 GetPixel(
126 _In_ HDC hdc,
127 _In_ INT x,
128 _In_ INT y)
129 {
130 if (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC) return CLR_INVALID;
131 if (!GdiValidateHandle((HGDIOBJ) hdc)) return CLR_INVALID;
132 return NtGdiGetPixel(hdc, x, y);
133 }
134
135
136 /*
137 * @implemented
138 */
139 COLORREF
140 WINAPI
141 SetPixel(
142 _In_ HDC hdc,
143 _In_ INT x,
144 _In_ INT y,
145 _In_ COLORREF crColor)
146 {
147 HANDLE_METADC(COLORREF, SetPixel, CLR_INVALID, hdc, x, y, crColor);
148
149 return NtGdiSetPixel(hdc, x, y, crColor);
150 }
151
152
153 /*
154 * @implemented
155 */
156 BOOL
157 WINAPI
158 SetPixelV(
159 _In_ HDC hdc,
160 _In_ INT x,
161 _In_ INT y,
162 _In_ COLORREF crColor)
163 {
164 return SetPixel(hdc, x, y, crColor) != CLR_INVALID;
165 }
166
167
168 /*
169 * @implemented
170 */
171 BOOL
172 WINAPI
173 FillRgn(
174 _In_ HDC hdc,
175 _In_ HRGN hrgn,
176 _In_ HBRUSH hbr)
177 {
178
179 if ((hrgn == NULL) || (hbr == NULL))
180 return FALSE;
181
182 HANDLE_METADC(BOOL, FillRgn, FALSE, hdc, hrgn, hbr);
183
184 return NtGdiFillRgn(hdc, hrgn, hbr);
185 }
186
187
188 /*
189 * @implemented
190 */
191 BOOL
192 WINAPI
193 FrameRgn(
194 _In_ HDC hdc,
195 _In_ HRGN hrgn,
196 _In_ HBRUSH hbr,
197 _In_ INT nWidth,
198 _In_ INT nHeight)
199 {
200
201 if ((hrgn == NULL) || (hbr == NULL))
202 return FALSE;
203
204 HANDLE_METADC(BOOL, FrameRgn, FALSE, hdc, hrgn, hbr, nWidth, nHeight);
205
206 return NtGdiFrameRgn(hdc, hrgn, hbr, nWidth, nHeight);
207 }
208
209
210 /*
211 * @implemented
212 */
213 BOOL
214 WINAPI
215 InvertRgn(
216 _In_ HDC hdc,
217 _In_ HRGN hrgn)
218 {
219
220 if (hrgn == NULL)
221 return FALSE;
222
223 HANDLE_METADC(BOOL, InvertRgn, FALSE, hdc, hrgn);
224
225 return NtGdiInvertRgn(hdc, hrgn);
226 }
227
228
229 /*
230 * @implemented
231 */
232 BOOL
233 WINAPI
234 PaintRgn(
235 _In_ HDC hdc,
236 _In_ HRGN hrgn)
237 {
238 return FillRgn(hdc, hrgn, GetCurrentObject(hdc, OBJ_BRUSH));
239 }
240
241
242 /*
243 * @implemented
244 */
245 BOOL
246 WINAPI
247 PolyBezier(
248 _In_ HDC hdc,
249 _In_reads_(cpt) const POINT *apt,
250 _In_ DWORD cpt)
251 {
252 HANDLE_METADC(BOOL, PolyBezier, FALSE, hdc, apt, cpt);
253
254 return NtGdiPolyPolyDraw(hdc ,(PPOINT)apt, &cpt, 1, GdiPolyBezier);
255 }
256
257
258 /*
259 * @implemented
260 */
261 BOOL
262 WINAPI
263 PolyBezierTo(
264 _In_ HDC hdc,
265 _In_reads_(cpt) const POINT *apt,
266 _In_ DWORD cpt)
267 {
268 HANDLE_METADC(BOOL, PolyBezierTo, FALSE, hdc, apt, cpt);
269
270 return NtGdiPolyPolyDraw(hdc , (PPOINT)apt, &cpt, 1, GdiPolyBezierTo);
271 }
272
273
274 /*
275 * @implemented
276 */
277 BOOL
278 WINAPI
279 PolyDraw(
280 _In_ HDC hdc,
281 _In_reads_(cpt) const POINT *apt,
282 _In_reads_(cpt) const BYTE *aj,
283 _In_ INT cpt)
284 {
285 HANDLE_METADC(BOOL, PolyDraw, FALSE, hdc, apt, aj, cpt);
286
287 return NtGdiPolyDraw(hdc, (PPOINT)apt, (PBYTE)aj, cpt);
288 }
289
290
291 /*
292 * @implemented
293 */
294 BOOL
295 WINAPI
296 Polygon(
297 _In_ HDC hdc,
298 _In_reads_(cpt) const POINT *apt,
299 _In_ INT cpt)
300 {
301 HANDLE_METADC(BOOL, Polygon, FALSE, hdc, apt, cpt);
302
303 return NtGdiPolyPolyDraw(hdc , (PPOINT)apt, (PULONG)&cpt, 1, GdiPolyPolygon);
304 }
305
306
307 /*
308 * @implemented
309 */
310 BOOL
311 WINAPI
312 Polyline(
313 _In_ HDC hdc,
314 _In_reads_(cpt) const POINT *apt,
315 _In_ INT cpt)
316 {
317 HANDLE_METADC(BOOL, Polyline, FALSE, hdc, apt, cpt);
318
319 return NtGdiPolyPolyDraw(hdc, (PPOINT)apt, (PULONG)&cpt, 1, GdiPolyPolyLine);
320 }
321
322
323 /*
324 * @implemented
325 */
326 BOOL
327 WINAPI
328 PolylineTo(
329 _In_ HDC hdc,
330 _In_reads_(cpt) const POINT *apt,
331 _In_ DWORD cpt)
332 {
333 HANDLE_METADC(BOOL, PolylineTo, FALSE, hdc, apt, cpt);
334
335 return NtGdiPolyPolyDraw(hdc , (PPOINT)apt, &cpt, 1, GdiPolyLineTo);
336 }
337
338
339 /*
340 * @implemented
341 */
342 BOOL
343 WINAPI
344 PolyPolygon(
345 _In_ HDC hdc,
346 _In_ const POINT *apt,
347 _In_reads_(csz) const INT *asz,
348 _In_ INT csz)
349 {
350 HANDLE_METADC(BOOL, PolyPolygon, FALSE, hdc, apt, asz, csz);
351
352 return NtGdiPolyPolyDraw(hdc, (PPOINT)apt, (PULONG)asz, csz, GdiPolyPolygon);
353 }
354
355
356 /*
357 * @implemented
358 */
359 BOOL
360 WINAPI
361 PolyPolyline(
362 _In_ HDC hdc,
363 _In_ CONST POINT *apt,
364 _In_reads_(csz) CONST DWORD *asz,
365 _In_ DWORD csz)
366 {
367 if (GDI_HANDLE_GET_TYPE(hdc) == GDILoObjType_LO_METADC16_TYPE)
368 return FALSE;
369
370 HANDLE_METADC(BOOL, PolyPolyline, FALSE, hdc, apt, asz, csz);
371
372 return NtGdiPolyPolyDraw(hdc , (PPOINT)apt, (PULONG)asz, csz, GdiPolyPolyLine);
373 }
374
375
376 /*
377 * @implemented
378 */
379 BOOL
380 WINAPI
381 ExtFloodFill(
382 _In_ HDC hdc,
383 _In_ INT xStart,
384 _In_ INT yStart,
385 _In_ COLORREF crFill,
386 _In_ UINT fuFillType)
387 {
388 HANDLE_METADC(BOOL, ExtFloodFill, FALSE, hdc, xStart, yStart, crFill, fuFillType);
389
390 return NtGdiExtFloodFill(hdc, xStart, yStart, crFill, fuFillType);
391 }
392
393
394 /*
395 * @implemented
396 */
397 BOOL
398 WINAPI
399 FloodFill(
400 _In_ HDC hdc,
401 _In_ INT xStart,
402 _In_ INT yStart,
403 _In_ COLORREF crFill)
404 {
405 return ExtFloodFill(hdc, xStart, yStart, crFill, FLOODFILLBORDER);
406 }
407
408 /*
409 * @implemented
410 */
411 BOOL
412 WINAPI
413 BitBlt(
414 _In_ HDC hdcDest,
415 _In_ INT xDest,
416 _In_ INT yDest,
417 _In_ INT cx,
418 _In_ INT cy,
419 _In_opt_ HDC hdcSrc,
420 _In_ INT xSrc,
421 _In_ INT ySrc,
422 _In_ DWORD dwRop)
423 {
424 /* Use PatBlt for no source blt, like windows does */
425 if (!ROP_USES_SOURCE(dwRop))
426 {
427 return PatBlt(hdcDest, xDest, yDest, cx, cy, dwRop);
428 }
429
430 /* For meta DCs we use StretchBlt */
431 HANDLE_METADC(BOOL,
432 StretchBlt,
433 FALSE,
434 hdcDest,
435 xDest,
436 yDest,
437 cx,
438 cx,
439 hdcSrc,
440 xSrc,
441 ySrc,
442 cx,
443 cx,
444 dwRop);
445
446 return NtGdiBitBlt(hdcDest, xDest, yDest, cx, cy, hdcSrc, xSrc, ySrc, dwRop, 0, 0);
447 }
448
449 BOOL
450 WINAPI
451 PatBlt(
452 _In_ HDC hdc,
453 _In_ INT nXLeft,
454 _In_ INT nYLeft,
455 _In_ INT nWidth,
456 _In_ INT nHeight,
457 _In_ DWORD dwRop)
458 {
459 HANDLE_METADC(BOOL, PatBlt, FALSE, hdc, nXLeft, nYLeft, nWidth, nHeight, dwRop);
460
461 /* FIXME some part need be done in user mode */
462 return NtGdiPatBlt( hdc, nXLeft, nYLeft, nWidth, nHeight, dwRop);
463 }
464
465 BOOL
466 WINAPI
467 PolyPatBlt(
468 _In_ HDC hdc,
469 _In_ DWORD dwRop,
470 _In_ PPOLYPATBLT pPoly,
471 _In_ DWORD nCount,
472 _In_ DWORD dwMode)
473 {
474 UINT i;
475 BOOL bResult;
476 HBRUSH hbrOld;
477
478 /* Handle meta DCs */
479 if ((GDI_HANDLE_GET_TYPE(hdc) == GDILoObjType_LO_METADC16_TYPE) ||
480 (GDI_HANDLE_GET_TYPE(hdc) == GDILoObjType_LO_ALTDC_TYPE))
481 {
482 if (!GdiValidateHandle(hdc))
483 {
484 return FALSE;
485 }
486
487 /* Save the current DC brush */
488 hbrOld = SelectObject(hdc, GetStockObject(DC_BRUSH));
489
490 /* Assume success */
491 bResult = TRUE;
492
493 /* Loop all rect */
494 for (i = 0; i < nCount; i++)
495 {
496 /* Select the brush for this rect */
497 SelectObject(hdc, pPoly[i].hBrush);
498
499 /* Do the PatBlt operation for this rect */
500 bResult &= PatBlt(hdc,
501 pPoly[i].nXLeft,
502 pPoly[i].nYLeft,
503 pPoly[i].nWidth,
504 pPoly[i].nHeight,
505 dwRop);
506 }
507
508 /* Restore the old brush */
509 SelectObject(hdc, hbrOld);
510
511 return bResult;
512 }
513
514 /* FIXME some part need be done in user mode */
515 return NtGdiPolyPatBlt(hdc, dwRop, pPoly, nCount, dwMode);
516 }
517
518 /*
519 * @implemented
520 */
521 BOOL
522 WINAPI
523 StretchBlt(
524 _In_ HDC hdcDest,
525 _In_ INT xDest,
526 _In_ INT yDest,
527 _In_ INT cxDest,
528 _In_ INT cyDest,
529 _In_opt_ HDC hdcSrc,
530 _In_ INT xSrc,
531 _In_ INT ySrc,
532 _In_ INT cxSrc,
533 _In_ INT cySrc,
534 _In_ DWORD dwRop)
535 {
536 HANDLE_METADC(BOOL,
537 StretchBlt,
538 FALSE,
539 hdcDest,
540 xDest,
541 yDest,
542 cxDest,
543 cyDest,
544 hdcSrc,
545 xSrc,
546 ySrc,
547 cxSrc,
548 cySrc,
549 dwRop);
550
551 return NtGdiStretchBlt(hdcDest,
552 xDest,
553 yDest,
554 cxDest,
555 cyDest,
556 hdcSrc,
557 xSrc,
558 ySrc,
559 cxSrc,
560 cySrc,
561 dwRop,
562 0);
563 }
564
565
566 /*
567 * @implemented
568 */
569 BOOL
570 WINAPI
571 MaskBlt(
572 _In_ HDC hdcDest,
573 _In_ INT xDest,
574 _In_ INT yDest,
575 _In_ INT cx,
576 _In_ INT cy,
577 _In_ HDC hdcSrc,
578 _In_ INT xSrc,
579 _In_ INT ySrc,
580 _In_ HBITMAP hbmMask,
581 _In_ INT xMask,
582 _In_ INT yMask,
583 _In_ DWORD dwRop)
584 {
585 HANDLE_METADC(BOOL,
586 MaskBlt,
587 FALSE,
588 hdcDest,
589 xDest,
590 yDest,
591 cx,
592 cy,
593 hdcSrc,
594 xSrc,
595 ySrc,
596 hbmMask,
597 xMask,
598 yMask,
599 dwRop);
600
601 return NtGdiMaskBlt(hdcDest,
602 xDest,
603 yDest,
604 cx,
605 cy,
606 hdcSrc,
607 xSrc,
608 ySrc,
609 hbmMask,
610 xMask,
611 yMask,
612 dwRop,
613 GetBkColor(hdcSrc));
614 }
615
616
617 /*
618 * @implemented
619 */
620 BOOL
621 WINAPI
622 PlgBlt(
623 _In_ HDC hdcDest,
624 _In_reads_(3) const POINT * ppt,
625 _In_ HDC hdcSrc,
626 _In_ INT xSrc,
627 _In_ INT ySrc,
628 _In_ INT cx,
629 _In_ INT cy,
630 _In_opt_ HBITMAP hbmMask,
631 _In_ INT xMask,
632 _In_ INT yMask)
633 {
634 HANDLE_METADC(BOOL,
635 PlgBlt,
636 FALSE,
637 hdcDest,
638 ppt,
639 hdcSrc,
640 xSrc,
641 ySrc,
642 cx,
643 cy,
644 hbmMask,
645 xMask,
646 yMask);
647
648 return NtGdiPlgBlt(hdcDest,
649 (LPPOINT)ppt,
650 hdcSrc,
651 xSrc,
652 ySrc,
653 cx,
654 cy,
655 hbmMask,
656 xMask,
657 yMask,
658 GetBkColor(hdcSrc));
659 }
660
661 BOOL
662 WINAPI
663 GdiAlphaBlend(
664 _In_ HDC hdcDst,
665 _In_ INT xDst,
666 _In_ INT yDst,
667 _In_ INT cxDst,
668 _In_ INT cyDst,
669 _In_ HDC hdcSrc,
670 _In_ INT xSrc,
671 _In_ INT ySrc,
672 _In_ INT cxSrc,
673 _In_ INT cySrc,
674 _In_ BLENDFUNCTION blendfn)
675 {
676 if (hdcSrc == NULL ) return FALSE;
677
678 if (GDI_HANDLE_GET_TYPE(hdcSrc) == GDI_OBJECT_TYPE_METADC) return FALSE;
679
680 HANDLE_METADC(BOOL,
681 AlphaBlend,
682 FALSE,
683 hdcDst,
684 xDst,
685 yDst,
686 cxDst,
687 cyDst,
688 hdcSrc,
689 xSrc,
690 ySrc,
691 cxSrc,
692 cySrc,
693 blendfn);
694
695 return NtGdiAlphaBlend(hdcDst,
696 xDst,
697 yDst,
698 cxDst,
699 cyDst,
700 hdcSrc,
701 xSrc,
702 ySrc,
703 cxSrc,
704 cySrc,
705 blendfn,
706 0);
707 }
708
709
710 /*
711 * @implemented
712 */
713 BOOL
714 WINAPI
715 GdiTransparentBlt(
716 _In_ HDC hdcDst,
717 _In_ INT xDst,
718 _In_ INT yDst,
719 _In_ INT cxDst,
720 _In_ INT cyDst,
721 _In_ HDC hdcSrc,
722 _In_ INT xSrc,
723 _In_ INT ySrc,
724 _In_ INT cxSrc,
725 _In_ INT cySrc,
726 _In_ UINT crTransparent)
727 {
728 HANDLE_METADC(BOOL,
729 TransparentBlt,
730 FALSE,
731 hdcDst,
732 xDst,
733 yDst,
734 cxDst,
735 cyDst,
736 hdcSrc,
737 xSrc,
738 ySrc,
739 cxSrc,
740 cySrc,
741 crTransparent);
742
743 /* FIXME some part need be done in user mode */
744 return NtGdiTransparentBlt(hdcDst, xDst, yDst, cxDst, cyDst, hdcSrc, xSrc, ySrc, cxSrc, cySrc, crTransparent);
745 }
746
747 /*
748 * @implemented
749 */
750 BOOL
751 WINAPI
752 GdiGradientFill(
753 _In_ HDC hdc,
754 _In_reads_(nVertex) PTRIVERTEX pVertex,
755 _In_ ULONG nVertex,
756 _In_ PVOID pMesh,
757 _In_ ULONG nCount,
758 _In_ ULONG ulMode)
759 {
760 HANDLE_METADC(BOOL, GradientFill, FALSE, hdc, pVertex, nVertex, pMesh, nCount, ulMode);
761
762 /* FIXME some part need be done in user mode */
763 return NtGdiGradientFill(hdc, pVertex, nVertex, pMesh, nCount, ulMode);
764 }