Search in sources :

Example 1 with Scene

use of com.android.tools.idea.uibuilder.scene.Scene in project android by JetBrains.

the class DrawConstraintModel method paint.

//////////////////////////////////////////////////////////////////////////////
// Painting
//////////////////////////////////////////////////////////////////////////////
/**
   * Paint ourselves and our children
   * @param gc                 the graphic context
   * @param screenView
   * @param component          the component to draw
   * @param width              width of the canvas
   * @param height             height of the canvas
   * @param showAllConstraints flag to show or not all the existing constraints
   */
public boolean paint(@NotNull Graphics2D gc, ScreenView screenView, ConstraintWidget component, int width, int height, boolean showAllConstraints) {
    Graphics2D g = (Graphics2D) gc.create();
    WidgetDecorator.setShowFakeUI(mShowFakeUI);
    if (!ConstraintLayoutHandler.USE_SOLVER) {
        int dpi = myConstraintModel.getNlModel().getConfiguration().getDensity().getDpiValue();
        myConstraintModel.setDpiValue(dpi);
        Scene scene = screenView.getScene();
        myConstraintModel.updateNlModel(scene, myConstraintModel.getNlModel().getComponents(), true);
    }
    if (mySceneDraw.getCurrentStyle() == WidgetDecorator.BLUEPRINT_STYLE) {
        mySceneDraw.drawBackground(myConstraintModel.getScene().getWidget(component), myViewTransform, g, width, height);
    }
    if (myConstraintModel.getNeedsAnimateConstraints() != -1) {
        mySceneDraw.animateConstraints(myConstraintModel.getNeedsAnimateConstraints());
        myConstraintModel.setNeedsAnimateConstraints(-1);
    }
    mySceneDraw.setApplyConstraints(ConstraintLayoutHandler.USE_SOLVER);
    boolean ret = mySceneDraw.paintWidgets(component, width, height, myViewTransform, g, showAllConstraints, myMouseInteraction);
    g.dispose();
    return ret;
}
Also used : Scene(com.android.tools.idea.uibuilder.scene.Scene) WidgetsScene(com.android.tools.sherpa.structure.WidgetsScene)

Example 2 with Scene

use of com.android.tools.idea.uibuilder.scene.Scene in project android by JetBrains.

the class AnchorTarget method connectMe.

/**
   * Connect the anchor to the given target. Applied immediately in memory.
   *
   * @param component
   * @param attribute
   * @param targetComponent
   * @return
   */
private AttributesTransaction connectMe(NlComponent component, String attribute, NlComponent targetComponent) {
    AttributesTransaction attributes = component.startAttributeTransaction();
    String targetId = null;
    if (targetComponent == component.getParent()) {
        targetId = SdkConstants.ATTR_PARENT;
    } else {
        targetId = SdkConstants.NEW_ID_PREFIX + targetComponent.ensureLiveId();
    }
    attributes.setAttribute(SdkConstants.SHERPA_URI, attribute, targetId);
    if (myType == Type.BASELINE) {
        clearAttributes(SdkConstants.SHERPA_URI, ourTopAttributes, attributes);
        clearAttributes(SdkConstants.SHERPA_URI, ourBottomAttributes, attributes);
        attributes.setAttribute(SdkConstants.SHERPA_URI, SdkConstants.ATTR_LAYOUT_VERTICAL_BIAS, null);
        attributes.setAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_TOP, null);
        attributes.setAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_LAYOUT_MARGIN_BOTTOM, null);
    } else if (ourReciprocalAttributes.get(attribute) != null) {
        attributes.setAttribute(SdkConstants.SHERPA_URI, ourReciprocalAttributes.get(attribute), null);
    }
    if (ourMapMarginAttributes.get(attribute) != null) {
        Scene scene = myComponent.getScene();
        int marginValue = getDistance(attribute, targetComponent, scene);
        if (!scene.isControlDown()) {
            if (marginValue < 0) {
                marginValue = 0;
            } else {
                marginValue = Scout.getMargin();
            }
        } else {
            marginValue = Math.max(marginValue, 0);
        }
        String margin = String.format(SdkConstants.VALUE_N_DP, marginValue);
        attributes.setAttribute(SdkConstants.ANDROID_URI, ourMapMarginAttributes.get(attribute), margin);
        scene.needsRebuildList();
        myConnectedX = myLastX;
        myConnectedY = myLastY;
    }
    cleanup(attributes);
    attributes.apply();
    myComponent.getScene().needsLayout(Scene.ANIMATED_LAYOUT);
    return attributes;
}
Also used : Scene(com.android.tools.idea.uibuilder.scene.Scene) AttributesTransaction(com.android.tools.idea.uibuilder.model.AttributesTransaction)

