Пример #1
0
        void Layout(UiContext context, RectangleF parent, out RectangleF myRectangle, out RectangleF track)
        {
            var height = Cascade(Style?.Height, null, Height);
            var myPos  = context.AnchorPosition(parent, Anchor, X, Y, Width, height);

            myRectangle = new RectangleF(myPos.X, myPos.Y, Width, height);
            var heightAdjust = (Style?.ButtonMarginY ?? 0) * 2;

            leftbutton.Height  = myRectangle.Height - heightAdjust;
            rightbutton.Height = myRectangle.Height - heightAdjust;
            track        = myRectangle;
            track.X     += leftbutton.GetDimensions().X;
            track.Width -= (leftbutton.GetDimensions().X + rightbutton.GetDimensions().X);
            if (Style != null)
            {
                track.X      += Style.TrackMarginX;
                track.Width  -= Style.TrackMarginX * 2;
                track.Y      += Style.TrackMarginY;
                track.Height -= Style.TrackMarginY * 2;
            }
            thumb.Width  = track.Width * ThumbSize;
            thumb.X      = ScrollOffset * (track.Width - thumb.Width);
            thumb.Height = track.Height;
            if (thumb.Dragging && (track.Width - thumb.Width) >= 0.01f)
            {
                var newX = MathHelper.Clamp(thumb.DragOffset.X + dragXStart, 0, track.Width - thumb.Width);
                ScrollOffset = newX / (track.Width - thumb.Width);
            }
        }
Пример #2
0
 public override void OnMouseWheel(UiContext context, RectangleF parentRectangle, float delta)
 {
     if (!Visible)
     {
         return;
     }
     Layout(context, parentRectangle, out _, out var track);
     if (track.Contains(context.MouseX, context.MouseY))
     {
         if (Smooth)
         {
             ScrollOffset -= Tick * 4 * delta;
             if (ScrollOffset > 1)
             {
                 ScrollOffset = 1;
             }
             if (ScrollOffset < 0)
             {
                 ScrollOffset = 0;
             }
         }
         else
         {
             nextScrollDir = delta > 0 ? -1 : 1;
         }
     }
 }
Пример #3
0
        public override void OnMouseUp(UiContext context, RectangleF parentRectangle)
        {
            var myPos       = context.AnchorPosition(parentRectangle, Anchor, X, Y, Width, Height);
            var myRectangle = new RectangleF(myPos.X, myPos.Y, Width, Height);

            Scrollbar.OnMouseUp(context, myRectangle);
        }
Пример #4
0
        void RenderCharacter(UiContext context, RectangleF myRect)
        {
            var px = context.PointsToPixels(myRect);
            //Get current state
            var rs     = context.RenderState;
            var cc     = rs.ClearColor;
            var prevRt = rs.RenderTarget;

            //new state
            context.Mode3D();
            rs.DepthEnabled = true;
            var renderTarget = new RenderTarget2D(px.Width, px.Height);

            rs.RenderTarget = renderTarget;
            rs.ClearColor   = Color4.Transparent;
            rs.ClearAll();
            //draw

            //restore state
            rs.RenderTarget = prevRt;
            rs.DepthEnabled = false;
            rs.ClearColor   = cc;
            context.Mode2D();
            context.Renderer2D.Draw(renderTarget.Texture, new Rectangle(0, 0, px.Width, px.Height), px, Color4.White);
            //Free
            renderTarget.Dispose();
        }
Пример #5
0
 public override void EnableScripting(UiContext context, string modalData)
 {
     scriptingContext = context;
     scriptingEnabled = true;
     this.modalData   = modalData;
     SetActiveScene();
 }
Пример #6
0
 public void Draw(UiContext context, RectangleF rectangle)
 {
     foreach (var e in Elements)
     {
         e.Render(context, rectangle);
     }
 }
