UPLOAD - DOSUIT07.ZIP - SCREEN.CPP

 
Output of file : SCREEN.CPP contained in archive : DOSUIT07.ZIP

#ifdef ALL
#define SCREENA
#define SCREENB
#define SCREENC
#define SCREEND
#define SCREENE
#define SCREENF
#define SCREENG
#define SCREENH
#define SCREENI
#define SCREENJ
#define SCREENK
#define SCREENL
#define SCREENM
#endif
#ifndef SCREENA
#define LIBRARY_MODULE
#endif

/*
* Basic Screen class.
* All drawing on the screen is through a Screen.
* The standard implementation uses the whole screen as the only Screen.
*/
#ifdef __ZTC__
#include /* Zortech mouse package */
#include /* Zortech disp package */
#endif
#ifdef __TURBOC__
extern void msm_showcursor(), msm_hidecursor();
#include
#include
#ifdef enable
#undef enable
#endif
#ifdef disable
#undef disable
#endif
#endif
#include
#include
#include
#include "screen.hpp"


#ifdef __TURBOC__
extern union REGS bios_regs;
extern void bioscall(int callno);
extern void disp_move(int y,int x);
#endif

#if 0
SavedRectangle::SavedRectangle(const Rectangle& r)
: (r), savedarea(new unsigned[width() * height()])
{
}

SavedRectangle::~SavedRectangle()
{
delete savedarea;
}

SavedRectangle *Screen::saveRectangle(const Rectangle& r) const
{
ASSERT(this->encloses(r));

SavedRectangle *sr = new SavedRectangle(r);
if(sr)
{
msm_hidecursor();
disp_peekbox(sr->savedarea,r.top(),r.left(),r.bottom(),r.right());
msm_showcursor();
}
return sr;
}

void Screen::restoreRectangle(SavedRectangle* sr)
{
if(sr)
{
msm_hidecursor();
disp_pokebox(sr->savedarea,sr->top(),sr->left(),sr->bottom(),sr->right());
msm_showcursor();
delete sr;
}
}
#endif

#ifdef SCREENA
static int screen_inited;

#ifdef __TURBOC__
union REGS bios_regs;
void bioscall(int callno)
{
bios_regs.h.ah = callno;
int86(0x10,&bios_regs,&bios_regs);
}

int disp_numrows = 25, disp_numcols = 80, disp_mode = 7, disp_mono = 1;

void disp_open()
{
disp_numrows = 25;
disp_numcols = 80;
disp_mode = 7;
disp_mono = 1;
bios_regs.h.al = 0x30; // enquire info from EGA
bios_regs.x.bx = bios_regs.x.dx = 0;
bioscall(0x11);
if(bios_regs.h.dl) // EGA or better
disp_numrows = bios_regs.h.dl + 1;
bioscall(15);
disp_numcols = bios_regs.h.ah;
disp_mode = bios_regs.h.al;
if(disp_mode != 7 && disp_mode != 15)
disp_mono = 0;
}

void disp_move(int y, int x)
{
bios_regs.h.bh = 0;
bios_regs.h.dh = y;
bios_regs.h.dl = x;
bioscall(2);
}
#endif

Screen::Screen()
: Rectangle(origin,80,25), cursorHidden(0), colorflag(!disp_mono)
{
cursorpt.x = cursorpt.y = 0;
if(!screen_inited++)
enable();
hidecursor();
disp_move(0,0);
#ifdef __ZTC__
disp_eeop();
disp_flush();
#endif
#ifdef __TURBOC__
bios_regs.h.al = 0;
bios_regs.h.bh = 0x07;
bios_regs.h.ch = 0;
bios_regs.h.cl = 0;

bios_regs.h.dh = disp_numrows;
bios_regs.h.dl = disp_numcols;
bioscall(6);
#endif
setsize((coord)disp_numcols,(coord)disp_numrows);
}

Screen::~Screen()
{
if(!--screen_inited)
disable();
}

void Screen::showcursor(int block)
{
#ifdef __ZTC__
disp_setcursortype(block ? DISP_CURSORBLOCK : DISP_CURSORUL);
if(cursorHidden)
{
disp_showcursor();
cursorHidden = 0;
}
#endif
#ifdef __TURBOC__
_setcursortype(block ? _SOLIDCURSOR : _NORMALCURSOR);
cursorHidden = 0;
#endif
}

