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); } }
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; } } }
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); }
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(); }
public override void EnableScripting(UiContext context, string modalData) { scriptingContext = context; scriptingEnabled = true; this.modalData = modalData; SetActiveScene(); }
public void Draw(UiContext context, RectangleF rectangle) { foreach (var e in Elements) { e.Render(context, rectangle); } }
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); } }
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; } } }
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); }
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); } }
public override void Render(UiContext context, RectangleF parentRectangle) { DoTimers(context.GlobalTime); ScriptedEvent("Update"); Background?.Draw(context, parentRectangle); base.Render(context, parentRectangle); }
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); }
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); }
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); } }
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); }
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; }
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); }
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; }
public override void OnMouseUp(UiContext context, RectangleF parentRectangle) { var myRectangle = GetMyRectangle(context, parentRectangle); if (Infocard != null && scrollbarVisible) { scrollbar.OnMouseUp(context, myRectangle); } }
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); }
public override void Render(UiContext context, RectangleF parentRectangle) { if (Visible) { Update(context, Vector2.Zero); Background?.Draw(context, parentRectangle); base.Render(context, parentRectangle); } }
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; } }
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); }
public override void OnMouseUp(UiContext context, RectangleF parentRectangle) { if (!Visible) { return; } Dragging = false; HeldDown = false; DragStart = DragOffset = Vector2.Zero; }
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); } }
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); } }
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); }
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)); }