Example #1
0
        private Component CreateEdge(bool vertical, bool minSide)
        {
            Panel zone = new Panel();
            zone.Parent.Value = this;
            zone.Position.Exp = () =>
            {
                Point2D vec = Position.Value;
                if(vertical)
                {
                    if(minSide)
                    {
                        vec.Y += northWestZone.Size.Value.Y;
                    }else
                    {
                        vec.X += Size.Value.X - zone.Size.Value.X;
                        vec.Y += northEastZone.Size.Value.Y;
                    }
                }else
                {
                    if(minSide)
                    {
                        vec.X += northWestZone.Size.Value.X;
                    }else
                    {
                        vec.X += southWestZone.Size.Value.X;
                        vec.Y += Size.Value.Y - zone.Size.Value.Y;
                    }
                }
                return vec;
            };
            zone.Size.Exp = () =>
            {
                Point2D vec;
                if(vertical)
                {
                    if(minSide)
                    {
                        vec.X = westSize.Value;
                        vec.Y = Size.Value.Y - northWestZone.Size.Value.Y - southWestZone.Size.Value.Y;
                    }else
                    {
                        vec.X = eastSize.Value;
                        vec.Y = Size.Value.Y - northEastZone.Size.Value.Y - southEastZone.Size.Value.Y;
                    }
                }else
                {
                    if(minSide)
                    {
                        vec.X = Size.Value.X - northWestZone.Size.Value.X - northEastZone.Size.Value.X;
                        vec.Y = northSize.Value;
                    }else
                    {

                        vec.X = Size.Value.X - southWestZone.Size.Value.X - southEastZone.Size.Value.X;
                        vec.Y = southSize.Value;
                    }
                }
                return vec;
            };
            zone.Opaque.Value = false;
            zone.Hidden.Value = true;
            zone.InputHidden.Value = false;
            zone.HoverCursor.Exp = () =>
            {
                if(DisableResize.Value) return Cursor.UNSPECIFIED;
                if(vertical) return Cursor.RESIZE_HORIZONTAL;
                else		 return Cursor.RESIZE_VERTICAL;
            };
            bool dragging = false;
            zone.OnMousePress += button => {if(button == MouseButton.LEFT) dragging = true;};
            zone.OnMouseRelease += button => {if(button == MouseButton.LEFT) dragging = false;};
            zone.OnMouseMove += (coords, delta) =>
            {
                if(!DisableResize.Value && dragging)
                {
                    Rectangle bounds = Bounds;
                    if(vertical)
                    {
                        if(minSide)
                        {
                            bounds.X += delta.X;
                            bounds.Width -= delta.X;
                        }else
                        {
                            bounds.Width += delta.X;
                        }
                    }else
                    {
                        if(minSide)
                        {
                            bounds.Y += delta.Y;
                            bounds.Height -= delta.Y;
                        }else
                        {
                            bounds.Height += delta.Y;
                        }
                    }
                    Bounds = bounds;
                    if(OnResize != null) OnResize();
                }
            };
            return zone;
        }
