protected override dfRenderData OnRebuildRenderData() { this.renderData.Clear(); if (Atlas != null && Atlas[Source] != null) { var options = new dfSprite.RenderOptions() { atlas = this.Atlas, spriteInfo = Atlas[Source], pixelsToUnits = 1, size = this.Size, color = Style.Color, baseIndex = 0, fillAmount = 1f, flip = dfSpriteFlip.None }; dfSlicedSprite.renderSprite(renderData, options); renderData.Material = Atlas.Material; renderData.Transform = Matrix4x4.identity; } return(renderData); }
private static void rebuildUV(dfRenderData renderData, dfSprite.RenderOptions options) { Rect rect = options.spriteInfo.region; dfList <Vector2> uV = renderData.UV; uV.Add(new Vector2(rect.x, rect.yMax)); uV.Add(new Vector2(rect.xMax, rect.yMax)); uV.Add(new Vector2(rect.xMax, rect.y)); uV.Add(new Vector2(rect.x, rect.y)); Vector2 item = Vector2.zero; if (options.flip.IsSet(dfSpriteFlip.FlipHorizontal)) { item = uV[1]; uV[1] = uV[0]; uV[0] = item; item = uV[3]; uV[3] = uV[2]; uV[2] = item; } if (options.flip.IsSet(dfSpriteFlip.FlipVertical)) { item = uV[0]; uV[0] = uV[3]; uV[3] = item; item = uV[1]; uV[1] = uV[2]; uV[2] = item; } }
protected override void OnRebuildRenderData() { if (base.Atlas == null) { return; } dfAtlas.ItemInfo spriteInfo = base.SpriteInfo; if (spriteInfo == null) { return; } this.renderData.Material = base.Atlas.Material; if (spriteInfo.border.horizontal == 0 && spriteInfo.border.vertical == 0) { base.OnRebuildRenderData(); return; } Color32 color32 = base.ApplyOpacity((!base.IsEnabled ? this.disabledColor : this.color)); dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions upperLeft = renderOption; upperLeft.atlas = this.atlas; upperLeft.color = color32; upperLeft.fillAmount = this.fillAmount; upperLeft.fillDirection = this.fillDirection; upperLeft.flip = this.flip; upperLeft.invertFill = this.invertFill; upperLeft.offset = this.pivot.TransformToUpperLeft(base.Size); upperLeft.pixelsToUnits = base.PixelsToUnits(); upperLeft.size = base.Size; upperLeft.spriteInfo = base.SpriteInfo; renderOption = upperLeft; dfSlicedSprite.renderSprite(this.renderData, renderOption); }
private void renderSprite(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination) { try { string value = token.GetAttribute(0).Value.Value; dfAtlas.ItemInfo item = this.SpriteAtlas[value]; if (item != null) { dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions spriteAtlas = renderOption; spriteAtlas.atlas = this.SpriteAtlas; spriteAtlas.color = color; spriteAtlas.fillAmount = 1f; spriteAtlas.offset = position; spriteAtlas.pixelsToUnits = base.PixelRatio; spriteAtlas.size = new Vector2((float)token.Width, (float)token.Height); spriteAtlas.spriteInfo = item; renderOption = spriteAtlas; dfSprite.renderSprite(this.SpriteBuffer, renderOption); } } finally { } }
protected override void OnRebuildRenderData() { if ((this.Atlas != null) && !string.IsNullOrEmpty(this.backgroundSprite)) { dfAtlas.ItemInfo info = this.Atlas[this.backgroundSprite]; if (info != null) { base.renderData.Material = this.Atlas.Material; Color32 color = base.ApplyOpacity(this.BackgroundColor); dfSprite.RenderOptions options = new dfSprite.RenderOptions { atlas = this.atlas, color = color, fillAmount = 1f, offset = base.pivot.TransformToUpperLeft(base.Size), pixelsToUnits = base.PixelsToUnits(), size = base.Size, spriteInfo = info }; if ((info.border.horizontal == 0) && (info.border.vertical == 0)) { dfSprite.renderSprite(base.renderData, options); } else { dfSlicedSprite.renderSprite(base.renderData, options); } } } }
protected override void OnRebuildRenderData() { if (this.Atlas == null || string.IsNullOrEmpty(this.backgroundSprite)) { return; } dfAtlas.ItemInfo item = this.Atlas[this.backgroundSprite]; if (item == null) { return; } this.renderData.Material = this.Atlas.Material; Color32 color32 = base.ApplyOpacity((!base.IsEnabled ? this.disabledColor : this.color)); dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions upperLeft = renderOption; upperLeft.atlas = this.atlas; upperLeft.color = color32; upperLeft.fillAmount = 1f; upperLeft.offset = this.pivot.TransformToUpperLeft(base.Size); upperLeft.pixelsToUnits = base.PixelsToUnits(); upperLeft.size = base.Size; upperLeft.spriteInfo = item; renderOption = upperLeft; if (item.border.horizontal != 0 || item.border.vertical != 0) { dfSlicedSprite.renderSprite(this.renderData, renderOption); } else { dfSprite.renderSprite(this.renderData, renderOption); } }
protected internal virtual void renderBackground() { if (this.Atlas != null) { dfAtlas.ItemInfo info = this.Atlas[this.backgroundSprite]; if (info != null) { Color32 color = base.ApplyOpacity(this.BackgroundColor); dfSprite.RenderOptions options = new dfSprite.RenderOptions { atlas = this.atlas, color = color, fillAmount = 1f, offset = base.pivot.TransformToUpperLeft(base.Size), pixelsToUnits = base.PixelsToUnits(), size = base.Size, spriteInfo = info }; if ((info.border.horizontal == 0) && (info.border.vertical == 0)) { dfSprite.renderSprite(base.renderData, options); } else { dfSlicedSprite.renderSprite(base.renderData, options); } } } }
private void renderSprite(dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination) { try { //@Profiler.BeginSample( "Render embedded sprite" ); var spriteName = token.GetAttribute(0).Value.Value; var spriteInfo = SpriteAtlas[spriteName]; if (spriteInfo == null) { return; } var options = new dfSprite.RenderOptions() { atlas = SpriteAtlas, color = color, fillAmount = 1, flip = dfSpriteFlip.None, offset = position, pixelsToUnits = PixelRatio, size = new Vector2(token.Width, token.Height), spriteInfo = spriteInfo }; dfSprite.renderSprite(SpriteBuffer, options); } finally { //@Profiler.EndSample(); } }
private void renderBackground() { if (this.Atlas == null) { return; } dfAtlas.ItemInfo item = this.Atlas[this.backgroundSprite]; if (item == null) { return; } Color32 color32 = base.ApplyOpacity((!base.IsEnabled ? base.DisabledColor : base.Color)); dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions upperLeft = renderOption; upperLeft.atlas = this.atlas; upperLeft.color = color32; upperLeft.fillAmount = 1f; upperLeft.offset = this.pivot.TransformToUpperLeft(base.Size); upperLeft.pixelsToUnits = base.PixelsToUnits(); upperLeft.size = base.Size; upperLeft.spriteInfo = item; renderOption = upperLeft; if (item.border.horizontal != 0 || item.border.vertical != 0) { dfSlicedSprite.renderSprite(this.renderData, renderOption); } else { dfSprite.renderSprite(this.renderData, renderOption); } }
private void renderSelection() { if ((base.Atlas != null) && (this.selectedIndex >= 0)) { dfAtlas.ItemInfo info = base.Atlas[this.ItemHighlight]; if (info != null) { Vector3 vector2; float num = base.PixelsToUnits(); Vector3 vector = base.pivot.TransformToUpperLeft(base.Size); vector2 = new Vector3(vector.x + this.listPadding.left, (vector.y - this.listPadding.top) + this.scrollPosition, 0f) { y = vector2.y - (this.selectedIndex * this.itemHeight) }; Color32 color = base.ApplyOpacity(base.color); dfSprite.RenderOptions options = new dfSprite.RenderOptions { atlas = base.atlas, color = color, fillAmount = 1f, pixelsToUnits = num, size = new Vector3(this.size.x - this.listPadding.horizontal, (float)this.itemHeight), spriteInfo = info, offset = vector2 }; if ((info.border.horizontal > 0) || (info.border.vertical > 0)) { dfSlicedSprite.renderSprite(base.renderData, options); } else { dfSprite.renderSprite(base.renderData, options); } } } }
private static void rebuildColors(dfRenderData renderData, dfSprite.RenderOptions options) { for (int i = 0; i < 16; i++) { renderData.Colors.Add(options.color); } }
protected override void OnRebuildRenderData() { if ((!(this.Atlas != null) || !(this.Atlas.Material != null) ? true : !base.IsVisible)) { return; } if (this.SpriteInfo == null) { return; } this.renderData.Material = this.Atlas.Material; Color32 color32 = base.ApplyOpacity((!base.IsEnabled ? this.disabledColor : this.color)); dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions atlas = renderOption; atlas.atlas = this.Atlas; atlas.color = color32; atlas.fillAmount = this.fillAmount; atlas.fillDirection = this.fillDirection; atlas.flip = this.flip; atlas.invertFill = this.invertFill; atlas.offset = this.pivot.TransformToUpperLeft(base.Size); atlas.pixelsToUnits = base.PixelsToUnits(); atlas.size = base.Size; atlas.spriteInfo = this.SpriteInfo; renderOption = atlas; dfSprite.renderSprite(this.renderData, renderOption); }
private static void rebuildColors(dfRenderData renderData, dfSprite.RenderOptions options) { dfList <Color32> colors = renderData.Colors; colors.Add(options.color); colors.Add(options.color); colors.Add(options.color); colors.Add(options.color); }
private static void rebuildTriangles(dfRenderData renderData, dfSprite.RenderOptions options) { int baseIndex = options.baseIndex; dfList <int> triangles = renderData.Triangles; for (int i = 0; i < triangleIndices.Length; i++) { triangles.Add(baseIndex + triangleIndices[i]); } }
private static void rebuildTriangles(dfRenderData renderData, dfSprite.RenderOptions options) { int num = options.baseIndex; dfList <int> triangles = renderData.Triangles; triangles.EnsureCapacity(triangles.Count + (int)dfSprite.TRIANGLE_INDICES.Length); for (int i = 0; i < (int)dfSprite.TRIANGLE_INDICES.Length; i++) { triangles.Add(num + dfSprite.TRIANGLE_INDICES[i]); } }
internal static void renderSprite(dfRenderData renderData, dfSprite.RenderOptions options) { options.baseIndex = renderData.Vertices.Count; rebuildTriangles(renderData, options); rebuildVertices(renderData, options); rebuildUV(renderData, options); rebuildColors(renderData, options); if (options.fillAmount < 1f) { doFill(renderData, options); } }
private void renderHover() { if (Application.isPlaying && ((((base.Atlas != null) && base.IsEnabled) && ((this.hoverIndex >= 0) && (this.hoverIndex <= (this.items.Length - 1)))) && !string.IsNullOrEmpty(this.ItemHover))) { dfAtlas.ItemInfo info = base.Atlas[this.ItemHover]; if (info != null) { Vector3 vector = base.pivot.TransformToUpperLeft(base.Size); Vector3 vector2 = new Vector3(vector.x + this.listPadding.left, (vector.y - this.listPadding.top) + this.scrollPosition, 0f); float stepSize = base.PixelsToUnits(); int num2 = this.hoverIndex * this.itemHeight; if (this.animateHover) { float num3 = Mathf.Abs((float)(this.hoverTweenLocation - num2)); float num4 = (this.size.y - this.listPadding.vertical) * 0.5f; if (num3 > num4) { this.hoverTweenLocation = num2 + (Mathf.Sign(this.hoverTweenLocation - num2) * num4); num3 = num4; } float maxDelta = (Time.deltaTime / stepSize) * 2f; this.hoverTweenLocation = Mathf.MoveTowards(this.hoverTweenLocation, (float)num2, maxDelta); } else { this.hoverTweenLocation = num2; } vector2.y -= this.hoverTweenLocation.Quantize(stepSize); Color32 color = base.ApplyOpacity(base.color); dfSprite.RenderOptions options = new dfSprite.RenderOptions { atlas = base.atlas, color = color, fillAmount = 1f, pixelsToUnits = base.PixelsToUnits(), size = new Vector3(this.size.x - this.listPadding.horizontal, (float)this.itemHeight), spriteInfo = info, offset = vector2 }; if ((info.border.horizontal > 0) || (info.border.vertical > 0)) { dfSlicedSprite.renderSprite(base.renderData, options); } else { dfSprite.renderSprite(base.renderData, options); } if (num2 != this.hoverTweenLocation) { this.Invalidate(); } } } }
internal static void renderSprite(dfRenderData data, dfSprite.RenderOptions options) { options.baseIndex = data.Vertices.Count; dfSprite.rebuildTriangles(data, options); dfSprite.rebuildVertices(data, options); dfSprite.rebuildUV(data, options); dfSprite.rebuildColors(data, options); if (options.fillAmount > -1f && options.fillAmount < 1f) { dfSprite.doFill(data, options); } }
private void renderProgressFill() { if (this.Atlas == null) { return; } dfAtlas.ItemInfo item = this.Atlas[this.progressSprite]; if (item == null) { return; } Vector3 vector3 = new Vector3((float)this.padding.left, (float)(-this.padding.top)); Vector2 vector2 = new Vector2(this.size.x - (float)this.padding.horizontal, this.size.y - (float)this.padding.vertical); float single = 1f; float single1 = this.maxValue - this.minValue; float single2 = (this.rawValue - this.minValue) / single1; dfProgressFillMode _dfProgressFillMode = this.fillMode; if (_dfProgressFillMode == dfProgressFillMode.Stretch) { vector2.x *single2 >= (float)item.border.horizontal; } if (_dfProgressFillMode != dfProgressFillMode.Fill) { vector2.x = Mathf.Max((float)item.border.horizontal, vector2.x * single2); } else { single = single2; } Color32 color32 = base.ApplyOpacity((!base.IsEnabled ? base.DisabledColor : this.ProgressColor)); dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions upperLeft = renderOption; upperLeft.atlas = this.atlas; upperLeft.color = color32; upperLeft.fillAmount = single; upperLeft.offset = this.pivot.TransformToUpperLeft(base.Size) + vector3; upperLeft.pixelsToUnits = base.PixelsToUnits(); upperLeft.size = vector2; upperLeft.spriteInfo = item; renderOption = upperLeft; if (item.border.horizontal != 0 || item.border.vertical != 0) { dfSlicedSprite.renderSprite(this.renderData, renderOption); } else { dfSprite.renderSprite(this.renderData, renderOption); } }
private void renderSelection() { if (Atlas == null || selectedIndex < 0) { return; } var spriteInfo = Atlas[ItemHighlight]; if (spriteInfo == null) { return; } var p2u = PixelsToUnits(); var pivotOffset = pivot.TransformToUpperLeft(Size); var offset = new Vector3( pivotOffset.x + listPadding.left, pivotOffset.y - listPadding.top + scrollPosition, 0 ); offset.y -= (selectedIndex * itemHeight); var color = ApplyOpacity(this.color); var options = new dfSprite.RenderOptions() { atlas = atlas, color = color, fillAmount = 1, flip = dfSpriteFlip.None, pixelsToUnits = p2u, size = new Vector3(this.size.x - listPadding.horizontal, itemHeight), spriteInfo = spriteInfo, offset = offset }; if (spriteInfo.border.horizontal > 0 || spriteInfo.border.vertical > 0) { dfSlicedSprite.renderSprite(renderData, options); } else { dfSprite.renderSprite(renderData, options); } }
private static void rebuildVertices(dfRenderData renderData, dfSprite.RenderOptions options) { float x = 0f; float y = 0f; float num3 = Mathf.Ceil(options.size.x); float num4 = Mathf.Ceil(-options.size.y); dfAtlas.ItemInfo spriteInfo = options.spriteInfo; float left = spriteInfo.border.left; float top = spriteInfo.border.top; float right = spriteInfo.border.right; float bottom = spriteInfo.border.bottom; if (options.flip.IsSet(dfSpriteFlip.FlipHorizontal)) { float num9 = right; right = left; left = num9; } if (options.flip.IsSet(dfSpriteFlip.FlipVertical)) { float num10 = bottom; bottom = top; top = num10; } verts[0] = new Vector3(x, y, 0f) + options.offset; verts[1] = verts[0] + new Vector3(left, 0f, 0f); verts[2] = verts[0] + new Vector3(left, -top, 0f); verts[3] = verts[0] + new Vector3(0f, -top, 0f); verts[4] = new Vector3(num3 - right, y, 0f) + options.offset; verts[5] = verts[4] + new Vector3(right, 0f, 0f); verts[6] = verts[4] + new Vector3(right, -top, 0f); verts[7] = verts[4] + new Vector3(0f, -top, 0f); verts[8] = new Vector3(x, num4 + bottom, 0f) + options.offset; verts[9] = verts[8] + new Vector3(left, 0f, 0f); verts[10] = verts[8] + new Vector3(left, -bottom, 0f); verts[11] = verts[8] + new Vector3(0f, -bottom, 0f); verts[12] = new Vector3(num3 - right, num4 + bottom, 0f) + options.offset; verts[13] = verts[12] + new Vector3(right, 0f, 0f); verts[14] = verts[12] + new Vector3(right, -bottom, 0f); verts[15] = verts[12] + new Vector3(0f, -bottom, 0f); for (int i = 0; i < verts.Length; i++) { renderData.Vertices.Add(((Vector3)(verts[i] * options.pixelsToUnits)).Quantize(options.pixelsToUnits)); } }
private static void rebuildVertices(dfRenderData renderData, dfSprite.RenderOptions options) { float single = 0f; float single1 = 0f; float single2 = Mathf.Ceil(options.size.x); float single3 = Mathf.Ceil(-options.size.y); dfAtlas.ItemInfo itemInfo = options.spriteInfo; float single4 = (float)itemInfo.border.left; float single5 = (float)itemInfo.border.top; float single6 = (float)itemInfo.border.right; float single7 = (float)itemInfo.border.bottom; if (options.flip.IsSet(dfSpriteFlip.FlipHorizontal)) { float single8 = single6; single6 = single4; single4 = single8; } if (options.flip.IsSet(dfSpriteFlip.FlipVertical)) { float single9 = single7; single7 = single5; single5 = single9; } dfSlicedSprite.verts[0] = new Vector3(single, single1, 0f) + options.offset; dfSlicedSprite.verts[1] = dfSlicedSprite.verts[0] + new Vector3(single4, 0f, 0f); dfSlicedSprite.verts[2] = dfSlicedSprite.verts[0] + new Vector3(single4, -single5, 0f); dfSlicedSprite.verts[3] = dfSlicedSprite.verts[0] + new Vector3(0f, -single5, 0f); dfSlicedSprite.verts[4] = new Vector3(single2 - single6, single1, 0f) + options.offset; dfSlicedSprite.verts[5] = dfSlicedSprite.verts[4] + new Vector3(single6, 0f, 0f); dfSlicedSprite.verts[6] = dfSlicedSprite.verts[4] + new Vector3(single6, -single5, 0f); dfSlicedSprite.verts[7] = dfSlicedSprite.verts[4] + new Vector3(0f, -single5, 0f); dfSlicedSprite.verts[8] = new Vector3(single, single3 + single7, 0f) + options.offset; dfSlicedSprite.verts[9] = dfSlicedSprite.verts[8] + new Vector3(single4, 0f, 0f); dfSlicedSprite.verts[10] = dfSlicedSprite.verts[8] + new Vector3(single4, -single7, 0f); dfSlicedSprite.verts[11] = dfSlicedSprite.verts[8] + new Vector3(0f, -single7, 0f); dfSlicedSprite.verts[12] = new Vector3(single2 - single6, single3 + single7, 0f) + options.offset; dfSlicedSprite.verts[13] = dfSlicedSprite.verts[12] + new Vector3(single6, 0f, 0f); dfSlicedSprite.verts[14] = dfSlicedSprite.verts[12] + new Vector3(single6, -single7, 0f); dfSlicedSprite.verts[15] = dfSlicedSprite.verts[12] + new Vector3(0f, -single7, 0f); for (int i = 0; i < (int)dfSlicedSprite.verts.Length; i++) { renderData.Vertices.Add((dfSlicedSprite.verts[i] * options.pixelsToUnits).Quantize(options.pixelsToUnits)); } }
private void renderProgressFill() { if (this.Atlas != null) { dfAtlas.ItemInfo info = this.Atlas[this.progressSprite]; if (info != null) { Vector3 vector = new Vector3((float)this.padding.left, (float)-this.padding.top); Vector2 vector2 = new Vector2(this.size.x - this.padding.horizontal, this.size.y - this.padding.vertical); float num = 1f; float num2 = this.maxValue - this.minValue; float num3 = (this.rawValue - this.minValue) / num2; dfProgressFillMode fillMode = this.fillMode; if ((fillMode == dfProgressFillMode.Stretch) && ((vector2.x * num3) < info.border.horizontal)) { } if (fillMode == dfProgressFillMode.Fill) { num = num3; } else { vector2.x = Mathf.Max((float)info.border.horizontal, vector2.x * num3); } Color32 color = base.ApplyOpacity(!base.IsEnabled ? base.DisabledColor : this.ProgressColor); dfSprite.RenderOptions options = new dfSprite.RenderOptions { atlas = this.atlas, color = color, fillAmount = num, offset = base.pivot.TransformToUpperLeft(base.Size) + vector, pixelsToUnits = base.PixelsToUnits(), size = vector2, spriteInfo = info }; if ((info.border.horizontal == 0) && (info.border.vertical == 0)) { dfSprite.renderSprite(base.renderData, options); } else { dfSlicedSprite.renderSprite(base.renderData, options); } } } }
protected override dfRenderData OnRebuildRenderData() { this.renderData.Clear(); if ((this.Atlas != null) && (this.Atlas[this.Source] != null)) { dfSprite.RenderOptions options = new dfSprite.RenderOptions { atlas = this.Atlas, spriteInfo = this.Atlas[this.Source], pixelsToUnits = 1f, size = base.Size, color = this.Style.Color, fillAmount = 1f }; dfSlicedSprite.renderSprite(this.renderData, options); this.renderData.Material = this.Atlas.Material; this.renderData.Transform = Matrix4x4.identity; } return(this.renderData); }
private static void doFill(dfRenderData renderData, dfSprite.RenderOptions options) { int num = options.baseIndex; dfList <Vector3> vertices = renderData.Vertices; dfList <Vector2> uV = renderData.UV; int num1 = num; int num2 = num + 1; int num3 = num + 3; int num4 = num + 2; if (options.invertFill) { if (options.fillDirection != dfFillDirection.Horizontal) { num1 = num + 3; num2 = num + 2; num3 = num; num4 = num + 1; } else { num1 = num + 1; num2 = num; num3 = num + 2; num4 = num + 3; } } if (options.fillDirection != dfFillDirection.Horizontal) { vertices[num3] = Vector3.Lerp(vertices[num3], vertices[num1], 1f - options.fillAmount); vertices[num4] = Vector3.Lerp(vertices[num4], vertices[num2], 1f - options.fillAmount); uV[num3] = Vector2.Lerp(uV[num3], uV[num1], 1f - options.fillAmount); uV[num4] = Vector2.Lerp(uV[num4], uV[num2], 1f - options.fillAmount); } else { vertices[num2] = Vector3.Lerp(vertices[num2], vertices[num1], 1f - options.fillAmount); vertices[num4] = Vector3.Lerp(vertices[num4], vertices[num3], 1f - options.fillAmount); uV[num2] = Vector2.Lerp(uV[num2], uV[num1], 1f - options.fillAmount); uV[num4] = Vector2.Lerp(uV[num4], uV[num3], 1f - options.fillAmount); } }
protected override dfRenderData OnRebuildRenderData() { this.renderData.Clear(); if (this.Atlas != null && this.Atlas[this.Source] != null) { dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions atlas = renderOption; atlas.atlas = this.Atlas; atlas.spriteInfo = this.Atlas[this.Source]; atlas.pixelsToUnits = 1f; atlas.size = this.Size; atlas.color = this.Style.Color; atlas.fillAmount = 1f; renderOption = atlas; dfSlicedSprite.renderSprite(this.renderData, renderOption); this.renderData.Material = this.Atlas.Material; this.renderData.Transform = Matrix4x4.identity; } return(this.renderData); }
private static void rebuildVertices(dfRenderData renderData, dfSprite.RenderOptions options) { dfList <Vector3> vertices = renderData.Vertices; int num = options.baseIndex; float single = 0f; float single1 = 0f; float single2 = Mathf.Ceil(options.size.x); float single3 = Mathf.Ceil(-options.size.y); vertices.Add(new Vector3(single, single1, 0f) * options.pixelsToUnits); vertices.Add(new Vector3(single2, single1, 0f) * options.pixelsToUnits); vertices.Add(new Vector3(single2, single3, 0f) * options.pixelsToUnits); vertices.Add(new Vector3(single, single3, 0f) * options.pixelsToUnits); Vector3 vector3 = options.offset.RoundToInt() * options.pixelsToUnits; for (int i = 0; i < 4; i++) { vertices[num + i] = (vertices[num + i] + vector3).Quantize(options.pixelsToUnits); } }
protected override dfRenderData OnRebuildRenderData() { this.renderData.Clear(); if (this.Atlas != null && this.Atlas[this.Source] != null) { dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions atlas = renderOption; atlas.atlas = this.Atlas; atlas.spriteInfo = this.Atlas[this.Source]; atlas.pixelsToUnits = 1f; atlas.size = this.Size; atlas.color = this.Style.Color; atlas.fillAmount = 1f; renderOption = atlas; dfSlicedSprite.renderSprite(this.renderData, renderOption); this.renderData.Material = this.Atlas.Material; this.renderData.Transform = Matrix4x4.identity; } return this.renderData; }
protected override void OnRebuildRenderData() { if (Atlas == null || string.IsNullOrEmpty(backgroundSprite)) { return; } var spriteInfo = Atlas[backgroundSprite]; if (spriteInfo == null) { return; } renderData.Material = Atlas.Material; var color = ApplyOpacity(IsEnabled ? this.color : this.disabledColor); var options = new dfSprite.RenderOptions() { atlas = atlas, color = color, fillAmount = 1, flip = dfSpriteFlip.None, offset = pivot.TransformToUpperLeft(Size), pixelsToUnits = PixelsToUnits(), size = Size, spriteInfo = spriteInfo }; if (spriteInfo.border.horizontal == 0 && spriteInfo.border.vertical == 0) { dfSprite.renderSprite(renderData, options); } else { dfSlicedSprite.renderSprite(renderData, options); } }
private void renderSelection() { if (base.Atlas == null || this.selectedIndex < 0) { return; } dfAtlas.ItemInfo item = base.Atlas[this.ItemHighlight]; if (item == null) { return; } float units = base.PixelsToUnits(); Vector3 upperLeft = this.pivot.TransformToUpperLeft(base.Size); Vector3 vector3 = new Vector3(upperLeft.x + (float)this.listPadding.left, upperLeft.y - (float)this.listPadding.top + this.scrollPosition, 0f) { y = vector3.y - (float)(this.selectedIndex * this.itemHeight) }; Color32 color32 = base.ApplyOpacity(this.color); dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions vector31 = renderOption; vector31.atlas = this.atlas; vector31.color = color32; vector31.fillAmount = 1f; vector31.pixelsToUnits = units; vector31.size = new Vector3(this.size.x - (float)this.listPadding.horizontal, (float)this.itemHeight); vector31.spriteInfo = item; vector31.offset = vector3; renderOption = vector31; if (item.border.horizontal > 0 || item.border.vertical > 0) { dfSlicedSprite.renderSprite(this.renderData, renderOption); } else { dfSprite.renderSprite(this.renderData, renderOption); } }
protected internal virtual void renderBackground() { if (Atlas == null) { return; } var spriteInfo = Atlas[backgroundSprite]; if (spriteInfo == null) { return; } var color = ApplyOpacity(BackgroundColor); var options = new dfSprite.RenderOptions() { atlas = atlas, color = color, fillAmount = 1, flip = dfSpriteFlip.None, offset = pivot.TransformToUpperLeft(Size), pixelsToUnits = PixelsToUnits(), size = Size, spriteInfo = spriteInfo }; if (spriteInfo.border.horizontal == 0 && spriteInfo.border.vertical == 0) { dfSprite.renderSprite(renderData, options); } else { dfSlicedSprite.renderSprite(renderData, options); } }
protected internal virtual void renderBackground() { if( Atlas == null ) return; var spriteInfo = Atlas[ backgroundSprite ]; if( spriteInfo == null ) { return; } var color = ApplyOpacity( IsEnabled ? this.color : this.disabledColor ); var options = new dfSprite.RenderOptions() { atlas = atlas, color = color, fillAmount = 1, flip = dfSpriteFlip.None, offset = pivot.TransformToUpperLeft( Size ), pixelsToUnits = PixelsToUnits(), size = Size, spriteInfo = spriteInfo }; if( spriteInfo.border.horizontal == 0 && spriteInfo.border.vertical == 0 ) dfSprite.renderSprite( renderData, options ); else dfSlicedSprite.renderSprite( renderData, options ); }
protected override void OnRebuildRenderData() { if( Atlas == null || string.IsNullOrEmpty( backgroundSprite ) ) return; var spriteInfo = Atlas[ backgroundSprite ]; if( spriteInfo == null ) { return; } renderData.Material = Atlas.Material; var color = ApplyOpacity( IsEnabled ? this.color : this.disabledColor ); var options = new dfSprite.RenderOptions() { atlas = atlas, color = color, fillAmount = 1, flip = dfSpriteFlip.None, offset = pivot.TransformToUpperLeft( Size ), pixelsToUnits = PixelsToUnits(), size = Size, spriteInfo = spriteInfo }; if( spriteInfo.border.horizontal == 0 && spriteInfo.border.vertical == 0 ) dfSprite.renderSprite( renderData, options ); else dfSlicedSprite.renderSprite( renderData, options ); }
protected internal virtual void renderBackground() { if (this.Atlas == null) { return; } dfAtlas.ItemInfo backgroundSprite = this.getBackgroundSprite(); if (backgroundSprite == null) { return; } Color32 color32 = base.ApplyOpacity(this.getActiveColor()); dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions upperLeft = renderOption; upperLeft.atlas = this.atlas; upperLeft.color = color32; upperLeft.fillAmount = 1f; upperLeft.offset = this.pivot.TransformToUpperLeft(base.Size); upperLeft.pixelsToUnits = base.PixelsToUnits(); upperLeft.size = base.Size; upperLeft.spriteInfo = backgroundSprite; renderOption = upperLeft; if (backgroundSprite.border.horizontal != 0 || backgroundSprite.border.vertical != 0) { dfSlicedSprite.renderSprite(this.renderData, renderOption); } else { dfSprite.renderSprite(this.renderData, renderOption); } }
protected override dfRenderData OnRebuildRenderData() { this.renderData.Clear(); if( Atlas != null && Atlas[ Source ] != null ) { var options = new dfSprite.RenderOptions() { atlas = this.Atlas, spriteInfo = Atlas[ Source ], pixelsToUnits = 1, size = this.Size, color = Style.Color, baseIndex = 0, fillAmount = 1f, flip = dfSpriteFlip.None }; dfSlicedSprite.renderSprite( renderData, options ); renderData.Material = Atlas.Material; renderData.Transform = Matrix4x4.identity; } return renderData; }
private void renderSprite( dfMarkupToken token, Color32 color, Vector3 position, dfRenderData destination ) { try { //@Profiler.BeginSample( "Render embedded sprite" ); var spriteName = token.GetAttribute( 0 ).Value.Value; var spriteInfo = SpriteAtlas[ spriteName ]; if( spriteInfo == null ) return; var options = new dfSprite.RenderOptions() { atlas = SpriteAtlas, color = color, fillAmount = 1, flip = dfSpriteFlip.None, offset = position, pixelsToUnits = PixelRatio, size = new Vector2( token.Width, token.Height ), spriteInfo = spriteInfo }; dfSprite.renderSprite( SpriteBuffer, options ); } finally { //@Profiler.EndSample(); } }
private void renderHover() { if( !Application.isPlaying ) return; var hoverDisabled = Atlas == null || !this.IsEnabled || hoverIndex < 0 || hoverIndex > items.Length - 1 || string.IsNullOrEmpty( ItemHover ); if( hoverDisabled ) return; var spriteInfo = Atlas[ ItemHover ]; if( spriteInfo == null ) { return; } var pivotOffset = pivot.TransformToUpperLeft( Size ); var offset = new Vector3( pivotOffset.x + listPadding.left, pivotOffset.y - listPadding.top + scrollPosition, 0 ); var pixelSize = PixelsToUnits(); var hoverTargetPos = ( hoverIndex * itemHeight ); if( animateHover ) { var tweenDistance = Mathf.Abs( hoverTweenLocation - hoverTargetPos ); float maxDistance = ( size.y - listPadding.vertical ) * 0.5f; if( tweenDistance > maxDistance ) { hoverTweenLocation = hoverTargetPos + Mathf.Sign( hoverTweenLocation - hoverTargetPos ) * maxDistance; tweenDistance = maxDistance; } var speed = Time.deltaTime / pixelSize * 2f; hoverTweenLocation = Mathf.MoveTowards( hoverTweenLocation, hoverTargetPos, speed ); } else { hoverTweenLocation = hoverTargetPos; } offset.y -= hoverTweenLocation.Quantize( pixelSize ); var color = ApplyOpacity( this.color ); var options = new dfSprite.RenderOptions() { atlas = atlas, color = color, fillAmount = 1, flip = dfSpriteFlip.None, pixelsToUnits = PixelsToUnits(), size = new Vector3( this.size.x - listPadding.horizontal, itemHeight ), spriteInfo = spriteInfo, offset = offset }; if( spriteInfo.border.horizontal > 0 || spriteInfo.border.vertical > 0 ) dfSlicedSprite.renderSprite( renderData, options ); else dfSprite.renderSprite( renderData, options ); if( hoverTargetPos != hoverTweenLocation ) { Invalidate(); } }
private void renderSelection() { if( Atlas == null || selectedIndex < 0 ) return; var spriteInfo = Atlas[ ItemHighlight ]; if( spriteInfo == null ) { return; } var p2u = PixelsToUnits(); var pivotOffset = pivot.TransformToUpperLeft( Size ); var offset = new Vector3( pivotOffset.x + listPadding.left, pivotOffset.y - listPadding.top + scrollPosition, 0 ); offset.y -= ( selectedIndex * itemHeight ); var color = ApplyOpacity( this.color ); var options = new dfSprite.RenderOptions() { atlas = atlas, color = color, fillAmount = 1, flip = dfSpriteFlip.None, pixelsToUnits = p2u, size = new Vector3( this.size.x - listPadding.horizontal, itemHeight ), spriteInfo = spriteInfo, offset = offset }; if( spriteInfo.border.horizontal > 0 || spriteInfo.border.vertical > 0 ) dfSlicedSprite.renderSprite( renderData, options ); else dfSprite.renderSprite( renderData, options ); }
private void renderHover() { if (!Application.isPlaying) { return; } if ((base.Atlas == null || !base.IsEnabled || this.hoverIndex < 0 || this.hoverIndex > (int)this.items.Length - 1 ? true : string.IsNullOrEmpty(this.ItemHover))) { return; } dfAtlas.ItemInfo item = base.Atlas[this.ItemHover]; if (item == null) { return; } Vector3 upperLeft = this.pivot.TransformToUpperLeft(base.Size); Vector3 vector3 = new Vector3(upperLeft.x + (float)this.listPadding.left, upperLeft.y - (float)this.listPadding.top + this.scrollPosition, 0f); float units = base.PixelsToUnits(); int num = this.hoverIndex * this.itemHeight; if (!this.animateHover) { this.hoverTweenLocation = (float)num; } else { float single = Mathf.Abs(this.hoverTweenLocation - (float)num); float single1 = (this.size.y - (float)this.listPadding.vertical) * 0.5f; if (single > single1) { this.hoverTweenLocation = (float)num + Mathf.Sign(this.hoverTweenLocation - (float)num) * single1; single = single1; } float single2 = Time.deltaTime / units * 2f; this.hoverTweenLocation = Mathf.MoveTowards(this.hoverTweenLocation, (float)num, single2); } vector3.y = vector3.y - this.hoverTweenLocation.Quantize(units); Color32 color32 = base.ApplyOpacity(this.color); dfSprite.RenderOptions renderOption = new dfSprite.RenderOptions(); dfSprite.RenderOptions units1 = renderOption; units1.atlas = this.atlas; units1.color = color32; units1.fillAmount = 1f; units1.pixelsToUnits = base.PixelsToUnits(); units1.size = new Vector3(this.size.x - (float)this.listPadding.horizontal, (float)this.itemHeight); units1.spriteInfo = item; units1.offset = vector3; renderOption = units1; if (item.border.horizontal > 0 || item.border.vertical > 0) { dfSlicedSprite.renderSprite(this.renderData, renderOption); } else { dfSprite.renderSprite(this.renderData, renderOption); } if ((float)num != this.hoverTweenLocation) { this.Invalidate(); } }
private void renderProgressFill() { if( Atlas == null ) return; var spriteInfo = Atlas[ progressSprite ]; if( spriteInfo == null ) { return; } var paddingOffset = new Vector3( padding.left, -padding.top ); var fillSize = new Vector2( size.x - padding.horizontal, size.y - padding.vertical ); var progressFill = 1f; var valueRange = maxValue - minValue; var lerp = ( rawValue - minValue ) / valueRange; // There is a minimum size that sliced sprites can be stretched to, which is the // sum of their left and right borders. If the fill amount is less than that, we // automatically switch the FillMode to Fill instead of Stretch var activeMode = fillMode; if( activeMode == dfProgressFillMode.Stretch && fillSize.x * lerp < spriteInfo.border.horizontal ) { // TODO: Make this an option... Doesn't look right on sprites that have transparent padding in the image //activeMode = ProgressFillMode.Fill; // TODO: Switching to fill should resize the image instead of stretching to fill // the entire control then performing fill operation. } if( activeMode == dfProgressFillMode.Fill ) { progressFill = lerp; } else { fillSize.x = Mathf.Max( spriteInfo.border.horizontal, fillSize.x * lerp ); } var color = ApplyOpacity( IsEnabled ? this.ProgressColor : this.DisabledColor ); var options = new dfSprite.RenderOptions() { atlas = atlas, color = color, fillAmount = progressFill, flip = dfSpriteFlip.None, offset = pivot.TransformToUpperLeft( Size ) + paddingOffset, pixelsToUnits = PixelsToUnits(), size = fillSize, spriteInfo = spriteInfo }; if( spriteInfo.border.horizontal == 0 && spriteInfo.border.vertical == 0 ) dfSprite.renderSprite( renderData, options ); else dfSlicedSprite.renderSprite( renderData, options ); }