home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1998 July / pcx23_9807.iso / PC-XUSER / PC-XUSER.16 / ABC / SCREEN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-02  |  5.1 KB  |  247 lines

  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <malloc.h>
  5. #include "keydef.h"
  6.  
  7. char keret[4][8]={"┌─┐│┘─└│",
  8.          "╔═╗║╝═╚║",
  9.          "┌─┐│┘─└│",        //ugyanaz mint az elso ketto
  10.          "╔═╗║╝═╚║"};        //atirando
  11.  
  12. #define SELECTEDCOL BLUE
  13. #define SELECTEDBCK WHITE
  14. #define NORMALCOL   WHITE
  15. #define NORMALBCK   CYAN
  16.  
  17.  
  18.  
  19. void screeninit(void)
  20. {
  21.  directvideo=1;            //nem a BIOS on keresztul cammog
  22.  _wscroll=0;               //nem gorgeti a kepernyot, ha az utoso sorba ertunk
  23.  textbackground(BLUE);
  24.  clrscr();
  25. }
  26.  
  27. void screentitle(char *title)
  28. {
  29.  int x;
  30.  struct text_info ti;
  31.  
  32.  gettextinfo(&ti);
  33.  textcolor(RED);
  34.  textbackground(LIGHTGRAY);
  35.  gotoxy(1,1);
  36.  for(x=0;x<40-strlen(title)/2;x++) cprintf(" ");
  37.  cprintf("%s",title);
  38.  for(;x<79;x++) cprintf(" ");
  39.  textattr(ti.attribute);
  40. }
  41.  
  42. void screenhelp(char *helptxt)
  43. {
  44.  int x;
  45.  struct text_info ti;
  46.  
  47.  gettextinfo(&ti);
  48.  textbackground(CYAN);
  49.  textcolor(BLACK);
  50.  gotoxy(1,24);
  51.  for (x=0;x<80;x++) cprintf(" ");
  52.  gotoxy(1,25);
  53.  for (x=0;x<80;x++) cprintf(" ");
  54.  gotoxy(1,24);
  55.  cprintf(helptxt);
  56.  textattr(ti.attribute);
  57. }
  58.  
  59. void ablak(int x1,int y1,int x2,int y2,char *cim,int type)
  60. {
  61.  int x,y;
  62.  
  63.  for(y=y1;y<y2;y++)
  64.  {
  65.   gotoxy(x1,y);
  66.   for(x=x1;x<x2;x++) cprintf(" ");
  67.  }
  68.  
  69.  gotoxy(x1,y1);putch(keret[type][0]);
  70.  for(x=x1+1;x<x2;x++) {gotoxy(x,y1);putch(keret[type][1]);}
  71.  gotoxy(x2,y1);putch(keret[type][2]);
  72.  for(x=y1+1;x<y2;x++) {gotoxy(x2,x);putch(keret[type][3]);}
  73.  gotoxy(x2,y2);putch(keret[type][4]);
  74.  gotoxy(x1,y2);putch(keret[type][6]);
  75.  for(x=x1+1;x<x2;x++) {gotoxy(x,y2);putch(keret[type][5]);}
  76.  gotoxy(x1,y1);
  77.  for(x=y1+1;x<y2;x++) {gotoxy(x1,x);putch(keret[type][7]);}
  78.  
  79.  gotoxy((x1+x2)/2-strlen(cim)/2,y1);
  80.  cprintf("%s",cim);
  81. }
  82.  
  83. int linedit(int cx,int cy,char *str)
  84. {
  85.  int x=0,y,l,ex=0;
  86.  char c;
  87.  
  88.  l=strlen(str);
  89. // x=l;
  90.  
  91.  do
  92.  {
  93.   gotoxy(cx,cy);cprintf("%s",str);
  94.   gotoxy(cx+x,cy);
  95.   c=getch();
  96.   switch(c)
  97.   {
  98.    case 0: c=getch();
  99.        switch(c)
  100.        {
  101.         case RIGHT: if (x<l-1) x++; break;
  102.         case LEFT: if (x>0) x--; break;
  103.         case UP:   ex=1; break;
  104.         case DOWN: ex=1; break;
  105.         case DEL:  memmove(str+x,str+x+1,l-x);str[l-1]=' ';break;
  106. //            case INS:
  107.        }
  108.        break;
  109.    case BS: if (x>0) {x--;memmove(str+x,str+x+1,l-x);str[l-1]=' ';} break;
  110.    case ESC:   ex=1; break;
  111.    case ENTER: ex=1; break;
  112.    default: if (x<l-1)
  113.         {
  114.           memmove(str+x+1,str+x,l-x);str[x]=c;str[l]=0;x++;
  115.         }
  116.         break;
  117.   }  //switch
  118.  } while(!ex);
  119.  fflush(stdin);
  120.  return(c);
  121. }
  122.  
  123. int edtwin(int x1, int y1, int x2, int y2 , char *cim, int n, char *label1, char *str1, ...)
  124. {
  125.  int t,c;
  126.  struct text_info ti;
  127.  char *bck;
  128.  
  129.  gettextinfo(&ti);    //eredeti allapot
  130.  bck=(char *)malloc((x2-x1+1)*(y2-y1+1)*2);
  131.  gettext(x1,y1,x2,y2,bck);
  132.  
  133.  textbackground(NORMALBCK);
  134.  textcolor(NORMALCOL);
  135.  
  136.  ablak(x1,y1,x2,y2,cim,0);  //keret
  137.  
  138.  for(t=0;t<n;t++)                  //kirak
  139.  {
  140.   gotoxy(x1+1,y1+t+1);
  141.   cprintf("%s",*(&label1+2*t));
  142.   cprintf("%s",*(&str1+2*t));
  143.  }
  144.  
  145.  t=0;
  146.  do                       //mozog
  147.  {
  148.   textbackground(SELECTEDBCK);
  149.   textcolor(SELECTEDCOL);
  150.   c=linedit(x1+strlen(*(&label1+2*t))+1,y1+t+1,*(&str1+2*t));     //edital
  151.   textbackground(NORMALBCK);
  152.   textcolor(NORMALCOL);
  153.   gotoxy(x1+strlen(*(&label1+2*t))+1,y1+t+1);
  154.   cprintf("%s",*(&str1+2*t));
  155.   switch(c)
  156.   {
  157.    case UP: if (t>0) t--; break;
  158.    case DOWN: if (t<n-1) t++; break;
  159.   }
  160.  } while (c!=ESC && c!=ENTER);
  161.  
  162.  puttext(x1,y1,x2,y2,bck);
  163.  free(bck);
  164.  
  165.  return(c==ENTER);
  166. }
  167.  
  168. int mnuwin(int x1, int y1, int x2, int y2 , char *cim, int n, char *mnu1, ...)
  169. {
  170.  int t,c;
  171.  struct text_info ti;
  172.  char *bck;
  173.  
  174.  _setcursortype(_NOCURSOR);
  175.  
  176.  gettextinfo(&ti);    //eredeti allapot
  177.  bck=(char *)malloc((x2-x1+1)*(y2-y1+1)*2);
  178.  gettext(x1,y1,x2,y2,bck);
  179.  
  180.  textbackground(NORMALBCK);
  181.  textcolor(NORMALCOL);
  182.  
  183.  ablak(x1,y1,x2,y2,cim,0);  //keret
  184.  
  185.  for(t=0;t<n;t++)                  //kirak
  186.  {
  187.   gotoxy((x1+x2)/2-strlen(*(&mnu1+t))/2,y1+t+1);
  188.   cprintf("%s",*(&mnu1+t));
  189.  }
  190.  
  191.  t=0;
  192.  do                       //mozog
  193.  {
  194.   textbackground(SELECTEDBCK);
  195.   textcolor(SELECTEDCOL);
  196.   gotoxy((x1+x2)/2-strlen(*(&mnu1+t))/2,y1+t+1);
  197.   cprintf("%s",*(&mnu1+t));
  198.   c=getch();
  199.   textbackground(NORMALBCK);
  200.   textcolor(NORMALCOL);
  201.   gotoxy((x1+x2)/2-strlen(*(&mnu1+t))/2,y1+t+1);
  202.   cprintf("%s",*(&mnu1+t));
  203.   if (c==0)
  204.   {
  205.    c=getch();
  206.    switch(c)
  207.    {
  208.     case UP: if (t>0) t--; break;
  209.     case DOWN: if (t<n-1) t++; break;
  210.    }
  211.   }
  212.  } while (c!=ESC && c!=ENTER);
  213.  if (c==ESC) t=-1;
  214.  fflush(stdin);
  215.  puttext(x1,y1,x2,y2,bck);
  216.  free(bck);
  217.  _setcursortype(_NORMALCURSOR);
  218.  return(t);
  219. }
  220.  
  221. void msgwin(char *msg)
  222. {
  223.  int x1,y1=10,x2,y2=12;
  224.  char *bck;
  225.  struct text_info ti;
  226.  
  227.  x1=39-strlen(msg)/2;
  228.  x2=41+strlen(msg)/2;
  229.  
  230.  _setcursortype(_NOCURSOR);
  231.  
  232.  gettextinfo(&ti);    //eredeti allapot
  233.  bck=(char *)malloc((x2-x1+1)*(y2-y1+1)*2);
  234.  gettext(x1,y1,x2,y2,bck);
  235.  
  236.  ablak(x1,y1,x2,y2,"",1);
  237.  gotoxy(x1+1,11);
  238.  cprintf("%s",msg);
  239.  getch();
  240.  gotoxy(ti.curx,ti.cury);
  241.  
  242.  puttext(x1,y1,x2,y2,bck);
  243.  free(bck);
  244.  fflush(stdin);
  245.  
  246.  _setcursortype(_NORMALCURSOR);
  247. }