update for HEAD-2003091401
[reactos.git] / apps / tests / shaptest / shaptest.c
index 3ef8e4d..693cfc3 100644 (file)
 
 #include <windows.h>
 #include <stdio.h>
+#include <assert.h>
 
+#ifndef ASSERT
+#define ASSERT assert
+#endif
+
+#define nelem(x) (sizeof (x) / sizeof *(x))
 
 HFONT tf;
 LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM);
 
-void __stdcall PolygonTest(HDC Desktop)
+void PolygonTest ( HDC hdc )
 {
-       HPEN BluePen;  
-       HPEN OldPen;
-       HBRUSH RedBrush;
-       HBRUSH OldBrush;
-       POINT lpPointsAlternate[5];
-       POINT lpPointsWinding[5];
-       DWORD Mode;
-
-       //create a pen to draw the shape
-       BluePen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0xff));
-       RedBrush = CreateSolidBrush(RGB(0xff, 0, 0));
-
-       //initialize a set of points for alternate.
-       lpPointsAlternate[0].x = 20;
-       lpPointsAlternate[0].y = 80; //{20,80};
-       lpPointsAlternate[1].x = 60;
-       lpPointsAlternate[1].y = 20; //{60,20};
-       lpPointsAlternate[2].x = 90;
-       lpPointsAlternate[2].y = 80; //{90,80};
-       lpPointsAlternate[3].x = 20;
-       lpPointsAlternate[3].y = 40; //{20,40};
-       lpPointsAlternate[4].x = 100;
-       lpPointsAlternate[4].y = 40; //{100,40};
-
-       //initialize a set of points for winding.
-       lpPointsWinding[0].x = 130;
-       lpPointsWinding[0].y = 80; //{130,80};
-       lpPointsWinding[1].x = 170;
-       lpPointsWinding[1].y = 20; //{170,20};
-       lpPointsWinding[2].x = 200;
-       lpPointsWinding[2].y = 80; //{200,80};
-       lpPointsWinding[3].x = 130;
-       lpPointsWinding[3].y = 40; //{130,40};
-       lpPointsWinding[4].x = 210;
-       lpPointsWinding[4].y = 40; //{210,40};
-
-       OldPen = (HPEN)SelectObject(Desktop, BluePen);
-       OldBrush = (HBRUSH)SelectObject(Desktop, RedBrush);
-
-       Mode = GetPolyFillMode(Desktop);
-
-       SetPolyFillMode(Desktop, ALTERNATE);
-       Polygon(Desktop,lpPointsAlternate,5);
-
-       SetPolyFillMode(Desktop, WINDING);
-       Polygon(Desktop,lpPointsWinding,5);
-       
-       //cleanup
-       SetPolyFillMode(Desktop, Mode);
-       SelectObject(Desktop, OldPen);
-       SelectObject(Desktop, OldBrush);
-       DeleteObject(BluePen);
-       DeleteObject(RedBrush);
-
+  HPEN Pen, OldPen;
+  HBRUSH RedBrush, OldBrush;
+  DWORD Mode;
+  POINT PointsAlternate[] =
+  {
+    { 20, 80 },
+    { 60, 20 },
+    { 90, 80 },
+    { 20, 40 },
+    { 100, 40 }
+  };
+  POINT PointsWinding[] =
+  {
+    { 130, 80 },
+    { 170, 20 },
+    { 200, 80 },
+    { 130, 40 },
+    { 210, 40 }
+  };
+  POINT Tri1[] =
+  {
+    { 3, 3 },
+    { 5, 3 },
+    { 3, 5 }
+  };
+  POINT Tri2[] =
+  {
+    { 7, 3 },
+    { 7, 7 },
+    { 3, 7 },
+  };
+  POINT Square1[] =
+  {
+    { 1, 15 },
+    { 3, 15 },
+    { 3, 17 },
+    { 1, 17 }
+  };
+  POINT Square2[] =
+  {
+    { 5, 15 },
+    { 7, 15 },
+    { 7, 17 },
+    { 5, 17 }
+  };
+  POINT Square3[] =
+  {
+    { 1, 23 },
+    { 3, 23 },
+    { 3, 25 },
+    { 1, 25 }
+  };
+  POINT Square4[] =
+  {
+    { 5, 23 },
+    { 7, 23 },
+    { 7, 25 },
+    { 5, 25 }
+  };
+  POINT Square5[] =
+  {
+    { 1, 31 },
+    { 3, 31 },
+    { 3, 33 },
+    { 1, 33 }
+  };
+  POINT Square6[] =
+  {
+    { 5, 31 },
+    { 7, 31 },
+    { 7, 33 },
+    { 5, 33 }
+  };
+
+  //create a pen to draw the shape
+  Pen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0xff));
+  ASSERT(Pen);
+  RedBrush = CreateSolidBrush(RGB(0xff, 0, 0));
+  ASSERT(RedBrush);
+
+  OldPen = (HPEN)SelectObject(hdc, Pen);
+  OldBrush = (HBRUSH)SelectObject(hdc, RedBrush);
+
+  Mode = GetPolyFillMode(hdc);
+
+  RoundRect ( hdc, 32, 8, 48, 24, 8, 8 );
+
+  SetPolyFillMode(hdc, ALTERNATE);
+  Polygon(hdc,PointsAlternate,nelem(PointsAlternate));
+
+  SetPolyFillMode(hdc, WINDING);
+  Polygon(hdc,PointsWinding,nelem(PointsWinding));
+
+  Rectangle ( hdc, 1, 1, 10, 10 );
+  Polygon(hdc,Tri1,nelem(Tri1));
+  Polygon(hdc,Tri2,nelem(Tri2));
+
+  Rectangle ( hdc,  1, 11,  4, 14 );
+  Rectangle ( hdc,  5, 11,  8, 14 );
+  Rectangle ( hdc,  9, 11, 12, 14 );
+  Rectangle ( hdc, 13, 11, 16, 14 );
+  Polygon(hdc,Square1,nelem(Square1));
+  Polygon(hdc,Square2,nelem(Square2));
+  Rectangle ( hdc,  1, 19,  4, 22 );
+  Rectangle ( hdc,  5, 19,  8, 22 );
+  Rectangle ( hdc,  9, 19, 12, 22 );
+  Rectangle ( hdc, 13, 19, 16, 22 );
+  Polygon(hdc,Square3,nelem(Square3));
+  Polygon(hdc,Square4,nelem(Square4));
+  Rectangle ( hdc,  1, 27,  4, 30 );
+  Rectangle ( hdc,  5, 27,  8, 30 );
+  Rectangle ( hdc,  9, 27, 12, 30 );
+  Rectangle ( hdc, 13, 27, 16, 30 );
+
+  // switch to null pen to make surey they display correctly
+  DeleteObject ( SelectObject(hdc, OldPen) );
+  Pen = CreatePen ( PS_NULL, 0, 0 );
+  ASSERT(Pen);
+  OldPen = (HPEN)SelectObject(hdc, Pen);
+
+  Polygon(hdc,Square5,nelem(Square5));
+  Polygon(hdc,Square6,nelem(Square6));
+  Rectangle ( hdc,  1, 35,  4, 38 );
+  Rectangle ( hdc,  5, 35,  8, 38 );
+  Rectangle ( hdc,  9, 35, 12, 38 );
+  Rectangle ( hdc, 13, 35, 16, 38 );
+
+  //cleanup
+  SetPolyFillMode(hdc, Mode);
+  DeleteObject ( SelectObject(hdc, OldPen) );
+  DeleteObject ( SelectObject(hdc, OldBrush) );
 }
 
 
