Ejemplo n.º 1
0
        void DrawEntity(T entity)
        {
            var vertexData = graph.VerticesData[entity];

            drawContext.position    = transform.Apply(vertexData.pos);
            drawContext.isTarget    = parent.IsSeed(entity);
            drawContext.isSelected  = entitySelection.Contains(entity);
            drawContext.isUnexlored = vertexData.unexplored;
            drawContext.widgetType  = entityWidgetType;
            drawContext.style       = SkinManager.GetSkin().entityWidget;

            entityDrawerBounds[entity] = parent.GetBackend().DrawContent(entity, drawContext);
        }
Ejemplo n.º 2
0
        public void FitViewRectToGraph(bool immediately)
        {
            if (immediately)
            {
                transform = GetOptimalTransform();
                return;
            }

            // viewRect: canvas shrunk down to 80%
            Rect viewRect = parent.GetViewRect();

            viewRect = Util.CenterRect(viewRect.center, viewRect.GetExtents() * 0.8f);

            // find graphRect (logical coords)
            var  logicalPositions = graph.VerticesData.Values.Select(v => v.pos);
            Rect logicalPosBounds = Util.GetBounds(logicalPositions).ClampExtents(0.01f, 0.01f, float.MaxValue, float.MaxValue);

            var logicalExtents = logicalPosBounds.GetExtents();
            var viewExtents    = viewRect.GetExtents();

            // fit logical extents into display extents
            var fullScale = new Vector2(
                viewExtents.x / logicalExtents.x,
                viewExtents.y / logicalExtents.y
                );

            var   targetScale           = transform.scale.Clamp(fullScale * 0.5f, fullScale);
            bool  scaleChange           = targetScale != transform.scale;
            var   targetTransform       = new Transform2d(transform.translation, targetScale, transform.rotation);
            var   targetViewGraphBounds = targetTransform.Apply(logicalPosBounds);
            float xOver  = targetViewGraphBounds.xMax - viewRect.xMax;
            float xUnder = targetViewGraphBounds.xMin - viewRect.xMin;
            float yOver  = targetViewGraphBounds.yMax - viewRect.yMax;
            float yUnder = targetViewGraphBounds.yMin - viewRect.yMin;

            var shift = new Vector2(
                xOver > 0 ? xOver : xUnder < 0 ? xUnder : 0,
                yOver > 0 ? yOver : yUnder < 0 ? yUnder : 0);
            bool translateChanged = shift != Vector2.zero;

            if (scaleChange || translateChanged)
            {
                targetTransform.translation -= shift;
                Tweener.gen.Add(new Tween <Transform2d>(t => transform = t, 0.2f, TweenUtil.Transform2(transform, targetTransform, TwoValueEasing.Linear)));
            }
        }
Ejemplo n.º 3
0
        static Transform2d Zoom(Transform2d transform, bool zoomIn, bool affectX, bool affectY, Vector2 fixPosition)
        {
            // adjust the offset such that the window stays centered on the same graph position
            var fixPositionBase = transform.Revert(fixPosition);

            var targetTransform = new Transform2d(transform);

            if (affectX)
            {
                targetTransform.scale.x *= zoomIn ? 3f / 2 : 2f / 3;
            }
            if (affectY)
            {
                targetTransform.scale.y *= zoomIn ? 3f / 2 : 2f / 3;
            }

            var newfixPosition = targetTransform.Apply(fixPositionBase);

            targetTransform.translation += fixPosition - newfixPosition;
            return(targetTransform);
        }