void __fastcall TForm1::FormCreate(TObject *Sender)
{
  HINSTANCE HInst;
  {   //kanoume load tous analogous kersores pou tha xrisimopoihsoume
    HInst = reinterpret_cast<HINSTANCE>(HInstance);
    Screen->Cursors[crFill] = LoadCursor(HInst, "FILL");  //kouvas gia to fill
    Screen->Cursors[crPlus] = LoadCursor(HInst, "PLUS");  //stavros gia ta sximata
    Screen->Cursors[crDraw] = LoadCursor(HInst, "DRAW");  //molivi
    Screen->Cursors[crErase] = LoadCursor(HInst, "ERASE"); //goma
    Cursor = TCursor(crDraw);
   }
   {
   SkinImage=new TPicture;   //anoigma tis eikonas ap' to arxeio pou tha
                             //valoume sto toolbar...me onome toolpic.bmp
   SkinImage->LoadFromFile("toolpic.bmp");
   }
        {  //kanoume disabled ta koumpia undo/redo kata to anoigma tis formas
        Undo1->Enabled=false;
        Redo1->Enabled=false;
        ToolUndo->Enabled=false;
        ToolRedo->Enabled=false;
       }
}
//---------------------------------------------------------------------------
void    TRForm::ShowCusorOnImg(int   X ,int  Y)
{
#define INV 3
    if((X>selectedRt.Left-INV&&X<selectedRt.Left+INV)&& \
            (Y>selectedRt.Top-INV&&Y<selectedRt.Top+INV))
    {
        Image1->Cursor = TCursor(crSizeNWSE_); //crSizeNWSE
        selectdPos = epLeftUp;
    }
    else if((X>selectedRt.Right-INV&&X<selectedRt.Right+INV)&& \
            (Y>selectedRt.Bottom-INV&&Y<selectedRt.Bottom+INV))
    {
        Image1->Cursor = TCursor(crSizeNWSE_); // crSizeNWSE
        selectdPos = epRightDown;
    }
    else if((X>selectedRt.Left-INV&&X<selectedRt.Left+INV)&& \
            (Y>selectedRt.Bottom-INV&&Y<selectedRt.Bottom+INV))
    {
        Image1->Cursor = TCursor(crSizeNESW_); // crSizeNESW
        selectdPos = epLeftDown;
    }
    else if((X>selectedRt.Right-INV&&X<selectedRt.Right+INV)&& \
            (Y>selectedRt.Top-INV&&Y<selectedRt.Top+INV))
    {
        Image1->Cursor = TCursor(crSizeNESW_); // crSizeNESW
        selectdPos = epRightUp;
    }
    else if(X>selectedRt.Left-INV&&X<selectedRt.Right+INV && \
            Y>selectedRt.Top-INV&&Y<selectedRt.Bottom+INV)
    {
        if(iWhichShapeDraw==0)
            Image1->Cursor = TCursor(crSizeAll_);//crSizeAll
        else
            Image1->Cursor = crCross;// ...

        Image1->PopupMenu = PopupMenu1;
    }
    else
    {
        Image1->Cursor = TCursor(crCursor_);  //TCursor(crCursor_)
        //Screen->Cursor = TCursor(crCursor_);// error ...
        Image1->PopupMenu = NULL;
    }
}
//---------------------------------------------------------------------------
void    TRForm::InitRegionCapture()
{
    //ShowMessage("InitRegionCapture");
    Image1->Cursor = TCursor(crCursor_);  //TCursor(crCursor_)
    Image2->Visible = false;
    //CoolBar1->Visible = false;
    CoolBar1->Left = Screen->Width+10;
    CoolBar1->Top = Screen->Height+10;
    //lblCapture->Visible = false;
    lblCapture->Left = Screen->Width+10;
    lblCapture->Top = Screen->Height+10;
    panelPenBrush->Visible = false;
    editWord->Visible = false;

    iWhichShapeDraw = 0;
    tbRectangle->Down = false;
    tbRound->Down = false;
    tbWord->Down = false;
    tbLine->Down = false;
    tbRoundRect->Down = false;
    originPt.x = movePt.x = 0;
    originPt.y = movePt.y = 0;
    //selectedRt = TRect(0 ,0 ,0 ,0);
    bLeftMDown = bLeftMDown_ = bIsRegionSelected = false;

    vector<TShape_*>::iterator  it = vecShapes.begin();
    for(; it!=vecShapes.end(); it++)
        delete (*it);
    vecShapes.clear();
    if(shapeTemp!=NULL) // ...
    {
        delete shapeTemp;
        shapeTemp = NULL;
    }
    //Image1->Repaint();
}
//simvan kata to opio i goma perni ton analogo kersora (goma)
void __fastcall TForm1::EraseButtonClick(TObject *Sender)
{
        Form1->Cursor=TCursor(crErase);
        ScrollBox1->Cursor=TCursor(crErase);
}
//simvan kata to opio to molivi perni ton analogo kersora (molivi)
void __fastcall TForm1::PencilButtonClick(TObject *Sender)
{
        Form1->Cursor=TCursor(crDraw);
        ScrollBox1->Cursor=TCursor(crDraw);
}
//simvan kata to opio to gemisma xromatos perni ton analogo kersora (kouva)
void __fastcall TForm1::FillButtonClick(TObject *Sender)
{
     Form1->Cursor=TCursor(crFill);
     ScrollBox1->Cursor=TCursor(crFill);
}
//---------------------------------------------------------------------------
void    TRForm::HandleSelRect(int   X ,int  Y)
{
    TPoint  temp(X ,Y);
    temp -= leftDownPt;
    switch(Image1->Cursor)
    {
    case TCursor(crSizeAll_): // crSizeAll
    {
        DrawRect(originPt, movePt, pmNotXor);
        //DrawRect(Point(selectedRt.left,selectedRt.top) ,
        //         Point(selectedRt.right,selectedRt.bottom) , pmNotXor);
        // 重新构造originPt movePt,左上角,右下角
        originPt = TPoint(selectedRt.left,selectedRt.top);
        originPt += temp;
        movePt = TPoint(selectedRt.right,selectedRt.bottom);
        movePt += temp;
        DrawRect(originPt, movePt, pmNotXor);
        break;
    }
    case TCursor(crSizeNWSE_): //crSizeNWSE
    {
        if(selectdPos==epLeftUp)
        {
            //ShowMessage("selectdPos==epLeftUp");
            DrawRect(originPt, movePt, pmNotXor);
            originPt = TPoint(selectedRt.right,selectedRt.bottom);
            movePt = TPoint(selectedRt.left,selectedRt.top);
            movePt += temp;
            DrawRect(originPt, movePt, pmNotXor);
        }
        else
        {
            DrawRect(originPt, movePt, pmNotXor);
            originPt = TPoint(selectedRt.left,selectedRt.top);
            movePt = TPoint(selectedRt.right,selectedRt.bottom);
            movePt += temp;
            DrawRect(originPt, movePt, pmNotXor);
        }
        break;
    }
    case TCursor(crSizeNESW_): // crSizeNESW
    {
        if(selectdPos==epLeftDown)
        {
            //ShowMessage("selectdPos==epLeftUp");
            DrawRect(originPt, movePt, pmNotXor);
            originPt = TPoint(selectedRt.right,selectedRt.top);
            movePt = TPoint(selectedRt.left,selectedRt.bottom);
            movePt += temp;
            DrawRect(originPt, movePt, pmNotXor);
        }
        else
        {
            DrawRect(originPt, movePt, pmNotXor);
            originPt = TPoint(selectedRt.left,selectedRt.bottom);
            movePt = TPoint(selectedRt.right,selectedRt.top);
            movePt += temp;
            DrawRect(originPt, movePt, pmNotXor);
        }
        break;
    }
    case crCross:
    {
        /*------ */
        break;
    }
    case TCursor(crCursor_):
        break;
    default :
        break;
    }
}