//MiniOS Version 1.0
//Created By: Joshua Nixon
//Greets: Raemar(Coding Concepts), Blake Royer(Snake Game)
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
class MiniOS
{
 private:
 //This will hold the attribute for the window
 struct WndAttribute
  {
   int WndSize;//Size of the window in memory
   int WndX1;//The X1 coordinate(Top Right)
   int WndY1;//The Y1 coordinate(Top Right)
   int WndX2;//The X2 coordinate(Bottom Left)
   int WndY2;//The Y2 coordinate(Bottom Left)
   int WndStyle;//How window will appear to user
   int WndFcColor;//Window on Focus Color
   int WndLFcColor;//Window on Lost Focus Color
   int WndBackGrd;//Color of the windows background
   //Icons Later add..
   int WndTitleLine;//The color of the lines on the title bar
  };

 //We need the exact same kind of struct to hold the coordinates and info in mem
 struct BackBuff
  {
   int WndSize;//Size of the window in memory
   int WndX1;//The X1 coordinate(Top Right)
   int WndY1;//The Y1 coordinate(Top Right)
   int WndX2;//The X2 coordinate(Bottom Left)
   int WndY2;//The Y2 coordinate(Bottom Left)
   int WndStyle;//How window will appear to user
   int WndFcColor;//Window on Focus Color
   int WndLFcColor;//Window on Lost Focus Color
   int WndBackGrd;//Color of the windows background
   //Icons Later add..
   int WndTitleLine;//The color of the lines on the title bar
  };


 //This will hold the quality (esstentail quality)
 struct WndQuality
  {
   char* WndName;//The window name in memory will work like a handle;
   char* WndCaption;//The windows Title Bar Caption
  };

 //Create the folder for the window
 struct WndFolder
  {
   int X;
   int Y;
   int Color;
  };
 struct WndFile
  {
   char* FileName;
   char* Bytes;
  };

 //Use inheritance to grab the member for the each Structure
 struct WndMain
  {
   WndAttribute WndAttr;
   WndQuality WndQual;
   WndFolder WndFol;
  };
 struct UserInfo
  {
   char *ID;//This will hold the User Name
   char *CODE;//This will hold the Password
  };

 //This struct will hold the data for the new user
 struct Wizard_Info
  {
   char Id[15];
   char Code[15];
   char First[15];
   char Last[15];
   char Sex[15];
  };

 //*******************************************************************
 //End Structure Declarations
 //*******************************************************************
 char* Emotion[4];
 char* TitleBarButtons[2];//Used for close button, minimize button, max button
 char* ButtonLabel[3];
 char* InputBoxSy;//Icon for the inputbox
 char* LogFileName;//The Filename for the log file to save\load .

 int Mouse_x;//Used to hold the X coordinate of the cursor
 int Mouse_y;//Used to hold the Y coordinate of the cursor
 int WndCount;


 public:
  void Create_Log_File();
  void Drawsprite(char SpriteFile[12],int XCo, int YCo, int StartX,
			int StartY);

  int CreateWindow(int WndX1,int WndY1,int WndX2,int WndY2,
		   int WndStyle, int WndFcColor, int WndLFcColor,
		   int WndBackGrd, int WndTitleLine);

  int TypeEngine(int XCor, int YCor,int Visible_Color, int Cover_Color,
		 int XBound, int YBound, int BackSpace_Bound, int Tab_Bound,
		 int Return_TabCoor,  int Status);
  void GetMousePos(int *button,int *x, int *y);//Get the mouse position
  void Hide_Cursor();
  int CreateFolder(int X, int Y, int Color);
  void CreateTxtBox_Lbl(int X1, int Y1, int X2, int Y2,char* TxtLabel);
  void CreateMsgBox(int MsgStyle, int ChoiceEm,char* Line1, char* Line2,
			  char* Line3, char* Line4, char* Line5);
  void Back_Buff(int a1,int b1,int a2,int b2,int x1,int y1);
  void User_Wizard();
  void Get_Wnd_Visual();
  //Function for making the mouse work
  void GetClick(int bta,int btb,int link[][5]);
  void Mouse_Enable();
  void Mouse_Read_Cursor();
  void ShowMouse();
  //Set default values for struct window
  void Set_Default();
  void Create_Entire_Interface();
  void Set_WndNumber();
  void External_EXE(char *FileName);
  char Time[15];
  char Date[15];

