Пример #1
0
 /// <summary>
 /// Redraws the overlay<br/>
 /// We need to know the stage bounds because we want to inteligently place the label (not to be clipped)
 /// </summary>
 /// <param name="bounds"></param>
 /// <param name="stageBounds"></param>
 /// <param name="text"></param>
 public void Redraw(Rectangle bounds, Rectangle stageBounds, string text)
 {
     //Debug.Log("Setting overlay to: " + bounds + "; stageBounds: " + stageBounds);
     _overlayBounds = bounds;
     _stageBounds = stageBounds;
     Text = text;
     InvalidateSize();
     InvalidateDisplayList();
 }
Пример #2
0
        public DragProxyTween(object target, Rectangle oldBounds, Rectangle newBounds)
        {
            Target = target;
            OldBounds = oldBounds;
            NewBounds = newBounds;

            //Duration = DefaultDuration;
            //Easer = DefaultEaser;

            Add(Tween.New().SetOptions(
                new TweenOption(TweenOptionType.Property, "X"),
                new TweenOption(TweenOptionType.Duration, DefaultDuration),
                new TweenOption(TweenOptionType.Easer, DefaultEaser),
                new TweenOption(TweenOptionType.StartValue, OldBounds.X),
                new TweenOption(TweenOptionType.EndValue, NewBounds.X)
            ));

            Add(Tween.New().SetOptions(
                new TweenOption(TweenOptionType.Property, "Y"),
                new TweenOption(TweenOptionType.Duration, DefaultDuration),
                new TweenOption(TweenOptionType.Easer, DefaultEaser),
                new TweenOption(TweenOptionType.StartValue, OldBounds.Y),
                new TweenOption(TweenOptionType.EndValue, NewBounds.Y)
            ));

            Add(Tween.New().SetOptions(
                new TweenOption(TweenOptionType.Property, "Width"),
                new TweenOption(TweenOptionType.Duration, DefaultDuration),
                new TweenOption(TweenOptionType.Easer, DefaultEaser),
                new TweenOption(TweenOptionType.StartValue, OldBounds.Width),
                new TweenOption(TweenOptionType.EndValue, NewBounds.Width)
                //new TweenOption(TweenOptionType.Proxy, new SetActualWidthProxy(Target))
            ));

            Add(Tween.New().SetOptions(
                new TweenOption(TweenOptionType.Property, "Height"),
                new TweenOption(TweenOptionType.Duration, DefaultDuration),
                new TweenOption(TweenOptionType.Easer, DefaultEaser),
                new TweenOption(TweenOptionType.StartValue, OldBounds.Height),
                new TweenOption(TweenOptionType.EndValue, NewBounds.Height)
                //new TweenOption(TweenOptionType.Proxy, new SetActualHeightProxy(Target))
            ));
            
            /*Property = "Bounds";
            //Interpolator = new RectangleInterpolator();
            Duration = DefaultDuration;
            Easer = DefaultEaser;
            StartValueReader = new PropertyReader("Bounds");*/
        }
Пример #3
0
        // ReSharper restore UnassignedField.Global
#endif

        public static Rectangle CalculateBounds(float parentWidth, float parentHeight, float? left, float? right, float? top, float? bottom, float? width, float? height)
        {
#if DEBUG
            if (DebugMode)
                Debug.Log(
                string.Format("CalculateBounds parentWidth: {0}; parentHeight: {1}; left: {2}; right: {3}; top: {4}; bottom: {5}; width: {6}; height: {7};",
                parentWidth, parentHeight, left, right, top, bottom, width, height));
#endif      

            float x = left ?? 0;
            float y = top ?? 0;
            float w;
            float h;

            /*Debug.Log("parentWidth: " + parentWidth);
            Debug.Log("left: " + left);
            Debug.Log("right: " + right);*/

            if (null != width) // explicit width defined
                w = (int)width;
            else
            {
                w = parentWidth;
                if (null != left)
                    w -= (float) left;
                if (null != right)
                    w -= (float) right;

                w = Math.Max(0, w);
            }

            if (null != height) // explicit width defined
                h = (int)height;
            else
            {
                h = parentHeight;
                if (null != top)
                    h -= (float)top;
                if (null != bottom)
                    h -= (float)bottom;

                h = Math.Max(0, h);
            }

            Rectangle b = new Rectangle(x, y, w, h);
            //Debug.Log(b);

            return b;
        }
