Блок-схема алгоритма - Основные типы графических редакторов

РЕАЛИЗАЦИЯ

Для реализации приложения был использован языка программирования C++. Код получившейся программы представлен ниже:

Код в файле Unit1.h:

//---------------------------------------------------------------------------

#include <vcl. h>

#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma link "IWBaseControl"

#pragma link "IWBaseHTMLControl"

#pragma link "IWCompListbox"

#pragma link "IWControl"

#pragma link "IWVCLBaseControl"

#pragma link "cspin"

#pragma resource "*.dfm"

TForm1 *Form1;

Bool F;

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

F=false;

Image1->Canvas->Pen->Width=StrToInt(CSpinEdit1->Text) ;

PaintBox1->Canvas->Pen->Width=StrToInt(CSpinEdit1->Text) ;

Image1->Canvas->FloodFill(0,0,RGB(255,255,255), fsSurface);

Form1->DoubleBuffered=true;

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::Image1MouseDown(TObject *Sender, TMouseButton Button,

TShiftState Shift, int X, int Y)

{

PaintBox1->Left=X;

PaintBox1->Top=Y;

PaintBox1->Width=0;

PaintBox1->Height=0;

F=true;

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,

Int X, int Y)

{

If (F)

{

PaintBox1->Width=X-PaintBox1->Left;

PaintBox1->Height=Y-PaintBox1->Top;

Application->ProcessMessages();

PaintBox1->Canvas->MoveTo(1,1);

PaintBox1->Canvas->LineTo(X+1-PaintBox1->Left, Y+1-PaintBox1->Top);

}

StatusBar1->SimpleText="Положение мыши: X [ "+IntToStr(X)+" ] Y [ "+IntToStr(Y)+" ]"+"Цвет: R"+IntToStr(GetRValue(ColorToRGB(Image1->Canvas->Pen->Color)))+" G"+IntToStr(GetGValue(ColorToRGB(Image1->Canvas->Pen->Color)))+" B"+IntToStr(GetBValue(ColorToRGB(Image1->Canvas->Pen->Color)));

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

F=false;

Image1->Canvas->MoveTo(PaintBox1->Left, PaintBox1->Top);

Image1->Canvas->LineTo(PaintBox1->Left+PaintBox1->Width, PaintBox1->Top+PaintBox1->Height);

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::SBlackMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

Image1->Canvas->Pen->Color=RGB(0,0,0);

PaintBox1->Canvas->Pen->Color=RGB(0,0,0);

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::SRedMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

Image1->Canvas->Pen->Color=RGB(255,0,0);

PaintBox1->Canvas->Pen->Color=RGB(255,0,0);

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::SGreenMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

Image1->Canvas->Pen->Color=RGB(0,255,0);

PaintBox1->Canvas->Pen->Color=RGB(0,255,0);

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::SWhiteMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

Image1->Canvas->Pen->Color=RGB(255,255,255);

PaintBox1->Canvas->Pen->Color=RGB(255,255,255);

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::SBlueMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

Image1->Canvas->Pen->Color=RGB(0,0,255);

PaintBox1->Canvas->Pen->Color=RGB(0,0,255);

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::N1Click(TObject *Sender)

{

If (SaveDialog1->Execute())

{

Image1->Picture->SaveToFile(SaveDialog1->FileName );

}

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::N2Click(TObject *Sender)

{

If (OpenPictureDialog1->Execute())

{

Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName );

}

Image1->Canvas->Pen->Width=StrToInt(CSpinEdit1->Text) ;

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::CSpinEdit1Change(TObject *Sender)

{

Image1->Canvas->Pen->Width=StrToInt(CSpinEdit1->Text) ;

PaintBox1->Canvas->Pen->Width=StrToInt(CSpinEdit1->Text) ;

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::Shape1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

Image1->Canvas->Pen->Color=RGB(0,255,255);

PaintBox1->Canvas->Pen->Color=RGB(0,255,255);

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::Shape2MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

Image1->Canvas->Pen->Color=RGB(255,0,255);

PaintBox1->Canvas->Pen->Color=RGB(255,0,255);

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::Shape3MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)

{

Image1->Canvas->Pen->Color=RGB(255,255,0);

PaintBox1->Canvas->Pen->Color=RGB(255,255,0);

}

//---------------------------------------------------------------------------

Void __fastcall TForm1::Button1Click(TObject *Sender)

{

TRect r;

R. left=Image1->Left-1;

R. right=Image1->Width;

R. bottom=Image1->Height;

R. top=Image1->Top-1;

Image1->Canvas->Brush->Color=RGB(255,255,255);

Image1->Canvas->FillRect(r);

StatusBar1->SimpleText="Стерли!";

}

//---------------------------------------------------------------------------

Код в файле Unit1.h:

// ---------------------------------------------------------------------------

#ifndef Unit1H

#define Unit1H

// ---------------------------------------------------------------------------

#include <Classes. hpp>

#include <Controls. hpp>

#include <StdCtrls. hpp>

#include <Forms. hpp>

#include <Menus. hpp>

#include <FileCtrl. hpp>

#include <ExtCtrls. hpp>

#include <Dialogs. hpp>

#include <ExtDlgs. hpp>

#include "IWBaseControl. hpp"

#include "IWBaseHTMLControl. hpp"

#include "IWCompListbox. hpp"

#include "IWControl. hpp"

#include "IWVCLBaseControl. hpp"

#include <DBCtrls. hpp>

#include <ActnList. hpp>

#include <Buttons. hpp>

#include "cspin. h"

#include <ComCtrls. hpp>

// ---------------------------------------------------------------------------

Class TForm1 : public TForm {

__published: // IDE-managed Components

TImage *Image1;

TPaintBox *PaintBox1;

TPanel *Panel1;

TMainMenu *MainMenu1;

TOpenPictureDialog *OpenPictureDialog1;

TSaveDialog *SaveDialog1;

TPanel *Panel2;

TShape *SBlack;

TShape *SRed;

TShape *SGreen;

TShape *SWhite;

TShape *SBlue;

TLabel *Label2;

TLabel *Label1;

TMenuItem *N1;

TMenuItem *N2;

TCSpinEdit *CSpinEdit1;

TShape *Shape1;

TShape *Shape2;

TShape *Shape3;

TButton *Button1;

TStatusBar *StatusBar1;

Void __fastcall Image1MouseDown(TObject *Sender, TMouseButton Button,

TShiftState Shift, int X, int Y);

Void __fastcall Image1MouseMove(TObject *Sender, TShiftState Shift,

Int X, int Y);

Void __fastcall Image1MouseUp(TObject *Sender, TMouseButton Button,

TShiftState Shift, int X, int Y);

Void __fastcall SBlackMouseDown(TObject *Sender, TMouseButton Button,

TShiftState Shift, int X, int Y);

Void __fastcall SRedMouseDown(TObject *Sender, TMouseButton Button,

TShiftState Shift, int X, int Y);

Void __fastcall SGreenMouseDown(TObject *Sender, TMouseButton Button,

TShiftState Shift, int X, int Y);

Void __fastcall SWhiteMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,

Int X, int Y);

Void __fastcall SBlueMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,

Int X, int Y);

Void __fastcall N1Click(TObject *Sender);

Void __fastcall N2Click(TObject *Sender);

Void __fastcall CSpinEdit1Change(TObject *Sender);

Void __fastcall Shape1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,

Int X, int Y);

Void __fastcall Shape2MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,

Int X, int Y);

Void __fastcall Shape3MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,

Int X, int Y);

Void __fastcall Button1Click(TObject *Sender);

Private: // User declarations

Public : // User declarations

__fastcall TForm1(TComponent* Owner);

};

// ---------------------------------------------------------------------------

Extern PACKAGE TForm1 *Form1;

// ---------------------------------------------------------------------------

#endif

Похожие статьи




Блок-схема алгоритма - Основные типы графических редакторов

Предыдущая | Следующая