Dave's Brain

Browse - programming tips - javascript get current position of dojox gfx object

Date: 2009aug6
Language: javaScript
Keywords: dojo

Q.  How do I get the current position of a dojox.gfx object?

A.  This function show you how:

function getPosition(myshape) {
	var	shape, trans, x, y;

	shape = myshape.getShape()

	trans = myshape.getTransform();
	if (trans == null) {	// will be null if it hasn't yet moved
		trans = { dx: 0, dy: 0 };
	}
		
	x = shape.x + trans.dx;
	y = shape.y + trans.dy;

	return {x, y};
}

function exampleUse() {
	var		surface, rect, position;

	surface = dojox.gfx.createSurface(...);
	rect = surface.createRect(...)
	new dojox.gfx.Moveable(rect);

	// ... later, after user has had a chance to move it ...
	position = getPosition(rect);
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: