Browse Source

using key events

Unknown 6 years ago
parent
commit
87416b2e86
3 changed files with 121 additions and 11 deletions
  1. 4 2
      vectoredit/umain.lfm
  2. 42 9
      vectoredit/umain.pas
  3. 75 0
      vectoredit/uvectororiginal.pas

+ 4 - 2
vectoredit/umain.lfm

@@ -1,7 +1,7 @@
 object Form1: TForm1
 object Form1: TForm1
-  Left = 376
+  Left = 374
   Height = 475
   Height = 475
-  Top = 25
+  Top = 0
   Width = 981
   Width = 981
   Caption = 'Vector Edit'
   Caption = 'Vector Edit'
   ClientHeight = 475
   ClientHeight = 475
@@ -10,6 +10,8 @@ object Form1: TForm1
   OnCreate = FormCreate
   OnCreate = FormCreate
   OnDestroy = FormDestroy
   OnDestroy = FormDestroy
   OnKeyDown = FormKeyDown
   OnKeyDown = FormKeyDown
+  OnKeyUp = FormKeyUp
+  OnUTF8KeyPress = FormUTF8KeyPress
   LCLVersion = '1.6.0.4'
   LCLVersion = '1.6.0.4'
   object BGRAVirtualScreen1: TBGRAVirtualScreen
   object BGRAVirtualScreen1: TBGRAVirtualScreen
     Left = 60
     Left = 60

+ 42 - 9
vectoredit/umain.pas

@@ -9,7 +9,7 @@ uses
   ExtCtrls, StdCtrls, ComCtrls, ExtDlgs, Menus, BGRAVirtualScreen,
   ExtCtrls, StdCtrls, ComCtrls, ExtDlgs, Menus, BGRAVirtualScreen,
   BCTrackbarUpdown, BCPanel, BGRAImageList, BCButton, BGRALazPaint,
   BCTrackbarUpdown, BCPanel, BGRAImageList, BCButton, BGRALazPaint,
   BGRABitmap, BGRABitmapTypes, BGRATransform, BGRALayerOriginal, BGRAGraphics,
   BGRABitmap, BGRABitmapTypes, BGRATransform, BGRALayerOriginal, BGRAGraphics,
-  uvectororiginal, uvectorialfill, uvectorshapes, BGRAGradientScanner;
+  uvectororiginal, uvectorialfill, uvectorshapes, BGRAGradientScanner, LCLType;
 
 
 const
 const
   EditorPointSize = 7;
   EditorPointSize = 7;
@@ -138,6 +138,8 @@ type
     procedure FormCreate(Sender: TObject);
     procedure FormCreate(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
     procedure FormDestroy(Sender: TObject);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
     procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
+    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+    procedure FormUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
     procedure ToolButtonBackFillChange(Sender: TObject);
     procedure ToolButtonBackFillChange(Sender: TObject);
     procedure ShapeBackColorMouseUp(Sender: TObject; {%H-}Button: TMouseButton;
     procedure ShapeBackColorMouseUp(Sender: TObject; {%H-}Button: TMouseButton;
       {%H-}Shift: TShiftState; X, Y: Integer);
       {%H-}Shift: TShiftState; X, Y: Integer);
@@ -248,7 +250,16 @@ var
 
 
 implementation
 implementation
 
 
-uses math, LCLType, BGRAPen, BGRAThumbnail, BGRAGradientOriginal, uvectorclipboard;
+uses math, BGRAPen, BGRAThumbnail, BGRAGradientOriginal, uvectorclipboard;
+
+function LCLKeyToSpecialKey(Key: Word): TSpecialKey;
+var
+  sk: TSpecialKey;
+begin
+  for sk := low(TSpecialKey) to high(TSpecialKey) do
+    if Key = SpecialKeyToLCL[sk] then exit(sk);
+  exit(skUnknown);
+end;
 
 
 function IsCreateShapeTool(ATool: TPaintTool): boolean;
 function IsCreateShapeTool(ATool: TPaintTool): boolean;
 begin
 begin
@@ -727,15 +738,16 @@ begin
   FBackTexRepetitionMenu.Free;
   FBackTexRepetitionMenu.Free;
 end;
 end;
 
 
-procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
-  );
+procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
+var
+  AHandled: boolean;
 begin
 begin
