Startpunkten

This commit is contained in:
2026-03-05 13:44:23 +01:00
commit adf9f82c8b
26 changed files with 3313 additions and 0 deletions

196
Template_List/twindow.cpp Normal file
View File

@@ -0,0 +1,196 @@
#include <dos.h>
#include <conio.h>
#include <bios.h>
#include <string.h>
#include <ctype.h>
#include "twindow.hpp"
const int MAXX=80;
const int MAXY=25;
const int MINX=0;
const int MINY=0;
class Display
{
public:
typedef unsigned far* ScreenPtr;
static void drawChar(unsigned x,unsigned y, char c, unsigned fg, unsigned bg);
};
void Display::drawChar(unsigned x,unsigned y, char c, unsigned fg, unsigned bg)
{
ScreenPtr display = (ScreenPtr)MK_FP(0xB800,0x0);
display[y*80+x] = (((bg<<4)|fg)<<8)|(c & 255);
}
//=============================================================================
// default constructor: skapar fönstret med vissa koordinater och färger
//-----------------------------------------------------------------------------
TWindow::TWindow()
{
Left=10;Right=18;Bottom=18;Top=15;background=BLUE;foreground=WHITE;
text=NULL;
}
//=============================================================================
// constructor: skapar fönstret med vissa koordinater och färger
//-----------------------------------------------------------------------------
TWindow::TWindow(unsigned left,unsigned top,unsigned right ,unsigned bottom, DColor bg, DColor fg):
Left(left),Right(right),Bottom(bottom),Top(top),background(bg), foreground(fg)
{
theState = 0;//FALSE;
text=NULL;
}
//=============================================================================
// destructor: förstör fönstret
//-----------------------------------------------------------------------------
TWindow::~TWindow()
{
if(isVisible())
hide();
}
//=============================================================================
// hide: gömmer fönstret
//-----------------------------------------------------------------------------
void TWindow::hide()
{
erase();
}
//=============================================================================
// show: visar fönstret
//-----------------------------------------------------------------------------
void TWindow::display()
{
draw();
if(text)
showText();
}
//=============================================================================
// draw: ritar upp fönstret
//-----------------------------------------------------------------------------
void TWindow::draw()
{
theState = 1;//;TRUE;
for(int j= Top; j< Bottom; j++ )
for(int i=Left; i< Right ; i++ ) {
Display::drawChar(i,j,' ',foreground,background);
}
drawBorder();
}
//=============================================================================
// erase: ritar över fönstret med svart
//-----------------------------------------------------------------------------
void TWindow::erase()
{
for(int j= Top; j<= Bottom; j++ )
for(int i=Left; i<= Right ; i++ )
Display::drawChar(i,j,' ',BLACK,BLACK);
theState = 0;//FALSE;
}
//=============================================================================
// drewBorder: ritar ramen runt fönstret
//-----------------------------------------------------------------------------
void TWindow::drawBorder()
{
for(int i=Left+1; i< Right; i++)Display::drawChar(i ,Top , HLine , foreground, background);
for( i=Left+1; i< Right; i++)Display::drawChar(i ,Bottom , HLine , foreground, background);
for( i=Top+1; i< Bottom; i++)Display::drawChar(Left ,i , VLine , foreground, background);
for( i=Top+1; i< Bottom; i++)Display::drawChar(Right ,i , VLine , foreground, background);
Display::drawChar(Left ,Top , LeftTop , foreground, background);
Display::drawChar(Right ,Top ,RightTop , foreground, background);
Display::drawChar(Right ,Bottom ,RightBottom, foreground, background);
Display::drawChar(Left ,Bottom , LeftBottom, foreground, background);
}
void TWindow::move(unsigned relX, unsigned relY)
{
Left=Left+relX;
Right=Right+relX;
Top=Top+relY;
Bottom=Bottom+relY;
}
void TWindow::moveAbs(unsigned x, unsigned y)
{
unsigned width=Right-Left;
unsigned height=Bottom-Top;
Left=x;
Right=x+width;
Top=y;
Bottom=y+height;
}
void TWindow::setText(char* txt)
{
text=new char[strlen(txt)];
strcpy(text, txt);
}
void TWindow::showText()
{
int x=Left+1,y=Top+1;
for(int i=0;i<strlen(text);i++) {
Display::drawChar(x, y, text[i], foreground, background);
if(++x>=Right) {
x=Left+1;
y++;
}
}
}
void TWindow::editText()
{
int i=0;
delete text;
int size=(Right-Left-1)*(Bottom-Top-1);
text=new char[size];
text[0]='\0';
char* buffer=new char[size];
while(((buffer[i]=bioskey(0))!=ENTER)&&(i<size)) {
if(buffer[i]==BACK) {
text[i-1]='\0';
if(--i<0)i=0;
draw();
showText();
}
else if(buffer[i]==ESC) {
delete text;
text=NULL;
draw();
return;
}
else if(isalnum(buffer[i])||buffer[i]==' ') {
text[i]=buffer[i];
text[i+1]='\0';
showText();
i++;
}
}
}
TWindow& TWindow::operator=(TWindow& t)
{
delete text;
text=new char[strlen(t.text)];
strcpy(text, t.text);
return *this;
}
boolean TWindow::operator==(TWindow& t)
{
return strcmp(t.text, text)==0;
}
boolean TWindow::operator<(TWindow& t)
{
return strcmp(text, t.text)<0;
}
boolean TWindow::operator>(TWindow& t)
{
return strcmp(text, t.text)>0;
}
ostream& operator<<(ostream& o, TWindow& t)
{
t.display();
return o;
}
istream& operator>>(istream&i, TWindow& t)
{
t.editText();
return i;
}