Skip to content

Commit

Permalink
const ruler
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Dec 14, 2021
1 parent 4f7b810 commit c7b2cc4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions js/common/view/RulerIconNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,32 +68,34 @@ class RulerIconNode extends RulerNode {
this.touchArea = this.localBounds.dilatedXY( options.touchAreaDilationX, options.touchAreaDilationY );
this.mouseArea = this.localBounds.dilatedXY( options.mouseAreaDilationX, options.mouseAreaDilationY );

const ruler = rulerNode.ruler;

// rotate to create a vertical ruler icon
if ( rulerNode.ruler.isVertical ) {
if ( ruler.isVertical ) {
this.rotate( -Math.PI / 2 );
}

// Add a listener to forward drag events from the icon to its associated ruler.
this.addInputListener( DragListener.createForwardingListener( ( event: SceneryEvent ) => {

// Make the ruler visible.
rulerNode.ruler.visibleProperty.value = true;
ruler.visibleProperty.value = true;

// Set position of the ruler so that the pointer is initially at the center of rulerNode.
assert && assert( event.pointer.point ); // {Vector2|null}
const zoomTransform = zoomTransformProperty.value;
const viewPosition = rulerNode.globalToParentPoint( event.pointer.point! );
let x;
let y;
if ( rulerNode.ruler.isVertical ) {
if ( ruler.isVertical ) {
x = viewPosition.x - GOConstants.RULER_HEIGHT / 2;
y = viewPosition.y - zoomTransform.modelToViewDeltaY( rulerNode.ruler.length ) / 2;
y = viewPosition.y - zoomTransform.modelToViewDeltaY( ruler.length ) / 2;
}
else {
x = viewPosition.x - zoomTransform.modelToViewDeltaX( rulerNode.ruler.length ) / 2;
x = viewPosition.x - zoomTransform.modelToViewDeltaX( ruler.length ) / 2;
y = viewPosition.y - GOConstants.RULER_HEIGHT / 2;
}
rulerNode.ruler.positionProperty.value = zoomTransform.viewToModelXY( x, y );
ruler.positionProperty.value = zoomTransform.viewToModelXY( x, y );

// Forward events to the RulerNode.
rulerNode.startDrag( event );
Expand Down

1 comment on commit c7b2cc4

@pixelzoom
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.