Skip to content

Commit f5a2238

Browse files
committed
Handle resize of TGeo drawing inside TCanvas
1 parent e41549d commit f5a2238

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

scripts/JSRoot.geom.js

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4160,21 +4160,13 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
41604160
jsrp.showProgress(msg);
41614161
}
41624162

4163-
/** @summary Check if HTML element was resized and drawing need to be adjusted */
4164-
TGeoPainter.prototype.checkResize = function(arg) {
4165-
let cp = this.getCanvPainter();
4166-
4167-
// firefox is the only browser which correctly supports resize of embedded canvas,
4168-
// for others we should force canvas redrawing at every step
4169-
if (cp && !cp.checkCanvasResize(arg)) return false;
4163+
/** @summary perform resize */
4164+
TGeoPainter.prototype.performResize = function(width, height) {
4165+
if ((this._scene_width === width) && (this._scene_height === height)) return false;
4166+
if ((width < 10) || (height < 10)) return false;
41704167

4171-
let sz = this.getSizeFor3d();
4172-
4173-
if ((this._scene_width === sz.width) && (this._scene_height === sz.height)) return false;
4174-
if ((sz.width<10) || (sz.height<10)) return false;
4175-
4176-
this._scene_width = sz.width;
4177-
this._scene_height = sz.height;
4168+
this._scene_width = width;
4169+
this._scene_height = height;
41784170

41794171
if (this._camera && this._renderer) {
41804172
if (this._camera.type == "PerspectiveCamera")
@@ -4192,6 +4184,19 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
41924184
return true;
41934185
}
41944186

4187+
4188+
/** @summary Check if HTML element was resized and drawing need to be adjusted */
4189+
TGeoPainter.prototype.checkResize = function(arg) {
4190+
let cp = this.getCanvPainter();
4191+
4192+
// firefox is the only browser which correctly supports resize of embedded canvas,
4193+
// for others we should force canvas redrawing at every step
4194+
if (cp && !cp.checkCanvasResize(arg)) return false;
4195+
4196+
let sz = this.getSizeFor3d();
4197+
return this.performResize(sz.width, sz.height);
4198+
}
4199+
41954200
/** @summary Toggle enlarge state */
41964201
TGeoPainter.prototype.toggleEnlarge = function() {
41974202
if (this.enlargeMain('toggle'))
@@ -4286,6 +4291,21 @@ JSROOT.define(['d3', 'three', 'geobase', 'painter', 'base3d'], (d3, THREE, geo,
42864291
return true;
42874292
}
42884293

4294+
/** @summary Redraw TGeo object inside TPad */
4295+
TGeoPainter.prototype.redraw = function(reason) {
4296+
if (!this._on_pad || (reason != "resize")) return;
4297+
4298+
let main = this.getFramePainter();
4299+
if (!main) return;
4300+
4301+
let sz = main.getSizeFor3d(main.access3dKind());
4302+
4303+
main.apply3dSize(sz);
4304+
4305+
return this.performResize(sz.width, sz.height);
4306+
}
4307+
4308+
42894309
/** @summary Create geo painter
42904310
* @private */
42914311
jsrp.createGeoPainter = function(divid, obj, opt) {

0 commit comments

Comments
 (0)