void CALLBACK OnMouse( bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, bool bSideButton1Down, bool bSideButton2Down, int nMouseWheelDelta, int xPos, int yPos, void* pUserContext ) { if (!gDragging_out && gDragging && bLeftButtonDown) { int delta_xPos = xPos-gLast_xPos; int delta_yPos = yPos-gLast_yPos; gViewTranslationX += delta_xPos; gViewTranslationY += delta_yPos; } if (nMouseWheelDelta) { float halfWidth = gSurfaceWidth / 2.0f; float halfHeight = gSurfaceHeight / 2.0f; int oldzoom = gViewZoomStep; gViewZoomStep += nMouseWheelDelta; float old_scale = powf(2.0, oldzoom/300.0f); float new_scale = powf(2.0, gViewZoomStep/300.0f); float vx = gViewTranslationX-(xPos-halfWidth); float vy = gViewTranslationY-(yPos-halfHeight); vx *= new_scale/old_scale; vy *= new_scale/old_scale; gViewTranslationX = int(vx+xPos-halfWidth); gViewTranslationY = int(vy+yPos-halfHeight); } POINT base, pt = {xPos, yPos}; gSampleUI.GetLocation(base); pt.x -= base.x; pt.y -= base.y; CDXUTControl* ctrl = gSampleUI.GetControlAtPoint(pt); if (!gDragging) { gDragging_out = !!ctrl && bLeftButtonDown; } gDragging = bLeftButtonDown; gLast_xPos = xPos; gLast_yPos = yPos; }