Archived

This topic is now archived and is closed to further replies.

sdoherty55

Direct Input Mouse (Cursor) out of sink with Virtual Coordinates

Recommended Posts

sdoherty55    122
In using a good majority of the code from scrawl demo program, I am finding that the mouse x and y coordinates get out of sink. For example, lets say that I start the mouse at the top left corner of the screen (0,0) and move the mouse around the center of the screen. I notice that once I try to put the mouse back to the top left hand corner of the screen, the mouse coordinates are 0,0 before the mouse hits the top corner? This is even the case when I don''t allow the mouse to hit the right or bottom edges of the screen? I noticed that the demo application "pick" uses a much simplier method of reading mouse coordinates. Any advice would be great. Thanks The following are a couple of routines from "scrawl.cpp": //----------------------------------------------------------------------------- // Name: OnMouseInput() // Desc: Handles responding to any mouse input that is generated from // the mouse event being triggered. //----------------------------------------------------------------------------- void CMyD3DApplication::MouseUpdate( HWND hWnd ) { BOOL bDone; DIDEVICEOBJECTDATA od; DWORD dwElements; HRESULT hr; // Invalidate the old cursor so it will be erased // InvalidateCursorRect( hWnd ); // Attempt to read one data element. Continue as long as // device data is available. bDone = FALSE; while( !bDone ) { dwElements = 1; hr = g_pMouse->GetDeviceData( sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0 ); if( hr == DIERR_INPUTLOST ){ SetAcquire(); break; } else if (hr == DIERR_INVALIDPARAM){ break; } else if (hr == DIERR_NOTACQUIRED){ break; } else if (hr == DIERR_NOTBUFFERED){ break; } else if (hr == DIERR_NOTINITIALIZED){ break; } // Unable to read data or no data available if( FAILED(hr) || dwElements == 0 ) { break; } // Look at the element to see what happened switch( od.dwOfs ) { case DIMOFS_X: // Mouse horizontal motion UpdateCursorPosition( od.dwData, 0 ); break; case DIMOFS_Y: // Mouse vertical motion UpdateCursorPosition( 0, od.dwData ); break; case DIMOFS_BUTTON0: // Right button pressed or released case DIMOFS_BUTTON1: // Left button pressed or released // Is the right or a swapped left button down? if( ( g_bSwapMouseButtons && DIMOFS_BUTTON1 == od.dwOfs ) || ( !g_bSwapMouseButtons && DIMOFS_BUTTON0 == od.dwOfs ) ) { if( od.dwData & 0x80 ) { // left button pressed, so go into button-down mode bDone = TRUE; // OnLeftButtonDown( hWnd ); } } // is the left or a swapped right button down? if( ( g_bSwapMouseButtons && DIMOFS_BUTTON0 == od.dwOfs ) || ( !g_bSwapMouseButtons && DIMOFS_BUTTON1 == od.dwOfs ) ) { if( !(od.dwData & 0x80) ) { // button released, so check context menu bDone = TRUE; // OnRightButtonUp( hWnd ); } } break; } } // Invalidate the new cursor so it will be drawn // InvalidateCursorRect( hWnd ); } //----------------------------------------------------------------------------- // Name: UpdateCursorPosition() // Desc: Move our private cursor in the requested direction, subject // to clipping, scaling, and all that other stuff. // // This does not redraw the cursor. You need to do that yourself. //----------------------------------------------------------------------------- void CMyD3DApplication::UpdateCursorPosition( int dx, int dy ) { // Pick up any leftover fuzz from last time. This is important // when scaling down mouse motions. Otherwise, the user can // drag to the right extremely slow for the length of the table // and not get anywhere. dx += g_dxFuzz; g_dxFuzz = 0; dy += g_dyFuzz; g_dyFuzz = 0; switch( g_iSensitivity ) { case 1: // High sensitivity: Magnify! dx *= 2; dy *= 2; break; case -1: // Low sensitivity: Scale down g_dxFuzz = dx % 2; // remember the fuzz for next time g_dyFuzz = dy % 2; dx /= 2; dy /= 2; break; case 0: // normal sensitivity // No adjustments needed break; } g_x += dx; g_y += dy; // clip the cursor to our client area if( g_x < 0 ) g_x = 0; if( g_x >= SCRAWL_CXBITMAP ) g_x = SCRAWL_CXBITMAP - 1; if( g_y < 0 ) g_y = 0; if( g_y >= SCRAWL_CYBITMAP ) g_y = SCRAWL_CYBITMAP - 1; }

Share this post


Link to post
Share on other sites