Пример #4
0
        public ScaleBoundsTween(object target, Rectangle oldBounds, Rectangle newBounds)
        {
            Target = target;
            OldBounds = oldBounds;
            NewBounds = newBounds;

            //Duration = DefaultDuration;
            //Easer = DefaultEaser;

            Add(Tween.New().SetOptions(
                new TweenOption(TweenOptionType.Property, "X"),
                new TweenOption(TweenOptionType.Duration, DefaultDuration),
                new TweenOption(TweenOptionType.Easer, DefaultEaser),
                new TweenOption(TweenOptionType.StartValue, OldBounds.X),
                new TweenOption(TweenOptionType.EndValue, NewBounds.X)
            ));

            Add(Tween.New().SetOptions(
                new TweenOption(TweenOptionType.Property, "Y"),
                new TweenOption(TweenOptionType.Duration, DefaultDuration),
                new TweenOption(TweenOptionType.Easer, DefaultEaser),
                new TweenOption(TweenOptionType.StartValue, OldBounds.Y),
                new TweenOption(TweenOptionType.EndValue, NewBounds.Y)
            ));

            Add(Tween.New().SetOptions(
                new TweenOption(TweenOptionType.Property, "Width"),
                new TweenOption(TweenOptionType.Duration, DefaultDuration),
                new TweenOption(TweenOptionType.Easer, DefaultEaser),
                new TweenOption(TweenOptionType.StartValue, OldBounds.Width),
                new TweenOption(TweenOptionType.EndValue, NewBounds.Width)/*,
                new TweenOption(TweenOptionType.Proxy, new SetActualWidthProxy(target))*/
            ));

            Add(Tween.New().SetOptions(
                new TweenOption(TweenOptionType.Property, "Height"),
                new TweenOption(TweenOptionType.Duration, DefaultDuration),
                new TweenOption(TweenOptionType.Easer, DefaultEaser),
                new TweenOption(TweenOptionType.StartValue, OldBounds.Height),
                new TweenOption(TweenOptionType.EndValue, NewBounds.Height)/*,
                new TweenOption(TweenOptionType.Proxy, new SetActualHeightProxy(target))*/
            ));
        }
Пример #5
0
        //private readonly Rectangle _retVal = new Rectangle();

        public object Interpolate(float fraction, object startValue, object endValue)
        {
            _startValue = (Rectangle)startValue;
            _endValue = (Rectangle)endValue;

            // NOTE: Beware!
            // You cannot use _retVal with reference types!
            // That is because the first time the _retVal is being returned from this interpolator, it Bounds of the target object start referencing it
            // The next moment, we are changing values here (on the same object), and when "appliing" the new values to the object, 
            // Equals returns true because those values are already there (it's the same Rectangle), so nothing happens

            //_retVal.X = _startValue.X + (_endValue.X - _startValue.X) * fraction;
            //_retVal.Y = _startValue.Y + (_endValue.Y - _startValue.Y) * fraction;
            //_retVal.Width = _startValue.Width + (_endValue.Width - _startValue.Width) * fraction;
            //_retVal.Height = _startValue.Height + (_endValue.Height - _startValue.Height) * fraction;
            //return _retVal;

            return new Rectangle(_startValue.X + (_endValue.X - _startValue.X) * fraction, _startValue.Y + (_endValue.Y - _startValue.Y) * fraction, _startValue.Width + (_endValue.Width - _startValue.Width) * fraction, _startValue.Height + (_endValue.Height - _startValue.Height) * fraction);
        }
        protected override void ValidateChild(DisplayObject child)
        {
            _childBounds = child.Transform.Bounds;

            _isClippingGroup = null != _group && _group.ClipAndEnableScrolling;

            _childRenderingPosition = _isClippingGroup ?
                                    child.Transform.Position : // parent is clipping. Origin is the distance from (0, 0) of the parent
                                    _imc.Transform.RenderingPosition.Add(child.Transform.Position); // add to rendering position

            _childGlobalPosition = _imc.Transform.GlobalPosition.Add(child.Transform.Position);

            _childRenderingRect = new Rect(_childRenderingPosition.X, _childRenderingPosition.Y, _childBounds.Width, _childBounds.Height);
            _childLocalRenderingRect = new Rect(0, 0, _childBounds.Width, _childBounds.Height);

            child.Transform.Apply(_childRenderingPosition, _childGlobalPosition, _childRenderingRect, _childLocalRenderingRect);

            child.Transform.ValidateChildren(); // RECURSION! (skin etc.)
        }
Пример #7
0
 /// <summary>
 /// Gets align bounds
 /// </summary>
 /// <param name="childrenBounds"></param>
 /// <param name="containerBounds"></param>
 /// <returns></returns>
 public static Rectangle GetAlignBounds(Rectangle childrenBounds, Rectangle containerBounds)
 {
     float width = Math.Max(childrenBounds.Width, containerBounds.Width);
     float height = Math.Max(childrenBounds.Height, containerBounds.Height);
     return new Rectangle(0, 0, width, height);
 }
