@@ -38,6 +38,7 @@ class PaperCanvas extends React.Component {
38
38
39
39
this . exportJSON = this . exportJSON . bind ( this ) ;
40
40
this . handleKeyPress = this . handleKeyPress . bind ( this ) ;
41
+ this . handleKeyUp = this . handleKeyUp . bind ( this ) ;
41
42
42
43
this . testPaper1 = this . testPaper1 . bind ( this ) ;
43
44
this . testPaper2 = this . testPaper2 . bind ( this ) ;
@@ -223,6 +224,7 @@ class PaperCanvas extends React.Component {
223
224
this . paper . view . on ( 'mousemove' , this . mouseMove ) ;
224
225
this . paper . view . on ( 'mouseup' , this . mouseUp ) ;
225
226
this . paper . view . on ( 'mousedown' , this . mouseDown ) ;
227
+ this . paper . view . on ( 'keyup' , this . handleKeyUp )
226
228
}
227
229
initFrame ( ) {
228
230
let bounds = new this . paper . Path . Rectangle ( 0 , 0 , this . context . Params . Paper . width , this . context . Params . Paper . height ) ;
@@ -573,6 +575,35 @@ class PaperCanvas extends React.Component {
573
575
console . log ( `Key "${ event . key } " pressed [event: keydown]` )
574
576
}
575
577
578
+ handleKeyUp ( event )
579
+ {
580
+ console . log ( `Key "${ event . key } " pressed [event: keyup]` )
581
+ if ( this . selected ) {
582
+ if ( event . key === "up" )
583
+ {
584
+ this . selected . position . y = this . selected . position . y - 1 ;
585
+ this . signalSelectedChange ( ) ;
586
+ }
587
+ else if ( event . key === "down" )
588
+ {
589
+ this . selected . position . y = this . selected . position . y + 1 ;
590
+ this . signalSelectedChange ( ) ;
591
+ }
592
+ else if ( event . key === "right" )
593
+ {
594
+ this . selected . position . x = this . selected . position . x + 1 ;
595
+ this . signalSelectedChange ( ) ;
596
+ }
597
+ else if ( event . key === "left" )
598
+ {
599
+ this . selected . position . x = this . selected . position . x - 1 ;
600
+ this . signalSelectedChange ( ) ;
601
+ }
602
+ }
603
+
604
+
605
+ }
606
+
576
607
exportJSON ( ) {
577
608
this . paper . activate ( ) ;
578
609
this . deselectAll ( ) ;
@@ -837,11 +868,7 @@ class PaperCanvas extends React.Component {
837
868
838
869
let canvasWidth = this . canvasRef . current . offsetWidth /*/ window.devicePixelRatio*/ ;
839
870
let canvasHeight = this . canvasRef . current . offsetHeight /*/ window.devicePixelRatio*/ ;
840
- //let xratio = canvasWidth / this.context.Params.Paper.width;
841
- //let yratio = canvasHeight / this.context.Params.Paper.height;
842
- //let pixelMillimeterRatio = Math.min(xratio, yratio);
843
- //this.canvasRef.current.width = this.canvasRef.current.offsetWidth;
844
- //this.canvasRef.current.height = this.canvasRef.current.offsetHeight;
871
+
845
872
this . paper . view . viewSize = [ canvasWidth , canvasHeight ] ;
846
873
}
847
874
testPaper2 ( ) {
@@ -944,7 +971,7 @@ class PaperCanvas extends React.Component {
944
971
945
972
return (
946
973
< >
947
- < div id = "falsediv" ref = { this . divref } >
974
+ < div id = "falsediv" ref = { this . divref } onKeyUp = { this . handleKeyUp } >
948
975
< canvas id = { this . props . Id } ref = { this . canvasRef } onKeyDown = { this . handleKeyPress } resize hdpi >
949
976
{ this . props . children }
950
977
</ canvas >
0 commit comments