Добавил:
sergey123
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "matrix.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
using namespace std;
int pp,xx,yy,xxx,yyy,ff,c1=100,c2=100;//det;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y)
{
pp=X;
if (SpeedButton1->Down) {
for (int i=0; i<10; i++)
{
xx=Form1->TrackBar1->Position;
yy=Form1->TrackBar2->Position;
switch(xx)
{
case 5:
xx=X+100; break;
case 4:
xx=X+80; break;
case 3:
xx=X+60; break;
case 2:
xx=X+40; break;
case 1:
xx=X+20; break;
}
switch(yy)
{
case 5:
yy=Y+100; break;
case 4:
yy=Y+80; break;
case 3:
yy=Y+60; break;
case 2:
yy=Y+40; break;
case 1:
yy=Y+20; break;
}
if (((xx>=Image1->Width)||(yy>=Image1->Height))||((p[i])&&(X>=p[i]->X1)&&(Y>=p[i]->Y1)&&(X<=p[i]->X2)&&(Y<=p[i]->Y2))||((p[i])&&(xx>=p[i]->X1)&&(Y>=p[i]->Y1)&&(xx<=p[i]->X2)&&(Y<=p[i]->Y2))||((p[i])&&(X>=p[i]->X1)&&(yy>=p[i]->Y1)&&(X<=p[i]->X2)&&(yy<=p[i]->Y2))||((p[i])&&(xx>=p[i]->X1)&&(yy>=p[i]->Y1)&&(xx<=p[i]->X2)&&(yy<=p[i]->Y2))) {
break;
}
else if (p[i] == NULL) {
p[i]=new CMatrix();
p[i]->X1=X;
p[i]->Y1=Y;
switch(p[i]->x)
{
case 5:
p[i]->X2=p[i]->X1+100; break;
case 4:
p[i]->X2=p[i]->X1+80; break;
case 3:
p[i]->X2=p[i]->X1+60; break;
case 2:
p[i]->X2=p[i]->X1+40; break;
case 1:
p[i]->X2=p[i]->X1+20; break;
}
switch(p[i]->y)
{
case 5:
p[i]->Y2=p[i]->Y1+100; break;
case 4:
p[i]->Y2=p[i]->Y1+80; break;
case 3:
p[i]->Y2=p[i]->Y1+60; break;
case 2:
p[i]->Y2=p[i]->Y1+40; break;
case 1:
p[i]->Y2=p[i]->Y1+20; break;
}
for (int k=0; k < p[i]->y; k++) {
for (int j=0; j < p[i]->x; j++) {
Image1->Canvas->TextOut(X,Y,p[i]->M[k*p[i]->x+j]);
X=X+20;
}
X=pp;
Y=Y+20;
}
break;}
}
}
else if (SpeedButton2->Down) {
for (int i =0;i < 10; i++) {
if ((p[i])&&(X>=p[i]->X1)&&(Y>=p[i]->Y1)&&(X<=p[i]->X2)&&(Y<=p[i]->Y2)) {
Image1->Canvas->Pen->Color = clWhite;
Image1->Canvas->Brush->Color = clWhite;
Image1->Canvas->Rectangle(p[i]->X1,p[i]->Y1,p[i]->X2,p[i]->Y2);
if(i==c1||i==c2){
ff=0;
c1=100; c2=100;
Image2->Canvas->Brush->Color = clWhite;
Image2->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
Image3->Canvas->Brush->Color = clWhite;
Image3->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
Image4->Canvas->Brush->Color = clWhite;
Image4->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
}
delete p[i];
p[i]=NULL;
break;
}
}
}
else
{
if (ff==0) {
xxx=10;
yyy=10;
for (int i =0;i < 10; i++) {
if ((p[i])&&(X>=p[i]->X1)&&(Y>=p[i]->Y1)&&(X<=p[i]->X2)&&(Y<=p[i]->Y2)) {
for (int k=0; k < p[i]->y; k++) {
for (int j=0; j < p[i]->x; j++) {
Image2->Canvas->TextOut(xxx,yyy,p[i]->M[k*p[i]->x+j]);
xxx=xxx+20;
}
xxx=10;
yyy=yyy+20;
}
ff=1;
c1=i;
break;
}
}
}
else if (ff==1) {
xxx=10;
yyy=10;
for (int i =0;i < 10; i++) {
if ((p[i])&&(X>=p[i]->X1)&&(Y>=p[i]->Y1)&&(X<=p[i]->X2)&&(Y<=p[i]->Y2)) {
for (int k=0; k < p[i]->y; k++) {
for (int j=0; j < p[i]->x; j++) {
Image3->Canvas->TextOut(xxx,yyy,p[i]->M[k*p[i]->x+j]);
xxx=xxx+20;
}
xxx=10;
yyy=yyy+20;
}
ff=2;
c2=i;
break;
}
}
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Image1->Canvas->Brush->Color = clWhite;
Image1->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
Image2->Canvas->Brush->Color = clWhite;
Image2->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
Image3->Canvas->Brush->Color = clWhite;
Image3->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
Image4->Canvas->Brush->Color = clWhite;
Image4->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
ff=0;
c1=100; c2=100;
Image2->Canvas->Brush->Color = clWhite;
Image2->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
Image3->Canvas->Brush->Color = clWhite;
Image3->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
Image4->Canvas->Brush->Color = clWhite;
Image4->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
//det=
Edit1->Text=p[0]->M[5];
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if (c1==100||c2==100) {
}
else{
Image4->Canvas->Brush->Color = clWhite;
Image4->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
if ((p[c1]->x==p[c2]->x)&&(p[c1]->y==p[c2]->y)) {
CMatrix *MatNew;
MatNew=new CMatrix();
*(MatNew)=*(p[c1])+*(p[c2]);
xxx=10;
yyy=10;
for (int k=0; k < MatNew->y; k++) {
for (int j=0; j < MatNew->x; j++) {
Image4->Canvas->TextOut(xxx,yyy,MatNew->M[k*MatNew->x+j]);
xxx=xxx+30;
}
xxx=10;
yyy=yyy+20;
}
}
}}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
if (c1==100||c2==100) {
}
else{
Image4->Canvas->Brush->Color = clWhite;
Image4->Canvas->FillRect(Rect(0, 0, Image1->Width, Image1->Height));
if ((p[c1]->x==p[c2]->x)&&(p[c1]->y==p[c2]->y)){
CMatrix *MatNew;
MatNew=new CMatrix();
*(MatNew)=*(p[c1])-*(p[c2]);
xxx=10;
yyy=10;
for (int k=0; k < MatNew->y; k++) {
for (int j=0; j < MatNew->x; j++) {
Image4->Canvas->TextOut(xxx,yyy,MatNew->M[k*MatNew->x+j]);
xxx=xxx+30;
}
xxx=10;
yyy=yyy+20;
}
}
}}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
if (c1==100||c2==100) {
}
else{
CMatrix *MatNew;
MatNew=new CMatrix();
*(MatNew)=(*(p[c1]))*(*(p[c2]));
xxx=10;
yyy=10;
for (int k=0; k < MatNew->x; k++) {
for (int j=0; j < MatNew->y; j++) {
Image4->Canvas->TextOut(xxx,yyy,MatNew->M[j*MatNew->x+k]);
xxx=xxx+30;
}
xxx=10;
yyy=yyy+20;
}
}
}
//---------------------------------------------------------------------------