Пример #8
0
 /// <summary>
 /// Centers the inner rectangle inside the given outer rectangle
 /// </summary>
 /// <param name="outer">Outer rectangle</param>
 /// <param name="inner">Inner rectangle</param>
 /// <returns>Centered rectangle</returns>
 public static Rectangle CenterRectangle(Rectangle outer, Rectangle inner)
 {
     return new Rectangle((outer.Width - inner.Width) / 2, (outer.Height - inner.Height) / 2, inner.Width, inner.Height);
 }
Пример #9
0
        /// <summary>
        /// Render slot
        /// </summary>
        /// <param name="parameters"></param>
        public void RenderSlot(params object[] parameters)
        {
            // Checking if the current component moved and/or resized
            // NOTE: Using brute force checking here (instead of listening to move and resize events)
            // because the component may choose not to dispatch any events
            // However - no harm done - the DesignerOverlay should be off in the production
            if (null == _stage)
                return;

            if (null != _hoveredComponent && !_previousHoveredBounds.Equals(_hoveredComponent.Transform.GlobalBounds) && IsInspectable(_hoveredComponent))
            {
                _stage.Hover(_hoveredComponent);
                _previousHoveredBounds = _hoveredComponent.Transform.GlobalBounds;
            }

            if (null != _selectedComponent && !_previousSelectedBounds.Equals(_selectedComponent.Transform.GlobalBounds) && IsInspectable(_selectedComponent))
            {
                _stage.Select(_selectedComponent);
                _previousSelectedBounds = _selectedComponent.Transform.GlobalBounds;
            }
        }
Пример #10
0
 public static Rectangle CenterRect(Rectangle inner, Rectangle outer)
 {
     //Debug.Log("inner: " + inner + "; outer: " + outer);
     return new Rectangle((outer.Width - inner.Width) / 2, (outer.Height - inner.Height) / 2, inner.Width, inner.Height);
 }
Пример #11
0
 /**
  *  
  */
 override internal Rectangle GetElementBoundsRightOfScrollRect(Rectangle scrollRect)
 {
     var bounds = new Rectangle();
     // Find the column that spans or is to the right of the scrollRect right edge.
     int column = (int) Math.Floor((double) ((scrollRect.Right + 1 + _horizontalGap) / (_columnWidth + _horizontalGap)));
     bounds.Left = LeftEdge(column);
     bounds.Right = RightEdge(column);
     return bounds;
 }
Пример #12
0
 /// <summary>
 /// Returns true if two rectangles intersect
 /// </summary>
 /// <param name="rectangle"></param>
 /// <returns></returns>
 public bool Intersects(Rectangle rectangle)
 {
     // reverse logic - early exit
     return !(Left > rectangle.Right ||
        Right < rectangle.Left ||
        Top > rectangle.Bottom ||
        Bottom < rectangle.Top);
 }
Пример #13
0
 /// <summary>
 /// Checks if a given rectangle is placed inside this rectangle
 /// </summary>
 /// <param name="rectangle"></param>
 /// <returns></returns>
 public bool Contains(Rectangle rectangle)
 {
     return (rectangle.Left >= Left &&
        rectangle.Right <= Right &&
        rectangle.Top >= Top &&
        rectangle.Bottom <= Bottom);
 }
Пример #14
0
        /// <summary>
        /// We should listen the mouse move events over the component
        /// If mouse moved over the event, we should check border and draw overlay
        /// </summary>
        /// <param name="e"></param>
        private void ComponentMouseMoveHandler(Event e)
        {
            if (!Enabled)
                return;

            Debug.Log(string.Format("ComponentMouseMoveHandler [{0}, {1}]", e.Phase, e.CurrentTarget));

            if (!(e.Target is DisplayListMember))
                return;

            DisplayListMember dlm = (DisplayListMember)e.Target;

            MouseEvent me = (MouseEvent)e;

            //Container container = _component as Container;

            //Point coordsInComponentSpace = null != container ? 
            //      container.GlobalToContent(dlm.LocalToGlobal(me.LocalPosition)) : 
            //      _component.GlobalToLocal(dlm.LocalToGlobal(me.LocalPosition));

            Point coordsInComponentSpace = _component.GlobalToLocal(dlm.LocalToGlobal(me.LocalPosition));

            // if some component is already being dragged/resized, do not draw borders on hover
            if (DragManager.IsDragging)
                return;

            if (_constraintMode)
            {
                _constrainedRect = _constraintMetrics.GetConstrainedRectangle(_component.Transform.LocalBounds);
                DoRenderOverlay = _constrainedRect.Contains(coordsInComponentSpace);
            }
            else
            {
                DoRenderOverlay = true;
            }

            if (DoRenderOverlay)
            {
                e.Cancel();
            }
        }
Пример #15
0
 public virtual Rectangle GlobalToLocal(Rectangle r)
 {
     Rectangle r2 = (Rectangle)r.Clone();
     r2.Position = GlobalToLocal(r2.Position);
     return r2;
 }
