📄 unit2.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
#include "Unit13.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//TForm2 *Form2;
extern int iFormNum;
extern int iActForm2;
extern int iGraphStyle;
extern int iGraphThick;
extern bool bIsTransparence;
extern TColor tBrushColor;
extern TColor tGroundColor;
extern TColor tGraphColor;
extern bool bForm2Null[50];
extern int iForm2Sum;
extern int iTemplate[4][4];
extern int iTNum;
extern TPoint pProcessBegin,pProcessEnd;
extern int iThre;
extern long lCopyStyle;
long lXTemp,lYTemp;
int iR,iG,iB;
TColor tTempColor;
float fWtempR,fWtempG,fWtempB;
float fla;
int ilb;
int iSmoothStyle;
Graphics::TBitmap *bBitmapCopy=new Graphics::TBitmap;
TCursor tCurTemp;
long lProStep,lProSum,lProi;
int iSunDirection=1;
int iSunConstant=128;
int iSpreadBound=5;
long lofx,lofy,lforx,lfory;
int iTemp,jTemp;
int iPointRange;
extern int iMASAIKE;
TPoint preP,curP;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
int i;
iPicNum=10;
iPicBegin=1;
iPicEnd=0;
iPicNow=0;
iMaxZoom=4;
iZoom=0;
pPBegin.x=0;
pPBegin.y=0;
pPEnd.x=lPicWidth;
pPEnd.y=lPicHeight;
sOperator[0]="打开";
iPointRange=0;
for(i=0;i<iPicNum;i++)
bPicArray[i]=new Graphics::TBitmap();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormResize(TObject *Sender)
{
if(Panel1->Width < this->ClientWidth)
Panel1->Left=(this->ClientWidth - Panel1->Width)/2;
else
Panel1->Left=0;
if(Panel1->Height < this->ClientHeight)
Panel1->Top=(this->ClientHeight - Panel1->Height)/2;
else
Panel1->Top=0;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormClose(TObject *Sender, TCloseAction &Action)
{
int i;
i=MessageBox(NULL,"是否保存图像","Question?",MB_YESNOCANCEL|MB_ICONQUESTION);
if(i==IDYES)
{
//保存
gotosave:
if(SaveDialog1->Execute())
{
if(FileExists(SaveDialog1->FileName))
{
i=MessageBox(NULL,"您所指定的文件已经存在,是否覆盖?","Question",MB_YESNOCANCEL|MB_ICONQUESTION);
if(i==IDNO)
goto gotosave;
if(i==IDYES)
{
if(!DeleteFile(SaveDialog1->FileName))
{
MessageBox(NULL,"指定的文件正在使用,无法覆盖","error",MB_OK|MB_ICONERROR);
goto gotosave;
}
}
else
{
Action=caNone;
return;
}
}
this->Image1->Picture->SaveToFile(SaveDialog1->FileName);
MessageBox(NULL,"保存成功","OK",MB_OK);
Action=caFree;
iForm2Sum--;
bForm2Null[iOrder]=true;
Form3->ListBox1->Clear();
for(i=0;i<iPicNum;i++)
delete bPicArray[i];
}
else
{
Action=caNone;
return;
}
}
else if(i==IDNO)
{
Action=caFree;
iForm2Sum--;
bForm2Null[iOrder]=true;
Form3->ListBox1->Clear();
for(i=0;i<iPicNum;i++)
delete bPicArray[i];
}
else
{
Action=caNone;
return;
}
Form1->StatusBar2->Panels->Items[2]->Text=" ";
Form1->StatusBar2->Panels->Items[3]->Text=" ";
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormActivate(TObject *Sender)
{
SetForm3List();
pProcessBegin.x=pPBegin.x;
pProcessBegin.y=pPBegin.y;
pProcessEnd.x=pPEnd.x;
pProcessEnd.y=pPEnd.y;
iActForm2=iOrder;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Shift.Contains(ssRight)||!iGraphStyle)
{
iGraphStyle=0;
Image1->Cursor=crArrow;
Shape1->Visible=false;
Image1->Canvas->Pen->Mode=pmCopy;
Form1->Panel3->Visible=false;
Form1->Panel4->Visible=false;
Form3->SpeedButton4->Down=true;
return;
}
preP.x=X;
preP.y=Y;
switch(iGraphStyle){
case 1:
Shape1->Shape=stRectangle;
break;
case 2:
Image1->Canvas->Pixels[X*(1 - 0.2*iZoom)][Y*(1 - 0.2*iZoom)]=tGraphColor;
return;
case 3:
Image1->Canvas->Pen->Mode=pmNot;
curP.x=X*(1 - 0.2*iZoom);
curP.y=Y*(1 - 0.2*iZoom);
break;
case 4:
Shape1->Shape=stRectangle;
break;
case 5:
Shape1->Shape=stEllipse;
break;
case 6:
f_imagePointProcess(6,X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
break;
case 7:
f_imagePointProcess(7,X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
break;
case 8:
tTempColor=Image1->Canvas->Pixels[X*(1 - 0.2*iZoom)][Y*(1 - 0.2*iZoom)];
Form3->Shape1->Brush->Color=tTempColor;
Form1->StatusBar2->Panels->Items[1]->Text="RGB: ("+IntToStr(GetRValue(tTempColor))+","+IntToStr(GetGValue(tTempColor))+","+IntToStr(GetBValue(tTempColor))+")";
break;
case 9:
break;
default :
break;
}
if(iGraphStyle==1||iGraphStyle==4||iGraphStyle==5)
{
Shape1->Top=Y;
Shape1->Left=X;
Shape1->Width=1;
Shape1->Height=1;
Shape1->Visible=true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
Form1->StatusBar2->Panels->Items[2]->Text="X: "+IntToStr((int)(X*(1 - 0.2*iZoom)));
Form1->StatusBar2->Panels->Items[3]->Text="Y: "+IntToStr((int)(X*(1 - 0.2*iZoom)));
if(!Shift.Contains(ssLeft)||!iGraphStyle)
return;
switch(iGraphStyle){
case 1:
Shape1->Width=X - preP.x;
Shape1->Height=Y - preP.y;
//
break;
case 2:
Image1->Canvas->Pixels[X*(1 - 0.2*iZoom)][Y*(1 - 0.2*iZoom)]=tGraphColor;
break;
case 3:
Image1->Canvas->MoveTo(preP.x*(1 - 0.2*iZoom),preP.y*(1 - 0.2*iZoom));
Image1->Canvas->LineTo(curP.x,curP.y);
Image1->Canvas->MoveTo(preP.x*(1 - 0.2*iZoom),preP.y*(1 - 0.2*iZoom));
Image1->Canvas->LineTo(X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
curP.x=X*(1 - 0.2*iZoom);
curP.y=Y*(1 - 0.2*iZoom);
break;
case 4:
Shape1->Width=X - preP.x;
Shape1->Height=Y - preP.y;
break;
case 5:
Shape1->Width=X - preP.x;
Shape1->Height=Y - preP.y;
break;
case 6:
f_imagePointProcess(6,X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
break;
case 7:
f_imagePointProcess(7,X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
break;
case 8:
break;
case 9:
break;
default:
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Image1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if(Shift.Contains(ssRight)||!iGraphStyle||iGraphStyle==2)
return;
if(iGraphStyle==3||iGraphStyle==4||iGraphStyle==5)
{
Image1->Canvas->Pen->Mode=pmCopy;
Image1->Canvas->Pen->Width=iGraphThick;
Image1->Canvas->Pen->Color=tGraphColor;
if(bIsTransparence)
Image1->Canvas->Brush->Style=bsClear;
else
{
Image1->Canvas->Brush->Style=bsSolid;
Image1->Canvas->Brush->Color=tBrushColor;
}
}
switch(iGraphStyle){
case 1:
pProcessBegin.x=Shape1->Left*(1 - 0.2*iZoom);
pProcessBegin.y=Shape1->Top*(1 - 0.2*iZoom);
pProcessEnd.x=(Shape1->Left+Shape1->Width)*(1 - 0.2*iZoom);
pProcessEnd.y=(Shape1->Top+Shape1->Height)*(1 - 0.2*iZoom);
if(pProcessBegin.x>pProcessEnd.x)
{
iR=pProcessEnd.x;
pProcessEnd.x=pProcessBegin.x;
pProcessBegin.x=iR;
}
if(pProcessBegin.y>pProcessEnd.y)
{
iR=pProcessEnd.y;
pProcessEnd.y=pProcessBegin.y;
pProcessBegin.y=iR;
}
if(pProcessBegin.x<0)
pProcessBegin.x=0;
if(pProcessBegin.y<0)
pProcessBegin.y=0;
if(pProcessEnd.x>=lPicWidth)
pProcessEnd.x=lPicWidth-1;
if(pProcessEnd.y>=lPicHeight)
pProcessEnd.y=lPicHeight-1;
break;
case 3:
Image1->Canvas->MoveTo(preP.x*(1 - 0.2*iZoom),preP.y*(1 - 0.2*iZoom));
Image1->Canvas->LineTo(X*(1 - 0.2*iZoom),Y*(1 - 0.2*iZoom));
break;
case 4:
Image1->Canvas->Rectangle(Shape1->Left*(1 - 0.2*iZoom),Shape1->Top*(1 - 0.2*iZoom),(Shape1->Left+Shape1->Width)*(1 - 0.2*iZoom),(Shape1->Top+Shape1->Height)*(1 - 0.2*iZoom));
Shape1->Visible=false;
break;
case 5:
Image1->Canvas->Ellipse(Shape1->Left*(1 - 0.2*iZoom),Shape1->Top*(1 - 0.2*iZoom),(Shape1->Left+Shape1->Width)*(1 - 0.2*iZoom),(Shape1->Top+Shape1->Height)*(1 - 0.2*iZoom));
Shape1->Visible=false;
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 100:
f_imageZoom(true);
break;
case 101:
f_imageZoom(false);
break;
default :
break;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -