home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / dr2v41b1.zip / SMESSAGE.C < prev   
C/C++ Source or Header  |  1994-09-29  |  4KB  |  122 lines

  1. /*********************************************************************
  2. *     SMESSAGE.C -- Sample Doors/2 source code.  This is the default *
  3. *                   function used to display an internode message to *
  4. *                   the user.  It does the following:                *
  5. *                                                                    *
  6. *                   (a) Saves a rectangular region of the screen,    *
  7. *                   (b) Draws a rectangular text box on the screen,  *
  8. *                   (c) Displays the message in the text box,        *
  9. *                   (d) Waits for the user to hit {Enter}, and       *
  10. *                   (e) Redraws the screen region overwritten.       *
  11. *                                                                    *
  12. *                   This source is provided in the unregistered      *
  13. *                   version in case you wish to try writing your     *
  14. *                   own message-handling function.                   *
  15. *                                                                    *
  16. *  Author:     Joel Downer                Date:     5/94             *
  17. **********************************************************************/
  18.  
  19. /* Determines the space required to display message. */
  20.  
  21. void CalcSize(tInternodeMsg *Message, int *top, int *left,
  22.    int *bottom, int *right);
  23.  
  24. void od_show_message(tInternodeMsg *Message)
  25.    {
  26.    char *savescreen;
  27.    int savex, savey;
  28.    int top;
  29.    int left;
  30.    int bottom;
  31.    int right;
  32.    int between_size;
  33.    int screensize;
  34.    char ans;
  35.    char save_delimiter = od_control.od_colour_delimiter;
  36.  
  37.    int row;
  38.  
  39.    /* Zero-length messages -- like door status messages -- shouldn't be
  40.       displayed. */
  41.  
  42.    if (strlen(Message->text) == 0)
  43.       return;
  44.  
  45.    /* Because a different function is used to handle messages in chat, this
  46.       function shouldn't display chat messages. */
  47.  
  48.    if (Message->event == EVT_CHAT_MSG)
  49.       return;
  50.  
  51.    /* How big a box do we need to display this message? */
  52.    CalcSize(Message, &top, &left, &bottom, &right);
  53.  
  54.    between_size = (right - left) - 1;
  55.    screensize = 2 * (bottom - top + 1) * (right - left + 1);
  56.  
  57.    if ((savescreen = malloc(screensize)) == NULL)
  58.       return;
  59.  
  60.    od_save_screen(savescreen, &savex, &savey, left, top, right, bottom);
  61.  
  62.    od_set_colour(L_WHITE, D_BLUE);
  63.  
  64.    od_set_cursor(top, left);
  65.    od_putch(od_control.od_box_chars[0]);
  66.    od_repeat(od_control.od_box_chars[1], between_size);
  67.    od_putch(od_control.od_box_chars[2]);
  68.  
  69.    for (row = top + 1; row < bottom; ++row)
  70.       {
  71.       od_set_cursor(row, left);
  72.       od_putch(od_control.od_box_chars[3]);
  73.       od_repeat(' ', between_size);
  74.       od_putch(od_control.od_box_chars[3]);
  75.       }
  76.  
  77.    od_set_cursor(bottom, left);
  78.    od_putch(od_control.od_box_chars[4]);
  79.    od_repeat(od_control.od_box_chars[1], between_size);
  80.    od_putch(od_control.od_box_chars[5]);
  81.  
  82.    /* If you have changed the color delimiter from '`' (e.g., to prevent
  83.       users from entering color strings on an
  84.  
  85.       od_input_str(str, len, 32, 127);
  86.  
  87.       call and corrupting the display), this code insures that "`bright
  88.       cyan on blue`" won't be displayed to the user in lieu of a color
  89.       change. */
  90.  
  91.    od_control.od_colour_delimiter = 'ç';
  92.  
  93.    if (Message->from_player)
  94.       {
  95.       od_set_cursor(top + 1, left + 2);
  96.       od_printf("çbright cyan on blueçReceived from çbright white on blueç%s"
  97.          "çbright cyan on blueç on node çbright white on blueç%d"
  98.          "çbright cyan on blueç:", Message->name,
  99.          Message->source_node);
  100.  
  101.       od_set_cursor(top + 3, left + 2);
  102.       }
  103.    else
  104.       od_set_cursor(top + 2, left + 2);
  105.  
  106.    od_printf("çbright white on blueç%s", Message->text);
  107.  
  108.    od_set_cursor(top + 4, left + 2);
  109.    od_printf("çbright cyan on blueçHit \'çbright white on blueçEnter"
  110.       "çbright cyan on blueç\' to continue.");
  111.  
  112.    do {
  113.       ans = od_get_key(TRUE);
  114.       } while (ans != '\r');
  115.  
  116.    /* Restoring old color delimiter now... */
  117.    od_control.od_colour_delimiter = save_delimiter;
  118.  
  119.    od_restore_screen(savescreen, &savex, &savey, left, top, right, bottom);
  120.    free(savescreen);
  121.    }
  122.