home *** CD-ROM | disk | FTP | other *** search
/ MegaDoom Adventures / PMWMEGADOOM.iso / doom / creators / deu52gcc / src / edit.c < prev    next >
Text File  |  1994-05-21  |  51KB  |  1,713 lines

  1. /*
  2.    Doom Editor Utility, by Brendon Wyber and Raphaël Quinet.
  3.  
  4.    You are allowed to use any parts of this code in another program, as
  5.    long as you give credits to the authors in the documentation and in
  6.    the program itself.  Read the file README.1ST for more information.
  7.  
  8.    This program comes with absolutely no warranty.
  9.  
  10.    EDIT.C - Editor routines.
  11. */
  12.  
  13. /* the includes */
  14. #include "deu.h"
  15. #include "levels.h"
  16.  
  17. extern Bool InfoShown;        /* should we display the info bar? */
  18. BCINT  MoveSpeed = 20;        /* movement speed */
  19.  
  20.  
  21. /*
  22.    the driving program
  23. */
  24.  
  25. void EditLevel( BCINT episode, BCINT mission, Bool newlevel)
  26. {
  27.    ReadWTextureNames();
  28.    ReadFTextureNames();
  29.    InitGfx();
  30.    CheckMouseDriver();
  31.    if (episode < 1 || mission < 1)
  32.       SelectLevel( &episode, &mission);
  33.    if (episode > 0 && mission > 0)
  34.    {
  35.       ClearScreen();
  36.       ReadLevelData( episode, mission);
  37.       if (newlevel)
  38.       {
  39.      ForgetLevelData();
  40.      MapMinX = -4000;
  41.      MapMinY = -4000;
  42.      MapMaxX = 4000;
  43.      MapMaxY = 4000;
  44.       }
  45.       LogMessage( ": Editing E%dM%d...\n", episode, mission);
  46.       EditorLoop( episode, mission);
  47.       LogMessage( ": Finished editing E%dM%d...\n", episode, mission);
  48.       TermGfx();
  49.       if (! Registered)
  50.      printf( "Please register DOOM if you want to be able to save your changes.\n");
  51.       ForgetLevelData();
  52.       /* forget the level pointer */
  53.       Level = NULL;
  54.    }
  55.    else
  56.       TermGfx();
  57.    ForgetWTextureNames();
  58.    ForgetFTextureNames();
  59. }
  60.  
  61.  
  62.  
  63. /*
  64.    select a level
  65. */
  66.  
  67. void SelectLevel( BCINT *episode, BCINT *mission)
  68. {
  69.    MDirPtr dir;
  70.    char name[ 7];
  71.    char **levels;
  72.    int ep,mi,n = 0;
  73.  
  74.    dir = MasterDir;
  75.    while (dir)
  76.    {
  77.       if (dir->dir.size == 0 && dir->dir.name[ 0] == 'E' && dir->dir.name[ 2] == 'M' && dir->dir.name[ 4] == '\0')
  78.       {
  79.            if (n == 0)
  80.               levels = (char**)GetMemory( sizeof( char *));
  81.            else
  82.               levels = (char**)ResizeMemory( levels, (n + 1) * sizeof( char *));
  83.            levels[ n] = dir->dir.name;
  84.            n++;
  85.       }
  86.       dir = dir->next;
  87.    }
  88.    if (*episode < 1)
  89.       *episode = 1;
  90.    if (*mission < 1)
  91.       *mission = 1;
  92.    sprintf( name, "E%dM%d", *episode, *mission);
  93.    InputNameFromList( -1, -1, "Select an episode and a mission number:", n, levels, name);
  94.    FreeMemory( levels);
  95.    if (*name)
  96.    {
  97.       sscanf( name, "E%dM%d", &ep, &mi);
  98.       *episode = (BCINT) ep;
  99.       *mission = (BCINT) mi;
  100.    }
  101.    else
  102.    {
  103.       *episode = 0;
  104.       *mission = 0;
  105.    }
  106. }
  107.  
  108.  
  109.  
  110. /*
  111.    get the name of the new WAD file
  112. */
  113.  
  114. char *GetWadFileName( BCINT episode, BCINT mission)
  115. {
  116.    char *outfile = (char*)GetMemory( 80);
  117.    char *dotp;
  118.    WadPtr wad;
  119.  
  120.    /* get the file name */
  121.    if (! strcmp(Level->wadfile->filename, MainWad))
  122.       sprintf( outfile, "E%dM%d.WAD", episode, mission);
  123.    else
  124.       strcpy( outfile, Level->wadfile->filename);
  125.    do
  126.    {
  127.       InputFileName( -1, -1, "Name of the new WAD file:", 79, outfile);
  128.    }
  129.    while (!strcmp(outfile, MainWad));
  130.    /* escape */
  131.    if (outfile[ 0] == '\0')
  132.    {
  133.       FreeMemory( outfile);
  134.       return NULL;
  135.    }
  136.    /* if the WAD file already exists, rename it to "*.BAK" */
  137.    for (wad = WadFileList; wad; wad = wad->next)
  138.       if (!stricmp( outfile, wad->filename))
  139.       {
  140.      dotp = strrchr( wad->filename, '.');
  141.      if (dotp == NULL)
  142.         strcat( wad->filename, ".BAK");
  143.      else
  144.         strcpy( dotp, ".BAK");
  145.      /* need to close, then reopen: problems with SHARE.EXE */
  146.      fclose( wad->fileinfo);
  147.      if (rename( outfile, wad->filename) < 0)
  148.      {
  149.         if (unlink( wad->filename) < 0)
  150.            ProgError( "could not delete file \"%s\"", wad->filename);
  151.         if (rename( outfile, wad->filename) < 0)
  152.            ProgError( "could not rename \"%s\" to \"%s\"", outfile, wad->filename);
  153.      }
  154.      wad->fileinfo = fopen( wad->filename, "rb");
  155.      if (wad->fileinfo == NULL)
  156.         ProgError( "could not reopen file \"%s\"", wad->filename);
  157.      break;
  158.       }
  159.    return outfile;
  160. }
  161.  
  162.  
  163.  
  164. /*
  165.    display the help screen
  166.  */
  167.  
  168. void DisplayHelp( BCINT objtype, BCINT grid) /* SWAP! */
  169. {
  170.    BCINT x0 = 137;
  171.    BCINT y0 = 50;
  172.  
  173.    if (UseMouse)
  174.       HideMousePointer();
  175.    /* put in the instructions */
  176.    DrawScreenBox3D( x0, y0, x0 + 364, y0 + 355);
  177.    SetColor( LIGHTCYAN);
  178.    DrawScreenText( x0 + 100, y0 + 20, "Doom Editor Utility");
  179.    DrawScreenText( 269 - strlen(GetEditModeName( objtype)) * 4, y0 + 32, "- %s Editor -", GetEditModeName( objtype));
  180.    SetColor( BLACK);
  181.    DrawScreenText( x0 + 10, y0 + 60, "Use the mouse or the cursor keys to move");
  182.    DrawScreenText( -1, -1, "around.  The map scrolls when the pointer");
  183.    DrawScreenText( -1, -1, "reaches the edge of the screen.");
  184.    DrawScreenText( -1, y0 + 100, "Other useful keys are:");
  185.    if (Registered)
  186.       DrawScreenText( -1, y0 + 115, "Q     - Quit, saving changes");
  187.    else
  188.    {
  189.       SetColor( DARKGRAY);
  190.       DrawScreenText( -1, y0 + 115, "Q     - Quit without saving changes");
  191.       SetColor( BLACK);
  192.    }
  193.    DrawScreenText( -1, -1, "Esc   - Exit without saving changes");
  194.    DrawScreenText( -1, -1, "Tab   - Switch to the next editing mode");
  195.    DrawScreenText( -1, -1, "Space - Change the move/scroll speed");
  196.    DrawScreenText( -1, -1, "+/-   - Change the map scale (current: %d)", (BCINT) (1.0 / Scale + 0.5));
  197.    DrawScreenText( -1, -1, "G     - Change the grid scale (cur.: %d)", grid);
  198.    DrawScreenText( -1, -1, "N, >  - Jump to the next object.");
  199.    DrawScreenText( -1, -1, "P, <  - Jump to the previous object.");
  200.    DrawScreenText( -1, -1, "J, #  - Jump to a specific object (enter #)");
  201.    DrawScreenText( -1, -1, "M     - Mark/unmark current object (select)");
  202.    if (objtype == OBJ_THINGS || objtype == OBJ_VERTEXES)
  203.       DrawScreenText( -1, -1, "D     - Toggle drag mode");
  204.    else
  205.       DrawScreenText( -1, -1, "C     - Clear all marks and redraw map");
  206.    DrawScreenText( -1, -1, "Ins   - Insert a new object");
  207.    DrawScreenText( -1, -1, "Del   - Delete the current object");
  208.    DrawScreenText( -1, -1, "Enter - Edit the current/selected object(s)");
  209.    DrawScreenText( -1, y0 + 265, "Mouse buttons:");
  210.    if (SwapButtons)
  211.    {
  212.       DrawScreenText( -1, y0 + 280, "Left  - Edit the current/selected object(s)");
  213.       DrawScreenText( -1, -1, "Middle- Mark/unmark the current object.");
  214.    }
  215.    else
  216.    {
  217.       DrawScreenText( -1, y0 + 280, "Left  - Mark/unmark the current object");
  218.       DrawScreenText( -1, -1, "Middle- Edit the current/selected object(s)");
  219.    }
  220.    DrawScreenText( -1, -1, "Right - Drag the current/selected object(s)");
  221.    DrawScreenText( -1, y0 + 320, "Please read DEU.TXT for more information");
  222.    SetColor( YELLOW);
  223.    DrawScreenText( -1, y0 + 340, "Press any key to return to the editor...");
  224.    bioskey( 0);
  225.    if (UseMouse)
  226.       ShowMousePointer();
  227. }
  228.  
  229.  
  230.  
  231. /*
  232.    the editor main loop
  233. */
  234.  
  235. void EditorLoop( BCINT episode, BCINT mission) /* SWAP! */
  236. {
  237.    BCINT  EditMode = OBJ_THINGS;
  238.    BCINT  CurObject = -1;
  239.    BCINT  OldObject = -1;
  240.    Bool   RedrawMap = TRUE;
  241.    Bool   RedrawObj = FALSE;
  242.    Bool   DragObject = FALSE;
  243.    int    key, altkey;
  244.    BCINT  buttons, oldbuttons;
  245.    BCINT  GridScale = 0;
  246.    Bool   GridShown = TRUE;
  247.    SelPtr Selected = NULL;
  248.    char   keychar;
  249.    BCINT  SelBoxX = 0;
  250.    BCINT  SelBoxY = 0;
  251.    Bool   StretchSelBox = FALSE;
  252.    Bool   ShowRulers = FALSE;
  253.    BCINT  OldPointerX = 0;
  254.    BCINT  OldPointerY = 0;
  255.  
  256.    MadeChanges = FALSE;
  257.    MadeMapChanges = FALSE;
  258.    if (InitialScale < 1)
  259.       InitialScale = 1;
  260.    else if (InitialScale > 20)
  261.       InitialScale = 20;
  262.    Scale = (float) (1.0 / InitialScale);
  263.    CenterMapAroundCoords( (MapMinX + MapMaxX) / 2, (MapMinY + MapMaxY) / 2);
  264.    if (UseMouse)
  265.    {
  266.       ResetMouseLimits();
  267.       SetMouseCoords( PointerX, PointerY);
  268.       ShowMousePointer();
  269.       oldbuttons = 0;
  270.    }
  271.    else
  272.       FakeCursor = TRUE;
  273.  
  274.    for (;;)
  275.    {
  276.       key = 0;
  277.       altkey = 0;
  278.  
  279.       /* get mouse position and button status */
  280.       if (UseMouse)
  281.       {
  282.      if (FakeCursor || ShowRulers)
  283.      {
  284.         HideMousePointer();
  285.         DrawPointer( ShowRulers);
  286.         ShowMousePointer();
  287.      }
  288.      GetMouseCoords( &PointerX, &PointerY, &buttons);
  289.      if (FakeCursor || ShowRulers)
  290.      {
  291.         HideMousePointer();
  292.         DrawPointer( ShowRulers);
  293.         ShowMousePointer();
  294.      }
  295.      if ( buttons == 1 && PointerY < 17)
  296.      {
  297.         /* kluge for the menu bar */
  298.         altkey = 0x08;
  299.         if (PointerX < 12)
  300.            Beep();
  301.         else if (PointerX < 60)
  302.            key = 0x2100; /* 'F' */
  303.         else if (PointerX < 108)
  304.            key = 0x1200; /* 'E' */
  305.         else if (PointerX < 172)
  306.            key = 0x1f00; /* 'S' */
  307.         else if (PointerX < 228)
  308.            key = 0x3200; /* 'M' */
  309.         else if (PointerX < 276)
  310.            key = 0x1700; /* 'I' */
  311.         else if (PointerX < 348)
  312.            key = 0x1800; /* 'O' */
  313.         else if (PointerX < 406)
  314.            key = 0x2E00; /* 'C' */
  315.         else if (PointerX < ScrMaxX - 43)
  316.            Beep();
  317.         else
  318.            key = 0x2300; /* 'H' */
  319.      }
  320.      else
  321.      {
  322.         if (buttons != oldbuttons)
  323.         {
  324.            switch (buttons)
  325.            {
  326.            case 1:
  327.           if (SwapButtons)
  328.                 key = 0x000D;
  329.              else
  330.                 key = 'M';      /* Press left button = Mark/Unmark ('M') */
  331.                  break;
  332.            case 2:
  333.              if (! DragObject)
  334.                 key = 'D';      /* Press right button = Drag */
  335.              break;
  336.            case 3:
  337.            case 4:
  338.                 if (SwapButtons)
  339.                 key = 'M';
  340.              else
  341.                 key = 0x000D;   /* Press middle button = Edit ('Enter') */
  342.              break;
  343.            default:
  344.              if (StretchSelBox) /* Release left button = End Selection Box */
  345.                 key = 'M';
  346.           if (DragObject)    /* Release right button = End Drag */
  347.              key = 'D';
  348.           break;
  349.            }
  350.            altkey = bioskey( 2);
  351.         }
  352.      }
  353.      oldbuttons = buttons;
  354.       }
  355.  
  356.       /* drag object(s) */
  357.       if (DragObject)
  358.       {
  359.      BCINT forgetit = FALSE;
  360.  
  361.      if (IsSelected( Selected, CurObject) == FALSE)
  362.         ForgetSelection( &Selected);
  363.      else if (Selected->objnum != CurObject)
  364.      {
  365.         /* current object must be first in the list */
  366.         UnSelectObject( &Selected, CurObject);
  367.         SelectObject( &Selected, CurObject);
  368.      }
  369.      if (Selected == NULL && CurObject >= 0)
  370.      {
  371.         SelectObject( &Selected, CurObject);
  372.         forgetit = TRUE;
  373.      }
  374.      if (Selected)
  375.      {
  376.         if (MoveObjectsToCoords( EditMode, Selected, MAPX( PointerX), MAPY( PointerY), GridScale))
  377.            RedrawMap = TRUE;
  378.         if (forgetit)
  379.            ForgetSelection( &Selected);
  380.      }
  381.      else
  382.      {
  383.         Beep();
  384.         DragObject = FALSE;
  385.      }
  386.       }
  387.       else if (StretchSelBox)
  388.       {
  389.      BCINT x = MAPX( PointerX);
  390.      BCINT y = MAPY( PointerY);
  391.  
  392.      /* draw selection box */
  393.      SetColor( CYAN);
  394.      setwritemode( XOR_PUT);
  395.      DrawMapLine( SelBoxX, SelBoxY, SelBoxX, y);
  396.      DrawMapLine( SelBoxX, y, x, y);
  397.      DrawMapLine( x, y, x, SelBoxY);
  398.      DrawMapLine( x, SelBoxY, SelBoxX, SelBoxY);
  399.      delay( 50);
  400.      DrawMapLine( SelBoxX, SelBoxY, SelBoxX, y);
  401.      DrawMapLine( SelBoxX, y, x, y);
  402.      DrawMapLine( x, y, x, SelBoxY);
  403.      DrawMapLine( x, SelBoxY, SelBoxX, SelBoxY);
  404.      setwritemode( COPY_PUT);
  405.       }
  406.       else if (!RedrawObj)
  407.       {
  408.      /* check if there is something near the pointer */
  409.      OldObject = CurObject;
  410.      if ((bioskey( 2) & 0x03) == 0x00)  /* no shift keys */
  411.         CurObject = GetCurObject( EditMode, MAPX( PointerX - 4), MAPY( PointerY - 4), MAPX( PointerX + 4), MAPY( PointerY + 4));
  412.      if (CurObject < 0)
  413.         CurObject = OldObject;
  414.       }
  415.  
  416.       /* draw the map */
  417.       if (RedrawMap)
  418.       {
  419.      DrawMap( EditMode, GridScale, GridShown);
  420.      HighlightSelection( EditMode, Selected);
  421.       }
  422.  
  423.       /* highlight the current object and display the information box */
  424.       if (RedrawMap || CurObject != OldObject || RedrawObj)
  425.       {
  426.      RedrawObj = FALSE;
  427.      if (!RedrawMap && OldObject >= 0)
  428.           HighlightObject( EditMode, OldObject, YELLOW);
  429.      if (CurObject != OldObject)
  430.      {
  431.         PlaySound( 50, 10);
  432.         OldObject = CurObject;
  433.      }
  434.      if (CurObject >= 0)
  435.           HighlightObject( EditMode, CurObject, YELLOW);
  436.      if (bioskey( 1)) /* speedup */
  437.         RedrawObj = TRUE;
  438.      else
  439.         DisplayObjectInfo( EditMode, CurObject);
  440.       }
  441.       if (RedrawMap && (FakeCursor || ShowRulers))
  442.       {
  443.      if (UseMouse)
  444.         HideMousePointer();
  445.      DrawPointer( ShowRulers);
  446.      if (UseMouse)
  447.         ShowMousePointer();
  448.       }
  449.  
  450.       /* display the current pointer coordinates */
  451.       if (RedrawMap || PointerX != OldPointerX || PointerY != OldPointerY)
  452.       {
  453.            SetColor( LIGHTGRAY);
  454.            DrawScreenBox( ScrMaxX - 170, 4, ScrMaxX - 50, 12);
  455.            SetColor( BLUE);
  456.            DrawScreenText( ScrMaxX - 170, 4, "%d, %d", MAPX( PointerX), MAPY( PointerY));
  457.            OldPointerX = PointerX;
  458.            OldPointerY = PointerY;
  459.       }
  460.  
  461.       /* the map is up to date */
  462.       RedrawMap = FALSE;
  463.  
  464.       /* get user input */
  465.       if (bioskey( 1) || key)
  466.       {
  467.      if (! key)
  468.      {
  469.         key = bioskey( 0);
  470.         altkey = bioskey( 2);
  471.      }
  472.  
  473.      /* user wants to access the drop-down menus */
  474.      if (altkey & 0x08)    /* if alt is pressed... */
  475.      {
  476.         if ((key & 0xFF00) == 0x2100)       /* Scan code for F */
  477.            key = PullDownMenu( 18, 19,
  478.                               "Save         F2", 0x3C00,    (BCINT) 'S', 1,
  479.                           "Save As ExMx F3", 0x3D00,    (BCINT) 'A', 6,
  480.                           "Print          ", -1,        (BCINT) 'P', -1,
  481.                           "Quit          Q", (BCINT) 'Q', (BCINT) 'Q', 1,
  482.                                  NULL);
  483.         else if ((key & 0xFF00) == 0x1200)  /* Scan code for E */
  484.         {
  485.            key = PullDownMenu( 66, 19,
  486.                           "Copy object(s)      O", (BCINT) 'O', (BCINT) 'C', 1,
  487.                           "Add object        Ins", 0x5200,    (BCINT) 'A', 1,
  488.                    "Delete object(s)  Del", 0x5300,    (BCINT) 'D', 1,
  489.                    ((EditMode == OBJ_VERTEXES) ?
  490.                    NULL :
  491.                    "Preferences        F5"), 0x3F00,   (BCINT) 'P', 1,
  492.                    NULL);
  493.         }
  494.         else if ((key & 0xFF00) == 0x1F00)  /* Scan code for S */
  495.            key = PullDownMenu( 114, 19,
  496.                    "Find/Change       F4", -1,        (BCINT) 'F', -1,
  497.                    "Repeat last find    ", -1,        (BCINT) 'R', -1,
  498.                    "Next object        N", (BCINT) 'N', (BCINT) 'N', 1,
  499.                       "Prev object        P", (BCINT) 'P', (BCINT) 'P', 1,
  500.                         "Jump to object...  J", (BCINT) 'J', (BCINT) 'J', 1,
  501.                    NULL);
  502.         else if ((key & 0xFF00) == 0x3200)  /* Scan code for M */
  503.            key = PullDownMenu( 178, 19,
  504.                    ((EditMode == OBJ_THINGS) ?
  505.                           "√ Things              T" :
  506.                           "  Things              T"), (BCINT) 'T', (BCINT) 'T', 3,
  507.                    ((EditMode == OBJ_LINEDEFS) ?
  508.                    "√ Linedefs+Sidedefs   L" :
  509.                    "  Linedefs+Sidedefs   L"), (BCINT) 'L', (BCINT) 'L', 3,
  510.                    ((EditMode == OBJ_VERTEXES) ?
  511.                    "√ Vertexes            V" :
  512.                    "  Vertexes            V"), (BCINT) 'V', (BCINT) 'V', 3,
  513.                     ((EditMode == OBJ_SECTORS) ?
  514.                    "√ Sectors             S" :
  515.                          "  Sectors             S"), (BCINT) 'S', (BCINT) 'S', 3,
  516.                    "  Next mode         Tab",  0x0009,    (BCINT) 'N', 3,
  517.                          "  Last mode   Shift+Tab",  0x0F00,    (BCINT) 'L', 3,
  518.                    "  3D Preview          3",  (BCINT) '3', (BCINT) '3', -1,
  519.                    NULL);
  520.         else if ((key & 0xFF00) == 0x1700)  /* Scan code for I */
  521.         {
  522.            key = 0;
  523.            /* code duplicated from 'F8' - I hate to do that */
  524.            if (Selected)
  525.           MiscOperations( 234, 19, EditMode, &Selected);
  526.            else
  527.            {
  528.                  if (CurObject >= 0)
  529.              SelectObject( &Selected, CurObject);
  530.           MiscOperations( 234, 19, EditMode, &Selected);
  531.           if (CurObject >= 0)
  532.              UnSelectObject( &Selected, CurObject);
  533.            }
  534.            CurObject = -1;
  535.            DragObject = FALSE;
  536.            StretchSelBox = FALSE;
  537.         }
  538.         else if ((key & 0xFF00) == 0x1800)  /* Scan code for O */
  539.         {
  540.            BCINT savednum, i;
  541.  
  542.            key = 0;
  543.            /* don't want to create the object behind the menu bar... */
  544.            if (PointerY < 20)
  545.            {
  546.                PointerX = ScrCenterX;
  547.           PointerY = ScrCenterY;
  548.            }
  549.            /* code duplicated from 'F9' - I hate to do that */
  550.            savednum = NumLineDefs;
  551.                   InsertStandardObject( 282, 19, MAPX( PointerX), MAPY( PointerY));
  552.            if (NumLineDefs > savednum)
  553.            {
  554.           ForgetSelection( &Selected);
  555.           EditMode = OBJ_LINEDEFS;
  556.           for (i = savednum; i < NumLineDefs; i++)
  557.              SelectObject( &Selected, i);
  558.           CurObject = NumLineDefs - 1;
  559.            OldObject = -1;
  560.                 DragObject = FALSE;
  561.           StretchSelBox = FALSE;
  562.            }
  563.         }
  564.         else if ((key & 0xFF00) == 0x2E00)  /* Scan code for C */
  565.         {
  566.            key = 0;
  567.            CheckLevel( 354, 19);
  568.         }
  569.         else if ((key & 0xFF00) == 0x2300)  /* Scan code for H */
  570.            key = PullDownMenu( ScrMaxX, 19,
  571.                    "  Keyboard & mouse  F1",  0x3B00,    (BCINT) 'K', 3,
  572.                    (InfoShown ?
  573.                    "√ Info bar           I" :
  574.                    "  Info bar           I"), (BCINT) 'I', (BCINT) 'I', 3,
  575.                    "  About DEU...        ",  -1,        (BCINT) 'A', -1,
  576.                    NULL);
  577.         else
  578.         {
  579.            Beep();
  580.            key = 0;
  581.         }
  582.         RedrawMap = TRUE;
  583.      }
  584.  
  585.      /* User wants to do the impossible. */
  586.      if (key == -1)
  587.      {
  588.         NotImplemented();
  589.         RedrawMap = TRUE;
  590.      }
  591.  
  592.      /* simplify the checks later on */
  593.      if (isprint(key & 0x00ff))
  594.         keychar = toupper(key & 0x00ff);
  595.      else
  596.         keychar = '\0';
  597.  
  598.      /* erase the (keyboard) pointer */
  599.      if (FakeCursor || ShowRulers)
  600.      {
  601.         HideMousePointer();
  602.         DrawPointer( ShowRulers);
  603.         ShowMousePointer();
  604.      }
  605.  
  606.      /* user wants to exit */
  607.      if (keychar == 'Q')
  608.      {
  609.         ForgetSelection( &Selected);
  610.         if (CheckStartingPos())
  611.         {
  612.            if (Registered && MadeChanges)
  613.            {
  614.           char *outfile;
  615.  
  616.           outfile = GetWadFileName( episode, mission);
  617.           if (outfile)
  618.           {
  619.              SaveLevelData( outfile);
  620.              break;
  621.           }
  622.            }
  623.            else
  624.           break;
  625.         }
  626.         RedrawMap = TRUE;
  627.      }
  628.      else if ((key & 0x00FF) == 0x001B) /* 'Esc' */
  629.      {
  630.         if (DragObject)
  631.            DragObject = FALSE;                          
  632.         else if (StretchSelBox)
  633.            StretchSelBox = FALSE;
  634.         else
  635.         {
  636.            ForgetSelection( &Selected);
  637.            if (!MadeChanges || Confirm(-1, -1, "You have unsaved changes.  Do you really want to quit?", NULL))
  638.                break;
  639.            RedrawMap = TRUE;
  640.         }
  641.      }
  642.  
  643.      /* user is lost */
  644.      else if ((key & 0xFF00) == 0x3B00) /* 'F1' */
  645.      {
  646.         DisplayHelp( EditMode, GridScale);
  647.         RedrawMap = TRUE;
  648.      }
  649.  
  650.      /* user wants to save the level data */
  651.      else if ((key & 0xFF00) == 0x3C00 && Registered) /* 'F2' */
  652.      {
  653.         char *outfile;
  654.             
  655.             if (CheckStartingPos())
  656.             {
  657.            outfile = GetWadFileName( episode, mission);
  658.            if (outfile)
  659.               SaveLevelData( outfile);
  660.             }
  661.             RedrawMap = TRUE;
  662.         }
  663.  
  664.      /* user wants to save and change the episode and mission numbers */
  665.      else if ((key & 0xFF00) == 0x3D00 && Registered) /* 'F3' */
  666.      {
  667.         char *outfile;
  668.         BCINT e, m;
  669.         MDirPtr newLevel, oldl, newl;
  670.         char name[ 7];
  671.  
  672.         if (CheckStartingPos())
  673.         {
  674.            outfile = GetWadFileName( episode, mission);
  675.            if (outfile)
  676.            {
  677.            e = episode;
  678.            m = mission;
  679.            SelectLevel( &e, &m);
  680.            if (e > 0 && m > 0 && (e != episode || m != mission))
  681.            {
  682.               /* horrible but it works... */
  683.               episode = e;
  684.               mission = m;
  685.               sprintf( name, "E%dM%d", episode, mission);
  686.               newLevel = FindMasterDir( MasterDir, name);
  687.               oldl = Level;
  688.               newl = newLevel;
  689.               for (m = 0; m < 11; m++)
  690.               {
  691.               newl->wadfile = oldl->wadfile;
  692.               if (m > 0)
  693.                  newl->dir = oldl->dir;
  694.               /*
  695.               if (!strcmp( outfile, oldl->wadfile->filename))
  696.               {
  697.                  oldl->wadfile = WadFileList;
  698.                  oldl->dir = lost...
  699.               }
  700.               */
  701.               oldl = oldl->next;
  702.               newl = newl->next;
  703.               }
  704.               Level = newLevel;
  705.            }
  706.            SaveLevelData( outfile);
  707.            }
  708.         }
  709.         RedrawMap = TRUE;
  710.      }
  711.  
  712.         /* user wants to get the 'Preferences' menu */
  713.      else if ((key & 0xFF00) == 0x3F00) /* 'F5' */
  714.      {
  715.         Preferences( -1, -1);
  716.         RedrawMap = TRUE;
  717.      }
  718.      /* user wants to get the menu of misc. ops */
  719.      else if ((key & 0xFF00) == 0x4200) /* 'F8' */
  720.      {
  721.         if (Selected)
  722.            MiscOperations( -1, -1, EditMode, &Selected);
  723.         else
  724.         {
  725.            if (CurObject >= 0)
  726.            SelectObject( &Selected, CurObject);
  727.            MiscOperations( -1, -1, EditMode, &Selected);
  728.            if (CurObject >= 0)
  729.            UnSelectObject( &Selected, CurObject);
  730.         }
  731.         CurObject = -1;
  732.         RedrawMap = TRUE;
  733.         DragObject = FALSE;
  734.         StretchSelBox = FALSE;
  735.      }
  736.  
  737.      /* user wants to insert a standard shape */
  738.      else if ((key & 0xFF00) == 0x4300) /* 'F9' */
  739.      {
  740.         BCINT savednum, i;
  741.  
  742.         savednum = NumLineDefs;
  743.         InsertStandardObject( -1, -1, MAPX( PointerX), MAPY( PointerY));
  744.         if (NumLineDefs > savednum)
  745.         {
  746.            ForgetSelection( &Selected);
  747.            EditMode = OBJ_LINEDEFS;
  748.            for (i = savednum; i < NumLineDefs; i++)
  749.           SelectObject( &Selected, i);
  750.            CurObject = NumLineDefs - 1;
  751.            OldObject = -1;
  752.            DragObject = FALSE;
  753.            StretchSelBox = FALSE;
  754.         }
  755.         RedrawMap = TRUE;
  756.      }
  757.  
  758.      /* user wants to check his level */
  759.      else if ((key & 0xFF00) == 0x4400) /* 'F10' */
  760.      {
  761.         CheckLevel( -1, -1);
  762.         RedrawMap = TRUE;
  763.      }
  764.  
  765.      /* user wants to display/hide the info box */
  766.      else if (keychar == 'I')
  767.      {
  768.         InfoShown = !InfoShown;
  769.         RedrawMap = TRUE;
  770.      }
  771.  
  772.      /* user wants to change the scale */
  773.      else if ((keychar == '+' || keychar == '=') && Scale < 4.0)
  774.      {
  775.         OrigX += (BCINT) ((PointerX - ScrCenterX) / Scale);
  776.         OrigY += (BCINT) ((ScrCenterY - PointerY) / Scale);
  777.         if (Scale < 1.0)
  778.            Scale = 1.0 / ((1.0 / Scale) - 1.0);
  779.         else
  780.            Scale = Scale * 2.0;
  781.         OrigX -= (BCINT) ((PointerX - ScrCenterX) / Scale);
  782.         OrigY -= (BCINT) ((ScrCenterY - PointerY) / Scale);
  783.         RedrawMap = TRUE;
  784.      }
  785.      else if ((keychar == '-' || keychar == '_') && Scale > 0.05)
  786.      {
  787.         OrigX += (BCINT) ((PointerX - ScrCenterX) / Scale);
  788.         OrigY += (BCINT) ((ScrCenterY - PointerY) / Scale);
  789.         if (Scale < 1.0)
  790.            Scale = 1.0 / ((1.0 / Scale) + 1.0);
  791.         else
  792.            Scale = Scale / 2.0;
  793.         OrigX -= (BCINT) ((PointerX - ScrCenterX) / Scale);
  794.         OrigY -= (BCINT) ((ScrCenterY - PointerY) / Scale);
  795.         RedrawMap = TRUE;
  796.      }
  797.  
  798.      /* user wants to set the scale directly */
  799.      else if (keychar >= '0' && keychar <= '9')
  800.      {
  801.         OrigX += (BCINT) ((PointerX - ScrCenterX) / Scale);
  802.         OrigY += (BCINT) ((ScrCenterY - PointerY) / Scale);
  803.         if (keychar == '0')
  804.            Scale = 0.1;
  805.         else
  806.            Scale = 1.0 / (keychar - '0');
  807.         OrigX -= (BCINT) ((PointerX - ScrCenterX) / Scale);
  808.         OrigY -= (BCINT) ((ScrCenterY - PointerY) / Scale);
  809.         RedrawMap = TRUE;
  810.      }
  811.  
  812.      /* user wants to move */
  813.      else if ((key & 0xFF00) == 0x4800 && (PointerY - MoveSpeed) >= 0)
  814.      {
  815.         if (UseMouse)
  816.            SetMouseCoords( PointerX, PointerY - MoveSpeed);
  817.         else
  818.            PointerY -= MoveSpeed;
  819.      }
  820.      else if ((key & 0xFF00) == 0x5000 && (PointerY + MoveSpeed) <= ScrMaxY)
  821.      {
  822.         if (UseMouse)
  823.            SetMouseCoords( PointerX, PointerY + MoveSpeed);
  824.         else
  825.            PointerY += MoveSpeed;
  826.      }
  827.      else if ((key & 0xFF00) == 0x4B00 && (PointerX - MoveSpeed) >= 0)
  828.      {
  829.         if (UseMouse)
  830.            SetMouseCoords( PointerX - MoveSpeed, PointerY);
  831.         else
  832.            PointerX -= MoveSpeed;
  833.      }
  834.      else if ((key & 0xFF00) == 0x4D00 && (PointerX + MoveSpeed) <= ScrMaxX)
  835.      {
  836.         if (UseMouse)
  837.            SetMouseCoords( PointerX + MoveSpeed, PointerY);
  838.         else
  839.            PointerX += MoveSpeed;
  840.      }
  841.  
  842.      /* user wants so scroll the map */
  843.      else if ((key & 0xFF00) == 0x4900 && MAPY( ScrCenterY) < MapMaxY)
  844.      {
  845.         OrigY += (BCINT) (ScrCenterY / Scale);
  846.         RedrawMap = TRUE;
  847.      }
  848.      else if ((key & 0xFF00) == 0x5100 && MAPY( ScrCenterY) > MapMinY)
  849.      {
  850.         OrigY -= (BCINT) (ScrCenterY / Scale);
  851.         RedrawMap = TRUE;
  852.      }
  853.      else if ((key & 0xFF00) == 0x4700 && MAPX( ScrCenterX) > MapMinX)
  854.      {
  855.         OrigX -= (BCINT) (ScrCenterX / Scale);
  856.         RedrawMap = TRUE;
  857.      }
  858.      else if ((key & 0xFF00) == 0x4F00 && MAPX( ScrCenterX) < MapMaxX)
  859.      {
  860.         OrigX += (BCINT) (ScrCenterX / Scale);
  861.         RedrawMap = TRUE;
  862.      }
  863.  
  864.      /* user wants to change the movement speed */
  865.      else if (keychar == ' ')
  866.         MoveSpeed = MoveSpeed == 1 ? 20 : 1;
  867.  
  868.      /* user wants to change the edit mode */
  869.      else if ((key & 0x00FF) == 0x0009 || (key & 0xFF00) == 0x0F00 || keychar == 'T' || keychar == 'V' || keychar == 'L' || keychar == 'S')
  870.      {
  871.         BCINT   PrevMode = EditMode;
  872.         SelPtr NewSel;
  873.  
  874.         if ((key & 0x00FF) == 0x0009) /* 'Tab' */
  875.         {
  876.            switch (EditMode)
  877.            {
  878.            case OBJ_THINGS:
  879.           EditMode = OBJ_VERTEXES;
  880.                  break;
  881.            case OBJ_VERTEXES:
  882.                EditMode = OBJ_LINEDEFS;
  883.           break;
  884.            case OBJ_LINEDEFS:
  885.           EditMode = OBJ_SECTORS;
  886.           break;
  887.            case OBJ_SECTORS:
  888.           EditMode = OBJ_THINGS;
  889.                 break;
  890.            }
  891.         }
  892.         else if ((key & 0xFF00) == 0x0F00) /* 'Shift-Tab' */
  893.         {
  894.            switch (EditMode)
  895.            {
  896.            case OBJ_THINGS:
  897.           EditMode = OBJ_SECTORS;
  898.           break;
  899.            case OBJ_VERTEXES:
  900.                 EditMode = OBJ_THINGS;
  901.                  break;
  902.            case OBJ_LINEDEFS:
  903.                 EditMode = OBJ_VERTEXES;
  904.                 break;
  905.            case OBJ_SECTORS:
  906.                 EditMode = OBJ_LINEDEFS;
  907.                 break;
  908.            }
  909.         }
  910.         else 
  911.             {
  912.                if (keychar == 'T')
  913.               EditMode = OBJ_THINGS;
  914.            else if (keychar == 'V')
  915.               EditMode = OBJ_VERTEXES;
  916.            else if (keychar == 'L')
  917.               EditMode = OBJ_LINEDEFS;
  918.            else if (keychar == 'S')
  919.               EditMode = OBJ_SECTORS;
  920.                ForgetSelection( &Selected);
  921.             }
  922.  
  923.          /* special cases for the selection list... */
  924.         if (Selected)
  925.         {
  926.            /* select all LineDefs bound to the selected Sectors */
  927.            if (PrevMode == OBJ_SECTORS && EditMode == OBJ_LINEDEFS)
  928.            {
  929.           int l, sd;
  930.  
  931.           ObjectsNeeded( OBJ_LINEDEFS, OBJ_SIDEDEFS, 0);
  932.           NewSel = NULL;
  933.           for (l = 0; l < NumLineDefs; l++)
  934.           {
  935.              sd = LineDefs[ l].sidedef1;
  936.              if (sd >= 0 && IsSelected( Selected, SideDefs[ sd].sector))
  937.             SelectObject( &NewSel, l);
  938.              else
  939.              {
  940.             sd = LineDefs[ l].sidedef2;
  941.             if (sd >= 0 && IsSelected( Selected, SideDefs[ sd].sector))
  942.                SelectObject( &NewSel, l);
  943.              }
  944.           }
  945.           ForgetSelection( &Selected);
  946.           Selected = NewSel;
  947.            }
  948.            /* select all Vertices bound to the selected LineDefs */
  949.            else if (PrevMode == OBJ_LINEDEFS && EditMode == OBJ_VERTEXES)
  950.            {
  951.           ObjectsNeeded( OBJ_LINEDEFS, 0);
  952.           NewSel = NULL;
  953.           while (Selected)
  954.           {
  955.              if (!IsSelected( NewSel, LineDefs[ Selected->objnum].start))
  956.             SelectObject( &NewSel, LineDefs[ Selected->objnum].start);
  957.              if (!IsSelected( NewSel, LineDefs[ Selected->objnum].end))
  958.             SelectObject( &NewSel, LineDefs[ Selected->objnum].end);
  959.              UnSelectObject( &Selected, Selected->objnum);
  960.           }
  961.           Selected = NewSel;
  962.            }
  963.            /* select all Sectors that have their LineDefs selected */
  964.            else if (PrevMode == OBJ_LINEDEFS && EditMode == OBJ_SECTORS)
  965.            {
  966.           int l, sd;
  967.  
  968.           ObjectsNeeded( OBJ_LINEDEFS, OBJ_SIDEDEFS, 0);
  969.           NewSel = NULL;
  970.           /* select all Sectors... */
  971.           for (l = 0; l < NumSectors; l++)
  972.              SelectObject( &NewSel, l);
  973.           /* ... then unselect those that should not be in the list */
  974.           for (l = 0; l < NumLineDefs; l++)
  975.              if (!IsSelected( Selected, l))
  976.              {
  977.             sd = LineDefs[ l].sidedef1;
  978.             if (sd >= 0)
  979.                UnSelectObject( &NewSel, SideDefs[ sd].sector);
  980.             sd = LineDefs[ l].sidedef2;
  981.             if (sd >= 0)
  982.                UnSelectObject( &NewSel, SideDefs[ sd].sector);
  983.              }
  984.           ForgetSelection( &Selected);
  985.           Selected = NewSel;
  986.            }
  987.            /* select all LineDefs that have both ends selected */
  988.            else if (PrevMode == OBJ_VERTEXES && EditMode == OBJ_LINEDEFS)
  989.            {
  990.           int l;
  991.  
  992.           ObjectsNeeded( OBJ_LINEDEFS, 0);
  993.           NewSel = NULL;
  994.           for (l = 0; l < NumLineDefs; l++)
  995.              if (IsSelected( Selected, LineDefs[ l].start) && IsSelected( Selected, LineDefs[ l].end))
  996.             SelectObject( &NewSel, l);
  997.           ForgetSelection( &Selected);
  998.           Selected = NewSel;
  999.            }
  1000.            /* unselect all */
  1001.            else
  1002.           ForgetSelection( &Selected);
  1003.         }
  1004.         if (GetMaxObjectNum( EditMode) >= 0 && Select0 == TRUE)
  1005.            CurObject = 0;
  1006.         else
  1007.            CurObject = -1;
  1008.         OldObject = -1;
  1009.         DragObject = FALSE;
  1010.         StretchSelBox = FALSE;
  1011.         RedrawMap = TRUE;
  1012.      }
  1013.  
  1014.      /* user wants to change the grid scale */
  1015.      else if (keychar == 'G')
  1016.      {
  1017.         if ((altkey & 0x03) == 0x00)  /* no shift keys */
  1018.         {
  1019.            if (GridScale == 0)
  1020.               GridScale = 256;
  1021.            else if (GridScale > 8)
  1022.           GridScale /= 2;
  1023.            else
  1024.           GridScale = 0;
  1025.         }
  1026.         else
  1027.         {
  1028.            if (GridScale == 0)
  1029.               GridScale = 8;
  1030.            else if (GridScale < 256)
  1031.               GridScale *= 2;
  1032.            else
  1033.               GridScale = 0;
  1034.         }
  1035.         RedrawMap = TRUE;
  1036.      }
  1037.      else if (keychar == 'H')
  1038.      {  
  1039.             if ((altkey & 0x03) != 0x00)  /* shift key pressed */
  1040.                GridScale = 0;
  1041.         else
  1042.                GridShown = !GridShown;
  1043.         RedrawMap = TRUE;
  1044.      }
  1045.  
  1046.      /* user wants to toggle the rulers */
  1047.      else if (keychar == 'R')
  1048.         ShowRulers = !ShowRulers;
  1049.  
  1050.      /* user wants to toggle drag mode */
  1051.      else if (keychar == 'D')
  1052.      {
  1053.         StretchSelBox = FALSE;
  1054.         if (DragObject)
  1055.         {
  1056.            DragObject = FALSE;
  1057.            if (EditMode == OBJ_VERTEXES)
  1058.            {
  1059.           if (Selected == NULL && CurObject >= 0)
  1060.                {
  1061.              SelectObject( &Selected, CurObject);
  1062.              if (AutoMergeVertices( &Selected))
  1063.             RedrawMap = TRUE;
  1064.              ForgetSelection( &Selected);
  1065.           }
  1066.           else
  1067.              if (AutoMergeVertices( &Selected))
  1068.             RedrawMap = TRUE;
  1069.            }
  1070.            else if (EditMode == OBJ_LINEDEFS)
  1071.            {
  1072.           SelPtr NewSel, cur;
  1073.  
  1074.           ObjectsNeeded( OBJ_LINEDEFS, 0);
  1075.           NewSel = NULL;
  1076.           if (Selected == NULL && CurObject >= 0)
  1077.           {
  1078.              SelectObject( &NewSel, LineDefs[ CurObject].start);
  1079.              SelectObject( &NewSel, LineDefs[ CurObject].end);
  1080.           }
  1081.           else
  1082.           {
  1083.              for (cur = Selected; cur; cur = cur->next)
  1084.              {
  1085.             if (!IsSelected( NewSel, LineDefs[ cur->objnum].start))
  1086.                SelectObject( &NewSel, LineDefs[ cur->objnum].start);
  1087.             if (!IsSelected( NewSel, LineDefs[ cur->objnum].end))
  1088.                SelectObject( &NewSel, LineDefs[ cur->objnum].end);
  1089.              }
  1090.           }
  1091.           if (AutoMergeVertices( &NewSel))
  1092.              RedrawMap = TRUE;
  1093.           ForgetSelection( &NewSel);
  1094.            }
  1095.         }
  1096.         else
  1097.         {
  1098.            DragObject = TRUE;
  1099.            if (EditMode == OBJ_THINGS && CurObject >= 0)
  1100.           MoveObjectsToCoords( EditMode, NULL, Things[ CurObject].xpos, Things[ CurObject].ypos, 0);
  1101.            else if (EditMode == OBJ_VERTEXES && CurObject >= 0)
  1102.           MoveObjectsToCoords( EditMode, NULL, Vertexes[ CurObject].x, Vertexes[ CurObject].y, 0);
  1103.            else
  1104.           MoveObjectsToCoords( EditMode, NULL, MAPX( PointerX), MAPY( PointerY), GridScale);
  1105.         }
  1106.           }
  1107.  
  1108.          /* user wants to select the next or previous object */
  1109.      else if (keychar == 'N' || keychar == '>')
  1110.      {
  1111.         if (CurObject < GetMaxObjectNum( EditMode))
  1112.           CurObject++;
  1113.         else if (GetMaxObjectNum( EditMode) >= 0)
  1114.           CurObject = 0;
  1115.         else
  1116.           CurObject = -1;
  1117.         RedrawMap = TRUE;
  1118.      }
  1119.      else if (keychar == 'P' || keychar == '<')
  1120.      {
  1121.         if (CurObject > 0)
  1122.            CurObject--;
  1123.         else
  1124.            CurObject = GetMaxObjectNum( EditMode);
  1125.         RedrawMap = TRUE;
  1126.      }
  1127.      else if (keychar == 'J' || keychar == '#')
  1128.      {
  1129.         OldObject = InputObjectNumber( -1, -1, EditMode, CurObject);
  1130.         if (OldObject >= 0)
  1131.         {
  1132.            CurObject = OldObject;
  1133.            GoToObject( EditMode, CurObject);
  1134.         }
  1135.         else
  1136.            OldObject = CurObject;
  1137.         RedrawMap = TRUE;
  1138.      }
  1139.  
  1140.      /* user wants to mark/unmark an object or a group of objects */
  1141.      else if (keychar == 'M')
  1142.      {
  1143.         if (StretchSelBox)
  1144.         {
  1145.            SelPtr oldsel;
  1146.  
  1147.            /* select all objects in the selection box */
  1148.            StretchSelBox = FALSE;
  1149.            RedrawMap = TRUE;
  1150.            /* additive selection box or not? */
  1151.            if (AdditiveSelBox == FALSE)
  1152.           ForgetSelection( &Selected);
  1153.            else
  1154.           oldsel = Selected;
  1155.            Selected = SelectObjectsInBox( EditMode, SelBoxX, SelBoxY, MAPX( PointerX), MAPY( PointerY));
  1156.            if (AdditiveSelBox == TRUE)
  1157.           while (oldsel != NULL)
  1158.                  {
  1159.              if (! IsSelected( Selected, oldsel->objnum))
  1160.             SelectObject( &Selected, oldsel->objnum);
  1161.              UnSelectObject( &oldsel, oldsel->objnum);
  1162.           }
  1163.            if (Selected)
  1164.            {
  1165.           CurObject = Selected->objnum;
  1166.               PlaySound( 440, 10);
  1167.            }
  1168.            else
  1169.           CurObject = -1;
  1170.         }
  1171.         else if ((altkey & 0x03) == 0x00)  /* no shift keys */
  1172.         {
  1173.            if (CurObject >= 0)
  1174.            {
  1175.           /* mark or unmark one object */
  1176.           if (IsSelected( Selected, CurObject))
  1177.              UnSelectObject( &Selected, CurObject);
  1178.           else
  1179.              SelectObject( &Selected, CurObject);
  1180.           HighlightObject( EditMode, CurObject, GREEN);
  1181.           if (Selected)
  1182.              PlaySound( 440, 10);
  1183.           DragObject = FALSE;
  1184.            }
  1185.            else
  1186.           Beep();
  1187.         }
  1188.         else
  1189.         {
  1190.            /* begin "stretch selection box" mode */
  1191.            SelBoxX = MAPX( PointerX);
  1192.            SelBoxY = MAPY( PointerY);
  1193.            StretchSelBox = TRUE;
  1194.            DragObject = FALSE;
  1195.         }
  1196.      }
  1197.  
  1198.      /* user wants to clear all marks and redraw the map */
  1199.      else if (keychar == 'C')
  1200.      {
  1201.         ForgetSelection( &Selected);
  1202.         RedrawMap = TRUE;
  1203.         DragObject = FALSE;
  1204.         StretchSelBox = FALSE;
  1205.      }
  1206.  
  1207.      /* user wants to copy a group of objects */
  1208.      else if (keychar == 'O' && CurObject >= 0)
  1209.      {
  1210.         /* copy the object(s) */
  1211.         if (Selected == NULL)
  1212.            SelectObject( &Selected, CurObject);
  1213.         CopyObjects( EditMode, Selected);
  1214.         /* enter drag mode */
  1215.         DragObject = TRUE;
  1216.         CurObject = Selected->objnum;
  1217.         if (EditMode == OBJ_THINGS)
  1218.            MoveObjectsToCoords( EditMode, NULL, Things[ CurObject].xpos, Things[ CurObject].ypos, 0);
  1219.         else if (EditMode == OBJ_VERTEXES)
  1220.            MoveObjectsToCoords( EditMode, NULL, Vertexes[ CurObject].x, Vertexes[ CurObject].y, 0);
  1221.         else
  1222.            MoveObjectsToCoords( EditMode, NULL, MAPX( PointerX), MAPY( PointerY), GridScale);
  1223.         RedrawMap = TRUE;
  1224.         StretchSelBox = FALSE;
  1225.      }
  1226.  
  1227.      /* user wants to edit the current object */
  1228.      else if ((key & 0x00FF) == 0x000D && CurObject >= 0) /* 'Enter' */
  1229.      {
  1230.         if (Selected)
  1231.            EditObjectsInfo( 0, 30, EditMode, Selected);
  1232.         else
  1233.         {
  1234.            SelectObject( &Selected, CurObject);
  1235.            EditObjectsInfo( 0, 30, EditMode, Selected);
  1236.            UnSelectObject( &Selected, CurObject);
  1237.         }
  1238.         RedrawMap = TRUE;
  1239.         DragObject = FALSE;
  1240.         StretchSelBox = FALSE;
  1241.      }
  1242.  
  1243.      /* user wants to delete the current object */
  1244.      else if ((key & 0xFF00) == 0x5300 && CurObject >= 0) /* 'Del' */
  1245.      {
  1246.         if (EditMode == OBJ_THINGS || Expert || Confirm( -1, -1,
  1247.                 (Selected ? "Do you really want to delete these objects?" : "Do you really want to delete this object?"),
  1248.                 (Selected ? "This will also delete the objects bound to them." : "This will also delete the objects bound to it.")))
  1249.         {
  1250.            if (Selected)
  1251.           DeleteObjects( EditMode, &Selected);
  1252.            else
  1253.           DeleteObject( EditMode, CurObject);
  1254.            CurObject = -1;
  1255.         }
  1256.         DragObject = FALSE;
  1257.         StretchSelBox = FALSE;
  1258.         RedrawMap = TRUE;
  1259.      }
  1260.  
  1261.      /* user wants to insert a new object */
  1262.      else if ((key & 0xFF00) == 0x5200) /* 'Ins' */
  1263.      {
  1264.         SelPtr cur;
  1265.  
  1266.         /* first special case: if several Vertices are selected, add new LineDefs */
  1267.         if (EditMode == OBJ_VERTEXES && Selected != NULL && Selected->next != NULL)
  1268.         {
  1269.            BCINT firstv;
  1270.  
  1271.            ObjectsNeeded( OBJ_LINEDEFS, 0);
  1272.            if (Selected->next->next != NULL)
  1273.           firstv = Selected->objnum;
  1274.            else
  1275.           firstv = -1;
  1276.            EditMode = OBJ_LINEDEFS;
  1277.            /* create LineDefs between the Vertices */
  1278.            for (cur = Selected; cur->next; cur = cur->next)
  1279.            {
  1280.           /* check if there is already a LineDef between the two Vertices */
  1281.           for (CurObject = 0; CurObject < NumLineDefs; CurObject++)
  1282.              if ((LineDefs[ CurObject].start == cur->next->objnum && LineDefs[ CurObject].end == cur->objnum)
  1283.               || (LineDefs[ CurObject].end == cur->next->objnum && LineDefs[ CurObject].start == cur->objnum))
  1284.             break;
  1285.           if (CurObject < NumLineDefs)
  1286.              cur->objnum = CurObject;
  1287.           else
  1288.           {
  1289.              InsertObject( OBJ_LINEDEFS, -1, 0, 0);
  1290.              CurObject = NumLineDefs - 1;
  1291.              LineDefs[ CurObject].start = cur->next->objnum;
  1292.                     LineDefs[ CurObject].end = cur->objnum;
  1293.              cur->objnum = CurObject;
  1294.           }
  1295.            }
  1296.            /* close the polygon if there are more than 2 Vertices */
  1297.            if (firstv >= 0 && (altkey & 0x03) != 0x00)  /* shift key pressed */
  1298.            {
  1299.           for (CurObject = 0; CurObject < NumLineDefs; CurObject++)
  1300.              if ((LineDefs[ CurObject].start == firstv && LineDefs[ CurObject].end == cur->objnum)
  1301.               || (LineDefs[ CurObject].end == firstv && LineDefs[ CurObject].start == cur->objnum))
  1302.             break;
  1303.           if (CurObject < NumLineDefs)
  1304.              cur->objnum = CurObject;
  1305.           else
  1306.           {
  1307.                     InsertObject( OBJ_LINEDEFS, -1, 0, 0);
  1308.              CurObject = NumLineDefs - 1;
  1309.              LineDefs[ CurObject].start = firstv;
  1310.              LineDefs[ CurObject].end = cur->objnum;
  1311.              cur->objnum = CurObject;
  1312.           }
  1313.            }
  1314.            else
  1315.                  UnSelectObject( &Selected, cur->objnum);
  1316.         }
  1317.         /* second special case: if several LineDefs are selected, add new SideDefs and one Sector */
  1318.         else if (EditMode == OBJ_LINEDEFS && Selected != NULL)
  1319.         {
  1320.            ObjectsNeeded( OBJ_LINEDEFS, 0);
  1321.            for (cur = Selected; cur; cur = cur->next)
  1322.           if (LineDefs[ cur->objnum].sidedef1 >= 0 && LineDefs[ cur->objnum].sidedef2 >= 0)
  1323.           {
  1324.              char msg[ 80];
  1325.  
  1326.              Beep();
  1327.              sprintf( msg, "LineDef #%d already has two SideDefs", cur->objnum);
  1328.              Notify( -1, -1, "Error: cannot add the new Sector", msg);
  1329.              break;
  1330.           }
  1331.            if (cur == NULL)
  1332.            {
  1333.           EditMode = OBJ_SECTORS;
  1334.           InsertObject( OBJ_SECTORS, -1, 0, 0);
  1335.           CurObject = NumSectors - 1;
  1336.           for (cur = Selected; cur; cur = cur->next)
  1337.           {
  1338.                     InsertObject( OBJ_SIDEDEFS, -1, 0, 0);
  1339.              SideDefs[ NumSideDefs - 1].sector = CurObject;
  1340.              ObjectsNeeded( OBJ_LINEDEFS, OBJ_SIDEDEFS, 0);
  1341.                  if (LineDefs[ cur->objnum].sidedef1 >= 0)
  1342.              {
  1343.             BCINT s;
  1344.  
  1345.             s = SideDefs[ LineDefs[ cur->objnum].sidedef1].sector;
  1346.             if (s >= 0)
  1347.             {
  1348.                Sectors[ CurObject].floorh = Sectors[ s].floorh;
  1349.                Sectors[ CurObject].ceilh = Sectors[ s].ceilh;
  1350.                strncpy( Sectors[ CurObject].floort, Sectors[ s].floort, 8);
  1351.                strncpy( Sectors[ CurObject].ceilt, Sectors[ s].ceilt, 8);
  1352.                Sectors[ CurObject].light = Sectors[ s].light;
  1353.                    }
  1354.             LineDefs[ cur->objnum].sidedef2 = NumSideDefs - 1;
  1355.             LineDefs[ cur->objnum].flags = 4;
  1356.             strncpy( SideDefs[ NumSideDefs - 1].tex3, "-", 8);
  1357.             strncpy( SideDefs[ LineDefs[ cur->objnum].sidedef1].tex3, "-", 8);
  1358.              }
  1359.              else
  1360.                    LineDefs[ cur->objnum].sidedef1 = NumSideDefs - 1;
  1361.           }
  1362.           ForgetSelection( &Selected);
  1363.           SelectObject( &Selected, CurObject);
  1364.            }
  1365.         }
  1366.         /* normal case: add a new object of the current type */
  1367.         else
  1368.         {
  1369.            ForgetSelection( &Selected);
  1370.            if (GridScale > 0)
  1371.           InsertObject( EditMode, CurObject, (BCINT) ((int)(MAPX( PointerX) + GridScale / 2)) & ((int)(~(GridScale - 1))), (BCINT) ((int)(MAPY( PointerY) + GridScale / 2)) & (int)(~(GridScale - 1)));
  1372.            else
  1373.           InsertObject( EditMode, CurObject, MAPX( PointerX), MAPY( PointerY));
  1374.            CurObject = GetMaxObjectNum( EditMode);
  1375.            if (EditMode == OBJ_LINEDEFS)
  1376.            {
  1377.           if (! Input2VertexNumbers( -1, -1, "Choose the two vertices for the new LineDef",
  1378.                              &(LineDefs[ CurObject].start), &(LineDefs[ CurObject].end)))
  1379.                  {
  1380.                     DeleteObject( EditMode, CurObject);
  1381.                     CurObject = -1;
  1382.                  }
  1383.            }
  1384.                  else if (EditMode == OBJ_VERTEXES)
  1385.                {
  1386.            SelectObject( &Selected, CurObject);
  1387.            if (AutoMergeVertices( &Selected))
  1388.               RedrawMap = TRUE;
  1389.            ForgetSelection( &Selected);
  1390.             }
  1391.         }
  1392.         DragObject = FALSE;
  1393.         StretchSelBox = FALSE;
  1394.         RedrawMap = TRUE;
  1395.      }
  1396.  
  1397.      /* user likes music */
  1398.      else if (key)
  1399.         Beep();
  1400.  
  1401.      /* redraw the (keyboard) pointer */
  1402.      if (FakeCursor || ShowRulers)
  1403.      {
  1404.         HideMousePointer();
  1405.         DrawPointer( ShowRulers);
  1406.         ShowMousePointer();
  1407.      }
  1408.       }
  1409.  
  1410.       /* check if Scroll Lock is off */
  1411.       if ((bioskey( 2) & 0x10) == 0x00)
  1412.       {
  1413.      /* move the map if the pointer is near the edge of the screen */
  1414.      if (PointerY <= (UseMouse ? 2 : 20))
  1415.      {
  1416.         if (! UseMouse)
  1417.            PointerY += MoveSpeed;
  1418.         if (MAPY( ScrCenterY) < MapMaxY)
  1419.         {                                   
  1420.            OrigY += (BCINT) (MoveSpeed * 2.0 / Scale);
  1421.            RedrawMap = TRUE;
  1422.         }
  1423.      }
  1424.      if (PointerY >= ScrMaxY - (UseMouse ? 8 : 20))
  1425.      {
  1426.         if (! UseMouse)
  1427.            PointerY -= MoveSpeed;
  1428.         if (MAPY( ScrCenterY) > MapMinY)
  1429.         {
  1430.            OrigY -= (BCINT) (MoveSpeed * 2.0 / Scale);
  1431.            RedrawMap = TRUE;
  1432.         }
  1433.      }
  1434.      if (PointerX <= (UseMouse ? 8 : 20))
  1435.      {
  1436.         if (! UseMouse)   
  1437.            PointerX += MoveSpeed;
  1438.         if (MAPX( ScrCenterX) > MapMinX)
  1439.         {
  1440.            OrigX -= (BCINT) (MoveSpeed * 2.0 / Scale);
  1441.            RedrawMap = TRUE;
  1442.         }
  1443.      }
  1444.      if (PointerX >= ScrMaxX - (UseMouse ? 8 : 20))
  1445.      {
  1446.         if (! UseMouse)
  1447.            PointerX -= MoveSpeed;
  1448.         if (MAPX( ScrCenterX) < MapMaxX)
  1449.         {
  1450.            OrigX += (BCINT) (MoveSpeed * 2.0 / Scale);
  1451.            RedrawMap = TRUE;
  1452.         }
  1453.      }
  1454.       }
  1455.    }
  1456. }
  1457.  
  1458.  
  1459.  
  1460. /*
  1461.    draw the actual game map                            
  1462. */
  1463.  
  1464. void DrawMap( BCINT editmode, BCINT grid, Bool drawgrid) /* SWAP! */
  1465. {
  1466.    BCINT  n, m;
  1467.  
  1468.    /* clear the screen */
  1469.    ClearScreen();
  1470.  
  1471.    /* draw the grid */
  1472.    if (drawgrid == TRUE && grid > 0)
  1473.    {                       
  1474.       BCINT mapx0 = (BCINT)(((int)MAPX( 0)) & ((int)~(grid - 1)));
  1475.       BCINT mapx1 = (BCINT)(((int)(MAPX( ScrMaxX) + grid)) & ((int)~(grid - 1)));
  1476.       BCINT mapy0 = (BCINT)(((int)(MAPY( ScrMaxY) - grid)) & ((int)~(grid - 1)));
  1477.       BCINT mapy1 = (BCINT)(((int)MAPY( 0)) & ((int)~(grid - 1)));
  1478.  
  1479.       SetColor( BLUE);
  1480.       for (n = mapx0; n <= mapx1; n += grid)
  1481.      DrawMapLine( n, mapy0, n, mapy1);
  1482.       for (n = mapy0; n <= mapy1; n += grid)
  1483.      DrawMapLine( mapx0, n, mapx1, n);
  1484.    }
  1485.  
  1486.    /* draw the linedefs to form the map */
  1487.    switch (editmode)
  1488.    {
  1489.    case OBJ_THINGS:
  1490.       ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1491.       for (n = 0; n < NumLineDefs; n++)
  1492.       {
  1493.      if (LineDefs[ n].flags & 1)
  1494.         SetColor( WHITE);
  1495.      else
  1496.         SetColor( LIGHTGRAY);
  1497.      DrawMapLine( Vertexes[ LineDefs[ n].start].x, Vertexes[ LineDefs[ n].start].y,
  1498.               Vertexes[ LineDefs[ n].end].x, Vertexes[ LineDefs[ n].end].y);
  1499.       }
  1500.       break;
  1501.    case OBJ_VERTEXES:
  1502.       ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1503.       SetColor( LIGHTGRAY);
  1504.       for (n = 0; n < NumLineDefs; n++)
  1505.      DrawMapVector( Vertexes[ LineDefs[ n].start].x, Vertexes[ LineDefs[ n].start].y,
  1506.             Vertexes[ LineDefs[ n].end].x, Vertexes[ LineDefs[ n].end].y);
  1507.       break;
  1508.    case OBJ_LINEDEFS:
  1509.       ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1510.       for (n = 0; n < NumLineDefs; n++)
  1511.       {
  1512.      if (LineDefs[ n].type > 0)
  1513.      {
  1514.         if (LineDefs[ n].tag > 0)
  1515.            SetColor( LIGHTMAGENTA);
  1516.         else
  1517.            SetColor( LIGHTGREEN);
  1518.      }
  1519.      else if (LineDefs[ n].tag > 0)
  1520.         SetColor( LIGHTRED);
  1521.      else if (LineDefs[ n].flags & 1)
  1522.         SetColor( WHITE);
  1523.      else
  1524.         SetColor( LIGHTGRAY);
  1525.      DrawMapLine( Vertexes[ LineDefs[ n].start].x, Vertexes[ LineDefs[ n].start].y,
  1526.               Vertexes[ LineDefs[ n].end].x, Vertexes[ LineDefs[ n].end].y);
  1527.       }
  1528.       break;
  1529.    case OBJ_SECTORS:
  1530.       ObjectsNeeded( OBJ_LINEDEFS, OBJ_SIDEDEFS, 0);
  1531.       for (n = 0; n < NumLineDefs; n++)
  1532.       {
  1533.      if ((m = LineDefs[ n].sidedef1) < 0 || (m = SideDefs[ m].sector) < 0)
  1534.         SetColor( LIGHTRED);
  1535.      else
  1536.      {
  1537.         if (Sectors[ m].tag > 0)
  1538.            SetColor( LIGHTGREEN);
  1539.         else if (Sectors[ m].special > 0)
  1540.            SetColor( LIGHTCYAN);
  1541.         else if (LineDefs[ n].flags & 1)
  1542.            SetColor( WHITE);
  1543.         else
  1544.            SetColor( LIGHTGRAY);
  1545.         if ((m = LineDefs[ n].sidedef2) >= 0)
  1546.         {
  1547.            if ((m = SideDefs[ m].sector) < 0)
  1548.           SetColor( LIGHTRED);
  1549.            else if (Sectors[ m].tag > 0)
  1550.           SetColor( LIGHTGREEN);
  1551.            else if (Sectors[ m].special > 0)
  1552.           SetColor( LIGHTCYAN);
  1553.         }
  1554.      }
  1555.      ObjectsNeeded( OBJ_LINEDEFS, OBJ_VERTEXES, 0);
  1556.      DrawMapLine( Vertexes[ LineDefs[ n].start].x, Vertexes[ LineDefs[ n].start].y,
  1557.               Vertexes[ LineDefs[ n].end].x, Vertexes[ LineDefs[ n].end].y);
  1558.       }
  1559.       break;
  1560.    }
  1561.  
  1562.    /* draw in the vertices */
  1563.    if (editmode == OBJ_VERTEXES)
  1564.    {
  1565.       SetColor( LIGHTGREEN);
  1566.       for (n = 0; n < NumVertexes; n++)
  1567.       {
  1568.      DrawMapLine( Vertexes[ n].x - OBJSIZE, Vertexes[ n].y - OBJSIZE, Vertexes[ n].x + OBJSIZE, Vertexes[ n].y + OBJSIZE);
  1569.      DrawMapLine( Vertexes[ n].x + OBJSIZE, Vertexes[ n].y - OBJSIZE, Vertexes[ n].x - OBJSIZE, Vertexes[ n].y + OBJSIZE);
  1570.       }
  1571.    }
  1572.  
  1573.    /* draw in the things */
  1574.    ObjectsNeeded( OBJ_THINGS, 0);
  1575.    if (editmode == OBJ_THINGS)
  1576.    {
  1577.       for (n = 0; n < NumThings; n++)
  1578.       {
  1579.      m = GetThingRadius( Things[ n].type);
  1580.      SetColor( GetThingColour( Things[ n].type));
  1581.      DrawMapLine( Things[ n].xpos - m, Things[ n].ypos, Things[ n].xpos + m, Things[ n].ypos);
  1582.      DrawMapLine( Things[ n].xpos, Things[ n].ypos - m, Things[ n].xpos, Things[ n].ypos + m);
  1583.      DrawMapCircle( Things[ n].xpos, Things[ n].ypos, m);
  1584.       }
  1585.    }
  1586.    else
  1587.    {
  1588.       SetColor( LIGHTGRAY);
  1589.       for (n = 0; n < NumThings; n++)
  1590.       {
  1591.      DrawMapLine( Things[ n].xpos - OBJSIZE, Things[ n].ypos, Things[ n].xpos + OBJSIZE, Things[ n].ypos);
  1592.      DrawMapLine( Things[ n].xpos, Things[ n].ypos - OBJSIZE, Things[ n].xpos, Things[ n].ypos + OBJSIZE);
  1593.       }
  1594.    }
  1595.  
  1596.    /* draw in the title bar */
  1597.    DrawScreenBox3D( 0, 0, ScrMaxX, 16);
  1598.    SetColor( WHITE);
  1599.    DrawScreenText( 20,  4, "File  Edit  Search  Modes  Misc  Objects  Check");
  1600.    DrawScreenText( 20,  6, "_     _     _       _       _    _        _    ");
  1601.    DrawScreenText( ScrMaxX - 45, 4, "Help");
  1602.    DrawScreenText( ScrMaxX - 45, 6, "_   ");
  1603.  
  1604.    /* draw the bottom line, if needed */
  1605.    if (InfoShown)
  1606.    {
  1607.       DrawScreenBox3D( 0, ScrMaxY - 11, ScrMaxX, ScrMaxY);
  1608.       if (MadeMapChanges == TRUE)
  1609.         DrawScreenText( 5, ScrMaxY - 8, "Editing %s on %s #", GetEditModeName( editmode), Level->dir.name);
  1610.       else if (MadeChanges == TRUE)
  1611.            DrawScreenText( 5, ScrMaxY - 8, "Editing %s on %s *", GetEditModeName( editmode), Level->dir.name);
  1612.       else
  1613.           DrawScreenText( 5, ScrMaxY - 8, "Editing %s on %s", GetEditModeName( editmode), Level->dir.name);
  1614.       if (Scale < 1.0)
  1615.           DrawScreenText( ScrMaxX - 176, ScrMaxY - 8, "Scale: 1/%d  Grid: %d", (BCINT) (1.0 / Scale + 0.5), grid);
  1616.       else
  1617.      DrawScreenText( ScrMaxX - 176, ScrMaxY - 8, "Scale: %d/1  Grid: %d", (BCINT) Scale, grid);
  1618.       if (farcoreleft() < 50000L)
  1619.       {
  1620.      if (farcoreleft() < 20000L)
  1621.         SetColor( LIGHTRED);
  1622.      else
  1623.         SetColor( RED);
  1624.       }
  1625.       DrawScreenText( ScrCenterX - ((editmode == OBJ_LINEDEFS) ? 10 : 50), ScrMaxY - 8, "Free mem: %lu", farcoreleft());
  1626.    }
  1627. }
  1628.  
  1629.  
  1630.  
  1631. /*
  1632.    center the map around the given coords
  1633. */
  1634.  
  1635. void CenterMapAroundCoords( BCINT xpos, BCINT ypos)
  1636. {
  1637.    OrigX = xpos;
  1638.    OrigY = ypos;
  1639.    PointerX = ScrCenterX;
  1640.    PointerY = ScrCenterY;
  1641. }
  1642.  
  1643.  
  1644.  
  1645. /*
  1646.    center the map around the object and zoom in if necessary
  1647. */
  1648.  
  1649. void GoToObject( BCINT objtype, BCINT objnum) /* SWAP! */
  1650. {
  1651.    BCINT xpos, ypos;
  1652.    BCINT xpos2, ypos2;
  1653.    BCINT n;
  1654.    BCINT sd1, sd2;
  1655.    float oldscale;
  1656.  
  1657.    GetObjectCoords( objtype, objnum, &xpos, &ypos);
  1658.    CenterMapAroundCoords( xpos, ypos);
  1659.    oldscale = Scale;
  1660.  
  1661.    /* zoom in until the object can be selected */
  1662.    while (Scale < 4.0 && GetCurObject( objtype, MAPX( PointerX - 4), MAPY( PointerY - 4), MAPX( PointerX + 4), MAPY( PointerY + 4)) != objnum)
  1663.    {
  1664.        if (Scale < 1.0)
  1665.       Scale = 1.0 / ((1.0 / Scale) - 1.0);
  1666.        else
  1667.       Scale = Scale * 2.0;
  1668.    }
  1669.    /* Special case for Sectors: if several Sectors are one inside another, then     */
  1670.    /* zooming in on the center won't help.  So I choose a LineDef that borders the  */
  1671.    /* the Sector and move a few pixels towards the inside of the Sector.            */
  1672.    if (objtype == OBJ_SECTORS && GetCurObject( OBJ_SECTORS, OrigX, OrigY, OrigX, OrigY) != objnum)
  1673.    {
  1674.       /* restore the Scale */
  1675.       Scale = oldscale;
  1676.       for (n = 0; n < NumLineDefs; n++)
  1677.       {
  1678.      ObjectsNeeded( OBJ_LINEDEFS, 0);
  1679.      sd1 = LineDefs[ n].sidedef1;
  1680.      sd2 = LineDefs[ n].sidedef2;
  1681.      ObjectsNeeded( OBJ_SIDEDEFS, 0);
  1682.      if (sd1 >= 0 && SideDefs[ sd1].sector == objnum)
  1683.         break;
  1684.      if (sd2 >= 0 && SideDefs[ sd2].sector == objnum)
  1685.         break;
  1686.       }
  1687.       if (n < NumLineDefs)
  1688.       {
  1689.      GetObjectCoords( OBJ_LINEDEFS, n, &xpos2, &ypos2);
  1690.      n = ComputeDist( abs( xpos - xpos2), abs( ypos - ypos2)) / 7;
  1691.      if (n <= 1)
  1692.        n = 2;
  1693.      xpos = xpos2 + (xpos - xpos2) / n;
  1694.      ypos = ypos2 + (ypos - ypos2) / n;
  1695.      CenterMapAroundCoords( xpos, ypos);
  1696.      /* zoom in until the sector can be selected */
  1697.      while (Scale > 4.0 && GetCurObject( OBJ_SECTORS, OrigX, OrigY, OrigX, OrigY) != objnum)
  1698.       {
  1699.          if (Scale < 1.0)
  1700.             Scale = 1.0 / ((1.0 / Scale) - 1.0);
  1701.          else
  1702.             Scale = Scale / 2.0;
  1703.       }
  1704.       }
  1705.    }
  1706.    if (UseMouse)
  1707.       SetMouseCoords( PointerX, PointerY);
  1708. }
  1709.  
  1710.  
  1711.  
  1712. /* end of file */
  1713.