public void DrawWholeView(Rect Canvas, TimeUnit LeftTime, TimeUnit RightTime, DataBridge Data) { TimeUnit MinTime, MaxTime; Data.GetTimeRange(out MinTime, out MaxTime); var LeftNorm = GetTimeNormalised(MinTime, MaxTime, LeftTime); var RightNorm = GetTimeNormalised(MinTime, MaxTime, RightTime); var RectNorm = new Rect(LeftNorm, 0, RightNorm - LeftNorm, 1); var VisibleRect = PopMath.RectMult(RectNorm, Canvas); //EditorGUI.DrawRect (Canvas, CanvasBackgroundColour); EditorGUI.DrawRect(VisibleRect, Color.red); }
public void Draw(Rect CanvasRect, TimeUnit LeftTime, TimeUnit RightTime, TimeUnit?SelectedTime, TimeUnit?HoverTime, DataBridge Data, List <DataStreamMeta> Streams, DragMeta DragMeta) { EditorGUI.DrawRect(CanvasRect, CanvasBackgroundColour); //DrawWholeView (Canvas, LeftTime, RightTime, Data); var StreamRects = new Rect[Streams.Count]; for (int s = 0; s < Streams.Count; s++) { var st0 = (s + 0) / (float)Streams.Count; var st1 = (s + 1) / (float)Streams.Count; var StreamBorder = 1; var Top = Mathf.Lerp(CanvasRect.min.y + StreamBorder, CanvasRect.max.y, st0); var Bot = Mathf.Lerp(CanvasRect.min.y + StreamBorder, CanvasRect.max.y, st1) - StreamBorder; var Left = CanvasRect.min.x + StreamBorder; var Right = CanvasRect.max.x - StreamBorder; var StreamRect = new Rect(Left, Top, Right - Left, Bot - Top); StreamRects [s] = StreamRect; } var DrawCap = MaxDataDraws; Rect?FirstSelectionRect = null; // draw streams for (int s = 0; s < Streams.Count; s++) { var StreamRect = StreamRects [s]; var Stream = Streams [s]; EditorGUI.DrawRect(StreamRect, StreamBackgroundColour); var StreamColour = Stream.Colour; // get all the data in the visible region var StreamDatas = Data.GetStreamData(Stream, LeftTime, RightTime); var StreamDataRect = new Rect(0, 0, 1, 1); var MinWidthPx = 1; System.Func <TimeUnit, TimeUnit, Color, DataState, Rect> DrawMarker = (DataTimeLeft, DataTimeRight, Colour, State) => { var LeftNorm = GetTimeNormalised(LeftTime, RightTime, DataTimeLeft); var RightNorm = GetTimeNormalised(LeftTime, RightTime, DataTimeRight); StreamDataRect.x = LeftNorm; StreamDataRect.width = RightNorm - LeftNorm; var DrawStreamDataRect = PopMath.RectMult(StreamDataRect, StreamRect); DrawStreamDataRect.width = Mathf.Max(MinWidthPx, DrawStreamDataRect.width); if (DrawStreamDataRect.width <= 2.0f) { DrawStreamDataRect.width = MinWidthPx; } // giant rects kill performance (CPU renderer??) DrawStreamDataRect = DrawStreamDataRect.ClipToParent(StreamRect); if (State == DataState.Loaded) { EditorGUI.DrawRect(DrawStreamDataRect, Colour); } else { var StripeHeight = 2; int i = 0; var yoffset = (DrawStreamDataRect.height % StripeHeight) - (StripeHeight / 2.0f); for (var y = 0; y < DrawStreamDataRect.height + StripeHeight; y += StripeHeight, i++) { if (i % 3 == 2) { continue; } var Rect = DrawStreamDataRect; Rect.y = y + yoffset + DrawStreamDataRect.yMin; Rect.height = StripeHeight; // clip if (Rect.yMin > DrawStreamDataRect.yMax) { continue; } Rect.yMin = Mathf.Max(Rect.yMin, DrawStreamDataRect.yMin); Rect.yMax = Mathf.Min(Rect.yMax, DrawStreamDataRect.yMax); EditorGUI.DrawRect(Rect, Colour); } } return(DrawStreamDataRect); }; System.Func <TimeUnit, TimeUnit, Color, DataState, Rect> DrawData = (DataTimeLeft, DataTimeRight, Colour, State) => { var DrawStreamDataRect = DrawMarker(DataTimeLeft, DataTimeRight, Colour, State); // put some notches in long data // gr: correct the notches for the clipping change // gr: also, on mega long data, this causes a giant loop. start & end at nearest (also fixes above) var DurationMs = DataTimeRight.Time - DataTimeLeft.Time; var MaxLoopDuration = 10000; var NotchStep = Stream.NotchStepMs.HasValue ? Stream.NotchStepMs.Value : DurationMs; for (int NotchMs = NotchStep; NotchMs < DurationMs && DurationMs < MaxLoopDuration; NotchMs += NotchStep) { var LeftNorm = GetTimeNormalised(LeftTime, RightTime, new TimeUnit(DataTimeLeft.Time + NotchMs)); //var RightNorm = LeftNorm; StreamDataRect.x = LeftNorm; StreamDataRect.width = 0; var NotchDrawStreamDataRect = PopMath.RectMult(StreamDataRect, StreamRect); NotchDrawStreamDataRect.width = MinWidthPx; NotchDrawStreamDataRect = NotchDrawStreamDataRect.ClipToParent(StreamRect); EditorGUI.DrawRect(NotchDrawStreamDataRect, BlockNotchColour); } // change cursor if this is draggable if (Stream.Draggable) { EditorGUIUtility.AddCursorRect(DrawStreamDataRect, MouseCursor.Pan); } return(DrawStreamDataRect); }; System.Func <TimeUnit, Color, Rect> DrawLine = (DataTimeLeft, Colour) => { var SelectedTimeDuration = 16; var DataTimeRight = new TimeUnit(DataTimeLeft.Time + SelectedTimeDuration); return(DrawMarker(DataTimeLeft, DataTimeRight, Colour, DataState.Loaded)); }; // draw hover underneath if (HoverTime.HasValue) { var SelectedTimeLeft = HoverTime.Value; DrawLine(SelectedTimeLeft, HoverColour); } foreach (var StreamData in StreamDatas) { if (DrawCap-- <= 0) { break; } DrawData(StreamData.GetStartTime(), StreamData.GetEndTime(), StreamColour, StreamData.GetStatus()); // draw again offset by drag if (DragMeta != null && DragMeta.Draggable && DragMeta.StreamIndex == s) { var DraggedStartTime = new TimeUnit(StreamData.GetStartTime().Time + DragMeta.DragAmount.Time); var DraggedEndTime = new TimeUnit(StreamData.GetEndTime().Time + DragMeta.DragAmount.Time); DrawData(DraggedStartTime, DraggedEndTime, DragColour, StreamData.GetStatus()); } } // draw selection over the top if (SelectedTime.HasValue) { var SelectedTimeLeft = SelectedTime.Value; var Rect = DrawLine(SelectedTimeLeft, SelectionColour); if (!FirstSelectionRect.HasValue) { FirstSelectionRect = Rect; } } // draw text over that var LabelStyle = new GUIStyle(); LabelStyle.alignment = TextAnchor.LowerLeft; LabelStyle.fontStyle = StreamLabelFontStyle; LabelStyle.normal.textColor = StreamLabelColour; EditorGUI.DropShadowLabel(StreamRect, Stream.Name, LabelStyle); } // draw time labels { var LabelStyle = new GUIStyle(); LabelStyle.alignment = TextAnchor.UpperLeft; LabelStyle.fontStyle = TimeLabelFontStyle; LabelStyle.normal.textColor = TimeLabelColour; EditorGUI.DropShadowLabel(CanvasRect, "|< " + LeftTime.GetLabel(false), LabelStyle); } { var LabelStyle = new GUIStyle(); LabelStyle.alignment = TextAnchor.UpperRight; LabelStyle.fontStyle = TimeLabelFontStyle; LabelStyle.normal.textColor = TimeLabelColour; EditorGUI.DropShadowLabel(CanvasRect, RightTime.GetLabel(false) + " >|", LabelStyle); } if (SelectedTime.HasValue && FirstSelectionRect.HasValue) { var LabelStyle = new GUIStyle(); LabelStyle.alignment = TextAnchor.UpperLeft; LabelStyle.fontStyle = SelectedTimeLabelFontStyle; LabelStyle.normal.textColor = SelectedTimeLabelColour; var Label = "\n<<" + SelectedTime.Value.GetLabel(true); EditorGUI.DropShadowLabel(FirstSelectionRect.Value, Label, LabelStyle); } if (DrawCap <= 0) { Debug.Log("Exceeded draw cap"); } }