Code:
/*
Coded by Patrick(Virtual Void)
May 26, 2011
thank my post /fmm
*/
#include <iostream.h>
#include <dos.h>
#define VID_SEG 0xA000
/* VID_SEG is the video segment */
void SetVideoMode13h()
{
_AH = 0;
_AL = 0x13; //Video mode
geninterrupt(0x10);//generate interrupt 10h
}
void SetTextMode()
{
_AH = 0;
_AL = 0x03; //text mode
geninterrupt(0x010); //generate int 10h
}
void DrawPixel(int x, int y, unsigned char Color)
{
pokeb(VID_SEG, (y * 320) + x, Color); //320 is the screen width in 0x13 VGA mode
}
void DrawRect(int Top_Left_X,int Top_Left_Y, int Width, int Height, unsigned char Colour)
{
DrawPixel(Top_Left_X, Top_Left_Y, Colour);
int Bottom_Left_X = Top_Left_X;
int Bottom_Left_Y = Top_Left_Y + Height;
DrawPixel(Bottom_Left_X, Bottom_Left_Y, Colour);
int Top_Right_X = Top_Left_X + Width;
int Top_Right_Y = Top_Left_Y;
DrawPixel(Top_Right_X, Top_Right_Y, Colour);
int Bottom_Right_X = Top_Right_X;
int Bottom_Right_Y = Top_Right_Y + Height;
DrawPixel(Bottom_Right_X, Bottom_Right_Y, Colour);
int t_x, b_x, l_y, r_y; // top x, bottom x, left y, right y, connect point
// the equal signs show what side is drawn
for(t_x = Top_Left_X; t_x <= Top_Right_X; t_x++) // ======
{ // | |
DrawPixel(t_x, Top_Left_Y, Colour); // | |
} // |____|
for(b_x = Bottom_Left_X; b_x <= Bottom_Right_X; b_x++) // _____
{ // | |
DrawPixel(b_x, Bottom_Left_Y, Colour); // | |
} // =====
for(l_y = Top_Left_Y; l_y <= Bottom_Left_Y; l_y++) // _____
{ // = |
DrawPixel(Top_Left_X, l_y, Colour); // = |
} // =___|
for(r_y = Top_Right_Y; r_y <= Bottom_Left_Y; r_y++) // _____
{ // | =
DrawPixel(Top_Right_X, r_y, Colour); // | =
} // |___=
}
class Rectangle
{
public:
Rectangle(int Height_,int Width_,int TopLeftX_, int TopLeftY_,unsigned char color_)
{
Height = Height_;
Width = Width_;
TopLeftX = TopLeftX_;
TopLeftY = TopLeftY_;
color = color_;
}
~Rectangle(){}
//Rectangle attributes
unsigned char color;
int Height;
int Width;
int TopLeftX;
int TopLeftY;
};
int main()
{
cout << "Enter the Rect's:\nTop left X coord\nTop left Y coord\nWidth\nHeight\nColor(to 255)\nFill 1 or 0\n";
//Just don't make anything cause a rect to be > 319,199, max res
int tlx, tly, wid, hei;
unsigned char col;
cin >> tlx >> tly >> wid >> hei >> col;
Rectangle rect(hei,wid,tlx,tly,col);
cout << "Set Rect's attributes successfully. Press Enter for Rect\n";
cin.ignore();
cin.get();
SetVideoMode13h();
DrawRect(rect.TopLeftX,rect.TopLeftY,rect.Width,rect.Height,rec*****lor);
cin.ignore();
cin.get();
rect.~Rectangle();
SetTextMode();
return 0;
}