Пример #16
0
        /// <summary>
        /// Constrains this rectangle with the outer one
        /// </summary>
        /// <param name="outer"></param>
        /// <returns></returns>
        public Rectangle GetConstrainedRectangle(Rectangle outer)
        {
            Rectangle rect = new Rectangle();

            if (null != Left)
                rect.X = outer.X + (float) Left;

            if (null != Width)
                rect.Width = (float)Width;
            else if (null != Right)
                rect.Width = outer.Width - rect.X - (float)Right;

            if (null != Top)
                rect.Y = outer.Y + (float)Top;

            if (null != Height)
                rect.Height = (float)Height;
            else if (null != Bottom)
                rect.Height = outer.Height - rect.Y - (float)Bottom;

            //Debug.Log(("   -> result: " + rect));

            return rect;
        }
Пример #17
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected Point CalculatePopUpPosition()
        {
            Point regPoint = new Point();
        
            /*if (!matrix)
                return regPoint;*/
        
            var popUpBounds = new Rectangle(); 
            var popUpAsDisplayObject = _popup as DisplayObject;
        
            DeterminePosition(_popupPosition, popUpAsDisplayObject.Width, popUpAsDisplayObject.Height,
                              /*matrix, */regPoint, popUpBounds);

            PopupPosition adjustedPosition = PopupPosition.Above;
            bool isAdjusted = false;

            var screenSize = SystemManager.Instance.ScreenSize;

            // Position the popUp in the opposite direction if it 
            // does not fit on the screen. 
            switch(_popupPosition)
            {
                case PopupPosition.Below :
                    if (popUpBounds.Bottom > screenSize.Y) { 
                        adjustedPosition = PopupPosition.Above;
                        isAdjusted = true;
                    }
                    break;
                case PopupPosition.Above :
                    if (popUpBounds.Top < 0)
                    {
                        adjustedPosition = PopupPosition.Below;
                        isAdjusted = true;
                    }
                    break;
                case PopupPosition.Left :
                    if (popUpBounds.Left < 0)
                    {
                        adjustedPosition = PopupPosition.Right;
                        isAdjusted = true;
                    }
                    break;
                case PopupPosition.Right :
                    if (popUpBounds.Right > screenSize.X)
                    {
                        adjustedPosition = PopupPosition.Left; 
                        isAdjusted = true;
                    }
                    break;
            }
        
            // Get the new registration point based on the adjusted position
            if (isAdjusted)
            {
                var adjustedRegPoint = new Point();
                var adjustedBounds = new Rectangle(); 
                DeterminePosition((PopupPosition) adjustedPosition, popUpAsDisplayObject.Width, 
                                  popUpAsDisplayObject.Height,
                                  /*matrix, */adjustedRegPoint, adjustedBounds);
         
                // If we adjusted the position but the popUp still doesn't fit, 
                // then revert to the original position. 
                switch(adjustedPosition)
                {
                    case PopupPosition.Below :
                        if (adjustedBounds.Bottom > screenSize.Y)
                            isAdjusted = false; 
                        break;
                    case PopupPosition.Above :
                        if (adjustedBounds.Top < 0)
                            isAdjusted = false; 
                        break;
                    case PopupPosition.Left :
                        if (adjustedBounds.Left < 0)
                            isAdjusted = false; 
                        break;
                    case PopupPosition.Right :
                        if (adjustedBounds.Right > screenSize.X)
                            isAdjusted = false;  
                        break;
                }

                if (isAdjusted)
                {
                    regPoint = adjustedRegPoint;
                    popUpBounds = adjustedBounds;
                }
            }
        
            /*MatrixUtil.decomposeMatrix(decomposition, matrix, 0, 0);
            var concatScaleX:Number = decomposition[3];
            var concatScaleY:Number = decomposition[4]; */
        
            // If the popUp still doesn't fit, then nudge it
            // so it is completely on the screen. Make sure to include scale.

            if (popUpBounds.Top < 0)
                regPoint.Y += (0 - popUpBounds.Top); // / concatScaleY;
            else if (popUpBounds.Bottom > screenSize.Y)
                regPoint.Y -= (popUpBounds.Bottom - screenSize.Y); // / concatScaleY;

            if (popUpBounds.Left < 0)
                regPoint.X += (0 - popUpBounds.Left); // / concatScaleX;    
            else if (popUpBounds.Right > screenSize.X)
                regPoint.X -= (popUpBounds.Right - screenSize.X);// / concatScaleX;

            return LocalToGlobal(regPoint);
            //return matrix.transformPoint(regPoint);
        }
