Esempio n. 1
0
void MainMouseMove(HWND hwnd, int x, int y, UINT keyFlags)
{
	switch (state)
	{
	case STATE_GAME:
		if (gbMouselook)
		{
			RECT		rect;
//			WINDOWINFO	windowInfo;
			POINT	pt, center;
//			int		x, y;

//			GetWindowInfo(hMain, &windowInfo);
			GetClientRect(hMain, &rect);
			pt.x = rect.left;
			pt.y = rect.top;
			ClientToScreen(hMain, &pt);

			center.x = (gD3DRect.right - gD3DRect.left) / 2;
			center.y = (gD3DRect.bottom - gD3DRect.top) / 2;

			center.x += gD3DRect.left + pt.x;
			center.y += gD3DRect.top + pt.y;

			GetCursorPos(&pt);

/*			if (pt.x != (rect.right / 2))
				UserTurnPlayerMouse((pt.x - (rect.right / 2)) * gMouselookXScale);
			if (pt.y != (rect.bottom / 2))
				PlayerChangeHeightMouse((pt.y - (rect.bottom / 2)) * gMouselookYScale);

			if ((pt.x != (rect.right / 2)) || (pt.y != (rect.bottom / 2)))
				SetCursorPos(rect.right / 2, rect.bottom / 2);*/
			if (pt.x != center.x)
				UserTurnPlayerMouse((pt.x - center.x) * config.mouselookXScale / 3);
			if (pt.y != center.y)
				PlayerChangeHeightMouse((pt.y - center.y) * config.mouselookYScale / 3);

			if ((pt.x != center.x) || (pt.y != center.y))
				SetCursorPos(center.x, center.y);
		}

		GameMouseMove(hwnd, x, y, keyFlags);
		break;
	}
}
Esempio n. 2
0
LRESULT CALLBACK WindowProc(HWND hwnd,
						    UINT msg, 
                            WPARAM wparam, 
                            LPARAM lparam)
{                       
    // this is the main message handler of the system
    PAINTSTRUCT	ps;		   // used in WM_PAINT
    HDC			hdc;	   // handle to a device context

    // what is the message
    switch(msg) {
        case WM_LBUTTONDOWN:
		case WM_LBUTTONUP: {
			NimblePoint p;
 	        p.x = (int)LOWORD(lparam);
		    p.y = (int)HIWORD(lparam);
	    	if( msg==WM_LBUTTONDOWN )
                GameMouseButtonDown( p, 0 );
            else
                GameMouseButtonUp( p, 0 );
            break;
		}
        case WM_MOUSELEAVE:
            RequestedTrackMouseEvent = false;
            HostShowCursor(true);
            break;

		case WM_MOUSEMOVE: {

            if (!RequestedTrackMouseEvent) {
                // First time mouse entered my window:
                // Request leave notification
                TRACKMOUSEEVENT tme;
                tme.cbSize = sizeof(tme);
                tme.hwndTrack = hwnd;
                tme.dwFlags = TME_LEAVE;
                TrackMouseEvent(&tme);
                RequestedTrackMouseEvent = true;
            }

	        NimblePoint p;
			p.x = (int)LOWORD(lparam);
		    p.y = (int)HIWORD(lparam);
	    	GameMouseMove( p );
            break;
		}
	    case WM_CREATE:
		    // Do initialization stuff here
		    return 0;

        case WM_PAINT:
            // Start painting
            hdc = BeginPaint(hwnd,&ps);

            // End painting
            EndPaint(hwnd,&ps);
            return 0;
        
        case WM_MOVE:
    	    return 0;
    	
	    case WM_SIZE:
		    // Extract new window size
		    // Round to multiple of four, because some of our loop unrollings depend upon such.
		    WindowWidth = RoundAndClip(LOWORD(lparam));
		    WindowHeight = HIWORD(lparam);
		    ResizeOrMove = true;
		    return 0;
		
	    case WM_COMMAND:
		    break;

	    case WM_DESTROY:
		    // Kill the application
		    PostQuitMessage(0);
	    	return 0;

		case WM_CHAR: {
 			if( GameKeyDown(wparam) )
				PostMessage(hwnd, WM_DESTROY,0,0);
			return 0;
		}
    	default:
            break;

    } // end switch

    // Process any messages that we didn't take care of
    return (DefWindowProc(hwnd, msg, wparam, lparam));

} // end WinProc