home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / YOWZA.ZIP / SAMPLE.C < prev    next >
Text File  |  1990-09-27  |  4KB  |  126 lines

  1. #define INCL_OS2
  2. #define INCL_PM
  3.  
  4. #include <os2.h>
  5. #include <string.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8.  
  9. /**************************************************************************/
  10.   Any variables that must retain their values between draw proc. calls
  11.   must be global and should be defined here.
  12. /**************************************************************************/
  13.  
  14. VOID    define_global_variables_here;
  15.  
  16.  
  17.  /* The following are global variables used in the star-field alg. */
  18.  
  19. POINTL  points[3000];           /* array of points in the star field.        */
  20. SWP     windowPos;              /* position of YowZa! window.                */
  21. RECTL   windowRect;             /* window pos. in global coordinates         */
  22. UCHAR   screen_cleared=FALSE;   /* screen_clear flag - TRUE = screen cleared */
  23.  
  24. /**************************************************************************/
  25.   Here begins the draw procedure.
  26. /**************************************************************************/
  27.  
  28. VOID EXPENTRY YowzaDrawProc(hab, hps, theWindow, parm1, parm2, paintFlag,sysFlags)
  29. HAB     hab;
  30. HPS     hps;
  31. HWND    theWindow;
  32. ULONG   parm1;
  33. ULONG   parm2;
  34. UCHAR  *paintFlag;
  35. UCHAR   sysFlags;
  36.  
  37. {
  38. /**************************************************************************/
  39.   Declare any local variables here.  Their value will be lost between
  40.   draw proc. calls.
  41. /**************************************************************************/
  42.  
  43. VOID    define_local_variables_here;
  44.  
  45.  
  46. POINTL  aPoint;
  47.  
  48.    /* this line will make the grapihcs routine re-start if the grapihcs
  49.       are stopped and re-started. */
  50.  
  51.    if (new_update)
  52.       screen_cleared=FALSE;
  53.  
  54.    /* place your graphics code here - code for the star field display is
  55.       shown as an example. */
  56.  
  57.  
  58.   /* on the first time through, we find the location of YowZa!'s main window
  59.      and convert it to global coordinates then fill the rectangle with
  60.      black - ie. erase the main window to black. */
  61.  
  62.   if (!screen_cleared)
  63.    {
  64.      WinQueryWindowPos(theWindow,&windowPos);
  65.      windowRect.xLeft   = (LONG) windowPos.x;
  66.      windowRect.yBottom = (LONG) windowPos.y;
  67.      windowRect.xRight  = (LONG) (windowPos.x + windowPos.cx);
  68.      windowRect.yTop    = (LONG) (windowPos.y + windowPos.cy);
  69.      screen_cleared = TRUE;
  70.      WinFillRect(hps,&windowRect,CLR_BLACK);
  71.    }
  72.  
  73.   /* now pick a random point within the screen bounds and store in the
  74.      star field array. */
  75.  
  76.   aPoint.x = (rand() % (windowPos.cx-2));
  77.   aPoint.y = (rand() % windowPos.cy);
  78.   points[loop_count++] = aPoint;
  79.  
  80.   /* pick a random colour to draw this point with and draw it on the screen */
  81.  
  82.   GpiSetColor(hps,(LONG) rand() % 31);
  83.   GpiMove(hps,&aPoint); aPoint.x++;
  84.   GpiLine(hps,&aPoint);
  85.  
  86.   /* once we've drawn all 3000 points, we loop through each point in the
  87.      star field and erase each one.  Note the paintFlg reference in the
  88.      for loop.  This insures we don't waste time completing the loop if the
  89.      user moves the mouse or hits a key. */
  90.  
  91.   if (loop_count == 3000)
  92.    {
  93.      GpiSetColor(hps,CLR_BLACK);
  94.      for (i=0;(i<maxPoints) && *paintFlag;i++)
  95.       {
  96.         GpiMove(hps,&(points[i])); (points[i].x)++;
  97.         GpiLine(hps,&(points[i]));
  98.       }
  99.      loop_count=0;
  100.    }
  101. }
  102.  
  103. /************************************************************************
  104.   A Sample YowzaQueryGraphics routine.
  105.  ************************************************************************/
  106.  
  107. VOID EXPENTRY YowzaQueryGraphics(numGraphics, nameText)
  108. USHORT *numGraphics;
  109. UCHAR  **nameText;
  110. {
  111.    *numGraphics = number_of_graphics_routines_in_YOWDRAW_DLL;
  112.    *nameText = (UCHAR*) graphics_names_text_array;
  113. }
  114.  
  115.  /***************************************************************************
  116.   * This function returns whether a particular graphics algorithm requires  *
  117.   * the screen to be cleared when the routine is first started.             *
  118.   ***************************************************************************/
  119.  
  120. BOOL EXPENTRY YowzaQueryErase(testAlg)
  121. USHORT  testAlg;
  122.  
  123. {
  124.    return(GraphicsEraseTable[testAlg]);
  125. }
  126.