Пример #18
0
        internal void RenderHandler(object parameter)
        {
            if (null == _stage) // could be null on application recompile
                return;

            if (_sticky != Sticky)
            {
#if DEBUG
                if (DebugMode)
                    Debug.Log("Sticky changed");
#endif
                _sticky = Sticky;
                if (!_sticky)
                    HideOverlay();
            }

            // Checking if the current component moved and/or resized
            // NOTE: Using brute force checking here (instead of listening to move and resize events)
            // because the component may choose not to dispatch any events
            // However - no harm done - the GuiInspector should be off in the production
            if (null != _currentComponent) // && null != _stage)
            {
                if (!_previousBounds.Equals(_currentComponent.Transform.GlobalBounds) && IsInspectable(_currentComponent))
                {
                    _stage.DoShowOverlay(_currentComponent);
                    _previousBounds = _currentComponent.Transform.GlobalBounds;
                }
            }
        }
Пример #19
0
 /// <summary>
 /// Centers THIS rectangle inside the given outer rectangle
 /// </summary>
 /// <param name="outerRectangle"></param>
 /// <returns>Centered (THIS) rectangle</returns>
 public Rectangle CenterInside(Rectangle outerRectangle)
 {
     //Debug.Log("outerRectangle: " + outerRectangle);
     return CenterRectangle(outerRectangle, this);
 }
Пример #20
0
        private void ComponentMouseDownHandler(Event e)
        {
            Debug.Log(string.Format("ComponentMouseDownHandler [{0}, {1}]", e.Phase, e.CurrentTarget));

            if (!Enabled)
                return;

            if (AutoBringToFront)
                _component.BringToFront();

            MouseEvent me = (MouseEvent) e;

            //var container = _component.Parent as Container; // 20121125 (because dragging didn't work well when parent scrolled)
            //_startCoordinates = null != container ?
            //    container.GlobalToContent(_component.Transform.GlobalPosition) : // GlobalToContent no more - TODO
            //    _component.Parent.GlobalToLocal(_component.Transform.GlobalPosition);

            _clickCoordinates = me.GlobalPosition;

            if (_constraintMode)
            {
                _constrainedRect = _constraintMetrics.GetConstrainedRectangle(_component.Transform.LocalBounds);

                if (!_constrainedRect.Contains(me.LocalPosition))
                    return;
            }

            e.CancelAndStopPropagation();

            DragManager.IsDragging = true;

            SystemEventDispatcher.Instance.AddEventListener(MouseEvent.MOUSE_MOVE, MouseMoveHandler);
            SystemEventDispatcher.Instance.AddEventListener(MouseEvent.MOUSE_UP, MouseUpHandler);

            if (-1 == _cursorId)
            {
                _cursorId = CursorManager.Instance.SetCursor(CursorType.Move, CursorPriority.High);
            }
        }
Пример #21
0
 /// <summary>
 /// Constrains this rectangle inside another rectangle's bounds
 /// </summary>
 /// <param name="rectangle"></param>
 public void ConstrainWithin(Rectangle rectangle)
 {
     X = Math.Max(X, rectangle.X);
     Y = Math.Max(Y, rectangle.Y);
     Right = Math.Min(Right, rectangle.Right);
     Bottom = Math.Min(Bottom, rectangle.Bottom);
 }
Пример #22
0
        private static Color _transparent = new Color(1, 1, 1, 0); // transparent

        private void DrawPixels(Rectangle fillRect, int yMax, int yMin, int xMin, int xMax, bool hasStroke, Color[] pixels, int count)
        {
            //if (null == Fill)
            //    Fill = new Fill(new Color(1, 1, 1, 0)); // transparent

            for (int y = yMax; y > yMin; y--)
            {
                for (int x = xMin; x < xMax; x++)
                {
                    _isFill = false;
                    _isStroke = false;

                    _point.X = x; 
                    _point.Y = y;

                    _isFill = fillRect.Contains(_point);

                    if (hasStroke && !_isFill)
                        _isStroke = Bounds.Contains(_point);

                    _color = _transparent; // new Color(1, 1, 1, 0); // transparent

                    if (_isFill && null != Fill) {
                        _color = CalculatePixelColor(Fill, y, x);
                    }
                    else if (_isStroke && null != Stroke) {
                        _color = CalculatePixelColor(Stroke, x, y);
                    }

                    pixels[count] = _color;

                    count++;
                }
            }
        }
Пример #23
0
 /// <summary>
 /// Equality
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool Equals(Rectangle other)
 {
     if (ReferenceEquals(null, other)) return false;
     //if (ReferenceEquals(this, other)) return true; // commented 20120625
     return other._x == _x && other._y == _y && other._width == _width && other._height == _height;
 }
Пример #24
0
 internal virtual Rectangle GetElementBoundsAboveScrollRect(Rectangle scrollRect) // TEMP internal (protected)
 {
     return new Rectangle { Top = scrollRect.Top - 1, Bottom = scrollRect.Top };
 }
