Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

ODDrBox.c 5.92 KB
Newer Older
rswindell's avatar
rswindell committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* OpenDoors Online Software Programming Toolkit
 * (C) Copyright 1991 - 1999 by Brian Pirie.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
Deucе's avatar
Deucе committed
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
rswindell's avatar
rswindell committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 *
 *
 *        File: ODDrBox.c
 *
 * Description: Implements the od_draw_box() function.
 *
 *   Revisions: Date          Ver   Who  Change
 *              ---------------------------------------------------------------
 *              Oct 13, 1994  6.00  BP   New file header format.
 *              Dec 09, 1994  6.00  BP   Standardized coding style.
 *              Aug 19, 1995  6.00  BP   32-bit portability.
 *              Nov 16, 1995  6.00  BP   Removed oddoor.h, added odcore.h.
 *              Dec 12, 1995  6.00  BP   Added entry, exit and kernel macros.
 *              Dec 30, 1995  6.00  BP   Added ODCALL for calling convention.
 *              Feb 19, 1996  6.00  BP   Changed version number to 6.00.
 *              Mar 03, 1996  6.10  BP   Begin version 6.10.
33
 *              Aug 10, 2003  6.23  SH   *nix support
rswindell's avatar
rswindell committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
 */

#define BUILDING_OPENDOORS

#include "OpenDoor.h"
#include "ODCore.h"
#include "ODGen.h"
#include "ODKrnl.h"


/* ----------------------------------------------------------------------------
 * od_draw_box()
 *
 * Draws a box on the local and remote screens, using the box characters
 * specified in od_control.od_box_chars. Unlike the window functions, this
 * function does not store the original contents of the screen where the box
 * is drawn.
 *
 * Parameters: btLeft   - Column number of the left side of the box.
 *
 *             btTop    - Row number of the top side of the box.
 *
 *             btRight  - Column number of hte right side of the box.
 *
 *             btBottom - Row number of the bottom side of the box.
 *
 *     Return: TRUE on success, or FALSE on failure.
 */
ODAPIDEF BOOL ODCALL od_draw_box(BYTE btLeft, BYTE btTop, BYTE btRight,
   BYTE btBottom)
{
   /* Number of current line being drawn. */
   BYTE btLine;

   /* X size of window. */
   BYTE btBetweenSize = (btRight - btLeft) - 1;

   /* Log function entry if running in trace mode */
   TRACE(TRACE_API, "od_draw_box()");

   /* Ensure that OpenDoors has been initialized */
   if(!bODInitialized) od_init();

   OD_API_ENTRY();

   /* Setup od_box_chars appropriately */
   if(od_control.od_box_chars[BOX_BOTTOM] == 0)
   {
      od_control.od_box_chars[BOX_BOTTOM] = od_control.od_box_chars[BOX_TOP];
   }
   if(od_control.od_box_chars[BOX_RIGHT] == 0)
   {
      od_control.od_box_chars[BOX_RIGHT] = od_control.od_box_chars[BOX_LEFT];
   }

   /* Check that required display capabilities are supported. */
   if(!(od_control.user_ansi || od_control.user_avatar))
   {
      od_control.od_error = ERR_NOGRAPHICS;
      OD_API_EXIT();
      return(FALSE);
   }

   /* Check that parameters are within valid range. */
   if(btLeft<1 || btTop<1 || btRight>80 || btBottom>25)
   {
      od_control.od_error = ERR_PARAMETER;
      OD_API_EXIT();
      return(FALSE);
   }

   /* Move to top corner, if needed. */
   od_set_cursor(btTop, btLeft);

   /* Display left corner character. */
   od_putch(od_control.od_box_chars[BOX_UPPERLEFT]);

   /* Display top line. */
   od_repeat(od_control.od_box_chars[BOX_TOP], btBetweenSize);

   /* Display right corner character. */
   od_putch(od_control.od_box_chars[BOX_UPPERRIGHT]);

   /* If AVATAR display mode is available. */
   if(od_control.user_avatar)                    
   {
      /* Display first left vertical line. */
      od_set_cursor(btTop + 1, btLeft);
      od_putch(od_control.od_box_chars[BOX_LEFT]);

      /* Fill in the center of the window. */
      od_emulate(22);
      od_emulate(12);
      od_emulate((BYTE)od_control.od_cur_attrib);
      od_emulate((BYTE)((btBottom - btTop) - 1));
      od_emulate(btBetweenSize);

      /* Display first right vertical line. */
      od_set_cursor(btTop + 1, btRight);
      od_putch(od_control.od_box_chars[BOX_RIGHT]);

      /* Display remaining vertical lines. */
      for(btLine = btTop + 2; btLine < btBottom; ++btLine)
      {
         /* Move to the start of the line. */
         od_set_cursor(btLine, btLeft);

         /* Display left line character. */
         od_putch(od_control.od_box_chars[BOX_LEFT]);

         /* Move to line start. */
         od_set_cursor(btLine, btRight);

         /* Display right line character. */
         od_putch(od_control.od_box_chars[BOX_RIGHT]);
      }
   }

   /* If AVATAR mode is not available. */
   else
   {
      /* Loop through middle lines of window. */
      for(btLine = btTop + 1; btLine < btBottom; ++btLine)
      {
         /* Move to the start of the line. */
         od_set_cursor(btLine,btLeft);

         /* Display left line character. */
         od_putch(od_control.od_box_chars[BOX_LEFT]);

         /* Display the blank area. */
         od_repeat(' ', btBetweenSize);

         /* Display the right line character. */
         od_putch(od_control.od_box_chars[BOX_RIGHT]);
      }
   }

   /* Move to bottom corner. */
   od_set_cursor(btBottom, btLeft);

   /* Display left corner character. */
   od_putch(od_control.od_box_chars[BOX_LOWERLEFT]);

   /* Display bottom line. */
   od_repeat(od_control.od_box_chars[BOX_BOTTOM], btBetweenSize);

   /* Display right corner character. */
   od_putch(od_control.od_box_chars[BOX_LOWERRIGHT]);

   /* Return with success. */
   OD_API_EXIT();
   return(TRUE);
}