00001
00002 #include <string.h>
00003 #include "cur.h"
00004 #include "box.h"
00005 #include "video.h"
00006
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 void save (WINDOW *w) { w->Save = 1; }
00034 void nosave (WINDOW *w) { w->Save = 0; }
00035 void boxed (WINDOW *w) { w->boxed = 1; }
00036 void unboxed (WINDOW *w) { w->boxed = 0; }
00037
00046 void def_ground(WINDOW *w,int f,int b)
00047 {
00048 w->attrib = (f & 0x7f) | ((b & 0x7f) << 3);
00049 }
00050
00051
00052
00066 WINDOW *newwin(int lines,int cols,int begin_y,int begin_x,void *IoChan,int attrib,int nBoxed)
00067
00068
00069
00070
00071
00072
00073 {
00074 WINDOW *win;
00075 int nCols,nRows;
00076
00077 if( !(win = (WINDOW *) malloc( sizeof(WINDOW) )) )
00078 {
00079 return win;
00080 }
00081 win->IO = IoChan;
00082 DisplayAttrib(&nCols,&nRows);
00083
00084 if( cols > nCols )
00085 {
00086 cols = 80;
00087 begin_x = 0;
00088 }
00089 else if( begin_x + cols > nCols )
00090 begin_x = 80 - cols;
00091
00092 if( lines > nRows )
00093 {
00094 lines = nRows;
00095 begin_y = 0;
00096 }
00097 else if( begin_y + lines > nRows )
00098 begin_x = nRows - cols;
00099 win->dvRow = begin_y;
00100 win->dvCol = begin_x;
00101 win->x_org = begin_x ;
00102 win->y_org = begin_y ;
00103 win->x_size = cols ;
00104 win->y_size = lines ;
00105 win->row = 0 ;
00106 win->col = 0 ;
00107 win->scroll_ok = 0 ;
00108 win->wrap_ok = 1 ;
00109 win->boxed = nBoxed ;
00110 win->Echo = 1;
00111 win->Crmode = 0;
00112 win->Nl = 1;
00113 win->hidden = 0 ;
00114 win->attrib = attrib ;
00115 win->image = !win->Save ? NULL : savescr( begin_x, begin_x + (cols - 1) ,
00116 begin_y, begin_y + (lines - 1) );
00117 werase(win);
00118
00119 if( win->boxed )
00120 {
00121 box( win, VERT, HORIZ );
00122 win->x_size -= 2;
00123 win->y_size -= 2;
00124 win->x_org += 1;
00125 win->y_org += 1;
00126 cmove(win, win->y_org, win->x_org );
00127 }
00128 return win;
00129 }
00130
00138 void WinSetTitle(WINDOW *w, char *title)
00139 {
00140 int x,y,l,i;
00141
00142 y = w->y_org - 1;
00143 l = strlen(title);
00144 x = w->x_org - 1 + (w->x_size + 2 - l) / 2;
00145 for(i=0;i<l;++i)
00146 {
00147 SCREEN[ y ][ x+i ].letter = title[i];
00148 SCREEN[ y][ x+i ].attribute = w->attrib;
00149 }
00150 }
00151