Skip to content

Commit

Permalink
event on paper size change
Browse files Browse the repository at this point in the history
  • Loading branch information
crocsg committed Jun 11, 2024
1 parent 9e823f4 commit 1a46370
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
18 changes: 16 additions & 2 deletions src/PaperCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class PaperCanvas extends React.Component {
this.mouseUp = this.mouseUp.bind(this);
this.mouseMove = this.mouseMove.bind(this);
this.resize = this.resize.bind(this);
this.OnPaperParamChange = this.OnPaperParamChange.bind(this);

this.importSvg = this.importSvg.bind(this);
this.addTxt = this.addTxt.bind(this);
Expand Down Expand Up @@ -63,14 +64,26 @@ class PaperCanvas extends React.Component {

return;
}
OnPaperParamChange ()
{
console.log ("onpaperchange " + this.context.Params.Paper.width + " " +
this.context.Params.Paper.height + " " +
this.context.Params.Paper.usablewidth + " " +
this.context.Params.Paper.usableheight);
this.resize ();
this.deleteFrame();
this.initFrame();
}
forceCanvasPixelSize() {
let canvasWidth = this.canvasRef.current.offsetWidth;// * window.devicePixelRatio;
let canvasHeight = this.canvasRef.current.offsetHeight;// * window.devicePixelRatio;
/*
console.log("client canvas size = " + this.canvasRef.current.clientWidth + " " + this.canvasRef.current.clientHeight);
console.log("brut canvas size = " + this.canvasRef.current.offsetWidth + " " + this.canvasRef.current.offsetHeight);
console.log("computed canvas size = " + canvasWidth + " " + canvasHeight);
console.log("window.devicePixelRatio = " + window.devicePixelRatio);
console.log("view size " + this.paper.project.view.size);
*/
this.canvasRef.current.width = canvasWidth;
this.canvasRef.current.height = canvasHeight;
this.paper.project.view.viewSize = [canvasWidth, canvasHeight];
Expand All @@ -81,7 +94,7 @@ class PaperCanvas extends React.Component {
let xratio = canvasWidth / this.context.Params.Paper.width;
let yratio = canvasHeight / this.context.Params.Paper.height;
let pixelMillimeterRatio = Math.min(xratio, yratio);

/*
//let pixelMillimeterRatio = Math.min(canvasWidth / this.context.Params.Paper.width, canvasHeight / this.context.Params.Paper.height);
console.log("canvas size :" + canvasWidth + " " + canvasHeight);
console.log("ratio :" + xratio + " " + yratio);
Expand All @@ -105,6 +118,7 @@ class PaperCanvas extends React.Component {
console.log("pix ratio:" + pixelMillimeterRatio);
console.log("paper view size " + this.paper.view.size.width + " " + this.paper.view.size.height)
*/
this.zoom = 1;
this.pixelRatio = pixelMillimeterRatio;
}
Expand Down Expand Up @@ -365,7 +379,7 @@ class PaperCanvas extends React.Component {

this.deleteFrame();
this.initFrame();
this.paper.view.draw();
//this.paper.view.draw();
}
SelectedDelete() {
if (this.selected) {
Expand Down
22 changes: 8 additions & 14 deletions src/Parameter.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ class Parameters extends React.Component {

option.Paper[key] = parseInt(value);
this.context.SetOption(option);

let canv = this.context.GetPaperCanvas();
if (canv)
{
canv.OnPaperParamChange ();
}


}
handleChangeNumeric (key, value)
Expand Down Expand Up @@ -271,20 +278,7 @@ class Parameters extends React.Component {
</div>
<div className="GroupColumn">
<div className="Group">
<p>
<label>
Interpolation Chemin (Path):&nbsp;
<input type="checkbox"
id="svginterpol"
label="Interpolation des chemins SVG "
checked={this.context.Params.SvgInterpol}
onChange={(e) => {
this.handleChangeGeneral('SvgInterpol', e.target.checked);
}}
key="svginterpol"
/>
</label>
</p>



<p>
Expand Down

0 comments on commit 1a46370

Please sign in to comment.