ODDrBox.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* OpenDoors Online Software Programming Toolkit
  2. * (C) Copyright 1991 - 1999 by Brian Pirie.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. *
  19. * File: ODDrBox.c
  20. *
  21. * Description: Implements the od_draw_box() function.
  22. *
  23. * Revisions: Date Ver Who Change
  24. * ---------------------------------------------------------------
  25. * Oct 13, 1994 6.00 BP New file header format.
  26. * Dec 09, 1994 6.00 BP Standardized coding style.
  27. * Aug 19, 1995 6.00 BP 32-bit portability.
  28. * Nov 16, 1995 6.00 BP Removed oddoor.h, added odcore.h.
  29. * Dec 12, 1995 6.00 BP Added entry, exit and kernel macros.
  30. * Dec 30, 1995 6.00 BP Added ODCALL for calling convention.
  31. * Feb 19, 1996 6.00 BP Changed version number to 6.00.
  32. * Mar 03, 1996 6.10 BP Begin version 6.10.
  33. * Aug 10, 2003 6.23 SH *nix support
  34. */
  35. #define BUILDING_OPENDOORS
  36. #include "OpenDoor.h"
  37. #include "ODCore.h"
  38. #include "ODGen.h"
  39. #include "ODKrnl.h"
  40. /* ----------------------------------------------------------------------------
  41. * od_draw_box()
  42. *
  43. * Draws a box on the local and remote screens, using the box characters
  44. * specified in od_control.od_box_chars. Unlike the window functions, this
  45. * function does not store the original contents of the screen where the box
  46. * is drawn.
  47. *
  48. * Parameters: btLeft - Column number of the left side of the box.
  49. *
  50. * btTop - Row number of the top side of the box.
  51. *
  52. * btRight - Column number of hte right side of the box.
  53. *
  54. * btBottom - Row number of the bottom side of the box.
  55. *
  56. * Return: TRUE on success, or FALSE on failure.
  57. */
  58. ODAPIDEF BOOL ODCALL od_draw_box(BYTE btLeft, BYTE btTop, BYTE btRight,
  59. BYTE btBottom)
  60. {
  61. /* Number of current line being drawn. */
  62. BYTE btLine;
  63. /* X size of window. */
  64. BYTE btBetweenSize = (btRight - btLeft) - 1;
  65. /* Log function entry if running in trace mode */
  66. TRACE(TRACE_API, "od_draw_box()");
  67. /* Ensure that OpenDoors has been initialized */
  68. if(!bODInitialized) od_init();
  69. OD_API_ENTRY();
  70. /* Setup od_box_chars appropriately */
  71. if(od_control.od_box_chars[BOX_BOTTOM] == 0)
  72. {
  73. od_control.od_box_chars[BOX_BOTTOM] = od_control.od_box_chars[BOX_TOP];
  74. }
  75. if(od_control.od_box_chars[BOX_RIGHT] == 0)
  76. {
  77. od_control.od_box_chars[BOX_RIGHT] = od_control.od_box_chars[BOX_LEFT];
  78. }
  79. /* Check that required display capabilities are supported. */
  80. if(!(od_control.user_ansi || od_control.user_avatar))
  81. {
  82. od_control.od_error = ERR_NOGRAPHICS;
  83. OD_API_EXIT();
  84. return(FALSE);
  85. }
  86. /* Check that parameters are within valid range. */
  87. if(btLeft<1 || btTop<1 || btRight>80 || btBottom>25)
  88. {
  89. od_control.od_error = ERR_PARAMETER;
  90. OD_API_EXIT();
  91. return(FALSE);
  92. }
  93. /* Move to top corner, if needed. */
  94. od_set_cursor(btTop, btLeft);
  95. /* Display left corner character. */
  96. od_putch(od_control.od_box_chars[BOX_UPPERLEFT]);
  97. /* Display top line. */
  98. od_repeat(od_control.od_box_chars[BOX_TOP], btBetweenSize);
  99. /* Display right corner character. */
  100. od_putch(od_control.od_box_chars[BOX_UPPERRIGHT]);
  101. /* If AVATAR display mode is available. */
  102. if(od_control.user_avatar)
  103. {
  104. /* Display first left vertical line. */
  105. od_set_cursor(btTop + 1, btLeft);
  106. od_putch(od_control.od_box_chars[BOX_LEFT]);
  107. /* Fill in the center of the window. */
  108. od_emulate(22);
  109. od_emulate(12);
  110. od_emulate((BYTE)od_control.od_cur_attrib);
  111. od_emulate((BYTE)((btBottom - btTop) - 1));
  112. od_emulate(btBetweenSize);
  113. /* Display first right vertical line. */
  114. od_set_cursor(btTop + 1, btRight);
  115. od_putch(od_control.od_box_chars[BOX_RIGHT]);
  116. /* Display remaining vertical lines. */
  117. for(btLine = btTop + 2; btLine < btBottom; ++btLine)
  118. {
  119. /* Move to the start of the line. */
  120. od_set_cursor(btLine, btLeft);
  121. /* Display left line character. */
  122. od_putch(od_control.od_box_chars[BOX_LEFT]);
  123. /* Move to line start. */
  124. od_set_cursor(btLine, btRight);
  125. /* Display right line character. */
  126. od_putch(od_control.od_box_chars[BOX_RIGHT]);
  127. }
  128. }
  129. /* If AVATAR mode is not available. */
  130. else
  131. {
  132. /* Loop through middle lines of window. */
  133. for(btLine = btTop + 1; btLine < btBottom; ++btLine)
  134. {
  135. /* Move to the start of the line. */
  136. od_set_cursor(btLine,btLeft);
  137. /* Display left line character. */
  138. od_putch(od_control.od_box_chars[BOX_LEFT]);
  139. /* Display the blank area. */
  140. od_repeat(' ', btBetweenSize);
  141. /* Display the right line character. */
  142. od_putch(od_control.od_box_chars[BOX_RIGHT]);
  143. }
  144. }
  145. /* Move to bottom corner. */
  146. od_set_cursor(btBottom, btLeft);
  147. /* Display left corner character. */
  148. od_putch(od_control.od_box_chars[BOX_LOWERLEFT]);
  149. /* Display bottom line. */
  150. od_repeat(od_control.od_box_chars[BOX_BOTTOM], btBetweenSize);
  151. /* Display right corner character. */
  152. od_putch(od_control.od_box_chars[BOX_LOWERRIGHT]);
  153. /* Return with success. */
  154. OD_API_EXIT();
  155. return(TRUE);
  156. }