void Screen::hidecursor()
{
if(!cursorHidden)
{
#ifdef __ZTC__
disp_hidecursor();
#endif
#ifdef __TURBOC__
_setcursortype(_NOCURSOR);
#endif
cursorHidden = 1;
}
}

int Screen::enable()
{
disp_open(); // initialise disp package
colorflag = !disp_mono;
if(cursorHidden)
#ifdef __ZTC__
disp_hidecursor(); // and text cursor off
#endif
#ifdef __TURBOC__
_setcursortype(_NOCURSOR);
#endif
return 1;
}

void Screen::disable()
{
disp_move(bottom(),left());
#ifdef __ZTC__
disp_flush();
disp_showcursor();
disp_close(); // close disp package
#endif
#ifdef __TURBOC__
_setcursortype(_NORMALCURSOR);
#endif
}

#endif

#ifdef SCREENB
void Screen::emergencyMessage(const char *s)
{
Point p;

p.x = 0;
p.y = height() / 2;
fillrect(*this,Color(White,Black),' ');
printstring(p,Color(White),s,strlen(s));
}
#endif

#ifdef SCREENC
void Screen::scroll(const Rectangle &a,const color c,int nlines)
{
ASSERT(this->encloses(a));
msm_hidecursor();
#ifdef __ZTC__
disp_scroll(nlines,a.top(),a.left(),a.bottom(),a.right(),c);
#endif
#ifdef __TURBOC__
bios_regs.h.al = (nlines >= 0) ? nlines : -nlines;
bios_regs.h.bh = c;
bios_regs.h.ch = a.top();
bios_regs.h.cl = a.left();
bios_regs.h.dh = a.bottom();
bios_regs.h.dl = a.right();
bioscall((nlines >= 0) ? 6 : 7);
#endif
msm_showcursor();
}
#endif

#ifdef SCREEND
void Screen::printstring(Point at,const color c,const char *s,int length)
{
if(length < 0)
length = strlen(s);
if(at.x + length - 1 > right()) // clip string
length = right() - at.x + 1;
if(length <= 0 || !this->encloses(at))
return;
msm_hidecursor();
#ifdef __ZTC__
{
unsigned attr = (unsigned)c << 8;

while(length--)
disp_pokew(at.y,at.x++,attr + (unsigned char)(*s++));
}
#endif
#ifdef __TURBOC__
while(length--)
{
disp_move(at.y,at.x++);
bios_regs.h.al = (unsigned char)(*s++);
bios_regs.h.bh = 0;
bios_regs.h.bl = c;
bios_regs.x.cx = 1;
bioscall(9);
}
update();
#endif
msm_showcursor();
}
#endif

#ifdef SCREENE
void Screen::fprintstring(Point at,const color c,const char *s,const int length)
{
int l = strlen(s);

if(l > length)
l = length;
printstring(at,c,s,l);
if(l < length)
{
at.x += l;
Rectangle r(at,length - l,1);
fillrect(r,c,' ');
}
}
#endif

#ifdef SCREENF
void Screen::fillrect(const Rectangle& r,const color c,const char x)
{
if(!this->encloses(r))
return;
msm_hidecursor();
#ifdef __ZTC__
disp_fillbox(((unsigned)c << 8) + (unsigned char)x,r.top(),r.left(),r.bottom(),r.right());
#endif
#ifdef __TURBOC__
for(int row = r.top(); row <= r.bottom(); row++)
{
disp_move(row,r.left());
bios_regs.h.al = x;
bios_regs.h.bh = 0;
bios_regs.h.bl = c;
bios_regs.x.cx = r.width();
bioscall(9);
}
update();
#endif
msm_showcursor();
}
#endif

#ifdef SCREENG
void Screen::cursor(const Point& p)
{
if(this->encloses(p))
{
cursorpt = p;
update();
}
}
#endif

#ifdef SCREENH
void Screen::update()
{
disp_move(cursorpt.y,cursorpt.x);
#ifdef __ZTC__
disp_flush();
#endif
}
#endif

