home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Zone / VRZONE.ISO / mac / PC / REND386 / DEVEL5 / USERINT.C < prev    next >
C/C++ Source or Header  |  1992-09-21  |  3KB  |  135 lines

  1. /* User interface routines for 3DVIEW */
  2.  
  3. /* Written by Bernie Roehl, January 1992 (broehl@sunee.waterloo.edu) */
  4.  
  5. /* Copyright 1992 by Dave Stampe and Bernie Roehl.
  6.    May be freely used to write software for release into the public domain;
  7.    all commercial endeavours MUST contact Bernie Roehl and Dave Stampe
  8.    for permission to incorporate any part of this software into their
  9.    products!
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <ctype.h>
  14. #include "../include/rend386.h"
  15. #include "../include/userint.h"
  16. #include "../include/pointer.h"
  17. #include "../include/cursor.h"
  18.  
  19. /* Colors */
  20. #define INTERIOR   4
  21. #define TEXT      14
  22.  
  23. #define TEXTHEIGHT 8
  24. #define TEXTWIDTH 8
  25.  
  26. extern int left_page, right_page;
  27. extern PDRIVER *menu_device;
  28.  
  29. void neatbox(int w, int h, int *x, int *y)
  30. {
  31.     extern int v_page;
  32.     *x = (screeninfo->xcent - (w >> 1)) & 0x0FF8;
  33.     *y = screeninfo->ycent - (h >> 1);
  34.     right_page = left_page = v_page; /* stop stereo for now */
  35.     user_box(*x-2, *y-2, *x+w+8, *y+h+8, 0);
  36.     user_box(*x-5, *y-5, *x+w+5, *y+h+5, INTERIOR);
  37. }
  38.  
  39. void poptext(char *text[])
  40. {
  41.     int i, h = 0, w = 0, x, y, page;
  42.     page = cursor_hide();
  43.     for (i = 0; text[i]; ++i) {
  44.         h += TEXTHEIGHT;
  45.         if (strlen(text[i])*TEXTWIDTH > w)
  46.             w = strlen(text[i])*TEXTWIDTH;
  47.     }
  48.     if (w > 300) w = 300;
  49.     neatbox(w , h , &x, &y);
  50.     for (i = 0; text[i]; ++i) {
  51.         user_text(x, y, TEXT, text[i]);
  52.         y += TEXTHEIGHT;
  53.     }
  54.     cursor_show(page);
  55. }
  56.  
  57. int menu(char *text[]) /* returns number (0--n) of entry clicked on */
  58. {
  59.     int i, h = 0, w = 0, x, y, page;
  60.     int top;
  61.     unsigned buttons;
  62.     int num = 0;
  63.     page = cursor_hide();
  64.     for (i = 0; text[i]; ++i)
  65.     {
  66.         h += TEXTHEIGHT;
  67.         if (strlen(text[i])*TEXTWIDTH > w)
  68.             w = strlen(text[i])*TEXTWIDTH;
  69.     }
  70.     if (w > 300) w = 300;
  71.     neatbox(w, h, &x, &y);
  72.     top = y;
  73.     for (i = 0; text[i]; ++i)
  74.     {
  75.         user_text(x, y, TEXT, text[i]);
  76.         y += TEXTHEIGHT;
  77.         num++;
  78.     }
  79.     cursor_show(page);
  80.     do {
  81.         while (move_2D(menu_device, &x, &y, &buttons) == 0);
  82.         do { 
  83.             move_2D(menu_device,&x, &y, &buttons); 
  84.         }
  85.         while (!buttons);
  86.         do { 
  87.             move_2D(menu_device,&x, &y, &buttons); 
  88.         }
  89.         while (buttons);
  90.         i = (y-top) / TEXTHEIGHT;
  91.     }
  92.     while ((i < 0) || (i >= num));
  93.     return(i);
  94. }
  95.  
  96. void popmsg(char *msg)
  97. {
  98.     int x, y, page;
  99.     page = cursor_hide();
  100.     neatbox(strlen(msg)*TEXTWIDTH+16, TEXTHEIGHT+16, &x, &y);
  101.     user_text(x+8, y+8, TEXT, msg);
  102.     cursor_show(page);
  103. }
  104.  
  105. unsigned askfor(char *prompt, char *buff, int n)
  106. {
  107.     unsigned c, page;
  108.     int x, y, i;
  109.  
  110.     page = cursor_hide();
  111.     neatbox(strlen(prompt)*TEXTWIDTH + n * TEXTWIDTH + 10,
  112.     TEXTHEIGHT + 10, &x, &y);
  113.     user_text(x, y, TEXT, prompt);
  114.     x += strlen(prompt) * TEXTWIDTH;
  115.     buff[i = 0] = '\0';
  116.     while ((c = getkey()) != 0x1B)
  117.     {
  118.         if (c == '\r') break;
  119.         if (c == '\b' && i > 0)
  120.         {
  121.             user_box(x, y, x+TEXTWIDTH*strlen(buff), y+TEXTHEIGHT, INTERIOR);
  122.             buff[--i] = '\0';
  123.             user_text(x, y, TEXT,buff);
  124.         }
  125.         if (isprint(c) && i < n)
  126.         {
  127.             buff[i++] = c;
  128.             buff[i] = '\0';
  129.             user_text(x, y, TEXT, buff);
  130.         }
  131.     }
  132.     cursor_show(page);
  133.     return c;
  134. }
  135.