Board index » cppbuilder » The mouse move make graphic data move

The mouse move make graphic data move

Dear Sir :
My code as following,  It can't determine a correct direction when I move
mouse from right to left.
It just only move to up or down.
By the way, Its speed is so slowly to move, Why?

void __fastcall TFormImageEdit::ImageEditGridMouseMove(TObject *Sender,
      TShiftState Shift, int X, int Y)
{
    NewImgMovePosX=X;
    NewImgMovePosY=Y;
if (ImgMove)
  {
  if (OldImgMovePosY>NewImgMovePosY )
       ImageMoveDirection(WM_MoveUp ) ;    //this function is writed myself
   if (OldImgMovePosY<NewImgMovePosY )
      ImageMoveDirection(WM_MoveDown);
   if (OldImgMovePosX<NewImgMovePosX )
      ImageMoveDirection(WM_MoveLeft ) ;
   if (OldImgMovePosX>NewImgMovePosX )
      ImageMoveDirection(WM_MoveRight ) ;
  }

Quote
}

David
 

Re:The mouse move make graphic data move


Hello David,
While its hard to be sure as I can't see your ImageMoveDirection function, I
have spotted one problem.

Quote
>   if (OldImgMovePosY>NewImgMovePosY )
>        ImageMoveDirection(WM_MoveUp ) ;    //this function is writed
myself
>    if (OldImgMovePosY<NewImgMovePosY )
>       ImageMoveDirection(WM_MoveDown);
>    if (OldImgMovePosX<NewImgMovePosX )

If you are following a normal coordinate system, then if your old X ordinate
is less than the new one, then the image is moving right, not left.

Quote
>       ImageMoveDirection(WM_MoveLeft ) ;
>    if (OldImgMovePosX>NewImgMovePosX )

Same as above, you ahve it round the wrong way.

Quote
>       ImageMoveDirection(WM_MoveRight ) ;

As for the speed of moving, well I would need to be able to see your
ImageMoveDirection function to be able to help there.

Vesty.

Re:The mouse move make graphic data move


Quote
Dear  Vesty wrote:
> If you are following a normal coordinate system, then if your old X
ordinate
> is less than the new one, then the image is moving right, not left.

Thanks , I see;

Quote
> While its hard to be sure as I can't see your ImageMoveDirection function,
I
> have spotted one problem.

 > As for the speed of moving, well I would need to be able to see your

Quote
> ImageMoveDirection function to be able to help there.

my code as following:

int cnt=1;
  switch(MoveDirection)
  {
  case WM_MoveUp:
     for (int i=0 ; i < ImageEditGrid->Width ; i++)
       {
          ImgRowBuf[0][i*3]=ImageBuffer[0][i*3];
          ImgRowBuf[0][i*3+1]=ImageBuffer[0][i*3+1];
          ImgRowBuf[0][i*3+2]=ImageBuffer[0][i*3+2];
       }
     for ( int col =0 ,j ; col <  ImageEditGrid->Width  ; col++)   //i =col
,j= row
        for ( int row  =0 ;row < ImageEditGrid->Height  ; row++)
//scanline -->row
              {
                      j= (row+cnt)  >= ImageEditGrid->Height
                          ? (row+cnt)  - ImageEditGrid->Height
                          : (row+cnt) ;    //if > width then wrap
                      ImageBuffer[row][col*3] = ImageBuffer[j][col*3];
//Lsb->Msb
                      ImageBuffer[row][col*3+1] =ImageBuffer[j][col*3+1];
                      ImageBuffer[row][col*3+2] =ImageBuffer[j][col*3+2];
               }
     for (int i=0 ; i < ImageEditGrid->Width ; i++)
       {
//          ImageBuffer[ImageEditGrid->Height-1][i*3]=ImgColBuf[0][i*3];
//add the three row will make some error, so I mark it
//          ImageBuffer[ImageEditGrid->Height-1][i*3+1]=ImgColBuf[0][i*3+1];
//          ImageBuffer[ImageEditGrid->Height-1][i*3+2]=ImgColBuf[0][i*3+2];
       }
       break;
  case WM_MoveDown:
     for (int i=0 ; i < ImageEditGrid->Width ; i++)
       {
          ImgRowBuf[0][i*3]=ImageBuffer[ImageEditGrid->Height-1][i*3];
          ImgRowBuf[0][i*3+1]=ImageBuffer[ImageEditGrid->Height-1][i*3+1];
          ImgRowBuf[0][i*3+2]=ImageBuffer[ImageEditGrid->Height-1][i*3+2];
       }
     for ( int col=  ImageEditGrid->Width-1,j ; col >=0 ; col--)   //i =col
,j= row
        for ( int row= ImageEditGrid->Height-1 ;row  >=0 ; row--)
//scanline -->row, ??|Cao???
              {
                      j= (row+cnt)  >= ImageEditGrid->Height
                          ? (row+cnt)  - ImageEditGrid->Height
                          : (row+cnt) ;    //if > width then wrap
                      ImageBuffer[j][col*3] = ImageBuffer[row][col*3] ;
//Lsb->Msb
                      ImageBuffer[j][col*3+1]  =ImageBuffer[row][col*3+1];
                      ImageBuffer[j][col*3+2]  =ImageBuffer[row][col*3+2];
               }
     for (int i=0 ; i < ImageEditGrid->Width ; i++)
       {
          ImageBuffer[0][i*3]=ImgColBuf[0][i*3];
          ImageBuffer[0][i*3+1]=ImgColBuf[0][i*3+1];
          ImageBuffer[0][i*3+2]=ImgColBuf[0][i*3+2];
       }
       break;

Quote
}

then show it as following:
    for ( int j =0 ; j<  ImageEditGrid->Height; j++)    //scanline -->row,
??|Cao???
      for ( int i =0 ; i<  ImageEditGrid->Width ; i++)   //i =col ,j= row
           {
                   int CRed =ImageBuffer[j][i*3];
                   int CGreen =ImageBuffer[j][i*3+1];
                   int CBlue =ImageBuffer[j][i*3+2];
                   SetPixel(ImageEditGrid->Canvas->Handle,i,j,(COLORREF)
RGB(CRed,CGreen,CBlue)) ;
           }

has any other way to make it the speedest.
and how can i  reduce its rate that graphic data

Thanks~

David

Other Threads