Пример #7
0
        public override void Render(UiContext context, RectangleF parentRectangle)
        {
            if (context.GlobalTime - lastChange > blinkDuration)
            {
                lastChange    = context.GlobalTime;
                cursorVisible = !cursorVisible;
            }
            if (!Visible)
            {
                return;
            }
            if (doSetFocus)
            {
                context.OnFocus();
                doSetFocus = false;
                hasFocus   = true;
            }
            if (hasFocus)
            {
                context.SetTextFocus(this);
            }
            var rect = GetMyRectangle(context, parentRectangle);

            Background?.Draw(context, rect);
            DrawText(context, rect);
            (hasFocus ? FocusedBorder ?? Border : Border)?.Draw(context, rect);
        }
        public override void Render(UiContext context, RectangleF parentRectangle)
        {
            if (!Visible)
            {
                return;
            }
            var myPos       = context.AnchorPosition(parentRectangle, Anchor, X, Y, Width, Height);
            var myRectangle = new RectangleF(myPos.X, myPos.Y, Width, Height);

            if (Fill)
            {
                myRectangle = parentRectangle;
            }
            if (Background != null)
            {
                Background.Draw(context, myRectangle);
            }
            if (!loaded)
            {
                texture = context.GetTextureFile(Path);
                loaded  = true;
            }
            if (texture != null)
            {
                context.Mode2D();
                var color = (Tint ?? InterfaceColor.White).Color;
                context.Renderer2D.DrawImageStretched(texture, context.PointsToPixels(myRectangle), color, Flip);
            }
        }
Пример #9
0
        protected void Update(UiContext context, Vector2 myPos)
        {
            aspectRatio = context.ViewportWidth / context.ViewportHeight;
            TimeSpan delta;

            if (lastTime == TimeSpan.FromSeconds(0))
            {
                delta = TimeSpan.FromSeconds(0);
            }
            else
            {
                delta = context.GlobalTime - lastTime;
            }
            lastTime = context.GlobalTime;
            if (CurrentAnimation != null)
            {
                CurrentAnimation.SetWidgetPosition(myPos);
                CurrentAnimation.Update(delta.TotalSeconds, aspectRatio);
                if (!CurrentAnimation.Running)
                {
                    if (CurrentAnimation.FinalPositionSet.HasValue)
                    {
                        animSetPos = CurrentAnimation.FinalPositionSet.Value;
                    }
                    CurrentAnimation = null;
                }
            }
        }
Пример #10
0
        public override void Render(UiContext context, RectangleF parentRectangle)
        {
            var rect = GetMyRectangle(context, parentRectangle);

            Background?.Draw(context, rect);
            float y  = rect.Y + rect.Height;
            float dt = (float)context.DeltaTime;

            lock (Chat.Messages)
            {
                for (int i = Chat.Messages.Count - 1; i >= 0 && (i >= Chat.Messages.Count - 16); i--)
                {
                    var msg = Chat.Messages[i];
                    if (msg.TimeAlive <= 0)
                    {
                        continue;
                    }
                    msg.TimeAlive -= dt;
                    var sz = context.RenderContext.Renderer2D.MeasureStringCached(ref msg.Cache, msg.Font, context.TextSize(msg.Size),
                                                                                  msg.Text);
                    float h = context.PixelsToPoints(sz.Y);
                    y -= h;
                    DrawText(context, ref msg.Cache, new RectangleF(rect.X, y, rect.Width, h), msg.Size, msg.Font,
                             msg.Color, InterfaceColor.Black, HorizontalAlignment.Left, VerticalAlignment.Default,
                             false, msg.Text);
                    y -= 2;
                }
            }
            Border?.Draw(context, rect);
        }
Пример #11
0
        public override void Render(UiContext context, RectangleF parentRectangle)
        {
            if (!Visible)
            {
                return;
            }
            var myPos       = context.AnchorPosition(parentRectangle, Anchor, X, Y, Width, Height);
            var myRectangle = new RectangleF(myPos.X, myPos.Y, Width, Height);

            if (Fill)
            {
                myRectangle = parentRectangle;
            }
            if (Background != null)
            {
                Background.Draw(context, myRectangle);
            }
            if (!string.IsNullOrEmpty(Name) && (!loaded || texture == null || texture.IsDisposed))
            {
                texture = context.Data.ResourceManager.FindTexture(Name) as Texture2D;
                loaded  = true;
            }
            if (texture != null)
            {
                var color = (Tint ?? InterfaceColor.White).Color;
                context.RenderContext.Renderer2D.DrawImageStretched(texture, context.PointsToPixels(myRectangle), color, Flip);
            }
        }
Пример #12
0
 public override void Render(UiContext context, RectangleF parentRectangle)
 {
     DoTimers(context.GlobalTime);
     ScriptedEvent("Update");
     Background?.Draw(context, parentRectangle);
     base.Render(context, parentRectangle);
 }
Пример #13
0
        RectangleF GetMyRectangle(UiContext context, RectangleF parentRectangle)
        {
            var myPos       = context.AnchorPosition(parentRectangle, Anchor, X, Y, Width, Height);
            var myRectangle = new RectangleF(myPos.X, myPos.Y, Width, Height);

            return(myRectangle);
        }
