TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ANTHONY TIBBS
from: KURT KUZBA
date: 1997-12-27 13:05:00
subject: Windowing 1/5

AT>   Kurt? You seem to do a lot with direct video output...
AT>   Maybe you have something? :-)
   I had a little time and an itch, so I came up with this.
   You should be able to derive your windows however you like.
   I did a simple one with no borders and one with borders and
   shadows, just for the fun of it. You will likely have no
   problem adding whatever you like given this code from which
   to begin. The thing to remember is that the wd2 struct holds
   the absolute dimensions of screen area effected, and wd1
   holds just the writable window area itself. The TextOut()
   function allows you to write to multiple windows, though I
   didn't include support for overlapping updated text. As long
   as the windows do not overlap, you can write to more than
   one, with each maintaining its own boundaries and colors.
   Simply setting the wd2 parameters ensures that Grab() will
   buffer the underlying screen data, and closing the window
   will automatically restore it. The Graying routine could
   also go into the base class Grab() function, if you like.
   Adding your Title Headers and other bordering schemes should
   prove to be fairly elementary and should not threaten the
   stability or robustness of the class, since they simple
   manipulate the window created in Grab(). Happy Coding... 
/*_|_|   begin   WINDERS.CPP   (part 1 of 5)                       **
_|_|_|   PUBLIC DOMAIN   by Kurt Kuzba   12/25/1997                **
_|_|_|   A simple example of using windowed text in Borland C++.   **
_|_|_|   No warrantees or guarantees given or implied.             **
_|_|*/
//   define base window class MyWindows   ***************************
#include 
#include 
#include 
#define WIDE 80
#define HIGH 25
typedef struct{   int nL, nT, nR, nB, nA, nBA; } WIN_DEF;
class MyWindows {
public:
   MyWindows();
   ~MyWindows();
   void SetColors(int);
   void TxtOut(char*, int, int);
   int Grab();
   WIN_DEF wd1, wd2;
   char *psBuffer;
};
//**********   MyWindows functions
MyWindows::MyWindows() { psBuffer = (char*)NULL; }
MyWindows::~MyWindows()
{
   window(1, 1, WIDE, HIGH);
   if(psBuffer)
   {
      puttext(wd2.nL, wd2.nT, wd2.nR, wd2.nB, psBuffer);
      delete []psBuffer;
   }
}
int MyWindows::Grab(void)
{
   int bufsize = (1 + wd2.nR - wd2.nL) * (1 + wd2.nB - wd2.nT) * 2;
   psBuffer = new char   [bufsize];
   gettext(wd2.nL, wd2.nT, wd2.nR, wd2.nB, psBuffer);
   window(wd2.nL, wd2.nT, wd2.nR, wd2.nB);
   textattr(wd2.nA = wd2.nA);
   return bufsize;
}
void MyWindows::SetColors(int a) { wd1.nA = a; }
void MyWindows::TxtOut(char *Text, int line = 1, int column = 1)
{
   if(!line)
      line = (wd1.nB - wd1.nT + 2 ) / 2;
   if(!column)
      column = (wd1.nR - wd1.nL - strlen(Text)) / 2 + 1;
   window(wd1.nL, wd1.nT, wd1.nR, wd1.nB);
   gotoxy(column, line);
   textattr(wd1.nA);
   cprintf(Text);
}
/*_|_|   end   WINDERS.CPP   (part 1 of 5)                         */
> ] The Sky is full of Good and Bad that Mortals Never Know.....
---
---------------
* Origin: *YOPS ]I[* 3.1 GIG * RA/FD/FE RADist * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.