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

  1. #ifndef __WINDOW__
  2. #define WINDOW
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. #define FALSE    0
  7. #define TRUE    1
  8.  
  9. // Line drawing symbols
  10. #define UL    218
  11. #define UR    191
  12. #define LL    192
  13. #define LR    217
  14. #define H    196
  15. #define V    179
  16. #define ULD    201
  17. #define URD    187
  18. #define LLD    200
  19. #define LRD    188
  20. #define HD    205
  21. #define VD    186
  22.  
  23. // Border Types
  24. #define SINGLE_BORDER    1
  25. #define DOUBLE_BORDER    2
  26.  
  27. // Colors (Foreground & Background)
  28. #define BLACK    0    // Background & Foreground
  29. #define BLUE    1
  30. #define GREEN    2
  31. #define CYAN    3
  32. #define RED    4
  33. #define MAGENTA    5
  34. #define BROWN    6
  35. #define LGRAY    7
  36. #define DGRAY    8    // Foreground only
  37. #define LBLUE    9
  38. #define LGREEN    10
  39. #define LCYAN    11
  40. #define LRED    12
  41. #define LMAGENTA 13
  42. #define YELLOW    14
  43. #define WHITE    15
  44.  
  45. typedef unsigned char uchar;
  46. enum ScrMode {
  47.     SCR_MODE_UNKNOWN = -1,
  48.     SCR_MODE_25x40 = 0,    // all except monochrome
  49.     SCR_MODE_25x80 = 1,    // all (default)
  50.     SCR_MODE_30x80 = 2,    // VGA and MCGA
  51.     SCR_MODE_43x80 = 3,    // EGA
  52.     SCR_MODE_50x80 = 4    // VGA and MCGA
  53. };
  54.  
  55. enum VideoCardType {
  56.     TYPE_UNKNOWN = -1,
  57.     TYPE_MDA = 0,
  58.     TYPE_CGA = 1,
  59.     TYPE_HGC = 2,
  60.     TYPE_EGA = 3,
  61.     TYPE_MCGA = 4,
  62.     TYPE_VGA = 5
  63. };
  64.  
  65. class Window;
  66. // Cell class - defines a position as an attribute & caharcter
  67. class Cell {
  68. public:
  69.     Cell();
  70.     void Put(uchar attr, uchar c);
  71.     void Put(short word);
  72.     void Get(uchar &attr, uchar &c);
  73.     short Get();
  74. private:
  75.     uchar Character;
  76.     uchar Attribute;
  77. };
  78.  
  79.  
  80. // Buffer that holds contents of window
  81. class WindowBuffer {
  82. public:
  83.     WindowBuffer();
  84.     WindowBuffer(const WindowBuffer &wb);
  85.     ~WindowBuffer();
  86.     void SetSize(int rows, int cols);
  87.     void Fill(uchar attr, uchar c);
  88.     void Put(int row, int col, uchar attr, uchar c);
  89.     void Put(int row, int col, short word);
  90.     void Get(int row, int col, uchar &attr, uchar &c);
  91.     short Get(int row, int col);
  92. protected:
  93.     Cell *Buffer;
  94.     int RowSize;
  95.     int ColSize;
  96. };
  97.  
  98. // Window list class - linked list of windows
  99. struct WindowListNode {
  100.     WindowListNode *Prev;
  101.     WindowListNode *Next;
  102.     Window *WindowPtr;
  103. };
  104. class WindowList {
  105. public:
  106.     WindowList();
  107.     ~WindowList();
  108.     void Add(Window *w);
  109.     void Delete(Window *w);
  110.     void MoveTop(Window *w);
  111.     void MoveBottom(Window *w);
  112.     short IsTop(Window *w);
  113.     Window *AtBottom();
  114.     Window *NextWindow();
  115. private:
  116.     WindowListNode *Bottom;
  117.     WindowListNode *Top;
  118.     WindowListNode *Current;
  119. };
  120.  
  121. // Window class
  122. class Window {
  123. public:
  124.     Window(int row, int col, int width, int height, uchar attr);
  125.     ~Window();
  126.     void DrawBorder(int BorderType);
  127.     void ResetWindows();
  128.     int Getch();
  129.     void VPut(int row, int col, uchar attr, uchar c);
  130.     void VPut(int row, int col, short word);
  131.     void VGet(int row, int col, uchar &attr, uchar &c);
  132.     short VGet(int row, int col);
  133.     void Cls();
  134.     void HideCursor();
  135.     void ShowCursor();
  136. protected:
  137.     static short far *Video;
  138.     static VideoCardType vc;
  139.     static int Initialized;
  140.     static WindowList List;
  141.     static int CursorHidden;
  142.     int Row;
  143.     int Col;
  144.     int Width;
  145.     int Height;
  146.     int ScreenRows;
  147.     int ScreenCols;
  148.     uchar WindowAttr;
  149.     int CursorRow;
  150.     int CursorCol;
  151.     uchar WallpaperAttr;
  152.     uchar WallpaperSymbol;
  153.     WindowBuffer Buffer;
  154.     WindowBuffer SavedBuffer;
  155.     unsigned short CursorShape;
  156. private:
  157.     VideoCardType IdentifyVideoCard();
  158.     void SetVideoMem();
  159.     void Display();
  160.     void SaveScreen();
  161.     void RestoreScreen();
  162. };
  163.  
  164. // function prototypes
  165. void Error(char *msg);
  166. #endif
  167.