delete .cvsignore
[reactos.git] / rosapps / notevil / notevil.c
index 3466d92..166dd75 100644 (file)
@@ -1,7 +1,7 @@
-/* $Id: notevil.c,v 1.1 1999/05/15 07:23:34 ea Exp $
+/* $Id$
  *
  * notevil.c
- * 
+ *
  * --------------------------------------------------------------------
  *
  * This software is free software; you can redistribute it and/or
@@ -17,7 +17,7 @@
  * You should have received a copy of the GNU Library General Public
  * License along with this software; see the file COPYING.LIB. If
  * not, write to the Free Software Foundation, Inc., 675 Mass Ave,
- * Cambridge, MA 02139, USA.  
+ * Cambridge, MA 02139, USA.
  *
  * --------------------------------------------------------------------
  * ReactOS Coders Console Parade
@@ -36,6 +36,8 @@ LPCTSTR app_name = _TEXT("notevil");
 
 HANDLE myself;
 HANDLE ScreenBuffer;
+CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo;
+HANDLE WaitableTimer;
 
 void
 WriteStringAt(
@@ -47,14 +49,16 @@ WriteStringAt(
        DWORD   cWritten = 0;
        WORD    wLen = lstrlen(lpString);
 
-       if (0 == wLen) return;
-       WriteConsoleOutputCharacter(
-               ScreenBuffer,
-               lpString,
-               wLen,
-               xy,
-               & cWritten
-               );
+       if (0 == wLen)
+               return;
+       // don't bother writing text when erasing
+       if( wColor )
+         WriteConsoleOutputCharacter( ScreenBuffer,
+                                      lpString,
+                                      wLen,
+                                      xy,
+                                      & cWritten
+                                      );
        FillConsoleOutputAttribute(
                ScreenBuffer,
                wColor,
@@ -74,7 +78,7 @@ WriteCoord(COORD c)
 
        wsprintf(
                buf,
-               _TEXT("x=%d  y=%d"),
+               _TEXT("x=%02d  y=%02d"),
                c.X,
                c.Y
                );
@@ -111,21 +115,24 @@ GetNextString(
        return 0;
 }
 
-       
+
 VOID
 DisplayTitle(VOID)
 {
-       COORD   xy = {24,12};
+       LPTSTR szTitle = _TEXT("ReactOS Coders Console Parade");
+       COORD  xy;
+
+       xy.X = (ScreenBufferInfo.dwSize.X - lstrlen(szTitle)) / 2;
+       xy.Y = ScreenBufferInfo.dwSize.Y / 2;
 
        WriteStringAt(
-               _TEXT("ReactOS Coders Console Parade"),
+               szTitle,
                xy,
                (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
                );
 }
 
 
-
 #define RES_DELAY_CHANGE 12
 #define RES_BUFFER_SIZE  1024
 void
@@ -134,11 +141,14 @@ MainLoop(void)
        TCHAR   NameString [RES_BUFFER_SIZE];
        DWORD   NameIndex = 1;
        INT     NameLength = 0;
-       COORD   xy = {40,12}; 
+       COORD   xy;
        INT     n = RES_DELAY_CHANGE;
        INT     dir_y = 1;
        INT     dir_x = 1;
-       WORD    wColor = 0;
+       WORD    wColor = 1;
+
+       xy.X = ScreenBufferInfo.dwSize.X / 2;
+       xy.Y = ScreenBufferInfo.dwSize.Y / 2;
 
        for ( ; 1; ++n )
        {
@@ -150,25 +160,31 @@ MainLoop(void)
                                & NameIndex
                                );
                        NameLength = lstrlen(NameString);
-                       ++wColor;
+                       wColor++;
+                       if ((wColor & 0x000F) == 0)
+                               wColor = 1;
                }
-               if (!xy.X)
+               if (xy.X == 0)
                {
-                       if (dir_x == -1) dir_x = 1;
+                       if (dir_x == -1)
+                               dir_x = 1;
                }
-               else if (xy.X > 80 - NameLength)
+               else if (xy.X >= ScreenBufferInfo.dwSize.X - NameLength - 1)
                {
-                       if (dir_x == 1) dir_x = -1;
+                       if (dir_x == 1)
+                               dir_x = -1;
                }
                xy.X += dir_x;
-               switch (xy.Y)
+
+               if (xy.Y == 0)
+               {
+                       if (dir_y == -1)
+                               dir_y = 1;
+               }
+               else if (xy.Y >= ScreenBufferInfo.dwSize.Y - 1)
                {
-                       case 0:
-                               if (dir_y == -1) dir_y = 1;
-                               break;
-                       case 24:
-                               if (dir_y == 1) dir_y = -1;
-                               break;
+                       if (dir_y == 1)
+                               dir_y = -1;
                }
                xy.Y += dir_y;
 #ifdef DISPLAY_COORD
@@ -178,14 +194,14 @@ MainLoop(void)
                WriteStringAt(
                        NameString,
                        xy,
-                       (wColor & 0x000F)
+                       wColor
                        );
-               Sleep(100);
+               WaitForSingleObject( WaitableTimer, INFINITE );
                WriteStringAt(
                        NameString,
                        xy,
                        0
-                       );      
+                       );
        }
 }
 
@@ -196,8 +212,16 @@ main(
        char    *argv []
        )
 {
+        LARGE_INTEGER lint;
+       DWORD Written;
+       COORD Coord = { 0, 0 };
+
        myself = GetModuleHandle(NULL);
 
+       GetConsoleScreenBufferInfo (GetStdHandle(STD_OUTPUT_HANDLE),
+                                   &ScreenBufferInfo);
+       ScreenBufferInfo.dwSize.X = ScreenBufferInfo.srWindow.Right - ScreenBufferInfo.srWindow.Left + 1;
+       ScreenBufferInfo.dwSize.Y = ScreenBufferInfo.srWindow.Bottom - ScreenBufferInfo.srWindow.Top + 1;
        ScreenBuffer = CreateConsoleScreenBuffer(
                        GENERIC_WRITE,
                        0,
@@ -214,6 +238,25 @@ main(
                        );
                return EXIT_FAILURE;
        }
+       // Fill buffer with black background
+       FillConsoleOutputAttribute( ScreenBuffer,
+                                   0,
+                                   ScreenBufferInfo.dwSize.X * ScreenBufferInfo.dwSize.Y,
+                                   Coord,
+                                   &Written );
+
+       WaitableTimer = CreateWaitableTimer( NULL, FALSE, NULL );
+       if( WaitableTimer == INVALID_HANDLE_VALUE )
+         {
+           printf( "CreateWaitabletimer() failed\n" );
+           return 1;
+         }
+       lint.QuadPart = -2000000;
+       if( SetWaitableTimer( WaitableTimer, &lint, 200, NULL, NULL, FALSE ) == FALSE )
+         {
+           printf( "SetWaitableTimer() failed: %x\n", GetLastError() );
+           return 2;
+         }
        SetConsoleActiveScreenBuffer(ScreenBuffer);
        MainLoop();
        CloseHandle(ScreenBuffer);