Example #1
0
        protected override void LayoutItemWidgets()
        {
            // get render area
            var renderRect = GetItemRenderArea();

            // get starting position
            var x0 = CoordConverter.AlignToPixels(renderRect.d_min.X);
            var y0 = CoordConverter.AlignToPixels(renderRect.d_min.Y);


            var sz = new UVector2(UDim.Absolute(CoordConverter.AlignToPixels(renderRect.Width)), UDim.Absolute(0));   // set item width

            // iterate through all items attached to this window
            foreach (var item in ListItems)
            {
                // get the "optimal" height of the item and use that!
                sz.d_y.d_offset = CoordConverter.AlignToPixels(item.GetItemPixelSize().Height); // rounding errors ?

                // set destination rect
                var rect = new URect
                {
                    Position = new UVector2(UDim.Absolute(x0), UDim.Absolute(y0)),
                    Size     = new USize(sz.d_x, sz.d_y)
                };
                // todo: vector vs size
                item.SetArea(rect);

                // next position
                y0 += CoordConverter.AlignToPixels(sz.d_y.d_offset + ItemSpacing);
            }
        }
Example #2
0
 public override void DrawRect(URect rect, UColor color, bool fill)
 {
     if (fill)
     {
         g.FillRectangle(new SolidBrush(ParseColor(color)), rect.X, rect.Y, rect.Width, rect.Height);
     }
     else
     {
         g.DrawRectangle(new Pen(ParseColor(color)), rect.X, rect.Y, rect.Width, rect.Height);
     }
 }
Example #3
0
        /// <summary>
        /// move the window's bottom edge by 'delta'.
        /// The rest of the window does not move, thus this changes the size of the Window.
        /// </summary>
        /// <param name="delta">
        /// float value that specifies the amount to move the window edge, and in which direction.
        /// Positive values make window larger.
        /// </param>
        /// <param name="outArea"></param>
        /// <returns></returns>
        protected bool MoveBottomEdge(float delta, ref URect outArea)
        {
            // store this so we can work out how much size actually changed
            var orgHeight = d_pixelSize.Height;

            // ensure that we only size to the set constraints.
            //
            // NB: We are required to do this here due to our virtually unique sizing nature; the
            // normal system for limiting the window size is unable to supply the information we
            // require for updating our internal state used to manage the dragging, etc.
            var maxHeight = CoordConverter.AsAbsolute(d_maxSize.d_height, GetRootContainerSize().Height);
            var minHeight = CoordConverter.AsAbsolute(d_minSize.d_height, GetRootContainerSize().Height);
            var newHeight = orgHeight + delta;

            if (Math.Abs(maxHeight - 0.0f) > float.Epsilon && newHeight > maxHeight)
            {
                delta = maxHeight - orgHeight;
            }
            else if (newHeight < minHeight)
            {
                delta = minHeight - orgHeight;
            }

            // ensure adjustment will be whole pixel
            var adjustment = /*PixelAligned(*/ delta /*)*/;

            outArea.d_max.d_y.d_offset += adjustment;

            if (d_verticalAlignment == VerticalAlignment.Bottom)
            {
                outArea.d_max.d_y.d_offset += adjustment;
                outArea.d_min.d_y.d_offset += adjustment;
            }
            else if (d_verticalAlignment == VerticalAlignment.Centre)
            {
                outArea.d_max.d_y.d_offset += adjustment * 0.5f;
                outArea.d_min.d_y.d_offset += adjustment * 0.5f;
            }

            // move the dragging point so mouse remains 'attached' to edge of window
            _dragPoint.Y += adjustment;

            return(d_verticalAlignment == VerticalAlignment.Bottom);
        }
