From b25c2dc92bfc94c3e4d99fe1391d2f33045128dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Mon, 14 Jul 2003 09:47:47 +0000 Subject: [PATCH] Line clipping test program svn path=/trunk/; revision=5112 --- reactos/apps/tests/lineclip/.cvsignore | 7 ++ reactos/apps/tests/lineclip/lineclip.c | 167 +++++++++++++++++++++++++ reactos/apps/tests/lineclip/makefile | 21 ++++ 3 files changed, 195 insertions(+) create mode 100644 reactos/apps/tests/lineclip/.cvsignore create mode 100644 reactos/apps/tests/lineclip/lineclip.c create mode 100644 reactos/apps/tests/lineclip/makefile diff --git a/reactos/apps/tests/lineclip/.cvsignore b/reactos/apps/tests/lineclip/.cvsignore new file mode 100644 index 00000000000..7a0e35791aa --- /dev/null +++ b/reactos/apps/tests/lineclip/.cvsignore @@ -0,0 +1,7 @@ +lineclip.exe +lineclip.nostrip.exe +lineclip.sym +lineclip.coff +*.d +*.o +*.map diff --git a/reactos/apps/tests/lineclip/lineclip.c b/reactos/apps/tests/lineclip/lineclip.c new file mode 100644 index 00000000000..b82809cb043 --- /dev/null +++ b/reactos/apps/tests/lineclip/lineclip.c @@ -0,0 +1,167 @@ +#include +#include + +LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM); + +int WINAPI +WinMain(HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpszCmdLine, + int nCmdShow) +{ + WNDCLASS wc; + MSG msg; + HWND hWnd; + + wc.lpszClassName = "ClipClass"; + 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.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); + wc.lpszMenuName = NULL; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + if (RegisterClass(&wc) == 0) + { + fprintf(stderr, "RegisterClass failed (last error 0x%X)\n", + GetLastError()); + return(1); + } + + hWnd = CreateWindow("ClipClass", + "Line clipping test", + WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL, + 0, + 0, + CW_USEDEFAULT, + CW_USEDEFAULT, + NULL, + NULL, + hInstance, + NULL); + if (hWnd == NULL) + { + fprintf(stderr, "CreateWindow failed (last error 0x%X)\n", + GetLastError()); + return(1); + } + + ShowWindow(hWnd, nCmdShow); + + while(GetMessage(&msg, NULL, 0, 0)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + return msg.wParam; +} + +static void +DrawLines(HDC hDC) +{ + static struct + { + int fromx; + int fromy; + int tox; + int toy; + } + points[ ] = + { + { 50, 99, 125, 99 }, + { 160, 99, 190, 99 }, + { 300, 99, 225, 99 }, + { 50, 100, 125, 100 }, + { 160, 100, 190, 100 }, + { 300, 100, 225, 100 }, + { 50, 125, 300, 125 }, + { 50, 149, 125, 149 }, + { 160, 149, 190, 149 }, + { 300, 149, 225, 149 }, + { 50, 150, 125, 150 }, + { 160, 150, 190, 150 }, + { 300, 150, 225, 150 }, + { 160, 249, 190, 249 }, + { 160, 250, 190, 250 }, + { 149, 50, 149, 125 }, + { 149, 160, 149, 190 }, + { 149, 300, 149, 225 }, + { 150, 50, 150, 125 }, + { 150, 160, 150, 190 }, + { 150, 300, 150, 225 }, + { 199, 50, 199, 125 }, + { 199, 160, 199, 190 }, + { 199, 300, 199, 225 }, + { 200, 50, 200, 125 }, + { 200, 160, 200, 190 }, + { 200, 300, 200, 225 }, + { 175, 50, 175, 300 }, + { 50, 55, 300, 290 }, + { 300, 295, 50, 60 }, + { 50, 290, 300, 55 }, + { 300, 60, 50, 295 }, + { 55, 50, 290, 300 }, + { 295, 300, 60, 50 }, + { 55, 300, 290, 50 }, + { 295, 50, 60, 300 } + }; + int i; + + for (i = 0; i < sizeof(points) / sizeof(points[0]); i++) + { + MoveToEx(hDC, points[i].fromx, points[i].fromy, NULL); + LineTo(hDC, points[i].tox, points[i].toy); + } +} + +LRESULT CALLBACK MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + PAINTSTRUCT ps; + HDC hDC; + RECT clr, wir; + HRGN ClipRgn, ExcludeRgn; + char spr[100], sir[100]; + RECT Rect; + + switch(msg) + { + case WM_PAINT: + GetClientRect(hWnd, &clr); + ClipRgn = CreateRectRgnIndirect(&clr); + hDC = BeginPaint(hWnd, &ps); + Rect.left = 100; + Rect.top = 100; + Rect.right = 250; + Rect.bottom = 150; + FillRect(hDC, &Rect, CreateSolidBrush(RGB(0xFF, 0x00, 0x00))); + ExcludeRgn = CreateRectRgnIndirect(&Rect); + CombineRgn(ClipRgn, ClipRgn, ExcludeRgn, RGN_DIFF); + DeleteObject(ExcludeRgn); + Rect.left = 150; + Rect.top = 150; + Rect.right = 200; + Rect.bottom = 250; + FillRect(hDC, &Rect, CreateSolidBrush(RGB(0xFF, 0x00, 0x00))); + SelectObject(hDC, CreatePen(PS_SOLID, 0, RGB(0xFF, 0xFF, 0x00))); + DrawLines(hDC); + SelectObject(hDC, CreatePen(PS_SOLID, 0, RGB(0x00, 0x00, 0xFF))); + ExcludeRgn = CreateRectRgnIndirect(&Rect); + CombineRgn(ClipRgn, ClipRgn, ExcludeRgn, RGN_DIFF); + DeleteObject(ExcludeRgn); + SelectClipRgn(hDC, ClipRgn); + DrawLines(hDC); + EndPaint(hWnd, &ps); + break; + + case WM_DESTROY: + PostQuitMessage(0); + break; + + default: + return DefWindowProc(hWnd, msg, wParam, lParam); + } + return 0; +} diff --git a/reactos/apps/tests/lineclip/makefile b/reactos/apps/tests/lineclip/makefile new file mode 100644 index 00000000000..ec106b86fc1 --- /dev/null +++ b/reactos/apps/tests/lineclip/makefile @@ -0,0 +1,21 @@ +# $Id: makefile,v 1.1 2003/07/14 09:47:47 gvg Exp $ + +PATH_TO_TOP = ../../.. + +TARGET_NORC = yes + +TARGET_TYPE = program + +TARGET_APPTYPE = windows + +TARGET_NAME = lineclip + +TARGET_SDKLIBS = kernel32.a gdi32.a + +TARGET_OBJECTS = $(TARGET_NAME).o + +include $(PATH_TO_TOP)/rules.mak + +include $(TOOLS_PATH)/helper.mk + +# EOF