Пример #25
0
        /**
         *   
         */  
        override internal int GetNavigationDestinationIndex(int currentIndex, NavigationUnit navigationUnit, bool arrowKeysWrapFocus)
        {
            if (null == Target || Target.NumberOfContentChildren < 1)
                return -1;

            int maxIndex = Target.NumberOfContentChildren - 1;

            // Special case when nothing was previously selected
            if (currentIndex == -1)
            {
                if (navigationUnit == NavigationUnit.Up || navigationUnit == NavigationUnit.Left)
                    return arrowKeysWrapFocus ? maxIndex : -1;

                if (navigationUnit == NavigationUnit.Down || navigationUnit == NavigationUnit.Right)
                    return 0;    
            }    
                
            // Make sure currentIndex is within range
            bool inRows = _orientation == TileOrientation.Rows;
            currentIndex = Math.Max(0, Math.Min(maxIndex, currentIndex));

            // Find the current column and row
            int currentRow;
            int currentColumn;
            if (inRows)
            {
                // Is the TileLayout initialized with valid values?
                if (_columnCount == 0 || _rowHeight + _verticalGap == 0)
                    return currentIndex;
                        
                currentRow = currentIndex / _columnCount;
                currentColumn = currentIndex - currentRow * _columnCount;
            }
            else
            {
                // Is the TileLayout initialized with valid values?
                if (_rowCount == 0 || _columnWidth + _horizontalGap == 0)
                    return currentIndex;
        
                currentColumn = currentIndex / _rowCount;
                currentRow = currentIndex - currentColumn * _rowCount;
            }
            
            int newRow = currentRow;
            int newColumn = currentColumn;

            // Handle user input, almost all range checks are
            // performed after the calculations, at the end of the method.
            switch (navigationUnit)
            {
                case NavigationUnit.Left: 
                {
                    // If we are at the first column, can
                    // we go to the previous element (last column, previous row)?
                    if (newColumn == 0 && inRows && newRow > 0)
                    {
                        newRow--;
                        newColumn = _columnCount - 1;
                    }
                    else if (arrowKeysWrapFocus && newColumn == 0 && inRows && newRow == 0)
                    {
                        newRow = _rowCount - 1;
                        newColumn = _columnCount - 1;
                    }
                    else
                        newColumn--;
                    break;
                }

                case NavigationUnit.Right:
                {
                    // If we are at the last column, can
                    // we go to the next element (first column, next row)?
                    if (newColumn == _columnCount - 1 && inRows && newRow < _rowCount - 1)
                    {
                        newColumn = 0;
                        newRow++;
                    }
                    else if (arrowKeysWrapFocus && newColumn == _columnCount - 1 && inRows && newRow == _rowCount - 1)
                    {
                        newColumn = 0;
                        newRow = 0;
                    }
                    else
                        newColumn++;
                    break;
                } 

                case NavigationUnit.Up:
                {
                    // If we are at the first row, can we
                    // go to the previous element (previous column, last row)?
                    if (newRow == 0 && !inRows && newColumn > 0)
                    {
                        newColumn--;
                        newRow = _rowCount - 1;
                    }
                    else if (arrowKeysWrapFocus && newRow == 0 && !inRows && newColumn == 0)
                    {
                        newColumn = _columnCount - 1;
                        newRow = _rowCount - 1;
                    }
                    else
                        newRow--;
                    break; 
                }

                case NavigationUnit.Down:
                {
                    // If we are at the last row, can we
                    // go to the next element (next column, first row)?
                    if (newRow == _rowCount - 1 && !inRows && newColumn < _columnCount - 1)
                    {
                        newColumn++;
                        newRow = 0;
                    }
                    else if (arrowKeysWrapFocus && newRow == _rowCount - 1 && !inRows && newColumn == _columnCount - 1)
                    {
                        newColumn = 0;
                        newRow = 0;
                    }
                    else
                        newRow++;
                    break; 
                }

                case NavigationUnit.PageUp:
                case NavigationUnit.PageDown:
                {
                    // Ensure we have a valid scrollRect as we use it for calculations below
                    Rectangle scrollRect = GetScrollRect();
                    if (null == scrollRect)
                        scrollRect = new Rectangle(0, 0, Target.ContentWidth, Target.ContentHeight);
                     
                    if (inRows)
                    {
                        int firstVisibleRow = (int) Mathf.Ceil(scrollRect.Top / ((float)_rowHeight + _verticalGap));
                        int lastVisibleRow = (int) Mathf.Floor(scrollRect.Bottom / ((float)_rowHeight + _verticalGap));
                         
                        if (navigationUnit == NavigationUnit.PageUp)
                        {
                            // Is the current row visible, somewhere in the middle of the scrollRect?
                            if (firstVisibleRow < currentRow && currentRow <= lastVisibleRow)
                                newRow = firstVisibleRow;
                            else                             
                                newRow = 2 * firstVisibleRow - lastVisibleRow;
                        } 
                        else
                        {
                            // Is the current row visible, somewhere in the middle of the scrollRect?
                            if (firstVisibleRow <= currentRow && currentRow < lastVisibleRow)
                                newRow = lastVisibleRow;
                            else                             
                                newRow = 2 * lastVisibleRow - firstVisibleRow;
                        }
                    }
                    else
                    {
                        int firstVisibleColumn = (int) Mathf.Ceil(scrollRect.Left / ((float)_columnWidth + _horizontalGap));
                        int lastVisibleColumn = (int) Mathf.Floor(scrollRect.Right / ((float)_columnWidth + _horizontalGap));
                        
                        if (navigationUnit == NavigationUnit.PageUp)
                        {
                            // Is the current column visible, somewhere in the middle of the scrollRect?
                            if (firstVisibleColumn < currentColumn && currentColumn <= lastVisibleColumn)
                                newColumn = firstVisibleColumn;
                            else    
                                newColumn = 2 * firstVisibleColumn - lastVisibleColumn; 
                        }
                        else
                        {
                            // Is the current column visible, somewhere in the middle of the scrollRect?
                            if (firstVisibleColumn <= currentColumn && currentColumn < lastVisibleColumn)
                                newColumn = lastVisibleColumn;
                            else    
                                newColumn = 2 * lastVisibleColumn - firstVisibleColumn;
                        }
                    }
                    break; 
                }
                default: 
                    return base.GetNavigationDestinationIndex(currentIndex, navigationUnit, arrowKeysWrapFocus);
            }

            // Make sure rows and columns are within range
            newRow = Math.Max(0, Math.Min(_rowCount - 1, newRow));
            newColumn = Math.Max(0, Math.Min(_columnCount - 1, newColumn));

            // Calculate the new index based on orientation        
            if (inRows)  
            {
                // Make sure we don't return an index for an empty space in the last row.
                // newRow is guaranteed to be greater than zero:
                
                // Step 1: We can end up at the empty space in the last row if we moved right from
                // the last item.
                if (currentIndex == maxIndex && newColumn > currentColumn)
                    newColumn = currentColumn;
                    
                // Step 2: We can end up at the empty space in the last row if we moved down from
                // the previous row.    
                if (newRow == _rowCount - 1 && newColumn > maxIndex - _columnCount * (_rowCount - 1))
                    newRow--;

                return newRow * _columnCount + newColumn;
            }
            else
            {
                // Make sure we don't return an index for an empty space in the last column.
                // newColumn is guaranteed to be greater than zero:

                // Step 1: We can end up at the empty space in the last column if we moved down from
                // the last item.
                if (currentIndex == maxIndex && newRow > currentRow)
                    newRow = currentRow;

                // Step 2: We can end up at the empty space in the last column if we moved right from
                // the previous column.    
                if (newColumn == _columnCount - 1 && newRow > maxIndex - _rowCount * (_columnCount - 1))
                    newColumn--;

                return newColumn * _rowCount + newRow;
            }
        }