Пример #14
0
        RectangleF GetMyRectangle(UiContext context, RectangleF parentRectangle)
        {
            var myPos = context.AnchorPosition(parentRectangle, Anchor, X, Y, Width, Height);

            Update(context, myPos);
            myPos = AnimatedPosition(myPos);
            var myRect = new RectangleF(myPos.X, myPos.Y, Width, Height);

            //layout children
            float x = 0;

            if (ItemA != null)
            {
                ItemA.Height = Height;
                ItemA.X      = 0;
                ItemA.Y      = 0;
                x            = ItemA.Width;
                if (ItemB == null)
                {
                    ItemA.Width = Width;
                }
                rectangleA = new RectangleF(myPos.X, myPos.Y, ItemA.Width, Height);
            }

            x += ItemMarginX;
            if (ItemB != null)
            {
                ItemB.X      = x;
                ItemB.Y      = 0;
                ItemB.Width  = Width - x;
                ItemB.Height = Height;
                rectangleB   = new RectangleF(myPos.X + x, myPos.Y, ItemB.Width, ItemB.Height);
            }
            return(myRect);
        }
Пример #15
0
        public override void Render(UiContext context, RectangleF parentRectangle)
        {
            if (!Visible)
            {
                return;
            }
            var myRectangle = GetMyRectangle(context, parentRectangle);

            Background?.Draw(context, myRectangle);
            ItemA?.Render(context, myRectangle);
            ItemB?.Render(context, myRectangle);
            UiRenderable border = Border;

            if (Enabled)
            {
                if (Selected)
                {
                    border = SelectedBorder ?? border;
                }
                if (rectangleA.Contains(context.MouseX, context.MouseY) ||
                    rectangleB.Contains(context.MouseX, context.MouseY))
                {
                    border = HoverBorder ?? border;
                }
            }
            if (ItemA != null)
            {
                border?.Draw(context, rectangleA);
            }
            if (ItemB != null)
            {
                border?.Draw(context, rectangleB);
            }
        }
Пример #16
0
        void OpenModal(UiContext context, string xml, object table, LuaFunction function)
        {
            string modalData = null;

            if (table != null)
            {
                modalData = (string)(
                    ((LuaFunction)lua["Serialize"]).Call(table)[0]
                    );
            }
            Action <string> onClose = null;

            if (function != null)
            {
                onClose = (x) =>
                {
                    object argument = null;
                    if (!string.IsNullOrEmpty(x))
                    {
                        argument = ((LuaFunction)lua["Deserialize"]).Call(x)[0];
                    }
                    function.Call(argument);
                };
            }
            context.OpenModal(xml, modalData, onClose);
        }
Пример #17
0
        public override void Render(UiContext context, RectangleF clientRectangle)
        {
            var color = (Color ?? InterfaceColor.White).GetColor(context.GlobalTime);

            if (context.PointsToPixels(Width) <= 1)
            {
                context.RenderContext.Renderer2D.DrawRectangle(context.PointsToPixels(clientRectangle), color, 1);
            }
            float w = Width / 3;

            //Left
            LR(context, clientRectangle, 0, w, 0, color);
            LR(context, clientRectangle, w, w, 1, color);
            LR(context, clientRectangle, 2 * w, w, 2, color);
            //Right
            var rW = clientRectangle.Width - Width;

            LR(context, clientRectangle, rW, w, 0, color);
            LR(context, clientRectangle, rW + w, w, 1, color);
            LR(context, clientRectangle, rW + 2 * w, w, 2, color);
            //Top
            TB(context, clientRectangle, 0, w, 0, color);
            TB(context, clientRectangle, w, w, 1, color);
            TB(context, clientRectangle, 2 * w, w, 2, color);
            //Bottom
            var rH = clientRectangle.Height - Width;

            TB(context, clientRectangle, rH, w, 0, color);
            TB(context, clientRectangle, rH + w, w, 1, color);
            TB(context, clientRectangle, rH + 2 * w, w, 2, color);
        }
 public void OnMouseUp(UiContext context, RectangleF parent)
 {
     Layout(parent, out var myRectangle, out var track);
     upbutton.OnMouseUp(context, myRectangle);
     downbutton.OnMouseUp(context, myRectangle);
     thumb.OnMouseUp(context, track);
     dragYStart = 0;
 }
