home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / WIN_Z.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  4.0 KB  |  172 lines

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