  union REGS i,o;//
  BackBuff BkBuff[100];//Hold the grpahics back buffer data

  //*******************************************************
  //These are are used for the differant sections
  //*******************************************************
    void Game();//Games ;)

  //*******************************************************
  //Set all the values for the variables used throughout
  //the class [default construtor]
  //*******************************************************
  MiniOS::MiniOS()
   {
    WndCount = 0;
    //Hold the coordinates and detail of windows
    TitleBarButtons[0] = new char[1];
    TitleBarButtons[1] = new char[1];
    TitleBarButtons[2] = new char[1];
    Emotion[0] = new char[1];
    Emotion[1] = new char[1];
    Emotion[2] = new char[1];
    Emotion[3] = new char[1];
    InputBoxSy = new char[1];
    ButtonLabel[0] = new char[3];
    ButtonLabel[1] = new char[7];
    ButtonLabel[2] = new char[4];
    ButtonLabel[3] = new char[3];
    LogFileName = new char[255];

    _strtime(Time);//Convert to string
    _strdate(Date);//Convert to string
    strcat(Date," ");//Do a nice little trick to store both of them in one
    strcat(Date,Time);//Do a nice little trick to store both of them in one
    //*****************************************
    //Allocation errors
    if((!TitleBarButtons[0]) || (!TitleBarButtons[1]) || (!TitleBarButtons[2]) ||
       (!Emotion[0]) || (!Emotion[1]) || (!Emotion[2]) || (!Emotion[3]) ||
       (!InputBoxSy) || (!LogFileName) )

	cout<<"Error allocating memory for window";


    //This is for the message box
    strcpy(Emotion[0],"?");//Question(Do what now)
    strcpy(Emotion[1],"!");//Explanation(Listen Up)
    strcpy(Emotion[2],"X");//Critical(UH Oh)
    strcpy(Emotion[3],"I");//Default

    //This is the titlebar button used on the very right to close open minimize
    strcpy(TitleBarButtons[0],"X");
    strcpy(TitleBarButtons[1],"_");
    strcpy(TitleBarButtons[2],"Û");

    //These are the symbols for the input boxes
    strcpy(InputBoxSy,"");//The Login in Symbol for Input Box
   }

  ~MiniOS()//deconstrutor
   {
    delete WndMain.WndQual.WndCaption;
    delete WndMain.WndQual.WndName;
    delete TitleBarButtons[0];
    delete TitleBarButtons[1];
    delete TitleBarButtons[2];
    delete Emotion[0];
    delete Emotion[1];
    delete Emotion[2];
    delete Emotion[3];
    delete InputBoxSy;
    delete ButtonLabel[0];
    delete ButtonLabel[1];
    delete ButtonLabel[2];
    delete ButtonLabel[3];
    delete LogFileName;

    closegraph();
   }

  WndMain WndMain;//Will Hold all information for the window
};
//*********************************************************************
//End MiniOS Class
//*********************************************************************

//Global Variables
MiniOS OS;//Make a instance of the class global


void Screen_Back_Buffer();//This function will update the screen when need

