public void Reset() { if (TransferEncoding != TransferEncoding.None) { ContentTransform.End(); ContentTransform = null; } StringQueue = null; chunkLen = chunkIndex = CurrentReadBytes = 0; State = BodyParserState.Dormant; TransferEncoding = TransferEncoding.None; CompressionType = CompressionType.Unknown; ContentLength = -1; IsSet = false; }
public override void Write(byte[] data) { ThrowIfEnded(); if (!IsSet) { throw new InvalidOperationException("Not set"); } // pass data through ContentTransform ContentTransform.Write(data); if (ContentTransform.Buffered == 0) { return; // no data available } data = ContentTransform.Read(); WriteTransformed(data); }
private void AddContentTransform(ContentTransform content) { content.Top.pivot = new Vector2(0, 1); if (Contents.Count == 0) { content.Top.SetParent(ContentContainer); content.Top.anchorMin = new Vector2(0, 1); content.Top.anchoredPosition = Vector2.Scale(Vector2.down + Vector2.right, OpenMarginV); } else { content.Top.SetParent(Contents[Contents.Count - 1].Bottom); content.Top.anchorMin = Orientation == EOrientation.TopToBottom ? Vector2.zero : Vector2.one; content.Top.anchoredPosition = PaddingV; } content.Top.anchorMax = content.Top.anchorMin; Contents.Add(content); }
public Task FlyOutAsync() { if (_isVisible) { _isVisible = false; var animation = new DoubleAnimation { From = ContentTransform.X, To = Width, Duration = TimeSpan.FromMilliseconds(300), EasingFunction = new CubicEase { EasingMode = EasingMode.EaseOut }, }; ContentTransform.BeginAnimation(TranslateTransform.XProperty, animation); return(Task.Delay(animation.Duration.TimeSpan)); } return(Task.FromResult <object>(null)); }
public void Finish() { ThrowIfEnded(); if (!IsSet) { throw new InvalidOperationException("Not set"); } if (IsCompressionSet) { // compressed data footer CompressorDuplex compressor = ContentTransform as CompressorDuplex; compressor.Finish(); WriteTransformed(compressor.Read()); } WriteTransformed(null); IsSet = false; ContentTransform.End(); IsCompressionSet = false; TransferEncoding = TransferEncoding.None; Compression = CompressionType.Unknown; ContentLength = -1; }
private void Awake() { Instance = this; tooltipObject = new GameObject("KsmGuiTooltip"); TopTransform = tooltipObject.AddComponent <RectTransform>(); // default of 0, 1 mean pivot is at the window top-left corner // pivotX = 0 => left, pivotX = 1 => right // pivotY = 0 => bottom, pivotY = 1 => top TopTransform.pivot = new Vector2(0f, 0f); // distance in pixels between the pivot and the center of the screen TopTransform.anchoredPosition = new Vector2(0f, 0f); TopTransform.sizeDelta = new Vector2(KsmGuiStyle.tooltipMaxWidth, 0f); // max width of tooltip, text wrap will occur if larger. // set the parent canvas // render order of the various UI canvases (lower value = on top) // maincanvas => Z 750 // appCanvas => Z 625 // actionCanvas => Z 500 // screenMessageCanvas => Z 450 // dialogCanvas => Z 400 // dragDropcanvas => Z 333 // debugCanvas => Z 315 // tooltipCanvas => Z 300 TopTransform.SetParentFixScale(UIMasterController.Instance.tooltipCanvas.transform); tooltipObject.AddComponent <CanvasRenderer>(); VerticalLayoutGroup toplayout = tooltipObject.AddComponent <VerticalLayoutGroup>(); toplayout.childAlignment = TextAnchor.UpperLeft; toplayout.childControlHeight = true; toplayout.childControlWidth = true; toplayout.childForceExpandHeight = false; toplayout.childForceExpandWidth = false; ContentSizeFitter topFitter = tooltipObject.AddComponent <ContentSizeFitter>(); topFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained; topFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; // first child : 1px white border GameObject border = new GameObject("KsmGuiTooltipBorder"); ContentTransform = border.AddComponent <RectTransform>(); ContentTransform.SetParentFixScale(TopTransform); border.AddComponent <CanvasRenderer>(); VerticalLayoutGroup borderLayout = border.AddComponent <VerticalLayoutGroup>(); borderLayout.padding = new RectOffset(1, 1, 1, 1); borderLayout.childAlignment = TextAnchor.UpperLeft; borderLayout.childControlHeight = true; borderLayout.childControlWidth = true; borderLayout.childForceExpandHeight = false; borderLayout.childForceExpandWidth = false; Image borderImage = border.AddComponent <Image>(); borderImage.color = KsmGuiStyle.tooltipBorderColor; borderImage.raycastTarget = false; // 2nd child : black background GameObject background = new GameObject("KsmGuiTooltipBackground"); RectTransform backgroundTranform = background.AddComponent <RectTransform>(); backgroundTranform.SetParentFixScale(ContentTransform); background.AddComponent <CanvasRenderer>(); VerticalLayoutGroup backgroundLayout = background.AddComponent <VerticalLayoutGroup>(); backgroundLayout.padding = new RectOffset(5, 5, 2, 2); backgroundLayout.childAlignment = TextAnchor.UpperLeft; backgroundLayout.childControlHeight = true; backgroundLayout.childControlWidth = true; backgroundLayout.childForceExpandHeight = false; backgroundLayout.childForceExpandWidth = false; Image backgroundImage = background.AddComponent <Image>(); backgroundImage.color = KsmGuiStyle.tooltipBackgroundColor; backgroundImage.raycastTarget = false; // last child : text GameObject textObject = new GameObject("KsmGuiTooltipText"); RectTransform textTransform = textObject.AddComponent <RectTransform>(); textTransform.SetParentFixScale(backgroundTranform); textObject.AddComponent <CanvasRenderer>(); textComponent = textObject.AddComponent <TextMeshProUGUI>(); textComponent.raycastTarget = false; textComponent.color = KsmGuiStyle.textColor; textComponent.font = KsmGuiStyle.textFont; textComponent.fontSize = KsmGuiStyle.textSize; textComponent.alignment = TextAlignmentOptions.Top; tooltipObject.SetLayerRecursive(5); //KsmGuiBase.ApplyCanvasScalerScale(TopTransform); tooltipObject.SetActive(false); IsVisible = false; }
private int ProcessData(byte[] data, bool writeExcess) { ThrowIfEnded(); if (!IsSet) { throw new InvalidOperationException("Not set"); } int i = 0, len; char c; byte[] sliced; for (; i < data.Length;) { switch (State) { case BodyParserState.RawRead: len = ContentLength == -1 ? data.Length - i : Math.Min(data.Length - i, ContentLength - CurrentReadBytes); sliced = new byte[len]; Buffer.BlockCopy(data, i, sliced, 0, len); i += len; CurrentReadBytes += len; ContentTransform.Write(data); if (ContentTransform.Buffered > 0) { Readable.Write(ContentTransform.Read()); } if (CurrentReadBytes == ContentLength) { State = BodyParserState.Dormant; OnEnd?.Invoke(); break; } break; case BodyParserState.Chunked_Length: c = (char)data[i++]; if (c != CR) { StringQueue.Append(c); } else { if (!int.TryParse(StringQueue.Next(), NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out int result)) { End(); return(-1); } chunkLen = result; State = BodyParserState.Chunked_LenLf; } break; case BodyParserState.Chunked_LenLf: c = (char)data[i++]; if (c != LF) { End(); return(-1); } if (chunkLen == 0) { State = BodyParserState.Chunked_Trailer; } else { State = BodyParserState.Chunked_ChunkData; } break; case BodyParserState.Chunked_ChunkData: len = Math.Min(data.Length - i, chunkLen - chunkIndex); sliced = new byte[len]; Buffer.BlockCopy(data, i, sliced, 0, len); i += len; CurrentReadBytes += len; chunkIndex += len; ContentTransform.Write(sliced); Readable.Write(ContentTransform.Read()); if (chunkLen == chunkIndex) { State = BodyParserState.Chunked_ChunkCr; } break; case BodyParserState.Chunked_ChunkCr: c = (char)data[i++]; if (c != CR) { End(); return(-1); } State = BodyParserState.Chunked_ChunkLf; break; case BodyParserState.Chunked_ChunkLf: c = (char)data[i++]; if (c != LF) { End(); return(-1); } State = BodyParserState.Chunked_Length; chunkLen = chunkIndex = 0; StringQueue.New(); break; case BodyParserState.Chunked_Trailer: c = (char)data[i++]; if (c != CR) { chunkIndex++; } else { if (chunkIndex == 0) { State = BodyParserState.Chunked_Lf; } else { chunkIndex = -1; // LF will be added } } break; case BodyParserState.Chunked_Lf: c = (char)data[i++]; if (c != LF) { End(); return(-1); } State = BodyParserState.Dormant; OnEnd?.Invoke(); ContentLength = CurrentReadBytes; break; default: throw new InvalidOperationException("ProcessData cannot execute on Dormant state"); } } if (writeExcess) { len = data.Length - i; sliced = new byte[len]; Buffer.BlockCopy(data, i, sliced, 0, len); Writable.Write(sliced); } return(i); }
public void Add(ContentTransform content) { AddContentTransform(content); ResizeToFitContent(); }