Пример #26
0
        /// <summary>
        /// Mouse move handler
        /// Fires when in processing mode (resizing)
        /// </summary>
        /// <param name="e"></param>
        private void MouseMoveHandler(Event e)
        {
            if (!IsResizing)
                return;

            e.CancelAndStopPropagation();

            MouseEvent me = (MouseEvent)e;

            Point position;

            position = me.GlobalPosition;

            var delta = position.Subtract(_clickCoords);

            switch (_resizeMode)
            {
                case ResizeMode.Right:
                    _newBounds = _origBounds.Expand(0, delta.X, 0, 0);
                    break;
                case ResizeMode.Left:
                    _newBounds = _origBounds.Expand(-delta.X, 0, 0, 0);
                    break;
                case ResizeMode.Top:
                    _newBounds = _origBounds.Expand(0, 0, -delta.Y, 0);
                    break;
                case ResizeMode.Bottom:
                    _newBounds = _origBounds.Expand(0, 0, 0, delta.Y);
                    break;
                case ResizeMode.TopLeft:
                    _newBounds = _origBounds.Expand(-delta.X, 0, -delta.Y, 0);
                    break;
                case ResizeMode.TopRight:
                    _newBounds = _origBounds.Expand(0, delta.X, -delta.Y, 0);
                    break;
                case ResizeMode.BottomLeft:
                    _newBounds = _origBounds.Expand(-delta.X, 0, 0, delta.Y);
                    break;
                case ResizeMode.BottomRight:
                    _newBounds = _origBounds.Expand(0, delta.X, 0, delta.Y);
                    break;
            }

            // gracefully handle the minimum sizes set by the user
            _newBounds.X = Mathf.Min(_newBounds.X, _origBounds.Right - _component.MinWidth);
            _newBounds.Y = Mathf.Min(_newBounds.Y, _origBounds.Bottom - _component.MinHeight);
            _newBounds.Width = Mathf.Min(Mathf.Max(_newBounds.Width, _component.MinWidth), _component.MaxWidth); // MeasuredMinWidth
            _newBounds.Height = Mathf.Min(Mathf.Max(_newBounds.Height, _component.MinHeight), _component.MaxHeight);

            // apply
            if (ChangeExplicitSize)
            {
                _component.Width = _newBounds.Width;
                _component.Height = _newBounds.Height;
            }
            else
            {
                _component.SetActualSize(_newBounds.Width, _newBounds.Height);
            }
            
            _component.Move(_newBounds.X, _newBounds.Y);

            /**
             * When resizing by the top/left edge, the visual jitter can be observed in component's right-aligned children
             * so to avoid this jitter, we should validate now
             * */
            if (_resizeMode == ResizeMode.Left || 
                _resizeMode == ResizeMode.Top || 
                _resizeMode == ResizeMode.TopLeft)
            {
                //_component.ValidateNow();    
            }
        }
