ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to Nudge layers or selection one pixel
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
727 Posts

Posted - Feb 03 2015 :  01:04:30  Show Profile  Reply
I want to allow users to Nudge (move) the active layer 1 pixel at a time using Arrow Key.

If there is any kind of marquee selection then in that case users should be able to Nudge the selection 1 pixel at a time in any of the four directions using arrow keys.

I tried to code in Form's KeyDown event but even after setting KeyPreview property to True I am not getting the event to fire.

I have also tried ImageEn's KeyDown event but it is also not getting fired.

How to achieve this?

TIA



Yogi Yang

w2m

USA
1990 Posts

Posted - Feb 03 2015 :  07:06:44  Show Profile  Reply
None of the mouse events will work for the layer dimensions. You must use the LayerNotify event to change a layers dimensions as well as looking for the TIELayerEvent.ielResized or the TIELayerEvent.ielResize in the event.

For selections use the OnSelectionChange or OnSelectionChanged events.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

38615 Posts

Posted - Feb 03 2015 :  21:57:28  Show Profile  Reply
Hi Yogi

If KeyPreview is false, you should be able to access the cursor key click in ImageEnView's KeyDown. Does it fire for other keys?



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

yogiyang

India
727 Posts

Posted - Feb 05 2015 :  02:03:18  Show Profile  Reply
Hi Nigel,

Here is the code that I have put in OnKeyDown event of ImageEn.

procedure TMDIChild.ImageEnView1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  Result: Boolean;
begin
  Result := GetKeyState(VK_SHIFT) < 0;
  if Result then
  begin
    if ImageEnView1.LayersCurrent > 0 then
    begin
      if GetKeyState(VK_LEFT) < 0 then
      begin
        ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX :=
           ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX - 10;
      end;
      if GetKeyState(VK_RIGHT) < 0 then
      begin
        ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX :=
           ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX + 10;
      end;
      if GetKeyState(VK_UP) < 0 then
      begin
        ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY :=
           ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY - 10;
      end;
      if GetKeyState(VK_DOWN) < 0 then
      begin
        ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY :=
           ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY + 10;
      end;
      ImageEnView1.Update;
    end;
  end;
end;


I debugged code and it is working fine. But nothing is happening visibly in the control on screen. I mean the layer is not moving on screen.

What must be wrong?

TIA



Yogi Yang
Go to Top of Page

xequte

38615 Posts

Posted - Feb 05 2015 :  16:46:07  Show Profile  Reply
Hi Yogi

Sorry, in reviewing the code, I realize you must use OnSpecialKey:

procedure Tfmain.ImageEnView1SpecialKey(Sender: TObject; CharCode: Word; Shift: TShiftState; var Handled: Boolean);
begin
  if ( ssShift in Shift ) and ( ImageEnView1.LayersCurrent > 0 ) then
    case CharCode of
      VK_LEFT :
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX - 10;
          ImageEnView1.Update;
          Handled := True;
        end;
      VK_RIGHT :
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosX + 10;
          ImageEnView1.Update;
          Handled := True;
        end;
      VK_UP :
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY - 10;
          ImageEnView1.Update;
          Handled := True;
        end;
      VK_DOWN :
        begin
          ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY := ImageEnView1.Layers[ImageEnView1.LayersCurrent].PosY + 10;
          ImageEnView1.Update;
          Handled := True;
        end;
    end;
end;


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

yogiyang

India
727 Posts

Posted - Feb 07 2015 :  02:48:26  Show Profile  Reply
Hi Nigel,

Thanks a lot.

Here is the final code just for info and with hope it will help someone else in future.

if ImageEnView1.CurrentLayer.Locked then
    exit;
  if ImageEnView1.LayersCurrent = 0 then
    exit;

  case CharCode of
    VK_LEFT :
    begin
      ImageEnView1.CurrentLayer.PosX := ImageEnView1.CurrentLayer.PosX - 1;
      ImageEnView1.Update;
      Handled := True;
    end;
    VK_RIGHT :
    begin
      ImageEnView1.CurrentLayer.PosX := ImageEnView1.CurrentLayer.PosX + 1;
      ImageEnView1.Update;
      Handled := True;
    end;
    VK_UP :
    begin
      ImageEnView1.CurrentLayer.PosY := ImageEnView1.CurrentLayer.PosY - 1;
      ImageEnView1.Update;
      Handled := True;
    end;
    VK_DOWN :
    begin
      ImageEnView1.CurrentLayer.PosY := ImageEnView1.CurrentLayer.PosY + 1;
      ImageEnView1.Update;
      Handled := True;
    end;
  end;
  if (ssShift in Shift) then
  begin
    case CharCode of
      VK_LEFT :
      begin
        ImageEnView1.CurrentLayer.PosX := ImageEnView1.CurrentLayer.PosX - 10;
        ImageEnView1.Update;
        Handled := True;
      end;
      VK_RIGHT :
      begin
        ImageEnView1.CurrentLayer.PosX := ImageEnView1.CurrentLayer.PosX + 10;
        ImageEnView1.Update;
        Handled := True;
      end;
      VK_UP :
      begin
        ImageEnView1.CurrentLayer.PosY := ImageEnView1.CurrentLayer.PosY - 10;
        ImageEnView1.Update;
        Handled := True;
      end;
      VK_DOWN :
      begin
        ImageEnView1.CurrentLayer.PosY := ImageEnView1.CurrentLayer.PosY + 10;
        ImageEnView1.Update;
        Handled := True;
      end;
    end;
  end;  //if (ssShift in Shift) then



Yogi Yang
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: