Не получается рисовать динамически эллипс...ка исправить?
Код:
UGrEdit.h
#ifndef UGrEditH
#define UGrEditH
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>
#include <ExtDlgs.hpp>
#include <Menus.hpp>
#include <clipbrd.hpp>
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image3;
TSpeedButton *SBRect;
TSpeedButton *SBRectang;
TSpeedButton *SBEllip;
TMainMenu *MainMenu1;
TMenuItem *MFile;
TMenuItem *MOpen;
TMenuItem *MSave;
TMenuItem *N1;
TOpenPictureDialog *OpenPictureDialog1;
TSavePictureDialog *SavePictureDialog1;
TButton *Button1;
TColorBox *ColorBox1;
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall Image3MouseMove(TObject *Sender, TShiftState Shift, int X,
int Y);
void __fastcall Image3MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall MSaveClick(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
void __fastcall SBEllipClick(TObject *Sender);
void __fastcall Image3MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall ColorBox1Change(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
Graphics::TBitmap *BitMap = new Graphics::TBitmap;
TRect R,R0;
int X0,Y0,X1,Y1;
bool RBegin = false, REnd = false, RDrag = false;
extern PACKAGE TForm1 *Form1;
endif
Код:
UGrEdit.cpp
#include <vcl.h>
#pragma hdrstop
#include"Unit2.h"
#include "UGrEdit.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
// константы курсоров
const int crFill = 1;
const int crPlus = 2;
const int crDraw = 3;
const int crErase = 4;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::FormCreate(TObject *Sender)
{
// регистрация курсоров
Screen->Cursors[crFill] = LoadCursor(HInstance, "FILL");
Screen->Cursors[crPlus] = LoadCursor(HInstance, "PLUS");
Screen->Cursors[crDraw] = LoadCursor(HInstance, "DRAW");
Screen->Cursors[crErase] = LoadCursor(HInstance, "ERASE");
Image3->Canvas->Rectangle(200,120,200,120);
BitMap->Assign(Image3->Picture);
Image3->Canvas->Pen->Color=clBlack;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
BitMap->Free();
}
void __fastcall TForm1::Image3MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if (SBEllip->Down && RBegin==true)
{
// Режим рисования эллипса
Image3->Canvas->Pen->Mode=pmNotXor;
Image3->Canvas->Ellipse(R);
if (X0 < X) { R.Left = X0; R.Right = X; }
else { R.Left = X; R.Right = X0; }
if (Y0 < Y) { R.Top = Y0; R.Bottom = Y; }
else { R.Top = Y; R.Bottom = Y0; }
}
}
void __fastcall TForm1::Image3MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
RBegin=false;
}
void __fastcall TForm1::MSaveClick(TObject *Sender)
{
if (SavePictureDialog1->Execute())
{
BitMap->Assign(Image3->Picture);
BitMap->SaveToFile(SavePictureDialog1->FileName);
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
;
}
void __fastcall TForm1::SBEllipClick(TObject *Sender)
{
Image3->Canvas->Brush->Color=ColorBox1->Selected;
Image3->Canvas->Brush->Style=bsClear;
Image3->Canvas->Pen->Color=ColorBox1->Selected;
BitMap->Assign(Image3->Picture);
}
void __fastcall TForm1::Image3MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y)
{
if(SBEllip->Down){
RBegin=true;
X0=X;
Y0=Y;
}
}
void __fastcall TForm1::ColorBox1Change(TObject *Sender)
{
Image3->Canvas->Pen->Color=ColorBox1->Selected;
}