home *** CD-ROM | disk | FTP | other *** search
- //
- // *************************************************************************
- // * *
- // * OMEGA C++ Windowing Class Library *
- // * ================================= *
- // * *
- // * Copyright 1991,92 Tom Clancy *
- // * Submitted to the public domain, April 1992 *
- // * *
- // *************************************************************************
- // * *
- // * Window Class Methods *
- // * *
- // *************************************************************************
- //
-
- #include <dos.h>
- #include <string.h>
- #include <conio.h>
- #include "fastwrit.hpp"
- #include "omwin.hpp"
-
- extern unsigned char boxstyles[2][6];
-
- oWindow::oWindow(int x, int y, int w, int l, int fg, int bk, int style) {
-
- Startx=x;
- Starty=y;
- TxtStartx=Startx+1;
- TxtStarty=Starty+1;
- Just=mNojust;
- Len=l;
- Wid=w;
- Endx=x+w-1;
- Endy=y+l-1;
- FGcolor=fg;
- BKcolor=bk;
- Shadowed=TRUE;
- ShadDir=shBottomright;
- Opened=FALSE;
- if(style<0 || style>1)
- style=0;
- Wstyle=style;
- strcpy(title,"\0");
- tPos=tCenter;
- Canresize=TRUE;
- Canclose=TRUE;
- Canexpand=TRUE;
- Candrag=TRUE;
- tFGcolor=WHITE;
- tBKcolor=BLUE;
- Buttoncolor=LIGHTGREEN;
- Expanded=FALSE;
- BoundX=1;
- BoundY=1;
- BoundX2=getscreenwid();
- BoundY2=getscreenlen();
- MinWid=20;
- MinLen=3;
- Oldx=Startx;
- Oldy=Starty;
- Oldx2=Endx;
- Oldy2=Endy;
- OldLen=Len;
- OldWid=Wid;
- SolidHeader=TRUE;
- }
-
- oWindow::oWindow () {
-
- Startx=1;
- Starty=1;
- TxtStartx=Startx+1;
- TxtStarty=Starty+1;
- Just=mNojust;
- Endx=1;
- Endy=1;
- Len=1;
- Wid=1;
- FGcolor=WHITE;
- BKcolor=BLACK;
- Shadowed=TRUE;
- ShadDir=shBottomright;
- Opened=FALSE;
- Wstyle=SINGLEBAR;
- strcpy(title,"\0");
- tPos=tCenter;
- Canresize=TRUE;
- Canclose=TRUE;
- Canexpand=TRUE;
- Candrag=TRUE;
- tFGcolor=WHITE;
- tBKcolor=BLUE;
- Buttoncolor=LIGHTGREEN;
- Expanded=FALSE;
- BoundX=1;
- BoundY=1;
- BoundX2=getscreenwid();
- BoundY2=getscreenlen();
- MinWid=20;
- MinLen=3;
- Oldx=Startx;
- Oldy=Starty;
- Oldx2=Endx;
- Oldy2=Endy;
- OldLen=Len;
- OldWid=Wid;
- SolidHeader=TRUE;
- }
-
- oWindow::~oWindow() {
- setlastcmd(0);
- setlastevent(0);
- if(Opened)
- disposewin();
- }
-
- void oWindow::setwindow(int x, int y, int w, int l, int fg, int bk, int style) {
-
- Startx=x;
- Starty=y;
- TxtStartx=Startx+1;
- TxtStarty=Starty+1;
- Len=l;
- Wid=w;
- Endx=x+w-1;
- Endy=y+l-1;
- FGcolor=fg;
- BKcolor=bk;
- Opened=FALSE;
- if(style<0 || style>1)
- style=0;
- Wstyle=style;
- }
-
- void oWindow::setjustify(windowjust j) {
- Just=j;
- if(Just!=mNojust) {
- dragging(OFF);
- resizing(OFF);
- expanding(OFF);
- }
- }
-
-
- void oWindow::display_info() {}
- void oWindow::display_help() {}
-
- void oWindow::settitle(char *s, int tpos, int fgcolor, int bkcolor) {
- char *t;
- t=new char[strlen(s)+1];
- strcpy(t,s);
- if(strlen(t)>130)
- t[129]='\0';
- strcpy(title,t);
- delete t;
- tFGcolor=fgcolor;
- tBKcolor=bkcolor;
- tPos=tpos;
- if(tPos<0 || tPos>2)
- tPos=tCenter;
- }
-
-
- void oWindow::dragging(int d) {
- Candrag=d;
- if(Candrag && Just!=mNojust)
- Candrag=FALSE;
- }
-
- void oWindow::expanding(int e) {
- Canexpand=e;
- if(Canexpand && Just!=mNojust)
- Canexpand=FALSE;
- }
-
- void oWindow::resizing(int r) {
- Canresize=r;
- if(Canresize && Just!=mNojust)
- Canresize=FALSE;
- }
-
- void oWindow::snaptocenter() {
- closewin();
- int oj=Just;
- Just=mCenterBoth;
- openwin();
- Just=oj;
- }
-
- void oWindow::openwin() {
-
- int newx,newy;
-
- if(!Opened) {
- if(Just!=mNojust) {
- newx=(getscreenwid()/2)-((getright()-getleft()+1) /2);
- newy=(getscreenlen()/2)-((getbottom()-gettop()+1) /2);
- switch(Just) {
-
- case mCenterX :
- setwindow(newx,gettop(),getwid(),getlen(),getfgcolor(),getbkcolor(),getstyle());
- break;
-
- case mCenterY :
- setwindow(getleft(),newy,getwid(),getlen(),getfgcolor(),getbkcolor(),getstyle());
- break;
-
- case mCenterBoth :
- setwindow(newx,newy,getwid(),getlen(),getfgcolor(),getbkcolor(),getstyle());
- break;
- }
- }
- Opened=TRUE;
- Behind.i=save_image(Startx, Starty, Endx, Endy, Behind);
- absdrawbox(Startx, Starty, Endx, Endy, FGcolor, BKcolor, Wstyle);
- if(SolidHeader)
- absfillarea(Startx+1,Starty,Endx-1, Starty, tFGcolor, tBKcolor, 32);
- if(Canclose) {
- if(SolidHeader) {
- oScreen::writeat(Startx+2,Starty,FGcolor,tBKcolor,"[ ]");
- oScreen::chwriteat(Startx+3,Starty,Buttoncolor,tBKcolor,CLOSECHAR);
- }
- else {
- oScreen::writeat(Startx+2,Starty,FGcolor,BKcolor,"[ ]");
- oScreen::chwriteat(Startx+3,Starty,Buttoncolor,BKcolor,CLOSECHAR);
- }
- }
- if(Canexpand) {
- if(SolidHeader) {
- oScreen::writeat(Endx-4,Starty,FGcolor,tBKcolor,"[ ]");
- if(!Expanded)
- oScreen::chwriteat(Endx-3,Starty,Buttoncolor,tBKcolor,EXPANDCHAR);
- else
- oScreen::chwriteat(Endx-3,Starty,Buttoncolor,tBKcolor,CONTRACTCHAR);
- }
- else {
- oScreen::writeat(Endx-4,Starty,FGcolor,BKcolor,"[ ]");
- if(!Expanded)
- oScreen::chwriteat(Endx-3,Starty,Buttoncolor,BKcolor,EXPANDCHAR);
- else
- oScreen::chwriteat(Endx-3,Starty,Buttoncolor,BKcolor,CONTRACTCHAR);
- }
- }
- if(Canresize) {
- oScreen::chwriteat(Endx-1,Endy,Buttoncolor,BKcolor,RESIZECHAR1);
- oScreen::chwriteat(Endx,Endy,Buttoncolor,BKcolor,RESIZECHAR2);
- }
- showtitle();
- if(Shadowed)
- drawshadow();
- display_info();
- }
- }
-
- void oWindow::showtitle() {
- if(strlen(title)) {
- char *t;
- t=new char[strlen(title)+1];
- strcpy(t,title);
- if(strlen(t)>Wid-10)
- t[Wid-10]='\0';
-
- switch(tPos) {
-
- case tLeft :
- break;
- case tRight :
- break;
- case tCenter :
- abswritebetween(Starty,Startx,Endx,tFGcolor,tBKcolor,t);
- break;
- }
- delete t;
- }
- }
-
-
- void oWindow::closewin() {
-
- if(Opened) {
- show_image(Startx, Starty, Behind);
- hideshadow();
- disposewin();
- cursoroff();
- }
- }
-
- void oWindow::disposewin() {
- if(Opened) {
- Opened=FALSE;
- delete Behind.i;
- if(Shadowed) {
- if(Side1)
- delete Shside1.i;
- if(Side2)
- delete Shside2.i;
- }
- }
- }
-
-
-
- void oWindow::drawshadow() {
-
- register int i;
- int ex,ey;
-
- Side1=FALSE;
- Side2=FALSE;
-
- if(Opened && Shadowed) {
- switch(ShadDir) {
- case shTopleft :
- Shy1=Starty-1;
- if(Shy1<BoundY)
- Shy1=BoundY;
- if(getscreenlen()==25)
- Shx1=Startx-2;
- else
- Shx1=Startx-1;
- if(Shx1<BoundX)
- Shx1=BoundX;
- ex=Endx-2;
- if(Starty>BoundY) {
- Side1=TRUE;
- Shside1.i=save_image(Shx1,Shy1,ex,Shy1,Shside1);
- for(i=Shx1; i<=ex; i++)
- oScreen::writeshadow(i,Shy1);
- }
- Shy2=Starty;
- Shx2=Shx1;
- ey=Starty+Len-2;
- if(Startx>BoundX) {
- Side2=TRUE;
- if(Startx>2 && getscreenlen()==25)
- Shside2.i=save_image(Shx2,Shy2,Shx2+1,ey,Shside2);
- else
- Shside2.i=save_image(Shx2,Shy2,Shx2,ey,Shside2);
- for(i=Shy2; i<=ey; i++) {
- oScreen::writeshadow(Shx2,i);
- if(Startx>2 && getscreenlen()==25)
- oScreen::writeshadow(Shx2+1,i);
- }
- }
- break;
-
- case shTopright :
- Shy1=Starty-1;
- if(Shy1<BoundY)
- Shy1=BoundY;
- Shx1=Startx+2;
- if(getscreenlen()==25)
- ex=Endx+2;
- else
- ex=Endx+1;
- if(ex>BoundX2)
- ex=BoundX2;
- if(Starty>BoundY) {
- Side1=TRUE;
- Shside1.i=save_image(Shx1,Shy1,ex,Shy1,Shside1);
- for(i=Shx1; i<=ex; i++)
- oScreen::writeshadow(i,Shy1);
- }
- if(Endx<BoundX2) {
- Shx2=Endx+1;
- Side2=TRUE;
- ex=Endx+2;
- if(ex>BoundX2)
- ex=BoundX2;
- Shy2=Starty;
- ey=Endy-1;
- if(getscreenlen()==25)
- Shside2.i=save_image(Shx2,Shy2,ex,ey,Shside2);
- else
- Shside2.i=save_image(Shx2,Shy2,Shx2,ey,Shside2);
- for(i=Shy2; i<=ey; i++) {
- oScreen::writeshadow(Shx2,i);
- if(ex==Endx+2 && getscreenlen()==25)
- oScreen::writeshadow(ex,i);
- }
- }
- break;
-
- case shBottomleft :
- if(Endy<BoundY2) {
- Shy1=Endy+1;
- ex=Endx-2;
- if(Startx>BoundX) {
- if(getscreenlen()==25)
- Shx1=Startx-2;
- else
- Shx1=Startx-1;
- if(Shx1<BoundX)
- Shx1=BoundX;
- }
- else
- Shx1=Startx;
- Side1=TRUE;
- Shside1.i=save_image(Shx1,Shy1,ex,Shy1,Shside1);
- for(i=Shx1; i<=ex; i++)
- oScreen::writeshadow(i,Shy1);
- }
- if(Startx>BoundX) {
- if(getscreenlen()==25)
- Shx2=Startx-2;
- else
- Shx2=Startx-1;
- if(Shx2<BoundX)
- Shx2=BoundX;
- ex=Startx-1;
- Shy2=Starty+1;
- ey=Endy;
- Side2=TRUE;
- Shside2.i=save_image(Shx2,Shy2,ex,ey,Shside2);
- for(i=Shy2; i<=ey; i++) {
- oScreen::writeshadow(Shx2,i);
- if(Shx2==Startx-2 && getscreenlen()==25)
- oScreen::writeshadow(ex,i);
- }
- }
-
- break;
-
- case shBottomright :
- if(Endy<BoundY2) {
- Shy1=Endy+1;
- Shx1=Startx+2;
- ex=Endx;
- if(Endx<BoundX2) {
- if(getscreenlen()==25)
- ex=Endx+2;
- else
- ex=Endx+1;
- if(ex>BoundX2)
- ex=Endx+1;
- }
- Side1=TRUE;
- Shside1.i=save_image(Shx1,Shy1,ex,Shy1,Shside1);
- for(i=Shx1; i<=ex; i++)
- oScreen::writeshadow(i,Shy1);
- }
- if(Endx<BoundX2) {
- Shx2=Endx+1;
- ex=Endx+2;
- if(ex>BoundX2)
- ex=Shx2;
- Shy2=Starty+1;
- ey=Endy;
- Side2=TRUE;
- if(getscreenlen()==25)
- Shside2.i=save_image(Shx2,Shy2,ex,ey,Shside2);
- else
- Shside2.i=save_image(Shx2,Shy2,Shx2,ey,Shside2);
- for(i=Shy2; i<=ey; i++) {
- oScreen::writeshadow(Shx2,i);
- if(ex==Endx+2 && getscreenlen()==25)
- oScreen::writeshadow(ex,i);
- }
- }
- break;
- }
- }
- }
-
- void oWindow::hideshadow() {
- if(Opened && Shadowed) {
- if(Side1)
- show_image(Shx1,Shy1,Shside1);
- if(Side2)
- show_image(Shx2,Shy2,Shside2);
- }
-
- }
-
-
- int oWindow::onclose() {
- return (((buttonx() >= getleft()+2) &&
- (buttonx() <= getleft()+4) &&
- (buttony() == gettop())));
- }
-
- int oWindow::onexpand() {
- return (((buttonx() >= getright()-4) &&
- (buttonx() <= getright()-2) &&
- (buttony() == gettop())));
- }
-
- int oWindow::ondrag() {
- return ((buttonx() >= getleft()) &&
- (buttonx() <= getright()) &&
- (buttony() == gettop()));
-
- }
-
- int oWindow::onresize() {
- return (buttonx() >= getright()-1 &&
- buttonx() <= getright() &&
- buttony() == getbottom());
-
- }
-
- void oWindow::expandwin() {
- cursoroff();
- if(!Expanded && Opened && Just==mNojust) {
- Expanded=ON;
- Oldx=Startx;
- Oldy=Starty;
- Oldx2=Endx;
- Oldy2=Endy;
- OldLen=Len;
- OldWid=Wid;
- activate_virtual();
- closewin();
- setwindow(BoundX,BoundY,BoundX2-BoundX+1,BoundY2-BoundY+1,FGcolor,BKcolor,Wstyle);
- openwin();
- deactivate_virtual();
- }
- }
-
- void oWindow::contractwin() {
- cursoroff();
- if(Expanded && Opened && Just==mNojust) {
- Expanded=OFF;
- activate_virtual();
- closewin();
- setwindow(Oldx,Oldy,OldWid,OldLen,FGcolor,BKcolor,Wstyle);
- openwin();
- deactivate_virtual();
- }
-
- }
-
- void oWindow::mSizewin() {
-
- int mx,my,mb;
- int ox,oy;
- int Shad,Dir;
-
- if(Canresize && Just==mNojust) {
- activate_virtual();
- Shad=Shadowed;
- Dir=ShadDir;
- closewin();
- setshadow(OFF,shNoshadow);
- openwin();
- mouse::getmouse(mx,my,mb);
- ox=mx;
- oy=my;
- hidemouse();
- while(mb==1) {
- cursoroff();
- display_virtual();
- closewin();
- while(ox==mx && oy==my && mb==1)
- mouse::getmouse(mx,my,mb);
- if(mx<getleft()+MinWid-1) {
- mx=getleft()+MinWid-1;
- setmouse(mx,my);
- }
- if(my<gettop()+MinLen-1) {
- my=gettop()+MinLen-1;
- setmouse(mx,my);
- }
- if(mx>BoundX2) {
- mx=BoundX2;
- setmouse(mx,my);
- }
- if(my>BoundY2) {
- my=BoundY2;
- setmouse(mx,my);
- }
- setwindow(Startx, Starty, mx-Startx+1, my-Starty+1, FGcolor, BKcolor, Wstyle);
- openwin();
- ox=mx;
- oy=my;
- }
- closewin();
- if(getleft()==BoundX && getright()==BoundX2 && gettop()==BoundY &&
- getbottom()==BoundY2)
- Expanded=ON;
- else
- Expanded=OFF;
- setshadow(Shad,Dir);
- openwin();
- deactivate_virtual();
-
- }
- }
-
-
- void oWindow::mDragwin() {
-
- int mx,my,mb;
- int ox,oy;
- int sx,l,w;
- image gag,b;
-
- cursoroff();
-
- if(!Expanded && Candrag && Just==mNojust) {
-
- gag.i=save_image(getleft(),gettop(),getright(),getbottom(),gag);
- activate_virtual();
- closewin();
- b.i=save_image(getleft(),gettop(),getright(),getbottom(),b);
- l=b.len;
- w=b.wid;
- mouse::getmouse(mx,my,mb);
- sx=mx-getleft();
- setmouse(getleft(),gettop());
- mouse::getmouse(mx,my,mb);
- ox=mx;
- oy=my;
- hidemouse();
- while(mb==1) {
- show_image(mx,my,gag);
- display_virtual();
- while(ox==mx && oy==my && mb==1)
- mouse::getmouse(mx,my,mb);
- show_image(ox,oy,b);
- if(mx+w>BoundX2) {
- mx=BoundX2-w+1;
- setmouse(mx,my);
- }
- if(my+l>BoundY2) {
- my=BoundY2-l+1;
- setmouse(mx,my);
- }
- if(mx<BoundX) {
- mx=BoundX;
- setmouse(mx,my);
- }
- if(my<BoundY) {
- my=BoundY;
- setmouse(mx,my);
- }
-
- delete b.i;
- save_image(mx,my,mx+w-1,my+l-1,b);
- ox=mx;
- oy=my;
- }
- delete gag.i;
- delete b.i;
- setwindow(mx,my,w,l,FGcolor,BKcolor,Wstyle);
- openwin();
-
- deactivate_virtual();
-
- setmouse(getleft()+sx,my);
- }
-
- }
-
- int oWindow::handle_key_event() {
-
- switch(getkeycode()) {
- case F1 :
- display_help();
- return cmdHelp;
- break;
-
- case AltF3:
- if(Canclose) {
- closewin();
- return cmdClose;
- }
- break;
-
- case F5 :
- if(Canexpand) {
- if(Expanded) {
- contractwin();
- return cmdContract;
- }
- expandwin();
- return cmdExpand;
- }
- break;
-
- case CtrlF5 :
- //kbDragwin();
- return cmdDrag;
- break;
- }
- return 0;
- }
-
- int oWindow::withinwindow() {
-
- if(buttonx()>Startx && buttonx() < Endx &&
- buttony()>Starty && buttony() < Endy) {
-
- setbuttonx(buttonx()-Startx);
- setbuttony(buttony()-Starty);
- return 1;
-
- }
- return 0;
-
- }
-
- int oWindow::handle_mouse_event() {
-
- if(buttonb()==1) {
- if(withinwindow())
- return cmdWithinwin;
- else
- if(onclose() && Canclose) {
- closewin();
- while(event());
- return cmdClose;
- }
- else
- if(onexpand() && Canexpand) {
- if(Expanded) {
- contractwin();
- while(event());
- return cmdContract;
- }
- else {
- expandwin();
- while(event());
- return cmdExpand;
- }
- }
- else
- if(onresize()) {
- mSizewin();
- return cmdResize;
- }
- else
- if(ondrag()) {
- mDragwin();
- return cmdDrag;
- }
-
-
- }
- return cmdNocmd;
- }
-
- void oWindow::run() {
-
- while(getlastcmd()!=cmdClose)
- handle_events();
- }
-
-
-
- void oWindow::getmouse(int &x, int &y, int &b) {
- int tx,ty,tb;
- mouse::getmouse(tx,ty,tb);
- if(tx>Startx && tx<Endx &&
- ty>Starty && ty<Endy) {
- x=tx-Startx;
- y=ty-Starty;
- b=tb;
- }
- else {
- x=tx;
- y=ty;
- b=tb;
- }
-
- }
-
-
- //
- // window write routines
- //
-
- char *oWindow::makewinstr(int x, int y, char *s, char *t) {
-
-
- t=new char[strlen(s)+1];
- t[0]='\0';
- if(x<Wid-1 && y<Len-1) {
- strcpy(t,s);
- if(x+strlen(t)>Wid-1)
- t[Wid-x-1]='\0';
- }
- return t;
- }
-
- void oWindow::writeat(int x, int y, int fg, int bk, char *str) {
-
- hidemouse();
- if(x<1) x=1;
- if(y<1) y=1;
- char *t;
- t=makewinstr(x,y,str,t);
- if(strlen(t))
- fastwritestr(TxtStartx+x-1,TxtStarty+y-1,(char)fg,(char)bk,t,getvvseg(),getvvofs());
- delete t;
- }
-
- void oWindow::plainwriteat(int x, int y, char *str) {
-
- hidemouse();
- if(x<1) x=1;
- if(y<1) y=1;
- char *t;
- t=makewinstr(x,y,str,t);
- if(strlen(t))
- plainwritestr(TxtStartx+x-1,TxtStarty+y-1,t,getvvseg(),getvvofs());
- delete t;
- }
-
- void oWindow::chwriteat(int x, int y, int fg, int bk, unsigned char c) {
-
- hidemouse();
- if(x<Wid-1 && y<Len-1)
- fastwritech(TxtStartx+x-1,TxtStarty+y-1,(char)fg,(char)bk,c,getvvseg(),getvvofs());
- }
-
- void oWindow::plainchwriteat(int x, int y, unsigned char c) {
-
- hidemouse();
- if(x<Wid-1 && y<Len-1)
- plainwritech(TxtStartx+x-1,TxtStarty+y-1,c,getvvseg(),getvvofs());
- }
-
- void oWindow::writeshadow(int x, int y) {
- hidemouse();
- if(x<Wid-1 && y<Len-1)
- shadowchar(TxtStartx+x-1,TxtStarty+y-1,getvvseg(),getvvofs());
- }
-
- void oWindow::movexy(int x, int y) {
- hidemouse();
- if(x<Wid-1 && y<Len-1)
- oScreen::movexy(TxtStartx+x-1,TxtStarty+y-1);
- else
- cursoroff();
- }
-
- void oWindow::attribln(int y, int x1, int x2, int fg, int bk) {
- hidemouse();
- if(y<Len-1) {
- if(x1>Wid-2) x1=Wid-2;
- if(x2>Wid-2) x2=Wid-2;
- fastattrib(TxtStarty+y-1, TxtStartx+x1-1, TxtStartx+x2-1, (char)fg, (char)bk,getvvseg(),getvvofs());
- }
- }
-
-