-void shaptest( HDC DevCtx ){
-  HDC  Desktop, MyDC, DC24;
-  HPEN  RedPen, GreenPen, BluePen, WhitePen;
-  HBITMAP  MyBitmap, DIB24;
-  HFONT  hf, tf;
-  BITMAPINFOHEADER BitInf;
-  BITMAPINFO BitPalInf;
-  HRGN hRgn1, hRgn2, hRgn3;
-  HBRUSH BlueBrush, DefBrush;
-  int sec,Xmod,Ymod;
-  char tbuf[5];
-
-
-  BlueBrush = CreateSolidBrush( RGB(0, 0, 0xff) );
-  DefBrush = SelectObject( DevCtx, BlueBrush );
-
-  SelectObject( DevCtx, DefBrush );
-  DeleteObject( BlueBrush );
-
-  // Create a blue pen and select it into the DC
-  BluePen = CreatePen(PS_SOLID, 8, RGB(0, 0, 0xff));
-  SelectObject(DevCtx, BluePen);
-
+void shaptest( HDC hdc )
+{
   //Test the Polygon routine.
-  PolygonTest(DevCtx);
+  PolygonTest(hdc);
 }
 
 
@@ -116,8 +178,8 @@ WinMain(HINSTANCE hInstance,
   wc.lpfnWndProc = MainWndProc;
   wc.style = CS_VREDRAW | CS_HREDRAW;
   wc.hInstance = hInstance;
-  wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
-  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+  wc.hIcon = (HICON)LoadIcon(NULL, (LPCTSTR)IDI_APPLICATION);
+  wc.hCursor = (HCURSOR)LoadCursor(NULL, (LPCTSTR)IDC_ARROW);
   wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
   wc.lpszMenuName = NULL;
   wc.cbClsExtra = 0;
@@ -125,7 +187,7 @@ WinMain(HINSTANCE hInstance,
   if (RegisterClass(&wc) == 0)
     {
       fprintf(stderr, "RegisterClass failed (last error 0x%X)\n",
-             GetLastError());
+             (unsigned int)GetLastError());
       return(1);
     }
 
@@ -143,7 +205,7 @@ WinMain(HINSTANCE hInstance,
   if (hWnd == NULL)
     {
       fprintf(stderr, "CreateWindow failed (last error 0x%X)\n",
-             GetLastError());
+             (unsigned int)GetLastError());
       return(1);
     }
 
@@ -166,27 +228,25 @@ WinMain(HINSTANCE hInstance,
 
 LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
-       PAINTSTRUCT ps;
-       HDC hDC;
-       RECT clr, wir;
-        char spr[100], sir[100];
-
-       switch(msg)
-       {
-       
-       case WM_PAINT:
-         hDC = BeginPaint(hWnd, &ps);
-         shaptest( hDC );
-         EndPaint(hWnd, &ps);
-         break;
-
-       case WM_DESTROY:
-         PostQuitMessage(0);
-         break;
-
-       default:
-         return DefWindowProc(hWnd, msg, wParam, lParam);
-       }
-       return 0;
+  PAINTSTRUCT ps;
+  HDC hDC;
+
+  switch(msg)
+  {
+  
+  case WM_PAINT:
+    hDC = BeginPaint(hWnd, &ps);
+    shaptest( hDC );
+    EndPaint(hWnd, &ps);
+    break;
+
+  case WM_DESTROY:
+    PostQuitMessage(0);
+    break;
+
+  default:
+    return DefWindowProc(hWnd, msg, wParam, lParam);
+  }
+  return 0;
 }