#ifdef SCREENI
Keys alt(int key)
{
static const Keys kaltdigits[] = {
KAlt0, KAlt1, KAlt2, KAlt3, KAlt4, KAlt5, KAlt6, KAlt7, KAlt8, KAlt9
};
static const Keys kaltalpha[] = {
KAltA, KAltB, KAltC, KAltD, KAltE, KAltF, KAltG, KAltH,
KAltI, KAltJ, KAltK, KAltL, KAltM, KAltN, KAltO, KAltP,
KAltQ, KAltR, KAltS, KAltT, KAltU, KAltV, KAltW, KAltX,
KAltY, KAltZ
};

if(isdigit(key))
return kaltdigits[key - '0'];
if(isalpha(key))
return kaltalpha[toupper(key) - 'A'];
if(key >= KF1 && key <= KF10)
return (Keys)(key - KF1 + KAltF1);
return Knone;
}
#endif

#ifdef SCREENJ
const char *ctrltable[' '] = {
"","^A","^B","^C","^D","^E","^F","^G","Bksp","Tab","\\n",
"^K","^L","\\r","^N","^O","^P","^Q","^R","^S","^T","^U","^V",
"^W","^X","^Y","^Z","Esc","^\\","^]","^^","^_" };
const char *alttable[256] = {
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, "BackTab",
"AltQ", "AltW", "AltE", "AltR", "AltT", "AltY", "AltU", "AltI",
"AltO", "AltP", 0, 0, 0, 0, "AltA", "AltS",
"AltD", "AltF", "AltG", "AltH", "AltJ", "AltK", "AltL", 0,
0, 0, 0, 0, "AltZ", "AltX", "AltC", "AltV",
"AltB", "AltN", "AltM", 0, 0, 0, 0, 0,
0, 0, 0, "F1", "F2", "F3", "F4", "F5",
"F6", "F7", "F8", "F9", "F10", 0, 0, "Home",
"Up", "PgUp", 0, "Left", 0, "Right",0, "End",
"Down", "PgDn", "Ins", "Del", "ShF1", "ShF2", "ShF3", "ShF4",
"ShF5", "ShF6", "ShF7", "ShF8", "ShF9", "ShF10","^F1", "^F2",
"^F3", "^F4", "^F5", "^F6", "^F7", "^F8", "^F9", "^F10",
"AltF1","AltF2","AltF3","AltF4","AltF5","AltF6","AltF7","AltF8",
"AltF9","AltF10",0, "^Left","^Right","^End",0, "^Home",
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, "^PgUp",0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, "^PgDn",0, 0, 0, 0,
};

const char *keyname(unsigned k)
{
static char asctable[256-' '][2];

if(!asctable[0][0])
{
for(int i = ' '; i < 256; i++)
asctable[i - ' '][0] = i;
}

if(k == (unsigned) Kauto)
return "Kauto";
if(k < ' ')
return ctrltable[k];
if(k == 127)
return "^Bksp";
if(k < 256)
return asctable[k - ' '];

unsigned i = k >> 8;

if(i < 256 && alttable[i])
return alttable[i];
return form("Key[0x%x]",k);
}

Keys namekey(const char *s)
{
if(!s[1])
return Keys(s[0]);

const char **p;
int n;

for(p = ctrltable, n = 0; n < ' '; n++, p++)
if(s[1] == (*p)[1] && !strcmp(s,*p))
return Keys(n);
if(!strcmp(s,"^Bksp"))
return Keys(127);
for(p = alttable, n = 0; n < 256; n++, p++)
if(*p && !strcmp(s,*p))
return Keys(n << 8);
if(sscanf((char *)s,"Key[%x]", &n) == 1)
return Keys(n);
return Kauto;
}
#endif

#ifdef SCREENK
extern const char
RightArrow[] = { 26, 0 },
LeftArrow[] = { 27, 0 },
DownArrow[] = { 25, 0 },
UpArrow[] = { 24, 0 };
#endif

#ifdef SCREENL
extern const char
RadioOn[] = { 10, 0 },
RadioOff[] = { 7, 0 },
CheckOn[] = { 'X', 0 },
CheckOff[] = { '-', 0 },
Tick[] = { (char) 251, 0 };
#endif

#ifdef SCREENM
extern const char boxChars[nBoxType][nBoxChars] =
{
{ 32, 32, 32, 32, 32, 32, 32, 32 }, // no box at all
{ 218, 196, 191, 179, 179, 192, 196, 217 }, // single box characters
{ 201, 205, 187, 186, 186, 200, 205, 188 }, // double box characters
{ 219, 219, 219, 219, 219, 219, 219, 219 } // bold box characters
};
#endif