Пример #27
0
 /**
  *  
  */
 override internal Rectangle GetElementBoundsBelowScrollRect(Rectangle scrollRect)
 {
     var bounds = new Rectangle();
     // Find the row that spans or is below the scrollRect bottom edge
     int row = (int) Math.Floor((double) ((scrollRect.Bottom + 1 + _verticalGap) / (_rowHeight + _verticalGap)));
     bounds.Top = TopEdge(row);
     bounds.Bottom = BottomEdge(row);
     return bounds;
 }
Пример #28
0
 internal virtual Rectangle GetElementBoundsBelowScrollRect(Rectangle scrollRect) // TEMP internal (protected)
 {
     return new Rectangle { Top = scrollRect.Bottom, Bottom = scrollRect.Bottom + 1 };
 }
Пример #29
0
 internal virtual Rectangle GetElementBoundsRightOfScrollRect(Rectangle scrollRect) // TEMP internal (protected)
 {
     return new Rectangle {Left = scrollRect.Right , Right = scrollRect.Right + 1};
 }
Пример #30
0
        /**
         *   
         */
        internal void DeterminePosition(PopupPosition placement, float popUpWidth, float popUpHeight,
                                               /*matrix:Matrix, */Point registrationPoint, Rectangle bounds)
        {
            switch(placement)
            {
                case PopupPosition.Below:
                    registrationPoint.X = 0;
                    registrationPoint.Y = Height;
                    break;
                case PopupPosition.Above:
                    registrationPoint.X = 0;
                    registrationPoint.Y = -popUpHeight;
                    break;
                case PopupPosition.Left:
                    registrationPoint.X = -popUpWidth;
                    registrationPoint.Y = 0;
                    break;
                case PopupPosition.Right:
                    registrationPoint.X = Width;
                    registrationPoint.Y = 0;
                    break;            
                case PopupPosition.Center:
                    registrationPoint.X = (Width - popUpWidth) / 2;
                    registrationPoint.Y = (Height - popUpHeight) / 2;
                    break;            
                case PopupPosition.TopLeft:
                    // already 0,0
                    break;
            }
        
            //var popUpAsDisplayObject = _popup as DisplayObject;
                
            /*Point globalTl = (Point) registrationPoint.Clone(); //matrix.transformPoint(registrationPoint);
            registrationPoint.Y += popUpAsDisplayObject.Height;
            Point globalBl = (Point) registrationPoint.Clone(); //matrix.transformPoint(registrationPoint);
            registrationPoint.X += popUpAsDisplayObject.Width;
            Point globalBr = (Point) registrationPoint.Clone(); //matrix.transformPoint(registrationPoint);
            registrationPoint.Y -= popUpAsDisplayObject.Height;
            Point globalTr = (Point) registrationPoint.Clone(); //matrix.transformPoint(registrationPoint);
            registrationPoint.X -= popUpAsDisplayObject.Width;
        
            bounds.Left = Mathf.Min(globalTl.X, globalBl.X, globalBr.X, globalTr.X);
            bounds.Right = Mathf.Max(globalTl.X, globalBl.X, globalBr.X, globalTr.X);
            bounds.Top = Mathf.Min(globalTl.Y, globalBl.Y, globalBr.Y, globalTr.Y);
            bounds.Bottom = Mathf.Max(globalTl.Y, globalBl.Y, globalBr.Y, globalTr.Y);*/

            var globalRegPoint = Parent.LocalToGlobal(registrationPoint);
            bounds.X = globalRegPoint.X;
            bounds.Y = globalRegPoint.Y;
            bounds.Width = popUpWidth;
            bounds.Height = popUpHeight;
        }