//*********************************************************************
//Begin the main program point
//*********************************************************************
int main()
{
  //intailize graphics
  int graphdriver = DETECT, graphmode, errorcode;


  //Put the user into graphic mode
  initgraph(&graphdriver,&graphmode,"..\\BGI\\");
  errorcode = graphresult();//Use this to hold the number error

if (errorcode != grOk)  /* an error
			   occurred */
{
   cout<<"Error Number: "<= 15 + 100 && Mouse_x <= getmaxx() - 310 &&
	Mouse_y >= 15 + 20  && Mouse_y <= getmaxy() - 280
	&& Button == 1 )
      {
       OS.Hide_Cursor();
       XM = Mouse_x - 100;
       YM = Mouse_y - 20;

       setactivepage(1);
       //OS.Create_Entire_Interface();

       setactivepage(0);//Back Buffer for the window
       //cleardevice();

       setfillstyle(SOLID_FILL,0);
       bar(XM-10,YM-10,Mouse_x + 210,Mouse_y + 210);
       setfillstyle(SOLID_FILL,0);
       bar(5,5,getmaxx()-5,415);
       OS.CreateWindow(XM,YM,Mouse_x + 200,Mouse_y + 200,1,2,3,6,1);



       OS.ShowMouse();
       setvisualpage(1);
       //View the back buffer
       setvisualpage(0);
      }

    //Location for each icons at the bottom

    //Icon 1: Terminal
    if( Mouse_x >= 20 && Mouse_x <= 52 &&
	Mouse_y >= getmaxy()-50 && Mouse_y <= getmaxy() - 28
	&& Button == 1 )
	 {
	  setlinestyle(0,1,1);
	  setcolor(1);
	  rectangle(13, getmaxy()-53,55, getmaxy()-13);
	 }

    //Icon 2: System
    if( Mouse_x >= 70 && Mouse_x <= 102 &&
	Mouse_y >= getmaxy()-50 && Mouse_y <= getmaxy() - 28
	&& Button == 1 )
	 {
	  setlinestyle(0,1,1);
	  setcolor(1);
	  rectangle(63,getmaxy()-53,103,getmaxy()-13);
	 }

    //Icon 3: Apps
    if( Mouse_x >= 120 && Mouse_x <= 170 &&
	Mouse_y >= getmaxy()-50 && Mouse_y <= getmaxy() - 28
	&& Button == 1 )
	 {
	  setlinestyle(0,1,1);
	  setcolor(1);
	  rectangle(113,getmaxy()-53,156,getmaxy()-13);
	 }
    //Icon 4: Internet
    if( Mouse_x >= 170 && Mouse_x <= 230 &&
	Mouse_y >= getmaxy()-50 && Mouse_y <= getmaxy() - 28
	&& Button == 1 )
	 {
	  setlinestyle(0,1,1);
	  setcolor(1);
	  rectangle(163,getmaxy()-53,203,getmaxy()-13);

	 }
    //Icon 4: Media
    if( Mouse_x >= 230 && Mouse_x <= 270 &&
	Mouse_y >= getmaxy()-50 && Mouse_y <= getmaxy() - 28
	&& Button == 1 )
	 {
	  setlinestyle(0,1,1);
	  setcolor(1);
	  rectangle(210,getmaxy()-53,253,getmaxy()-13);
	 }
    //Icon 5: Games
    if( Mouse_x >= 270 && Mouse_x <= 320 &&
	Mouse_y >= getmaxy()-50 && Mouse_y <= getmaxy() - 28
	&& Button == 1 )
	 {
	  setlinestyle(0,1,1);
	  setcolor(1);
	  rectangle(260,getmaxy()-53,303,getmaxy()-13);
	  OS.Game();
	 }

    //Icon 6: System Time (on the very end of operation bar)
    if( Mouse_x >= getmaxx()-100 && Mouse_x <= (getmaxx()-100)+32 &&
	Mouse_y >= getmaxy()-100 && Mouse_y <= (getmaxx()-100)+32
	&& Button == 1 )
       {
	 OS.CreateMsgBox(0,2,"Current Date\Time is:",OS.Date,"","","");
	 getch();
	 goto Test;
       }

    //Icon 7: Exit Jinx
    if( Mouse_x >= getmaxx()-50 && Mouse_x <= (getmaxx()-50)+32 &&
	Mouse_y >= getmaxy()-50 && Mouse_y <= (getmaxx()-50)+32
	&& Button == 1 )
	 {
	  setlinestyle(0,1,1);
	  setcolor(1);
	  rectangle(getmaxx()-55,getmaxy()-53,getmaxx()-15,getmaxy()-13);
	  //End sound
	  sound(900);
	  delay(200);
	  sound(200);
	  delay(100);
	  sound(900);
	  delay(200);
	  nosound();
	  //end sound part

	  OS.CreateMsgBox(0,2,"Log Off time Logged",OS.Date,"Good Bye","","");
	  exit(1);//Exit Jinx Totaly
	  return;
	 }


    //Clear all other left behind stuff
    if(Mouse_x >=10 && Mouse_y >= 10 && Mouse_x <= getmaxx()-10 &&
       Mouse_y <= 410)
       {
	//Control the whole interactive screen
	setcolor(0);
	setlinestyle(0,1,1);
	rectangle(63,getmaxy()-53,103,getmaxy()-13);
	rectangle(113,getmaxy()-53,156,getmaxy()-13);
	rectangle(163,getmaxy()-53,203,getmaxy()-13);
	rectangle(210,getmaxy()-53,253,getmaxy()-13);
	rectangle(260,getmaxy()-53,303,getmaxy()-13);
	rectangle(13, getmaxy()-53,55, getmaxy()-13);
	rectangle(getmaxx()-55,getmaxy()-53,getmaxx()-15,getmaxy()-13);
       }

 }//While Loop
 //**************************************************
 //End Drag and Drop
 //**************************************************

 //**************************************************





}//end update function


