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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to Nudge layers or selection one pixel

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
yogiyang Posted - Feb 03 2015 : 01:04:30
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
5   L A T E S T    R E P L I E S    (Newest First)
yogiyang Posted - Feb 07 2015 : 02:48:26
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
xequte Posted - Feb 05 2015 : 16:46:07
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
yogiyang Posted - Feb 05 2015 : 02:03:18
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
xequte Posted - Feb 03 2015 : 21:57:28
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
w2m Posted - Feb 03 2015 : 07:06:44
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