Example #2
0
        public Frame()
        {
            //init border to 1%
            Border.Exp = () => Size.Value * .01;
            Border.OnUpdate += MarkDirty;
            FlushBeforeUpdate(Border);

            ForeColor.Value = RGB.White;
            ForeColor.OnUpdate += MarkDirty;
            FlushBeforeUpdate(ForeColor);

            BorderColor.Value = RGB.Grey;
            BorderColor.OnUpdate += MarkDirty;
            FlushBeforeUpdate(BorderColor);

            BackColor.Value = RGB.Black;
            BackColor.OnUpdate += MarkDirty;
            FlushBeforeUpdate(BackColor);

            EdgeInterpolation.Value = Interpolation.Linear;
            EdgeInterpolation.OnUpdate += MarkDirty;
            FlushBeforeUpdate(EdgeInterpolation);

            TitleHeight.Exp = () => (int)(Size.Value.Y * .025);
            TitleHeight.OnUpdate += MarkDirty;
            FlushBeforeUpdate(TitleHeight);

            RoundEdges.Value = true;
            RoundEdges.OnUpdate += MarkDirty;
            FlushBeforeUpdate(RoundEdges);

            DisableNorthEdge.Value = false;
            DisableNorthEdge.OnUpdate += MarkDirty;
            FlushBeforeUpdate(DisableNorthEdge);

            DisableSouthEdge.Value = false;
            DisableSouthEdge.OnUpdate += MarkDirty;
            FlushBeforeUpdate(DisableSouthEdge);

            DisableWestEdge.Value = false;
            DisableWestEdge.OnUpdate += MarkDirty;
            FlushBeforeUpdate(DisableWestEdge);

            DisableEastEdge.Value = false;
            DisableEastEdge.OnUpdate += MarkDirty;
            FlushBeforeUpdate(DisableEastEdge);

            DisableTitle.Value = false;
            DisableTitle.OnUpdate += MarkDirty;
            FlushBeforeUpdate(DisableTitle);

            ResizeBorderMulti.Value = 1;

            DisableResize.Value = false;
            DisableMove.Value = false;

            Size.OnFilter += v =>
            {
                Point2D min = 0;
                if(!DisableNorthEdge.Value) min.Y += Border.Value.Y;
                if(!DisableSouthEdge.Value) min.Y += Border.Value.Y;
                if(!DisableWestEdge.Value) min.X += Border.Value.X;
                if(!DisableEastEdge.Value) min.X += Border.Value.X;
                if(!DisableTitle.Value) min.Y += TitleHeight.Value;
                return VectorUtil.Max(v, min);
            };

            //create title panel
            TitlePanel = new Panel();
            TitlePanel.DisableAutoReparent();
            TitlePanel.Parent.Value = this;
            //init color
            TitlePanel.Color.Exp = () => BorderColor.Value;
            //center in button
            TitlePanel.Position.Exp = () =>
            {
                Point2D vec = this.Position.Value;
                if(!DisableWestEdge.Value) vec.X += Border.Value.X / 2;
                if(!DisableNorthEdge.Value) vec.Y += Border.Value.Y / 2;
                return vec;
            };
            //reduce size by twice border
            TitlePanel.Size.Exp = () =>
            {
                Point2D vec;
                vec.X = this.Size.Value.X;
                if(!DisableWestEdge.Value) vec.X -= Border.Value.X / 2;
                if(!DisableEastEdge.Value) vec.X -= Border.Value.X / 2;
                vec.Y = TitleHeight.Value;
                return vec;
            };
            //slightly offset z coord
            TitlePanel.ZCoord.Exp = () => ZCoord.Value + .001;
            TitlePanel.Hidden.Value = true;

            //create content panel
            Content = new Panel();
            Content.DisableAutoReparent();
            Content.Parent.Value = this;
            //init color
            Content.Color.Exp = () => ForeColor.Value;
            //center in frame
            Content.Position.Exp = () =>
            {
                Point2D vec = this.Position.Value;
                if(!DisableWestEdge.Value) vec.X += Border.Value.X;
                if(!DisableNorthEdge.Value) vec.Y += Border.Value.Y;
                if(!DisableTitle.Value) vec.Y += TitleHeight.Value;
                return vec;
            };
            //reduce size by twice border
            Content.Size.Exp = () =>
            {
                Point2D vec = this.Size.Value;
                if(!DisableWestEdge.Value) vec.X -= Border.Value.X;
                if(!DisableEastEdge.Value) vec.X -= Border.Value.X;
                if(!DisableNorthEdge.Value) vec.Y -= Border.Value.Y;
                if(!DisableSouthEdge.Value) vec.Y -= Border.Value.Y;
                if(!DisableTitle.Value) vec.Y -= TitleHeight.Value;
                return vec;
            };
            //slightly offset z coord
            Content.ZCoord.Exp = () => ZCoord.Value + .001;
            Content.Hidden.Value = true;

            northSize.Exp = () => DisableNorthEdge.Value ? 0 : (int)(Border.Value.Y * ResizeBorderMulti.Value);
            southSize.Exp = () => DisableSouthEdge.Value ? 0 : (int)(Border.Value.Y * ResizeBorderMulti.Value);
            westSize.Exp = () => DisableWestEdge.Value ? 0 : (int)(Border.Value.X * ResizeBorderMulti.Value);
            eastSize.Exp = () => DisableEastEdge.Value ? 0 : (int)(Border.Value.X * ResizeBorderMulti.Value);

            //create all resizers
            //diagonals
            northWestZone = CreateCorner(true, true);
            southWestZone = CreateCorner(true, false);
            northEastZone = CreateCorner(false, true);
            southEastZone = CreateCorner(false, false);
            //edges
            westZone = CreateEdge(true, true);
            eastZone = CreateEdge(true, false);
            northZone = CreateEdge(false, true);
            southZone = CreateEdge(false, false);

            //create title mover
            Panel titleZone = new Panel();
            titleZone.Parent.Value = this;
            titleZone.Position.Exp = () =>
            {
                Point2D vec = Position.Value;
                vec.X += northWestZone.Size.Value.X;
                vec.Y += northZone.Size.Value.Y;
                return vec;
            };
            titleZone.Size.Exp = () =>
            {
                Point2D vec;
                vec.X = Size.Value.X - northEastZone.Size.Value.X - northWestZone.Size.Value.X;
                if(!DisableTitle.Value)
                {
                    vec.Y = TitleHeight.Value + Border.Value.Y - northZone.Size.Value.Y;
                }else
                {
                    vec.Y = 0;
                }
                return vec;
            };
            titleZone.Opaque.Value = false;
            titleZone.Hidden.Value = true;
            titleZone.InputHidden.Value = false;
            bool isDragging = false;
            titleZone.OnMousePress += button =>
            {
                if(button == MouseButton.LEFT)
                {
                    isDragging = true;
                    Grab();
                }
            };
            titleZone.OnMouseRelease += button =>
            {
                if(button == MouseButton.LEFT)
                {
                    isDragging = false;
                    Drop();
                }
            };
            titleZone.OnMouseMove += (coords, delta) =>
            {
                if(!DisableMove.Value && isDragging)
                {
                    Position.Value += delta;
                    if(OnMove != null) OnMove();
                }
            };
        }
