home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / WINCPP.ZIP / WINDOW.CPP < prev    next >
C/C++ Source or Header  |  1994-01-25  |  3KB  |  128 lines

  1. #include "window.h"
  2.  
  3. int Window::Initialized = FALSE;
  4. WindowList Window::List;
  5. int Window::CursorHidden = FALSE;
  6.  
  7. Window::Window(int row, int col, int width, int height, uchar attr) :
  8.     Buffer(), SavedBuffer()
  9. {
  10.     ScreenRows = 25;
  11.     ScreenCols = 80;
  12.     if (!Initialized) {
  13.         vc = IdentifyVideoCard();
  14.         SetVideoMem();
  15.         Cls();
  16.         Initialized = TRUE;
  17.     }
  18.     Row = row;
  19.     Col = col;
  20.     Width = width;
  21.     Height = height;
  22.     WindowAttr = attr;
  23.     CursorCol = CursorRow = 0;
  24.     WallpaperAttr = (BLACK<<4|LGRAY);
  25.     WallpaperSymbol = '\xb1';
  26.     List.Add(this);
  27.     SavedBuffer.SetSize(Height, Width);
  28.     SaveScreen();
  29.     Buffer.SetSize(Height, Width);
  30.     Buffer.Fill(attr, ' ');
  31.     DrawBorder(DOUBLE_BORDER);
  32.     Display();
  33. }
  34.  
  35.  
  36. Window::~Window()
  37. {
  38.     RestoreScreen();
  39.     List.Delete(this);
  40. }
  41.  
  42.  
  43. void Window::DrawBorder(int BorderType)
  44. {
  45.     register i;
  46.  
  47.     if (BorderType == DOUBLE_BORDER) {
  48.         Buffer.Put(0, 0, WindowAttr, ULD);
  49.         Buffer.Put(0, Width-1, WindowAttr, URD);
  50.         Buffer.Put(Height-1, 0, WindowAttr, LLD);
  51.         Buffer.Put(Height-1, Width-1, WindowAttr, LRD);
  52.         for (i=1; i<(Width-1); i++) {
  53.             Buffer.Put(0, i, WindowAttr, HD);
  54.             Buffer.Put(Height-1, i, WindowAttr, HD);
  55.         }
  56.         for (i=1; i<(Height-1); i++) {
  57.             Buffer.Put(i, 0, WindowAttr, VD);
  58.             Buffer.Put(i, Width-1, WindowAttr, VD);
  59.         }
  60.     }
  61.     else {
  62.         Buffer.Put(0, 0, WindowAttr, UL);
  63.         Buffer.Put(0, Width, WindowAttr, UR);
  64.         Buffer.Put(Height-1, 0, WindowAttr, LL);
  65.         Buffer.Put(Height-1, Width-1, WindowAttr, LR);
  66.         for (i=1; i<(Width-1); i++) {
  67.             Buffer.Put(0, i, WindowAttr, H);
  68.             Buffer.Put(Height-1, i, WindowAttr, H);
  69.         }
  70.         for (i=1; i<(Height-1); i++) {
  71.             Buffer.Put(i, 0, WindowAttr, V);
  72.             Buffer.Put(i, Width-1, WindowAttr, V);
  73.         }
  74.     }
  75. }
  76.  
  77.  
  78. void Window::Display()
  79. {
  80.     register r, c;
  81.  
  82.     for (r=0; r<Height; r++)
  83.         for(c=0; c<Width; c++)
  84.             VPut(Row+r, Col+c, Buffer.Get(r,c));
  85. }
  86.  
  87.  
  88. void Window::Cls()
  89. {
  90.     register r, c;
  91.  
  92.     for (r=0; r<ScreenRows; r++)
  93.         for (c=0; c<ScreenCols; c++)
  94.             VPut(r, c, (BLACK<<4|WHITE), ' ');
  95. }
  96.  
  97.  
  98. void Window::SaveScreen()
  99. {
  100.     register r,c;
  101.  
  102.     for (r=Row; r<Row+Height; r++)
  103.         for (c=Col; c<Col+Width; c++)
  104.             SavedBuffer.Put(r-Row, c-Col, VGet(r,c));
  105. }
  106.  
  107.  
  108. void Window::RestoreScreen()
  109. {
  110.     register r, c;
  111.  
  112.     for (r=0; r<Height; r++)
  113.         for(c=0; c<Width; c++)
  114.             VPut(Row+r, Col+c, SavedBuffer.Get(r,c));
  115. }
  116.  
  117.  
  118. void Window::ResetWindows()
  119. {
  120.     Window *w;
  121.  
  122.     w = List.AtBottom();
  123.     while (w != NULL) {
  124.         w->Display();
  125.         w->List.NextWindow();
  126.     }
  127. }
  128.