home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_messa.prg < prev    next >
Text File  |  1993-10-14  |  4KB  |  179 lines

  1. /*
  2.     File......: GT_Message.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Martin Bryant
  7.     Date......: 04/02/93
  8.     Revision..: 1.0
  9.  
  10.     This is an original work by Martin Bryant and is placed
  11.     in the public domain.
  12.  
  13.     Modification history:
  14.     ---------------------
  15.  
  16.     Rev 1.0 04/02/93
  17.     PD Revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_MESSAGE()
  23.  *  $CATEGORY$
  24.  *      Video
  25.  *  $ONELINER$
  26.  *      Display a message in a box on the screen
  27.  *  $SYNTAX$
  28.  *      GT_Message(<cText>,[<cTitle>],[<cColour>], ;
  29.  *                 [<cBoxLines>],[<nTop>],[<nLeft>],[<nBottom>], ;
  30.  *                 [<nRight>]) => lSuccess
  31.  *  $ARGUMENTS$
  32.  *      <cText> is the message to display.
  33.  *
  34.  *      <cTitle> is an optional title for the box.
  35.  *
  36.  *      <cColour> is an optional colour string.
  37.  *
  38.  *      <cBoxLines> are the optional box lines to use.
  39.  *
  40.  *      <nTop>,<nLeft>,<nBottom>,<nRight> are the
  41.  *      corners of the box. As many or  as few of these may
  42.  *      be used as required. The default is to centre the
  43.  *      message.
  44.  *  $RETURNS$
  45.  *      .T. / .F. based on the success.
  46.  *  $DESCRIPTION$
  47.  *      Display a message in a box on the screen
  48.  *  $EXAMPLES$
  49.  *      // Message centered on the screen
  50.  *      GT_Message('Hello?')
  51.  *
  52.  *      // Fix top left
  53.  *      GT_Message('Hello?',NIL,NIL,NIL,05,10)
  54.  *  $SEEALSO$
  55.  *
  56.  *  $INCLUDE$
  57.  *
  58.  *  $END$
  59.  */
  60.  
  61. #include "GT_LIB.ch"
  62.  
  63. #define MINIMUM     36
  64. #define BIAS        2.3
  65.  
  66. FUNCTION GT_Message(cText,cTitle,cSetColour,cBoxLines, ;
  67.     nTop,nLeft,nBottom,nRight)
  68.  
  69. LOCAL cColour := SETCOLOR()
  70. LOCAL cLine := ''
  71. LOCAL nColumns := 0
  72. LOCAL nCount := 0
  73. LOCAL nCharCount := 0
  74. LOCAL nFarRight := 0
  75. LOCAL nFarBottom := 0
  76. LOCAL nLineCount := 0
  77.  
  78. Default cText to ''
  79. Default cTitle to ''
  80. Default cSetColour to SETCOLOR()
  81. Default cBoxLines to BOX_SS
  82. Default nTop to -1
  83. Default nLeft to -1
  84. Default nBottom to -1
  85. Default nRight to -1
  86.  
  87. //  How many ?
  88. nCharCount := LEN(cText)
  89.  
  90. //  Sort out columns
  91. nColumns := IF(nCharCount<MINIMUM, ;
  92.     nCharCount, ;
  93.     ROUND(SQRT(nCharCount)*BIAS,0)) + 03
  94.  
  95. //  Far right position
  96. nFarRight := IF(nRight<0,INT((MAXCOL()+nColumns)/2),nRight)
  97.  
  98. DO CASE
  99.     CASE nLeft >= 0 .AND. nRight >= 0
  100.         // Both defined
  101.  
  102.     CASE nLeft >= 0
  103.         // Set right
  104.         nRight := nLeft + nColumns
  105.  
  106.     CASE nRight >=  0
  107.         // Set left
  108.         nLeft := nRight - nColumns
  109.  
  110.     OTHERWISE
  111.         // Set both
  112.         nRight := nFarRight
  113.         nLeft := nRight - nColumns
  114.  
  115. ENDCASE
  116.  
  117. //  Legal Values ?
  118. IF nLeft < 0
  119.     nLeft := 0
  120. ENDIF
  121. IF nRight > nFarRight
  122.     nRight := nFarRight
  123. ENDIF
  124.  
  125. //  Reset columns and lines
  126. nColumns := nRight - nLeft - 03
  127. nLineCount := MLCOUNT(cText,nColumns)
  128. nFarBottom := IF(nBottom<0,INT((MAXROW()+nLineCount)/2), ;
  129.     nBottom)
  130.  
  131. DO CASE
  132.     CASE nTop >= 0 .AND. nBottom >= 0
  133.         // Set Neither
  134.  
  135.     CASE nTop >= 0
  136.         // Set bottom
  137.         nBottom := nTop + nLineCount + 01
  138.  
  139.     CASE nBottom >= 0
  140.         // Set top
  141.         nTop := nBottom - nLineCount - 01
  142.  
  143.     OTHERWISE
  144.         // Set both
  145.         nBottom := nFarBottom
  146.         nTop := nBottom - nLineCount - 01
  147.  
  148. ENDCASE
  149.  
  150. //  Set limits
  151. IF nTop < 0
  152.     nTop := 0
  153. ENDIF
  154. IF nBottom > nFarBottom
  155.     nBottom := nFarBottom
  156. ENDIF
  157.  
  158. // Draw box
  159. GT_Window(nTop,nLeft,nBottom,nRight,cBoxLines,cSetColour, ;
  160.     cTitle)
  161.  
  162. //  Move left 2
  163. nLeft += 02
  164.  
  165. //  Draw text
  166. SETCOLOR(cSetColour)
  167. FOR nCount := 1 TO nLineCount
  168.     // Draw each line
  169.     cLine := PADC(RTRIM(MEMOLINE(cText,nColumns,nCount)), ;
  170.         nColumns)
  171.     @ nTop+nCount, nLeft SAY cLine
  172. NEXT
  173. SETCOLOR(cColour)
  174.  
  175. /*
  176.     End of GT_Message()
  177. */
  178. RETURN(.T.)
  179.