~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/lime/draw2d/SnapToGrid.js

  • Committer: parra
  • Date: 2010-03-15 15:56:56 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1448
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This notice must be untouched at all times.
 
2
 
 
3
Open-jACOB Draw2D
 
4
The latest version is available at
 
5
http://www.openjacob.org
 
6
 
 
7
Copyright (c) 2006 Andreas Herz. All rights reserved.
 
8
Created 5. 11. 2006 by Andreas Herz (Web: http://www.freegroup.de )
 
9
 
 
10
LICENSE: LGPL
 
11
 
 
12
This library is free software; you can redistribute it and/or
 
13
modify it under the terms of the GNU Lesser General Public
 
14
License (LGPL) as published by the Free Software Foundation; either
 
15
version 2.1 of the License, or (at your option) any later version.
 
16
 
 
17
This library is distributed in the hope that it will be useful,
 
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
20
Lesser General Public License for more details.
 
21
 
 
22
You should have received a copy of the GNU Lesser General Public
 
23
License along with this library; if not, write to the Free Software
 
24
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA,
 
25
or see http://www.gnu.org/copyleft/lesser.html
 
26
*/
 
27
 
 
28
/**
 
29
 * 
 
30
 * @version 0.9.14
 
31
 * @author Andreas Herz
 
32
 * @constructor
 
33
 */
 
34
draw2d.SnapToGrid=function(/*:draw2d.Workflow*/ workflow)
 
35
{
 
36
   draw2d.SnapToHelper.call(this,workflow);
 
37
}
 
38
 
 
39
draw2d.SnapToGrid.prototype = new draw2d.SnapToHelper;
 
40
 
 
41
/**
 
42
 * Applies a snapping correction to the given result. Snapping can occur in the four
 
43
 * primary directions: NORTH, SOUTH, EAST, WEST, as defined on {@link draw2d.PositionConstants}.
 
44
 * By default a Point is treated as an empty Rectangle. Only NORTH and WEST should be used
 
45
 * in general.  But SOUTH and EAST may also be used.  Similarly, VERTICAL and HORIZONTAL
 
46
 * may be used to allow a point to snap to the "center" or "middle" as defined by the
 
47
 * concrete subclass.
 
48
 */
 
49
draw2d.SnapToGrid.prototype.snapPoint=function(/*:int*/ direction, /*:draw2d.Point*/ inputPoint, /*:draw2d.Point*/ resultPoint)
 
50
{
 
51
  resultPoint.x=this.workflow.gridWidthX*Math.floor(((inputPoint.x + this.workflow.gridWidthX/2.0) / this.workflow.gridWidthX));
 
52
  resultPoint.y=this.workflow.gridWidthY*Math.floor(((inputPoint.y + this.workflow.gridWidthY/2.0) / this.workflow.gridWidthY));
 
53
  return 0;
 
54
}
 
55
 
 
56
/**
 
57
 * Applies a snap correction to a Rectangle based on a given Rectangle.  The provided
 
58
 * baseRect will be used as a reference for snapping.  The types of snapping to be
 
59
 * performed are indicated by the snapOrientation parameter. The correction is applied to
 
60
 * the result field.
 
61
 * <P>
 
62
 * All coordinate information received and returned by this method should be in absolute 
 
63
 * coordinates.
 
64
 */
 
65
draw2d.SnapToGrid.prototype.snapRectangle=function(/*:draw2d.Dimension*/ inputBounds,  /*:draw2d.Dimension*/ resultBounds)
 
66
{
 
67
    resultBounds.x = inputBounds.x;
 
68
    resultBounds.y = inputBounds.y;
 
69
    resultBounds.w = inputBounds.w;
 
70
    resultBounds.h = inputBounds.h;
 
71
    return 0;
 
72
}