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