Example 3 with Scene

use of com.android.tools.idea.uibuilder.scene.Scene in project android by JetBrains.

the class DragDndTarget method mouseDrag.

@Override
public void mouseDrag(int x, int y, @Nullable Target closestTarget) {
    if (myComponent instanceof TemporarySceneComponent) {
        Scene scene = myComponent.getScene();
        int dx = snapX(x);
        int dy = snapY(y);
        myComponent.setPosition(dx, dy);
        scene.needsRebuildList();
    } else {
        super.mouseDrag(x, y, closestTarget);
    }
}
Also used : Scene(com.android.tools.idea.uibuilder.scene.Scene) TemporarySceneComponent(com.android.tools.idea.uibuilder.scene.TemporarySceneComponent)

Example 4 with Scene

use of com.android.tools.idea.uibuilder.scene.Scene in project android by JetBrains.

the class DesignSurface method positionScreens.

private void positionScreens() {
    if (myScreenView == null) {
        return;
    }
    Dimension screenViewSize = myScreenView.getSize();
    // Position primary screen
    int availableWidth = myScrollPane.getWidth();
    int availableHeight = myScrollPane.getHeight();
    myStackVertically = isVerticalScreenConfig(availableWidth, availableHeight, screenViewSize);
    // If we are resizing the canvas, do not relocate the primary screen
    if (!myIsCanvasResizing) {
        if (myCentered && availableWidth > 10 && availableHeight > 10) {
            int requiredWidth = screenViewSize.width;
            if (myScreenMode == ScreenMode.BOTH && !myStackVertically) {
                requiredWidth += SCREEN_DELTA;
                requiredWidth += screenViewSize.width;
            }
            myScreenX = Math.max((availableWidth - requiredWidth) / 2, RULER_SIZE_PX + DEFAULT_SCREEN_OFFSET_X);
            int requiredHeight = screenViewSize.height;
            if (myScreenMode == ScreenMode.BOTH && myStackVertically) {
                requiredHeight += SCREEN_DELTA;
                requiredHeight += screenViewSize.height;
            }
            myScreenY = Math.max((availableHeight - requiredHeight) / 2, RULER_SIZE_PX + DEFAULT_SCREEN_OFFSET_Y);
        } else {
            if (myDeviceFrames) {
                myScreenX = RULER_SIZE_PX + 2 * DEFAULT_SCREEN_OFFSET_X;
                myScreenY = RULER_SIZE_PX + 2 * DEFAULT_SCREEN_OFFSET_Y;
            } else {
                myScreenX = RULER_SIZE_PX + DEFAULT_SCREEN_OFFSET_X;
                myScreenY = RULER_SIZE_PX + DEFAULT_SCREEN_OFFSET_Y;
            }
        }
    }
    myScreenView.setLocation(myScreenX, myScreenY);
    // Position blueprint view
    if (myBlueprintView != null) {
        if (myStackVertically) {
            // top/bottom stacking
            myBlueprintView.setLocation(myScreenX, myScreenY + screenViewSize.height + SCREEN_DELTA);
        } else {
            // left/right ordering
            myBlueprintView.setLocation(myScreenX + screenViewSize.width + SCREEN_DELTA, myScreenY);
        }
    }
    if (myScreenView != null && myScreenView.getScene() != null) {
        Scene scene = myScreenView.getScene();
        scene.needsRebuildList();
    }
    if (myBlueprintView != null && myBlueprintView.getScene() != null) {
        Scene scene = myBlueprintView.getScene();
        scene.needsRebuildList();
    }
}
Also used : Scene(com.android.tools.idea.uibuilder.scene.Scene)

Aggregations

Scene (com.android.tools.idea.uibuilder.scene.Scene)4 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)1 TemporarySceneComponent (com.android.tools.idea.uibuilder.scene.TemporarySceneComponent)1 WidgetsScene (com.android.tools.sherpa.structure.WidgetsScene)1