-  if Key = VK_RETURN then
+  if Assigned(img) then
   begin
   begin
-    Key := 0;
-    if Assigned(vectorOriginal) then
-      vectorOriginal.DeselectShape;
-  end else
+    img.KeyDown(Shift, LCLKeyToSpecialKey(Key), AHandled);
+    if AHandled then Key := 0;
+  end;
+
   if (Key = VK_X) and (ssCtrl in Shift) then
   if (Key = VK_X) and (ssCtrl in Shift) then
   begin
   begin
     Key := 0;
     Key := 0;
@@ -758,6 +770,27 @@ begin
   end;
   end;
 end;
 end;
 
 
+procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
+var
+  AHandled: boolean;
+begin
+  if Assigned(img) then
+  begin
+    img.KeyUp(Shift, LCLKeyToSpecialKey(Key), AHandled);
+    if AHandled then Key:= 0;
+  end;
+end;
+
+procedure TForm1.FormUTF8KeyPress(Sender: TObject; var UTF8Key: TUTF8Char);
+var AHandled: boolean;
+begin
+  if Assigned(img) then
+  begin
+    img.KeyPress(UTF8Key, AHandled);
+    if AHandled then UTF8Key:= '';
+  end;
+end;
+
 procedure TForm1.ToolButtonBackFillChange(Sender: TObject);
 procedure TForm1.ToolButtonBackFillChange(Sender: TObject);
 begin
 begin
   if FUpdatingFromShape then exit;
   if FUpdatingFromShape then exit;

+ 75 - 0
vectoredit/uvectororiginal.pas

