📄 sdl_os2fslib.c
字号:
break; case WM_BUTTON2UP:#ifdef DEBUG_BUILD printf("WM_BUTTON2UP\n"); fflush(stdout);#endif SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); // Don't report mouse movement! break; case WM_BUTTON3DOWN:#ifdef DEBUG_BUILD printf("WM_BUTTON3DOWN\n"); fflush(stdout);#endif pVideo = FSLib_GetUserParm(hwnd); if (pVideo) { SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_MIDDLE, 0, 0); // Don't report mouse movement! if (bMouseCapturable) { // We should capture the mouse! if (!bMouseCaptured) { WinSetCapture(HWND_DESKTOP, hwnd); WinSetPointer(HWND_DESKTOP, NULL); bMouseCaptured = 1; { SWP swpClient; POINTL ptl; // Center the mouse to the middle of the window! WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); ptl.x = 0; ptl.y = 0; WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ WinSetPointerPos(HWND_DESKTOP, ptl.x + swpClient.cx/2, ptl.y + swpClient.cy/2); } } } } break; case WM_BUTTON3UP:#ifdef DEBUG_BUILD printf("WM_BUTTON3UP\n"); fflush(stdout);#endif SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_MIDDLE, 0, 0); // Don't report mouse movement! break; case WM_MOUSEMOVE:#ifdef DEBUG_BUILD// printf("WM_MOUSEMOVE\n"); fflush(stdout);#endif pVideo = FSLib_GetUserParm(hwnd); if (pVideo) { if (pVideo->hidden->iSkipWMMOUSEMOVE) { pVideo->hidden->iSkipWMMOUSEMOVE--; } else { POINTS *ppts = (POINTS *) (&mp1); POINTL ptl; if (bMouseCaptured) { SWP swpClient; WinQueryWindowPos(pVideo->hidden->hwndClient, &swpClient); // Send relative mouse position, and re-center the mouse // Reposition the mouse to the center of the screen/window SDL_PrivateMouseMotion(0, // Buttons not changed 1, // Relative position ppts->x - (swpClient.cx/2), (swpClient.cy/2) - ppts->y); ptl.x = 0; ptl.y = 0; WinMapWindowPoints(pVideo->hidden->hwndClient, HWND_DESKTOP, &ptl, 1); pVideo->hidden->iSkipWMMOUSEMOVE++; /* Don't take next WM_MOUSEMOVE into account! */ // Center the mouse to the middle of the window! WinSetPointerPos(HWND_DESKTOP, ptl.x + swpClient.cx/2, ptl.y + swpClient.cy/2); } else { CONVERTMOUSEPOSITION(); // Send absolute mouse position SDL_PrivateMouseMotion(0, // Buttons not changed 0, // Absolute position ppts->x, ppts->y); } } if ((pVideo->hidden->iMouseVisible) && (!bMouseCaptured)) {#ifdef DEBUG_BUILD// printf("WM_MOUSEMOVE : ptr = %p\n", hptrGlobalPointer); fflush(stdout);#endif if (hptrGlobalPointer) WinSetPointer(HWND_DESKTOP, hptrGlobalPointer); else WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); } else { WinSetPointer(HWND_DESKTOP, NULL); } }#ifdef DEBUG_BUILD// printf("WM_MOUSEMOVE done\n"); fflush(stdout);#endif return (MRESULT) FALSE; case WM_CLOSE: // Window close#ifdef DEBUG_BUILD printf("WM_CLOSE\n"); fflush(stdout);#endif pVideo = FSLib_GetUserParm(hwnd); if (pVideo) { // Send Quit message to the SDL application! SDL_PrivateQuit(); return 0; } break;#ifdef BITBLT_IN_WINMESSAGEPROC case WM_UPDATERECTSREQUEST: pVideo = FSLib_GetUserParm(hwnd); if ((pVideo) && (pVideo->hidden->pSDLSurface)) { if (DosRequestMutexSem(pVideo->hidden->hmtxUseSrcBuffer, SEM_INDEFINITE_WAIT)==NO_ERROR) { int numrects; SDL_Rect *rects; int i; SWP swp; numrects = (int) mp1; rects = (SDL_Rect *) mp2; WinQueryWindowPos(hwnd, &swp);#ifndef RESIZE_EVEN_IF_RESIZABLE if ((!pVideo->hidden->pSDLSurface) || ( (pVideo->hidden->pSDLSurface) && (pVideo->hidden->pSDLSurface->flags & SDL_RESIZABLE) && ((swp.cx != pVideo->hidden->SrcBufferDesc.uiXResolution) || (swp.cy != pVideo->hidden->SrcBufferDesc.uiYResolution) ) && (!FSLib_QueryFSMode(hwnd)) ) ) { // Resizable surface and in resizing! // So, don't blit now!#ifdef DEBUG_BUILD printf("[WM_UPDATERECTSREQUEST] : Skipping blit while resizing!\n"); fflush(stdout);#endif } else#endif {#ifdef DEBUG_BUILD printf("[WM_UPDATERECTSREQUEST] : Blitting!\n"); fflush(stdout);#endif // Blit the changed areas for (i=0; i<numrects; i++) FSLIB_BITBLT(hwnd, pVideo->hidden->pchSrcBuffer, rects[i].y, rects[i].x, rects[i].w, rects[i].h); } DosReleaseMutexSem(pVideo->hidden->hmtxUseSrcBuffer); } } return 0;#endif default:#ifdef DEBUG_BUILD printf("Unhandled: %x\n", msg); fflush(stdout);#endif break; } // Run the default window procedure for unhandled stuffs return WinDefWindowProc(hwnd, msg, mp1, mp2);}///////////////////////////////////////////////////////////////////////// FrameWndProc//// This is the message processing window procedure for the// frame window of SDLWindowClass.///////////////////////////////////////////////////////////////////////static MRESULT EXPENTRY FrameWndProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2){ PFNWP pOldFrameProc; MRESULT result; PTRACKINFO ti; int cx, cy, ncx, ncy; RECTL rclTemp; PSWP pswpTemp; SDL_VideoDevice *pVideo = NULL; pVideo = (SDL_VideoDevice *) WinQueryWindowULong(hwnd, QWL_USER); pOldFrameProc = pVideo->hidden->pfnOldFrameProc; if ((pVideo->hidden->bProportionalResize) && (msg==WM_ADJUSTWINDOWPOS) && (!FSLib_QueryFSMode(pVideo->hidden->hwndClient)) ) { pswpTemp = (PSWP) mp1; /* Resizing? */ if (pswpTemp->fl & SWP_SIZE) { /* Calculate client size */ rclTemp.xLeft = pswpTemp->x; rclTemp.xRight = pswpTemp->x + pswpTemp->cx; rclTemp.yBottom = pswpTemp->y; rclTemp.yTop = pswpTemp->y + pswpTemp->cy; WinCalcFrameRect(hwnd, &rclTemp, TRUE); ncx = cx = rclTemp.xRight - rclTemp.xLeft; ncy = cy = rclTemp.yTop - rclTemp.yBottom; /* Calculate new size to keep it proportional */ if ((pVideo->hidden->ulResizingFlag & TF_LEFT) || (pVideo->hidden->ulResizingFlag & TF_RIGHT)) { /* The window is resized horizontally */ ncy = pVideo->hidden->SrcBufferDesc.uiYResolution * cx / pVideo->hidden->SrcBufferDesc.uiXResolution; } else if ((pVideo->hidden->ulResizingFlag & TF_TOP) || (pVideo->hidden->ulResizingFlag & TF_BOTTOM)) { /* The window is resized vertically */ ncx = pVideo->hidden->SrcBufferDesc.uiXResolution * cy / pVideo->hidden->SrcBufferDesc.uiYResolution; } /* Calculate back frame coordinates */ rclTemp.xLeft = pswpTemp->x; rclTemp.xRight = pswpTemp->x + ncx; rclTemp.yBottom = pswpTemp->y; rclTemp.yTop = pswpTemp->y + ncy; WinCalcFrameRect(hwnd, &rclTemp, FALSE); /* Store new size/position info */ pswpTemp->cx = rclTemp.xRight - rclTemp.xLeft; if (!(pVideo->hidden->ulResizingFlag & TF_TOP)) { pswpTemp->y = pswpTemp->y + pswpTemp->cy - (rclTemp.yTop - rclTemp.yBottom); pswpTemp->cy = rclTemp.yTop - rclTemp.yBottom; } else { pswpTemp->cy = rclTemp.yTop - rclTemp.yBottom; } } } result = (*pOldFrameProc)(hwnd, msg, mp1, mp2); if ((pVideo->hidden->bProportionalResize) && (msg==WM_QUERYTRACKINFO)) { ti = (PTRACKINFO) mp2; /* Store the direction of resizing */ if ((ti->fs & TF_LEFT) || (ti->fs & TF_RIGHT) || (ti->fs & TF_TOP) || (ti->fs & TF_BOTTOM)) pVideo->hidden->ulResizingFlag = ti->fs; } return result;}///////////////////////////////////////////////////////////////////////// PMThreadFunc//// This function implements the PM-Thread, which initializes the// application window itself, the DIVE, and start message processing.///////////////////////////////////////////////////////////////////////int iNumOfPMThreadInstances = 0; // Global!static void PMThreadFunc(void *pParm){ SDL_VideoDevice *pVideo = pParm; HAB hab; HMQ hmq; QMSG msg; ULONG fcf;#ifdef DEBUG_BUILD printf("[PMThreadFunc] : Starting\n"); fflush(stdout);#endif iNumOfPMThreadInstances++; // Initialize PM, create a message queue. hab=WinInitialize(0); hmq=WinCreateMsgQueue(hab,0); if (hmq==0) {#ifdef DEBUG_BUILD printf("[PMThreadFunc] : Could not create message queue!\n"); printf(" It might be that the application using SDL is not a PM app!\n"); fflush(stdout);#endif pVideo->hidden->iPMThreadStatus = 2; } else { int rc; RECTL rectl; fcf = ulFCFToUse; // Get from global setting#ifdef DEBUG_BUILD printf("[PMThreadFunc] : FSLib_CreateWindow()!\n"); fflush(stdout);#endif rc = FSLib_CreateWindow(HWND_DESKTOP, 0, &fcf, "SDL Application", NULLHANDLE, 0, &(pVideo->hidden->SrcBufferDesc), WndProc, &(pVideo->hidden->hwndClient), &(pVideo->hidden->hwndFrame));#ifdef DEBUG_BUILD printf("[PMThreadFunc] : FSLib_CreateWindow() rc = %d\n", rc); fflush(stdout);#endif if (!rc) {#ifdef DEBUG_BUILD printf("[PMThreadFunc] : Could not create FSLib window!\n"); fflush(stdout);#endif pVideo->hidden->iPMThreadStatus = 3; } else {#ifdef DEBUG_BUILD printf("[PMThreadFunc] : FSLib_AddUserParm()!\n"); fflush(stdout);#endif // Store pVideo pointer in window data for client window, so // it will know the instance to which it belongs to. FSLib_AddUserParm(pVideo->hidden->hwndClient, pVideo); // Now set default image width height and fourcc!#ifdef DEBUG_BUILD printf("[PMThreadFunc] : SetWindowPos()!\n"); fflush(stdout);#endif // Set the position and size of the main window, // and make it visible! // Calculate frame window size from client window size rectl.xLeft = 0; rectl.yBottom = 0; rectl.xRight = pVideo->hidden->SrcBufferDesc.uiXResolution; // Noninclusive rectl.yTop = pVideo->hidden->SrcBufferDesc.uiYResolution; // Noninclusive WinCalcFrameRect(pVideo->hidden->hwndFrame, &rectl, FALSE); SetAccessableWindowPos(pVideo->hidden->hwndFrame, HWND_TOP, (WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN) - (rectl.xRight-rectl.xLeft)) / 2, (WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN) - (rectl.yTop-rectl.yBottom)) / 2, (rectl.xRight-rectl.xLeft), (rectl.yTop-rectl.yBottom), SWP_SIZE | SWP_ACTIVATE | SWP_SHOW | SWP_MOVE); // Subclass frame procedure and store old window proc address pVideo->hidden->pfnOldFrameProc = WinSubclassWindow(pVideo->hidden->hwndFrame, FrameWndProc); WinSetWindowULong(pVideo->hidden->hwndFrame, QWL_USER, (ULONG) pVideo);#ifdef DEBUG_BUILD printf("[PMThreadFunc] : Entering message loop\n"); fflush(stdout);#endif pVideo->hidden->iPMThreadStatus = 1; while (WinGetMsg(hab, (PQMSG)&msg, 0, 0, 0)) WinDispatchMsg(hab, (PQMSG) &msg);#ifdef DEBUG_BUILD printf("[PMThreadFunc] : Leaving message loop\n"); fflush(stdout);#endif // We should release the captured the mouse! if (bMouseCaptured) { WinSetCapture(HWND_DESKTOP, NULLHANDLE); bMouseCaptured = 0; } // Destroy our window WinDestroyWindow(pVideo->hidden->hwndFrame); pVideo->hidden->hwndFrame=NULL; // Show pointer to make sure it will not be left hidden. WinSetPointer(HWND_DESKTOP, WinQuerySysPointer(HWND_DESKTOP, SPTR_ARROW, FALSE)); WinShowPointer(HWND_DESKTOP, TRUE); } // Uninitialize PM WinDestroyMsgQueue(hmq); // All done! pVideo->hidden->iPMThreadStatus = 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -