Exemple #1
0
 private void UpdateLabels(bool refresh = false)
 {
     if (_replayController.PlayListReplays.Count == 0)
     {
         return;
     }
     TimeBox.Text  = _replayController.CurrentTime.ToTimeString();
     timeBar.Value =
         (int)(Math.Min(_replayController.CurrentTime, _replayController.MaxTime) / _replayController.MaxTime * timeBar.Maximum);
     ShowCoordinates();
     SpeedLabel.Text = "Speed: " + _replayController.GetSpeed().ToString("F2");
     if (refresh)
     {
         TimeBox.Refresh();
         SpeedLabel.Refresh();
         CoordinateLabel.Refresh();
     }
 }
Exemple #2
0
    public void RefreshPositions()
    {
        if (!m_isEnabled)
        {
            return;
        }

        Vector2 min_GraphSpace     = m_nodeGraphView.viewTransform.position;
        Vector2 offset_GraphSpace  = m_nodeGraphView.contentViewContainer.layout.position;
        Vector2 center_ScreenSpace = new Vector2(min_GraphSpace.x - offset_GraphSpace.x, min_GraphSpace.y - offset_GraphSpace.y);
        Vector2 max_ScreenSpace    = new Vector2(m_nodeGraphView.viewport.worldBound.size.x - HALF_AXIS_LINE_WIDTH,
                                                 m_nodeGraphView.viewport.worldBound.size.y - HALF_AXIS_LINE_WIDTH);

        center_ScreenSpace.x = Mathf.Clamp(center_ScreenSpace.x, 0, max_ScreenSpace.x);
        center_ScreenSpace.y = Mathf.Clamp(center_ScreenSpace.y, HALF_AXIS_LINE_WIDTH, max_ScreenSpace.y);

        // Setting Axes bars
        m_xAxis.SetPos(new Vector2(Mathf.Max(center_ScreenSpace.x, AXIS_LINE_WIDTH - 1), 0));
        m_yAxis.SetPos(new Vector2(0, center_ScreenSpace.y));

        // Setting the coordinate labels
        m_cachedCoordinateLabels.AddRange(m_coordinateLabels);
        foreach (CoordinateLabel label in m_coordinateLabels)
        {
            Remove(label);
        }
        m_coordinateLabels.Clear();
        CoordinateLabel GetCoordinateLabel()
        {
            CoordinateLabel coordinateLabel;

            if (m_cachedCoordinateLabels.Count > 0)
            {
                coordinateLabel = m_cachedCoordinateLabels[m_cachedCoordinateLabels.Count - 1];
                m_cachedCoordinateLabels.RemoveAt(m_cachedCoordinateLabels.Count - 1);
            }
            else
            {
                coordinateLabel = new CoordinateLabel();
            }
            Add(coordinateLabel);
            m_coordinateLabels.Add(coordinateLabel);
            return(coordinateLabel);
        }

        float zoom = m_nodeGraphView.viewTransform.scale.x; // x and y are the same so just take one of them.
        float increment;

        if (zoom <= 0.35f)
        {
            increment = 400;
        }
        else if (zoom <= 0.6f)
        {
            increment = 200;
        }
        else
        {
            increment = 100;
        }
        float pixelsPerIncrement = increment * zoom;

        Vector2 lowerBound = new Vector2(
            Mathf.Floor((offset_GraphSpace.x - min_GraphSpace.x) / pixelsPerIncrement) * pixelsPerIncrement,
            Mathf.Floor((offset_GraphSpace.y - min_GraphSpace.y) / pixelsPerIncrement) * pixelsPerIncrement);
        Vector2 upperBound = new Vector2(
            Mathf.Ceil((max_ScreenSpace.x + offset_GraphSpace.x - min_GraphSpace.x) / pixelsPerIncrement) * pixelsPerIncrement,
            Mathf.Ceil((max_ScreenSpace.y + offset_GraphSpace.y - min_GraphSpace.y) / pixelsPerIncrement) * pixelsPerIncrement);

        for (float i = lowerBound.y; i <= upperBound.y; i += pixelsPerIncrement)
        {
            if ((int)i == 0)
            {
                continue;
            }

            GetCoordinateLabel().SetLabel((int)(Mathf.Round((i / zoom) / increment) * increment),
                                          new Vector2(Mathf.Max(center_ScreenSpace.x, AXIS_LINE_WIDTH - 1), i - offset_GraphSpace.y + min_GraphSpace.y),
                                          (center_ScreenSpace.x < max_ScreenSpace.x) ? CoordinateLabel.Direction.RIGHT : CoordinateLabel.Direction.LEFT);
        }
        for (float i = lowerBound.x; i <= upperBound.x; i += pixelsPerIncrement)
        {
            if ((int)i == 0)
            {
                continue;
            }

            GetCoordinateLabel().SetLabel((int)(Mathf.Round((i / zoom) / increment) * increment),
                                          new Vector2(i - offset_GraphSpace.x + min_GraphSpace.x, center_ScreenSpace.y),
                                          (center_ScreenSpace.y != max_ScreenSpace.y) ? CoordinateLabel.Direction.DOWN : CoordinateLabel.Direction.UP);
        }
    }