home *** CD-ROM | disk | FTP | other *** search
/ Total Destruction / Total_Destruction.iso / util / q2source.exe / utils3 / qe4 / win_z.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-28  |  4.0 KB  |  174 lines

  1. // win_cam.c -- windows specific camera view code
  2.  
  3. #include "qe3.h"
  4.  
  5. static HDC   s_hdcZ;
  6. static HGLRC s_hglrcZ;
  7.  
  8. /*
  9. ============
  10. WZ_WndProc
  11. ============
  12. */
  13. LONG WINAPI WZ_WndProc (
  14.     HWND    hWnd,
  15.     UINT    uMsg,
  16.     WPARAM  wParam,
  17.     LPARAM  lParam)
  18. {
  19.     int        fwKeys, xPos, yPos;
  20.     RECT    rect;
  21.  
  22.     GetClientRect(hWnd, &rect);
  23.  
  24.     switch (uMsg)
  25.     {
  26.  
  27.     case WM_DESTROY:
  28.         QEW_StopGL( hWnd, s_hglrcZ, s_hdcZ );
  29.         return 0;
  30.  
  31.     case WM_CREATE:
  32.         s_hdcZ = GetDC(hWnd);
  33.         QEW_SetupPixelFormat( s_hdcZ, false);
  34.         if ( ( s_hglrcZ = wglCreateContext( s_hdcZ ) ) == 0 )
  35.             Error( "wglCreateContext in WZ_WndProc failed" );
  36.  
  37.         if (!wglMakeCurrent( s_hdcZ, s_hglrcZ ))
  38.             Error ("wglMakeCurrent in WZ_WndProc failed");
  39.  
  40.         if (!wglShareLists( g_qeglobals.d_hglrcBase, s_hglrcZ ) )
  41.             Error( "wglShareLists in WZ_WndProc failed" );
  42.         return 0;
  43.  
  44.     case WM_PAINT:
  45.         { 
  46.             PAINTSTRUCT    ps;
  47.  
  48.             BeginPaint(hWnd, &ps);
  49.  
  50.             if ( !wglMakeCurrent( s_hdcZ, s_hglrcZ ) )
  51.                 Error ("wglMakeCurrent failed");
  52.             QE_CheckOpenGLForErrors();
  53.  
  54.             Z_Draw ();
  55.             SwapBuffers(s_hdcZ);
  56.  
  57.             EndPaint(hWnd, &ps);
  58.         }
  59.         return 0;
  60.  
  61.  
  62.     case WM_KEYDOWN:
  63.         QE_KeyDown (wParam);
  64.         return 0;
  65.  
  66.     case WM_MBUTTONDOWN:
  67.     case WM_RBUTTONDOWN:
  68.     case WM_LBUTTONDOWN:
  69.         if (GetTopWindow(g_qeglobals.d_hwndMain) != hWnd)
  70.             BringWindowToTop(hWnd);
  71.  
  72.         SetFocus( g_qeglobals.d_hwndZ );
  73.         SetCapture( g_qeglobals.d_hwndZ );
  74.         fwKeys = wParam;        // key flags 
  75.         xPos = (short)LOWORD(lParam);  // horizontal position of cursor 
  76.         yPos = (short)HIWORD(lParam);  // vertical position of cursor 
  77.         yPos = (int)rect.bottom - 1 - yPos;
  78.         Z_MouseDown (xPos, yPos, fwKeys);
  79.         return 0;
  80.  
  81.     case WM_MBUTTONUP:
  82.     case WM_RBUTTONUP:
  83.     case WM_LBUTTONUP:
  84.         fwKeys = wParam;        // key flags 
  85.         xPos = (short)LOWORD(lParam);  // horizontal position of cursor 
  86.         yPos = (short)HIWORD(lParam);  // vertical position of cursor 
  87.         yPos = (int)rect.bottom - 1 - yPos;
  88.         Z_MouseUp (xPos, yPos, fwKeys);
  89.         if (! (fwKeys & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
  90.             ReleaseCapture ();
  91.         return 0;
  92.  
  93.     case WM_GETMINMAXINFO:
  94.     {
  95.         MINMAXINFO *pmmi = (LPMINMAXINFO) lParam;
  96.  
  97.         pmmi->ptMinTrackSize.x = ZWIN_WIDTH;
  98.         return 0;
  99.     }
  100.  
  101.     case WM_MOUSEMOVE:
  102.         fwKeys = wParam;        // key flags 
  103.         xPos = (short)LOWORD(lParam);  // horizontal position of cursor 
  104.         yPos = (short)HIWORD(lParam);  // vertical position of cursor 
  105.         yPos = (int)rect.bottom - 1 - yPos;
  106.         Z_MouseMoved (xPos, yPos, fwKeys);
  107.         return 0;
  108.  
  109.     case WM_SIZE:
  110.         z.width = rect.right;
  111.         z.height = rect.bottom;
  112.         InvalidateRect( g_qeglobals.d_hwndZ, NULL, false);
  113.         return 0;
  114.  
  115.     case WM_NCCALCSIZE:// don't let windows copy pixels
  116.         DefWindowProc (hWnd, uMsg, wParam, lParam);
  117.         return WVR_REDRAW;
  118.  
  119.     case WM_KILLFOCUS:
  120.     case WM_SETFOCUS:
  121.         SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
  122.         return 0;
  123.  
  124.        case WM_CLOSE:
  125.         /* call destroy window to cleanup and go away */
  126.         DestroyWindow (hWnd);
  127.         return 0;
  128.     }
  129.  
  130.     return DefWindowProc (hWnd, uMsg, wParam, lParam);
  131. }
  132.  
  133.  
  134. /*
  135. ==============
  136. WZ_Create
  137. ==============
  138. */
  139. void WZ_Create (HINSTANCE hInstance)
  140. {
  141.     WNDCLASS   wc;
  142.  
  143.     /* Register the camera class */
  144.     memset (&wc, 0, sizeof(wc));
  145.  
  146.     wc.style         = 0;
  147.     wc.lpfnWndProc   = (WNDPROC)WZ_WndProc;
  148.     wc.cbClsExtra    = 0;
  149.     wc.cbWndExtra    = 0;
  150.     wc.hInstance     = hInstance;
  151.     wc.hIcon         = 0;
  152.     wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
  153.     wc.hbrBackground = NULL;
  154.     wc.lpszMenuName  = NULL;
  155.     wc.lpszClassName = Z_WINDOW_CLASS;
  156.  
  157.     if (!RegisterClass (&wc) )
  158.         Error ("WCam_Register: failed");
  159.  
  160.     g_qeglobals.d_hwndZ = CreateWindow (Z_WINDOW_CLASS ,
  161.         "Z",
  162.         QE3_STYLE,
  163.         0,20,ZWIN_WIDTH,screen_height-38,    // size
  164.         g_qeglobals.d_hwndMain,    // parent
  165.         0,        // no menu
  166.         hInstance,
  167.         NULL);
  168.     if (!g_qeglobals.d_hwndZ)
  169.         Error ("Couldn't create zwindow");
  170.  
  171.     LoadWindowState(g_qeglobals.d_hwndZ, "zwindow");
  172.     ShowWindow (g_qeglobals.d_hwndZ, SW_SHOWDEFAULT);
  173. }
  174.