@@ -75,6 +75,9 @@ type
     procedure MouseMove({%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; var {%H-}ACursor: TOriginalEditorCursor; var {%H-}AHandled: boolean); virtual;
     procedure MouseMove({%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; var {%H-}ACursor: TOriginalEditorCursor; var {%H-}AHandled: boolean); virtual;
     procedure MouseDown({%H-}RightButton: boolean; {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; var {%H-}ACursor: TOriginalEditorCursor; var {%H-}AHandled: boolean); virtual;
     procedure MouseDown({%H-}RightButton: boolean; {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; var {%H-}ACursor: TOriginalEditorCursor; var {%H-}AHandled: boolean); virtual;
     procedure MouseUp({%H-}RightButton: boolean; {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; var {%H-}ACursor: TOriginalEditorCursor; var {%H-}AHandled: boolean); virtual;
     procedure MouseUp({%H-}RightButton: boolean; {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; var {%H-}ACursor: TOriginalEditorCursor; var {%H-}AHandled: boolean); virtual;
+    procedure KeyDown({%H-}Shift: TShiftState; {%H-}Key: TSpecialKey; var {%H-}AHandled: boolean); virtual;
+    procedure KeyUp({%H-}Shift: TShiftState; {%H-}Key: TSpecialKey; var {%H-}AHandled: boolean); virtual;
+    procedure KeyPress({%H-}UTF8Key: string; var {%H-}AHandled: boolean); virtual;
     procedure BringToFront;
     procedure BringToFront;
     procedure SendToBack;
     procedure SendToBack;
     procedure MoveUp(APassNonIntersectingShapes: boolean);
     procedure MoveUp(APassNonIntersectingShapes: boolean);
@@ -172,6 +175,9 @@ type
     procedure MouseMove(Shift: TShiftState; X, Y: single; out ACursor: TOriginalEditorCursor; out AHandled: boolean); override;
     procedure MouseMove(Shift: TShiftState; X, Y: single; out ACursor: TOriginalEditorCursor; out AHandled: boolean); override;
     procedure MouseDown(RightButton: boolean; Shift: TShiftState; X, Y: single; out ACursor: TOriginalEditorCursor; out AHandled: boolean); override;
     procedure MouseDown(RightButton: boolean; Shift: TShiftState; X, Y: single; out ACursor: TOriginalEditorCursor; out AHandled: boolean); override;
     procedure MouseUp(RightButton: boolean; {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; out ACursor: TOriginalEditorCursor; out AHandled: boolean); override;
     procedure MouseUp(RightButton: boolean; {%H-}Shift: TShiftState; {%H-}X, {%H-}Y: single; out ACursor: TOriginalEditorCursor; out AHandled: boolean); override;
+    procedure KeyDown(Shift: TShiftState; Key: TSpecialKey; out AHandled: boolean); override;
+    procedure KeyUp(Shift: TShiftState; Key: TSpecialKey; out AHandled: boolean); override;
+    procedure KeyPress(UTF8Key: string; out AHandled: boolean); override;
   end;
   end;
 
 
 procedure RegisterVectorShape(AClass: TVectorShapeAny);
 procedure RegisterVectorShape(AClass: TVectorShapeAny);
@@ -254,6 +260,58 @@ begin
   end;
   end;
 end;
 end;
 
 
+procedure TVectorOriginalEditor.KeyDown(Shift: TShiftState; Key: TSpecialKey; out
+  AHandled: boolean);
+begin
+  if Assigned(FOriginal.SelectedShape) then
+  begin
+    if (Key = skReturn) and ([ssShift,ssCtrl,ssAlt]*Shift = []) then
+    begin
+      FOriginal.DeselectShape;
+      AHandled := true;
+      exit;
+    end else
+    if (Key = skEscape) and ([ssShift,ssCtrl,ssAlt]*Shift = []) and (FOriginal.SelectedShape.Usermode = vsuCreate) then
+    begin
+     FOriginal.SelectedShape.Remove;
+     AHandled:= true;
+    end else
+    begin
+      AHandled := false;
+      FOriginal.SelectedShape.KeyDown(Shift, Key, AHandled);
+      if AHandled then exit;
+    end;
+  end;
+
+  inherited KeyDown(Shift, Key, AHandled);
+end;
+
+procedure TVectorOriginalEditor.KeyUp(Shift: TShiftState; Key: TSpecialKey; out
+  AHandled: boolean);
+begin
+  if Assigned(FOriginal.SelectedShape) then
+  begin
+    AHandled := false;
+    FOriginal.SelectedShape.KeyUp(Shift, Key, AHandled);
+    if AHandled then exit;
+  end;
+
+  inherited KeyUp(Shift, Key, AHandled);
+end;
+
+procedure TVectorOriginalEditor.KeyPress(UTF8Key: string; out
+  AHandled: boolean);
+begin
+  if Assigned(FOriginal.SelectedShape) then
+  begin
+    AHandled := false;
+    FOriginal.SelectedShape.KeyPress(UTF8Key, AHandled);
+    if AHandled then exit;
+  end;
+
+  inherited KeyPress(UTF8Key, AHandled);
+end;
+
 { TVectorShape }
 { TVectorShape }
 
 
 function TVectorShape.GetIsSlow(AMatrix: TAffineMatrix): boolean;
 function TVectorShape.GetIsSlow(AMatrix: TAffineMatrix): boolean;
@@ -612,6 +670,23 @@ begin
   //nothing
   //nothing
 end;
 end;
 
 
+procedure TVectorShape.KeyDown(Shift: TShiftState; Key: TSpecialKey;
+  var AHandled: boolean);
+begin
+  //nothing
+end;
+
+procedure TVectorShape.KeyUp(Shift: TShiftState; Key: TSpecialKey;
+  var AHandled: boolean);
+begin
+  //nothing
+end;
+
+procedure TVectorShape.KeyPress(UTF8Key: string; var AHandled: boolean);
+begin
+  //nothing
+end;
+
 procedure TVectorShape.BringToFront;
 procedure TVectorShape.BringToFront;
 begin
 begin
   if Assigned(Container) then
   if Assigned(Container) then