home *** CD-ROM | disk | FTP | other *** search
- #include <conio.h>
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
- #include "keydef.h"
-
- char keret[4][8]={"┌─┐│┘─└│",
- "╔═╗║╝═╚║",
- "┌─┐│┘─└│", //ugyanaz mint az elso ketto
- "╔═╗║╝═╚║"}; //atirando
-
- #define SELECTEDCOL BLUE
- #define SELECTEDBCK WHITE
- #define NORMALCOL WHITE
- #define NORMALBCK CYAN
-
-
-
- void screeninit(void)
- {
- directvideo=1; //nem a BIOS on keresztul cammog
- _wscroll=0; //nem gorgeti a kepernyot, ha az utoso sorba ertunk
- textbackground(BLUE);
- clrscr();
- }
-
- void screentitle(char *title)
- {
- int x;
- struct text_info ti;
-
- gettextinfo(&ti);
- textcolor(RED);
- textbackground(LIGHTGRAY);
- gotoxy(1,1);
- for(x=0;x<40-strlen(title)/2;x++) cprintf(" ");
- cprintf("%s",title);
- for(;x<79;x++) cprintf(" ");
- textattr(ti.attribute);
- }
-
- void screenhelp(char *helptxt)
- {
- int x;
- struct text_info ti;
-
- gettextinfo(&ti);
- textbackground(CYAN);
- textcolor(BLACK);
- gotoxy(1,24);
- for (x=0;x<80;x++) cprintf(" ");
- gotoxy(1,25);
- for (x=0;x<80;x++) cprintf(" ");
- gotoxy(1,24);
- cprintf(helptxt);
- textattr(ti.attribute);
- }
-
- void ablak(int x1,int y1,int x2,int y2,char *cim,int type)
- {
- int x,y;
-
- for(y=y1;y<y2;y++)
- {
- gotoxy(x1,y);
- for(x=x1;x<x2;x++) cprintf(" ");
- }
-
- gotoxy(x1,y1);putch(keret[type][0]);
- for(x=x1+1;x<x2;x++) {gotoxy(x,y1);putch(keret[type][1]);}
- gotoxy(x2,y1);putch(keret[type][2]);
- for(x=y1+1;x<y2;x++) {gotoxy(x2,x);putch(keret[type][3]);}
- gotoxy(x2,y2);putch(keret[type][4]);
- gotoxy(x1,y2);putch(keret[type][6]);
- for(x=x1+1;x<x2;x++) {gotoxy(x,y2);putch(keret[type][5]);}
- gotoxy(x1,y1);
- for(x=y1+1;x<y2;x++) {gotoxy(x1,x);putch(keret[type][7]);}
-
- gotoxy((x1+x2)/2-strlen(cim)/2,y1);
- cprintf("%s",cim);
- }
-
- int linedit(int cx,int cy,char *str)
- {
- int x=0,y,l,ex=0;
- char c;
-
- l=strlen(str);
- // x=l;
-
- do
- {
- gotoxy(cx,cy);cprintf("%s",str);
- gotoxy(cx+x,cy);
- c=getch();
- switch(c)
- {
- case 0: c=getch();
- switch(c)
- {
- case RIGHT: if (x<l-1) x++; break;
- case LEFT: if (x>0) x--; break;
- case UP: ex=1; break;
- case DOWN: ex=1; break;
- case DEL: memmove(str+x,str+x+1,l-x);str[l-1]=' ';break;
- // case INS:
- }
- break;
- case BS: if (x>0) {x--;memmove(str+x,str+x+1,l-x);str[l-1]=' ';} break;
- case ESC: ex=1; break;
- case ENTER: ex=1; break;
- default: if (x<l-1)
- {
- memmove(str+x+1,str+x,l-x);str[x]=c;str[l]=0;x++;
- }
- break;
- } //switch
- } while(!ex);
- fflush(stdin);
- return(c);
- }
-
- int edtwin(int x1, int y1, int x2, int y2 , char *cim, int n, char *label1, char *str1, ...)
- {
- int t,c;
- struct text_info ti;
- char *bck;
-
- gettextinfo(&ti); //eredeti allapot
- bck=(char *)malloc((x2-x1+1)*(y2-y1+1)*2);
- gettext(x1,y1,x2,y2,bck);
-
- textbackground(NORMALBCK);
- textcolor(NORMALCOL);
-
- ablak(x1,y1,x2,y2,cim,0); //keret
-
- for(t=0;t<n;t++) //kirak
- {
- gotoxy(x1+1,y1+t+1);
- cprintf("%s",*(&label1+2*t));
- cprintf("%s",*(&str1+2*t));
- }
-
- t=0;
- do //mozog
- {
- textbackground(SELECTEDBCK);
- textcolor(SELECTEDCOL);
- c=linedit(x1+strlen(*(&label1+2*t))+1,y1+t+1,*(&str1+2*t)); //edital
- textbackground(NORMALBCK);
- textcolor(NORMALCOL);
- gotoxy(x1+strlen(*(&label1+2*t))+1,y1+t+1);
- cprintf("%s",*(&str1+2*t));
- switch(c)
- {
- case UP: if (t>0) t--; break;
- case DOWN: if (t<n-1) t++; break;
- }
- } while (c!=ESC && c!=ENTER);
-
- puttext(x1,y1,x2,y2,bck);
- free(bck);
-
- return(c==ENTER);
- }
-
- int mnuwin(int x1, int y1, int x2, int y2 , char *cim, int n, char *mnu1, ...)
- {
- int t,c;
- struct text_info ti;
- char *bck;
-
- _setcursortype(_NOCURSOR);
-
- gettextinfo(&ti); //eredeti allapot
- bck=(char *)malloc((x2-x1+1)*(y2-y1+1)*2);
- gettext(x1,y1,x2,y2,bck);
-
- textbackground(NORMALBCK);
- textcolor(NORMALCOL);
-
- ablak(x1,y1,x2,y2,cim,0); //keret
-
- for(t=0;t<n;t++) //kirak
- {
- gotoxy((x1+x2)/2-strlen(*(&mnu1+t))/2,y1+t+1);
- cprintf("%s",*(&mnu1+t));
- }
-
- t=0;
- do //mozog
- {
- textbackground(SELECTEDBCK);
- textcolor(SELECTEDCOL);
- gotoxy((x1+x2)/2-strlen(*(&mnu1+t))/2,y1+t+1);
- cprintf("%s",*(&mnu1+t));
- c=getch();
- textbackground(NORMALBCK);
- textcolor(NORMALCOL);
- gotoxy((x1+x2)/2-strlen(*(&mnu1+t))/2,y1+t+1);
- cprintf("%s",*(&mnu1+t));
- if (c==0)
- {
- c=getch();
- switch(c)
- {
- case UP: if (t>0) t--; break;
- case DOWN: if (t<n-1) t++; break;
- }
- }
- } while (c!=ESC && c!=ENTER);
- if (c==ESC) t=-1;
- fflush(stdin);
- puttext(x1,y1,x2,y2,bck);
- free(bck);
- _setcursortype(_NORMALCURSOR);
- return(t);
- }
-
- void msgwin(char *msg)
- {
- int x1,y1=10,x2,y2=12;
- char *bck;
- struct text_info ti;
-
- x1=39-strlen(msg)/2;
- x2=41+strlen(msg)/2;
-
- _setcursortype(_NOCURSOR);
-
- gettextinfo(&ti); //eredeti allapot
- bck=(char *)malloc((x2-x1+1)*(y2-y1+1)*2);
- gettext(x1,y1,x2,y2,bck);
-
- ablak(x1,y1,x2,y2,"",1);
- gotoxy(x1+1,11);
- cprintf("%s",msg);
- getch();
- gotoxy(ti.curx,ti.cury);
-
- puttext(x1,y1,x2,y2,bck);
- free(bck);
- fflush(stdin);
-
- _setcursortype(_NORMALCURSOR);
- }