void MiniOS::Get_Wnd_Visual()
{
    int I = 0;

   for(I = 0; I < WndCount; I++)
    {
     //CReate the window
     CreateWindow(BkBuff[WndCount].WndSize,BkBuff[WndCount].WndX1,
		  BkBuff[WndCount].WndY1,BkBuff[WndCount].WndX2,
		  BkBuff[WndCount].WndY2,BkBuff[WndCount].WndStyle,
		  BkBuff[WndCount].WndFcColor,BkBuff[WndCount].WndLFcColor,
		  BkBuff[WndCount].WndBackGrd);
    }
}
void MiniOS::Set_WndNumber()
 {
  WndCount++;//Add one so the window will be able to have a back buffer
}
//*********************************************************************
//Very important function, this will show the windows on the screen
//There are three differant types 0-2
//*********************************************************************
int MiniOS::CreateWindow(int WndX1,int WndY1,int WndX2,int WndY2,
		   int WndStyle, int WndFcColor, int WndLFcColor,
		   int WndBackGrd, int WndTitleLine)
{
   palettetype pal;//Contains palette information for the current graphics driver
   getpalette(&pal);//GetPalette demands that a pointer be passed

   settextstyle(DEFAULT_FONT,HORIZ_DIR,1);


   WndMain.WndAttr.WndSize = sizeof(WndMain);
   WndMain.WndAttr.WndX1 = WndX1;
   WndMain.WndAttr.WndY1 = WndY1;
   WndMain.WndAttr.WndX2 = WndX2;
   WndMain.WndAttr.WndY2 = WndY2;
   WndMain.WndAttr.WndStyle = WndStyle;
   WndMain.WndAttr.WndFcColor =  WndFcColor;
   WndMain.WndAttr.WndLFcColor = WndLFcColor;
   WndMain.WndAttr.WndBackGrd = WndBackGrd;
   WndMain.WndAttr.WndTitleLine = WndTitleLine;

   //**************************************************************
       BkBuff[WndCount].WndSize = WndMain.WndAttr.WndSize;
       BkBuff[WndCount].WndX1 = WndMain.WndAttr.WndX1;
       BkBuff[WndCount].WndY1 = WndMain.WndAttr.WndY1;
       BkBuff[WndCount].WndX2 = WndMain.WndAttr.WndX2;
       BkBuff[WndCount].WndY2 = WndMain.WndAttr.WndY2;
       BkBuff[WndCount].WndStyle  = WndMain.WndAttr.WndStyle;
       BkBuff[WndCount].WndFcColor = WndMain.WndAttr.WndFcColor;
       BkBuff[WndCount].WndLFcColor = WndMain.WndAttr.WndLFcColor;
       BkBuff[WndCount].WndBackGrd = WndMain.WndAttr.WndBackGrd;
   //Create the BackBuffer Data
   //**************************************************************

 setfillstyle(SOLID_FILL,WndMain.WndAttr.WndBackGrd);
 bar(WndMain.WndAttr.WndX1+70, WndMain.WndAttr.WndY1+30,
      WndMain.WndAttr.WndX2,WndMain.WndAttr.WndY2);

 //Used to create the gradient titlebar
 for (int I=0; I= (MaxX/2)+90 && Mouse_x <= (MaxX/2+100)+45 &&
		 Mouse_y >= (MaxY/2)+120 && Mouse_y <= (MaxY/2+100)+40
		 && Button == 1 )
	      {
		setfillstyle(SOLID_FILL,BLACK);
		bar(MaxX/2+15,MaxY/2-10,MaxX/2+300,MaxY/2+150);
	      }
	   }//End Emotion Choice If
	}


   break;


    default:
    break;
  }//end switch

     cin.get();
     return;

}

