Annotation of hatari/src/view.c, revision 1.1.1.1

1.1       root        1: /*
                      2:   Hatari
                      3: 
                      4:   Main viewing window display. This involves redrawing of the Window and also of directing input
                      5:   to the various functions. Parts of this code control the relative mouse movement, debouncing
                      6:   of input keys and the sizing of the view Window.
                      7: */
                      8: 
                      9: #include <SDL.h>
                     10: 
                     11: #include "main.h"
                     12: #include "debug.h"
                     13: #include "dialog.h"
                     14: /*#include "dsurface.h"*/
                     15: #include "floppy.h"
                     16: #include "ikbd.h"
                     17: #include "keymap.h"
                     18: #include "reset.h"
                     19: #include "screen.h"
                     20: #include "shortcut.h"
                     21: #include "statusBar.h"
                     22: /*#include "toolbar.h"*/
                     23: #include "vdi.h"
                     24: #include "joy.h"
                     25: #include "view.h"
                     26: 
                     27: 
                     28: //HBITMAP Bitmaps[MAX_BITMAPS];             /* Handles to Bitmaps used to draw view window */
                     29: //HCURSOR Cursors[MAX_CURSORS];             /* Cursors used to hide/show during view */
                     30: 
                     31: BOOL bWindowsMouseMode = FALSE/*TRUE*/;     /* TRUE if mouse in Windows mode, FALSE if ST mode */
                     32: BOOL bCursorOn = TRUE;                      /* TRUE if we are showing the standard windows arrow cursor */
                     33: 
                     34: //RECT WindowInitRect;
                     35: //HMENU hFullScreenMenu;                    /* Menu handle for full-screen options access */
                     36: 
                     37: char szPreviousImageFilenames[2][MAX_FLOPPY_MENU_IMAGES][MAX_FILENAME_LENGTH] = {
                     38:   { "","","","" },
                     39:   { "","","","" }
                     40: };
                     41: int nPreviousImageFilenames[2]= { 0,0 };    // Drive A, B
                     42: 
                     43: // List of ST scan codes to NOT de-bounce when running in maximum speed
                     44: char DebounceExtendedKeys[] = {
                     45:   0x1d,  // CTRL
                     46:   0x2a,  // Left SHIFT
                     47:   0x01,  // ESC
                     48:   0x38,  // ALT
                     49:   0x36,  // Right SHIFT
                     50:   0      //term
                     51: };
                     52: 
                     53: // Size of screen area for Windows according to resolution and options settings
                     54: // Index ONLY using 'View_GetWindowBorderSizeIndex()'
                     55: /*
                     56: RECT MinWindowBorderSizes[2][3] = {
                     57:   { // Non-Overscan
                     58:     0,0, 320,200,  // ST_LOW_RES
                     59:     0,0, 640,400,  // ST_MEDIUM_RES
                     60:     0,0, 640,400,  // ST_HIGH_RES
                     61:   },
                     62:   { // Overscan
                     63:     0,0, 320+OVERSCAN_LEFT+OVERSCAN_RIGHT,200+OVERSCAN_TOP+OVERSCAN_BOTTOM,      // ST_LOW_RES
                     64:     0,0, 640+OVERSCAN_LEFT*2+OVERSCAN_RIGHT*2,400+OVERSCAN_TOP*2+OVERSCAN_BOTTOM*2,  // ST_MEDIUM_RES
                     65:     0,0, 640,400,  // ST_HIGH_RES
                     66:   }
                     67: };
                     68: 
                     69: RECT WindowBorderSizes[2][3] = {
                     70:   { // Non-Overscan
                     71:     0,0, 320,200,  // ST_LOW_RES
                     72:     0,0, 640,400,  // ST_MEDIUM_RES
                     73:     0,0, 640,400,  // ST_HIGH_RES
                     74:   },
                     75:   { // Overscan
                     76:     0,0, 320+OVERSCAN_LEFT+OVERSCAN_RIGHT,200+OVERSCAN_TOP+OVERSCAN_BOTTOM,      // ST_LOW_RES
                     77:     0,0, 640+OVERSCAN_LEFT*2+OVERSCAN_RIGHT*2,400+OVERSCAN_TOP*2+OVERSCAN_BOTTOM*2,  // ST_MEDIUM_RES
                     78:     0,0, 640,400,  // ST_HIGH_RES
                     79:   }
                     80: };
                     81: */
                     82: 
                     83: //-----------------------------------------------------------------------
                     84: /*
                     85:   Set default Window init position(CW_USEDEFAULT)
                     86: */
                     87: /*
                     88: void View_DefaultWindowPos(void)
                     89: {
                     90:   WindowInitRect.left =
                     91:   WindowInitRect.top =
                     92:   WindowInitRect.right =
                     93:   WindowInitRect.bottom = CW_USEDEFAULT;
                     94: }
                     95: */
                     96: 
                     97: //-----------------------------------------------------------------------
                     98: /*
                     99:   Create our view window with toolbar/status bar and client area
                    100: */
                    101: /*
                    102: void View_CreateWindow(void)
                    103: {
                    104:   // Clear our short-cut keys
                    105:   ShortCut_ClearKeys();
                    106: 
                    107:   // Get size of window (320x200 default), make sure is on screen
                    108:   View_SizeWindow();
                    109: 
                    110:   // Create window, get global DC
                    111:   hWnd = CreateWindow(szName,PROG_NAME,WS_OVERLAPPEDWINDOW
                    112:    ,WindowInitRect.left,WindowInitRect.top,WindowInitRect.right,WindowInitRect.bottom
                    113:    ,NULL,NULL,hInst,NULL);
                    114:   MainDC = GetDC(hWnd);
                    115:   // Call Windows to allow drag'n'drop of disc images
                    116:   DragAcceptFiles(hWnd,TRUE);
                    117:   // Create menu for full-screen
                    118:   hFullScreenMenu = LoadMenu(hInst,MAKEINTRESOURCE(IDR_MENU_FULLSCREEN));
                    119: 
                    120:   // Load bitmaps needed for tool/status bars
                    121:   memset(Bitmaps,0x00,sizeof(HBITMAP)*MAX_BITMAPS);
                    122:   View_LoadBitmaps();
                    123: 
                    124:   // Load cursors used, and store off default
                    125:   Cursors[CURSOR_ORIGINAL] = SetCursor(Cursors[CURSOR_ARROW]);
                    126:   Cursors[CURSOR_ARROW] = LoadCursor(NULL,IDC_ARROW);
                    127:   Cursors[CURSOR_NULL] = LoadCursor(hInst,MAKEINTRESOURCE(IDC_CURSOR1));
                    128:   Cursors[CURSOR_HOURGLASS] = LoadCursor(NULL,IDC_WAIT);
                    129: 
                    130:   // Create pop-up menus for toolbar
                    131:   ToolBar_CreateMenus();
                    132: }
                    133: */
                    134: 
                    135: //-----------------------------------------------------------------------
                    136: /*
                    137:   Close our view Window
                    138: */
                    139: /*
                    140: void View_CloseWindow(void)
                    141: {
                    142:   // Free tool/status bar bitmaps
                    143:   View_FreeBitmaps();
                    144: 
                    145:   // Restore cursor back to normal
                    146:   SetCursor(Cursors[CURSOR_ORIGINAL]);
                    147: 
                    148:   // Free menus
                    149:   ToolBar_FreeMenus();
                    150:   // Free full-screen menu
                    151:   DestroyMenu(hFullScreenMenu);
                    152: }
                    153: */
                    154: 
                    155: //-----------------------------------------------------------------------
                    156: /*
                    157:   Show our view Window(create at correct size)
                    158: */
                    159: /*
                    160: void View_ShowWindow(void)
                    161: {
                    162:   // Set VDI before create window
                    163:    VDI_SetResolution(VDIModeOptions[ConfigureParams.TOSGEM.nGEMResolution],ConfigureParams.TOSGEM.nGEMColours);
                    164: }
                    165: */
                    166: 
                    167: //-----------------------------------------------------------------------
                    168: /*
                    169:   Load Bitmaps, using in ToolBar/StatusBar. Delete any existing ones, and remap to Windows colours
                    170: */
                    171: /*
                    172: void View_LoadBitmaps(void)
                    173: {
                    174:   // Free first
                    175:   View_FreeBitmaps();
                    176: 
                    177:   // Load bitmaps used from resource(remap colours to Windows using 'LoadImage')
                    178:   Bitmaps[BITMAP_TOOLBAR_ICONS] = (HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP_TOOLBAR_ICONS),IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADMAP3DCOLORS);
                    179:   Bitmaps[BITMAP_GRILL] = (HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP_GRILL),IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADMAP3DCOLORS);
                    180:   Bitmaps[BITMAP_RESIZE] = (HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP_RESIZE),IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADMAP3DCOLORS);
                    181:   Bitmaps[BITMAP_TOOLBAR_MENU] = (HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP_TOOLBAR_MENU),IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADMAP3DCOLORS);
                    182:   Bitmaps[BITMAP_TOOLBAR_SEPARATOR] = (HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP9),IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADMAP3DCOLORS);
                    183:   Bitmaps[BITMAP_STATUSBAR_ICONS] = (HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP_STATUSBAR_ICONS),IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADMAP3DCOLORS);
                    184: }
                    185: */
                    186: 
                    187: //-----------------------------------------------------------------------
                    188: /*
                    189:   Free Bitmaps used in View window
                    190: */
                    191: /*
                    192: void View_FreeBitmaps(void)
                    193: {
                    194:   int i;
                    195: 
                    196:   // Free any existing bitmaps
                    197:   for(i=0; i<MAX_BITMAPS; i++) {
                    198:     if (Bitmaps[i]) {
                    199:       DeleteObject(Bitmaps[i]);
                    200:       Bitmaps[i] = NULL;
                    201:     }
                    202:   }
                    203: }
                    204: */
                    205: 
                    206: //-----------------------------------------------------------------------
                    207: /*
                    208:   Set menu 'tick's - do to full-screen and pop-up versions
                    209: */
                    210: /*
                    211: void View_CheckMenuItem(int Control,BOOL bState)
                    212: {
                    213:   CheckMenuItem(hFullScreenMenu,Control,bState ? MF_CHECKED:MF_UNCHECKED);
                    214:   CheckMenuItem(hToolBarMenus[POPUP_MENU_OPTIONS][1],Control,bState ? MF_CHECKED:MF_UNCHECKED);    
                    215: }
                    216: */
                    217: 
                    218: //-----------------------------------------------------------------------
                    219: /*
                    220:   Set all items on menu bar
                    221: */
                    222: /*
                    223: void View_SetMenuChecks(void)
                    224: {
                    225:   View_CheckMenuItem(ID_OPTIONS_SOUND,ConfigureParams.Sound.bEnableSound);
                    226:   View_CheckMenuItem(ID_OPTIONS_MAXSPEED,ConfigureParams.Configure.nMinMaxSpeed==MINMAXSPEED_MAX);
                    227:   View_CheckMenuItem(ID_OPTIONS_CURSOREMU,ConfigureParams.Joysticks.Joy[1].bCursorEmulation);
                    228: }
                    229: */
                    230: 
                    231: //-----------------------------------------------------------------------
                    232: /*
                    233:   
                    234: */
                    235: /*
                    236: void View_SetMenuFileNames(HMENU hMenu, int InitMenuItem,int Drive)
                    237: {
                    238:   MENUITEMINFO MenuInfo;
                    239:   int i;
                    240: 
                    241:   // Delete any old menu items for filenames, including separator
                    242:   for(i=0; i<(MAX_FLOPPY_MENU_IMAGES+1); i++)
                    243:     RemoveMenu(hMenu,InitMenuItem,MF_BYPOSITION);
                    244: 
                    245:   // Do we have any filenames to add?
                    246:   if (nPreviousImageFilenames[Drive]!=0) {
                    247:     // Add separator
                    248:     memset(&MenuInfo,0x0,sizeof(MENUITEMINFO));
                    249:     MenuInfo.cbSize = sizeof(MENUITEMINFO);
                    250:     MenuInfo.fMask = MIIM_TYPE;
                    251:     MenuInfo.fType = MFT_SEPARATOR;
                    252:     InsertMenuItem(hMenu,InitMenuItem,TRUE,&MenuInfo);
                    253:     // Add filenames
                    254:     for(i=0; i<nPreviousImageFilenames[Drive]; i++) {
                    255:       memset(&MenuInfo,0x0,sizeof(MENUITEMINFO));
                    256:       MenuInfo.cbSize = sizeof(MENUITEMINFO);
                    257:       MenuInfo.fMask = MIIM_TYPE|MIIM_ID;
                    258:       MenuInfo.wID = (Drive==0) ? (ID_FLOPPYA_INSERT_SLOT1+i):(ID_FLOPPYB_INSERT_SLOT1+i);
                    259:       MenuInfo.fType = MFT_STRING;
                    260:       MenuInfo.dwTypeData = szPreviousImageFilenames[Drive][i];
                    261:       InsertMenuItem(hMenu,InitMenuItem+1+i,TRUE,&MenuInfo);
                    262:     }
                    263:   }
                    264: }
                    265: */
                    266: 
                    267: //-----------------------------------------------------------------------
                    268: /*
                    269:   Add filename to Floppy menu, move item to top if already on menu or just add a fresh
                    270: */
                    271: /*
                    272: void View_AddMenuFileName(int Drive,char *pszFileName)
                    273: {
                    274:   int i,j;
                    275: 
                    276:   // Is already in list?
                    277:   for(i=0; i<MAX_FLOPPY_MENU_IMAGES; i++) {
                    278:     if (!stricmp(szPreviousImageFilenames[Drive][i],pszFileName)) {
                    279:       // Found in list, move to top
                    280:       for(j=i; j>0; j--)
                    281:         strcpy(szPreviousImageFilenames[Drive][j],szPreviousImageFilenames[Drive][j-1]);
                    282:       // Copy to top
                    283:       strcpy(szPreviousImageFilenames[Drive][0],pszFileName);
                    284: 
                    285:       return;
                    286:     }
                    287:   }
                    288: 
                    289:   // Could not find in list, add to top
                    290: 
                    291:   // Move all down
                    292:   for(i=(MAX_FLOPPY_MENU_IMAGES-1); i>0; i--)
                    293:     strcpy(szPreviousImageFilenames[Drive][i],szPreviousImageFilenames[Drive][i-1]);
                    294:   // Add entry
                    295:   strcpy(szPreviousImageFilenames[Drive][0],pszFileName);
                    296:   nPreviousImageFilenames[Drive]++;
                    297:   if (nPreviousImageFilenames[Drive]>=MAX_FLOPPY_MENU_IMAGES)
                    298:     nPreviousImageFilenames[Drive] = MAX_FLOPPY_MENU_IMAGES;
                    299: }
                    300: */
                    301: 
                    302: //-----------------------------------------------------------------------
                    303: /*
                    304:   Create and populate full-screen menu
                    305: */
                    306: /*
                    307: void View_SetFullScreenMenu(void)
                    308: {
                    309:   SetMenu(hWnd,hFullScreenMenu);            // Set for menu display
                    310:   View_SetMenuChecks();
                    311:   // Set filenames on menu Floppy A,B
                    312:   View_SetMenuFileNames(GetSubMenu(hFullScreenMenu,1),NUM_FLOPPYA_MENU_ITEMS,0);
                    313:   View_SetMenuFileNames(GetSubMenu(hFullScreenMenu,2),NUM_FLOPPYB_MENU_ITEMS,1);
                    314: 
                    315:   DrawMenuBar(hWnd);
                    316: }
                    317: */
                    318: 
                    319: //-----------------------------------------------------------------------
                    320: /*
                    321:   Draw background rectangle in correct Window colour
                    322: */
                    323: /*
                    324: void View_DrawBackgroundRect(HDC hDC,RECT *pRect)
                    325: {
                    326:   HBRUSH hBrush;
                    327: 
                    328:   // Create brush for background
                    329:   hBrush = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
                    330:   // Fill
                    331:   FillRect(hDC,pRect,hBrush);
                    332:   // Clean up
                    333:   DeleteObject(hBrush);
                    334: }
                    335: */
                    336: 
                    337: //-----------------------------------------------------------------------
                    338: /*
                    339:   Draw line Window hi-light colour
                    340: */
                    341: /*
                    342: void View_DrawBackgroundLineLight(HDC hDC,int x,int y,int x2,int y2)
                    343: {
                    344:   HPEN hPen,hOldPen;
                    345: 
                    346:   // Create pen for hi-light
                    347:   hPen = CreatePen(PS_SOLID,0,GetSysColor(COLOR_3DHILIGHT));
                    348:   hOldPen = (HPEN)SelectObject(hDC,hPen);
                    349:   MoveToEx(hDC,x,y,NULL);
                    350:   LineTo(hDC,x2,y2);
                    351:   // Clean up
                    352:   DeleteObject(SelectObject(hDC,hOldPen));
                    353: }
                    354: */
                    355: 
                    356: //-----------------------------------------------------------------------
                    357: /*
                    358:   Draw line Window shadow colour
                    359: */
                    360: /*
                    361: void View_DrawBackgroundLineShadow(HDC hDC,int x,int y,int x2,int y2)
                    362: {
                    363:   HPEN hPen,hOldPen;
                    364: 
                    365:   // Create pen for shadow
                    366:   hPen = CreatePen(PS_SOLID,0,GetSysColor(COLOR_3DSHADOW));
                    367:   hOldPen = (HPEN)SelectObject(hDC,hPen);
                    368:   MoveToEx(hDC,x,y,NULL);
                    369:   LineTo(hDC,x2,y2);
                    370:   // Clean up
                    371:   DeleteObject(SelectObject(hDC,hOldPen));
                    372: }
                    373: */
                    374: 
                    375: //-----------------------------------------------------------------------
                    376: /*
                    377:   Draw view window, with ToolBar and StatusBar
                    378: */
                    379: /*
                    380: void View_DrawWindow(HDC hDC)
                    381: {
                    382:   HDC MemDC;
                    383:   RECT Rect,RectCopy;
                    384: 
                    385:   if (!bInFullScreen) {  // Only draw when in Window, else DirectX may draw! Doh!
                    386:     MemDC = CreateCompatibleDC(hDC);
                    387:     GetClientRect(hWnd,&Rect);
                    388: 
                    389:     // Draw speed bar
                    390:     View_DrawBackgroundLineLight(hDC,0,0, Rect.right,0);
                    391:     RectCopy = Rect;
                    392:     RectCopy.top = 1;
                    393:     RectCopy.bottom = 26;
                    394:     View_DrawBackgroundRect(hDC,&RectCopy);
                    395:     // Draw icons
                    396:     SelectObject(MemDC,Bitmaps[BITMAP_TOOLBAR_MENU]);       // Win98 Menu bar
                    397:     BitBlt(hDC,Rect.left+1,2,6,23,MemDC,0,0,SRCCOPY);
                    398:     SelectObject(MemDC,Bitmaps[BITMAP_TOOLBAR_SEPARATOR]);  // Win98 Icon space lines
                    399:     BitBlt(hDC,Rect.left+1+42,2,2,23,MemDC,0,0,SRCCOPY);
                    400:     BitBlt(hDC,Rect.left+1+114,2,2,23,MemDC,0,0,SRCCOPY);
                    401:     BitBlt(hDC,Rect.left+1+175,2,2,23,MemDC,0,0,SRCCOPY);
                    402:     ToolBar_DrawButtons(hDC);
                    403:     SelectObject(MemDC,Bitmaps[BITMAP_GRILL]);              // ST 'Grill'
                    404:     BitBlt(hDC,Rect.right-136,1,132,17,MemDC,0,0,SRCCOPY);
                    405: 
                    406:     // Draw outline
                    407:     View_DrawBackgroundLineShadow(hDC,Rect.right-1,Rect.top+26, 0,Rect.top+26);
                    408:     View_DrawBackgroundLineShadow(hDC,0,Rect.top+26, 0,Rect.bottom-17);
                    409:     View_DrawBackgroundLineLight(hDC,Rect.right-1,Rect.top+26, Rect.right-1,Rect.bottom-18);
                    410:     View_DrawBackgroundLineLight(hDC,Rect.right-1,Rect.bottom-18, 0,Rect.bottom-18);
                    411: 
                    412:     DeleteDC(MemDC);
                    413:     
                    414:     // Draw our status bar, with text and icons
                    415:     StatusBar_Draw();
                    416:   }
                    417: }
                    418: */
                    419: 
                    420: 
                    421: //-----------------------------------------------------------------------
                    422: /*
                    423:   Draw our full-screen menu
                    424: */
                    425: /*
                    426: void View_DrawMenu(void)
                    427: {
                    428:   // Update menu
                    429:   if (bFullScreenHold) {
                    430:     DrawMenuBar(hWnd);
                    431:   }
                    432: }
                    433: */
                    434: 
                    435: 
                    436: //-----------------------------------------------------------------------
                    437: /*
                    438:   Limit Windows cursor whole physical screen
                    439: */
                    440: /*
                    441: void View_LimitCursorToScreen(void)
                    442: {
                    443:   SetCursor(Cursors[CURSOR_ARROW]);          // Restore cursor
                    444:   ClipCursor(NULL);
                    445: }
                    446: */
                    447: 
                    448: //-----------------------------------------------------------------------
                    449: /*
                    450:   Set IKBD relative delta to zero
                    451: */
                    452: void View_ResetRelativeMouseDelta(void)
                    453: {
                    454:   int x,y;
                    455: 
                    456:   /* Get cursor point */
                    457:   SDL_GetMouseState(&x, &y);
                    458:   /* And set so we have a zero delta */
                    459:   KeyboardProcessor.Rel.X = KeyboardProcessor.Rel.PrevX = x;
                    460:   KeyboardProcessor.Rel.Y = KeyboardProcessor.Rel.PrevY = y;  
                    461: }
                    462: 
                    463: //-----------------------------------------------------------------------
                    464: /*
                    465:   Limit Windows cursor to area of ST screen display
                    466: */
                    467: /*
                    468: void View_LimitCursorToClient(void)
                    469: {
                    470:   RECT Rect;
                    471: 
                    472:   if (!bWindowsMouseMode) {
                    473:     // Find area of client area
                    474:     GetClientRect(hWnd,&Rect);
                    475:     // Make to screen coords, and limit cursor to this area
                    476:     ClientToScreen(hWnd,(POINT *)&Rect.left);
                    477:     ClientToScreen(hWnd,(POINT *)&Rect.right);
                    478: 
                    479:     // Limit mouse to client area
                    480:     ClipCursor(&Rect);
                    481:     // And make sure delta isn't passed back to emulation
                    482:     View_ResetRelativeMouseDelta();
                    483:   }
                    484:   else {
                    485:     // Allow cursor to move to all of desktop screen
                    486:     View_LimitCursorToScreen();
                    487:   }
                    488: }
                    489: */
                    490: 
                    491: //-----------------------------------------------------------------------
                    492: /*
                    493:   Set our mouse mode, by passing MOUSE_xxxx. This allows for a direct set to WINDOWS or ST
                    494:   and also the ability to TOGGLE the mode between the two
                    495:   Returns TRUE if was previously in MOUSE_WINDOWS mode(used to revert mode)
                    496: */
                    497: /*
                    498: BOOL View_ToggleWindowsMouse(int ForceToMode)
                    499: {
                    500:   int SetMode, OldWindowsMouse;
                    501: 
                    502:   // Store old mode
                    503:   OldWindowsMouse = bWindowsMouseMode;
                    504: 
                    505:   // Set which mouse mode to use
                    506:   if (ForceToMode==MOUSE_TOGGLE) {          // Toggle?
                    507:     if (bWindowsMouseMode)
                    508:       SetMode = MOUSE_ST;
                    509:     else
                    510:       SetMode = MOUSE_WINDOWS;
                    511:   }
                    512:   else                                      // Or force
                    513:     SetMode = ForceToMode;
                    514: 
                    515:   // Clear status bar text/reset toolbar, or show Help message if in Windows mode
                    516:   if (SetMode==MOUSE_ST)
                    517:     StatusBar_SetText("");
                    518:   else {
                    519:     ToolBar_UpdateOnMoveMove(-1,-1);
                    520:     StatusBar_SetText(pszStatusBarHelpText);
                    521:   }
                    522: 
                    523:   // Toggle windows mouse
                    524:   if (SetMode==MOUSE_ST) {                  // Go to ST mouse mode
                    525:     bWindowsMouseMode = FALSE;
                    526:     View_LimitCursorToClient();
                    527:     if (bCursorOn) {                        // 'ShowCursor' uses count, so make sure only turn on/off when need to!
                    528:       SetCursor(Cursors[CURSOR_NULL]);      // Use 'blank' cursor, as some graphics cards still display when turn off! Doh!
                    529:       ShowCursor(FALSE);
                    530:       bCursorOn = FALSE;
                    531:     }
                    532: 
                    533:     Main_UnPauseEmulation();
                    534:   }
                    535:   else {                                   // Return to Windows mouse mode!
                    536:     bWindowsMouseMode = TRUE;
                    537:     View_LimitCursorToScreen();
                    538:     if (!bCursorOn) {
                    539:       SetCursor(Cursors[CURSOR_ARROW]);    // Restore cursor
                    540:       ShowCursor(TRUE);
                    541:       bCursorOn = TRUE;
                    542:     }
                    543:   
                    544:     Main_PauseEmulation();
                    545:   }
                    546: 
                    547:   return(OldWindowsMouse);
                    548: }
                    549: */
                    550: 
                    551: 
                    552: //-----------------------------------------------------------------------
                    553: /*
                    554:   Scan list of keys to NOT de-bounce when running in maximum speed, eg ALT,SHIFT,CTRL etc...
                    555:   Return TRUE if key requires de-bouncing
                    556: */
                    557: BOOL View_DebounceSTKey(char STScanCode)
                    558: {
                    559:   int i=0;
                    560: 
                    561:   /* Are we in maximum speed, and have disabled key repeat? */
                    562: /*
                    563:   if ( (ConfigureParams.Configure.nMinMaxSpeed!=MINMAXSPEED_MIN) && (ConfigureParams.Keyboard.bDisableKeyRepeat) ) {
                    564:     // We should de-bounce all non extended keys, eg leave ALT,SHIFT,CTRL etc... held
                    565:     while (DebounceExtendedKeys[i]) {
                    566:       if (STScanCode==DebounceExtendedKeys[i])
                    567:         return(FALSE);
                    568:       i++;
                    569:     }
                    570: 
                    571:     // De-bounce key
                    572:     return(TRUE);
                    573:   }
                    574: */
                    575:   /* Do not de-bounce key */
                    576:   return(FALSE);
                    577: }
                    578: 
                    579: 
                    580: //-----------------------------------------------------------------------
                    581: /*
                    582:   Debounce any PC key held down if running with key repeat disabled
                    583:   This is called each ST frame, so keys get held down for one VBL which is enough for 68000 code to scan
                    584: */
                    585: void View_DebounceAllKeys(void)
                    586: {
                    587:   unsigned int Key;
                    588:   char STScanCode;
                    589: /*
                    590:   // Are we in maximum speed, and have disabled key repeat?
                    591:   if ( (ConfigureParams.Configure.nMinMaxSpeed!=MINMAXSPEED_MIN) && (ConfigureParams.Keyboard.bDisableKeyRepeat) ) {
                    592:     // Now run through each PC key looking for ones held down
                    593:     for(Key=0; Key<256; Key++) {
                    594:       // Is key held?
                    595:       if (Keyboard.KeyStates[Key]) {
                    596:         // Get scan code
                    597:         STScanCode = Keymap_RemapWindowsKeyToSTScanCode(Key);
                    598:         if (STScanCode!=-1) {
                    599:           // Does this require de-bouncing?
                    600:           if (View_DebounceSTKey(STScanCode))
                    601:             View_KeyUp(hWnd,0,MAKELONG(0,(Key&0x80) ? KF_EXTENDED|Key:Key));
                    602:         }
                    603:       }
                    604:     }
                    605:   }
                    606: */
                    607: }
                    608: 
                    609: //-----------------------------------------------------------------------
                    610: /*
                    611:   Check if mouse is at edges of our Window and move back to middle to allow us to emulate
                    612:   the relative mouse mode.
                    613:   As Windows does not allow 'relative' mouse movement (on all versions of Windows) we need to
                    614:   emulate this by finding the difference between this mouse position and the previous one.
                    615:   However, Windows will limit the mouse to the edge of the screen/client area and so we need
                    616:   to move the mouse back to the middle of the window when it gets close to the edges to give
                    617:   constant relative values. Phew!
                    618: */
                    619: void View_CheckMouseAtEdgeOfScreen(/*HWND hWnd,*/int MouseX,int MouseY)
                    620: {
                    621: /*
                    622:   RECT RectCapture;
                    623:   POINT MousePoint;
                    624: 
                    625:   // Get mouse point as client coordinates
                    626:   MousePoint.x = MouseX;
                    627:   MousePoint.y = MouseY;
                    628:   if (!bInFullScreen)
                    629:     ScreenToClient(hWnd,&MousePoint);
                    630: 
                    631:   // Calculate edges along client/full screen bounds
                    632:   View_GetMinBorderRect(&RectCapture);
                    633: 
                    634:   // Is mouse towards edge of client area? If so, need to reset to keep relative
                    635:   if ( (MousePoint.x<(RectCapture.left+20)) || (MousePoint.y<(RectCapture.top+20)) || (MousePoint.x>(RectCapture.right-20)) || (MousePoint.y>(RectCapture.bottom-20)) ) {
                    636:     // This is the middle of the window
                    637:     MousePoint.x = (RectCapture.right/2);
                    638:     MousePoint.y = (RectCapture.bottom/2);
                    639:     // Put back into screen coordinates for setting position back
                    640:     if (!bInFullScreen)
                    641:       ClientToScreen(hWnd,&MousePoint);
                    642:     SetCursorPos(MousePoint.x,MousePoint.y);
                    643: 
                    644:     // And make sure delta isn't passed back to emulation
                    645:     View_ResetRelativeMouseDelta();
                    646:   }
                    647: */
                    648: }
                    649: 
                    650: //-----------------------------------------------------------------------
                    651: /*
                    652:   Store current mouse position and check for edges of window(to create relative movement)
                    653: */
                    654: void View_UpdateSTMousePosition(void)
                    655: {
                    656:   int mx, my;
                    657: 
                    658:   /* Only update if in mouse emulation mode */
                    659:   if (!bWindowsMouseMode) {
                    660:     /* Get cursor position */
                    661:     SDL_GetMouseState(&mx, &my);
                    662:     KeyboardProcessor.Rel.X = mx;
                    663:     KeyboardProcessor.Rel.Y = my;
                    664:     /* Move Windows cursor back from edges of screen (creates relative movement) */
                    665:     View_CheckMouseAtEdgeOfScreen(mx, my);
                    666:   }
                    667: }
                    668: 
                    669: 
                    670: //-----------------------------------------------------------------------
                    671: /*
                    672:   User press key down
                    673: */
                    674: void View_KeyDown( unsigned int sdlkey, unsigned int sdlmod )
                    675: {
                    676:   BOOL bPreviousKeyState;
                    677:   char STScanCode;
                    678:   unsigned int Key;
                    679: 
                    680:   Key = sdlkey;
                    681: 
                    682:   /* If using cursor emulation, DON'T send keys to keyboard processor!!! Some games use keyboard as pause! */
                    683:   if ( (ConfigureParams.Joysticks.Joy[0].bCursorEmulation || ConfigureParams.Joysticks.Joy[1].bCursorEmulation)
                    684:             && !(SDL_GetModState()&(KMOD_LSHIFT|KMOD_RSHIFT)) )
                    685:    {
                    686:     if( Key==SDLK_UP )         { cursorJoyEmu |= 1; return; }
                    687:                 else if( Key==SDLK_DOWN )  { cursorJoyEmu |= 2; return; }
                    688:                 else if( Key==SDLK_LEFT )  { cursorJoyEmu |= 4; return; }
                    689:                 else if( Key==SDLK_RIGHT ) { cursorJoyEmu |= 8; return; }
                    690:                 else if( Key==SDLK_RCTRL || Key==SDLK_KP0 )  { cursorJoyEmu |= 128; return; }
                    691:    }
                    692: 
                    693:   /* Bring up help on F1 */
                    694: //FM  if ( (bWindowsMouseMode) && (Key==KEY_F1) )
                    695: //FIXME    ToolBar_Activate_Help();
                    696: 
                    697:   /* Set down */
                    698:   bPreviousKeyState = Keyboard.KeyStates[Key];
                    699:   Keyboard.KeyStates[Key] = TRUE;
                    700: 
                    701:   /* If pressed F11 or F12, retain short-cut keypress until safe to execute(start of VBL) */
                    702: /*FIXME
                    703:   if ( (Key==KEY_F11) || (Key==KEY_F12) )
                    704:    {
                    705:     ShortCutKey.Key = Key;
                    706:     ShortCutKey.bCtrlPressed = (GetAsyncKeyState(VK_CONTROL)&0x8000);
                    707:     ShortCutKey.bShiftPressed = (GetAsyncKeyState(VK_SHIFT)&0x8000);
                    708:    }
                    709:   else
                    710: */
                    711:    {
                    712:     STScanCode = Keymap_RemapKeyToSTScanCode(Key);
                    713: /*fprintf(stderr,"Key=%i, Scancode=%x\n",Key,STScanCode);*/
                    714:     if (STScanCode!=-1)
                    715:      {
                    716:       if (!bPreviousKeyState)
                    717:         IKBD_PressSTKey(STScanCode,TRUE);
                    718:      }
                    719:    }
                    720: 
                    721:   // If not running emulator check keys here and not on VBL
                    722:   if (bWindowsMouseMode)
                    723:     ShortCut_CheckKeys();
                    724: }
                    725: 
                    726: 
                    727: //-----------------------------------------------------------------------
                    728: /*
                    729:   User released key
                    730: */
                    731: void View_KeyUp(unsigned int sdlkey, unsigned int sdlmod)
                    732: {
                    733:   char STScanCode;
                    734:   unsigned int Key;
                    735: 
                    736:   Key = sdlkey;
                    737:   
                    738: 
                    739:   /* If using cursor emulation, DON'T send keys to keyboard processor!!! Some games use keyboard as pause! */
                    740:   if ( (ConfigureParams.Joysticks.Joy[0].bCursorEmulation || ConfigureParams.Joysticks.Joy[1].bCursorEmulation)
                    741:             && !(SDL_GetModState()&(KMOD_LSHIFT|KMOD_RSHIFT)) )
                    742:          {
                    743:     if( Key==SDLK_UP )         { cursorJoyEmu &= ~1; return; }
                    744:                 else if( Key==SDLK_DOWN )  { cursorJoyEmu &= ~2; return; }
                    745:                 else if( Key==SDLK_LEFT )  { cursorJoyEmu &= ~4; return; }
                    746:                 else if( Key==SDLK_RIGHT ) { cursorJoyEmu &= ~8; return; }
                    747:                 else if( Key==SDLK_RCTRL || Key==SDLK_KP0 )  { cursorJoyEmu &= ~128; return; }
                    748:    }
                    749: 
                    750:   /* Release key (only if was pressed) */
                    751:   STScanCode = Keymap_RemapKeyToSTScanCode(Key);
                    752:   if (STScanCode!=-1) {
                    753:     if (Keyboard.KeyStates[Key])
                    754:       IKBD_PressSTKey(STScanCode,FALSE);
                    755:   }
                    756: 
                    757:   Keyboard.KeyStates[Key] = FALSE;
                    758: }
                    759: 
                    760: 
                    761: //-----------------------------------------------------------------------
                    762: /*
                    763:   User moved mouse
                    764: */
                    765: /*
                    766: void View_MouseMove(HWND hWnd,UINT wParam,LONG lParam)
                    767: {
                    768:   int MouseX,MouseY;
                    769: 
                    770:   // Are we in Windows mouse mode?
                    771:   if (bWindowsMouseMode) {
                    772:     // Get mouse coords
                    773:     MouseX = LOWORD(lParam);
                    774:     MouseY = HIWORD(lParam);
                    775: 
                    776:     // Restore cursor
                    777:     SetCursor(Cursors[CURSOR_ARROW]);
                    778:     // Update toolbar
                    779:     ToolBar_UpdateOnMoveMove(MouseX,MouseY);
                    780: 
                    781:     return;
                    782:   }
                    783: }
                    784: */
                    785: 
                    786: //-----------------------------------------------------------------------
                    787: /*
                    788:   User pressed left mouse button
                    789: */
                    790: void View_LeftMouseButtonDown()
                    791: {
                    792:   int MouseX,MouseY;
                    793: 
                    794:   // Are we in Windows mouse mode?
                    795: /*
                    796:   if (bWindowsMouseMode)
                    797:    {
                    798:     // Get mouse coords
                    799:     MouseX = LOWORD(lParam);
                    800:     MouseY = HIWORD(lParam);
                    801: 
                    802:     // Activate toolbar button and execute
                    803:     ToolBar_ActivateOnLeftButtonDown(MouseX,MouseY);
                    804:    }
                    805:   else
                    806: */
                    807:    {
                    808:     if (Keyboard.LButtonDblClk==0)
                    809:       Keyboard.bLButtonDown |= BUTTON_MOUSE;  // Set button down flag
                    810:    }
                    811: }
                    812: 
                    813: 
                    814: //-----------------------------------------------------------------------
                    815: /*
                    816:   User released left mouse button
                    817: */
                    818: void View_LeftMouseButtonUp()
                    819: {
                    820:   /* Are we in Windows mouse mode? */
                    821: /*
                    822:   if (!bWindowsMouseMode) {
                    823:     if (Keyboard.LButtonDblClk==0)
                    824:       Keyboard.bLButtonDown &= ~BUTTON_MOUSE;  // Button is released
                    825:   }
                    826:   else
                    827: */
                    828:     Keyboard.bLButtonDown &= ~BUTTON_MOUSE;
                    829: }
                    830: 
                    831: 
                    832: //-----------------------------------------------------------------------
                    833: /*
                    834:   User pressed right mouse button
                    835: */
                    836: void View_RightMouseButtonDown()
                    837: {
                    838:   int MouseX,MouseY;
                    839: 
                    840:   /* Are we in Windows mouse mode? */
                    841: /*
                    842:   if (bWindowsMouseMode)
                    843:    {
                    844:     // Get mouse coords
                    845:     MouseX = LOWORD(lParam);
                    846:     MouseY = HIWORD(lParam);
                    847: 
                    848:     // Activate toolbar button and execute
                    849:     ToolBar_ActivateOnRightButtonDown(MouseX,MouseY);
                    850:    }
                    851:   else
                    852: */
                    853:    {
                    854:     Keyboard.bRButtonDown |= BUTTON_MOUSE;
                    855:    }
                    856: }
                    857: 
                    858: 
                    859: //-----------------------------------------------------------------------
                    860: /*
                    861:   User released right mouse button
                    862: */
                    863: void View_RightMouseButtonUp()
                    864: {
                    865:   // Are we in Windows mouse mode?
                    866:   if (bWindowsMouseMode)
                    867:     return;
                    868: 
                    869:   Keyboard.bRButtonDown &= ~BUTTON_MOUSE;
                    870: }
                    871: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.