Example #4
0
        /// <summary>
        /// move the window's top edge by 'delta'.
        /// The rest of the window does not move, thus this changes the size of the Window.
        /// </summary>
        /// <param name="delta">
        /// float value that specifies the amount to move the window edge, and in which direction.
        /// Positive values make window smaller.
        /// </param>
        /// <param name="outArea"></param>
        /// <returns></returns>
        protected bool MoveTopEdge(float delta, ref URect outArea)
        {
            var orgHeight = d_pixelSize.Height;

            // ensure that we only size to the set constraints.
            //
            // NB: We are required to do this here due to our virtually unique sizing nature; the
            // normal system for limiting the window size is unable to supply the information we
            // require for updating our internal state used to manage the dragging, etc.
            float maxHeight = CoordConverter.AsAbsolute(d_maxSize.d_height, GetRootContainerSize().Height);
            float minHeight = CoordConverter.AsAbsolute(d_minSize.d_height, GetRootContainerSize().Height);
            float newHeight = orgHeight - delta;

            if (Math.Abs(maxHeight - 0.0f) > float.Epsilon && newHeight > maxHeight)
            {
                delta = orgHeight - maxHeight;
            }
            else if (newHeight < minHeight)
            {
                delta = orgHeight - minHeight;
            }

            // ensure adjustment will be whole pixel
            float adjustment = /*PixelAligned(*/ delta /*)*/;

            if (d_verticalAlignment == VerticalAlignment.Bottom)
            {
                outArea.d_max.d_y.d_offset -= adjustment;
            }
            else if (d_verticalAlignment == VerticalAlignment.Centre)
            {
                outArea.d_max.d_y.d_offset -= adjustment * 0.5f;
                outArea.d_min.d_y.d_offset += adjustment * 0.5f;
            }
            else
            {
                outArea.d_min.d_y.d_offset += adjustment;
            }

            return(d_verticalAlignment == VerticalAlignment.Top);
        }
Example #5
0
        /// <summary>
        /// Setup size and position for the item widgets attached to this Menubar
        /// </summary>
        protected override void LayoutItemWidgets()
        {
            var renderRect = GetItemRenderArea();
            var x0         = CoordConverter.AlignToPixels(renderRect.Left);

            foreach (var item in ListItems)
            {
                var optimal = item.GetItemPixelSize();

                item.SetVerticalAlignment(VerticalAlignment.Centre);
                var rect = new URect
                {
                    Position = new UVector2(UDim.Absolute(x0), UDim.Absolute(0)),
                    Size     = new USize(UDim.Absolute(CoordConverter.AlignToPixels(optimal.Width)),
                                         UDim.Absolute(CoordConverter.AlignToPixels(optimal.Height)))
                };

                item.SetArea(rect);

                x0 += optimal.Width + ItemSpacing;
            }
        }
        /// <summary>
        /// Update state for drag sizing.
        /// </summary>
        /// <param name="localMouse">
        /// Mouse position as a pixel offset from the top-left corner of this window.
        /// </param>
        protected void DoDragSizing(Lunatics.Mathematics.Vector2 localMouse)
        {
            var delta = localMouse.X - _dragPoint.X;
            // store this so we can work out how much size actually changed
            var orgWidth = d_pixelSize.Width;

            // ensure that we only size to the set constraints.
            //
            // NB: We are required to do this here due to our virtually unique sizing nature; the
            // normal system for limiting the window size is unable to supply the information we
            // require for updating our internal state used to manage the dragging, etc.
            var maxWidth = CoordConverter.AsAbsolute(d_maxSize.d_width, GetRootContainerSize().Width);
            var minWidth = CoordConverter.AsAbsolute(d_minSize.d_width, GetRootContainerSize().Width);
            var newWidth = orgWidth + delta;

            if (maxWidth != 0.0f && newWidth > maxWidth)
            {
                delta = maxWidth - orgWidth;
            }
            else if (newWidth < minWidth)
            {
                delta = minWidth - orgWidth;
            }

            // update segment area rect
            // URGENT FIXME: The pixel alignment will be done automatically again, right? Why is it done here? setArea_impl will do it!
            var area = new URect(d_area.d_min.d_x, d_area.d_min.d_y,
                                 d_area.d_max.d_x + new UDim(0, /*PixelAligned(*/ delta /*)*/), d_area.d_max.d_y);

            SetAreaImpl(area.d_min, area.Size);

            // move the dragging point so mouse remains 'attached' to edge of segment
            _dragPoint.X += d_pixelSize.Width - orgWidth;

            OnSegmentSized(new WindowEventArgs(this));
        }
Example #7
0
 void OnEnable()
 {
     mRect = target as URect;
 }
Example #8
0
 void OnDisable()
 {
     mRect = null;
 }
Example #9
0
 /// <summary>
 /// 画矩形
 /// </summary>
 /// <param name="rect">大小</param>
 /// <param name="color">颜色</param>
 /// <param name="fill">是否填充</param>
 public abstract void DrawRect(URect rect, UColor color, bool fill);