#include #include #include #include #include #include "twindow.hpp" const int MAXX=80; const int MAXY=25; const int MINX=0; const int MINY=0; class Display { public: typedef unsigned far* ScreenPtr; static void drawChar(unsigned x,unsigned y, char c, unsigned fg, unsigned bg); }; void Display::drawChar(unsigned x,unsigned y, char c, unsigned fg, unsigned bg) { ScreenPtr display = (ScreenPtr)MK_FP(0xB800,0x0); display[y*80+x] = (((bg<<4)|fg)<<8)|(c & 255); } //============================================================================= // default constructor: skapar fönstret med vissa koordinater och färger //----------------------------------------------------------------------------- TWindow::TWindow() { Left=69;Right=78;Bottom=4;Top=1;background=BLUE;foreground=WHITE; text=NULL; } //============================================================================= // constructor: skapar fönstret med vissa koordinater och färger //----------------------------------------------------------------------------- TWindow::TWindow(unsigned left,unsigned top,unsigned right ,unsigned bottom, DColor bg, DColor fg): Left(left),Right(right),Bottom(bottom),Top(top),background(bg), foreground(fg) { theState = 0;//FALSE; text=NULL; } //============================================================================= // destructor: förstör fönstret //----------------------------------------------------------------------------- TWindow::~TWindow() { if(isVisible()) hide(); } //============================================================================= // hide: gömmer fönstret //----------------------------------------------------------------------------- void TWindow::hide() { erase(); } //============================================================================= // show: visar fönstret //----------------------------------------------------------------------------- void TWindow::display() { draw(); if(text) showText(); } //============================================================================= // draw: ritar upp fönstret //----------------------------------------------------------------------------- void TWindow::draw() { theState = 1;//;TRUE; for(int j= Top; j< Bottom; j++ ) for(int i=Left; i< Right ; i++ ) { Display::drawChar(i,j,' ',foreground,background); } drawBorder(); } //============================================================================= // erase: ritar över fönstret med svart //----------------------------------------------------------------------------- void TWindow::erase() { for(int j= Top; j<= Bottom; j++ ) for(int i=Left; i<= Right ; i++ ) Display::drawChar(i,j,' ',BLACK,BLACK); theState = 0;//FALSE; } //============================================================================= // drewBorder: ritar ramen runt fönstret //----------------------------------------------------------------------------- void TWindow::drawBorder() { for(int i=Left+1; i< Right; i++)Display::drawChar(i ,Top , HLine , foreground, background); for( i=Left+1; i< Right; i++)Display::drawChar(i ,Bottom , HLine , foreground, background); for( i=Top+1; i< Bottom; i++)Display::drawChar(Left ,i , VLine , foreground, background); for( i=Top+1; i< Bottom; i++)Display::drawChar(Right ,i , VLine , foreground, background); Display::drawChar(Left ,Top , LeftTop , foreground, background); Display::drawChar(Right ,Top ,RightTop , foreground, background); Display::drawChar(Right ,Bottom ,RightBottom, foreground, background); Display::drawChar(Left ,Bottom , LeftBottom, foreground, background); } void TWindow::move(unsigned relX, unsigned relY) { Left=Left+relX; Right=Right+relX; Top=Top+relY; Bottom=Bottom+relY; } void TWindow::moveAbs(unsigned x, unsigned y) { unsigned width=Right-Left; unsigned height=Bottom-Top; Left=x; Right=x+width; Top=y; Bottom=y+height; } void TWindow::setText(char* txt) { text=new char[strlen(txt)]; strcpy(text, txt); } void TWindow::showText() { int x=Left+1,y=Top+1; for(int i=0;i=Right) { x=Left+1; y++; } } } void TWindow::editText() { int i=0; delete text; int size=(Right-Left-1)*(Bottom-Top-1); text=new char[size]; text[0]='\0'; char* buffer=new char[size]; while(((buffer[i]=bioskey(0))!=ENTER)&&(i(TWindow& t) { return strcmp(text, t.text)>0; } ostream& operator<<(ostream& o, TWindow& t) { t.display(); return o; } istream& operator>>(istream&i, TWindow& t) { t.editText(); return i; }