home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dlib06.zip / DEMO1 / DEMO1.C next >
Text File  |  1994-07-05  |  6KB  |  209 lines

  1. #define INCL_WIN
  2. #define INCL_DOS
  3. #define INCL_GPI
  4. #include <os2.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <time.h>
  8. #include <process.h>
  9. #include "skeleton.h"
  10. #include "dlib.h"
  11.  
  12.  
  13.  
  14. MRESULT EXPENTRY ClientWndProc (HWND,ULONG,MPARAM,MPARAM);
  15.  
  16. #define MSG_SPRITES     1001
  17. #define MSG_SCROLL      1002
  18. #define MSG_START       1003
  19. #define MSG_LINES       1004
  20. #define MSG_STRETCH     1005
  21.  
  22. #define GetYSize() ScreenHeight
  23.  
  24. HAB    hab;
  25. HWND   hWndFrame, hWndClient;
  26. int    ScreenHeight;
  27. int    ClientXS, ClientYS;
  28. PIMAGE pic1;
  29. CHAR   szTitle[64];
  30. TID    tid;
  31. time_t t1,t2;
  32. ULONG  fps;
  33.  
  34. int main()
  35. {
  36.     HMQ   hmq;
  37.     QMSG  qmsg;
  38.     ULONG flFrameFlags    = FCF_TITLEBAR | FCF_SYSMENU       | FCF_SIZEBORDER |
  39.                             FCF_MINMAX   | FCF_SHELLPOSITION | FCF_TASKLIST   |
  40.                             FCF_ICON     | FCF_MENU;
  41.     CHAR  szClientClass[] = "CLIENT";
  42.  
  43.     hab = WinInitialize (0);
  44.     hmq = WinCreateMsgQueue (hab, 0);
  45.  
  46.     WinRegisterClass (hab, szClientClass, (PFNWP)ClientWndProc, CS_SIZEREDRAW|CS_MOVENOTIFY, 0);
  47.     WinLoadString (hab, 0, ID_APPNAME, sizeof(szTitle), szTitle);
  48.  
  49.     hWndFrame = WinCreateStdWindow (HWND_DESKTOP, 0,
  50.         &flFrameFlags, szClientClass, "g_blackl@kai.ee.cit.ac.nz", 0, 0, ID_APPNAME, &hWndClient);
  51.     WinSetWindowPos(hWndFrame,HWND_TOP,5,GetYSize()-295,370,290,SWP_SIZE |SWP_SHOW |SWP_ZORDER |SWP_MOVE | SWP_ACTIVATE);
  52.     dCreateVirtualScreen(1024,768);    
  53.  
  54.     while (WinGetMsg (hab, &qmsg, 0, 0, 0))
  55.         WinDispatchMsg (hab, &qmsg);
  56.  
  57.     WinDestroyWindow (hWndFrame);
  58.     WinDestroyMsgQueue (hmq);
  59.     WinTerminate (hab);
  60.     return (0);
  61. }
  62.  
  63.  
  64.  
  65. void AnimThread(void *arg)
  66. {
  67.     char *scr;
  68.     FILE *palette;
  69.     char rgb[256*3];
  70.     int OldXS,OldYS;
  71.     int i;
  72.  
  73.     palette = fopen("bad1.pal","rb");
  74.     fread(rgb,3,256,palette);               /* 256 colors, 1 byte red, 1 green, 1 blue */
  75.     fclose(palette);
  76.     dSetVirtualPalette(rgb);                         
  77.  
  78.     pic1 = dLoadImage("bad1.vga");
  79.     dCompileSprite(pic1);    
  80.     dBltStretchImage(pic1,0,0,ClientXS,ClientYS);
  81.     OldXS = ClientXS;
  82.     OldYS = ClientYS;
  83.     dShowView();
  84.  
  85.     t1 = time(NULL);
  86.     while (1) {
  87.        fps++;
  88.        dShowView();
  89.        if (OldYS != ClientYS || OldXS != ClientXS) {
  90.            dBltStretchImage(pic1,0,0,ClientXS,ClientYS);
  91.            OldXS = ClientXS;
  92.            OldYS = ClientYS;
  93.            t1 = time(NULL);
  94.            fps = 0;
  95.         }
  96.     }
  97. }
  98.  
  99.  
  100.  
  101. void SetupViewArea(void)
  102. {
  103.     SWP     swp;
  104.     RECTL   rect;
  105.     WinQueryWindowPos( hWndFrame, (PSWP)&swp );
  106.     rect.xLeft = swp.x;
  107.     rect.yBottom = swp.y;
  108.     rect.xRight = swp.x + swp.cx;
  109.     rect.yTop = swp.y + swp.cy;
  110.     WinCalcFrameRect(hWndFrame, &rect, TRUE);
  111.     ClientXS = rect.xRight-rect.xLeft;
  112.     ClientYS = rect.yTop-rect.yBottom;
  113.     dSetViewArea(rect.xLeft,ScreenHeight-(rect.yTop),ClientXS,ClientYS);
  114. }
  115.  
  116.  
  117.  
  118. MRESULT EXPENTRY ClientWndProc (HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  119. {
  120.     HPS     hps;
  121.     BOOL    bHandled = TRUE;
  122.     MRESULT mReturn  = 0;
  123.     RECTL   rect;
  124.     char    buf[50];
  125.     POINTL  pointl = {50,50};
  126.     USHORT  flag;
  127.  
  128.     switch (msg)
  129.     {
  130.          case WM_CREATE:
  131.             ScreenHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  132.             _beginthread(AnimThread,NULL,16556,NULL);
  133.             WinStartTimer(hab,hWnd,109,5000);
  134.             WinShowWindow(hWnd, TRUE);
  135.             break;
  136.  
  137.          case WM_TIMER:
  138.             t2 = time(NULL);
  139.             sprintf(buf,"max fps %d, size (%d,%d)",(fps/(t2-t1)),ClientXS,ClientYS);
  140.             WinSetWindowText(hWndFrame,buf);
  141.             break;
  142.  
  143.          case WM_MOVE:
  144.             SetupViewArea();
  145.             break;
  146.  
  147.          case WM_SIZE:
  148.             SetupViewArea();
  149.             break; 
  150.  
  151.          case WM_DESTROY:
  152.             bHandled = FALSE;
  153.             break;
  154.  
  155.          case WM_FOCUSCHANGE:
  156.             flag = SHORT1FROMMP(mp2);
  157.             if (flag == TRUE) {
  158.                DosExitCritSec();
  159.                t1 = time(NULL);
  160.                fps = 0;
  161.             } else {
  162.                DosEnterCritSec();
  163.             } 
  164.             bHandled = FALSE;
  165.             WinInvalidateRect(hWnd,NULL,FALSE);
  166.             break;
  167.  
  168.         case WM_PAINT:
  169.             SetupViewArea();
  170.             hps = WinBeginPaint (hWnd,0,0);
  171.             WinQueryWindowRect(hWnd,&rect);
  172.             WinFillRect(hps, &rect, CLR_BLACK);
  173.             WinEndPaint (hps);
  174.             break;
  175.  
  176.         case WM_COMMAND:
  177.             switch (LOUSHORT(mp1))
  178.             {
  179.                  case IDM_ABOUT:
  180.                     DosEnterCritSec();
  181.                     WinMessageBox(HWND_DESKTOP,
  182.                         hWnd, 
  183.                         "This is a simple demonstration of the frame rate posible"
  184.                         " for your video card at the current window size, using dLib. "
  185.                         "This is simply redrawing the frame over and over, as fast as possible."
  186.                         "\n\nWhilst dLib is quite fast, it cant work miracles. If you"
  187.                         " have a large window, or slow video card, things well look"
  188.                         " jerky.\nGraeme Blackley\ng_blackl@kai.ee.cit.ac.nz",
  189.                         "dLib information",    
  190.                         0,                     
  191.                         MB_INFORMATION | MB_OK);
  192.                     DosExitCritSec();
  193.                     t1 = time(NULL);
  194.                     fps = 0;
  195.                     break;
  196.             }
  197.  
  198.         default:
  199.             bHandled = FALSE;
  200.             break;
  201.     }
  202.  
  203.     if (!bHandled)
  204.         mReturn = WinDefWindowProc (hWnd,msg,mp1,mp2);
  205.  
  206.     return (mReturn);
  207. }
  208.  
  209.