paperjs pointtext onhover select and resize

僤鯓⒐⒋嵵緔 提交于 2019-12-24 20:29:17

问题


I am trying to add pointtext on canvas using paperjs. i am able to create pointtext on canvas but need to handle drag and resize of text.

scope.drawText = function () {
               var pointTextLocation = new p.Point(100,100);
                var myText = new p.PointText(pointTextLocation);
                myText.fillColor = 'red';
                myText.fontSize= 25;
                myText.content = 'Sample Text';
            };

is it possible to do like below screen using paperjs.

I didn't find anywhere on google. Please suggest how to do this?


回答1:


It is possible (using Item.scaling) but you will have to code the scaling box yourself (by drawing it with regular shapes interacting with mouse and keyboard events). This hand made scaling box will control your PointText.scaling and PointText.rotation properties.

The scaling box is not simple to code, neither hard, and I am very sorry to notice that, as often, this is an extremely frequent problem which does not have a standard solution yet (too many solutions to implement such scaling box), and to my knowledge there are no good code snippet to rely on yet.




回答2:


i have updated my code.I am able to create pointtext and dragging anywhere else in canvas. check here

But when i double click i have to edit text. How to do it?

var pointTextLocation = new p.Point(x,y);

                var myText = new p.PointText(pointTextLocation);
                myText.fillColor = 'red';
                myText.fontSize= 25;
                myText.content = 'Sample Text';

                myText.onDoubleClick = function(event) {
                    this.fontSize= 50;
                }
                myText.onClick = function(event) {
                    if(this.selected){
                        this.selected= false;
                    }else{
                     this.selected= true;   
                    }

                }
                 myText.onMouseDrag = function(event) {
                    myText.position=event.point;
                }


来源:https://stackoverflow.com/questions/55509206/paperjs-pointtext-onhover-select-and-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!