//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#define MIN(A,B) (A<B)?A:B
#define MAX(A,B) (A>B)?A:B
#include "Main.h"
#include "Font.h"
#include <Clipbrd.hpp>
#include "NewBMP.h"
#include <jpeg.hpp>
#include <printers.hpp>
#include <math.h>
#include "AboutBox.h"
#include "color.h"
#include "ResizeBMP.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CGRID"
#pragma link "CSPIN"
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
Screen->Cursors[crFill] = LoadCursorFromFile("res\\FILL.cur");
Screen->Cursors[crPlus] = LoadCursorFromFile("res\\PLUS.cur");
Screen->Cursors[crDraw] = LoadCursorFromFile("res\\DRAW.cur");
Screen->Cursors[crErase] = LoadCursorFromFile("res\\ERASE.cur");
Screen->Cursors[crText] = LoadCursorFromFile("res\\TEXT.cur");
Screen->Cursors[crZoom] = LoadCursorFromFile("res\\ZOOM.cur");
Image->Cursor=TCursor(crPlus);
Image->Canvas->MoveTo(0,0);
ToolState=dtSelect;
randomize();
Image->Canvas->Pen->Width=PenWidth->Value;
Image->Canvas->Pen->Style=psSolid;
Image->Canvas->Brush->Style=bsSolid;
isSelect=false;
OpenDialog1->Filter = GraphicFilter(__classid(TGraphic));
}
//---------------------------------------------------------------------------//----------353453453453-----------------------------------------------------------------
void __fastcall TMainForm::ColorGrid1Change(TObject *Sender)
{
FGShape->Brush->Color = ColorGrid1->ForegroundColor;
if (FGShape->Brush->Color == TColor(clBlack))
FGShape->Pen->Color = TColor(clWhite);
else
FGShape->Pen->Color = TColor(clBlack);
BGShape->Brush->Color = ColorGrid1->BackgroundColor;
if (BGShape->Brush->Color == TColor(clBlack))
BGShape->Pen->Color = TColor(clWhite);
else
BGShape->Pen->Color = TColor(clBlack);
}
void __fastcall TMainForm::PenWidthChange(TObject *Sender)
{
if (PenWidth->Value>50)
PenWidth->Value=50;
Image->Canvas->Pen->Width=PenWidth->Value;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::DrawShape(TPoint TopLeft, TPoint BottomRight, TPenMode AMode)
{
Image->Canvas->Pen->Mode = AMode;
switch (ToolState){
case dtLine:
Image->Canvas->MoveTo(TopLeft.x, TopLeft.y);
Image->Canvas->LineTo(BottomRight.x, BottomRight.y);
break;
case dtRectangle:
Image->Canvas->Rectangle(TopLeft.x, TopLeft.y, BottomRight.x, BottomRight.y);
break;
case dtEllipse:
Image->Canvas->Ellipse(TopLeft.x, TopLeft.y, BottomRight.x, BottomRight.y);
break;
case dtRoundRect:
Image->Canvas->RoundRect(TopLeft.x, TopLeft.y, BottomRight.x, BottomRight.y, (TopLeft.x - BottomRight.x)/2, (TopLeft.y - BottomRight.y)/2);
break;
case dtSolidRect:
Image->Canvas->Rectangle(TopLeft.x, TopLeft.y, BottomRight.x, BottomRight.y);
break;
case dtSolidEllipse:
Image->Canvas->Ellipse(TopLeft.x, TopLeft.y, BottomRight.x, BottomRight.y);
break;
case dtSolidRndRect:
Image->Canvas->RoundRect(TopLeft.x, TopLeft.y, BottomRight.x, BottomRight.y, (TopLeft.x - BottomRight.x)/2, (TopLeft.y - BottomRight.y)/2);
break;
case dtSelect:
Image->Canvas->Rectangle(TopLeft.x, TopLeft.y, BottomRight.x, BottomRight.y);
break;
}
Image->Canvas->Pen->Mode = pmCopy;
}
//---------------------------------------------------------------------------
void TMainForm::EraseSelect()
{
if (isSelect){
Image->Canvas->Brush->Style=bsClear;
Image->Canvas->Pen->Style = psDot;
Image->Canvas->Pen->Width = 1;
isSelect=false;
DrawShape(Origin, MovePt,pmNotXor);
Cut->Enabled=false;
Copy->Enabled=false;
Image->Canvas->Brush->Style=bsSolid;
Image->Canvas->Pen->Style = psSolid;
Image->Canvas->Pen->Width=PenWidth->Value;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ImageMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TVarRec tempvar[2] = {X, Y};
Graphics::TBitmap *tmpBitmap;
if (ToolState==dtFill)
{
if (Button == mbLeft)
Image->Canvas->Brush->Color
= FGShape->Brush->Color;
else
Image->Canvas->Brush->Color
= BGShape->Brush->Color;
Image->Canvas->FloodFill(X, Y, Image1->Canvas->Pixels[X][Y], fsSurface);
return;
}
//只有填充需要处理鼠标右键,右键用于使用被景色填充。
if (Button != mbLeft)
return;
switch (ToolState){
case dtPencil:
Image->Canvas->Pen->Width=1;
Image->Canvas->Pen->Color = FGShape->Brush->Color;
Image->Canvas->Brush->Color = BGShape->Brush->Color;
Image->Canvas->MoveTo(X,Y);
break;
case dtBrush:
Image->Canvas->Pen->Color = FGShape->Brush->Color;
Image->Canvas->Brush->Color = BGShape->Brush->Color;
Image->Canvas->MoveTo(X,Y);
break;
case dtErase:
Image->Canvas->Pen->Color = BGShape->Brush->Color;
Image->Canvas->Brush->Color = BGShape->Brush->Color;
Image->Canvas->Pen->Width = 13;
Image->Canvas->MoveTo(X,Y);
break;
case dtText:
if (FontForm->ShowModal() == IDOK){
Image->Canvas->Font
=FontForm->FontDialog1->Font;
Image->Canvas->TextOut(X,Y,FontForm->Edit1->Text);
}
break;
case dtFog:
for (int i=0;i<FogSize*FogSize/8;i++){
Image->Canvas->
Pixels[X+random(FogSize)][Y+random(FogSize)]
=FGShape->Brush->Color;
}
break;
case dtSolidRect:
case dtSolidEllipse:
case dtSolidRndRect:
Image->Canvas->Brush->Color = FGShape->Brush->Color;
Image->Canvas->Pen->Color = FGShape->Brush->Color;
Image->Canvas->Brush->Style=bsSolid;
Origin = Point(X, Y);
StatusBar1->Panels->Items[0]->Text =
Format("起点位置: (%d, %d)", tempvar, 2);
MovePt = Origin;
break;
case dtLine:
case dtRectangle:
case dtEllipse:
case dtRoundRect:
Image->Canvas->Brush->Style=bsClear;
Image->Canvas->Pen->Color = FGShape->Brush->Color;
Origin = Point(X, Y);
StatusBar1->Panels->Items[0]->Text =
Format("起点位置: (%d, %d)", tempvar, 2);
MovePt = Origin;
break;
case dtZoomIn:
tmpBitmap = new Graphics::TBitmap();
tmpBitmap->Width = Image->Picture->Width*ZoomSize;
tmpBitmap->Height = Image->Picture->Height*ZoomSize;
tmpBitmap->Canvas->StretchDraw
(TRect(0,0,tmpBitmap->Width,tmpBitmap->Height),
Image->Picture->Graphic);
Image->Picture->Graphic = tmpBitmap;
delete tmpBitmap;
break;
case dtZoomOut:
tmpBitmap = new Graphics::TBitmap();
tmpBitmap->Width = Image->Picture->Width/ZoomSize;
tmpBitmap->Height =
- 1
- 2
前往页