Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабы / неТельминов / lab6 / LAB6-2
.CPP// 6 laba 2 variant
#include <conio.h>
#include <dos.h>
#include <iostream.h>
#include <graphics.h>
#define RCOLOR RED
// mouse int
#define MOUSE 0x33
int MouseInit();
void MouseShow();
void MouseWnd(int, int, int, int);
void MouseHide();
int MouseLBPressed();
void MouseXY(int *, int *);
class Point
{
protected:
int x1, y1;
public:
void PointInit(int a, int b)
{
x1 = a;
y1 = b;
}
};
class Rectangle: public Point
{
int x2, y2;
public:
void RectInit(int a, int b)
{
PointInit(a, b);
x2 = a;
y2 = b;
}
void RectSet(int a, int b)
{
x2 = a;
y2 = b;
}
void RectDraw(int, int);
};
void Rectangle::RectDraw(int a, int b)
{
if(a != x2 && b != y2)
{
setcolor(BLACK);
rectangle(x1, y1, x2, y2);
RectSet(a, b);
setcolor(RCOLOR);
rectangle(x1, y1, x2, y2);
}
}
int main()
{
int GDriver = DETECT, GMode, PosX, PosY;
Rectangle RectOb;
clrscr();
// if mouse isn't installed then quit
if(!MouseInit())
{
cout << "Mouse isn't detected!\n";
getch();
return 0;
}
// if problems with graphic then quit
initgraph(&GDriver, &GMode, "C:\\DEMON\\SOFT\\BORLANDC\\BGI\\");
if(graphresult() != grOk)
{
cout << "Error graphic inizialization!\n";
getch();
return 0;
}
// use mouse in full screen
MouseWnd(1, 1, getmaxx(), getmaxy());
// show mouse cursor
MouseShow();
// wait until LB pressed
while(MouseLBPressed() != 1);
// if mouse isn't hide -> you will see some lines
MouseHide();
/* mouse cursor position:
x - column
y - row */
MouseXY(&PosX, &PosY);
RectOb.RectInit(PosX, PosY);
// will be a point
RectOb.RectDraw(PosX + 1, PosY + 1);
// while LB pressed draw RECTANGLE
while(MouseLBPressed() == 1)
{
MouseXY(&PosX, &PosY);
RectOb.RectDraw(PosX, PosY);
}
// wait until any Mouse Button pressed
MouseShow();
while(!MouseLBPressed());
// hide mouse and close graphic mode
MouseHide();
closegraph();
return 0;
}
/* return: ax - 0000h if mouse isn't installed
ax - FFFFh if mouse is installed */
int MouseInit()
{
REGS reg;
reg.x.ax = 0x0000;
int86(MOUSE, ®, ®);
return reg.x.ax;
}
void MouseShow()
{
REGS reg;
reg.x.ax = 0x0001;
int86(MOUSE, ®, ®);
}
// mouse window
void MouseWnd(int a, int b, int c, int d)
{
REGS reg;
reg.x.ax = 0x0007;
reg.x.cx = a;
reg.x.dx = c;
int86(MOUSE, ®, ®);
reg.x.ax = 0x0008;
reg.x.cx = b;
reg.x.dx = d;
int86(MOUSE, ®, ®);
}
void MouseHide()
{
REGS reg;
reg.x.ax = 0x0002;
int86(MOUSE, ®, ®);
}
/* return: bx - 1 if LB pressed
bx - 2 if RB pressed
bx - 3 if MB pressed */
int MouseLBPressed()
{
REGS reg;
reg.x.ax = 0x0003;
int86(MOUSE,®,®);
return reg.x.bx;
}
/* return: x = cx - column
y = dx - row */
void MouseXY(int *x, int *y)
{
REGS reg;
reg.x.ax = 0x0003;
int86(MOUSE, ®, ®);
*x = reg.x.cx;
*y = reg.x.dx;
}
Соседние файлы в папке lab6