Пример #19
0
        static void TB(UiContext context, RectangleF client, float pos, float w, int alphaSide, Color4 color)
        {
            var    r         = new RectangleF(client.X + 1.5f * w, client.Y + pos, client.Width - 3f * w, w);
            var    alphaZero = new Color4(color.R, color.G, color.B, 0);
            Color4 top       = alphaSide == 0 ? alphaZero : color;
            Color4 bottom    = alphaSide == 2 ? alphaZero : color;

            context.RenderContext.Renderer2D.FillRectangleColors(context.PointsToPixelsF(r), top, top, bottom, bottom);
        }
Пример #20
0
        public void DrawWithClip(UiContext context, RectangleF rectangle, RectangleF clip)
        {
            var clipRectangle = context.PointsToPixels(clip);

            context.RenderContext.ScissorRectangle = clipRectangle;
            context.RenderContext.ScissorEnabled   = true;
            Draw(context, rectangle);
            context.RenderContext.ScissorEnabled = false;
        }
Пример #21
0
        public override void OnMouseUp(UiContext context, RectangleF parentRectangle)
        {
            var myRectangle = GetMyRectangle(context, parentRectangle);

            if (Infocard != null && scrollbarVisible)
            {
                scrollbar.OnMouseUp(context, myRectangle);
            }
        }
Пример #22
0
        static void LR(UiContext context, RectangleF client, float pos, float w, int alphaSide, Color4 color)
        {
            var    r         = new RectangleF(client.X + pos, client.Y + w * 1.5f, w, client.Height - 3f * w);
            var    alphaZero = new Color4(color.R, color.G, color.B, 0);
            Color4 left      = alphaSide == 0 ? alphaZero : color;
            Color4 right     = alphaSide == 2 ? alphaZero : color;

            context.RenderContext.Renderer2D.FillRectangleColors(context.PointsToPixelsF(r), left, right, left, right);
        }
Пример #23
0
 public override void Render(UiContext context, RectangleF parentRectangle)
 {
     if (Visible)
     {
         Update(context, Vector2.Zero);
         Background?.Draw(context, parentRectangle);
         base.Render(context, parentRectangle);
     }
 }
Пример #24
0
        public override void OnMouseDown(UiContext context, RectangleF parentRectangle)
        {
            var myRect = GetMyRectangle(context, parentRectangle);

            if (CanRotate && myRect.Contains(context.MouseX, context.MouseY))
            {
                dragStart = new Vector2(context.MouseX, context.MouseY);
                dragging  = true;
            }
        }
Пример #25
0
        protected virtual RectangleF GetMyRectangle(UiContext context, RectangleF parentRectangle)
        {
            var myPos = context.AnchorPosition(parentRectangle, Anchor, X, Y, Width, Height);

            Update(context, myPos);
            myPos = AnimatedPosition(myPos);
            var myRect = new RectangleF(myPos.X, myPos.Y, Width, Height);

            return(myRect);
        }
Пример #26
0
 public override void OnMouseUp(UiContext context, RectangleF parentRectangle)
 {
     if (!Visible)
     {
         return;
     }
     Dragging  = false;
     HeldDown  = false;
     DragStart = DragOffset = Vector2.Zero;
 }
Пример #27
0
        public override void OnMouseWheel(UiContext context, RectangleF parentRectangle, float delta)
        {
            var myPos       = context.AnchorPosition(parentRectangle, Anchor, X, Y, Width, Height);
            var myRectangle = new RectangleF(myPos.X, myPos.Y, Width, Height);

            if (myRectangle.Contains(context.MouseX, context.MouseY))
            {
                Scrollbar.OnMouseWheel(delta);
            }
        }
Пример #28
0
        public override void OnMouseWheel(UiContext context, RectangleF parentRectangle, float delta)
        {
            var myRectangle = GetMyRectangle(context, parentRectangle);

            if (Infocard != null && scrollbarVisible &&
                myRectangle.Contains(context.MouseX, context.MouseY))
            {
                scrollbar.OnMouseWheel(delta);
            }
        }
Пример #29
0
 void DrawText(UiContext context, RectangleF myRect)
 {
     //Padding
     myRect.X     += 2;
     myRect.Width -= 4;
     //Draw
     DrawText(context, myRect, FontSize, Font, TextColor, TextShadow, HorizontalAlignment.Left,
              VerticalAlignment.Center,
              true, (hasFocus && cursorVisible) ? CurrentText + "|" : CurrentText);
 }
Пример #30
0
        public override void Render(UiContext context, RectangleF clientRectangle)
        {
            if (Color == null)
            {
                return;
            }
            var rect = context.PointsToPixels(clientRectangle);

            context.RenderContext.Renderer2D.FillRectangle(rect, Color.GetColor(context.GlobalTime));
        }