Example #3
0
 private Component CreateCorner(bool left, bool top)
 {
     Panel zone = new Panel();
     zone.Parent.Value = this;
     zone.Position.Exp = () =>
     {
         Point2D vec = Position.Value;
         if(!left) vec.X += Size.Value.X - zone.Size.Value.X;
         if(!top) vec.Y += Size.Value.Y - zone.Size.Value.Y;
         return vec;
     };
     zone.Size.Exp = () =>
     {
         Point2D vec = 0;
         if(left) vec.X = westSize.Value;
         else     vec.X = eastSize.Value;
         if(top)  vec.Y = northSize.Value;
         else     vec.Y = southSize.Value;
         return vec;
     };
     zone.Opaque.Value = false;
     zone.Hidden.Value = true;
     zone.InputHidden.Value = false;
     zone.HoverCursor.Exp = () =>
     {
         if(DisableResize.Value) return Cursor.UNSPECIFIED;
         if(left ^ top) return Cursor.RESIZE_NESW;
         else		   return Cursor.RESIZE_NWSE;
     };
     bool dragging = false;
     zone.OnMousePress += button => {if(button == MouseButton.LEFT) dragging = true;};
     zone.OnMouseRelease += button => {if(button == MouseButton.LEFT) dragging = false;};
     zone.OnMouseMove += (coords, delta) =>
     {
         if(!DisableResize.Value && dragging)
         {
             Rectangle bounds = Bounds;
             if(left)
             {
                 bounds.X += delta.X;
                 bounds.Width -= delta.X;
             }else
             {
                 bounds.Width += delta.X;
             }
             if(top)
             {
                 bounds.Y += delta.Y;
                 bounds.Height -= delta.Y;
             }else
             {
                 bounds.Height += delta.Y;
             }
             Bounds = bounds;
             if(OnResize != null) OnResize();
         }
     };
     return zone;
 }
Example #4
0
        public Button()
        {
            //init border to 5%
            Border.Exp = () => Size.Value * .05;
            Border.OnUpdate += MarkDirty;
            FlushBeforeUpdate(Border);

            ForeColor.Value = RGB.White;
            ForeColor.OnUpdate += MarkDirty;
            FlushBeforeUpdate(ForeColor);

            BackColor.Value = RGB.Black;
            BackColor.OnUpdate += MarkDirty;
            FlushBeforeUpdate(BackColor);

            //init hover color to average of fore and back
            HoverColor.Exp = () => (ForeColor.Value / 2) + (BackColor.Value / 2);
            HoverColor.OnUpdate += MarkDirty;
            FlushBeforeUpdate(HoverColor);

            EdgeInterpolation.Value = Interpolation.Linear;
            EdgeInterpolation.OnUpdate += MarkDirty;
            FlushBeforeUpdate(EdgeInterpolation);

            //create content panel
            Content = new Panel();
            Content.DisableAutoReparent();
            Content.Parent.Value = this;
            //init color
            Content.Color.Exp = () => ForeColor.Value;
            //center in button
            Content.Position.Exp = () =>
            {
                Point2D vec = Position.Value;
                vec += Size.Value / 2;
                vec -= Content.Size.Value / 2;
                return vec;
            };
            //reduce size by twice border
            Content.Size.Exp = () =>
            {
                Point2D vec = Size.Value;
                vec -= Border.Value * 2;
                return vec;
            };
            //slightly offset z coord
            Content.ZCoord.Exp = () => ZCoord.Value + .001;
            Content.Hidden.Value = true;

            //re-render when content color changes
            Content.Color.OnUpdate += MarkDirty;

            OnMouseEnter += () =>
            {
                if(!DisableHoverColor)
                {
                    Hovered = true;
                    Content.Color.Exp = () => HoverColor.Value;
                }
            };
            OnMouseExit += () =>
            {
                Hovered = false;
                Content.Color.Exp = () => ForeColor.Value;
            };
        }