//**************************************************************************
//This function will control all typing in the SHELL
//**************************************************************************
int MiniOS::TypeEngine(int XCor,int YCor,int Visible_Color, int Cover_Color,
		       int XBound, int YBound, int BackSpace_Bound,
		       int Tab_Bound, int Return_TabCoor, int Status)
{
  UserInfo UI;
  Wizard_Info UInfo;//Make a instance of the info struct for the user
  UI.ID = new char [15];
  UI.CODE = new char [15];
 //int MaxX = getmaxx() / 2;
 int MaxY = getmaxy() / 2;



    cin.get();

 int TempCorChar[4];
     TempCorChar[0] = MaxY - 93;
     TempCorChar[1] = MaxY - 63;
     TempCorChar[2] = MaxY - 33;
     TempCorChar[3] = MaxY - 3;
     TempCorChar[4] = MaxY + 27;
 //******************************
 int X = XCor+45, Y = YCor-8;//Used to hold the place for the cursor coordiantes
 //int MaxX = getmaxx() / 2, MaxY = getmaxy() / 2;
 char *Key = NULL;//The big string being used
 Key = 0;
 int I = -1, J = -1;//Give them the lowest value of the array
 int Wiz0 = -1, Wiz1 = -1, Wiz2 = -1, Wiz3 = -1, Wiz4 = -1;//Will Hold values
 //for the string array

 //Allocation error
 if( (!UI.ID) || (!UI.CODE) )
    return -1;



  setcolor(Visible_Color);//Used to control color of cursor
  outtextxy(X+8,Y,"_");

  do
   {

    *Key = getch();

    setcolor(Visible_Color);//Used to control color of cursor
    outtextxy(X+16,Y,"_");
     //Control the Range
     X+=8;//Goto the next blank

    //Where main output happens
    if((*Key != 13) && (*Key != 8) && (*Key!= 9))
     {
      if(X <= (XBound))//X Boundries MaxX/2+260
       {
	  outtextxy(X,Y,Key);
	  setcolor(Cover_Color);
	  outtextxy(X,Y,"_");
	  //Basically this part will let the compiler know how to control
	  //the range by the status
	 switch(Status)
	 {
	   case 0:
	    //Control which string we are on for the login
	    if(Y <= (YBound))//Y Boundries MaxY/2+75
	     {
	      I+=1;
	      UI.ID[I] = (char)*Key;
	     }
	    else
	     {
	      J+=1;
	      UI.CODE[J] = (char)*Key;
	     }//end else

	   case 1: //Used for most of the wizard on non moveable windows
	     if(Y == (TempCorChar[0]))//Y Boundries MaxY/2+75
	      {
	       Wiz0+=1;
	       UInfo.Id[Wiz0] = (char)*Key;
	      }
	     if(Y == (TempCorChar[1]))//Y Boundries MaxY/2+75
	      {
	       Wiz1+=1;
	       UInfo.Code[Wiz1] = (char)*Key;
	      }
	     if(Y == (TempCorChar[2]))//Y Boundries MaxY/2+75
	      {
	       Wiz2+=1;
	       UInfo.First[Wiz2] = (char)*Key;
	      }
	    if(Y == (TempCorChar[3]))//Y Boundries MaxY/2+75
	      {
	       Wiz3+=1;
	       UInfo.Last[Wiz3] = (char)*Key;
	      }
	    if(Y == (TempCorChar[4]))//Y Boundries MaxY/2+75
	      {
	       Wiz4+=1;
	       UInfo.Sex[Wiz4] = (char)*Key;
	      }

	 }//end Status

       }//end Xbound
    else
       {
	X-=8;
	setcolor(Cover_Color);
	outtextxy(X,Y,"__");
	outtextxy(X,Y,"");
       }//end else
     }//end if

     if(*Key == 8)//Backspace
      {

       if(X >= BackSpace_Bound)//BackSpace Boundry XCor + 55
	{
	 //Preform BackSpace using a block to cover it up
	 X-=8;
	 setfillstyle(SOLID_FILL,Cover_Color);
	 bar(X,Y,X+8,Y+8);

	 //SetCursor to right place and cover its tracks
	 setcolor(Cover_Color);
	 outtextxy(X+8,Y,"__");
	 setcolor(Visible_Color);
	 outtextxy(X,Y,"_");

	 X-=8;
	 outtextxy(X,Y,"");

	  //Control which string we are on for the login
	  if(Y >= (YBound))//Max
	    {
	     I-=1;
	     UI.ID[I] = (char)" ";
	    }
	  else
	    {
	     J-=1;
	     UI.CODE[J]  = (char)" ";
	    }
	}//End if Outer IF

	//If the back space does exceeds its
	else
	 {
	  X-=0;
	  if(Y >= (YBound))//Max
	    {
	     I-=1;
	     UI.ID[I] = (char)" ";
	    }
	  else
	    {
	     J-=1;
	     UI.CODE[J] = (char)" ";
	    }

	  //Cover Procedure
	  setcolor(Cover_Color);
	  outtextxy(X+8,Y,"__");
	  setcolor(Visible_Color);
	  outtextxy(X,Y,"_");
	 }

      }//end if

     //This will be used as the tab key
     if(*Key == 9)
      {


       if(Y <= Tab_Bound)//YCor + 30 Tab Boundry
	{
	 setcolor(Cover_Color);
	 outtextxy(X,Y,"__");

	 Y+=30;
	 X=XCor+45;

	 //View the curosr
	 setcolor(Visible_Color);//Used to control color of cursor
	 outtextxy(X+8,Y,"_");

	}

       if( Y >= (Tab_Bound))//Move back up to ID
	{
	 setcolor(Cover_Color);
	 outtextxy(X,Y,"__");


	 Y-=Return_TabCoor;//60 was this Tab Return Boundry
	 X=XCor+45;

	 //View the curosr
	 setcolor(Visible_Color);//Used to control color of cursor
	 outtextxy(X+8,Y,"_");

	}
      //cout<> Sprite[Y][X];

	for(X=0;X= 100 && Mouse_y >= 100 &&
       Mouse_x <= 132 && Mouse_y <= 132
       && Button == 1 )
      External_EXE("C:\\Snake.exe");

   //Call Upon Snake Game
   if( Mouse_x >= 150 && Mouse_y >= 100 &&
       Mouse_x <= 182 && Mouse_y <= 132
       && Button == 1 )
      {
      External_EXE("C:\\Falldown.exe");
      outtext("YAAAAA");
      }
  }

}
//**************************************************
//Function to run exe inside the program itself
//**************************************************
void MiniOS::External_EXE(char *FileName)
{
  char **Test= NULL;
  execvp(FileName, Test);
  return;
}

    Source: geocities.com/nit3shift