1 /* Catacomb Armageddon Source Code
\r
2 * Copyright (C) 1993-2014 Flat Rock Software
\r
4 * This program is free software; you can redistribute it and/or modify
\r
5 * it under the terms of the GNU General Public License as published by
\r
6 * the Free Software Foundation; either version 2 of the License, or
\r
7 * (at your option) any later version.
\r
9 * This program is distributed in the hope that it will be useful,
\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
12 * GNU General Public License for more details.
\r
14 * You should have received a copy of the GNU General Public License along
\r
15 * with this program; if not, write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
21 // ID_US_1.c - User Manager - General routines
\r
23 // By Jason Blochowiak
\r
24 // Hacked up for Catacomb 3D
\r
28 // This module handles dealing with user input & feedback
\r
30 // Depends on: Input Mgr, View Mgr, some variables from the Sound, Caching,
\r
31 // and Refresh Mgrs, Memory Mgr for background save/restore
\r
34 // ingame - Flag set by game indicating if a game is in progress
\r
35 // abortgame - Flag set if the current game should be aborted (if a load
\r
37 // loadedgame - Flag set if a game was loaded
\r
38 // abortprogram - Normally nil, this points to a terminal error message
\r
39 // if the program needs to abort
\r
40 // restartgame - Normally set to gd_Continue, this is set to one of the
\r
41 // difficulty levels if a new game should be started
\r
42 // PrintX, PrintY - Where the User Mgr will print (global coords)
\r
43 // WindowX,WindowY,WindowW,WindowH - The dimensions of the current
\r
47 #include "ID_HEADS.H"
\r
55 extern boolean showscorebox;
\r
57 extern boolean oldshooting;
\r
58 extern ScanCode firescan;
\r
68 word WindowX,WindowY,WindowW,WindowH;
\r
70 word MaxX=320,MaxY=200; // MDM (GAMERS EDGE)
\r
72 // Internal variables
\r
73 #define ConfigVersion 1
\r
75 static char *ParmStrings[] = {"TEDLEVEL","NOWAIT"},
\r
76 *ParmStrings2[] = {"COMP","NOCOMP"};
\r
77 static boolean US_Started;
\r
79 boolean Button0,Button1,
\r
81 int CursorX,CursorY;
\r
83 void (*USL_MeasureString)(char far *,word *,word *) = VW_MeasurePropString,
\r
84 (*USL_DrawString)(char far *) = VWB_DrawPropString;
\r
86 boolean (*USL_SaveGame)(int),(*USL_LoadGame)(int);
\r
87 void (*USL_ResetGame)(void);
\r
88 SaveGame Games[MaxSaveGames];
\r
89 HighScore Scores[MaxScores] =
\r
91 {"Sir Lancelot",500,3},
\r
100 // Internal routines
\r
104 ///////////////////////////////////////////////////////////////////////////
\r
106 // USL_HardError() - Handles the Abort/Retry/Fail sort of errors passed
\r
109 ///////////////////////////////////////////////////////////////////////////
\r
113 USL_HardError(word errval,int ax,int bp,int si)
\r
118 extern void ShutdownId(void);
\r
120 static char buf[32];
\r
121 static WindowRec wr;
\r
129 s = "Device Error";
\r
132 if ((di & 0x00ff) == 0)
\r
133 s = "Drive ~ is Write Protected";
\r
135 s = "Error on Drive ~";
\r
136 for (t = buf;*s;s++,t++) // Can't use sprintf()
\r
137 if ((*t = *s) == '~')
\r
138 *t = (ax & 0x00ff) + 'A';
\r
143 c = peekb(0x40,0x49); // Get the current screen mode
\r
144 if ((c < 4) || (c == 7))
\r
147 // DEBUG - handle screen cleanup
\r
149 US_SaveWindow(&wr);
\r
150 US_CenterWindow(30,3);
\r
152 US_CPrint("(R)etry or (A)bort?");
\r
154 IN_ClearKeysDown();
\r
156 asm sti // Let the keyboard interrupts come through
\r
160 switch (IN_WaitForASCII())
\r
173 US_RestoreWindow(&wr);
\r
182 fprintf(stderr,"Terminal Error: %s\n",s);
\r
184 fprintf(stderr,"You launched from TED. I suggest that you reboot...\n");
\r
194 ///////////////////////////////////////////////////////////////////////////
\r
196 // USL_GiveSaveName() - Returns a pointer to a static buffer that contains
\r
197 // the filename to use for the specified save game
\r
199 ///////////////////////////////////////////////////////////////////////////
\r
201 USL_GiveSaveName(word game)
\r
203 static char name[] = "SAVEGAMx."EXT;
\r
205 name[7] = '0' + game;
\r
209 ///////////////////////////////////////////////////////////////////////////
\r
211 // US_SetLoadSaveHooks() - Sets the routines that the User Mgr calls after
\r
212 // reading or writing the save game headers
\r
214 ///////////////////////////////////////////////////////////////////////////
\r
216 US_SetLoadSaveHooks(boolean (*load)(int),boolean (*save)(int),void (*reset)(void))
\r
218 USL_LoadGame = load;
\r
219 USL_SaveGame = save;
\r
220 USL_ResetGame = reset;
\r
223 ///////////////////////////////////////////////////////////////////////////
\r
225 // USL_ReadConfig() - Reads the configuration file, if present, and sets
\r
226 // things up accordingly. If it's not present, uses defaults. This file
\r
227 // includes the high scores.
\r
229 ///////////////////////////////////////////////////////////////////////////
\r
231 USL_ReadConfig(void)
\r
234 char sig[sizeof(EXT)];
\r
241 if ((file = open("CONFIG."EXT,O_BINARY | O_RDONLY)) != -1)
\r
243 read(file,sig,sizeof(EXT));
\r
244 read(file,&version,sizeof(version));
\r
245 if (strcmp(sig,EXT) || (version != ConfigVersion))
\r
250 read(file,Scores,sizeof(HighScore) * MaxScores);
\r
251 read(file,&sd,sizeof(sd));
\r
252 read(file,&sm,sizeof(sm));
\r
253 read(file,&ctl,sizeof(ctl));
\r
254 read(file,&(KbdDefs[0]),sizeof(KbdDefs[0]));
\r
255 read(file,&showscorebox,sizeof(showscorebox));
\r
256 read(file,&compatability,sizeof(compatability));
\r
258 read(file,&oldshooting,sizeof(oldshooting));
\r
259 read(file,&firescan,sizeof(firescan));
\r
263 HighScoresDirty = false;
\r
271 ctl = ctrl_Keyboard;
\r
272 showscorebox = true;
\r
274 oldshooting = false;
\r
278 HighScoresDirty = true;
\r
281 SD_Default(gotit,sd,sm);
\r
282 IN_Default(gotit,ctl);
\r
285 ///////////////////////////////////////////////////////////////////////////
\r
287 // USL_WriteConfig() - Writes out the current configuration, including the
\r
290 ///////////////////////////////////////////////////////////////////////////
\r
292 USL_WriteConfig(void)
\r
297 version = ConfigVersion;
\r
298 file = open("CONFIG."EXT,O_CREAT | O_BINARY | O_WRONLY,
\r
299 S_IREAD | S_IWRITE | S_IFREG);
\r
302 write(file,EXT,sizeof(EXT));
\r
303 write(file,&version,sizeof(version));
\r
304 write(file,Scores,sizeof(HighScore) * MaxScores);
\r
305 write(file,&SoundMode,sizeof(SoundMode));
\r
306 write(file,&MusicMode,sizeof(MusicMode));
\r
309 (Controls[0] == ctrl_Joystick1)
\r
310 || (Controls[0] == ctrl_Joystick2)
\r
312 Controls[0] = ctrl_Keyboard;
\r
313 write(file,&(Controls[0]),sizeof(Controls[0]));
\r
314 write(file,&(KbdDefs[0]),sizeof(KbdDefs[0]));
\r
315 write(file,&showscorebox,sizeof(showscorebox));
\r
316 write(file,&compatability,sizeof(compatability));
\r
318 write(file,&oldshooting,sizeof(oldshooting));
\r
319 write(file,&firescan,sizeof(firescan));
\r
325 ///////////////////////////////////////////////////////////////////////////
\r
327 // USL_CheckSavedGames() - Checks to see which saved games are present
\r
330 ///////////////////////////////////////////////////////////////////////////
\r
332 USL_CheckSavedGames(void)
\r
343 for (i = 0,game = Games;i < MaxSaveGames;i++,game++)
\r
345 filename = USL_GiveSaveName(i);
\r
347 if ((file = open(filename,O_BINARY | O_RDONLY)) != -1)
\r
351 (read(file,game,sizeof(*game)) == sizeof(*game))
\r
352 && (!strcmp(game->signature,EXT))
\r
353 && (game->oldtest == &PrintX)
\r
361 game->present = true;
\r
364 strcpy(game->signature,EXT);
\r
365 game->present = false;
\r
366 strcpy(game->name,"Empty");
\r
371 ///////////////////////////////////////////////////////////////////////////
\r
373 // US_Startup() - Starts the User Mgr
\r
375 ///////////////////////////////////////////////////////////////////////////
\r
384 harderr(USL_HardError); // Install the fatal error handler
\r
386 US_InitRndT(true); // Initialize the random number generator
\r
388 USL_ReadConfig(); // Read config file
\r
390 for (i = 1;i < _argc;i++)
\r
392 switch (US_CheckParm(_argv[i],ParmStrings2))
\r
395 if (grmode == EGAGR)
\r
396 compatability = true;
\r
399 compatability = false;
\r
407 ///////////////////////////////////////////////////////////////////////////
\r
409 // US_Setup() - Does the disk access part of the User Mgr's startup
\r
411 ///////////////////////////////////////////////////////////////////////////
\r
415 USL_CheckSavedGames(); // Check which saved games are present
\r
418 ///////////////////////////////////////////////////////////////////////////
\r
420 // US_Shutdown() - Shuts down the User Mgr
\r
422 ///////////////////////////////////////////////////////////////////////////
\r
432 US_Started = false;
\r
435 ///////////////////////////////////////////////////////////////////////////
\r
437 // US_CheckParm() - checks to see if a string matches one of a set of
\r
438 // strings. The check is case insensitive. The routine returns the
\r
439 // index of the string that matched, or -1 if no matches were found
\r
441 ///////////////////////////////////////////////////////////////////////////
\r
443 US_CheckParm(char *parm,char **strings)
\r
449 while (!isalpha(*parm)) // Skip non-alphas
\r
452 for (i = 0;*strings && **strings;i++)
\r
454 for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)
\r
471 ///////////////////////////////////////////////////////////////////////////
\r
473 // USL_ScreenDraw() - Draws a chunk of the text screen (called only by
\r
474 // US_TextScreen())
\r
476 ///////////////////////////////////////////////////////////////////////////
\r
478 USL_ScreenDraw(word x,word y,char *s,byte attr)
\r
480 byte far *screen,far *oscreen;
\r
482 screen = MK_FP(0xb800,(x * 2) + (y * 80 * 2));
\r
483 oscreen = (&introscn + 7) + ((x - 1) * 2) + (y * 80 * 2) + 1;
\r
489 *screen++ = (attr & 0x8f) | (*oscreen & 0x70);
\r
498 ///////////////////////////////////////////////////////////////////////////
\r
500 // USL_ClearTextScreen() - Makes sure the screen is in text mode, clears it,
\r
501 // and moves the cursor to the leftmost column of the bottom line
\r
503 ///////////////////////////////////////////////////////////////////////////
\r
505 USL_ClearTextScreen(void)
\r
507 // Set to 80x25 color text mode
\r
510 geninterrupt(0x10);
\r
512 // Use BIOS to move the cursor to the bottom of the screen
\r
514 geninterrupt(0x10); // Get current video mode into _BH
\r
515 _DL = 0; // Lefthand side of the screen
\r
516 _DH = 24; // Bottom row
\r
518 geninterrupt(0x10);
\r
522 ///////////////////////////////////////////////////////////////////////////
\r
524 // US_TextScreen() - Puts up the startup text screen
\r
525 // Note: These are the only User Manager functions that can be safely called
\r
526 // before the User Mgr has been started up
\r
528 ///////////////////////////////////////////////////////////////////////////
\r
530 US_TextScreen(void)
\r
534 USL_ClearTextScreen();
\r
536 _fmemcpy(MK_FP(0xb800,0),7 + &introscn,80 * 25 * 2);
\r
538 // Check for TED launching here
\r
539 for (i = 1;i < _argc;i++)
\r
541 n = US_CheckParm(_argv[i],ParmStrings);
\r
544 tedlevelnum = atoi(_argv[i + 1]);
\r
545 if (tedlevelnum >= 0)
\r
561 ///////////////////////////////////////////////////////////////////////////
\r
563 // USL_Show() - Changes the appearance of one of the fields on the text
\r
564 // screen. Possibly adds a checkmark in front of it and highlights it
\r
566 ///////////////////////////////////////////////////////////////////////////
\r
568 USL_Show(word x,word y,word w,boolean show,boolean hilight)
\r
570 byte far *screen,far *oscreen;
\r
572 screen = MK_FP(0xb800,((x - 1) * 2) + (y * 80 * 2));
\r
573 oscreen = (&introscn + 7) + ((x - 1) * 2) + (y * 80 * 2) - 1;
\r
574 *screen++ = show? 251 : ' '; // Checkmark char or space
\r
576 // *screen = (*oscreen & 0xf0) | 8;
\r
578 if (show && hilight)
\r
580 for (w++;w--;screen += 2,oscreen += 2)
\r
581 *screen = (*oscreen & 0xf0) | 0x0f;
\r
585 ///////////////////////////////////////////////////////////////////////////
\r
587 // USL_ShowMem() - Right justifies a longword in one of the memory fields on
\r
590 ///////////////////////////////////////////////////////////////////////////
\r
592 USL_ShowMem(word x,word y,long mem)
\r
597 for (i = strlen(ltoa(mem,buf,10));i < 5;i++)
\r
598 USL_ScreenDraw(x++,y," ",0xff);
\r
599 USL_ScreenDraw(x,y,buf,0xff);
\r
602 ///////////////////////////////////////////////////////////////////////////
\r
604 // US_UpdateTextScreen() - Called after the ID libraries are started up.
\r
605 // Displays what hardware is present.
\r
607 ///////////////////////////////////////////////////////////////////////////
\r
609 US_UpdateTextScreen(void)
\r
614 // Show video card info
\r
615 b = (grmode == CGAGR);
\r
616 USL_Show(21,7,4,(videocard >= CGAcard) && (videocard <= VGAcard),b);
\r
617 b = (grmode == EGAGR);
\r
618 USL_Show(21,8,4,(videocard >= EGAcard) && (videocard <= VGAcard),b);
\r
619 b = (grmode == VGAGR);
\r
620 USL_Show(21,9,4,videocard == VGAcard,b);
\r
622 USL_ScreenDraw(5,10,"SVGA Compatibility Mode Enabled.",0x4f);
\r
624 // Show input device info
\r
625 USL_Show(60,7,8,true,true);
\r
626 USL_Show(60,8,11,JoysPresent[0],true);
\r
627 USL_Show(60,9,11,JoysPresent[1],true);
\r
628 USL_Show(60,10,5,MousePresent,true);
\r
630 // Show sound hardware info
\r
631 USL_Show(21,14,11,true,SoundMode == sdm_PC);
\r
632 b = (SoundMode == sdm_AdLib) || (MusicMode == smm_AdLib);
\r
633 USL_Show(21,15,14,AdLibPresent,b);
\r
634 if (b && AdLibPresent) // Hack because of two lines
\r
636 byte far *screen,far *oscreen;
\r
642 screen = MK_FP(0xb800,(x * 2) + (y * 80 * 2) - 1);
\r
643 oscreen = (&introscn + 7) + (x * 2) + (y * 80 * 2) - 1;
\r
645 for (w++;w--;screen += 2,oscreen += 2)
\r
646 *screen = (*oscreen & 0xf0) | 0x0f;
\r
649 // Show memory available/used
\r
650 USL_ShowMem(63,15,mminfo.mainmem / 1024);
\r
651 USL_Show(53,15,23,true,true);
\r
652 USL_ShowMem(63,16,mminfo.EMSmem / 1024);
\r
653 USL_Show(53,16,23,mminfo.EMSmem? true : false,true);
\r
654 USL_ShowMem(63,17,mminfo.XMSmem / 1024);
\r
655 USL_Show(53,17,23,mminfo.XMSmem? true : false,true);
\r
656 totalmem = mminfo.mainmem + mminfo.EMSmem + mminfo.XMSmem;
\r
657 USL_ShowMem(63,18,totalmem / 1024);
\r
658 USL_Show(53,18,23,true,true); // DEBUG
\r
659 USL_ScreenDraw(52,18," ",0xff);
\r
661 // Change Initializing... to Loading...
\r
662 USL_ScreenDraw(27,22," Loading... ",0x9c);
\r
665 ///////////////////////////////////////////////////////////////////////////
\r
667 // US_FinishTextScreen() - After the main program has finished its initial
\r
668 // loading, this routine waits for a keypress and then clears the screen
\r
670 ///////////////////////////////////////////////////////////////////////////
\r
672 US_FinishTextScreen(void)
\r
674 static byte colors[] = {4,6,13,15,15,15,15,15,15};
\r
678 // Change Loading... to Press a Key
\r
680 if (!(tedlevel || NoWait))
\r
682 IN_ClearKeysDown();
\r
683 for (i = 0,up = true;!IN_UserInput(4,true);)
\r
697 USL_ScreenDraw(29,22," Ready - Press a Key ",0x00 + c);
\r
701 USL_ScreenDraw(29,22," Ready - Press a Key ",0x9a);
\r
702 IN_ClearKeysDown();
\r
704 USL_ClearTextScreen();
\r
708 // Window/Printing routines
\r
710 ///////////////////////////////////////////////////////////////////////////
\r
712 // US_SetPrintRoutines() - Sets the routines used to measure and print
\r
713 // from within the User Mgr. Primarily provided to allow switching
\r
714 // between masked and non-masked fonts
\r
716 ///////////////////////////////////////////////////////////////////////////
\r
718 US_SetPrintRoutines(void (*measure)(char far *,word *,word *),void (*print)(char far *))
\r
720 USL_MeasureString = measure;
\r
721 USL_DrawString = print;
\r
724 ///////////////////////////////////////////////////////////////////////////
\r
726 // US_Print() - Prints a string in the current window. Newlines are
\r
729 ///////////////////////////////////////////////////////////////////////////
\r
739 while ((c = *se) && (c != '\n'))
\r
743 USL_MeasureString(s,&w,&h);
\r
762 // MDM - (GAMERS EDGE) begin
\r
764 ///////////////////////////////////////////////////////////////////////////
\r
768 void US_Printxy(word x, word y, char *text)
\r
775 // PrintX = WindowX+x;
\r
776 // PrintY = WindowY+y;
\r
785 // MDM - (GAMERS EDGE) end
\r
787 ///////////////////////////////////////////////////////////////////////////
\r
789 // US_PrintUnsigned() - Prints an unsigned long
\r
791 ///////////////////////////////////////////////////////////////////////////
\r
793 US_PrintUnsigned(longword n)
\r
797 US_Print(ultoa(n,buffer,10));
\r
800 ///////////////////////////////////////////////////////////////////////////
\r
802 // US_PrintSigned() - Prints a signed long
\r
804 ///////////////////////////////////////////////////////////////////////////
\r
806 US_PrintSigned(long n)
\r
810 US_Print(ltoa(n,buffer,10));
\r
813 ///////////////////////////////////////////////////////////////////////////
\r
815 // USL_PrintInCenter() - Prints a string in the center of the given rect
\r
817 ///////////////////////////////////////////////////////////////////////////
\r
819 USL_PrintInCenter(char *s,Rect r)
\r
824 USL_MeasureString(s,&w,&h);
\r
825 rw = r.lr.x - r.ul.x;
\r
826 rh = r.lr.y - r.ul.y;
\r
828 px = r.ul.x + ((rw - w) / 2);
\r
829 py = r.ul.y + ((rh - h) / 2);
\r
833 ///////////////////////////////////////////////////////////////////////////
\r
835 // US_PrintCentered() - Prints a string centered in the current window.
\r
837 ///////////////////////////////////////////////////////////////////////////
\r
839 US_PrintCentered(char *s)
\r
845 r.lr.x = r.ul.x + WindowW;
\r
846 r.lr.y = r.ul.y + WindowH;
\r
848 USL_PrintInCenter(s,r);
\r
851 ///////////////////////////////////////////////////////////////////////////
\r
853 // US_CPrintLine() - Prints a string centered on the current line and
\r
854 // advances to the next line. Newlines are not supported.
\r
856 ///////////////////////////////////////////////////////////////////////////
\r
858 US_CPrintLine(char *s)
\r
862 USL_MeasureString(s,&w,&h);
\r
865 Quit("US_CPrintLine() - String exceeds width");
\r
866 px = WindowX + ((WindowW - w) / 2);
\r
872 ///////////////////////////////////////////////////////////////////////////
\r
874 // US_CPrint() - Prints a string in the current window. Newlines are
\r
877 ///////////////////////////////////////////////////////////////////////////
\r
886 while ((c = *se) && (c != '\n'))
\r
901 ///////////////////////////////////////////////////////////////////////////
\r
903 // US_ClearWindow() - Clears the current window to white and homes the
\r
906 ///////////////////////////////////////////////////////////////////////////
\r
908 US_ClearWindow(void)
\r
910 VWB_Bar(WindowX,WindowY,WindowW,WindowH,LT_GREY);
\r
915 ///////////////////////////////////////////////////////////////////////////
\r
917 // US_DrawWindow() - Draws a frame and sets the current window parms
\r
919 ///////////////////////////////////////////////////////////////////////////
\r
921 US_DrawWindow(word x,word y,word w,word h)
\r
941 VWB_DrawTile8M(sx,sy,0),VWB_DrawTile8M(sx,sy + sh,6);
\r
942 for (i = sx + 8;i <= sx + sw - 8;i += 8)
\r
943 VWB_DrawTile8M(i,sy,1),VWB_DrawTile8M(i,sy + sh,7);
\r
944 VWB_DrawTile8M(i,sy,2),VWB_DrawTile8M(i,sy + sh,8);
\r
946 for (i = sy + 8;i <= sy + sh - 8;i += 8)
\r
947 VWB_DrawTile8M(sx,i,3),VWB_DrawTile8M(sx + sw,i,5);
\r
950 ///////////////////////////////////////////////////////////////////////////
\r
952 // US_CenterWindow() - Generates a window of a given width & height in the
\r
953 // middle of the screen
\r
955 ///////////////////////////////////////////////////////////////////////////
\r
957 US_CenterWindow(word w,word h)
\r
959 US_DrawWindow(((MaxX / 8) - w) / 2,((MaxY / 8) - h) / 2,w,h);
\r
962 ///////////////////////////////////////////////////////////////////////////
\r
964 // US_CenterSaveWindow() - Generates a window of a given width & height in
\r
965 // the middle of the screen, saving the background
\r
967 ///////////////////////////////////////////////////////////////////////////
\r
969 US_CenterSaveWindow(word w,word h,memptr *save)
\r
974 x = ((MaxX / 8) - w) / 2;
\r
975 y = ((MaxY / 8) - h) / 2;
\r
976 MM_GetPtr(save,(w * h) * CHARWIDTH);
\r
977 screen = bufferofs + panadjust + ylookup[y] + (x * CHARWIDTH);
\r
978 VW_ScreenToMem(screen,*save,w * CHARWIDTH,h);
\r
979 US_DrawWindow(((MaxX / 8) - w) / 2,((MaxY / 8) - h) / 2,w,h);
\r
982 ///////////////////////////////////////////////////////////////////////////
\r
984 // US_RestoreSaveWindow() - Restores the background of the size of the
\r
985 // current window from the memory specified by save
\r
987 ///////////////////////////////////////////////////////////////////////////
\r
989 US_RestoreSaveWindow(memptr *save)
\r
993 screen = bufferofs + panadjust + ylookup[WindowY] + (WindowX * CHARWIDTH);
\r
994 VW_MemToScreen(*save,screen,WindowW * CHARWIDTH,WindowH);
\r
998 ///////////////////////////////////////////////////////////////////////////
\r
1000 // US_SaveWindow() - Saves the current window parms into a record for
\r
1001 // later restoration
\r
1003 ///////////////////////////////////////////////////////////////////////////
\r
1005 US_SaveWindow(WindowRec *win)
\r
1016 ///////////////////////////////////////////////////////////////////////////
\r
1018 // US_RestoreWindow() - Sets the current window parms to those held in the
\r
1021 ///////////////////////////////////////////////////////////////////////////
\r
1023 US_RestoreWindow(WindowRec *win)
\r
1034 // Cursor routines
\r
1037 ///////////////////////////////////////////////////////////////////////////
\r
1039 // US_StartCursor() - Sets up the cursor for User Mgr use
\r
1041 ///////////////////////////////////////////////////////////////////////////
\r
1043 US_StartCursor(void)
\r
1047 VW_SetCursor(CURSORARROWSPR);
\r
1048 CursorX = MaxX / 2;
\r
1049 CursorY = MaxY / 2;
\r
1050 VW_MoveCursor(CursorX,CursorY);
\r
1053 IN_ReadCursor(&info); // Dispose of any accumulated movement
\r
1056 ///////////////////////////////////////////////////////////////////////////
\r
1058 // US_ShutCursor() - Cleans up after US_StartCursor()
\r
1060 ///////////////////////////////////////////////////////////////////////////
\r
1062 US_ShutCursor(void)
\r
1067 ///////////////////////////////////////////////////////////////////////////
\r
1069 // US_UpdateCursor() - Gets the new cursor position & button states from
\r
1070 // the Input Mgr and tells the View Mgr where the cursor is
\r
1072 ///////////////////////////////////////////////////////////////////////////
\r
1074 US_UpdateCursor(void)
\r
1078 IN_ReadCursor(&info);
\r
1079 if (info.x || info.y || CursorBad)
\r
1081 CursorX += info.x;
\r
1082 if (CursorX >= MaxX)
\r
1083 CursorX = MaxX - 1;
\r
1084 else if (CursorX < 0)
\r
1087 CursorY += info.y;
\r
1088 if (CursorY >= MaxY)
\r
1089 CursorY = MaxY - 1;
\r
1090 else if (CursorY < 0)
\r
1093 VW_MoveCursor(CursorX,CursorY);
\r
1094 CursorBad = false;
\r
1096 Button0 = info.button0;
\r
1097 Button1 = info.button1;
\r
1098 return(Button0 || Button1);
\r
1104 ///////////////////////////////////////////////////////////////////////////
\r
1106 // USL_XORICursor() - XORs the I-bar text cursor. Used by US_LineInput()
\r
1108 ///////////////////////////////////////////////////////////////////////////
\r
1110 USL_XORICursor(int x,int y,char *s,word cursor)
\r
1112 char buf[MaxString];
\r
1116 buf[cursor] = '\0';
\r
1117 USL_MeasureString(buf,&w,&h);
\r
1121 USL_DrawString("\x80");
\r
1124 ///////////////////////////////////////////////////////////////////////////
\r
1126 // US_LineInput() - Gets a line of user input at (x,y), the string defaults
\r
1127 // to whatever is pointed at by def. Input is restricted to maxchars
\r
1128 // chars or maxwidth pixels wide. If the user hits escape (and escok is
\r
1129 // true), nothing is copied into buf, and false is returned. If the
\r
1130 // user hits return, the current string is copied into buf, and true is
\r
1133 ///////////////////////////////////////////////////////////////////////////
\r
1135 US_LineInput(int x,int y,char *buf,char *def,boolean escok,
\r
1136 int maxchars,int maxwidth)
\r
1139 cursorvis,cursormoved,
\r
1143 s[MaxString],olds[MaxString];
\r
1148 longword lasttime;
\r
1157 cursor = strlen(s);
\r
1158 cursormoved = redraw = true;
\r
1160 cursorvis = done = false;
\r
1161 lasttime = TimeCount;
\r
1162 LastASCII = key_None;
\r
1163 LastScan = sc_None;
\r
1168 USL_XORICursor(x,y,s,cursor);
\r
1174 LastScan = sc_None;
\r
1176 LastASCII = key_None;
\r
1182 case sc_LeftArrow:
\r
1186 cursormoved = true;
\r
1188 case sc_RightArrow:
\r
1192 cursormoved = true;
\r
1197 cursormoved = true;
\r
1200 cursor = strlen(s);
\r
1202 cursormoved = true;
\r
1220 case sc_BackSpace:
\r
1223 strcpy(s + cursor - 1,s + cursor);
\r
1228 cursormoved = true;
\r
1233 strcpy(s + cursor,s + cursor + 1);
\r
1237 cursormoved = true;
\r
1240 case 0x4c: // Keypad 5
\r
1242 case sc_DownArrow:
\r
1253 USL_MeasureString(s,&w,&h);
\r
1258 && (len < MaxString - 1)
\r
1259 && ((!maxchars) || (len < maxchars))
\r
1260 && ((!maxwidth) || (w < maxwidth))
\r
1263 for (i = len + 1;i > cursor;i--)
\r
1274 USL_DrawString(olds);
\r
1279 USL_DrawString(s);
\r
1286 cursorvis = false;
\r
1287 lasttime = TimeCount - TickBase;
\r
1289 cursormoved = false;
\r
1291 if (TimeCount - lasttime > TickBase / 2)
\r
1293 lasttime = TimeCount;
\r
1295 cursorvis ^= true;
\r
1298 USL_XORICursor(x,y,s,cursor);
\r
1300 VW_UpdateScreen();
\r
1304 USL_XORICursor(x,y,s,cursor);
\r
1309 USL_DrawString(olds);
\r
1312 VW_UpdateScreen();
\r
1314 IN_ClearKeysDown();
\r