client/js/foundation/geom/rect/rect.js in rsence-pre-3.0.0.8 vs client/js/foundation/geom/rect/rect.js in rsence-pre-3.0.0.9

- old
+ new

@@ -51,11 +51,11 @@ * **/ constructor: function() { this.viewIds = []; var _args=arguments; - + if (_args.length === 0) { this._constructorDefault(); } else if (_args.length === 4) { this._constructorSides(_args[0],_args[1],_args[2],_args[3]); } @@ -124,11 +124,11 @@ } else { return [ _this.left, _this.top, _this.width, _this.height ]; } }, - + _updateFlexibleDimensions: function(){ var _this = this, _viewIds = _this.viewIds, _parentElemId, @@ -144,10 +144,19 @@ } _viewId = _viewIds[0]; _view = HSystem.views[_viewId]; if(_view.flexRight || _view.flexBottom){ ELEM.flush(); + //// This will increase performance somewhat, but needs to be broader than it is: + // var i=0,_parentElemIds=[_view.elemId],_parentView; + // for(;i<_view.parents.length;i++){ + // _parentView = _view.parents[i]; + // if(_parentView && _parentView.elemId !== null && _parentView.elemId !== undefined){ + // _parentElemIds.push(_parentView.elemId); + // } + // } + // ELEM.flushElem(_parentElemIds); _parentSize = _view.parentSize(); if( _view.flexRight && _view.flexLeft ){ // calculate width and right _virtualWidth = _parentSize[0] - _this.left - _view.flexRightOffset; if( _view.minWidth !== null && _virtualWidth < _view.minWidth ){ _this.width = _view.minWidth; @@ -196,42 +205,44 @@ * * Use the accompanied methods instead. * **/ updateSecondaryValues: function(_noSize) { - + // this._updateFlexibleDimensions(); - + /** * isValid is true if the Rect's right side is greater than or equal to its left * and its bottom is greater than or equal to its top, and false otherwise. * An invalid rectangle can't be used to define an interface area (such as * the frame of a view or window). **/ this.isValid = ( this.right >= this.left && this.bottom >= this.top ); - + /** * * The Point-returning functions return the coordinates of one of the * rectangle's four corners. **/ this.leftTop = new HPoint(this.left, this.top); this.leftBottom = new HPoint(this.left, this.bottom); this.rightTop = new HPoint(this.right, this.top); this.rightBottom = new HPoint(this.right, this.bottom); - + /** * The width and height of a Rect's rectangle, as returned through these * properties. **/ if(!_noSize){ this.width = (this.right - this.left); this.height = (this.bottom - this.top); } + this.position = [ this.left, this.top ]; + this.size = [ this.width, this.height ]; return this; }, - + /** = Description * Sets the object's rectangle by defining the coordinates of all four * sides. * * The other set...() functions move one of the rectangle's corners to the @@ -246,11 +257,11 @@ * +_bottom+:: The coordinate of the bottom side. * **/ set: function() { var _args=arguments; - + if (_args.length === 0) { this._constructorDefault(); } else if (_args.length === 4) { this._constructorSides(_args[0],_args[1],_args[2],_args[3]); } @@ -264,11 +275,11 @@ throw "Invalid number of arguments."; } this.updateSecondaryValues(); return this; }, - + /** = Description * Moves the rect's left side to a new coordinate. * * = Parameters * +_left+:: The new left side coordinate (in px) @@ -277,11 +288,11 @@ setLeft: function(_left){ this.left = _left; this.updateSecondaryValues(); return this; }, - + /** = Description * Moves the rect's right side to a new coordinate. * * = Parameters * +_right+:: The new right side coordinate (in px) @@ -290,11 +301,11 @@ setRight: function(_right){ this.right = _right; this.updateSecondaryValues(); return this; }, - + /** = Description * Moves the rect's top side to a new coordinate. * * = Parameters * +_top+:: The new top side coordinate (in px) @@ -303,11 +314,11 @@ setTop: function(_top){ this.top = _top; this.updateSecondaryValues(); return this; }, - + /** = Description * Moves the rect's bottom side to a new coordinate. * * = Parameters * +_bottom+:: The new bottom side coordinate (in px) @@ -316,11 +327,11 @@ setBottom: function(_bottom){ this.bottom = _bottom; this.updateSecondaryValues(); return this; }, - + /** = Description * Moves the rects left and top sides to a new point. Affects the position, * width and height. * * = Parameters @@ -331,11 +342,11 @@ this.left=_point.x; this.top=_point.y; this.updateSecondaryValues(); return this; }, - + /** = Description * Moves the rects left and bottom sides to a new point. Affects the left * position, width and height. * * = Parameters @@ -346,11 +357,11 @@ this.left=_point.x; this.bottom=_point.y; this.updateSecondaryValues(); return this; }, - + /** = Description * Moves the rects right and top sides to a new point. Affects the top * position, width and height. * * = Parameters @@ -361,11 +372,11 @@ this.right=_point.x; this.top=_point.y; this.updateSecondaryValues(); return this; }, - + /** = Description * Moves the rects right and bottom sides to a new point. Affects the width * and height. Does not affect the position. * * = Parameters @@ -376,11 +387,11 @@ this.right=_point.x; this.bottom=_point.y; this.updateSecondaryValues(); return this; }, - + /** = Description * Moves the rects right side to a new coordinate. Does not affect the position. * * = Parameters * +_width+:: A numeric value representing the new target width of the rect. @@ -433,11 +444,11 @@ this.right = this.left + _width; this.bottom = this.top + _height; this.updateSecondaryValues(); return this; }, - + /** = Description * Returns true if the Rect has any area even a corner or part * of a side in common with rect, and false if it doesn't. * * = Parameters @@ -462,16 +473,16 @@ }, overlaps: function( _rect, _insetbyX, _insetByY ){ return this.intersects( _rect, _insetbyX, _insetByY ); }, - + /** = Description * Returns true if point or rect lies entirely within the Rect's * rectangle (and false if not). A rectangle contains the points that lie * along its edges; for example, two identical rectangles contain each other. - * + * * Also works with HPoint instances. * * = Parameters * +_obj+:: A HRect or HPoint to check the containment with. * @@ -496,11 +507,11 @@ }, _containsRect: function(_rect) { return ( _rect.left >= this.left && _rect.right <= this.right && _rect.top >= this.top && _rect.bottom <= this.bottom ); }, - + /** = Description * Insets the sides of the Rect's rectangle by x units (left and * right sides) and y units (top and bottom). Positive inset values shrink * the rectangle; negative values expand it. Note that both sides of each * pair moves the full amount. For example, if you inset a Rect by (4,4), the @@ -535,11 +546,11 @@ this.left += x; this.top += y; this.right -= x; this.bottom -= y; }, - + /** = Description * Moves the Rect horizontally by x units and vertically by y * units. The rectangle's size doesn't change. * * = Parameters @@ -570,11 +581,11 @@ this.left += x; this.top += y; this.right += x; this.bottom += y; }, - + /** = Description * Moves the Rect to the location (x,y). * * = Parameters * using a HPoint: @@ -604,11 +615,11 @@ this.right += x-this.left; this.left = x; this.bottom += y-this.top; this.top = y; }, - + /** = Description * Returns true if the two objects' rectangles exactly coincide. * * = Parameters * +_rect+:: A HRect instance to compare to. @@ -619,11 +630,11 @@ **/ equals: function(_rect) { return (this.left === _rect.left && this.top === _rect.top && this.right === _rect.right && this.bottom === _rect.bottom); }, - + /** = Description * Creates and returns a new Rect that's the intersection of this Rect and * the specified Rect. The new Rect encloses the area that the two Rects have * in common. If the two Rects don't intersect, the new Rect will be invalid. * @@ -638,11 +649,11 @@ return new HRect( Math.max(this.left, _rect.left), Math.max(this.top, _rect.top), Math.min(this.right, _rect.right), Math.min(this.bottom, _rect.bottom) ); }, - + /** = Description * Creates and returns a new Rect that minimally but completely encloses the * area defined by this Rect and the specified Rect. * * = Parameters @@ -656,14 +667,14 @@ return new HRect( Math.min(this.left, _rect.left), Math.min(this.top, _rect.top), Math.max(this.right, _rect.right), Math.max(this.bottom, _rect.bottom) ); }, - + // HValue and HView support valueObj: null, - + /** = Description * Bind function * * = Parameters * +_view+:: view @@ -674,22 +685,22 @@ this.viewIds.push( _view.viewId ); } this._updateFlexibleDimensions(); return this; }, - + /** = Description * Release function **/ release: function(_view){ var _viewIdx = this.viewIds.indexOf(_view.viewId); if(~_viewIdx){ this.viewIds.splice( _viewIdx, 1 ); } return this; }, - + /** = Description * Sets valueObj for this component given as parameter. * * = Parameters * +_valueObj+:: valueObj to use @@ -697,11 +708,11 @@ **/ setValueObj: function(_valueObj){ this.valueObj = _valueObj; return this; }, - + /** = Description * setValue function * * = Parameters * +_value+:: value @@ -722,7 +733,7 @@ }, toString: function(){ return ('[object Rect left='+this.left+' top='+this.top+' width='+this.width+' height='+this.height+' right='+this.right+' bottom='+this.bottom+']'); } - + });