Jump to content

Recommended Posts

Posted

Probl: scrieti un program care sa deseneze dreptunghiuri in modul text, folosind mouse.ul. Se apasa butonul din stanga si se marcheaza un colt, apoi se misca mouse.ul si se da drumul la buton in momentul in care s.a fixat si cel de al doilea colt (colturile sunt diagonal opuse).

Pentru lucrul cu mouse.ul vom folosi functiile din fisierul "mouset.h".

void mouse(int *a1, int *a2, int *a3, int *a4)

{

struct REGPACK regs;

regs.r_ax=a1;

regs.r_bx=a2;

regs.r_cx=a3;

regs.r_dx=a4;

intr(0x33, &regs);

a1=regs.r_ax;

a2=regs.r_bx;

a3=regs.r_cx;

a4=regs.r_dx;

}

void mouseinit(void)

{

int a=1, b, c, d;

mouse(a, b, c, d);

}

void mousehide(void)

{

int a=2, b, c, d;

mouse(a, b, c, d);

}

void mouseshow(void)

{

int a=1, b, c, d;

mouse(a, b, c, d);

}

void mousetdata(int &but, int &x, int &y)

{

int a=3, b, c, d;

mouse(a, b, c, d);

but=b;

x=c/8+1;

y=d/8+1;

}

void mousetmove(int x, int y)

{

int a=4, b, c=8*x-1, d=8*y-1;

mouse(a, b, c, d);

}
OBS: mouseinit() va initializa mouse.ul, mouseshow() il afiseaza pe ecran, mousehide() il ascunde, iar mousetdata(b, x, y) preia in variabilele intregi b, x si y datele despre mouse in mod text (b=butonul de mouse apasat). b=0 inseamna ca nici un buton nu s.a apasat b=1, butonul din stanga b=2, butonul din dreapta b=3, ambele butoane x, y=coloana, respectiv linia unde se afla mouse.ul mousetmove(x, y) muta cursorul de mouse in casuta de pe coloana x si linia y. apelul lui mousetdata(b, x, y)-prin referinta. Asadar in continuare scriem programul principal:
#include "mouset.h"

#include<conio.h>

#include<dos.h> //aceasta nu neaparat, caci deja e inclusa in "mouset.h"

//deseneaza un chenar de la (x1, y1) la (x2,y2) de caracterul c

void dreptunghi (int x1, int y1, int x2, int y2, char c)

{

	int aux, x, y;

	if(x1>x2)

	{

		aux=x1;

		x1=x2;

		x2=aux;

	}

	if(y1>y2)

	{

		aux=y1;

		y1=y2;

		y2=aux;

	}

	for(x=x1; x<=x2; x++)

	{

		gotoxy(x, y1);

		putch(c)

	  gotoxy(x, y2);

		putch(c);

	}

	for(y=y1; y<=y2; y++)

	{

		gotoxy(x1, y);

		putch(c);

		gotoxy(x2, y);

		putch(c);

	}

}

//deseneaza un dreptunghi umplut de la (x1, y1) la (x2, y2)

void dreptunghiplin(int x1, int y1, int x2, int y2)

{

	int aux, x, y;

	if(x1>x2)

	{

		aux=x1;

		x1=x2;

		x2=aux;

	}

	if(y1>y2)

	{

		aux=y1;

		y1=y2;

		y2=aux;

	}

	for(x=x1; x<=x1; x++)

		for(y=y1; y<=y2; y++)

		{

			gotoxy(x, y);

			putch(219);

		}

}

void main()

{


	int b, x, y, px, py;

  clrscr();

	//se initializeaza si afiseaza mouse.ul in centrul ecranului

	mouseinit();

	mouseshow();

	//se determina primul punct de coordonate (px, py)

	do{

		mousetdata(b, px, py);

	}while(b!=1);

	//pentru a nu avea neplaceri in afisarea dreptunghiurilor partiale, se ascunde mouse.ul

	mousehide();

	do{

		mousetdata(b, x,y);

		//x si y sunt coordonate provizorii ale celui de al doilea punct

		dreptunghi(px, py, x, y, 178);

		mouseshow();

		delay(50);

		mousehide();

		dreptunghi(px, py, x, y, 32);

		//intai se deseneaza dreptunghiul, apoi se afiseaza putin mouse.ul, apoi se sterge dreptunghiul

	}while(b==1);

	dreptunghiplin(px, py, x, y);

	//se deseneaza  dreptunghiul plin final

	mouseshow();

	getch();


}

  • Upvote 1

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.