Created
January 4, 2012 18:20
-
-
Save andrewrcollins/1561312 to your computer and use it in GitHub Desktop.
#TJHSST ~ Simple "windowing system" from Computer Systems Lab at TJHSST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A "window" unit in C. */ | |
#include <stdio.h> | |
#include <conio.h> | |
#include <string.h> | |
#define HOME 1,1,80,25 | |
#define MAX_WIN 10 | |
#define ACTIVATE 219 | |
#define SINGLE 0 | |
#define DOUBLE 1 | |
#define DOUBLETOP 2 | |
#define SINGLETOP 3 | |
struct | |
{ | |
char Tlc,Lrl,Trc,Blc,Tbl,Brc,Bzc,Rzc; | |
} Border[4] = | |
{ | |
218,196,191,192,179,217,193,180, | |
201,205,187,200,186,188,207,182, | |
213,205,184,212,179,190,207,180, | |
214,196,183,211,186,189,193,182 | |
}; | |
struct Window | |
{ | |
int left,top,right,bottom,border,curx,cury; | |
void *scrsave; | |
}; | |
struct Window_Stack | |
{ | |
struct Window *first,*current; | |
} Windows; | |
int winborder(),wininit(),winkill(),winopen(),winclose(),winresize(), | |
winresizex(),winresizey(),mcputs()/*winmove()*/; | |
int winborder(left,top,right,bottom,border) | |
int left,top,right,bottom,border; | |
{ | |
int i; | |
window(HOME); | |
gotoxy(right,bottom); | |
if((wherex()!=right)||(wherey()!=bottom)) return -1; | |
gotoxy(left,top); | |
if((wherex()!=left)||(wherey()!=top)) return -1; | |
putch(Border[border].Tlc); | |
for(i=(left+1);i<=(right-1);i++) putch(Border[border].Lrl); | |
putch(Border[border].Trc); | |
for(i=(top+1);i<=(bottom-1);i++) { | |
gotoxy(left,i); | |
putch(Border[border].Tbl); | |
if(i<=(bottom-3)) { | |
gotoxy(right,i); | |
putch(Border[border].Tbl); | |
} | |
else { | |
if(i==(bottom-2)) { | |
gotoxy(right-1,i); | |
putch((char)218); | |
putch(Border[border].Rzc); | |
} | |
if(i==(bottom-1)) { | |
gotoxy(right-2,i); | |
putch((char)218); | |
putch(ACTIVATE); | |
putch(Border[border].Rzc); | |
} | |
} | |
} | |
gotoxy(left,bottom); | |
putch(Border[border].Blc); | |
for(i=(left+1);i<=(right-3);i++) putch(Border[border].Lrl); | |
putch(Border[border].Bzc); | |
putch(Border[border].Bzc); | |
if((wherex()!=79)&&(wherey()!=25)) putch(Border[border].Brc); | |
return 1; | |
} | |
int wininit(void) | |
{ | |
struct text_info win_stats; | |
Windows.first=(struct Window *) malloc((MAX_WIN)*sizeof(struct Window)); | |
if(!Windows.first) return -1; | |
Windows.current=Windows.first; | |
gettextinfo(&win_stats); | |
Windows.first->left=win_stats.winleft-1; | |
Windows.first->right=win_stats.winright+1; | |
Windows.first->top=win_stats.wintop-1; | |
Windows.first->bottom=win_stats.winbottom+1; | |
Windows.first->border=0; | |
Windows.first->scrsave=NULL; | |
return 1; | |
} | |
int winkill(void) | |
{ | |
Windows.current=Windows.first; | |
free(Windows.first); | |
Windows.current=Windows.first=NULL; | |
return 1; | |
} | |
int winopen(left,top,right,bottom,border_type) | |
int left,top,right,bottom,border_type; | |
{ | |
Windows.current->curx=wherex(); | |
Windows.current->cury=wherey(); | |
Windows.current++; | |
if(Windows.current==(Windows.first+(MAX_WIN))) return -1; | |
Windows.current->left=left; | |
Windows.current->top=top; | |
Windows.current->right=right; | |
Windows.current->bottom=bottom; | |
Windows.current->border=border_type; | |
Windows.current->scrsave=NULL; | |
Windows.current->scrsave=(char *) malloc((right-left+1)*(bottom-top+1)*2); | |
hide(); | |
gettext(left,top,right,bottom,Windows.current->scrsave); | |
window(left+1,top+1,right-1,bottom-1); | |
clrscr(); | |
winborder(left,top,right,bottom,border_type); | |
window(left+1,top+1,right-1,bottom-1); | |
show(); | |
return 1; | |
} | |
int winclose(void) | |
{ | |
if(Windows.current==Windows.first) return -1; | |
hide(); | |
puttext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
free(Windows.current->scrsave); | |
Windows.current->scrsave=NULL; | |
Windows.current--; | |
window((Windows.current->left)+1,(Windows.current->top)+1, | |
(Windows.current->right)-1,(Windows.current->bottom)-1); | |
gotoxy(Windows.current->curx,Windows.current->cury); | |
show(); | |
return 1; | |
} | |
int winresize(void) | |
{ | |
int tx,ty; | |
while(mouseb()) { | |
if(mousech()) { | |
tx=mousex(); | |
ty=mousey(); | |
if((tx>(Windows.current->left+3))&&(ty>(Windows.current->top+3))) { | |
hide(); | |
puttext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
Windows.current->scrsave=(char *) realloc(Windows.current->scrsave, | |
(tx-Windows.current->left+2)*(ty-Windows.current->top+2)*2); | |
gettext(Windows.current->left,Windows.current->top, | |
tx+1,ty+1,Windows.current->scrsave); | |
window(Windows.current->left+1,Windows.current->top+1,tx+1,ty+1); | |
clrscr(); | |
winborder(Windows.current->left,Windows.current->top,tx+1,ty+1, | |
Windows.current->border); | |
window(Windows.current->left+1,Windows.current->top+1,tx-1,ty-1); | |
Windows.current->bottom=ty+1; | |
Windows.current->right=tx+1; | |
show(); | |
} | |
} | |
} | |
} | |
int winresizex(void) | |
{ | |
return Windows.current->right-1; | |
} | |
int winresizey(void) | |
{ | |
return Windows.current->bottom-1; | |
} | |
int move(void) | |
{ | |
int tx,ty; | |
while(mouseb()) { | |
if(mousech()) { | |
hide(); | |
gettext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
puttext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
show(); | |
} | |
} | |
} | |
int mcputs(str) | |
const char *str; | |
{ | |
int tmp; | |
hide(); | |
tmp=cputs(str); | |
show(); | |
return tmp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A true attempt at making a window program. | |
Seriously. Yes. First verion does seem to work. | |
Schedule for this program : | |
Over the nest week starting Tue and wrapping around to Sun. | |
AM PM | |
Sun þ--------------------------þ | |
Mon þ------------þ | |
Tue þ-------þ | |
Wed þ------------þ | |
Thu þ--þ | |
Fri þ------------þ | |
Sat þ--------þ | |
*/ | |
#include <stdio.h> | |
#include <conio.h> | |
struct BORDER | |
{ | |
char ulc,lrl,urc,dlc,udl,drc; | |
} sline,dline; | |
struct WINDOW | |
{ | |
int ulx,uly,drx,dry; | |
void *scr; | |
char message[255]; | |
struct BORDER border; | |
} | |
main() | |
{ | |
struct WINDOW test; | |
sline.ulc=218; | |
sline.lrl=196; | |
sline.urc=191; | |
sline.dlc=192; | |
sline.udl=179; | |
sline.drc=217; | |
dline.ulc=201; | |
dline.lrl=205; | |
dline.urc=187; | |
dline.dlc=200; | |
dline.udl=186; | |
dline.drc=188; | |
test.ulx=5; | |
test.uly=5; | |
test.drx=15; | |
test.dry=15; | |
test.border=dline; | |
gets(test.message); | |
open(test); | |
} | |
int open(w) | |
struct WINDOW w; | |
{ | |
register i; | |
w.scr=(char *) malloc(((w.drx-w.ulx)*(w.dry-w.uly)*2)); | |
gettext(w.ulx,w.uly,w.drx,w.dry,w.scr); | |
gotoxy(w.ulx,w.uly); | |
putch(w.border.ulc); | |
for (i=1;i<(w.drx-w.ulx);++i) | |
putch(w.border.lrl); | |
putch(w.border.urc); | |
for (i=1;i<(w.dry-w.uly);++i) | |
{ | |
gotoxy(w.ulx,w.uly+i); | |
putch(w.border.udl); | |
gotoxy(w.drx,w.uly+i); | |
putch(w.border.udl); | |
} | |
gotoxy(w.ulx,w.dry); | |
putch(w.border.dlc); | |
for (i=1;i<(w.drx-w.ulx);++i) | |
putch(w.border.lrl); | |
putch(w.border.drc); | |
window((w.ulx+1),(w.uly+1),(w.drx-1),(w.dry-1)); | |
clrscr(); | |
cputs(w.message); | |
getche(); | |
puttext(w.ulx,w.uly,w.drx,w.dry,w.scr); | |
free(w.scr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A true attempt at making a window program. | |
Seriously. Yes. | |
First verion does seem to work. | |
Second version. Add an array of WINDOW. | |
*/ | |
#include <stdio.h> | |
#include <conio.h> | |
struct BORDER | |
{ | |
char ulc,lrl,urc,dlc,udl,drc; | |
} line[2]; | |
struct WINDOW | |
{ | |
int ulx,uly,drx,dry,border; | |
void *scr; | |
char *message; | |
} | |
main() | |
{ | |
struct WINDOW test[2]; | |
register i; | |
line[0].ulc=218; | |
line[0].lrl=196; | |
line[0].urc=191; | |
line[0].dlc=192; | |
line[0].udl=179; | |
line[0].drc=217; | |
line[1].ulc=201; | |
line[1].lrl=205; | |
line[1].urc=187; | |
line[1].dlc=200; | |
line[1].udl=186; | |
line[1].drc=188; | |
for(i=0;i<2;++i) | |
{ | |
test[i].ulx=5*(i+1); | |
test[i].uly=5; | |
test[i].drx=15*(i+1); | |
test[i].dry=15; | |
test[i].border=1; | |
test[i].message="Hello"; | |
open(&test[i]); | |
} | |
for(i=1;i>-1;--i) | |
close(&test[i]); | |
} | |
int open(struct WINDOW *w) | |
{ | |
register i; | |
window(1,1,80,25); | |
w->scr=(char *) malloc(((w->drx-w->ulx)*(w->dry-w->uly)*2)); | |
gettext(w->ulx,w->uly,w->drx,w->dry,w->scr); | |
gotoxy(w->ulx,w->uly); | |
putch(line[w->border].ulc); | |
for (i=1;i<(w->drx-w->ulx);++i) | |
putch(line[w->border].lrl); | |
putch(line[w->border].urc); | |
for (i=1;i<(w->dry-w->uly);++i) | |
{ | |
gotoxy(w->ulx,w->uly+i); | |
putch(line[w->border].udl); | |
gotoxy(w->drx,w->uly+i); | |
putch(line[w->border].udl); | |
} | |
gotoxy(w->ulx,w->dry); | |
putch(line[w->border].dlc); | |
for (i=1;i<(w->drx-w->ulx);++i) | |
putch(line[w->border].lrl); | |
putch(line[w->border].drc); | |
window((w->ulx+1),(w->uly+1),(w->drx-1),(w->dry-1)); | |
clrscr(); | |
cputs(w->message); | |
} | |
int close(struct WINDOW *w) | |
{ | |
getche(); | |
puttext(w->ulx,w->uly,w->drx,w->dry,w->scr); | |
free(w->scr); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A true attempt at making a window program. | |
Seriously. Yes. | |
First verion does seem to work. | |
Second version. Add an array of WINDOW. | |
Third Version. Work on pointer problems. | |
*/ | |
#include <stdio.h> | |
#include <conio.h> | |
struct BORDER | |
{ | |
char ulc,lrl,urc,dlc,udl,drc; | |
} line[2] = | |
{ | |
218,196,191,192,179,217, | |
201,205,187,200,186,188 | |
}; | |
struct WINDOW | |
{ | |
int ulx,uly,drx,dry,border; | |
void *scr; | |
char *message; | |
}; | |
void border(); | |
int open(); | |
int close(); | |
main() | |
{ | |
struct WINDOW test[3]; | |
register i; | |
for(i=0;i<=2;++i) | |
{ | |
test[i].ulx=1+(i*5); | |
test[i].uly=1+(i*5); | |
test[i].drx=5+(i*10); | |
test[i].dry=5+(i*7); | |
test[i].border=i; | |
strcpy(test[i].message,"Hello"); | |
open(&test[i]); | |
getche(); | |
} | |
for(i=2;i>=0;--i) { | |
getche(); | |
close(&test[i]); | |
window(1,1,80,25); | |
} | |
} | |
int open(struct WINDOW *w) | |
{ | |
register i; | |
window(1,1,80,25); | |
w->scr=NULL; | |
w->scr=(char *) malloc(((((w->drx)-(w->ulx))*((w->dry)-(w->uly)))*2)); | |
gettext(w->ulx,w->uly,w->drx,w->dry,w->scr); | |
border((w->ulx),(w->uly),(w->drx),(w->dry)); | |
window((w->ulx+1),(w->uly+1),(w->drx-1),(w->dry-1)); | |
clrscr(); | |
cputs(w->message); | |
} | |
int close(struct WINDOW *w) | |
{ | |
window((w->ulx+1),(w->uly+1),(w->drx-1),(w->dry-1)); | |
puttext(w->ulx,w->uly,w->drx,w->dry,w->scr); | |
free(w->scr); | |
} | |
void border(left,up,right,down) | |
int left,up,right,down; | |
{ | |
int i; | |
gotoxy(left,up); | |
putch(218); | |
for(i=(left+1);i<=(right-1);i++) putch(196); | |
putch(191); | |
for(i=(up+1);i<=(down-1);i++) { | |
gotoxy(left,i); | |
putch(179); | |
gotoxy(right,i); | |
putch(179); | |
} | |
gotoxy(left,down); | |
putch(192); | |
for(i=(left+1);i<=(right-1);i++) putch(196); | |
putch(217); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A true attempt at making a window program. | |
Seriously. Yes. | |
By Andy Collins | |
Debug help from Jon Blocksom. | |
First verion does seem to work. | |
Second version. Add an array of Window. | |
Third Version. Work on pointer problems. | |
Fourth Version. Jon fixed the problem. Now add a Window Stack. | |
Fifth Version. Work out probs with stack-ing the program. | |
*/ | |
#include <stdio.h> | |
#include <conio.h> | |
#define HOME 1,1,80,25 | |
#define MAX_WIN 10 | |
struct | |
{ | |
char ulc,lrl,urc,dlc,udl,drc; | |
} Border[2] = | |
{ | |
218,196,191,192,179,217, | |
201,205,187,200,186,188 | |
}; | |
struct Window | |
{ | |
int left,up,right,down,border,scx,scy; | |
void *save; | |
char *message; | |
}; | |
struct Window_Stack | |
{ | |
struct Window *first,*current; | |
} windows; | |
void init(),kill(),border(); | |
int open(),close(); | |
main() | |
{ | |
register i; | |
init(); | |
for(i=1;i<2000;i++) putch('A'); | |
open(3,3,78,23,0,"This is truly a test."); | |
getche(); | |
open(10,10,70,15,1,"Whoa DUDE!"); | |
getche(); | |
close(); | |
close(); | |
kill(); | |
} | |
void border(left,up,right,down,border) | |
int left,up,right,down,border; | |
{ | |
int i; | |
gotoxy(left,up); | |
putch(Border[border].ulc); | |
for(i=(left+1);i<=(right-1);i++) putch(Border[border].lrl); | |
putch(Border[border].urc); | |
for(i=(up+1);i<=(down-1);i++) { | |
gotoxy(left,i); | |
putch(Border[border].udl); | |
gotoxy(right,i); | |
putch(Border[border].udl); | |
} | |
gotoxy(left,down); | |
putch(Border[border].dlc); | |
for(i=(left+1);i<=(right-1);i++) putch(Border[border].lrl); | |
putch(Border[border].drc); | |
} | |
void init(void) | |
{ | |
windows.first=(struct Window *) malloc((MAX_WIN)*sizeof(struct Window)); | |
windows.current=windows.first; | |
windows.current->left=0; | |
windows.current->right=81; | |
windows.current->up=0; | |
windows.current->down=26; | |
windows.current->border=0; | |
windows.current->scx=1; | |
windows.current->scy=1; | |
windows.current->save=NULL; | |
strcpy(windows.current->message,""); | |
} | |
void kill(void) | |
{ | |
windows.current=windows.first; | |
free(windows.first); | |
} | |
int open(left,up,right,down,border_type,message) | |
int left,up,right,down,border_type; | |
char *message; | |
{ | |
register i; | |
windows.current->scx=wherex(); | |
windows.current->scy=wherey(); | |
windows.current++; | |
if(windows.current==(windows.first+(MAX_WIN))) return; | |
windows.current->left=left; | |
windows.current->up=up; | |
windows.current->right=right; | |
windows.current->down=down; | |
windows.current->border=border_type; | |
strcpy(windows.current->message,message); | |
windows.current->save=(char *) malloc((((right-left)+1)*((down-up)+1))*2); | |
gettext(left,up,right,down,windows.current->save); | |
window(HOME); | |
border(left,up,right,down,border_type); | |
window(left+1,up+1,right-1,down-1); | |
clrscr(); | |
cputs(message); | |
} | |
int close() | |
{ | |
if(windows.current==windows.first) return; | |
puttext(windows.current->left,windows.current->up, | |
windows.current->right,windows.current->down, | |
windows.current->save); | |
free(windows.current->save); | |
windows.current--; | |
window((windows.current->left)+1,(windows.current->up)+1, | |
(windows.current->right)-1,(windows.current->down)-1); | |
gotoxy(windows.current->scx,windows.current->scy); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A true attempt at making a window program. | |
Seriously. Yes. | |
By Andy Collins | |
Debug help from Jon Blocksom. | |
First verion does seem to work. | |
Second version. Add an array of Window. | |
Third Version. Work on pointer problems. | |
Fourth Version. Jon fixed the problem. Now add a Window Stack. | |
Fifth Version. Fixed probs with stack and am now changing prog purpose. | |
Recreate the 'SunView' system of windowing. Difficult, but hah! | |
*/ | |
#include <stdio.h> | |
#include <conio.h> | |
#define HOME 1,1,80,25 | |
#define MAX_WIN 10 | |
struct | |
{ | |
char ulc,lrl,urc,dlc,udl,drc; | |
} Border[2] = | |
{ | |
218,196,191,192,179,217, | |
201,205,187,200,186,188 | |
}; | |
struct Window | |
{ | |
int left,up,right,down,border,scx,scy; | |
void *save; | |
char message[255]; | |
}; | |
struct Window_Stack | |
{ | |
struct Window *first,*current; | |
} windows; | |
void init(),kill(),border(); | |
int open(),close(); | |
main() | |
{ | |
register i; | |
init(); | |
for(i=1;i<2000;i++) putch('A'); | |
open(3,3,78,23,0,"This is truly a test."); | |
getche(); | |
open(10,10,70,15,1,"Whoa DUDE!"); | |
getche(); | |
close(); | |
close(); | |
kill(); | |
} | |
void border(left,up,right,down,border) | |
int left,up,right,down,border; | |
{ | |
int i; | |
gotoxy(left,up); | |
putch(Border[border].ulc); | |
for(i=(left+1);i<=(right-1);i++) putch(Border[border].lrl); | |
putch(Border[border].urc); | |
for(i=(up+1);i<=(down-1);i++) { | |
gotoxy(left,i); | |
putch(Border[border].udl); | |
gotoxy(right,i); | |
putch(Border[border].udl); | |
} | |
gotoxy(left,down); | |
putch(Border[border].dlc); | |
for(i=(left+1);i<=(right-1);i++) putch(Border[border].lrl); | |
putch(Border[border].drc); | |
} | |
void init(void) | |
{ | |
windows.first=(struct Window *) malloc((MAX_WIN)*sizeof(struct Window)); | |
windows.current=windows.first; | |
windows.first->left=0; | |
windows.first->right=81; | |
windows.first->up=0; | |
windows.first->down=26; | |
windows.first->border=0; | |
windows.first->scx=1; | |
windows.first->scy=1; | |
windows.first->save=NULL; | |
strcpy(windows.current->message,""); | |
} | |
void kill(void) | |
{ | |
windows.current=windows.first; | |
free(windows.first); | |
windows.current=windows.first=NULL; | |
} | |
int open(left,up,right,down,border_type,message) | |
int left,up,right,down,border_type; | |
char *message; | |
{ | |
register i; | |
windows.current->scx=wherex(); | |
windows.current->scy=wherey(); | |
windows.current++; | |
if(windows.current==(windows.first+(MAX_WIN))) return -1; | |
windows.current->left=left; | |
windows.current->up=up; | |
windows.current->right=right; | |
windows.current->down=down; | |
windows.current->border=border_type; | |
strcpy(windows.current->message,message); | |
windows.current->save=NULL; | |
windows.current->save=(char *) malloc((right-left+1)*(down-up+1)*2); | |
gettext(left,up,right,down,windows.current->save); | |
window(HOME); | |
border(left,up,right,down,border_type); | |
window(left+1,up+1,right-1,down-1); | |
clrscr(); | |
cputs(message); | |
return 1; | |
} | |
int close() | |
{ | |
if(windows.current==windows.first) return -1; | |
puttext(windows.current->left,windows.current->up, | |
windows.current->right,windows.current->down, | |
windows.current->save); | |
free(windows.current->save); | |
windows.current->save=NULL; | |
windows.current--; | |
window((windows.current->left)+1,(windows.current->up)+1, | |
(windows.current->right)-1,(windows.current->down)-1); | |
gotoxy(windows.current->scx,windows.current->scy); | |
return 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A true attempt at making a window program. | |
Seriously. Yes. | |
By Andy Collins | |
Debug help from Jon Blocksom. | |
First verion does seem to work. | |
Second version. Add an array of Window. | |
Third Version. Work on pointer problems. | |
Fourth Version. Jon fixed the problem. Now add a Window Stack. | |
Fifth Version. Fixed probs with stack and am now changing prog purpose. | |
Recreate the 'SunView' system of windowing. Difficult, but hah! | |
Sixth Version. Resizing Windows is the first step to this. Also start using | |
the mouse as input device. | |
*/ | |
#include <stdio.h> | |
#include <conio.h> | |
#include <string.h> | |
#include "mouse.c" | |
#define HOME 1,1,80,25 | |
#define MAX_WIN 10 | |
struct | |
{ | |
char Tlc,Lrl,Trc,Blc,Tbl,Brc; | |
} Border[4] = | |
{ | |
218,196,191,192,179,254, | |
201,205,187,200,186,254, | |
213,205,184,212,179,254, | |
214,196,183,211,186,254 | |
}; | |
struct Window | |
{ | |
int left,top,right,bottom,border,curx,cury; | |
void *scrsave; | |
}; | |
struct Window_Stack | |
{ | |
struct Window *first,*current; | |
} Windows; | |
int border(),init(),kill(),open(),close(),resize()/*,move()*/,mcputs(); | |
main() | |
{ | |
char ha[2]; | |
init(); | |
show(); | |
open(3,3,78,23,2); | |
mcputs("Hah!"); | |
while(!mouseb()); | |
open(10,10,70,15,3); | |
mcputs("Hee!"); | |
while(mouseb()!=7) { | |
if(mouseb()==1) { | |
switch(mousec()) { | |
case (char)254: | |
resize(); | |
/* break; | |
case 240: | |
move();*/ | |
} | |
} | |
} | |
close(); | |
close(); | |
hide(); | |
kill(); | |
} | |
int border(left,top,right,bottom,border) | |
int left,top,right,bottom,border; | |
{ | |
int i; | |
gotoxy(right,bottom); | |
if((wherex()!=right)||(wherey()!=bottom)) return -1; | |
gotoxy(left,top); | |
if((wherex()!=left)||(wherey()!=top)) return -1; | |
putch(Border[border].Tlc); | |
for(i=(left+1);i<=(right-1);i++) putch(Border[border].Lrl); | |
putch(Border[border].Trc); | |
for(i=(top+1);i<=(bottom-1);i++) { | |
gotoxy(left,i); | |
putch(Border[border].Tbl); | |
gotoxy(right,i); | |
putch(Border[border].Tbl); | |
} | |
gotoxy(left,bottom); | |
putch(Border[border].Blc); | |
for(i=(left+1);i<=(right-1);i++) putch(Border[border].Lrl); | |
putch(Border[border].Brc); | |
return 1; | |
} | |
int init(void) | |
{ | |
struct text_info win_stats; | |
Windows.first=(struct Window *) malloc((MAX_WIN)*sizeof(struct Window)); | |
if(!Windows.first) return -1; | |
Windows.current=Windows.first; | |
gettextinfo(&win_stats); | |
Windows.first->left=win_stats.winleft-1; | |
Windows.first->right=win_stats.winright+1; | |
Windows.first->top=win_stats.wintop-1; | |
Windows.first->bottom=win_stats.winbottom+1; | |
Windows.first->border=0; | |
Windows.first->scrsave=NULL; | |
return 1; | |
} | |
int kill(void) | |
{ | |
Windows.current=Windows.first; | |
free(Windows.first); | |
Windows.current=Windows.first=NULL; | |
return 1; | |
} | |
int open(left,top,right,bottom,border_type) | |
int left,top,right,bottom,border_type; | |
{ | |
Windows.current->curx=wherex(); | |
Windows.current->cury=wherey(); | |
Windows.current++; | |
if(Windows.current==(Windows.first+(MAX_WIN))) return -1; | |
Windows.current->left=left; | |
Windows.current->top=top; | |
Windows.current->right=right; | |
Windows.current->bottom=bottom; | |
Windows.current->border=border_type; | |
Windows.current->scrsave=NULL; | |
Windows.current->scrsave=(char *) malloc((right-left+1)*(bottom-top+1)*2); | |
hide(); | |
gettext(left,top,right,bottom,Windows.current->scrsave); | |
window(HOME); | |
border(left,top,right,bottom,border_type); | |
window(left+1,top+1,right-1,bottom-1); | |
clrscr(); | |
show(); | |
return 1; | |
} | |
int close(void) | |
{ | |
if(Windows.current==Windows.first) return -1; | |
hide(); | |
puttext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
free(Windows.current->scrsave); | |
Windows.current->scrsave=NULL; | |
Windows.current--; | |
window((Windows.current->left)+1,(Windows.current->top)+1, | |
(Windows.current->right)-1,(Windows.current->bottom)-1); | |
gotoxy(Windows.current->curx,Windows.current->cury); | |
show(); | |
return 1; | |
} | |
int resize(void) | |
{ | |
int tx,ty; | |
while(mouseb()==1) { | |
tx=mousex(); | |
ty=mousey(); | |
hide(); | |
puttext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
Windows.current->scrsave=(char *) realloc(Windows.current->scrsave, | |
(tx-Windows.current->left+1)*(ty-Windows.current->top+1)*2); | |
gettext(Windows.current->left,Windows.current->top, | |
tx,ty,Windows.current->scrsave); | |
border(Windows.current->left,Windows.current->top,tx,ty); | |
Windows.current->bottom=ty; | |
Windows.current->right=tx; | |
show(); | |
} | |
} | |
/*int move(void) | |
{ | |
int tx,ty; | |
while(mouseb()==1) { | |
tx=mousex(); | |
ty=mousey(); | |
hide(); | |
gettext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
puttext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave);*/ | |
int mcputs(str) | |
const char *str; | |
{ | |
int tmp; | |
hide(); | |
tmp=cputs(str); | |
show(); | |
return tmp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A true attempt at making a window program. | |
Seriously. Yes. | |
By Andy Collins | |
Debug help from Jon Blocksom. | |
First verion does seem to work. | |
Second version. Add an array of Window. | |
Third Version. Work on pointer problems. | |
Fourth Version. Jon fixed the problem. Now add a Window Stack. | |
Fifth Version. Fixed probs with stack and am now changing prog purpose. | |
Recreate the 'SunView' system of windowing. Difficult, but hah! | |
Sixth Version. Resizing Windows is the first step to this. Also start using | |
the mouse as input device. | |
*/ | |
#include <stdio.h> | |
#include <conio.h> | |
#include <string.h> | |
#include "mouse.c" | |
#define HOME 1,1,80,25 | |
#define MAX_WIN 10 | |
struct | |
{ | |
char Tlc,Lrl,Trc,Blc,Tbl,Brc; | |
} Border[4] = | |
{ | |
218,196,191,192,179,254, | |
201,205,187,200,186,254, | |
213,205,184,212,179,254, | |
214,196,183,211,186,254 | |
}; | |
struct Window | |
{ | |
int left,top,right,bottom,border,curx,cury; | |
void *scrsave; | |
}; | |
struct Window_Stack | |
{ | |
struct Window *first,*current; | |
} Windows; | |
int border(),init(),kill(),open(),close(),resize()/*,move()*/,mcputs(); | |
main() | |
{ | |
char ha[2]; | |
init(); | |
show(); | |
killcurs(); | |
open(3,3,78,23,2); | |
mcputs("Hah!"); | |
while(!mouseb()); | |
open(10,10,70,15,3); | |
mcputs("Hee!"); | |
while(!kbhit()) { | |
if(mouseb()==1) { | |
switch(mousec()) { | |
case (char)254: | |
resize(); | |
/* break; | |
case 240: | |
move();*/ | |
} | |
} | |
} | |
close(); | |
while(!mouseb()); | |
close(); | |
findcurs(); | |
hide(); | |
kill(); | |
} | |
int border(left,top,right,bottom,border) | |
int left,top,right,bottom,border; | |
{ | |
int i; | |
window(HOME); | |
gotoxy(right,bottom); | |
if((wherex()!=right)||(wherey()!=bottom)) return -1; | |
gotoxy(left,top); | |
if((wherex()!=left)||(wherey()!=top)) return -1; | |
putch(Border[border].Tlc); | |
for(i=(left+1);i<=(right-1);i++) putch(Border[border].Lrl); | |
putch(Border[border].Trc); | |
for(i=(top+1);i<=(bottom-1);i++) { | |
gotoxy(left,i); | |
putch(Border[border].Tbl); | |
gotoxy(right,i); | |
putch(Border[border].Tbl); | |
} | |
gotoxy(left,bottom); | |
putch(Border[border].Blc); | |
for(i=(left+1);i<=(right-1);i++) putch(Border[border].Lrl); | |
if((wherex()!=79)&&(wherey()!=25)) putch(Border[border].Brc); | |
return 1; | |
} | |
int init(void) | |
{ | |
struct text_info win_stats; | |
Windows.first=(struct Window *) malloc((MAX_WIN)*sizeof(struct Window)); | |
if(!Windows.first) return -1; | |
Windows.current=Windows.first; | |
gettextinfo(&win_stats); | |
Windows.first->left=win_stats.winleft-1; | |
Windows.first->right=win_stats.winright+1; | |
Windows.first->top=win_stats.wintop-1; | |
Windows.first->bottom=win_stats.winbottom+1; | |
Windows.first->border=0; | |
Windows.first->scrsave=NULL; | |
return 1; | |
} | |
int kill(void) | |
{ | |
Windows.current=Windows.first; | |
free(Windows.first); | |
Windows.current=Windows.first=NULL; | |
return 1; | |
} | |
int open(left,top,right,bottom,border_type) | |
int left,top,right,bottom,border_type; | |
{ | |
Windows.current->curx=wherex(); | |
Windows.current->cury=wherey(); | |
Windows.current++; | |
if(Windows.current==(Windows.first+(MAX_WIN))) return -1; | |
Windows.current->left=left; | |
Windows.current->top=top; | |
Windows.current->right=right; | |
Windows.current->bottom=bottom; | |
Windows.current->border=border_type; | |
Windows.current->scrsave=NULL; | |
Windows.current->scrsave=(char *) malloc((right-left+1)*(bottom-top+1)*2); | |
hide(); | |
gettext(left,top,right,bottom,Windows.current->scrsave); | |
border(left,top,right,bottom,border_type); | |
window(left+1,top+1,right-1,bottom-1); | |
clrscr(); | |
show(); | |
return 1; | |
} | |
int close(void) | |
{ | |
if(Windows.current==Windows.first) return -1; | |
hide(); | |
puttext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
free(Windows.current->scrsave); | |
Windows.current->scrsave=NULL; | |
Windows.current--; | |
window((Windows.current->left)+1,(Windows.current->top)+1, | |
(Windows.current->right)-1,(Windows.current->bottom)-1); | |
gotoxy(Windows.current->curx,Windows.current->cury); | |
show(); | |
return 1; | |
} | |
int resize(void) | |
{ | |
int tx,ty; | |
while(mouseb()) { | |
if(mousech()) { | |
tx=mousex(); | |
ty=mousey(); | |
if((tx>(Windows.current->left+1))&&(ty>(Windows.current->top+1))) { | |
hide(); | |
puttext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
Windows.current->scrsave=(char *) realloc(Windows.current->scrsave, | |
(tx-Windows.current->left+1)*(ty-Windows.current->top+1)*2); | |
gettext(Windows.current->left,Windows.current->top, | |
tx,ty,Windows.current->scrsave); | |
border(Windows.current->left,Windows.current->top,tx,ty, | |
Windows.current->border); | |
window(Windows.current->left+1,Windows.current->top+1,tx-1,ty-1); | |
clrscr(); | |
Windows.current->bottom=ty; | |
Windows.current->right=tx; | |
show(); | |
} | |
} | |
} | |
} | |
/*int move(void) | |
{ | |
int tx,ty; | |
while(mouseb()==1) { | |
tx=mousex(); | |
ty=mousey(); | |
hide(); | |
gettext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave); | |
puttext(Windows.current->left,Windows.current->top, | |
Windows.current->right,Windows.current->bottom, | |
Windows.current->scrsave);*/ | |
int mcputs(str) | |
const char *str; | |
{ | |
int tmp; | |
hide(); | |
tmp=cputs(str); | |
show(); | |
return tmp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* A windows test program. */ | |
#include <stdio.h> | |
#include <conio.h> | |
#include <string.h> | |
#include "window.c" | |
#define MOVE 196 | |
#define ACTIVATE 219 | |
main() | |
{ | |
wininit(); | |
hlimit(2,79); | |
vlimit(2,24); | |
show(); | |
killcurs(); | |
winopen(3,3,78,23,2); | |
while(!mouseb()) mcputs("Hah!"); | |
winopen(10,10,70,15,3); | |
mcputs("Hee!"); | |
while(mouseb()!=7) { | |
if(mouseb()==1) { | |
switch(mousec()) { | |
case ACTIVATE: | |
if((mousex()==winresizex())&&(mousey()==winresizey())) | |
winresize(); | |
break; | |
case MOVE: | |
move(); | |
break; | |
} | |
} | |
} | |
winclose(); | |
while(mouseb()!=4) { | |
if(mouseb()==1) { | |
switch(mousec()) { | |
case ACTIVATE: | |
if((mousex()==winresizex())&&(mousey()==winresizey())) | |
winresize(); | |
break; | |
case MOVE: | |
move(); | |
break; | |
} | |
} | |
} | |
winclose(); | |
findcurs(); | |
hide(); | |
winkill(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Set of C programs found on old 5.25 floppy disks from when I was a nerd at Thomas Jefferson High School for Science and Technology in the computer systems lab between 1988 and 1992.
It is a simple "windowing system."
https://gist.github.com/1561312#file_windowtest.c
It is worthy of note that Jon Blocksom helped debug a pointer problem.
http://twitter.com/jblocksom
See
https://gist.github.com/1561312#file_window4.c
https://gist.github.com/1561312#file_window5.c
https://gist.github.com/1561312#file_window6.c
https://gist.github.com/1561312#file_window7.c
Anyone can do whatever they'd like to with them--if anything.
I remain a nerd.