Annotation of pmsdk/samples/petzold/chap05/spiral.c, revision 1.1.1.1

1.1       root        1: /*--------------------------------
                      2:    SPIRAL.C -- GPI Spiral Drawing
                      3:  ---------------------------------*/
                      4: 
                      5: #include <os2.h>
                      6: #include <math.h>
                      7: 
                      8: #define NUMPOINTS 1000
                      9: #define NUMREV    20
                     10: #define PI        3.14159
                     11: 
                     12: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
                     13: 
                     14: int main (void)
                     15:      {
                     16:      static CHAR  szClientClass [] = "Spiral" ;
                     17:      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
                     18:                                  FCF_SIZEBORDER    | FCF_MINMAX  |
                     19:                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
                     20:      HAB          hab ;
                     21:      HMQ          hmq ;
                     22:      HWND         hwndFrame, hwndClient ;
                     23:      QMSG         qmsg ;
                     24: 
                     25:      hab = WinInitialize (0) ;
                     26:      hmq = WinCreateMsgQueue (hab, 0) ;
                     27: 
                     28:      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
                     29: 
                     30:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
                     31:                                      &flFrameFlags, szClientClass, NULL,
                     32:                                      0L, NULL, 0, &hwndClient) ;
                     33: 
                     34:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
                     35:           WinDispatchMsg (hab, &qmsg) ;
                     36: 
                     37:      WinDestroyWindow (hwndFrame) ;
                     38:      WinDestroyMsgQueue (hmq) ;
                     39:      WinTerminate (hab) ;
                     40:      return 0 ;
                     41:      }
                     42: 
                     43: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
                     44:      {
                     45:      static SHORT cxClient, cyClient ;
                     46:      double       dAngle, dScale ;
                     47:      HPS          hps ;
                     48:      PPOINTL      pptl ;
                     49:      SEL          sel ;
                     50:      SHORT        sIndex ;
                     51: 
                     52:      switch (msg)
                     53:          {
                     54:           case WM_SIZE:
                     55:                cxClient = SHORT1FROMMP (mp2) ;
                     56:                cyClient = SHORT2FROMMP (mp2) ;
                     57:                return 0 ;
                     58: 
                     59:           case WM_PAINT:
                     60:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
                     61:                GpiErase (hps) ;
                     62: 
                     63:                if (!DosAllocSeg (NUMPOINTS * sizeof (POINTL), &sel, 0))
                     64:                     {
                     65:                     pptl = MAKEP (sel, 0) ;
                     66: 
                     67:                     for (sIndex = 0 ; sIndex < NUMPOINTS ; sIndex ++)
                     68:                         {
                     69:                         dAngle = sIndex * 2 * PI / (NUMPOINTS / NUMREV) ;
                     70:                         dScale = 1 - (double) sIndex / NUMPOINTS ;
                     71: 
                     72:                         pptl[sIndex].x = (LONG) (cxClient / 2 *
                     73:                                                  (1 + dScale * cos (dAngle))) ;
                     74: 
                     75:                         pptl[sIndex].y = (LONG) (cyClient / 2 *
                     76:                                                  (1 + dScale * sin (dAngle))) ;
                     77:                         }
                     78:                     GpiMove (hps, pptl) ;
                     79:                     GpiPolyLine (hps, NUMPOINTS - 1L, pptl + 1) ;
                     80: 
                     81:                     DosFreeSeg (sel) ;
                     82:                     }
                     83:                WinEndPaint (hps) ;
                     84:                return 0 ;
                     85:           }
                     86:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
                     87:      }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.