public override void DoRepaint() { VisualElement parent = base.parent; GraphView graphView = parent as GraphView; if (graphView == null) { throw new InvalidOperationException("GridBackground can only be added to a GraphView"); } this.m_Container = graphView.contentViewContainer; Rect layout = graphView.layout; layout.x = 0f; layout.y = 0f; Vector3 vector = new Vector3(this.m_Container.transform.matrix.GetColumn(0).magnitude, this.m_Container.transform.matrix.GetColumn(1).magnitude, this.m_Container.transform.matrix.GetColumn(2).magnitude); Vector4 column = this.m_Container.transform.matrix.GetColumn(3); Rect layout2 = this.m_Container.layout; HandleUtility.ApplyWireMaterial(); GL.Begin(7); GL.Color(this.gridBackgroundColor); GL.Vertex(new Vector3(layout.x, layout.y)); GL.Vertex(new Vector3(layout.xMax, layout.y)); GL.Vertex(new Vector3(layout.xMax, layout.yMax)); GL.Vertex(new Vector3(layout.x, layout.yMax)); GL.End(); Vector3 vector2 = new Vector3(layout.x, layout.y, 0f); Vector3 vector3 = new Vector3(layout.x, layout.height, 0f); Matrix4x4 matrix4x = Matrix4x4.TRS(column, Quaternion.identity, Vector3.one); vector2 = matrix4x.MultiplyPoint(vector2); vector3 = matrix4x.MultiplyPoint(vector3); vector2.x += layout2.x * vector.x; vector2.y += layout2.y * vector.y; vector3.x += layout2.x * vector.x; vector3.y += layout2.y * vector.y; Handles.DrawWireDisc(vector2, new Vector3(0f, 0f, -1f), 6f); float x = vector2.x; float y = vector2.y; vector2.x = vector2.x % (this.spacing * vector.x) - this.spacing * vector.x; vector3.x = vector2.x; vector2.y = layout.y; vector3.y = layout.y + layout.height; while (vector2.x < layout.width) { vector2.x += this.spacing * vector.x; vector3.x += this.spacing * vector.x; GL.Begin(1); GL.Color(this.lineColor); GL.Vertex(this.Clip(layout, vector2)); GL.Vertex(this.Clip(layout, vector3)); GL.End(); } float num = this.spacing * (float)this.thickLines; vector2.x = (vector3.x = x % (num * vector.x) - num * vector.x); while (vector2.x < layout.width + num) { GL.Begin(1); GL.Color(this.thickLineColor); GL.Vertex(this.Clip(layout, vector2)); GL.Vertex(this.Clip(layout, vector3)); GL.End(); vector2.x += this.spacing * vector.x * (float)this.thickLines; vector3.x += this.spacing * vector.x * (float)this.thickLines; } vector2 = new Vector3(layout.x, layout.y, 0f); vector3 = new Vector3(layout.x + layout.width, layout.y, 0f); vector2.x += layout2.x * vector.x; vector2.y += layout2.y * vector.y; vector3.x += layout2.x * vector.x; vector3.y += layout2.y * vector.y; vector2 = matrix4x.MultiplyPoint(vector2); vector3 = matrix4x.MultiplyPoint(vector3); vector2.y = (vector3.y = vector2.y % (this.spacing * vector.y) - this.spacing * vector.y); vector2.x = layout.x; vector3.x = layout.width; while (vector2.y < layout.height) { vector2.y += this.spacing * vector.y; vector3.y += this.spacing * vector.y; GL.Begin(1); GL.Color(this.lineColor); GL.Vertex(this.Clip(layout, vector2)); GL.Vertex(this.Clip(layout, vector3)); GL.End(); } num = this.spacing * (float)this.thickLines; vector2.y = (vector3.y = y % (num * vector.y) - num * vector.y); while (vector2.y < layout.height + num) { GL.Begin(1); GL.Color(this.thickLineColor); GL.Vertex(this.Clip(layout, vector2)); GL.Vertex(this.Clip(layout, vector3)); GL.End(); vector2.y += this.spacing * vector.y * (float)this.thickLines; vector3.y += this.spacing * vector.y * (float)this.thickLines; } }
public static void ApplyWireMaterial() { HandleUtility.ApplyWireMaterial(); }
public static void DrawClampedDetailPatchGUI(int mouseOnPatchIndex, List <Vector4> clampedDetailPatchIconScreenPositions, Vector2 detailMinMaxHeight, Terrain terrain, IOnSceneGUI editContext) { if (mouseOnPatchIndex == -1) { s_ShowTooManyDetailText = false; } if (clampedDetailPatchIconScreenPositions == null || Event.current.type != EventType.Repaint) { return; } var terrainData = terrain.terrainData; float patchUVSize = 1.0f / terrainData.detailPatchCount; int heightmapRes = terrainData.heightmapResolution; HandleUtility.ApplyWireMaterial(CompareFunction.LessEqual); GL.PushMatrix(); GL.MultMatrix(Matrix4x4.TRS(terrain.GetPosition(), Quaternion.identity, terrainData.size)); GL.Begin(GL.LINES); float centerOffset = (detailMinMaxHeight.y + detailMinMaxHeight.x) / terrainData.size.y * 0.5f; float halfSizeOffset = (detailMinMaxHeight.y - detailMinMaxHeight.x) / terrainData.size.y * 0.5f + 0.001f; if (GUIUtility.hotControl != 0 && editContext.hitValidTerrain) { // hotControl != 0 && hitValidTerrain: during painting for (int i = 0; i < s_CachedClampedPatches.Length; ++i) { if (s_CachedClampedPatches[i].x * patchUVSize <= editContext.raycastHit.textureCoord.x && s_CachedClampedPatches[i].y * patchUVSize <= editContext.raycastHit.textureCoord.y && (s_CachedClampedPatches[i].x + 1) * patchUVSize > editContext.raycastHit.textureCoord.x && (s_CachedClampedPatches[i].y + 1) * patchUVSize > editContext.raycastHit.textureCoord.y) { mouseOnPatchIndex = i; break; } } } for (int i = 0; i < s_CachedClampedPatches.Length; ++i) { var patch = s_CachedClampedPatches[i]; var heightMinMax = CalculatePatchHeightMinMaxCached(patch, patchUVSize, heightmapRes, terrainData); var center = new Vector3((patch.x + 0.5f) * patchUVSize, (heightMinMax.y + heightMinMax.x) * 0.5f, (patch.y + 0.5f) * patchUVSize); var halfSize = new Vector3(patchUVSize, heightMinMax.y - heightMinMax.x, patchUVSize) * 0.5f; center.y += centerOffset; halfSize.y += halfSizeOffset; GL.Color(i == mouseOnPatchIndex ? new Color(1, 0.2f, 0.2f, 1) : new Color(0.75f, 0, 0, 0.33f)); GL.Vertex(center + new Vector3(-halfSize.x, -halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, -halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, -halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, -halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, -halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, -halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, -halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, -halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, -halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, -halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, halfSize.y, -halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, -halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(halfSize.x, halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, -halfSize.y, halfSize.z)); GL.Vertex(center + new Vector3(-halfSize.x, halfSize.y, halfSize.z)); } GL.End(); GL.PopMatrix(); Handles.BeginGUI(); // Draw icons from back to front var showTooManyDetailTextPos = Vector4.zero; for (int i = 0; i < clampedDetailPatchIconScreenPositions.Count; ++i) { var p = clampedDetailPatchIconScreenPositions[i]; var rect = new Rect(p.x - k_IconSize / 2, p.y - k_IconSize / 2, k_IconSize, k_IconSize); GUI.DrawTexture(rect, k_TooManyDetails.image, ScaleMode.StretchToFill, true, 1.0f, Color.white * ((int)p.w == mouseOnPatchIndex ? 1 : 0.75f), 0, 0); if ((int)p.w == mouseOnPatchIndex && s_ShowTooManyDetailText) { showTooManyDetailTextPos = p; } } if (mouseOnPatchIndex >= 0 && s_ShowTooManyDetailText) { var sceneViewRect = SceneView.lastActiveSceneView.cameraViewport; sceneViewRect.y = 0; var textSize = EditorStyles.tooltip.CalcSize(k_TooManyDetails); var textRect = new Rect(showTooManyDetailTextPos.x + k_IconSize / 2 + 4, showTooManyDetailTextPos.y - k_IconSize / 2, textSize.x, textSize.y); if (textRect.xMax > sceneViewRect.xMax) { // move left var newX = showTooManyDetailTextPos.x - k_IconSize / 2 - 4 - textSize.x; if (newX >= 0) { textRect.x = newX; } } if (textRect.yMax > sceneViewRect.yMax) { // move up var newY = showTooManyDetailTextPos.y + k_IconSize / 2 - textSize.y; if (newY >= 0) { textRect.y = newY; } } EditorStyles.tooltip.Draw(textRect, k_TooManyDetails, false, false, false, false); } Handles.EndGUI(); }
public static void DrawSelectedHexGridArea(GridLayout gridLayout, BoundsInt area, Color color) { int requiredVertices = 4 * (area.size.x + area.size.y) - 2; if (requiredVertices < 0) { return; } Vector3[] cellLocals = new Vector3[requiredVertices]; int horizontalCount = area.size.x * 2; int verticalCount = area.size.y * 2 - 1; int bottom = 0; int top = horizontalCount + verticalCount + horizontalCount - 1; int left = requiredVertices - 1; int right = horizontalCount; Vector3[] cellOffset = { Grid.Swizzle(gridLayout.cellSwizzle, new Vector3(0, gridLayout.cellSize.y / 2, area.zMin)), Grid.Swizzle(gridLayout.cellSwizzle, new Vector3(gridLayout.cellSize.x / 2, gridLayout.cellSize.y / 4, area.zMin)), Grid.Swizzle(gridLayout.cellSwizzle, new Vector3(gridLayout.cellSize.x / 2, -gridLayout.cellSize.y / 4, area.zMin)), Grid.Swizzle(gridLayout.cellSwizzle, new Vector3(0, -gridLayout.cellSize.y / 2, area.zMin)), Grid.Swizzle(gridLayout.cellSwizzle, new Vector3(-gridLayout.cellSize.x / 2, -gridLayout.cellSize.y / 4, area.zMin)), Grid.Swizzle(gridLayout.cellSwizzle, new Vector3(-gridLayout.cellSize.x / 2, gridLayout.cellSize.y / 4, area.zMin)) }; // Fill Top and Bottom Vertices for (int x = area.min.x; x < area.max.x; x++) { cellLocals[bottom++] = gridLayout.CellToLocal(new Vector3Int(x, area.min.y, area.zMin)) + cellOffset[4]; cellLocals[bottom++] = gridLayout.CellToLocal(new Vector3Int(x, area.min.y, area.zMin)) + cellOffset[3]; cellLocals[top--] = gridLayout.CellToLocal(new Vector3Int(x, area.max.y - 1, area.zMin)) + cellOffset[0]; cellLocals[top--] = gridLayout.CellToLocal(new Vector3Int(x, area.max.y - 1, area.zMin)) + cellOffset[1]; } // Fill first Left and Right Vertices cellLocals[left--] = gridLayout.CellToLocal(new Vector3Int(area.min.x, area.min.y, area.zMin)) + cellOffset[5]; cellLocals[top--] = gridLayout.CellToLocal(new Vector3Int(area.max.x - 1, area.max.y - 1, area.zMin)) + cellOffset[2]; // Fill Left and Right Vertices for (int y = area.min.y + 1; y < area.max.y; y++) { cellLocals[left--] = gridLayout.CellToLocal(new Vector3Int(area.min.x, y, area.zMin)) + cellOffset[4]; cellLocals[left--] = gridLayout.CellToLocal(new Vector3Int(area.min.x, y, area.zMin)) + cellOffset[5]; } for (int y = area.min.y; y < (area.max.y - 1); y++) { cellLocals[right++] = gridLayout.CellToLocal(new Vector3Int(area.max.x - 1, y, area.zMin)) + cellOffset[2]; cellLocals[right++] = gridLayout.CellToLocal(new Vector3Int(area.max.x - 1, y, area.zMin)) + cellOffset[1]; } HandleUtility.ApplyWireMaterial(); GL.PushMatrix(); GL.MultMatrix(gridLayout.transform.localToWorldMatrix); GL.Begin(GL.LINES); GL.Color(color); int i = 0; for (int j = cellLocals.Length - 1; i < cellLocals.Length; j = i++) { DrawBatchedLine(cellLocals[j], cellLocals[i]); } GL.End(); GL.PopMatrix(); }
public void TimeRuler(Rect position, float frameRate, bool labels, bool useEntireHeight, float alpha, TimeFormat timeFormat) { Color backupCol = GUI.color; GUI.BeginGroup(position); InitStyles(); HandleUtility.ApplyWireMaterial(); Color tempBackgroundColor = GUI.backgroundColor; SetTickMarkerRanges(); hTicks.SetTickStrengths(kTickRulerDistMin, kTickRulerDistFull, true); Color baseColor = timeAreaStyles.timelineTick.normal.textColor; baseColor.a = 0.75f * alpha; if (Event.current.type == EventType.Repaint) { GL.Begin(GL.LINES); // Draw tick markers of various sizes Rect cachedShowArea = shownArea; for (int l = 0; l < hTicks.tickLevels; l++) { float strength = hTicks.GetStrengthOfLevel(l) * .9f; m_TickCache.Clear(); hTicks.GetTicksAtLevel(l, true, m_TickCache); for (int i = 0; i < m_TickCache.Count; i++) { if (m_TickCache[i] < hRangeMin || m_TickCache[i] > hRangeMax) { continue; } int frame = Mathf.RoundToInt(m_TickCache[i] * frameRate); float height = useEntireHeight ? position.height : position.height * Mathf.Min(1, strength) * kTickRulerHeightMax; float x = FrameToPixel(frame, frameRate, position, cachedShowArea); // Draw line DrawVerticalLineFast(x, position.height - height + 0.5f, position.height - 0.5f, new Color(1, 1, 1, strength / kTickRulerFatThreshold) * baseColor); } } GL.End(); } if (labels) { // Draw tick labels int labelLevel = hTicks.GetLevelWithMinSeparation(kTickRulerDistLabel); m_TickCache.Clear(); hTicks.GetTicksAtLevel(labelLevel, false, m_TickCache); for (int i = 0; i < m_TickCache.Count; i++) { if (m_TickCache[i] < hRangeMin || m_TickCache[i] > hRangeMax) { continue; } int frame = Mathf.RoundToInt(m_TickCache[i] * frameRate); // Important to take floor of positions of GUI stuff to get pixel correct alignment of // stuff drawn with both GUI and Handles/GL. Otherwise things are off by one pixel half the time. float labelpos = Mathf.Floor(FrameToPixel(frame, frameRate, position)); string label = FormatTickTime(m_TickCache[i], frameRate, timeFormat); GUI.Label(new Rect(labelpos + 3, -1, 40, 20), label, timeAreaStyles.timelineTick); } } GUI.EndGroup(); GUI.backgroundColor = tempBackgroundColor; GUI.color = backupCol; }
void Draw() { VisualElement target = parent; var graphView = target as GraphView; if (graphView == null) { throw new InvalidOperationException("GridBackground can only be added to a GraphView"); } m_Container = graphView.contentViewContainer; Rect clientRect = graphView.layout; // Since we're always stretch to parent size, we will use (0,0) as (x,y) coordinates clientRect.x = 0; clientRect.y = 0; var containerScale = new Vector3(m_Container.transform.matrix.GetColumn(0).magnitude, m_Container.transform.matrix.GetColumn(1).magnitude, m_Container.transform.matrix.GetColumn(2).magnitude); var containerTranslation = m_Container.transform.matrix.GetColumn(3); var containerPosition = m_Container.layout; // background HandleUtility.ApplyWireMaterial(); GL.Begin(GL.QUADS); GL.Color(gridBackgroundColor); GL.Vertex(new Vector3(clientRect.x, clientRect.y)); GL.Vertex(new Vector3(clientRect.xMax, clientRect.y)); GL.Vertex(new Vector3(clientRect.xMax, clientRect.yMax)); GL.Vertex(new Vector3(clientRect.x, clientRect.yMax)); GL.End(); // vertical lines Vector3 from = new Vector3(clientRect.x, clientRect.y, 0.0f); Vector3 to = new Vector3(clientRect.x, clientRect.height, 0.0f); var tx = Matrix4x4.TRS(containerTranslation, Quaternion.identity, Vector3.one); from = tx.MultiplyPoint(from); to = tx.MultiplyPoint(to); from.x += (containerPosition.x * containerScale.x); from.y += (containerPosition.y * containerScale.y); to.x += (containerPosition.x * containerScale.x); to.y += (containerPosition.y * containerScale.y); Handles.DrawWireDisc(from, new Vector3(0.0f, 0.0f, -1.0f), 6f); float thickGridLineX = from.x; float thickGridLineY = from.y; // Update from/to to start at beginning of clientRect from.x = (from.x % (spacing * (containerScale.x)) - (spacing * (containerScale.x))); to.x = from.x; from.y = clientRect.y; to.y = clientRect.y + clientRect.height; while (from.x < clientRect.width) { from.x += spacing * containerScale.x; to.x += spacing * containerScale.x; GL.Begin(GL.LINES); GL.Color(lineColor); GL.Vertex(Clip(clientRect, from)); GL.Vertex(Clip(clientRect, to)); GL.End(); } float thickLineSpacing = (spacing * thickLines); from.x = to.x = (thickGridLineX % (thickLineSpacing * (containerScale.x)) - (thickLineSpacing * (containerScale.x))); while (from.x < clientRect.width + thickLineSpacing) { GL.Begin(GL.LINES); GL.Color(thickLineColor); GL.Vertex(Clip(clientRect, from)); GL.Vertex(Clip(clientRect, to)); GL.End(); from.x += (spacing * containerScale.x * thickLines); to.x += (spacing * containerScale.x * thickLines); } // horizontal lines from = new Vector3(clientRect.x, clientRect.y, 0.0f); to = new Vector3(clientRect.x + clientRect.width, clientRect.y, 0.0f); from.x += (containerPosition.x * containerScale.x); from.y += (containerPosition.y * containerScale.y); to.x += (containerPosition.x * containerScale.x); to.y += (containerPosition.y * containerScale.y); from = tx.MultiplyPoint(from); to = tx.MultiplyPoint(to); from.y = to.y = (from.y % (spacing * (containerScale.y)) - (spacing * (containerScale.y))); from.x = clientRect.x; to.x = clientRect.width; while (from.y < clientRect.height) { from.y += spacing * containerScale.y; to.y += spacing * containerScale.y; GL.Begin(GL.LINES); GL.Color(lineColor); GL.Vertex(Clip(clientRect, from)); GL.Vertex(Clip(clientRect, to)); GL.End(); } thickLineSpacing = spacing * thickLines; from.y = to.y = (thickGridLineY % (thickLineSpacing * (containerScale.y)) - (thickLineSpacing * (containerScale.y))); while (from.y < clientRect.height + thickLineSpacing) { GL.Begin(GL.LINES); GL.Color(thickLineColor); GL.Vertex(Clip(clientRect, from)); GL.Vertex(Clip(clientRect, to)); GL.End(); from.y += spacing * containerScale.y * thickLines; to.y += spacing * containerScale.y * thickLines; } }
public void DoTimeRulerGUI(Rect rect, float frameTime) { if (m_TimeArea == null || Event.current.type != EventType.Repaint) { return; } GUI.BeginClip(rect); rect.x = rect.y = 0; GUI.Box(rect, GUIContent.none, EditorStyles.toolbarButton); var baseColor = styles.timelineTick.normal.textColor; baseColor.a *= 0.75f; PrepareTicks(); // Tick lines if (Event.current.type == EventType.Repaint) { HandleUtility.ApplyWireMaterial(); if (Application.platform == RuntimePlatform.WindowsEditor) { GL.Begin(GL.QUADS); } else { GL.Begin(GL.LINES); } for (int l = 0; l < m_HTicks.tickLevels; l++) { var strength = m_HTicks.GetStrengthOfLevel(l) * .8f; var ticks = m_HTicks.GetTicksAtLevel(l, true); for (int i = 0; i < ticks.Length; i++) { // Draw line var time = ticks[i]; var x = m_TimeArea.TimeToPixel(time, rect); var height = rect.height * Mathf.Min(1, strength) * TimeArea.kTickRulerHeightMax; var color = new Color(1, 1, 1, strength / TimeArea.kTickRulerFatThreshold) * baseColor; TimeArea.DrawVerticalLineFast(x, rect.height - height + 0.5f, rect.height - 0.5f, color); } } GL.End(); } // Tick labels var labelWidth = k_TickLabelSeparation; int labelLevel = m_HTicks.GetLevelWithMinSeparation(labelWidth); float[] labelTicks = m_HTicks.GetTicksAtLevel(labelLevel, false); for (int i = 0; i < labelTicks.Length; i++) { var time = labelTicks[i]; float labelpos = Mathf.Floor(m_TimeArea.TimeToPixel(time, rect)); string label = FormatTickLabel(time, labelLevel); GUI.Label(new Rect(labelpos + 3, -3, labelWidth, 20), label, styles.timelineTick); } // Outside current frame coloring DrawOutOfRangeOverlay(rect, frameTime); // Range selection coloring DrawRangeSelectionOverlay(rect); GUI.EndClip(); }